1

我使用 Android NDK 和 OpenSL ES 编写了一个基本的记录器应用程序。它编译和链接很好,但是当我尝试在 Galaxy Nexus 设备上运行它时,我收到以下错误:

W/libOpenSLES(10708): Leaving Object::GetInterface (SL_RESULT_FEATURE_UNSUPPORTED)

这在线上发生:

res = (*recorderObj)->GetInterface(recorderObj, SL_IID_ANDROIDSIMPLEBUFFERQUEUE, &recorderBufferQueueItf);

这是否意味着不支持在 Galaxy Nexus 设备上使用 OpenSL ES 进行录制,或者我只是犯了一个错误?下面是相关代码:

    static SLObjectItf recorderObj;
    static SLEngineItf EngineItf;
    static SLRecordItf recordItf;
    static SLAndroidSimpleBufferQueueItf recorderBufferQueueItf;
    static SLDataSink recDest;
    static SLDataLocator_AndroidSimpleBufferQueue recBuffQueue;
    static SLDataFormat_PCM pcm;

    /* Setup the data source structure */
    locator_mic.locatorType = SL_DATALOCATOR_IODEVICE;
    locator_mic.deviceType = SL_IODEVICE_AUDIOINPUT;
    locator_mic.deviceID   = SL_DEFAULTDEVICEID_AUDIOINPUT;
    locator_mic.device = NULL;
    audioSource.pLocator = (void *) &locator_mic;
    audioSource.pFormat = NULL;

    /* Setup the data sink structure */
    recBuffQueue.locatorType = SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE;
    recBuffQueue.numBuffers = NB_BUFFERS_IN_QUEUE;

    /* set up the format of the data in the buffer queue */
    pcm.formatType = SL_DATAFORMAT_PCM;
    pcm.numChannels = 1;
    pcm.samplesPerSec = SL_SAMPLINGRATE_44_1;
    pcm.bitsPerSample = SL_PCMSAMPLEFORMAT_FIXED_16;
    pcm.containerSize = SL_PCMSAMPLEFORMAT_FIXED_16;
    pcm.channelMask = SL_SPEAKER_FRONT_CENTER;
    pcm.endianness = SL_BYTEORDER_LITTLEENDIAN;

    recDest.pLocator = (void *) &recBuffQueue;
    recDest.pFormat = (void * ) &pcm;

    /* Create audio recorder */
    res = (*EngineItf)->CreateAudioRecorder(EngineItf, &recorderObj, &audioSource, &recDest, 0, iidArray, required);
    CheckErr(res);

    /* Realizing the recorder in synchronous mode. */
    res = (*recorderObj)->Realize(recorderObj, SL_BOOLEAN_FALSE);
    CheckErr(res);

    /* Get the RECORD interface - it is an implicit interface */
    LOGI("GetInterface: Recorder");
    res = (*recorderObj)->GetInterface(recorderObj, SL_IID_RECORD, &recordItf);
    CheckErr(res);

    /* Get the buffer queue interface which was explicitly requested */
    LOGI("GetInterface: Buffer Queue");
    res = (*recorderObj)->GetInterface(recorderObj, SL_IID_ANDROIDSIMPLEBUFFERQUEUE, &recorderBufferQueueItf);
    CheckErr(res);

任何有关此问题的帮助都将受到欢迎:)

4

1 回答 1

2

创建音频记录器时,将“0”指定为倒数第三个参数,即要支持的非隐式接口的数量。缓冲区队列不是记录器的隐式接口。

尝试改变

res = (*EngineItf)->CreateAudioRecorder(EngineItf, &recorderObj, &audioSource, &recDest, 0, iidArray, required);

res = (*EngineItf)->CreateAudioRecorder(EngineItf, &recorderObj, &audioSource, &recDest, 1, iidArray, required);
于 2013-09-30T18:11:02.297 回答