Skip to content
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

Add channel mapping support #305

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

dodeca-6-tope
Copy link

@dodeca-6-tope dodeca-6-tope commented Mar 14, 2024

Map channels to their respective speakers for supported audio formats. This change solves an issue where receivers can't determine how to map channels for multi channel audio files.

@dodeca-6-tope
Copy link
Author

dodeca-6-tope commented Mar 14, 2024

@psobot a more flexible approach would be to take an optional layout and fallback to the changes I introduced here if not provided. Notice that channel count -> layout is a one-to-many relationship.

@psobot
Copy link
Member

psobot commented Mar 19, 2024

Thanks @dodeca-6-tope! This looks great - is there a plugin I can test this with before merging?

@dodeca-6-tope
Copy link
Author

@psobot not that I know of, but you can verify this change by writing and playing a multichannel track on your receiver if you have one lying around. Audacity also fills up the channels with the correct signals unlike before. The first thing I did is to look for a visualizer but I haven't found any.

@psobot
Copy link
Member

psobot commented Mar 19, 2024

Whoops, my apologies - I misread this as applying to VST3Plugin rather than AudioFile. This is much easier to test if it's just a metadata change in the output files. 👍🏻

@psobot
Copy link
Member

psobot commented Mar 19, 2024

After digging a bit deeper, I'm not sure this will actually change anything when writing audio files. From what I can tell, only the WavAudioFormat writer behaves differently when provided an AudioChannelSet - and it already calls canonicalWavChannelSet in its constructor:

    return createWriterFor (out, sampleRate, WavFileHelpers::canonicalWavChannelSet (static_cast<int> (numChannels)),
                            bitsPerSample, metadataValues, qualityOptionIndex);

...which does the same thing as namedChannelSet:

    inline AudioChannelSet canonicalWavChannelSet (int numChannels)
    {
        if (numChannels == 1)  return AudioChannelSet::mono();
        if (numChannels == 2)  return AudioChannelSet::stereo();
        if (numChannels == 3)  return AudioChannelSet::createLCR();
        if (numChannels == 4)  return AudioChannelSet::quadraphonic();
        if (numChannels == 5)  return AudioChannelSet::create5point0();
        if (numChannels == 6)  return AudioChannelSet::create5point1();
        if (numChannels == 7)  return AudioChannelSet::create7point0SDDS();
        if (numChannels == 8)  return AudioChannelSet::create7point1SDDS();

        return AudioChannelSet::discreteChannels (numChannels);
    }

Have you tested this change locally? All of my tests with different channel counts and audio formats seem to produce identical files before and after this change (except for Ogg Vorbis, for which the encoding process is not 100% deterministic).

@dodeca-6-tope
Copy link
Author

Tested on a receiver that initially mapped a down-mixed version (to mono) of the file to all channels equally and after this change it mapped as expected.

@dodeca-6-tope
Copy link
Author

Might be an issue with the receiver, will try again tomorrow with another device.

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.

None yet

2 participants