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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…