2013-02-27 66 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