iOS bluetooth / 16 kHz sample rate

672 views
Skip to first unread message

Eric

unread,
Oct 7, 2015, 2:51:01 AM10/7/15
to discuss-webrtc
I’m testing the overhaul of iOS device layer committed on Sept 7, 2015 - 86d907c And I’m seeing problems when using a bluetooth headset that has a 16 kHz sample rate.

In ActivateAudioSession(AVAudioSession* session, bool activate) the request to setPreferredSampleRate:kPreferredSampleRate == 48 kHz returns success, but ultimately Audio Unit returns recorded samples at 16 kHz sample rate. I don’t see any code to handle what happens if the AVAudioSession ignores the request for a 48 kHz sample rate. What I’m seeing is that AudioDeviceIOS::RecordedDataIsAvailable is called every 10.6667 msec with a varying number of frames due to the fact that 10.6667 msec @ 16 kHz is 170 2/3 samples. So there is a pattern where AudioDeviceIOS::RecordedDataIsAvailable receives 171 samples two times, then 170 samples… repeat. I commented out CHECK_EQ(size_in_bytes, desired_frame_size_bytes_) in FineAudioBuffer::DeliverRecordedData to see what the incoming samples looked like.

Any suggestions on best way to fix this? I need to use these recent changes to fix distorted loudspeaker playback on iPhone 6S/6S+, but then I’ll lose bluetooth headset support (or whatever aux input runs @ 16 kHz).


Some extra logging I added:
-------------------------------------------------------------------------
Internal speaker/mic on iPhone 6S is fine:

(audio_device_ios.mm:760): OnRecordedDataIsAvailable: [*] AudioUnitRender OK :   0[ deltaT = 10.667, dataSizeInBytes = 1024, busNum = 1 , frames = 512, flags = 0x16f2aeaf4]

(audio_device_ios.mm:760): OnRecordedDataIsAvailable: [*] AudioUnitRender OK :   0[ deltaT = 10.667, dataSizeInBytes = 1024, busNum = 1 , frames = 512, flags = 0x16f2aeaf4]

(audio_device_ios.mm:760): OnRecordedDataIsAvailable: [*] AudioUnitRender OK :   0[ deltaT = 10.667, dataSizeInBytes = 1024, busNum = 1 , frames = 512, flags = 0x16f2aeaf4]

(audio_device_ios.mm:760): OnRecordedDataIsAvailable: [*] AudioUnitRender OK :   0[ deltaT = 10.667, dataSizeInBytes = 1024, busNum = 1 , frames = 512, flags = 0x16f2aeaf4]

(audio_device_ios.mm:760): OnRecordedDataIsAvailable: [*] AudioUnitRender OK :   0[ deltaT = 10.667, dataSizeInBytes = 1024, busNum = 1 , frames = 512, flags = 0x16f2aeaf4]

...


Bluetooth headset on iPhone 6S:


(audio_device_ios.mm:760): OnRecordedDataIsAvailable: [*] AudioUnitRender OK :   0[ deltaT = 10.667, dataSizeInBytes = 340, busNum = 1 , frames = 170, flags = 0x16f446af4]

(audio_device_ios.mm:757): OnRecordedDataIsAvailable: [*] AudioUnitRender ERR: -50[ deltaT = 10.667, dataSizeInBytes = 340, busNum = 1 , frames = 171, flags = 0x16f446af4]

(audio_device_ios.mm:757): OnRecordedDataIsAvailable: [*] AudioUnitRender ERR: -50[ deltaT = 10.667, dataSizeInBytes = 340, busNum = 1 , frames = 171, flags = 0x16f446af4]

(audio_device_ios.mm:760): OnRecordedDataIsAvailable: [*] AudioUnitRender OK :   0[ deltaT = 10.667, dataSizeInBytes = 340, busNum = 1 , frames = 170, flags = 0x16f446af4]

(audio_device_ios.mm:757): OnRecordedDataIsAvailable: [*] AudioUnitRender ERR: -50[ deltaT = 10.667, dataSizeInBytes = 340, busNum = 1 , frames = 171, flags = 0x16f446af4]

(audio_device_ios.mm:757): OnRecordedDataIsAvailable: [*] AudioUnitRender ERR: -50[ deltaT = 10.667, dataSizeInBytes = 340, busNum = 1 , frames = 171, flags = 0x16f446af4]

(audio_device_ios.mm:760): OnRecordedDataIsAvailable: [*] AudioUnitRender OK :   0[ deltaT = 10.667, dataSizeInBytes = 340, busNum = 1 , frames = 170, flags = 0x16f446af4]

Henrik Andreasson

unread,
Oct 7, 2015, 5:59:15 AM10/7/15
to discuss...@googlegroups.com
Thanks for the detailed feedback. Please file an issue in the WebRTC issue tracker with all details required to reproduce locally.
To cover all BT devices can be tricky since they behave very differently. We might need the exact model to resolve this issue.

Based on your input, I am guessing that you see this warning:

LOG(LS_WARNING) << "Failed to enable an audio session with the preferred sample rate!";

and if that is the case, I would say that there is something that is not OK with this BT headset but I can't go into the details here.
We have verified that audio is fine using some Plantronics BT headsets, hence the latest version does not "break BT support".
Let's take the details in the issue once filed.

--

---
You received this message because you are subscribed to the Google Groups "discuss-webrtc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to discuss-webrt...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/discuss-webrtc/9d39a065-b4d3-4487-9713-f2c936d96abb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Eric

unread,
Oct 7, 2015, 6:25:39 PM10/7/15
to discuss-webrtc

Thanks for the detailed feedback. Please file an issue in the WebRTC issue tracker with all details required to reproduce locally.
To cover all BT devices can be tricky since they behave very differently. We might need the exact model to resolve this issue.

Filed here: 5058
 
I originally tested with a "yurbuds" headset. This morning I purchased two Plantronics headsets: M70 (inexpensive) and the "MARQUE 2" / "M165" (mid-level). I see the same issue with all 3 headsets.

Based on your input, I am guessing that you see this warning:

LOG(LS_WARNING) << "Failed to enable an audio session with the preferred sample rate!";

Correct, I see that. The log shows that immediately after activating the audio session, the sampleRate is 16 kHz (presumably because of the bluetooth headset being active in iOS). However when I check the AVAudioSession sampleRate in AudioDeviceIOS::OnRecordedDataIsAvailable() when AudioUnitRender() returns success, then I see a sampleRate of 48 kHz. But - the size of the recorded mic data and the timing of when AudioDeviceIOS::OnRecordedDataIsAvailable() is called, is consistent with a 16 kHz sample rate.
Reply all
Reply to author
Forward
0 new messages