I’m trying to get the microphone to record sounds played by the built in music player or other background apps like Spotify. I add:
[code:16xobby2] FMOD_IPHONE_EXTRADRIVERDATA extradriverdata;
memset(&extradriverdata, 0, sizeof(FMOD_IPHONE_EXTRADRIVERDATA));
extradriverdata.sessionCategory = FMOD_IPHONE_SESSIONCATEGORY_PLAYANDRECORD;
extradriverdata.forceMixWithOthers = true;
extradriverdata.forceSpeakerOutput = true;
result = system->init(32, FMOD_INIT_NORMAL | FMOD_INIT_ENABLE_PROFILE, &extradriverdata);[/code:16xobby2]
to the pitchdetection sample to test this on an iPhone4S and the background sound halts on app loading.
If I run this same code on an iPad3, the background sound continues and the app grabs the pitch as expected. ie All is OK on iPad.
So I switch
[code:16xobby2]extradriverdata.forceSpeakerOutput = !true;[/code:16xobby2]
on the iPhone and run again. This time the background sound is NOT interrupted, but it is diverted to the mini receiver speaker, which is not what I want.
Looks suspiciously like an FMOD bug to me. Or am I missing something?
[edit: some info from further testing. iPhone recording of background sound works OK if 4S is connected via HDMI]
FMOD version 4.42.06, XCode 4.5.1, Base SDK iOS 6
- david.de.candia asked 4 years ago
It sounds to me like an iOS bug, most likely device / version specific.
I have tested your code here with an iPhone 3GS with iOS 6.0 and it works as expected (i.e. it records the background music).
As a test I have modified one of the standard iOS examples to route to the main speaker and mix with the iPod while recording. I’ll e-mail you the test, I expect it will behave the same as FMOD in which case it is an iOS bug.
Thanks Matthew. Yes, your AurioTouch sample also stops the sound played by background apps like Spotify and Naturespace on opening on the 4S (but not if connected to HDMI). I’m guessing that if you try either of those apps on the 3gs you will see the same.
I’ve been unable to come up with a fix (although I know it is possible as I’ve seen other apps do it) but at least I have a workaround now.
Double clicking the home button, swiping to the music player controls, pressing play and then resuming the recording app works. Clumsy but at least it is something.
I also had to implement a kAudioSessionProperty_AudioRouteChange listener to handle switches between HMDI and AirTunes whilst recording. HDMI likes a frequency of 48000 and AirTunes 44100. Feel weird about hard coding these values. Is it possible to poll the output device for desired frequency I wonder?
>Is it possible to poll the output device for desired frequency I wonder?
A belated answer to my own question:
Float64 sampleRate = 44100;
UInt32 size = sizeof(sampleRate);
ThrowOnError(AudioSessionGetProperty(kAudioSessionProperty_CurrentHardwareSampleRate, &size, &sampleRate), "kAudioSessionProperty_CurrentHardwareSampleRate FAILED");
Please login first to submit.