【发布时间】:2014-12-15 23:20:28
【问题描述】:
我在不同的 iOS 上录制 Open Al 时遇到了一些问题。
使用无法解释的黑客攻击我确实解决了所有问题,但在 iPad air 上运行 iOS 8 时仍然存在问题。在另一台装有 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 air 的录制周期中,我们不会捕获样本。在 alcGetIntegerv 和 alcCaptureSamples 之后,我们有空缓冲区和计数器样本为零。这发生在第一次开始录制时。在第二次尝试中,我们在计数器中捕获了样本,但缓冲区仍然是空的。
我认为我在使用麦克风时遇到了问题。 iOS 不显示麦克风权限窗口。我尝试了 alcIsExtensionPresent,但他返回 true。
我不知道该怎么办。希望对您有所帮助。
对不起,我的英语不好。
【问题讨论】:
标签: ipad air ios8 audio-recording openal