Skip to content

Commit 9cdb76a

Browse files
authored
Support >2 channels (#13)
* Read number of channels correctly * Revert formatting * Corrected frequencies / and dont throw * Doc SampleMetadata
1 parent 510ddfc commit 9cdb76a

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

Fmod5Sharp/CodecRebuilders/FmodVorbisRebuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ private static void ReadSamplePackets(BinaryReader inputReader, out List<int> pa
176176
{
177177
var packetSize = inputReader.ReadUInt16();
178178

179-
if (packetSize == 0)
179+
if (packetSize == 0 || packetSize == 0xFFFF)
180180
break; //EOS
181181

182182
packetLengths.Add(packetSize);

Fmod5Sharp/FmodTypes/FmodSampleMetadata.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
namespace Fmod5Sharp.FmodTypes
66
{
7-
public class FmodSampleMetadata : IBinaryReadable
7+
//Can be verified against "FMOD::CodecFSB5::decodeSubSoundHeader" in fmod.dll
8+
public class FmodSampleMetadata : IBinaryReadable
89
{
910
internal bool HasAnyChunks;
1011
internal uint FrequencyId;
@@ -24,10 +25,16 @@ void IBinaryReadable.Read(BinaryReader reader)
2425

2526
HasAnyChunks = (encoded & 1) == 1; //Bit 0
2627
FrequencyId = (uint) encoded.Bits( 1, 4); //Bits 1-4
27-
var pow2 = (int) encoded.Bits(5, 2); //Bits 5-6
28-
NumChannels = 1 << pow2;
29-
if (NumChannels > 2)
30-
throw new("> 2 channels not supported");
28+
29+
int channelBits = (int)encoded.Bits(5, 2); //Bits 5-6
30+
NumChannels = channelBits switch
31+
{
32+
0 => 1,
33+
1 => 2,
34+
2 => 6,
35+
3 => 8,
36+
_ => 0
37+
};
3138

3239
IsStereo = NumChannels == 2;
3340

Fmod5Sharp/FsbLoader.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ public static class FsbLoader
1010
{
1111
internal static readonly Dictionary<uint, int> Frequencies = new()
1212
{
13-
{ 1, 8000 },
13+
{ 0, 4_000 },
14+
{ 1, 8_000 },
1415
{ 2, 11_000 },
15-
{ 3, 11_025 },
16+
{ 3, 12_000 },
1617
{ 4, 16_000 },
1718
{ 5, 22_050 },
1819
{ 6, 24_000 },

0 commit comments

Comments
 (0)