私はOSX10.8を使用しています
私のアプリケーションでは、マイクゲインを変更する必要がありました。オーディオキューを使用してバッファーをキャプチャしていますが、マイクゲインを変更するためのポインターを取得していません。
Apple HALのドキュメントもありますが、何も得られませんでした。
私はOSX10.8を使用しています
私のアプリケーションでは、マイクゲインを変更する必要がありました。オーディオキューを使用してバッファーをキャプチャしていますが、マイクゲインを変更するためのポインターを取得していません。
Apple HALのドキュメントもありますが、何も得られませんでした。
kAudioQueueProperty_CurrentDevice
まず、キューに、読み取り元のデバイスの識別子文字列である、を要求します。
次に、そのデバイスを開く必要があります。Core Audioの設計者は、一般的な「GetProperty」および「SetProperty」関数を介してすべての近くで気を悪くすることを信じているため、これは本来あるべき作業よりも多くの作業です。ここに行きます:
AudioValueTranslation
デバイス識別子を含む変数へのポインターと、必要な変数へのポインターを含む構造を作成しますAudioDeviceID
。AudioHardwareGetProperty
か、非推奨ではありませんが、より一般的AudioObjectGetProperty
に取得kAudioHardwarePropertyDeviceForUID
して、構造体へのポインターを渡します。HALはデバイスを検索し、構造体に配置したポインターを介してデバイスを返します。それでもエラーが返されない場合は、デバイスがあります。
最後のステップは、ゲインを設定することです。これは入力スコープに現れていると思いますが、100%確実ではありません。kAudioDevicePropertyVolumeScalar
とにかく、あなたは正しい組み合わせを見つけるまで、AudioDeviceSetProperty
そして/またはあなたがいじくり回しているでしょう。AudioObjectSetProperty
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リソースを節約してください。