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/main.h>
int bj_app_begin(void** user_data, int argc, char* argv[]) {
(void)user_data; (void)argc; (void)argv;
return bj_callback_exit_error;
}
.amplitude = 16000,
.sample_rate = 44100,
.channels = 2,
if (p_device == 0) {
if (p_error) {
}
return bj_callback_exit_error;
}
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;
return status;
}
General-purpose definitions for Banjo API.
Basic audio library interface.
bj_audio_device * bj_open_audio_device(const bj_audio_properties *p_properties, bj_audio_callback_t p_callback, void *p_callback_user_data, bj_error **p_error)
Open the default audio device for playback.
struct bj_audio_properties_t bj_audio_properties
Describe properties of an audio device.
struct bj_audio_device_t bj_audio_device
Opaque handle to an audio device instance.
Definition audio.h:24
void bj_audio_play_note(void *buffer, unsigned frames, const bj_audio_properties *audio, void *user_data, uint64_t base_sample_index)
Generate a basic waveform tone using a built-in callback.
void bj_audio_device_play(bj_audio_device *p_device)
Resume audio playback.
struct bj_audio_play_note_data_t bj_audio_play_note_data
Define parameters for generating simple waveforms.
void bj_close_audio_device(bj_audio_device *p_device)
Close an audio device and release all associated resources.
@ BJ_AUDIO_FORMAT_F32
!< 16-bit signed integer
Definition audio.h:35
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 since Banjo initialization.
Logging utility functions.
Header file for system interactions.
Header file for time manipulation utilities.