Loading media/libaaudio/examples/input_monitor/src/input_monitor.cpp +14 −4 Original line number Diff line number Diff line Loading @@ -24,7 +24,7 @@ #include <aaudio/AAudio.h> #define SAMPLE_RATE 48000 #define NUM_SECONDS 6 #define NUM_SECONDS 5 #define NANOS_PER_MICROSECOND ((int64_t)1000) #define NANOS_PER_MILLISECOND (NANOS_PER_MICROSECOND * 1000) #define NANOS_PER_SECOND (NANOS_PER_MILLISECOND * 1000) Loading Loading @@ -57,6 +57,11 @@ int main(int argc, char **argv) const aaudio_audio_format_t requestedDataFormat = AAUDIO_FORMAT_PCM_I16; aaudio_audio_format_t actualDataFormat; const int requestedInputChannelCount = 1; // Can affect whether we get a FAST path. //aaudio_performance_mode_t requestedPerformanceMode = AAUDIO_PERFORMANCE_MODE_NONE; const aaudio_performance_mode_t requestedPerformanceMode = AAUDIO_PERFORMANCE_MODE_LOW_LATENCY; //aaudio_performance_mode_t requestedPerformanceMode = AAUDIO_PERFORMANCE_MODE_POWER_SAVING; const aaudio_sharing_mode_t requestedSharingMode = AAUDIO_SHARING_MODE_SHARED; //const aaudio_sharing_mode_t requestedSharingMode = AAUDIO_SHARING_MODE_EXCLUSIVE; aaudio_sharing_mode_t actualSharingMode; Loading Loading @@ -89,6 +94,8 @@ int main(int argc, char **argv) AAudioStreamBuilder_setDirection(aaudioBuilder, AAUDIO_DIRECTION_INPUT); AAudioStreamBuilder_setFormat(aaudioBuilder, requestedDataFormat); AAudioStreamBuilder_setSharingMode(aaudioBuilder, requestedSharingMode); AAudioStreamBuilder_setPerformanceMode(aaudioBuilder, requestedPerformanceMode); AAudioStreamBuilder_setChannelCount(aaudioBuilder, requestedInputChannelCount); // Create an AAudioStream using the Builder. result = AAudioStreamBuilder_openStream(aaudioBuilder, &aaudioStream); Loading Loading @@ -124,6 +131,9 @@ int main(int argc, char **argv) // TODO handle other data formats assert(actualDataFormat == AAUDIO_FORMAT_PCM_I16); printf("PerformanceMode: requested = %d, actual = %d\n", requestedPerformanceMode, AAudioStream_getPerformanceMode(aaudioStream)); // Allocate a buffer for the audio data. data = new(std::nothrow) int16_t[framesPerRead * actualSamplesPerFrame]; if (data == nullptr) { Loading media/libaaudio/src/legacy/AudioStreamRecord.cpp +20 −1 Original line number Diff line number Diff line Loading @@ -69,7 +69,8 @@ aaudio_result_t AudioStreamRecord::open(const AudioStreamBuilder& builder) : AAudioConvert_aaudioToAndroidDataFormat(getFormat()); audio_input_flags_t flags = AUDIO_INPUT_FLAG_NONE; switch(getPerformanceMode()) { aaudio_performance_mode_t perfMode = getPerformanceMode(); switch (perfMode) { case AAUDIO_PERFORMANCE_MODE_LOW_LATENCY: flags = (audio_input_flags_t) (AUDIO_INPUT_FLAG_FAST | AUDIO_INPUT_FLAG_RAW); break; Loading Loading @@ -135,6 +136,24 @@ aaudio_result_t AudioStreamRecord::open(const AudioStreamBuilder& builder) mBlockAdapter = nullptr; } // Update performance mode based on the actual stream. // For example, if the sample rate does not match native then you won't get a FAST track. audio_input_flags_t actualFlags = mAudioRecord->getFlags(); aaudio_performance_mode_t actualPerformanceMode = AAUDIO_PERFORMANCE_MODE_NONE; // FIXME Some platforms do not advertise RAW mode for low latency inputs. if ((actualFlags & (AUDIO_INPUT_FLAG_FAST)) == (AUDIO_INPUT_FLAG_FAST)) { actualPerformanceMode = AAUDIO_PERFORMANCE_MODE_LOW_LATENCY; } setPerformanceMode(actualPerformanceMode); // Log warning if we did not get what we asked for. ALOGW_IF(actualFlags != flags, "AudioStreamRecord::open() flags changed from 0x%08X to 0x%08X", flags, actualFlags); ALOGW_IF(actualPerformanceMode != perfMode, "AudioStreamRecord::open() perfMode changed from %d to %d", perfMode, actualPerformanceMode); setState(AAUDIO_STREAM_STATE_OPEN); return AAUDIO_OK; Loading Loading
media/libaaudio/examples/input_monitor/src/input_monitor.cpp +14 −4 Original line number Diff line number Diff line Loading @@ -24,7 +24,7 @@ #include <aaudio/AAudio.h> #define SAMPLE_RATE 48000 #define NUM_SECONDS 6 #define NUM_SECONDS 5 #define NANOS_PER_MICROSECOND ((int64_t)1000) #define NANOS_PER_MILLISECOND (NANOS_PER_MICROSECOND * 1000) #define NANOS_PER_SECOND (NANOS_PER_MILLISECOND * 1000) Loading Loading @@ -57,6 +57,11 @@ int main(int argc, char **argv) const aaudio_audio_format_t requestedDataFormat = AAUDIO_FORMAT_PCM_I16; aaudio_audio_format_t actualDataFormat; const int requestedInputChannelCount = 1; // Can affect whether we get a FAST path. //aaudio_performance_mode_t requestedPerformanceMode = AAUDIO_PERFORMANCE_MODE_NONE; const aaudio_performance_mode_t requestedPerformanceMode = AAUDIO_PERFORMANCE_MODE_LOW_LATENCY; //aaudio_performance_mode_t requestedPerformanceMode = AAUDIO_PERFORMANCE_MODE_POWER_SAVING; const aaudio_sharing_mode_t requestedSharingMode = AAUDIO_SHARING_MODE_SHARED; //const aaudio_sharing_mode_t requestedSharingMode = AAUDIO_SHARING_MODE_EXCLUSIVE; aaudio_sharing_mode_t actualSharingMode; Loading Loading @@ -89,6 +94,8 @@ int main(int argc, char **argv) AAudioStreamBuilder_setDirection(aaudioBuilder, AAUDIO_DIRECTION_INPUT); AAudioStreamBuilder_setFormat(aaudioBuilder, requestedDataFormat); AAudioStreamBuilder_setSharingMode(aaudioBuilder, requestedSharingMode); AAudioStreamBuilder_setPerformanceMode(aaudioBuilder, requestedPerformanceMode); AAudioStreamBuilder_setChannelCount(aaudioBuilder, requestedInputChannelCount); // Create an AAudioStream using the Builder. result = AAudioStreamBuilder_openStream(aaudioBuilder, &aaudioStream); Loading Loading @@ -124,6 +131,9 @@ int main(int argc, char **argv) // TODO handle other data formats assert(actualDataFormat == AAUDIO_FORMAT_PCM_I16); printf("PerformanceMode: requested = %d, actual = %d\n", requestedPerformanceMode, AAudioStream_getPerformanceMode(aaudioStream)); // Allocate a buffer for the audio data. data = new(std::nothrow) int16_t[framesPerRead * actualSamplesPerFrame]; if (data == nullptr) { Loading
media/libaaudio/src/legacy/AudioStreamRecord.cpp +20 −1 Original line number Diff line number Diff line Loading @@ -69,7 +69,8 @@ aaudio_result_t AudioStreamRecord::open(const AudioStreamBuilder& builder) : AAudioConvert_aaudioToAndroidDataFormat(getFormat()); audio_input_flags_t flags = AUDIO_INPUT_FLAG_NONE; switch(getPerformanceMode()) { aaudio_performance_mode_t perfMode = getPerformanceMode(); switch (perfMode) { case AAUDIO_PERFORMANCE_MODE_LOW_LATENCY: flags = (audio_input_flags_t) (AUDIO_INPUT_FLAG_FAST | AUDIO_INPUT_FLAG_RAW); break; Loading Loading @@ -135,6 +136,24 @@ aaudio_result_t AudioStreamRecord::open(const AudioStreamBuilder& builder) mBlockAdapter = nullptr; } // Update performance mode based on the actual stream. // For example, if the sample rate does not match native then you won't get a FAST track. audio_input_flags_t actualFlags = mAudioRecord->getFlags(); aaudio_performance_mode_t actualPerformanceMode = AAUDIO_PERFORMANCE_MODE_NONE; // FIXME Some platforms do not advertise RAW mode for low latency inputs. if ((actualFlags & (AUDIO_INPUT_FLAG_FAST)) == (AUDIO_INPUT_FLAG_FAST)) { actualPerformanceMode = AAUDIO_PERFORMANCE_MODE_LOW_LATENCY; } setPerformanceMode(actualPerformanceMode); // Log warning if we did not get what we asked for. ALOGW_IF(actualFlags != flags, "AudioStreamRecord::open() flags changed from 0x%08X to 0x%08X", flags, actualFlags); ALOGW_IF(actualPerformanceMode != perfMode, "AudioStreamRecord::open() perfMode changed from %d to %d", perfMode, actualPerformanceMode); setState(AAUDIO_STREAM_STATE_OPEN); return AAUDIO_OK; Loading