0
0

I want to setup volume for some channels individualy, based on some value in Channel::getUserData.

But naive approach like

[code:6r72zya1]
[PSEUDOCODE! Cannot be compiled!]

FMOD::ChannelGroup *playing_channels = m_fmod_system->getMasterChannelGroup();
num_channels = playing_channels->getNumChannels();
for (int i = 0; i < num_channels; ++i)
{
FMOD::Channel *channel= playing_channels->getChannel(i);
float volume = channel->getUserData();
channeld->setVolume(volume);
}
[/code:6r72zya1]
failed.

getUserData() fail with FMOD_ERR_INVALID_HANDLE
num_channels is 1000 (which was passed to System::init), while I’m playing only one sound.

How should I iterate over playing channels? (ChannelGroup::override* does not fit me, becouse all channels are processed individually).

excerpt from real code:

[code:6r72zya1]
static FMOD::ChannelGroup *GetMasterChannelGroup(FMOD::System *fmod_system)
{
FMOD::ChannelGroup *all_playing_channels;
FMOD_RESULT fmod_res = fmod_system->getMasterChannelGroup(&all_playing_channels);
if (FMOD_OK != fmod_res)
return 0;
return all_playing_channels;
}

if (FMOD::ChannelGroup *all_playing_channels = GetMasterChannelGroup(m_fmod_system))
{
    int num_channels;
    FMOD_RESULT fmod_res = all_playing_channels-&gt;getNumChannels(&amp;num_channels);
    assert(fmod_res == FMOD_OK);
    if (fmod_res == FMOD_OK)
    {
        for (int i = 0; i &lt; num_channels; ++i)
        {
            FMOD::Channel *channel = NULL;
            fmod_res = all_playing_channels-&gt;getChannel(i, &amp;channel);
            assert(fmod_res == FMOD_OK &amp;&amp; channel);
            if (fmod_res == FMOD_OK &amp;&amp; channel)
            {
                if ( condition_based_on_getUserData )  &lt;-  error here, during FMOD::Channel::getUserData call
                {
                    fmod_res = channel-&gt;setVolume( value_based_on_getUserData );
                    assert(fmod_res == FMOD_OK);
                }
            }
        }
    }
}

static TMySound *GetOwnerSound(FMOD::Channel *channel)
{
    void *result_v;
    FMOD_RESULT res = channel-&gt;getUserData(&amp;result_v);
    assert(res == FMOD_OK); (void)res;    &lt;-   fail here.
    assert(result_v != NULL);
    return static_cast&lt;TMySound*&gt;(result_v);
}

[/code:6r72zya1]

  • You must to post comments
0
0

I print all chanells during this for-loop over getMasterChannelGroup,
And I print channel, wich I created playSound

I did not found that channel. Why?

[code:14x2vast]
FMOD_RESULT fmod_res = fmod_system->playSound(FMOD_CHANNEL_FREE, m_sound, false, &channel);
assert(fmod_res == FMOD_OK);

    LOG_DEBUG(&quot;creating sound channel: %p&quot;, channel);
    { //HACK!
        FMOD::ChannelGroup *all_playing_channels; 
        FMOD_RESULT fmod_res = fmod_system-&gt;getMasterChannelGroup(&amp;all_playing_channels);
        assert(fmod_res == FMOD_OK);

        int num_channels;
        fmod_res = all_playing_channels-&gt;getNumChannels(&amp;num_channels);
        assert(fmod_res == FMOD_OK);

        LOG_DEBUG(&quot;master group channels num: %d&quot;, num_channels);
        for (int i = 0; i &lt; num_channels; ++i)
        {
            FMOD::Channel *channel = NULL;
            fmod_res = all_playing_channels-&gt;getChannel(i, &amp;channel);
            LOG_DEBUG(&quot;%p &quot;, channel);
        }
    }

[/code:14x2vast]

[code:14x2vast]
creating sound channel: 10180002
master group channels num: 25
0128B428
0128B2EC
0128B1B0
0128B074
0128AF38
0128ADFC
0128ACC0
0128AB84
0128AA48
0128A90C
0128A7D0
0128A694
0128A558
0128A41C
0128A2E0
0128A1A4
0128A068
01289F2C
01289DF0
01289CB4
01289B78
01289A3C
01289900
012897C4
01289688
[/code:14x2vast]

  • You must to post comments
0
0

I have used System::getChannel instead getMasterChannelGroup()->Channel::getChannel, and it works.

What difference between channels in tMasterChannelGroup and System::getChannel ?

  • You must to post comments
0
0

Hi,
Thanks for that, it looks like ChannelGroup::getChannel was incorrectly returning the raw channel pointer instead of a reference counted handle which is what all of the channel commands expect. I’ve fixed this for the next release.

  • You must to post comments
0
0

I’ll be highly suspicious of that

float volume = channel->getUserData();

Storing volume as userData() has a pitfall – e.g. you can’t store the VALUE 0 (0.0f) in a userData(). If you do, then FMOD treats it as if you didn’t have userdata.

I went into the same trap, by trying to use it to store local channel numbering (from 0..255) and it was not storing that information for channel index 0.

  • You must to post comments
Showing 4 results
Your Answer

Please first to submit.