Loading media/libaaudio/examples/write_sine/src/write_sine.cpp +15 −15 Original line number Diff line number Diff line Loading @@ -63,8 +63,8 @@ int main(int argc, char **argv) aaudio_result_t result = AAUDIO_OK; const int requestedSamplesPerFrame = 2; int actualSamplesPerFrame = 0; const int requestedChannelCount = 2; int actualChannelCount = 0; const int requestedSampleRate = SAMPLE_RATE; int actualSampleRate = 0; aaudio_audio_format_t actualDataFormat = AAUDIO_FORMAT_UNSPECIFIED; Loading @@ -90,7 +90,7 @@ 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 AAudio, Z2\n", argv[0]); printf("%s - Play a sine wave using AAudio\n", argv[0]); // Use an AAudioStreamBuilder to contain requested parameters. result = AAudio_createStreamBuilder(&aaudioBuilder); Loading @@ -100,7 +100,7 @@ int main(int argc, char **argv) // Request stream properties. AAudioStreamBuilder_setSampleRate(aaudioBuilder, requestedSampleRate); AAudioStreamBuilder_setSamplesPerFrame(aaudioBuilder, requestedSamplesPerFrame); AAudioStreamBuilder_setChannelCount(aaudioBuilder, requestedChannelCount); AAudioStreamBuilder_setFormat(aaudioBuilder, REQUESTED_FORMAT); AAudioStreamBuilder_setSharingMode(aaudioBuilder, REQUESTED_SHARING_MODE); Loading @@ -120,9 +120,9 @@ int main(int argc, char **argv) sineOsc1.setup(440.0, actualSampleRate); sineOsc2.setup(660.0, actualSampleRate); actualSamplesPerFrame = AAudioStream_getSamplesPerFrame(aaudioStream); printf("SamplesPerFrame: requested = %d, actual = %d\n", requestedSamplesPerFrame, actualSamplesPerFrame); actualChannelCount = AAudioStream_getChannelCount(aaudioStream); printf("ChannelCount: requested = %d, actual = %d\n", requestedChannelCount, actualChannelCount); actualSharingMode = AAudioStream_getSharingMode(aaudioStream); printf("SharingMode: requested = %s, actual = %s\n", Loading Loading @@ -152,9 +152,9 @@ int main(int argc, char **argv) // Allocate a buffer for the audio data. if (actualDataFormat == AAUDIO_FORMAT_PCM_FLOAT) { floatData = new float[framesPerWrite * actualSamplesPerFrame]; floatData = new float[framesPerWrite * actualChannelCount]; } else if (actualDataFormat == AAUDIO_FORMAT_PCM_I16) { shortData = new int16_t[framesPerWrite * actualSamplesPerFrame]; shortData = new int16_t[framesPerWrite * actualChannelCount]; } else { printf("ERROR Unsupported data format!\n"); goto finish; Loading @@ -178,15 +178,15 @@ int main(int argc, char **argv) if (actualDataFormat == AAUDIO_FORMAT_PCM_FLOAT) { // Render sine waves to left and right channels. sineOsc1.render(&floatData[0], actualSamplesPerFrame, framesPerWrite); if (actualSamplesPerFrame > 1) { sineOsc2.render(&floatData[1], actualSamplesPerFrame, framesPerWrite); sineOsc1.render(&floatData[0], actualChannelCount, framesPerWrite); if (actualChannelCount > 1) { sineOsc2.render(&floatData[1], actualChannelCount, framesPerWrite); } } else if (actualDataFormat == AAUDIO_FORMAT_PCM_I16) { // Render sine waves to left and right channels. sineOsc1.render(&shortData[0], actualSamplesPerFrame, framesPerWrite); if (actualSamplesPerFrame > 1) { sineOsc2.render(&shortData[1], actualSamplesPerFrame, framesPerWrite); sineOsc1.render(&shortData[0], actualChannelCount, framesPerWrite); if (actualChannelCount > 1) { sineOsc2.render(&shortData[1], actualChannelCount, framesPerWrite); } } Loading media/libaaudio/examples/write_sine/src/write_sine_callback.cpp +5 −5 Original line number Diff line number Diff line Loading @@ -65,11 +65,11 @@ public: /** * Only call this after open() has been called. */ int32_t getSamplesPerFrame() { int32_t getChannelCount() { if (mStream == nullptr) { return AAUDIO_ERROR_INVALID_STATE; } return AAudioStream_getSamplesPerFrame(mStream);; return AAudioStream_getChannelCount(mStream);; } /** Loading Loading @@ -119,7 +119,7 @@ public: // Write zero data to fill up the buffer and prevent underruns. aaudio_result_t prime() { int32_t samplesPerFrame = AAudioStream_getSamplesPerFrame(mStream); int32_t samplesPerFrame = AAudioStream_getChannelCount(mStream); const int numFrames = 32; float zeros[numFrames * samplesPerFrame]; memset(zeros, 0, sizeof(zeros)); Loading Loading @@ -186,7 +186,7 @@ aaudio_data_callback_result_t MyDataCallbackProc( sineData->schedulerChecked = true; } int32_t samplesPerFrame = AAudioStream_getSamplesPerFrame(stream); int32_t samplesPerFrame = AAudioStream_getChannelCount(stream); // This code only plays on the first one or two channels. // TODO Support arbitrary number of channels. switch (AAudioStream_getFormat(stream)) { Loading Loading @@ -239,7 +239,7 @@ int main(int argc, char **argv) goto error; } printf("player.getFramesPerSecond() = %d\n", player.getFramesPerSecond()); printf("player.getSamplesPerFrame() = %d\n", player.getSamplesPerFrame()); printf("player.getChannelCount() = %d\n", player.getChannelCount()); myData.sineOsc1.setup(440.0, 48000); myData.sineOsc1.setSweep(300.0, 600.0, 5.0); myData.sineOsc2.setup(660.0, 48000); Loading media/libaaudio/include/aaudio/AAudio.h +22 −4 Original line number Diff line number Diff line Loading @@ -206,18 +206,26 @@ AAUDIO_API void AAudioStreamBuilder_setSampleRate(AAudioStreamBuilder* builder, int32_t sampleRate); /** * Request a number of samples per frame. * Request a number of channels for the stream. * * The stream may be opened with a different value. * So the application should query for the actual value after the stream is opened. * * The default, if you do not call this function, is AAUDIO_UNSPECIFIED. * * Note, this quantity is sometimes referred to as "channel count". * Note, this quantity is sometimes referred to as "samples per frame". * * @param builder reference provided by AAudio_createStreamBuilder() * @param samplesPerFrame Number of samples in one frame, ie. numChannels. * @param channelCount Number of channels desired. */ AAUDIO_API void AAudioStreamBuilder_setChannelCount(AAudioStreamBuilder* builder, int32_t channelCount); /** * * @deprecated use AAudioStreamBuilder_setChannelCount() */ // TODO remove as soon as the NDK and OS are in sync, before RC1 AAUDIO_API void AAudioStreamBuilder_setSamplesPerFrame(AAudioStreamBuilder* builder, int32_t samplesPerFrame); Loading Loading @@ -676,9 +684,19 @@ AAUDIO_API int32_t AAudioStream_getXRunCount(AAudioStream* stream); */ AAUDIO_API int32_t AAudioStream_getSampleRate(AAudioStream* stream); /** * A stream has one or more channels of data. * A frame will contain one sample for each channel. * * @param stream reference provided by AAudioStreamBuilder_openStream() * @return actual number of channels */ AAUDIO_API int32_t AAudioStream_getChannelCount(AAudioStream* stream); /** * The samplesPerFrame is also known as channelCount. * * @deprecated use AAudioStream_getChannelCount() * @param stream reference provided by AAudioStreamBuilder_openStream() * @return actual samples per frame */ Loading media/libaaudio/libaaudio.map.txt +2 −0 Original line number Diff line number Diff line Loading @@ -9,6 +9,7 @@ LIBAAUDIO { AAudioStreamBuilder_setFramesPerDataCallback; AAudioStreamBuilder_setSampleRate; AAudioStreamBuilder_setSamplesPerFrame; AAudioStreamBuilder_setChannelCount; AAudioStreamBuilder_setFormat; AAudioStreamBuilder_setSharingMode; AAudioStreamBuilder_setDirection; Loading @@ -32,6 +33,7 @@ LIBAAUDIO { AAudioStream_getXRunCount; AAudioStream_getSampleRate; AAudioStream_getSamplesPerFrame; AAudioStream_getChannelCount; AAudioStream_getDeviceId; AAudioStream_getFormat; AAudioStream_getSharingMode; Loading media/libaaudio/src/core/AAudioAudio.cpp +14 −1 Original line number Diff line number Diff line Loading @@ -128,6 +128,13 @@ AAUDIO_API void AAudioStreamBuilder_setSampleRate(AAudioStreamBuilder* builder, streamBuilder->setSampleRate(sampleRate); } AAUDIO_API void AAudioStreamBuilder_setChannelCount(AAudioStreamBuilder* builder, int32_t channelCount) { AudioStreamBuilder *streamBuilder = convertAAudioBuilderToStreamBuilder(builder); streamBuilder->setSamplesPerFrame(channelCount); } AAUDIO_API void AAudioStreamBuilder_setSamplesPerFrame(AAudioStreamBuilder* builder, int32_t samplesPerFrame) { Loading Loading @@ -334,6 +341,12 @@ AAUDIO_API int32_t AAudioStream_getSampleRate(AAudioStream* stream) return audioStream->getSampleRate(); } AAUDIO_API int32_t AAudioStream_getChannelCount(AAudioStream* stream) { AudioStream *audioStream = convertAAudioStreamToAudioStream(stream); return audioStream->getSamplesPerFrame(); } AAUDIO_API int32_t AAudioStream_getSamplesPerFrame(AAudioStream* stream) { AudioStream *audioStream = convertAAudioStreamToAudioStream(stream); Loading Loading
media/libaaudio/examples/write_sine/src/write_sine.cpp +15 −15 Original line number Diff line number Diff line Loading @@ -63,8 +63,8 @@ int main(int argc, char **argv) aaudio_result_t result = AAUDIO_OK; const int requestedSamplesPerFrame = 2; int actualSamplesPerFrame = 0; const int requestedChannelCount = 2; int actualChannelCount = 0; const int requestedSampleRate = SAMPLE_RATE; int actualSampleRate = 0; aaudio_audio_format_t actualDataFormat = AAUDIO_FORMAT_UNSPECIFIED; Loading @@ -90,7 +90,7 @@ 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 AAudio, Z2\n", argv[0]); printf("%s - Play a sine wave using AAudio\n", argv[0]); // Use an AAudioStreamBuilder to contain requested parameters. result = AAudio_createStreamBuilder(&aaudioBuilder); Loading @@ -100,7 +100,7 @@ int main(int argc, char **argv) // Request stream properties. AAudioStreamBuilder_setSampleRate(aaudioBuilder, requestedSampleRate); AAudioStreamBuilder_setSamplesPerFrame(aaudioBuilder, requestedSamplesPerFrame); AAudioStreamBuilder_setChannelCount(aaudioBuilder, requestedChannelCount); AAudioStreamBuilder_setFormat(aaudioBuilder, REQUESTED_FORMAT); AAudioStreamBuilder_setSharingMode(aaudioBuilder, REQUESTED_SHARING_MODE); Loading @@ -120,9 +120,9 @@ int main(int argc, char **argv) sineOsc1.setup(440.0, actualSampleRate); sineOsc2.setup(660.0, actualSampleRate); actualSamplesPerFrame = AAudioStream_getSamplesPerFrame(aaudioStream); printf("SamplesPerFrame: requested = %d, actual = %d\n", requestedSamplesPerFrame, actualSamplesPerFrame); actualChannelCount = AAudioStream_getChannelCount(aaudioStream); printf("ChannelCount: requested = %d, actual = %d\n", requestedChannelCount, actualChannelCount); actualSharingMode = AAudioStream_getSharingMode(aaudioStream); printf("SharingMode: requested = %s, actual = %s\n", Loading Loading @@ -152,9 +152,9 @@ int main(int argc, char **argv) // Allocate a buffer for the audio data. if (actualDataFormat == AAUDIO_FORMAT_PCM_FLOAT) { floatData = new float[framesPerWrite * actualSamplesPerFrame]; floatData = new float[framesPerWrite * actualChannelCount]; } else if (actualDataFormat == AAUDIO_FORMAT_PCM_I16) { shortData = new int16_t[framesPerWrite * actualSamplesPerFrame]; shortData = new int16_t[framesPerWrite * actualChannelCount]; } else { printf("ERROR Unsupported data format!\n"); goto finish; Loading @@ -178,15 +178,15 @@ int main(int argc, char **argv) if (actualDataFormat == AAUDIO_FORMAT_PCM_FLOAT) { // Render sine waves to left and right channels. sineOsc1.render(&floatData[0], actualSamplesPerFrame, framesPerWrite); if (actualSamplesPerFrame > 1) { sineOsc2.render(&floatData[1], actualSamplesPerFrame, framesPerWrite); sineOsc1.render(&floatData[0], actualChannelCount, framesPerWrite); if (actualChannelCount > 1) { sineOsc2.render(&floatData[1], actualChannelCount, framesPerWrite); } } else if (actualDataFormat == AAUDIO_FORMAT_PCM_I16) { // Render sine waves to left and right channels. sineOsc1.render(&shortData[0], actualSamplesPerFrame, framesPerWrite); if (actualSamplesPerFrame > 1) { sineOsc2.render(&shortData[1], actualSamplesPerFrame, framesPerWrite); sineOsc1.render(&shortData[0], actualChannelCount, framesPerWrite); if (actualChannelCount > 1) { sineOsc2.render(&shortData[1], actualChannelCount, framesPerWrite); } } Loading
media/libaaudio/examples/write_sine/src/write_sine_callback.cpp +5 −5 Original line number Diff line number Diff line Loading @@ -65,11 +65,11 @@ public: /** * Only call this after open() has been called. */ int32_t getSamplesPerFrame() { int32_t getChannelCount() { if (mStream == nullptr) { return AAUDIO_ERROR_INVALID_STATE; } return AAudioStream_getSamplesPerFrame(mStream);; return AAudioStream_getChannelCount(mStream);; } /** Loading Loading @@ -119,7 +119,7 @@ public: // Write zero data to fill up the buffer and prevent underruns. aaudio_result_t prime() { int32_t samplesPerFrame = AAudioStream_getSamplesPerFrame(mStream); int32_t samplesPerFrame = AAudioStream_getChannelCount(mStream); const int numFrames = 32; float zeros[numFrames * samplesPerFrame]; memset(zeros, 0, sizeof(zeros)); Loading Loading @@ -186,7 +186,7 @@ aaudio_data_callback_result_t MyDataCallbackProc( sineData->schedulerChecked = true; } int32_t samplesPerFrame = AAudioStream_getSamplesPerFrame(stream); int32_t samplesPerFrame = AAudioStream_getChannelCount(stream); // This code only plays on the first one or two channels. // TODO Support arbitrary number of channels. switch (AAudioStream_getFormat(stream)) { Loading Loading @@ -239,7 +239,7 @@ int main(int argc, char **argv) goto error; } printf("player.getFramesPerSecond() = %d\n", player.getFramesPerSecond()); printf("player.getSamplesPerFrame() = %d\n", player.getSamplesPerFrame()); printf("player.getChannelCount() = %d\n", player.getChannelCount()); myData.sineOsc1.setup(440.0, 48000); myData.sineOsc1.setSweep(300.0, 600.0, 5.0); myData.sineOsc2.setup(660.0, 48000); Loading
media/libaaudio/include/aaudio/AAudio.h +22 −4 Original line number Diff line number Diff line Loading @@ -206,18 +206,26 @@ AAUDIO_API void AAudioStreamBuilder_setSampleRate(AAudioStreamBuilder* builder, int32_t sampleRate); /** * Request a number of samples per frame. * Request a number of channels for the stream. * * The stream may be opened with a different value. * So the application should query for the actual value after the stream is opened. * * The default, if you do not call this function, is AAUDIO_UNSPECIFIED. * * Note, this quantity is sometimes referred to as "channel count". * Note, this quantity is sometimes referred to as "samples per frame". * * @param builder reference provided by AAudio_createStreamBuilder() * @param samplesPerFrame Number of samples in one frame, ie. numChannels. * @param channelCount Number of channels desired. */ AAUDIO_API void AAudioStreamBuilder_setChannelCount(AAudioStreamBuilder* builder, int32_t channelCount); /** * * @deprecated use AAudioStreamBuilder_setChannelCount() */ // TODO remove as soon as the NDK and OS are in sync, before RC1 AAUDIO_API void AAudioStreamBuilder_setSamplesPerFrame(AAudioStreamBuilder* builder, int32_t samplesPerFrame); Loading Loading @@ -676,9 +684,19 @@ AAUDIO_API int32_t AAudioStream_getXRunCount(AAudioStream* stream); */ AAUDIO_API int32_t AAudioStream_getSampleRate(AAudioStream* stream); /** * A stream has one or more channels of data. * A frame will contain one sample for each channel. * * @param stream reference provided by AAudioStreamBuilder_openStream() * @return actual number of channels */ AAUDIO_API int32_t AAudioStream_getChannelCount(AAudioStream* stream); /** * The samplesPerFrame is also known as channelCount. * * @deprecated use AAudioStream_getChannelCount() * @param stream reference provided by AAudioStreamBuilder_openStream() * @return actual samples per frame */ Loading
media/libaaudio/libaaudio.map.txt +2 −0 Original line number Diff line number Diff line Loading @@ -9,6 +9,7 @@ LIBAAUDIO { AAudioStreamBuilder_setFramesPerDataCallback; AAudioStreamBuilder_setSampleRate; AAudioStreamBuilder_setSamplesPerFrame; AAudioStreamBuilder_setChannelCount; AAudioStreamBuilder_setFormat; AAudioStreamBuilder_setSharingMode; AAudioStreamBuilder_setDirection; Loading @@ -32,6 +33,7 @@ LIBAAUDIO { AAudioStream_getXRunCount; AAudioStream_getSampleRate; AAudioStream_getSamplesPerFrame; AAudioStream_getChannelCount; AAudioStream_getDeviceId; AAudioStream_getFormat; AAudioStream_getSharingMode; Loading
media/libaaudio/src/core/AAudioAudio.cpp +14 −1 Original line number Diff line number Diff line Loading @@ -128,6 +128,13 @@ AAUDIO_API void AAudioStreamBuilder_setSampleRate(AAudioStreamBuilder* builder, streamBuilder->setSampleRate(sampleRate); } AAUDIO_API void AAudioStreamBuilder_setChannelCount(AAudioStreamBuilder* builder, int32_t channelCount) { AudioStreamBuilder *streamBuilder = convertAAudioBuilderToStreamBuilder(builder); streamBuilder->setSamplesPerFrame(channelCount); } AAUDIO_API void AAudioStreamBuilder_setSamplesPerFrame(AAudioStreamBuilder* builder, int32_t samplesPerFrame) { Loading Loading @@ -334,6 +341,12 @@ AAUDIO_API int32_t AAudioStream_getSampleRate(AAudioStream* stream) return audioStream->getSampleRate(); } AAUDIO_API int32_t AAudioStream_getChannelCount(AAudioStream* stream) { AudioStream *audioStream = convertAAudioStreamToAudioStream(stream); return audioStream->getSamplesPerFrame(); } AAUDIO_API int32_t AAudioStream_getSamplesPerFrame(AAudioStream* stream) { AudioStream *audioStream = convertAAudioStreamToAudioStream(stream); Loading