Skip to content

Conversation

@Masusder
Copy link

Number of channels was being read and then written incorrectly into packet info (for e.x. 4 instead of 6), resulting in malformed audio output. This fixes Vorbis rebuilder.

I can't tell about other formats though as I don't have any to test nor do I need them. I would appreciate if this could be merged as I need it in a different project. In case this breaks other formats somehow I would suggest to only skip samples with >2 channels in these cases instead of throwing completely

Comment on lines 7 to 12
public class FmodSampleMetadata : IBinaryReadable
{
internal bool HasAnyChunks;
internal uint FrequencyId;
internal ulong DataOffset;
internal List<FmodSampleChunk> Chunks = new();
Copy link
Contributor

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

{
0 => 1,
1 => 2,
2 => 6,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why isn't this 4?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be 6, that's the whole point

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any FMOD documentation about this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there is any, all I can give you is an example of converted audio:
4 channels
vs
6 channels

Tested on soundbanks from three different games

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From FMOD::CodecFSB5::decodeSubSoundHeader:

18001644e        if (channels != 0)
180016462            int128_t __xmm@00000008000000060000000200000001_1 =
180016462                __xmm@00000008000000060000000200000001
18001646c            *channels = *(&__xmm@00000008000000060000000200000001_1
18001646c                + ((zx.q((r10 u>> 5).d) & 3) << 2))

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From FMOD::CodecFSB5::decodeSubSoundHeader:

18001644e        if (channels != 0)
180016462            int128_t __xmm@00000008000000060000000200000001_1 =
180016462                __xmm@00000008000000060000000200000001
18001646c            *channels = *(&__xmm@00000008000000060000000200000001_1
18001646c                + ((zx.q((r10 u>> 5).d) & 3) << 2))

@ds5678 and after looking at this it appears that frequencies table was also incorrect, so I also changed it
Correct one should match to this:

180016472        if (frequency != 0)
180016493            __builtin_memcpy(dest: &var_58, 
180016493                src: "\xa0\x0f\x00\x00\x40\x1f\x00\x00\xf8\x2a\x00\x00\xe0\x2e\x00\x00\x80\x3e"
180016493            "00\x00\x22\x56\x00\x00\xc0\x5d\x00\x00\x00\x7d\x00\x00\x44\xac\x00\x00\x80\xbb"
180016493            "00\x00\x00\x77\x01\x00", 
180016493                count: 0x2c)
1800164b2            *frequency = *(&var_58 + ((zx.q((r10 u>> 1).d) & 0xf) << 2))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From FMOD::CodecFSB5::decodeSubSoundHeader

Please document in the code that the behavior can be verified by disassembling this function.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

}
void IBinaryReadable.Read(BinaryReader reader)
{
var sampleMode = reader.ReadUInt64();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the name change?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to clarify what it represents. I’ve reverted it back to how it was if that’s an issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants