21 #include <aaudio/AAudio.h>
24 using namespace Audio;
36 return AAUDIO_CALLBACK_RESULT_CONTINUE;
44 inline void check(aaudio_result_t code,
const char* message) {
45 if (code < AAUDIO_OK) {
46 std::string report(message);
47 report = report +
'\n' + AAudio_convertResultToText(code);
57 AAudioStream_close(
stream);
63 check(AAudioStream_close(
stream),
"Error when closing stream");
68 AAudioStreamBuilder *builder;
69 check(AAudio_createStreamBuilder(&builder),
70 "Error when creating stream builder.");
77 AAudioStreamBuilder_setFormat(builder, AAUDIO_FORMAT_PCM_I16);
80 AAudioStreamBuilder_setFormat(builder, AAUDIO_FORMAT_PCM_FLOAT);
89 AAudioStreamBuilder_setSharingMode(builder, AAUDIO_SHARING_MODE_EXCLUSIVE);
91 AAudioStreamBuilder_setPerformanceMode(builder, AAUDIO_PERFORMANCE_MODE_LOW_LATENCY);
94 check(AAudioStreamBuilder_openStream(builder, &
stream),
95 "Error when opening stream");
100 " sharing mode: %d\n"
101 " performance mode: %d\n",
103 (
int)AAudioStream_getDeviceId(
stream),
104 (
int)AAudioStream_getSharingMode(
stream),
105 (
int)AAudioStream_getPerformanceMode(
stream));
109 AAudioStreamBuilder_delete(builder);
115 "Error when requesting start of a stream");
117 aaudio_stream_state_t nextState = AAUDIO_STREAM_STATE_STARTED;
119 "Error when starting a stream");
125 "Error when requesting stop of a stream");
127 aaudio_stream_state_t nextState = AAUDIO_STREAM_STATE_STOPPED;
129 "Error when stopping a stream");
144 backend->initialize(
this,
mode);
aaudio_data_callback_result_t aaudioDataCallback(AAudioStream *stream, void *userData, void *audioData, int32_t numFrames)
static const int64_t ONE_SECOND_IN_NANOS
void initialize(BasicRealtimePlayback *frontend, AbstractPlayback::Mode mode)
void check(aaudio_result_t code, const char *message)
void initialize(Mode mode)
Initializes the playback setting its main parameters.
void stop()
Stops playback.
void start()
Starts playback.
OutputMode
Specifies how the output audio signal is handled by the audio backend.
void initialize(Mode mode)
Initializes the playback setting its main parameters.
virtual void start()
Starts playback.
Communicates an error occurred during the playback.
#define BEATMUP_DEBUG_I(...)
@ Float32
floating point, 32 bit per sample
@ Int16
signed integer, 16 bit per sample
AudioSampleFormat sampleFormat
format of each sample
dtime sampleRate
samples per second / sample rate in Hz
unsigned char numChannels
number of channels
dtime bufferLength
length of each atomic buffer in samples