So I’m trying to get the volume of a sound using getMeteringInfo, and am just getting no data. I’ve been following this example: http://52.88.2.202/questions/question/microphone-input-playback
but have not actuall been able to get any information back (i.e. it’s all zeros). Here’s my code:
When the sound is created:
//eventually, I'm going to be recording a sound, but I'm trying to get it working first on
//just a normal sine wave that I know the expected value for
memset(&m_exinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));
m_exinfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
m_exinfo.numchannels = m_fmodrecordchannels;
m_exinfo.format = FMOD_SOUND_FORMAT_PCM16;
m_exinfo.defaultfrequency = m_fmodrecordrate;
m_exinfo.length = m_exinfo.defaultfrequency * sizeof(short) * m_exinfo.numchannels\
* .7;
result = m_fmodSystem->createSound( "400Hz.wav", FMOD_LOOP_NORMAL | FMOD_DEFAULT, &m_exinfo,\
&m_sound);
ERRCHECK( result);
result = m_fmodSystem->playSound(m_sound, 0, false, &m_channel);
ERRCHECK( result );
result = m_channel->getDSP(FMOD_CHANNELCONTROL_DSP_FADER, &m_loudnessdsp);
ERRCHECK( result );
result = m_loudnessdsp->setMeteringEnabled( true, true );
ERRCHECK( result );
then, called repeatedly (whenever the screen is re-rendered):
FMOD_DSP_METERING_INFO preMeter, postMeter;
result = m_loudnessdsp->getMeteringInfo( &preMeter, &postMeter );
ERRCHECK( result );
float avgVol = 0;
debugPrintf( "short: %hu\n", preMeter.numchannels );
debugPrintf( "numberofsamples: %d\n", preMeter.numsamples );
for( int i = 0; i < preMeter.numchannels; ++i ) {
avgVol += preMeter.rmslevel[i];
debugPrintf( "rms: %f\n", preMeter.rmslevel[i] );
debugPrintf( "peak: %f\n", preMeter.peaklevel[i] );
}
avgVol = avgVol/preMeter.numchannels;
m_curr_vol = avgVol;
When I do this, all of the values are zero. I’ve checked and m_sound is the sound that is playing (it is - I can hear it) and it is the sound that is playing in m_channel. The only other DSP on there is an FFT which shouldn’t be affecting the track at all, just getting the dominant frequency from it. This also doesn’t work if I actually record a sound rather than trying to load it from a file (using recordStart and not looping). Anyone have any ideas as to why no information is being returned?