我有一些问题,我的开放铝录音在不同的iOS。
使用自我解释的黑客,我确实修复了所有的问题,但是iOS 8在iPad air上仍然存在问题。在另一个设备上(我可以检查)和iOS 5-8,一切正常工作。
所以,我的代码的那一部分:
//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);
}
}因此,在iPad空气记录周期,我们不是捕获样本。经过alcGetIntegerv和alcCaptureSamples后,我们有空的缓冲区和零的计数器样品。这发生在第一次开始录音。在第二次尝试中,我们在计数器中捕获了示例,但是缓冲区仍然是空的。
我想我对麦克风有问题。iOS不显示麦克风权限窗口。我试过alcIsExtensionPresent,但他返回了真。
我不知道该怎么办。我希望你能帮我。
为我糟糕的英语感到抱歉。
发布于 2014-12-15 15:20:28
我有时间回答自己的问题。我所需要的一切-是使用一个音频会话。就像这样:
//when playback
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategorySoloAmbient error:&error];和
//when recording
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:&error];现在不需要任何无法解释的黑客。
https://stackoverflow.com/questions/26358773
复制相似问题