Open Al中的录音问题

时间:2014-10-14 10:40:49

标签: ipad air ios8 audio-recording openal

我在不同iOS上的Open Al录制时遇到了一些问题。

使用自己无法解释的黑客攻击我确实解决了所有问题,但在iPad上播出的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上,我们不会捕获样本。在alcGetIntegerv和alcCaptureSamples之后,我们在计数器样本中有空缓冲区和零。这在首次开始录制时发生。在第二次尝试时,我们在计数器中捕获了样本,但缓冲区仍然是空的。

我认为我有访问麦克风的问题。 iOS不显示麦克风权限窗口。我尝试了alcIsExtensionPresent,但他回来了。

我不知道该怎么办。我希望得到你的帮助。

抱歉我的英语不好。

1 个答案:

答案 0 :(得分:1)

我找到了回答自己问题的时间。我需要的一切 - 是使用音频会话。像这样:

//when playback
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategorySoloAmbient error:&error];

//when recording
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:&error];

现在不需要任何无法解释的黑客攻击。

相关问题