首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >开式铝中的录音问题

开式铝中的录音问题
EN

Stack Overflow用户
提问于 2014-10-14 10:40:48
回答 1查看 281关注 0票数 1

我有一些问题,我的开放铝录音在不同的iOS。

使用自我解释的黑客,我确实修复了所有的问题,但是iOS 8在iPad air上仍然存在问题。在另一个设备上(我可以检查)和iOS 5-8,一切正常工作。

所以,我的代码的那一部分:

代码语言:javascript
复制
//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,但他返回了真。

我不知道该怎么办。我希望你能帮我。

为我糟糕的英语感到抱歉。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-12-15 15:20:28

我有时间回答自己的问题。我所需要的一切-是使用一个音频会话。就像这样:

代码语言:javascript
复制
//when playback
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategorySoloAmbient error:&error];

代码语言:javascript
复制
//when recording
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:&error];

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26358773

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档