Loading media/libaaudio/examples/write_sine/src/write_sine.cpp +9 −3 Original line number Diff line number Diff line Loading @@ -23,7 +23,7 @@ #include "SineGenerator.h" #define SAMPLE_RATE 48000 #define NUM_SECONDS 15 #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 @@ -104,6 +104,10 @@ int main(int argc, char **argv) AAudioStreamBuilder_setFormat(aaudioBuilder, REQUESTED_FORMAT); AAudioStreamBuilder_setSharingMode(aaudioBuilder, REQUESTED_SHARING_MODE); AAudioStreamBuilder_setPerformanceMode(aaudioBuilder, AAUDIO_PERFORMANCE_MODE_NONE); //AAudioStreamBuilder_setPerformanceMode(aaudioBuilder, AAUDIO_PERFORMANCE_MODE_LOW_LATENCY); //AAudioStreamBuilder_setPerformanceMode(aaudioBuilder, AAUDIO_PERFORMANCE_MODE_POWER_SAVING); // Create an AAudioStream using the Builder. result = AAudioStreamBuilder_openStream(aaudioBuilder, &aaudioStream); if (result != AAUDIO_OK) { Loading Loading @@ -132,7 +136,6 @@ int main(int argc, char **argv) // This is the number of frames that are read in one chunk by a DMA controller // or a DSP or a mixer. framesPerBurst = AAudioStream_getFramesPerBurst(aaudioStream); printf("Buffer: framesPerBurst = %d\n",framesPerBurst); printf("Buffer: bufferSize = %d\n", AAudioStream_getBufferSizeInFrames(aaudioStream)); bufferCapacity = AAudioStream_getBufferCapacityInFrames(aaudioStream); printf("Buffer: bufferCapacity = %d, remainder = %d\n", Loading @@ -144,12 +147,15 @@ int main(int argc, char **argv) while (framesPerWrite < 48) { framesPerWrite *= 2; } printf("DataFormat: framesPerWrite = %d\n",framesPerWrite); printf("Buffer: framesPerBurst = %d\n",framesPerBurst); printf("Buffer: framesPerWrite = %d\n",framesPerWrite); actualDataFormat = AAudioStream_getFormat(aaudioStream); printf("DataFormat: requested = %d, actual = %d\n", REQUESTED_FORMAT, actualDataFormat); // TODO handle other data formats printf("PerformanceMode: %d\n", AAudioStream_getPerformanceMode(aaudioStream)); // Allocate a buffer for the audio data. if (actualDataFormat == AAUDIO_FORMAT_PCM_FLOAT) { floatData = new float[framesPerWrite * actualChannelCount]; Loading media/libaaudio/examples/write_sine/src/write_sine_callback.cpp +7 −3 Original line number Diff line number Diff line Loading @@ -26,7 +26,7 @@ #include <aaudio/AAudio.h> #include "SineGenerator.h" #define NUM_SECONDS 15 #define NUM_SECONDS 5 //#define SHARING_MODE AAUDIO_SHARING_MODE_EXCLUSIVE #define SHARING_MODE AAUDIO_SHARING_MODE_SHARED Loading Loading @@ -88,6 +88,10 @@ public: // AAudioStreamBuilder_setFramesPerDataCallback(mBuilder, CALLBACK_SIZE_FRAMES); AAudioStreamBuilder_setBufferCapacityInFrames(mBuilder, 48 * 8); //AAudioStreamBuilder_setPerformanceMode(mBuilder, AAUDIO_PERFORMANCE_MODE_NONE); AAudioStreamBuilder_setPerformanceMode(mBuilder, AAUDIO_PERFORMANCE_MODE_LOW_LATENCY); //AAudioStreamBuilder_setPerformanceMode(mBuilder, AAUDIO_PERFORMANCE_MODE_POWER_SAVING); // Open an AAudioStream using the Builder. result = AAudioStreamBuilder_openStream(mBuilder, &mStream); if (result != AAUDIO_OK) goto finish1; Loading @@ -98,7 +102,6 @@ public: AAudioStream_getBufferSizeInFrames(mStream)); printf("AAudioStream_getBufferCapacityInFrames() = %d\n", AAudioStream_getBufferCapacityInFrames(mStream)); return result; finish1: AAudioStreamBuilder_delete(mBuilder); Loading Loading @@ -227,7 +230,7 @@ int main(int argc, char **argv) // Make printf print immediately so that debug info is not stuck // in a buffer if we hang or crash. setvbuf(stdout, nullptr, _IONBF, (size_t) 0); printf("%s - Play a sine sweep using an AAudio callback, Z1\n", argv[0]); printf("%s - Play a sine sweep using an AAudio callback\n", argv[0]); player.setSharingMode(SHARING_MODE); Loading Loading @@ -278,6 +281,7 @@ int main(int argc, char **argv) printf("Stream state is %d %s!\n", state, AAudio_convertStreamStateToText(state)); break; } printf("framesWritten = %d\n", (int) AAudioStream_getFramesWritten(player.getStream())); } printf("Woke up now.\n"); Loading media/libaaudio/include/aaudio/AAudio.h +38 −0 Original line number Diff line number Diff line Loading @@ -125,6 +125,25 @@ enum { }; typedef int32_t aaudio_sharing_mode_t; enum { /** * No particular performance needs. Default. */ AAUDIO_PERFORMANCE_MODE_NONE = 10, /** * Extending battery life is most important. */ AAUDIO_PERFORMANCE_MODE_POWER_SAVING, /** * Reducing latency is most important. */ AAUDIO_PERFORMANCE_MODE_LOW_LATENCY }; typedef int32_t aaudio_performance_mode_t; typedef struct AAudioStreamStruct AAudioStream; typedef struct AAudioStreamBuilderStruct AAudioStreamBuilder; Loading Loading @@ -279,6 +298,18 @@ AAUDIO_API void AAudioStreamBuilder_setDirection(AAudioStreamBuilder* builder, */ AAUDIO_API void AAudioStreamBuilder_setBufferCapacityInFrames(AAudioStreamBuilder* builder, int32_t numFrames); /** * Set the requested performance mode. * * The default, if you do not call this function, is AAUDIO_PERFORMANCE_MODE_NONE. * * @param builder reference provided by AAudio_createStreamBuilder() * @param mode the desired performance mode, eg. AAUDIO_PERFORMANCE_MODE_LOW_LATENCY */ AAUDIO_API void AAudioStreamBuilder_setPerformanceMode(AAudioStreamBuilder* builder, aaudio_performance_mode_t mode); /** * Return one of these values from the data callback function. */ Loading Loading @@ -721,6 +752,13 @@ AAUDIO_API aaudio_audio_format_t AAudioStream_getFormat(AAudioStream* stream); */ AAUDIO_API aaudio_sharing_mode_t AAudioStream_getSharingMode(AAudioStream* stream); /** * Get the performance mode used by the stream. * * @param stream reference provided by AAudioStreamBuilder_openStream() */ AAUDIO_API aaudio_performance_mode_t AAudioStream_getPerformanceMode(AAudioStream* stream); /** * @param stream reference provided by AAudioStreamBuilder_openStream() * @return direction Loading media/libaaudio/libaaudio.map.txt +2 −0 Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ LIBAAUDIO { AAudio_convertResultToText; AAudio_convertStreamStateToText; AAudio_createStreamBuilder; AAudioStreamBuilder_setPerformanceMode; AAudioStreamBuilder_setDeviceId; AAudioStreamBuilder_setDataCallback; AAudioStreamBuilder_setErrorCallback; Loading Loading @@ -34,6 +35,7 @@ LIBAAUDIO { AAudioStream_getSampleRate; AAudioStream_getSamplesPerFrame; AAudioStream_getChannelCount; AAudioStream_getPerformanceMode; AAudioStream_getDeviceId; AAudioStream_getFormat; AAudioStream_getSharingMode; Loading media/libaaudio/src/client/AudioStreamInternal.h +5 −0 Original line number Diff line number Diff line Loading @@ -90,6 +90,11 @@ public: // Called internally from 'C' void *callbackLoop(); bool isMMap() override { return true; } protected: aaudio_result_t processCommands(); Loading Loading
media/libaaudio/examples/write_sine/src/write_sine.cpp +9 −3 Original line number Diff line number Diff line Loading @@ -23,7 +23,7 @@ #include "SineGenerator.h" #define SAMPLE_RATE 48000 #define NUM_SECONDS 15 #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 @@ -104,6 +104,10 @@ int main(int argc, char **argv) AAudioStreamBuilder_setFormat(aaudioBuilder, REQUESTED_FORMAT); AAudioStreamBuilder_setSharingMode(aaudioBuilder, REQUESTED_SHARING_MODE); AAudioStreamBuilder_setPerformanceMode(aaudioBuilder, AAUDIO_PERFORMANCE_MODE_NONE); //AAudioStreamBuilder_setPerformanceMode(aaudioBuilder, AAUDIO_PERFORMANCE_MODE_LOW_LATENCY); //AAudioStreamBuilder_setPerformanceMode(aaudioBuilder, AAUDIO_PERFORMANCE_MODE_POWER_SAVING); // Create an AAudioStream using the Builder. result = AAudioStreamBuilder_openStream(aaudioBuilder, &aaudioStream); if (result != AAUDIO_OK) { Loading Loading @@ -132,7 +136,6 @@ int main(int argc, char **argv) // This is the number of frames that are read in one chunk by a DMA controller // or a DSP or a mixer. framesPerBurst = AAudioStream_getFramesPerBurst(aaudioStream); printf("Buffer: framesPerBurst = %d\n",framesPerBurst); printf("Buffer: bufferSize = %d\n", AAudioStream_getBufferSizeInFrames(aaudioStream)); bufferCapacity = AAudioStream_getBufferCapacityInFrames(aaudioStream); printf("Buffer: bufferCapacity = %d, remainder = %d\n", Loading @@ -144,12 +147,15 @@ int main(int argc, char **argv) while (framesPerWrite < 48) { framesPerWrite *= 2; } printf("DataFormat: framesPerWrite = %d\n",framesPerWrite); printf("Buffer: framesPerBurst = %d\n",framesPerBurst); printf("Buffer: framesPerWrite = %d\n",framesPerWrite); actualDataFormat = AAudioStream_getFormat(aaudioStream); printf("DataFormat: requested = %d, actual = %d\n", REQUESTED_FORMAT, actualDataFormat); // TODO handle other data formats printf("PerformanceMode: %d\n", AAudioStream_getPerformanceMode(aaudioStream)); // Allocate a buffer for the audio data. if (actualDataFormat == AAUDIO_FORMAT_PCM_FLOAT) { floatData = new float[framesPerWrite * actualChannelCount]; Loading
media/libaaudio/examples/write_sine/src/write_sine_callback.cpp +7 −3 Original line number Diff line number Diff line Loading @@ -26,7 +26,7 @@ #include <aaudio/AAudio.h> #include "SineGenerator.h" #define NUM_SECONDS 15 #define NUM_SECONDS 5 //#define SHARING_MODE AAUDIO_SHARING_MODE_EXCLUSIVE #define SHARING_MODE AAUDIO_SHARING_MODE_SHARED Loading Loading @@ -88,6 +88,10 @@ public: // AAudioStreamBuilder_setFramesPerDataCallback(mBuilder, CALLBACK_SIZE_FRAMES); AAudioStreamBuilder_setBufferCapacityInFrames(mBuilder, 48 * 8); //AAudioStreamBuilder_setPerformanceMode(mBuilder, AAUDIO_PERFORMANCE_MODE_NONE); AAudioStreamBuilder_setPerformanceMode(mBuilder, AAUDIO_PERFORMANCE_MODE_LOW_LATENCY); //AAudioStreamBuilder_setPerformanceMode(mBuilder, AAUDIO_PERFORMANCE_MODE_POWER_SAVING); // Open an AAudioStream using the Builder. result = AAudioStreamBuilder_openStream(mBuilder, &mStream); if (result != AAUDIO_OK) goto finish1; Loading @@ -98,7 +102,6 @@ public: AAudioStream_getBufferSizeInFrames(mStream)); printf("AAudioStream_getBufferCapacityInFrames() = %d\n", AAudioStream_getBufferCapacityInFrames(mStream)); return result; finish1: AAudioStreamBuilder_delete(mBuilder); Loading Loading @@ -227,7 +230,7 @@ int main(int argc, char **argv) // Make printf print immediately so that debug info is not stuck // in a buffer if we hang or crash. setvbuf(stdout, nullptr, _IONBF, (size_t) 0); printf("%s - Play a sine sweep using an AAudio callback, Z1\n", argv[0]); printf("%s - Play a sine sweep using an AAudio callback\n", argv[0]); player.setSharingMode(SHARING_MODE); Loading Loading @@ -278,6 +281,7 @@ int main(int argc, char **argv) printf("Stream state is %d %s!\n", state, AAudio_convertStreamStateToText(state)); break; } printf("framesWritten = %d\n", (int) AAudioStream_getFramesWritten(player.getStream())); } printf("Woke up now.\n"); Loading
media/libaaudio/include/aaudio/AAudio.h +38 −0 Original line number Diff line number Diff line Loading @@ -125,6 +125,25 @@ enum { }; typedef int32_t aaudio_sharing_mode_t; enum { /** * No particular performance needs. Default. */ AAUDIO_PERFORMANCE_MODE_NONE = 10, /** * Extending battery life is most important. */ AAUDIO_PERFORMANCE_MODE_POWER_SAVING, /** * Reducing latency is most important. */ AAUDIO_PERFORMANCE_MODE_LOW_LATENCY }; typedef int32_t aaudio_performance_mode_t; typedef struct AAudioStreamStruct AAudioStream; typedef struct AAudioStreamBuilderStruct AAudioStreamBuilder; Loading Loading @@ -279,6 +298,18 @@ AAUDIO_API void AAudioStreamBuilder_setDirection(AAudioStreamBuilder* builder, */ AAUDIO_API void AAudioStreamBuilder_setBufferCapacityInFrames(AAudioStreamBuilder* builder, int32_t numFrames); /** * Set the requested performance mode. * * The default, if you do not call this function, is AAUDIO_PERFORMANCE_MODE_NONE. * * @param builder reference provided by AAudio_createStreamBuilder() * @param mode the desired performance mode, eg. AAUDIO_PERFORMANCE_MODE_LOW_LATENCY */ AAUDIO_API void AAudioStreamBuilder_setPerformanceMode(AAudioStreamBuilder* builder, aaudio_performance_mode_t mode); /** * Return one of these values from the data callback function. */ Loading Loading @@ -721,6 +752,13 @@ AAUDIO_API aaudio_audio_format_t AAudioStream_getFormat(AAudioStream* stream); */ AAUDIO_API aaudio_sharing_mode_t AAudioStream_getSharingMode(AAudioStream* stream); /** * Get the performance mode used by the stream. * * @param stream reference provided by AAudioStreamBuilder_openStream() */ AAUDIO_API aaudio_performance_mode_t AAudioStream_getPerformanceMode(AAudioStream* stream); /** * @param stream reference provided by AAudioStreamBuilder_openStream() * @return direction Loading
media/libaaudio/libaaudio.map.txt +2 −0 Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ LIBAAUDIO { AAudio_convertResultToText; AAudio_convertStreamStateToText; AAudio_createStreamBuilder; AAudioStreamBuilder_setPerformanceMode; AAudioStreamBuilder_setDeviceId; AAudioStreamBuilder_setDataCallback; AAudioStreamBuilder_setErrorCallback; Loading Loading @@ -34,6 +35,7 @@ LIBAAUDIO { AAudioStream_getSampleRate; AAudioStream_getSamplesPerFrame; AAudioStream_getChannelCount; AAudioStream_getPerformanceMode; AAudioStream_getDeviceId; AAudioStream_getFormat; AAudioStream_getSharingMode; Loading
media/libaaudio/src/client/AudioStreamInternal.h +5 −0 Original line number Diff line number Diff line Loading @@ -90,6 +90,11 @@ public: // Called internally from 'C' void *callbackLoop(); bool isMMap() override { return true; } protected: aaudio_result_t processCommands(); Loading