-
Notifications
You must be signed in to change notification settings - Fork 11
Support >2 channels #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,38 +1,43 @@ | ||
| using System.Collections.Generic; | ||
| using Fmod5Sharp.Util; | ||
| using System.Collections.Generic; | ||
| using System.IO; | ||
| using Fmod5Sharp.Util; | ||
|
|
||
| namespace Fmod5Sharp.FmodTypes | ||
| { | ||
| public class FmodSampleMetadata : IBinaryReadable | ||
| { | ||
| internal bool HasAnyChunks; | ||
| internal uint FrequencyId; | ||
| internal ulong DataOffset; | ||
| internal List<FmodSampleChunk> Chunks = new(); | ||
| internal int NumChannels; | ||
| public class FmodSampleMetadata : IBinaryReadable | ||
| { | ||
| internal bool HasAnyChunks; | ||
| internal uint FrequencyId; | ||
| internal ulong DataOffset; | ||
| internal List<FmodSampleChunk> Chunks = new(); | ||
| internal int NumChannels; | ||
|
|
||
| public bool IsStereo; | ||
| public ulong SampleCount; | ||
| public bool IsStereo; | ||
| public ulong SampleCount; | ||
|
|
||
| public int Frequency => FsbLoader.Frequencies.TryGetValue(FrequencyId, out var actualFrequency) ? actualFrequency : (int)FrequencyId; //If set by FREQUENCY chunk, id is actual frequency | ||
| public uint Channels => (uint)NumChannels; | ||
| public int Frequency => FsbLoader.Frequencies.TryGetValue(FrequencyId, out var actualFrequency) ? actualFrequency : (int)FrequencyId; // If set by FREQUENCY chunk, id is actual frequency | ||
| public uint Channels => (uint)NumChannels; | ||
|
|
||
| void IBinaryReadable.Read(BinaryReader reader) | ||
| { | ||
| var encoded = reader.ReadUInt64(); | ||
|
|
||
| HasAnyChunks = (encoded & 1) == 1; //Bit 0 | ||
| FrequencyId = (uint) encoded.Bits( 1, 4); //Bits 1-4 | ||
| var pow2 = (int) encoded.Bits(5, 2); //Bits 5-6 | ||
| NumChannels = 1 << pow2; | ||
| if (NumChannels > 2) | ||
| throw new("> 2 channels not supported"); | ||
|
|
||
| IsStereo = NumChannels == 2; | ||
|
|
||
| DataOffset = encoded.Bits(7, 27) * 32; | ||
| SampleCount = encoded.Bits(34, 30); | ||
| } | ||
| } | ||
| void IBinaryReadable.Read(BinaryReader reader) | ||
| { | ||
| var sampleMode = reader.ReadUInt64(); | ||
|
||
|
|
||
| HasAnyChunks = (sampleMode & 1) == 1; // Bit 0 | ||
| FrequencyId = (uint)sampleMode.Bits(1, 4); // Bits 1-4 | ||
|
|
||
| int channelBits = (int)sampleMode.Bits(5, 2); // Bits 5-6 | ||
| NumChannels = channelBits switch | ||
| { | ||
| 0 => 1, | ||
| 1 => 2, | ||
| 2 => 6, | ||
|
||
| 3 => 8, | ||
| _ => throw new("Number of channels not supported"), | ||
| }; | ||
| IsStereo = NumChannels == 2; | ||
|
|
||
| DataOffset = sampleMode.Bits(7, 27) * 32; | ||
| SampleCount = sampleMode.Bits(34, 30); | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't make formatting changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure