2013-02-27 64 views
0

我在OSX 10.8更改话筒增益编程在OSX

在我的应用我不得不改变麦克风增益,我使用AudioQueue捕捉缓冲区,但没有得到任何指针改变麦克风增益,

苹果HAL文件还可以,但没有得到任何东西,

回答

0

看来,改变音量增益是不可能在飞行时AudioQueue运行,一些如何能够增加麦克风增益缓冲器,张贴代码,

void AQRecorder::setGain(void *data, int bytes, float gain){ 
    SInt16 *editBuffer = (SInt16 *)data; 

    // loop over every packet 

    for (int nb = 0; nb < (bytes/2); nb++) { 

     // we check if the gain has been modified to save resoures 
     if (gain != 0) { 
      // we need more accuracy in our calculation so we calculate with doubles 
      double gainSample = ((double)editBuffer[nb])/32767.0; 

      /* 
      at this point we multiply with our gain factor 
      we dont make a addition to prevent generation of sound where no sound is. 

      no noise 
      0*10=0 

      noise if zero 
      0+10=10 
      */ 
      gainSample *= gain; 

      /** 
      our signal range cant be higher or lesser -1.0/1.0 
      we prevent that the signal got outside our range 
      */ 
      gainSample = (gainSample < -1.0) ? -1.0 : (gainSample > 1.0) ? 1.0 : gainSample; 

      /* 
      This thing here is a little helper to shape our incoming wave. 
      The sound gets pretty warm and better and the noise is reduced a lot. 
      Feel free to outcomment this line and here again. 

      You can see here what happens here http://silentmatt.com/javascript-function-plotter/ 
      Copy this to the command line and hit enter: plot y=(1.5*x)-0.5*x*x*x 
      */ 

      gainSample = (1.5 * gainSample) - 0.5 * gainSample * gainSample * gainSample; 

      // multiply the new signal back to short 
      gainSample = gainSample * 32767.0; 

      // write calculate sample back to the buffer 
      editBuffer[nb] = (SInt16)gainSample; 
     } 
    } 
} 

记住此功能只应叫当有一个增益变化,否则保存CPU资源..

0

首先,问你的队列其kAudioQueueProperty_CurrentDevice,这是它的读取设备的标识字符串。

接下来,您需要打开该设备。这是比它应该做的更多的工作,因为Core Audio的设计人员通过通用的“GetProperty”和“SetProperty”功能相信所有事情都做得很好。这里所说:

  1. 创建包含一个指向包含设备标识符和一个指向您希望AudioDeviceID变量的变量的AudioValueTranslation结构。
  2. 使用AudioHardwareGetProperty或未被弃用,但更通用的AudioObjectGetProperty得到kAudioHardwarePropertyDeviceForUID,将指针传递给结构。 HAL将查找设备,并通过放置在结构中的指针将其返回给您。

如果这没有返回错误,您现在有一个设备。

最后一步是设置其增益。我认为这是显示为kAudioDevicePropertyVolumeScalar上的输入范围,但我不是100%确定。无论如何,你会修补AudioDeviceSetProperty和/或AudioObjectSetProperty,直到找到合适的组合。

+0

,非常感谢,我会试一试 – Amitg2k12 2013-02-28 03:47:54

+0

我试过了,但我不能AudioObjectHasProperty总是返回麦克风错误,此外,我需要做它当AudioQueue运行:(,有一些解决方法张贴在这里... – Amitg2k12 2013-03-01 03:09:41