Answered
0
0

Hello everyone, I want to access to real-time volume when play the sound by fmod in Android,I try to use this method “channel->getVolume(float *volume);”,but access to the value is aways 1.000…As follow:

    float volume;
    ...
    system->update();
while (isplaying) {
    channel->isPlaying(&isplaying);
    channel->getVolume(&volume);
    LOGI("%f", volume);
    usleep(500 * 1000);
}

Log information:
09-15 17:55:46.451: I/lsl(5741): /storage/emulated/0/lsl.mp3
09-15 17:55:46.451: I/lsl(5741): voice====fix
09-15 17:55:46.451: I/lsl(5741): 1.000000
09-15 17:55:46.951: I/lsl(5741): 1.000000
09-15 17:55:47.451: I/lsl(5741): 1.000000
09-15 17:55:47.951: I/lsl(5741): 1.000000
09-15 17:55:48.451: I/lsl(5741): 1.000000
09-15 17:55:48.951: I/lsl(5741): 1.000000
09-15 17:55:49.451: I/lsl(5741): 1.000000

Thank you for your help!!!

  • You must to post comments
Best Answer
0
1

getVolume() will always return the value that was passed to setVolume(), or the default of 1.0.

What you want to do is enable metering and get the RMS.

FMOD::DSP* head;
channel->getDSP(FMOD_CHANNELCONTROL_DSP_HEAD, &head);
head->setMeteringEnabled(false, true);
system->update();

while (isplaying)
{
    FMOD_DSP_METERING_INFO meteringInfo;
    head->getMeteringInfo(nullptr, &meteringInfo);
    if (meteringInfo.numchannels > 0)
    {
        printf("RMS is %.3f\n", meteringInfo.rmslevel[0]);
    }
    system->update();
    channel->isPlaying(&isplaying);
    Sleep(100);
}
  • You must to post comments
0
0

Nicholas Wilcox.Thank you so much,I’m very excited that you can answer my question,I just started to contact FMOD,Think you…I used you method in my code ,as follow:

    DSP* head;
    system->playSound(sound, 0, false, &channel);
channel->getDSP(FMOD_CHANNELCONTROL_DSP_HEAD, &head);
head->setMeteringEnabled(false, true);
system->update();
while (isplaying) {

// channel->getVolume(&volume);
// sound->getMusicChannelVolume(0, &volume);
// LOGI(“%f”, volume);
FMOD_DSP_METERING_INFO meteringInfo;
head->getMeteringInfo(NULL, &meteringInfo);
if(meteringInfo.numchannels > 0){
LOGI(“RMS is %.3f\n”, meteringInfo.rmslevel[0]);
}
system->update();
channel->isPlaying(&isplaying);
usleep(500 * 1000);
}

Log information like this:
09-16 09:58:45.945: I/lsl(10351): RMS is 0.172
09-16 09:58:46.445: I/lsl(10351): RMS is 0.125
09-16 09:58:46.945: I/lsl(10351): RMS is 0.160
09-16 09:58:47.445: I/lsl(10351): RMS is 0.127
09-16 09:58:47.945: I/lsl(10351): RMS is 0.089
09-16 09:58:48.445: I/lsl(10351): RMS is 0.060
09-16 09:58:48.945: I/lsl(10351): RMS is 0.048
Thank a lot.And I saw a method in document,like this:
Sound::getMusicChannelVolume (int channel, float *volume);
Parameters:
channel
MOD/S3M/XM/IT/MIDI music subchannel to retrieve the volume for.
volume
Address of a variable to receive the volume of the channel from 0.0 to 1.0. Default = 1.0.

But I don’t know how to write the first parameter…

  • Nicholas Wilcox

    getMusicChannelVolume() is the equivalent of Channel::getVolume() but for the sub-channels of tracker formats. It just returns the number set with setMusicChannelVolume(). To know the number of sub-channels you would use Sound::getMusicNumChannels().

  • You must to post comments
0
0

Nicholas Wilcox ,Thank you for your answer, later still hope your advice…

  • You must to post comments
Showing 3 results
Your Answer

Please first to submit.