Loading media/liboboe/Android.bp +3 −3 Original line number Diff line number Diff line Loading @@ -13,11 +13,11 @@ // limitations under the License. ndk_headers { name: "libOboe_headers", name: "libAAudio_headers", from: "include", to: "", srcs: ["include/oboe/*.h"], license: "include/oboe/NOTICE", srcs: ["include/aaudio/*.h"], license: "include/aaudio/NOTICE", } ndk_library { Loading media/liboboe/README.md +1 −1 Original line number Diff line number Diff line Oboe Audio input/output API AAudio Audio input/output API media/liboboe/examples/write_sine/README.md +2 −2 Original line number Diff line number Diff line # cd to this directory mkdir -p jni/include/oboe ln -s $PLATFORM/frameworks/av/media/liboboe/include/oboe/*.h jni/include/oboe mkdir -p jni/include/aaudio ln -s $PLATFORM/frameworks/av/media/liboboe/include/aaudio/*.h jni/include/aaudio ln -s $PLATFORM/out/target/product/$TARGET_PRODUCT/symbols/out/soong/ndk/platforms/android-current/arch-arm64/usr/lib/liboboe.so jni $NDK/ndk-build adb push libs/arm64-v8a/write_sine_threaded /data Loading media/liboboe/examples/write_sine/src/write_sine.cpp +64 −64 Original line number Diff line number Diff line Loading @@ -14,31 +14,31 @@ * limitations under the License. */ // Play sine waves using Oboe. // Play sine waves using AAudio. #include <stdio.h> #include <stdlib.h> #include <math.h> #include <oboe/OboeDefinitions.h> #include <oboe/OboeAudio.h> #include <aaudio/AAudioDefinitions.h> #include <aaudio/AAudio.h> #include "SineGenerator.h" #define SAMPLE_RATE 48000 #define NUM_SECONDS 10 static const char *getSharingModeText(oboe_sharing_mode_t mode) { static const char *getSharingModeText(aaudio_sharing_mode_t mode) { const char *modeText = "unknown"; switch (mode) { case OBOE_SHARING_MODE_EXCLUSIVE: case AAUDIO_SHARING_MODE_EXCLUSIVE: modeText = "EXCLUSIVE"; break; case OBOE_SHARING_MODE_LEGACY: case AAUDIO_SHARING_MODE_LEGACY: modeText = "LEGACY"; break; case OBOE_SHARING_MODE_SHARED: case AAUDIO_SHARING_MODE_SHARED: modeText = "SHARED"; break; case OBOE_SHARING_MODE_PUBLIC_MIX: case AAUDIO_SHARING_MODE_PUBLIC_MIX: modeText = "PUBLIC_MIX"; break; default: Loading @@ -51,25 +51,25 @@ int main(int argc, char **argv) { (void)argc; // unused oboe_result_t result = OBOE_OK; aaudio_result_t result = AAUDIO_OK; const int requestedSamplesPerFrame = 2; int actualSamplesPerFrame = 0; const int requestedSampleRate = SAMPLE_RATE; int actualSampleRate = 0; const oboe_audio_format_t requestedDataFormat = OBOE_AUDIO_FORMAT_PCM16; oboe_audio_format_t actualDataFormat = OBOE_AUDIO_FORMAT_PCM16; const oboe_sharing_mode_t requestedSharingMode = OBOE_SHARING_MODE_EXCLUSIVE; //const oboe_sharing_mode_t requestedSharingMode = OBOE_SHARING_MODE_LEGACY; oboe_sharing_mode_t actualSharingMode = OBOE_SHARING_MODE_LEGACY; OboeStreamBuilder oboeBuilder = OBOE_STREAM_BUILDER_NONE; OboeStream oboeStream = OBOE_STREAM_NONE; oboe_stream_state_t state = OBOE_STREAM_STATE_UNINITIALIZED; oboe_size_frames_t framesPerBurst = 0; oboe_size_frames_t framesToPlay = 0; oboe_size_frames_t framesLeft = 0; const aaudio_audio_format_t requestedDataFormat = AAUDIO_FORMAT_PCM16; aaudio_audio_format_t actualDataFormat = AAUDIO_FORMAT_PCM16; const aaudio_sharing_mode_t requestedSharingMode = AAUDIO_SHARING_MODE_EXCLUSIVE; //const aaudio_sharing_mode_t requestedSharingMode = AAUDIO_SHARING_MODE_LEGACY; aaudio_sharing_mode_t actualSharingMode = AAUDIO_SHARING_MODE_LEGACY; AAudioStreamBuilder aaudioBuilder = AAUDIO_STREAM_BUILDER_NONE; AAudioStream aaudioStream = AAUDIO_STREAM_NONE; aaudio_stream_state_t state = AAUDIO_STREAM_STATE_UNINITIALIZED; aaudio_size_frames_t framesPerBurst = 0; aaudio_size_frames_t framesToPlay = 0; aaudio_size_frames_t framesLeft = 0; int32_t xRunCount = 0; int16_t *data = nullptr; Loading @@ -80,64 +80,64 @@ int main(int argc, char **argv) // in a buffer if we hang or crash. setvbuf(stdout, nullptr, _IONBF, (size_t) 0); printf("%s - Play a sine wave using Oboe\n", argv[0]); printf("%s - Play a sine wave using AAudio\n", argv[0]); // Use an OboeStreamBuilder to contain requested parameters. result = Oboe_createStreamBuilder(&oboeBuilder); if (result != OBOE_OK) { // Use an AAudioStreamBuilder to contain requested parameters. result = AAudio_createStreamBuilder(&aaudioBuilder); if (result != AAUDIO_OK) { goto finish; } // Request stream properties. result = OboeStreamBuilder_setSampleRate(oboeBuilder, requestedSampleRate); if (result != OBOE_OK) { result = AAudioStreamBuilder_setSampleRate(aaudioBuilder, requestedSampleRate); if (result != AAUDIO_OK) { goto finish; } result = OboeStreamBuilder_setSamplesPerFrame(oboeBuilder, requestedSamplesPerFrame); if (result != OBOE_OK) { result = AAudioStreamBuilder_setSamplesPerFrame(aaudioBuilder, requestedSamplesPerFrame); if (result != AAUDIO_OK) { goto finish; } result = OboeStreamBuilder_setFormat(oboeBuilder, requestedDataFormat); if (result != OBOE_OK) { result = AAudioStreamBuilder_setFormat(aaudioBuilder, requestedDataFormat); if (result != AAUDIO_OK) { goto finish; } result = OboeStreamBuilder_setSharingMode(oboeBuilder, requestedSharingMode); if (result != OBOE_OK) { result = AAudioStreamBuilder_setSharingMode(aaudioBuilder, requestedSharingMode); if (result != AAUDIO_OK) { goto finish; } // Create an OboeStream using the Builder. result = OboeStreamBuilder_openStream(oboeBuilder, &oboeStream); printf("oboeStream 0x%08x\n", oboeStream); if (result != OBOE_OK) { // Create an AAudioStream using the Builder. result = AAudioStreamBuilder_openStream(aaudioBuilder, &aaudioStream); printf("aaudioStream 0x%08x\n", aaudioStream); if (result != AAUDIO_OK) { goto finish; } result = OboeStream_getState(oboeStream, &state); printf("after open, state = %s\n", Oboe_convertStreamStateToText(state)); result = AAudioStream_getState(aaudioStream, &state); printf("after open, state = %s\n", AAudio_convertStreamStateToText(state)); // Check to see what kind of stream we actually got. result = OboeStream_getSampleRate(oboeStream, &actualSampleRate); result = AAudioStream_getSampleRate(aaudioStream, &actualSampleRate); printf("SampleRate: requested = %d, actual = %d\n", requestedSampleRate, actualSampleRate); sineOsc1.setup(440.0, actualSampleRate); sineOsc2.setup(660.0, actualSampleRate); result = OboeStream_getSamplesPerFrame(oboeStream, &actualSamplesPerFrame); result = AAudioStream_getSamplesPerFrame(aaudioStream, &actualSamplesPerFrame); printf("SamplesPerFrame: requested = %d, actual = %d\n", requestedSamplesPerFrame, actualSamplesPerFrame); result = OboeStream_getSharingMode(oboeStream, &actualSharingMode); result = AAudioStream_getSharingMode(aaudioStream, &actualSharingMode); printf("SharingMode: requested = %s, actual = %s\n", getSharingModeText(requestedSharingMode), getSharingModeText(actualSharingMode)); // This is the number of frames that are read in one chunk by a DMA controller // or a DSP or a mixer. result = OboeStream_getFramesPerBurst(oboeStream, &framesPerBurst); result = AAudioStream_getFramesPerBurst(aaudioStream, &framesPerBurst); printf("DataFormat: original framesPerBurst = %d\n",framesPerBurst); if (result != OBOE_OK) { fprintf(stderr, "ERROR - OboeStream_getFramesPerBurst() returned %d\n", result); if (result != AAUDIO_OK) { fprintf(stderr, "ERROR - AAudioStream_getFramesPerBurst() returned %d\n", result); goto finish; } // Some DMA might use very short bursts of 16 frames. We don't need to write such small Loading @@ -147,7 +147,7 @@ int main(int argc, char **argv) } printf("DataFormat: final framesPerBurst = %d\n",framesPerBurst); OboeStream_getFormat(oboeStream, &actualDataFormat); AAudioStream_getFormat(aaudioStream, &actualDataFormat); printf("DataFormat: requested = %d, actual = %d\n", requestedDataFormat, actualDataFormat); // TODO handle other data formats Loading @@ -155,20 +155,20 @@ int main(int argc, char **argv) data = new int16_t[framesPerBurst * actualSamplesPerFrame]; if (data == nullptr) { fprintf(stderr, "ERROR - could not allocate data buffer\n"); result = OBOE_ERROR_NO_MEMORY; result = AAUDIO_ERROR_NO_MEMORY; goto finish; } // Start the stream. printf("call OboeStream_requestStart()\n"); result = OboeStream_requestStart(oboeStream); if (result != OBOE_OK) { fprintf(stderr, "ERROR - OboeStream_requestStart() returned %d\n", result); printf("call AAudioStream_requestStart()\n"); result = AAudioStream_requestStart(aaudioStream); if (result != AAUDIO_OK) { fprintf(stderr, "ERROR - AAudioStream_requestStart() returned %d\n", result); goto finish; } result = OboeStream_getState(oboeStream, &state); printf("after start, state = %s\n", Oboe_convertStreamStateToText(state)); result = AAudioStream_getState(aaudioStream, &state); printf("after start, state = %s\n", AAudio_convertStreamStateToText(state)); // Play for a while. framesToPlay = actualSampleRate * NUM_SECONDS; Loading @@ -181,27 +181,27 @@ int main(int argc, char **argv) } // Write audio data to the stream. oboe_nanoseconds_t timeoutNanos = 100 * OBOE_NANOS_PER_MILLISECOND; aaudio_nanoseconds_t timeoutNanos = 100 * AAUDIO_NANOS_PER_MILLISECOND; int minFrames = (framesToPlay < framesPerBurst) ? framesToPlay : framesPerBurst; int actual = OboeStream_write(oboeStream, data, minFrames, timeoutNanos); int actual = AAudioStream_write(aaudioStream, data, minFrames, timeoutNanos); if (actual < 0) { fprintf(stderr, "ERROR - OboeStream_write() returned %zd\n", actual); fprintf(stderr, "ERROR - AAudioStream_write() returned %zd\n", actual); goto finish; } else if (actual == 0) { fprintf(stderr, "WARNING - OboeStream_write() returned %zd\n", actual); fprintf(stderr, "WARNING - AAudioStream_write() returned %zd\n", actual); goto finish; } framesLeft -= actual; } result = OboeStream_getXRunCount(oboeStream, &xRunCount); printf("OboeStream_getXRunCount %d\n", xRunCount); result = AAudioStream_getXRunCount(aaudioStream, &xRunCount); printf("AAudioStream_getXRunCount %d\n", xRunCount); finish: delete[] data; OboeStream_close(oboeStream); OboeStreamBuilder_delete(oboeBuilder); printf("exiting - Oboe result = %d = %s\n", result, Oboe_convertResultToText(result)); return (result != OBOE_OK) ? EXIT_FAILURE : EXIT_SUCCESS; AAudioStream_close(aaudioStream); AAudioStreamBuilder_delete(aaudioBuilder); printf("exiting - AAudio result = %d = %s\n", result, AAudio_convertResultToText(result)); return (result != AAUDIO_OK) ? EXIT_FAILURE : EXIT_SUCCESS; } media/liboboe/examples/write_sine/src/write_sine_threaded.cpp +82 −82 Original line number Diff line number Diff line Loading @@ -14,7 +14,7 @@ * limitations under the License. */ // Play sine waves using an Oboe background thread. // Play sine waves using an AAudio background thread. #include <assert.h> #include <unistd.h> Loading @@ -22,34 +22,34 @@ #include <stdio.h> #include <math.h> #include <time.h> #include <oboe/OboeDefinitions.h> #include <oboe/OboeAudio.h> #include <aaudio/AAudioDefinitions.h> #include <aaudio/AAudio.h> #include "SineGenerator.h" #define NUM_SECONDS 10 #define SHARING_MODE OBOE_SHARING_MODE_EXCLUSIVE //#define SHARING_MODE OBOE_SHARING_MODE_LEGACY #define SHARING_MODE AAUDIO_SHARING_MODE_EXCLUSIVE //#define SHARING_MODE AAUDIO_SHARING_MODE_LEGACY // Prototype for a callback. typedef int audio_callback_proc_t(float *outputBuffer, oboe_size_frames_t numFrames, aaudio_size_frames_t numFrames, void *userContext); static void *SimpleOboePlayerThreadProc(void *arg); static void *SimpleAAudioPlayerThreadProc(void *arg); /** * Simple wrapper for Oboe that opens a default stream and then calls * Simple wrapper for AAudio that opens a default stream and then calls * a callback function to fill the output buffers. */ class SimpleOboePlayer { class SimpleAAudioPlayer { public: SimpleOboePlayer() {} virtual ~SimpleOboePlayer() { SimpleAAudioPlayer() {} virtual ~SimpleAAudioPlayer() { close(); }; void setSharingMode(oboe_sharing_mode_t requestedSharingMode) { void setSharingMode(aaudio_sharing_mode_t requestedSharingMode) { mRequestedSharingMode = requestedSharingMode; } Loading @@ -66,34 +66,34 @@ public: /** * Open a stream */ oboe_result_t open(audio_callback_proc_t *proc, void *userContext) { aaudio_result_t open(audio_callback_proc_t *proc, void *userContext) { mCallbackProc = proc; mUserContext = userContext; oboe_result_t result = OBOE_OK; aaudio_result_t result = AAUDIO_OK; // Use an OboeStreamBuilder to contain requested parameters. result = Oboe_createStreamBuilder(&mBuilder); if (result != OBOE_OK) return result; // Use an AAudioStreamBuilder to contain requested parameters. result = AAudio_createStreamBuilder(&mBuilder); if (result != AAUDIO_OK) return result; result = OboeStreamBuilder_setSharingMode(mBuilder, mRequestedSharingMode); if (result != OBOE_OK) goto finish1; result = AAudioStreamBuilder_setSharingMode(mBuilder, mRequestedSharingMode); if (result != AAUDIO_OK) goto finish1; // Open an OboeStream using the Builder. result = OboeStreamBuilder_openStream(mBuilder, &mStream); if (result != OBOE_OK) goto finish1; // Open an AAudioStream using the Builder. result = AAudioStreamBuilder_openStream(mBuilder, &mStream); if (result != AAUDIO_OK) goto finish1; // Check to see what kind of stream we actually got. result = OboeStream_getSampleRate(mStream, &mFramesPerSecond); result = AAudioStream_getSampleRate(mStream, &mFramesPerSecond); printf("open() mFramesPerSecond = %d\n", mFramesPerSecond); if (result != OBOE_OK) goto finish2; result = OboeStream_getSamplesPerFrame(mStream, &mSamplesPerFrame); if (result != AAUDIO_OK) goto finish2; result = AAudioStream_getSamplesPerFrame(mStream, &mSamplesPerFrame); printf("open() mSamplesPerFrame = %d\n", mSamplesPerFrame); if (result != OBOE_OK) goto finish2; if (result != AAUDIO_OK) goto finish2; // This is the number of frames that are read in one chunk by a DMA controller // or a DSP or a mixer. result = OboeStream_getFramesPerBurst(mStream, &mFramesPerBurst); if (result != OBOE_OK) goto finish2; result = AAudioStream_getFramesPerBurst(mStream, &mFramesPerBurst); if (result != AAUDIO_OK) goto finish2; // Some DMA might use very short bursts. We don't need to write such small // buffers. But it helps to use a multiple of the burst size for predictable scheduling. while (mFramesPerBurst < 48) { Loading @@ -101,9 +101,9 @@ public: } printf("DataFormat: final framesPerBurst = %d\n",mFramesPerBurst); result = OboeStream_getFormat(mStream, &mDataFormat); if (result != OBOE_OK) { fprintf(stderr, "ERROR - OboeStream_getFormat() returned %d\n", result); result = AAudioStream_getFormat(mStream, &mDataFormat); if (result != AAUDIO_OK) { fprintf(stderr, "ERROR - AAudioStream_getFormat() returned %d\n", result); goto finish2; } Loading @@ -111,75 +111,75 @@ public: mOutputBuffer = new float[mFramesPerBurst * mSamplesPerFrame]; if (mOutputBuffer == nullptr) { fprintf(stderr, "ERROR - could not allocate data buffer\n"); result = OBOE_ERROR_NO_MEMORY; result = AAUDIO_ERROR_NO_MEMORY; } // If needed allocate a buffer for converting float to int16_t. if (mDataFormat == OBOE_AUDIO_FORMAT_PCM16) { if (mDataFormat == AAUDIO_FORMAT_PCM16) { mConversionBuffer = new int16_t[mFramesPerBurst * mSamplesPerFrame]; if (mConversionBuffer == nullptr) { fprintf(stderr, "ERROR - could not allocate conversion buffer\n"); result = OBOE_ERROR_NO_MEMORY; result = AAUDIO_ERROR_NO_MEMORY; } } return result; finish2: OboeStream_close(mStream); mStream = OBOE_HANDLE_INVALID; AAudioStream_close(mStream); mStream = AAUDIO_HANDLE_INVALID; finish1: OboeStreamBuilder_delete(mBuilder); mBuilder = OBOE_HANDLE_INVALID; AAudioStreamBuilder_delete(mBuilder); mBuilder = AAUDIO_HANDLE_INVALID; return result; } oboe_result_t close() { if (mStream != OBOE_HANDLE_INVALID) { aaudio_result_t close() { if (mStream != AAUDIO_HANDLE_INVALID) { stop(); printf("call OboeStream_close(0x%08x)\n", mStream); fflush(stdout); OboeStream_close(mStream); mStream = OBOE_HANDLE_INVALID; OboeStreamBuilder_delete(mBuilder); mBuilder = OBOE_HANDLE_INVALID; printf("call AAudioStream_close(0x%08x)\n", mStream); fflush(stdout); AAudioStream_close(mStream); mStream = AAUDIO_HANDLE_INVALID; AAudioStreamBuilder_delete(mBuilder); mBuilder = AAUDIO_HANDLE_INVALID; delete mOutputBuffer; mOutputBuffer = nullptr; delete mConversionBuffer; mConversionBuffer = nullptr; } return OBOE_OK; return AAUDIO_OK; } // Start a thread that will call the callback proc. oboe_result_t start() { aaudio_result_t start() { mEnabled = true; oboe_nanoseconds_t nanosPerBurst = mFramesPerBurst * OBOE_NANOS_PER_SECOND aaudio_nanoseconds_t nanosPerBurst = mFramesPerBurst * AAUDIO_NANOS_PER_SECOND / mFramesPerSecond; return OboeStream_createThread(mStream, nanosPerBurst, SimpleOboePlayerThreadProc, return AAudioStream_createThread(mStream, nanosPerBurst, SimpleAAudioPlayerThreadProc, this); } // Tell the thread to stop. oboe_result_t stop() { aaudio_result_t stop() { mEnabled = false; return OboeStream_joinThread(mStream, nullptr, 2 * OBOE_NANOS_PER_SECOND); return AAudioStream_joinThread(mStream, nullptr, 2 * AAUDIO_NANOS_PER_SECOND); } oboe_result_t callbackLoop() { aaudio_result_t callbackLoop() { int32_t framesWritten = 0; int32_t xRunCount = 0; oboe_result_t result = OBOE_OK; aaudio_result_t result = AAUDIO_OK; result = OboeStream_requestStart(mStream); if (result != OBOE_OK) { fprintf(stderr, "ERROR - OboeStream_requestStart() returned %d\n", result); result = AAudioStream_requestStart(mStream); if (result != AAUDIO_OK) { fprintf(stderr, "ERROR - AAudioStream_requestStart() returned %d\n", result); return result; } // Give up after several burst periods have passed. const int burstsPerTimeout = 8; oboe_nanoseconds_t nanosPerTimeout = burstsPerTimeout * mFramesPerBurst * OBOE_NANOS_PER_SECOND aaudio_nanoseconds_t nanosPerTimeout = burstsPerTimeout * mFramesPerBurst * AAUDIO_NANOS_PER_SECOND / mFramesPerSecond; while (mEnabled && result >= 0) { Loading @@ -194,23 +194,23 @@ public: mConversionBuffer[i] = (int16_t)(32767.0 * mOutputBuffer[i]); } // Write the application data to stream. result = OboeStream_write(mStream, mConversionBuffer, mFramesPerBurst, nanosPerTimeout); result = AAudioStream_write(mStream, mConversionBuffer, mFramesPerBurst, nanosPerTimeout); } else { // Write the application data to stream. result = OboeStream_write(mStream, mOutputBuffer, mFramesPerBurst, nanosPerTimeout); result = AAudioStream_write(mStream, mOutputBuffer, mFramesPerBurst, nanosPerTimeout); } framesWritten += result; if (result < 0) { fprintf(stderr, "ERROR - OboeStream_write() returned %zd\n", result); fprintf(stderr, "ERROR - AAudioStream_write() returned %zd\n", result); } } result = OboeStream_getXRunCount(mStream, &xRunCount); printf("OboeStream_getXRunCount %d\n", xRunCount); result = AAudioStream_getXRunCount(mStream, &xRunCount); printf("AAudioStream_getXRunCount %d\n", xRunCount); result = OboeStream_requestStop(mStream); if (result != OBOE_OK) { fprintf(stderr, "ERROR - OboeStream_requestStart() returned %d\n", result); result = AAudioStream_requestStop(mStream); if (result != AAUDIO_OK) { fprintf(stderr, "ERROR - AAudioStream_requestStart() returned %d\n", result); return result; } Loading @@ -218,24 +218,24 @@ public: } private: OboeStreamBuilder mBuilder = OBOE_HANDLE_INVALID; OboeStream mStream = OBOE_HANDLE_INVALID; AAudioStreamBuilder mBuilder = AAUDIO_HANDLE_INVALID; AAudioStream mStream = AAUDIO_HANDLE_INVALID; float * mOutputBuffer = nullptr; int16_t * mConversionBuffer = nullptr; audio_callback_proc_t * mCallbackProc = nullptr; void * mUserContext = nullptr; oboe_sharing_mode_t mRequestedSharingMode = SHARING_MODE; aaudio_sharing_mode_t mRequestedSharingMode = SHARING_MODE; int32_t mSamplesPerFrame = 0; int32_t mFramesPerSecond = 0; oboe_size_frames_t mFramesPerBurst = 0; oboe_audio_format_t mDataFormat = OBOE_AUDIO_FORMAT_PCM16; aaudio_size_frames_t mFramesPerBurst = 0; aaudio_audio_format_t mDataFormat = AAUDIO_FORMAT_PCM16; volatile bool mEnabled = false; // used to request that callback exit its loop }; static void *SimpleOboePlayerThreadProc(void *arg) { SimpleOboePlayer *player = (SimpleOboePlayer *) arg; static void *SimpleAAudioPlayerThreadProc(void *arg) { SimpleAAudioPlayer *player = (SimpleAAudioPlayer *) arg; player->callbackLoop(); return nullptr; } Loading @@ -261,17 +261,17 @@ int MyCallbackProc(float *outputBuffer, int32_t numFrames, void *userContext) { int main(int argc, char **argv) { (void)argc; // unused SimpleOboePlayer player; SimpleAAudioPlayer player; SineThreadedData_t myData; oboe_result_t result; aaudio_result_t result; // 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 wave using an Oboe Thread\n", argv[0]); printf("%s - Play a sine wave using an AAudio Thread\n", argv[0]); result = player.open(MyCallbackProc, &myData); if (result != OBOE_OK) { if (result != AAUDIO_OK) { fprintf(stderr, "ERROR - player.open() returned %d\n", result); goto error; } Loading @@ -284,7 +284,7 @@ int main(int argc, char **argv) myData.samplesPerFrame = player.getSamplesPerFrame(); result = player.start(); if (result != OBOE_OK) { if (result != AAUDIO_OK) { fprintf(stderr, "ERROR - player.start() returned %d\n", result); goto error; } Loading @@ -299,12 +299,12 @@ int main(int argc, char **argv) printf("Woke up now.\n"); result = player.stop(); if (result != OBOE_OK) { if (result != AAUDIO_OK) { fprintf(stderr, "ERROR - player.stop() returned %d\n", result); goto error; } result = player.close(); if (result != OBOE_OK) { if (result != AAUDIO_OK) { fprintf(stderr, "ERROR - player.close() returned %d\n", result); goto error; } Loading @@ -313,7 +313,7 @@ int main(int argc, char **argv) return EXIT_SUCCESS; error: player.close(); printf("exiting - Oboe result = %d = %s\n", result, Oboe_convertResultToText(result)); printf("exiting - AAudio result = %d = %s\n", result, AAudio_convertResultToText(result)); return EXIT_FAILURE; } Loading
media/liboboe/Android.bp +3 −3 Original line number Diff line number Diff line Loading @@ -13,11 +13,11 @@ // limitations under the License. ndk_headers { name: "libOboe_headers", name: "libAAudio_headers", from: "include", to: "", srcs: ["include/oboe/*.h"], license: "include/oboe/NOTICE", srcs: ["include/aaudio/*.h"], license: "include/aaudio/NOTICE", } ndk_library { Loading
media/liboboe/README.md +1 −1 Original line number Diff line number Diff line Oboe Audio input/output API AAudio Audio input/output API
media/liboboe/examples/write_sine/README.md +2 −2 Original line number Diff line number Diff line # cd to this directory mkdir -p jni/include/oboe ln -s $PLATFORM/frameworks/av/media/liboboe/include/oboe/*.h jni/include/oboe mkdir -p jni/include/aaudio ln -s $PLATFORM/frameworks/av/media/liboboe/include/aaudio/*.h jni/include/aaudio ln -s $PLATFORM/out/target/product/$TARGET_PRODUCT/symbols/out/soong/ndk/platforms/android-current/arch-arm64/usr/lib/liboboe.so jni $NDK/ndk-build adb push libs/arm64-v8a/write_sine_threaded /data Loading
media/liboboe/examples/write_sine/src/write_sine.cpp +64 −64 Original line number Diff line number Diff line Loading @@ -14,31 +14,31 @@ * limitations under the License. */ // Play sine waves using Oboe. // Play sine waves using AAudio. #include <stdio.h> #include <stdlib.h> #include <math.h> #include <oboe/OboeDefinitions.h> #include <oboe/OboeAudio.h> #include <aaudio/AAudioDefinitions.h> #include <aaudio/AAudio.h> #include "SineGenerator.h" #define SAMPLE_RATE 48000 #define NUM_SECONDS 10 static const char *getSharingModeText(oboe_sharing_mode_t mode) { static const char *getSharingModeText(aaudio_sharing_mode_t mode) { const char *modeText = "unknown"; switch (mode) { case OBOE_SHARING_MODE_EXCLUSIVE: case AAUDIO_SHARING_MODE_EXCLUSIVE: modeText = "EXCLUSIVE"; break; case OBOE_SHARING_MODE_LEGACY: case AAUDIO_SHARING_MODE_LEGACY: modeText = "LEGACY"; break; case OBOE_SHARING_MODE_SHARED: case AAUDIO_SHARING_MODE_SHARED: modeText = "SHARED"; break; case OBOE_SHARING_MODE_PUBLIC_MIX: case AAUDIO_SHARING_MODE_PUBLIC_MIX: modeText = "PUBLIC_MIX"; break; default: Loading @@ -51,25 +51,25 @@ int main(int argc, char **argv) { (void)argc; // unused oboe_result_t result = OBOE_OK; aaudio_result_t result = AAUDIO_OK; const int requestedSamplesPerFrame = 2; int actualSamplesPerFrame = 0; const int requestedSampleRate = SAMPLE_RATE; int actualSampleRate = 0; const oboe_audio_format_t requestedDataFormat = OBOE_AUDIO_FORMAT_PCM16; oboe_audio_format_t actualDataFormat = OBOE_AUDIO_FORMAT_PCM16; const oboe_sharing_mode_t requestedSharingMode = OBOE_SHARING_MODE_EXCLUSIVE; //const oboe_sharing_mode_t requestedSharingMode = OBOE_SHARING_MODE_LEGACY; oboe_sharing_mode_t actualSharingMode = OBOE_SHARING_MODE_LEGACY; OboeStreamBuilder oboeBuilder = OBOE_STREAM_BUILDER_NONE; OboeStream oboeStream = OBOE_STREAM_NONE; oboe_stream_state_t state = OBOE_STREAM_STATE_UNINITIALIZED; oboe_size_frames_t framesPerBurst = 0; oboe_size_frames_t framesToPlay = 0; oboe_size_frames_t framesLeft = 0; const aaudio_audio_format_t requestedDataFormat = AAUDIO_FORMAT_PCM16; aaudio_audio_format_t actualDataFormat = AAUDIO_FORMAT_PCM16; const aaudio_sharing_mode_t requestedSharingMode = AAUDIO_SHARING_MODE_EXCLUSIVE; //const aaudio_sharing_mode_t requestedSharingMode = AAUDIO_SHARING_MODE_LEGACY; aaudio_sharing_mode_t actualSharingMode = AAUDIO_SHARING_MODE_LEGACY; AAudioStreamBuilder aaudioBuilder = AAUDIO_STREAM_BUILDER_NONE; AAudioStream aaudioStream = AAUDIO_STREAM_NONE; aaudio_stream_state_t state = AAUDIO_STREAM_STATE_UNINITIALIZED; aaudio_size_frames_t framesPerBurst = 0; aaudio_size_frames_t framesToPlay = 0; aaudio_size_frames_t framesLeft = 0; int32_t xRunCount = 0; int16_t *data = nullptr; Loading @@ -80,64 +80,64 @@ int main(int argc, char **argv) // in a buffer if we hang or crash. setvbuf(stdout, nullptr, _IONBF, (size_t) 0); printf("%s - Play a sine wave using Oboe\n", argv[0]); printf("%s - Play a sine wave using AAudio\n", argv[0]); // Use an OboeStreamBuilder to contain requested parameters. result = Oboe_createStreamBuilder(&oboeBuilder); if (result != OBOE_OK) { // Use an AAudioStreamBuilder to contain requested parameters. result = AAudio_createStreamBuilder(&aaudioBuilder); if (result != AAUDIO_OK) { goto finish; } // Request stream properties. result = OboeStreamBuilder_setSampleRate(oboeBuilder, requestedSampleRate); if (result != OBOE_OK) { result = AAudioStreamBuilder_setSampleRate(aaudioBuilder, requestedSampleRate); if (result != AAUDIO_OK) { goto finish; } result = OboeStreamBuilder_setSamplesPerFrame(oboeBuilder, requestedSamplesPerFrame); if (result != OBOE_OK) { result = AAudioStreamBuilder_setSamplesPerFrame(aaudioBuilder, requestedSamplesPerFrame); if (result != AAUDIO_OK) { goto finish; } result = OboeStreamBuilder_setFormat(oboeBuilder, requestedDataFormat); if (result != OBOE_OK) { result = AAudioStreamBuilder_setFormat(aaudioBuilder, requestedDataFormat); if (result != AAUDIO_OK) { goto finish; } result = OboeStreamBuilder_setSharingMode(oboeBuilder, requestedSharingMode); if (result != OBOE_OK) { result = AAudioStreamBuilder_setSharingMode(aaudioBuilder, requestedSharingMode); if (result != AAUDIO_OK) { goto finish; } // Create an OboeStream using the Builder. result = OboeStreamBuilder_openStream(oboeBuilder, &oboeStream); printf("oboeStream 0x%08x\n", oboeStream); if (result != OBOE_OK) { // Create an AAudioStream using the Builder. result = AAudioStreamBuilder_openStream(aaudioBuilder, &aaudioStream); printf("aaudioStream 0x%08x\n", aaudioStream); if (result != AAUDIO_OK) { goto finish; } result = OboeStream_getState(oboeStream, &state); printf("after open, state = %s\n", Oboe_convertStreamStateToText(state)); result = AAudioStream_getState(aaudioStream, &state); printf("after open, state = %s\n", AAudio_convertStreamStateToText(state)); // Check to see what kind of stream we actually got. result = OboeStream_getSampleRate(oboeStream, &actualSampleRate); result = AAudioStream_getSampleRate(aaudioStream, &actualSampleRate); printf("SampleRate: requested = %d, actual = %d\n", requestedSampleRate, actualSampleRate); sineOsc1.setup(440.0, actualSampleRate); sineOsc2.setup(660.0, actualSampleRate); result = OboeStream_getSamplesPerFrame(oboeStream, &actualSamplesPerFrame); result = AAudioStream_getSamplesPerFrame(aaudioStream, &actualSamplesPerFrame); printf("SamplesPerFrame: requested = %d, actual = %d\n", requestedSamplesPerFrame, actualSamplesPerFrame); result = OboeStream_getSharingMode(oboeStream, &actualSharingMode); result = AAudioStream_getSharingMode(aaudioStream, &actualSharingMode); printf("SharingMode: requested = %s, actual = %s\n", getSharingModeText(requestedSharingMode), getSharingModeText(actualSharingMode)); // This is the number of frames that are read in one chunk by a DMA controller // or a DSP or a mixer. result = OboeStream_getFramesPerBurst(oboeStream, &framesPerBurst); result = AAudioStream_getFramesPerBurst(aaudioStream, &framesPerBurst); printf("DataFormat: original framesPerBurst = %d\n",framesPerBurst); if (result != OBOE_OK) { fprintf(stderr, "ERROR - OboeStream_getFramesPerBurst() returned %d\n", result); if (result != AAUDIO_OK) { fprintf(stderr, "ERROR - AAudioStream_getFramesPerBurst() returned %d\n", result); goto finish; } // Some DMA might use very short bursts of 16 frames. We don't need to write such small Loading @@ -147,7 +147,7 @@ int main(int argc, char **argv) } printf("DataFormat: final framesPerBurst = %d\n",framesPerBurst); OboeStream_getFormat(oboeStream, &actualDataFormat); AAudioStream_getFormat(aaudioStream, &actualDataFormat); printf("DataFormat: requested = %d, actual = %d\n", requestedDataFormat, actualDataFormat); // TODO handle other data formats Loading @@ -155,20 +155,20 @@ int main(int argc, char **argv) data = new int16_t[framesPerBurst * actualSamplesPerFrame]; if (data == nullptr) { fprintf(stderr, "ERROR - could not allocate data buffer\n"); result = OBOE_ERROR_NO_MEMORY; result = AAUDIO_ERROR_NO_MEMORY; goto finish; } // Start the stream. printf("call OboeStream_requestStart()\n"); result = OboeStream_requestStart(oboeStream); if (result != OBOE_OK) { fprintf(stderr, "ERROR - OboeStream_requestStart() returned %d\n", result); printf("call AAudioStream_requestStart()\n"); result = AAudioStream_requestStart(aaudioStream); if (result != AAUDIO_OK) { fprintf(stderr, "ERROR - AAudioStream_requestStart() returned %d\n", result); goto finish; } result = OboeStream_getState(oboeStream, &state); printf("after start, state = %s\n", Oboe_convertStreamStateToText(state)); result = AAudioStream_getState(aaudioStream, &state); printf("after start, state = %s\n", AAudio_convertStreamStateToText(state)); // Play for a while. framesToPlay = actualSampleRate * NUM_SECONDS; Loading @@ -181,27 +181,27 @@ int main(int argc, char **argv) } // Write audio data to the stream. oboe_nanoseconds_t timeoutNanos = 100 * OBOE_NANOS_PER_MILLISECOND; aaudio_nanoseconds_t timeoutNanos = 100 * AAUDIO_NANOS_PER_MILLISECOND; int minFrames = (framesToPlay < framesPerBurst) ? framesToPlay : framesPerBurst; int actual = OboeStream_write(oboeStream, data, minFrames, timeoutNanos); int actual = AAudioStream_write(aaudioStream, data, minFrames, timeoutNanos); if (actual < 0) { fprintf(stderr, "ERROR - OboeStream_write() returned %zd\n", actual); fprintf(stderr, "ERROR - AAudioStream_write() returned %zd\n", actual); goto finish; } else if (actual == 0) { fprintf(stderr, "WARNING - OboeStream_write() returned %zd\n", actual); fprintf(stderr, "WARNING - AAudioStream_write() returned %zd\n", actual); goto finish; } framesLeft -= actual; } result = OboeStream_getXRunCount(oboeStream, &xRunCount); printf("OboeStream_getXRunCount %d\n", xRunCount); result = AAudioStream_getXRunCount(aaudioStream, &xRunCount); printf("AAudioStream_getXRunCount %d\n", xRunCount); finish: delete[] data; OboeStream_close(oboeStream); OboeStreamBuilder_delete(oboeBuilder); printf("exiting - Oboe result = %d = %s\n", result, Oboe_convertResultToText(result)); return (result != OBOE_OK) ? EXIT_FAILURE : EXIT_SUCCESS; AAudioStream_close(aaudioStream); AAudioStreamBuilder_delete(aaudioBuilder); printf("exiting - AAudio result = %d = %s\n", result, AAudio_convertResultToText(result)); return (result != AAUDIO_OK) ? EXIT_FAILURE : EXIT_SUCCESS; }
media/liboboe/examples/write_sine/src/write_sine_threaded.cpp +82 −82 Original line number Diff line number Diff line Loading @@ -14,7 +14,7 @@ * limitations under the License. */ // Play sine waves using an Oboe background thread. // Play sine waves using an AAudio background thread. #include <assert.h> #include <unistd.h> Loading @@ -22,34 +22,34 @@ #include <stdio.h> #include <math.h> #include <time.h> #include <oboe/OboeDefinitions.h> #include <oboe/OboeAudio.h> #include <aaudio/AAudioDefinitions.h> #include <aaudio/AAudio.h> #include "SineGenerator.h" #define NUM_SECONDS 10 #define SHARING_MODE OBOE_SHARING_MODE_EXCLUSIVE //#define SHARING_MODE OBOE_SHARING_MODE_LEGACY #define SHARING_MODE AAUDIO_SHARING_MODE_EXCLUSIVE //#define SHARING_MODE AAUDIO_SHARING_MODE_LEGACY // Prototype for a callback. typedef int audio_callback_proc_t(float *outputBuffer, oboe_size_frames_t numFrames, aaudio_size_frames_t numFrames, void *userContext); static void *SimpleOboePlayerThreadProc(void *arg); static void *SimpleAAudioPlayerThreadProc(void *arg); /** * Simple wrapper for Oboe that opens a default stream and then calls * Simple wrapper for AAudio that opens a default stream and then calls * a callback function to fill the output buffers. */ class SimpleOboePlayer { class SimpleAAudioPlayer { public: SimpleOboePlayer() {} virtual ~SimpleOboePlayer() { SimpleAAudioPlayer() {} virtual ~SimpleAAudioPlayer() { close(); }; void setSharingMode(oboe_sharing_mode_t requestedSharingMode) { void setSharingMode(aaudio_sharing_mode_t requestedSharingMode) { mRequestedSharingMode = requestedSharingMode; } Loading @@ -66,34 +66,34 @@ public: /** * Open a stream */ oboe_result_t open(audio_callback_proc_t *proc, void *userContext) { aaudio_result_t open(audio_callback_proc_t *proc, void *userContext) { mCallbackProc = proc; mUserContext = userContext; oboe_result_t result = OBOE_OK; aaudio_result_t result = AAUDIO_OK; // Use an OboeStreamBuilder to contain requested parameters. result = Oboe_createStreamBuilder(&mBuilder); if (result != OBOE_OK) return result; // Use an AAudioStreamBuilder to contain requested parameters. result = AAudio_createStreamBuilder(&mBuilder); if (result != AAUDIO_OK) return result; result = OboeStreamBuilder_setSharingMode(mBuilder, mRequestedSharingMode); if (result != OBOE_OK) goto finish1; result = AAudioStreamBuilder_setSharingMode(mBuilder, mRequestedSharingMode); if (result != AAUDIO_OK) goto finish1; // Open an OboeStream using the Builder. result = OboeStreamBuilder_openStream(mBuilder, &mStream); if (result != OBOE_OK) goto finish1; // Open an AAudioStream using the Builder. result = AAudioStreamBuilder_openStream(mBuilder, &mStream); if (result != AAUDIO_OK) goto finish1; // Check to see what kind of stream we actually got. result = OboeStream_getSampleRate(mStream, &mFramesPerSecond); result = AAudioStream_getSampleRate(mStream, &mFramesPerSecond); printf("open() mFramesPerSecond = %d\n", mFramesPerSecond); if (result != OBOE_OK) goto finish2; result = OboeStream_getSamplesPerFrame(mStream, &mSamplesPerFrame); if (result != AAUDIO_OK) goto finish2; result = AAudioStream_getSamplesPerFrame(mStream, &mSamplesPerFrame); printf("open() mSamplesPerFrame = %d\n", mSamplesPerFrame); if (result != OBOE_OK) goto finish2; if (result != AAUDIO_OK) goto finish2; // This is the number of frames that are read in one chunk by a DMA controller // or a DSP or a mixer. result = OboeStream_getFramesPerBurst(mStream, &mFramesPerBurst); if (result != OBOE_OK) goto finish2; result = AAudioStream_getFramesPerBurst(mStream, &mFramesPerBurst); if (result != AAUDIO_OK) goto finish2; // Some DMA might use very short bursts. We don't need to write such small // buffers. But it helps to use a multiple of the burst size for predictable scheduling. while (mFramesPerBurst < 48) { Loading @@ -101,9 +101,9 @@ public: } printf("DataFormat: final framesPerBurst = %d\n",mFramesPerBurst); result = OboeStream_getFormat(mStream, &mDataFormat); if (result != OBOE_OK) { fprintf(stderr, "ERROR - OboeStream_getFormat() returned %d\n", result); result = AAudioStream_getFormat(mStream, &mDataFormat); if (result != AAUDIO_OK) { fprintf(stderr, "ERROR - AAudioStream_getFormat() returned %d\n", result); goto finish2; } Loading @@ -111,75 +111,75 @@ public: mOutputBuffer = new float[mFramesPerBurst * mSamplesPerFrame]; if (mOutputBuffer == nullptr) { fprintf(stderr, "ERROR - could not allocate data buffer\n"); result = OBOE_ERROR_NO_MEMORY; result = AAUDIO_ERROR_NO_MEMORY; } // If needed allocate a buffer for converting float to int16_t. if (mDataFormat == OBOE_AUDIO_FORMAT_PCM16) { if (mDataFormat == AAUDIO_FORMAT_PCM16) { mConversionBuffer = new int16_t[mFramesPerBurst * mSamplesPerFrame]; if (mConversionBuffer == nullptr) { fprintf(stderr, "ERROR - could not allocate conversion buffer\n"); result = OBOE_ERROR_NO_MEMORY; result = AAUDIO_ERROR_NO_MEMORY; } } return result; finish2: OboeStream_close(mStream); mStream = OBOE_HANDLE_INVALID; AAudioStream_close(mStream); mStream = AAUDIO_HANDLE_INVALID; finish1: OboeStreamBuilder_delete(mBuilder); mBuilder = OBOE_HANDLE_INVALID; AAudioStreamBuilder_delete(mBuilder); mBuilder = AAUDIO_HANDLE_INVALID; return result; } oboe_result_t close() { if (mStream != OBOE_HANDLE_INVALID) { aaudio_result_t close() { if (mStream != AAUDIO_HANDLE_INVALID) { stop(); printf("call OboeStream_close(0x%08x)\n", mStream); fflush(stdout); OboeStream_close(mStream); mStream = OBOE_HANDLE_INVALID; OboeStreamBuilder_delete(mBuilder); mBuilder = OBOE_HANDLE_INVALID; printf("call AAudioStream_close(0x%08x)\n", mStream); fflush(stdout); AAudioStream_close(mStream); mStream = AAUDIO_HANDLE_INVALID; AAudioStreamBuilder_delete(mBuilder); mBuilder = AAUDIO_HANDLE_INVALID; delete mOutputBuffer; mOutputBuffer = nullptr; delete mConversionBuffer; mConversionBuffer = nullptr; } return OBOE_OK; return AAUDIO_OK; } // Start a thread that will call the callback proc. oboe_result_t start() { aaudio_result_t start() { mEnabled = true; oboe_nanoseconds_t nanosPerBurst = mFramesPerBurst * OBOE_NANOS_PER_SECOND aaudio_nanoseconds_t nanosPerBurst = mFramesPerBurst * AAUDIO_NANOS_PER_SECOND / mFramesPerSecond; return OboeStream_createThread(mStream, nanosPerBurst, SimpleOboePlayerThreadProc, return AAudioStream_createThread(mStream, nanosPerBurst, SimpleAAudioPlayerThreadProc, this); } // Tell the thread to stop. oboe_result_t stop() { aaudio_result_t stop() { mEnabled = false; return OboeStream_joinThread(mStream, nullptr, 2 * OBOE_NANOS_PER_SECOND); return AAudioStream_joinThread(mStream, nullptr, 2 * AAUDIO_NANOS_PER_SECOND); } oboe_result_t callbackLoop() { aaudio_result_t callbackLoop() { int32_t framesWritten = 0; int32_t xRunCount = 0; oboe_result_t result = OBOE_OK; aaudio_result_t result = AAUDIO_OK; result = OboeStream_requestStart(mStream); if (result != OBOE_OK) { fprintf(stderr, "ERROR - OboeStream_requestStart() returned %d\n", result); result = AAudioStream_requestStart(mStream); if (result != AAUDIO_OK) { fprintf(stderr, "ERROR - AAudioStream_requestStart() returned %d\n", result); return result; } // Give up after several burst periods have passed. const int burstsPerTimeout = 8; oboe_nanoseconds_t nanosPerTimeout = burstsPerTimeout * mFramesPerBurst * OBOE_NANOS_PER_SECOND aaudio_nanoseconds_t nanosPerTimeout = burstsPerTimeout * mFramesPerBurst * AAUDIO_NANOS_PER_SECOND / mFramesPerSecond; while (mEnabled && result >= 0) { Loading @@ -194,23 +194,23 @@ public: mConversionBuffer[i] = (int16_t)(32767.0 * mOutputBuffer[i]); } // Write the application data to stream. result = OboeStream_write(mStream, mConversionBuffer, mFramesPerBurst, nanosPerTimeout); result = AAudioStream_write(mStream, mConversionBuffer, mFramesPerBurst, nanosPerTimeout); } else { // Write the application data to stream. result = OboeStream_write(mStream, mOutputBuffer, mFramesPerBurst, nanosPerTimeout); result = AAudioStream_write(mStream, mOutputBuffer, mFramesPerBurst, nanosPerTimeout); } framesWritten += result; if (result < 0) { fprintf(stderr, "ERROR - OboeStream_write() returned %zd\n", result); fprintf(stderr, "ERROR - AAudioStream_write() returned %zd\n", result); } } result = OboeStream_getXRunCount(mStream, &xRunCount); printf("OboeStream_getXRunCount %d\n", xRunCount); result = AAudioStream_getXRunCount(mStream, &xRunCount); printf("AAudioStream_getXRunCount %d\n", xRunCount); result = OboeStream_requestStop(mStream); if (result != OBOE_OK) { fprintf(stderr, "ERROR - OboeStream_requestStart() returned %d\n", result); result = AAudioStream_requestStop(mStream); if (result != AAUDIO_OK) { fprintf(stderr, "ERROR - AAudioStream_requestStart() returned %d\n", result); return result; } Loading @@ -218,24 +218,24 @@ public: } private: OboeStreamBuilder mBuilder = OBOE_HANDLE_INVALID; OboeStream mStream = OBOE_HANDLE_INVALID; AAudioStreamBuilder mBuilder = AAUDIO_HANDLE_INVALID; AAudioStream mStream = AAUDIO_HANDLE_INVALID; float * mOutputBuffer = nullptr; int16_t * mConversionBuffer = nullptr; audio_callback_proc_t * mCallbackProc = nullptr; void * mUserContext = nullptr; oboe_sharing_mode_t mRequestedSharingMode = SHARING_MODE; aaudio_sharing_mode_t mRequestedSharingMode = SHARING_MODE; int32_t mSamplesPerFrame = 0; int32_t mFramesPerSecond = 0; oboe_size_frames_t mFramesPerBurst = 0; oboe_audio_format_t mDataFormat = OBOE_AUDIO_FORMAT_PCM16; aaudio_size_frames_t mFramesPerBurst = 0; aaudio_audio_format_t mDataFormat = AAUDIO_FORMAT_PCM16; volatile bool mEnabled = false; // used to request that callback exit its loop }; static void *SimpleOboePlayerThreadProc(void *arg) { SimpleOboePlayer *player = (SimpleOboePlayer *) arg; static void *SimpleAAudioPlayerThreadProc(void *arg) { SimpleAAudioPlayer *player = (SimpleAAudioPlayer *) arg; player->callbackLoop(); return nullptr; } Loading @@ -261,17 +261,17 @@ int MyCallbackProc(float *outputBuffer, int32_t numFrames, void *userContext) { int main(int argc, char **argv) { (void)argc; // unused SimpleOboePlayer player; SimpleAAudioPlayer player; SineThreadedData_t myData; oboe_result_t result; aaudio_result_t result; // 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 wave using an Oboe Thread\n", argv[0]); printf("%s - Play a sine wave using an AAudio Thread\n", argv[0]); result = player.open(MyCallbackProc, &myData); if (result != OBOE_OK) { if (result != AAUDIO_OK) { fprintf(stderr, "ERROR - player.open() returned %d\n", result); goto error; } Loading @@ -284,7 +284,7 @@ int main(int argc, char **argv) myData.samplesPerFrame = player.getSamplesPerFrame(); result = player.start(); if (result != OBOE_OK) { if (result != AAUDIO_OK) { fprintf(stderr, "ERROR - player.start() returned %d\n", result); goto error; } Loading @@ -299,12 +299,12 @@ int main(int argc, char **argv) printf("Woke up now.\n"); result = player.stop(); if (result != OBOE_OK) { if (result != AAUDIO_OK) { fprintf(stderr, "ERROR - player.stop() returned %d\n", result); goto error; } result = player.close(); if (result != OBOE_OK) { if (result != AAUDIO_OK) { fprintf(stderr, "ERROR - player.close() returned %d\n", result); goto error; } Loading @@ -313,7 +313,7 @@ int main(int argc, char **argv) return EXIT_SUCCESS; error: player.close(); printf("exiting - Oboe result = %d = %s\n", result, Oboe_convertResultToText(result)); printf("exiting - AAudio result = %d = %s\n", result, AAudio_convertResultToText(result)); return EXIT_FAILURE; }