Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

android - AAudioStream_getChannelCount returns 0

I'm trying to record audio using the native audio library of the NDK.

According to the AAudioStreamBuilder_setChannelCount documentation

The default, if you do not call this function, is AAUDIO_UNSPECIFIED. An optimal value will then be chosen when the stream is opened. After opening a stream with an unspecified value, the application must query for the actual value, which may vary by device.

Unfortunately, AAudioStream_getChannelCount (as well as AAudioStream_getFramesPerDataCallback) just returns 0.

Currently, I'm using this simple code

    AAudioStreamBuilder *builder = nullptr;
    AAudioStream *as = nullptr;

    AAudio_createStreamBuilder(&builder);
    AAudioStreamBuilder_setDirection(builder, AAUDIO_DIRECTION_INPUT);
    AAudioStreamBuilder_setDataCallback(builder, data_callback, nullptr);
    AAudioStreamBuilder_setErrorCallback(builder, error_callback, nullptr);
    AAudioStreamBuilder_setPerformanceMode(builder, AAUDIO_PERFORMANCE_MODE_NONE);
    AAudioStreamBuilder_openStream(builder, &as);


    LOGD("State: %d", AAudioStream_getState(as));
    LOGD("Channels: %d", AAudioStream_getChannelCount(as));
    LOGD("Frames per Callback: %d", AAudioStream_getFramesPerDataCallback(as));
    LOGD("Sample Rate: %d", AAudioStream_getSampleRate(as));

And this is the output I got

State: 2
Channels: 0
Frames per Callback: 0
Sample Rate: 48000

Am I misunderstanding something or missing a step?

I'm trying this on an API 26 Emulator Device if it matters.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...