An example on how to use the callback-based audio API for raw PCM output.
An example on how to use the callback-based audio API for raw PCM output.
#define BJ_AUTOMAIN_CALLBACKS
#include <banjo/audio.h>
#include <banjo/main.h>
bj_audio_play_note_data data = {0};
bj_audio_device* p_device = 0;
int bj_app_begin(void** user_data, int argc, char* argv[]) {
(void)user_data; (void)argc; (void)argv;
return bj_callback_exit_error;
}
p_device = bj_open_audio_device(&p_error, bj_audio_play_note, &data);
if (p_device == 0) {
if (p_error) {
}
return bj_callback_exit_error;
}
bj_audio_device_play(p_device);
return bj_callback_continue;
}
int bj_app_iterate(void* user_data) {
(void)user_data;
static const double melody[] = {
261.63, 293.66, 329.63,
349.23, 392.00, 349.23,
329.63, 293.66, 261.63
};
data.frequency = melody[note];
return note >= 9
? bj_callback_exit_success
: bj_callback_continue;
}
int bj_app_end(void* user_data, int status) {
(void)user_data;
bj_close_audio_device(p_device);
return status;
}
General-purpose definitions for Banjo API.
uint32_t code
Error code.
Definition error.h:132
char message[BJ_ERROR_MESSAGE_MAX_LEN+1]
Optional error description.
Definition error.h:133
Error structure.
Definition error.h:131
#define bj_err(...)
Log a message using the BJ_LOG_ERROR level.
Definition log.h:131
void bj_end(bj_error **p_error)
De-initializes the system.
bj_bool bj_begin(bj_error **p_error)
Initializes the system.
double bj_get_time(void)
Gets the current time in seconds.
Logging utility functions.
Header file for system interactions.
Header file for time manipulation.