LoginSignup
1
2

More than 3 years have passed since last update.

bluetooth マイク音声aacエンコードするとAudioFormatUnsupportedエラー

Posted at

現象

Airpodsなどのbluetooth micがついてるデバイスで音声データ取得して、aac変換するエンコーダ設定、bitrate設定部分でAudioFormatUnsupportedエラーがでる。

理由

bluetooth micの企画samplerateは8khzか、16khzさかサポートしてなくて、エンコーダ設定部分で高いbitrate設定するとエラーがでる。今回は96kbps設定しようとしてました。

MacのAudio MIDI Setupで確認できる
image.png

解決方法

bitrate設定を小さくする.
16khz以下場合は32kbpsする. ステレオの場合は*1.5で大丈夫。

// audioのsamplebufferから取得
 AudioStreamBasicDescription *srcDesc= CMAudioFormatDescriptionGetStreamBasicDescription((CMAudioFormatDescriptionRef)CMSampleBufferGetFormatDescription(sb));

 int samplerate = srcDesc.mSampleRate;
 int bitrate = 96000;

 // 16khz以下の場合はbitrate小さくする
 if(samplerate <= 16000) {
   bitrate = 32000;
 }
 UInt32 sz = sizeof(bitrate);
 OSStatus r = AudioConverterSetProperty(mConverter, kAudioConverterEncodeBitRate, sz, &bitrate)

参考

image.png

bluetooth audio
https://www.silabs.com/documents/login/presentations/Developing-Bluetooth-Audio.pdf

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2