Source code question of libopenmpt

Started by bass, January 13, 2025, 18:45:04

Previous topic - Next topic

bass

Hi, I have a general question about the source code of the library:
For example, in Fastmix.cpp in the method "CreateStereoMix(int count)" there is the following code to use a channel for mixing:

    for(uint32 nChn = 0; nChn < m_nMixChannels; nChn++)
    {
        ModChannel &chn = m_PlayState.Chn[m_PlayState.ChnMix[nChn]];
                ...

How are these channels organized? I've read that the real channels are never used for NNA actions (or volume ramping/note cut actions). If I have a MOD file with 4 Channels and m_nMixChannels is 5, the last one in this case must be an NNA channel and have a MasterChannel value > 0, right?
Can I get the master channel this way:
ModChannel &masterChn = m_PlayState.Chn[chn.nMasterChn - 1];

But how do I know which real channel chn belongs to if it has MasterChannel = 0?

I would like to understand how these channels are organized. When calling the read method of the library, are the first 4 values of this array always used as master channels? And is everything after these first 4 values in the array are NNA channels? Or is there some sort of rotation of channels?

When I call "get_current_channel_vu_mono( std::int32_t channel )" the return value is something like this:
m_sndFile->m_PlayState.Chn[channel].nLeftVU ...

So I would think, that the master channels are always the first values in the array and that NNA-channels are always copied from the master channels. So, a fadeout of a note (for declicking) would be processed in a NNA-channel (i.e. channel 5), right?
Or are there other strategies?
Thanks a lot!

Saga Musix

The first ChnSettings.size() (= GetNumChannels()) entries in the m_PlayState.Chn array are indeed always pattern channels, and as a consequence their nMasterChn is always 0 (channels never point at themselves). If an active NNA channel has nMasterChn == 0, that means that the channel was triggered interactively (through the interactive interface of libopenmpt, or by playing notes in the sample / instrument editor in the case of OpenMPT), so the space in the Chn array past the pattern channels is shared between interactive and NNA channels. Everything else you figured out is also correct.
» No support, bug reports, feature requests via private messages - they will not be answered. Use the forums and the issue tracker so that everyone can benefit from your post.

bass

Thanks for the answer, Saga Musix!!
I have checked and resolved this ticket here
https://bugs.openmpt.org/view.php?id=1042
FOR MY NEEDS and can now display the sample data for each channel for my player which works very good. However, my implementation does not take plugins or VST instruments into account as these things are calculated directly over the entire buffer as I have seen it.. But for most normal players, this should be fine, I think.
I don´t know, if anyone is interested...

I just wasn´t sure for related NNA-channels whether I can add their sample data together to their master channel buffer and divide the final result by the number of nna channels + master channel or if the volumes for NNA-channels are already adjusted by internal calculations in some way.

Saga Musix

You never divide by the number of active channels. If you did that, the volume (or in your case, the displayed waveform) would wildly fluctuate just because a channel is turning on or off. You just add all channels up, that's what the mixer does.
» No support, bug reports, feature requests via private messages - they will not be answered. Use the forums and the issue tracker so that everyone can benefit from your post.

bass

Yes, I know, but I never worked with Impulse Tracker. I was not sure, if I would get clipping/overflow in some cases when adding all data (nna and pattern data) of a channel together.

Saga Musix

That's essentially why you have so many different volume settings like global volume and sample pre-amp - if the samples are too loud, you would lower the pre-amp to prevent clipping while composing the track.
» No support, bug reports, feature requests via private messages - they will not be answered. Use the forums and the issue tracker so that everyone can benefit from your post.