Reputation: 1
I have some problems with my Open Al recording on different iOS.
Using self unexplained hacks i did fix all problems, but remained trouble with iOS 8 on iPad air. On the other device(on which i was able to check) with the iOS 5-8 everything works alright.
So, that part of my code:
//hack for iOS 7-8, otherwise program crashes on alcCaptureOpenDevice
if([[UIDevice currentDevice].systemVersion floatValue] >= 7.0f)
alcMakeContextCurrent(nil);
controller->captureDevice = alcCaptureOpenDevice(nil, args->rate, args->format, args->rate * resolution * tracks);
if(controller->captureDevice)
{
//i am trying something like this, but no effect
if([[UIDevice currentDevice].systemVersion floatValue] >= 7.0f)
{
controller->captureContext = alcCreateContext(controller->captureDevice, NULL);
alcMakeContextCurrent(controller->captureContext);
}
if(args->time < 0 || args->time > MAX_RECORDING_TIME)
args->time = MAX_RECORDING_TIME;
//allocate memory for buffers
ALbyte* dataBuffer = new ALbyte[(int)(args->rate * resolution * tracks * ceil(args->time + 1))];
ALbyte* tempBuffer = new ALbyte[(int)(args->rate * resolution * tracks * ceil(args->time + 1))];
ALint dataSamples = 0;
ALint tempSamples = 0;
NSTimeInterval startTime = [[NSDate date] timeIntervalSince1970];
alcCaptureStart(controller->captureDevice);
//cycle of recording
while(controller->recognition)
{
//timing
NSTimeInterval curTime = [[NSDate date] timeIntervalSince1970];
if(curTime - startTime >= args->time)
break;
//check how much audio data has been captured
alcGetIntegerv(controller->captureDevice, ALC_CAPTURE_SAMPLES, resolution * tracks, &tempSamples);
//read the captured audio
alcCaptureSamples(controller->captureDevice, tempBuffer, tempSamples);
//copying from the temporary buffer into the data buffer
int i = 0, j = 0;
for(i = dataSamples * resolution * tracks; i < (dataSamples + tempSamples) * resolution * tracks; i++, j++)
dataBuffer[i] = tempBuffer[j];
dataSamples += tempSamples;
if(!tempSamples)
continue;
//.. using captured data
}
alcCaptureStop(controller->captureDevice);
alcCaptureCloseDevice(controller->captureDevice);
//hack for iOS 7-8, for we will may again play sounds
if([[UIDevice currentDevice].systemVersion floatValue] >= 7.0f)
{
alcDestroyContext(controller->captureContext);
alcMakeContextCurrent(controller->playbackContext);
}
}
So on iPad air in recording cycle we are not capture samples. After alcGetIntegerv and alcCaptureSamples we have empty buffer and zero in counter samples. This happens on first start recording. On the second attempt we have captured samples in a counter, but buffer anyway remains empty.
I think i have problem with access to the microphone. iOS does not show microphone permission window. I tried alcIsExtensionPresent, but he returned true.
I do not know what to do. I hope for your help.
And sorry for my bad english.
Upvotes: 0
Views: 294
Reputation: 1
I found the time for answer to myself question. Everything that I needed - is to use an audio session. Something like this:
//when playback
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategorySoloAmbient error:&error];
and
//when recording
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:&error];
And now do not need any unexplained hacks.
Upvotes: 0