Microphone Input Playback (STUDIO API)

I got my microphone input working fine in my custom engine. I am getting all the levels, dominant frequency data i need from the microphone. The issue is i’m still hearing microphone playback. I tried muting the channel. If i do that i end up getting absolutely no data. Any solution to this?

I am using getMeteringInfo for the peak values.

Is it possible to have the metering set to Pre Fader? Because I think it is post fader at the moment. But at the same time I would want to monitor the signal after applying a microphone filter that filters out all the frequencies outside the (20-150Hz) range.

You can get metering pre fader.

channel->setMute(true);
FMOD::DSP* fader;
channel->getDSP(FMOD_CHANNELCONTROL_DSP_FADER, &fader);
fader->setMeteringEnabled(true, true);

while(channelPlaying)
{
    FMOD_DSP_METERING_INFO preFaderMeter, postFaderMeter;
    fader->getMeteringInfo(&preFaderMeter, &postFaderMeter);
    // postFaderMeter will have zero power, preFaderMeter will contain signal power
}

That’s a demonstration only. In real code if you know the channel is muted there is not point checking the output meter:

fader->setMeteringEnabled(true, false); // input meter only
fader->getMeteringInfo(&preFaderMeter, NULL);

This is what I’m doing. And I was already following the stuff you asked me to. But input.peaklevel[0] gives me 0 when mute I the micChannel and gives me proper values when I unmute it. Here is my code:

      void AudioSystem::UpdateMicData()
      {
        FMOD_RESULT result;
        
        result = pFMODAudioSystem->getRecordPosition(0, &_recordpos);
        ErrCheck(result);
    
        // STUFF
    
        if (_samplesrecorded >= _adjustedlatency && !micChannel)
        {
          result = pFMODAudioSystem->playSound(micSound, 0, false, &micChannel);
          ErrCheck(result);
        }
        
        if (micChannel && _recorddelta)
        {
          // MORE STUFF
       
          result = micChannel->getPosition(&_playpos, FMOD_TIMEUNIT_PCM);
          ErrCheck(result);
    
          // EVEN MORE STUFF
    
          if (_check == true)
          {
            //micChannel->setMute(true); // GIVES ZERO IF UNCOMMENTED
            micFilter(100.0f, 1.0f); // Apply microphone filter
            micMeter();  // Get the RMS peaks from the mic       
    
            _check = false;        
          }      
    
          meter->getMeteringInfo(&input, 0);
    
          // FOR TESTING
          meterConsoleOut();
        }   
      }
    
      void AudioSystem::micMeter()
      {
        FMOD_RESULT result;
    
        result = micChannel->getDSP(FMOD_CHANNELCONTROL_DSP_HEAD, &meter);
        ErrCheck(result);
    
        // Starts metering the input values
        result = meter->setMeteringEnabled(true, false);
        ErrCheck(result);
      }
    
      void AudioSystem::micFilter(float cutoff, float resonance)
      {
        FMOD_RESULT result;
        bool active;
        
        result = pFMODAudioSystem->createDSPByType(FMOD_DSP_TYPE_LOWPASS, &filter);
        ErrCheck(result);
       
        result = filter->setParameterFloat(FMOD_DSP_LOWPASS_CUTOFF, cutoff);
        ErrCheck(result);
    
        result = filter->setParameterFloat(FMOD_DSP_LOWPASS_RESONANCE, resonance);
        ErrCheck(result);
    
        result = filter->getActive(&active);
        ErrCheck(result);
    
        if (active)
        {
          result = micChannel->removeDSP(filter);
          ErrCheck(result);
        }
        else
        {
          result = micChannel->addDSP(0, filter, 0);
          ErrCheck(result);
        }  
      }

At the moment your effect chain is [Lowpass <- Fader <- Source] and you’re metering the head which will the lowpass, and the signal will already be muted by the fader.

You want [Fader <- Lowpass <- Source]

Change

micChannel->addDSP(0, filter, 0);

to

micChannel->addDSP(FMOD_CHANNELCONTROL_DSP_TAIL, filter, 0);
2 Likes

Thanks a lot Nicholas for helping me out with this! This solved so many problems I had in mind.