|
Banjo API 0.0.1
C99 game development API
|
Data Structures | |
| struct | bj_audio_properties_t |
| struct | bj_audio_play_note_data_t |
| struct | bj_audio_layer_t |
| struct | bj_audio_layer_create_info |
Macros | |
| #define | BJ_AUDIO_FORMAT_WIDTH(x) |
| #define | BJ_AUDIO_FORMAT_FLOAT(x) |
| #define | BJ_AUDIO_FORMAT_INT(x) |
| #define | BJ_AUDIO_FORMAT_BIG_ENDIAN(x) |
| #define | BJ_AUDIO_FORMAT_SIGNED(x) |
Typedefs | |
| typedef struct bj_audio_device_t | bj_audio_device |
| typedef enum bj_audio_format_t | bj_audio_format |
| typedef struct bj_audio_properties_t | bj_audio_properties |
| typedef void(* | bj_audio_callback_t) (void *buffer, unsigned frames, const bj_audio_properties *audio, void *user_data, uint64_t base_sample_index) |
| typedef struct bj_audio_play_note_data_t | bj_audio_play_note_data |
| typedef struct bj_audio_layer_t | bj_audio_layer |
Enumerations | |
| enum | bj_audio_format_t { BJ_AUDIO_FORMAT_UNKNOWN = 0x0000 , BJ_AUDIO_FORMAT_INT16 = 0x8010 , BJ_AUDIO_FORMAT_F32 = 0x8120 } |
Functions | |
| 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) |
| void | bj_close_audio_device (bj_audio_device *p_device) |
| void | bj_play_audio_device (bj_audio_device *p_device) |
| void | bj_pause_audio_device (bj_audio_device *p_device) |
| void | bj_reset_audio_device (bj_audio_device *p_device) |
| void | bj_stop_audio_device (bj_audio_device *p_device) |
| bj_bool | bj_audio_playing (const bj_audio_device *p_device) |
| void | bj_play_audio_note (void *buffer, unsigned frames, const bj_audio_properties *audio, void *user_data, uint64_t base_sample_index) |
Provide basic PCM audio playback.
The audio component offers 1-channel Pulse-Code Modulation (PCM) playback with a callback-based interface, suitable for retro-style games and basic procedural sound generation.
Banjo supports audio manipulation for Windows, GNU/Linux and WebAssembly.
Add support for audio on macOS
Add support for audio push-based API
Add support for audio WAVE format
Add support for audio MIDI format
| struct bj_audio_properties_t |
Describe properties of an audio device.
This structure is passed to audio callbacks to inform them about the format and limits of the current playback device.
| Data Fields | ||
|---|---|---|
| int16_t | amplitude | Maximum amplitude of the output samples. |
| unsigned int | channels | Number of channels (currently always 1). |
| bj_audio_format | format | Sampling format. |
| unsigned int | sample_rate | Number of samples per second (Hz). |
| struct bj_audio_layer_t |
Represent an audio backend (ALSA, MME, etc).
Internal structure used to abstract platform-specific device control.
| Data Fields | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| void(*)(struct bj_audio_layer_t *self, bj_audio_device *device) | close_device |
Close an audio device managed by this backend. Used to stop and destroy a specific audio device instance.
| ||||||||||
| struct bj_audio_layer_data_t * | data |
Backend-specific data pointer. Used internally by the backend to store platform-specific state. | ||||||||||
| void(*)(struct bj_audio_layer_t *self, bj_error **p_error) | end |
Shutdown and clean up the backend. Called during deinitialization to release all backend-related resources.
| ||||||||||
| bj_audio_device *(*)(struct bj_audio_layer_t *self, const bj_audio_properties *p_properties, bj_audio_callback_t callback, void *user_data, bj_error **p_error) | open_device |
Open an audio device through this backend. Initializes a new audio device using the given properties and callback.
| ||||||||||
| struct bj_audio_layer_create_info |
Declare a backend and its constructor function.
Used at initialization to register available backends such as ALSA, MME, or WebAudio.

| Data Fields | ||
|---|---|---|
| bj_audio_layer *(*)(bj_error **) | create | Factory function to instantiate the backend. |
| const char * | name | Name of the backend (e.g., "alsa", "mme"). |
| #define BJ_AUDIO_FORMAT_BIG_ENDIAN | ( | x | ) |
Test whether the audio format uses big-endian byte order.
| x | Audio format code (bj_audio_format). |
| #define BJ_AUDIO_FORMAT_FLOAT | ( | x | ) |
Test whether the audio format is floating point.
| x | Audio format code (bj_audio_format). |
| #define BJ_AUDIO_FORMAT_INT | ( | x | ) |
Test whether the audio format is integer PCM.
| x | Audio format code (bj_audio_format). |
| #define BJ_AUDIO_FORMAT_SIGNED | ( | x | ) |
Test whether integer samples are signed.
| x | Audio format code (bj_audio_format). |
| #define BJ_AUDIO_FORMAT_WIDTH | ( | x | ) |
Extract the sample width (in bits) from an audio format code.
| x | Audio format code (bj_audio_format). |
| typedef void(* bj_audio_callback_t) (void *buffer, unsigned frames, const bj_audio_properties *audio, void *user_data, uint64_t base_sample_index) |
Define a callback for generating audio samples.
This callback is called periodically from a dedicated audio thread to generate PCM audio data.
| buffer | Output buffer to write int16_t samples into. |
| frames | Number of audio frames to generate. |
| audio | Pointer to audio device properties (read-only). |
| user_data | User-defined pointer passed at device creation. |
| base_sample_index | Index of the first sample in the current buffer. |
| typedef struct bj_audio_device_t bj_audio_device |
Opaque handle to an audio device instance.
Instances are created with bj_open_audio_device and must be released with bj_close_audio_device.
| typedef enum bj_audio_format_t bj_audio_format |
Audio sample format descriptor.
Encodes sample width, sign, float/integer, and endianness flags. Use the helper macros to inspect properties.
| typedef struct bj_audio_layer_t bj_audio_layer |
Represent an audio backend (ALSA, MME, etc).
Internal structure used to abstract platform-specific device control.
| typedef struct bj_audio_play_note_data_t bj_audio_play_note_data |
Define parameters for generating simple waveforms.
Used with bj_play_audio_note to synthesize tones such as sine or square.
| typedef struct bj_audio_properties_t bj_audio_properties |
Describe properties of an audio device.
This structure is passed to audio callbacks to inform them about the format and limits of the current playback device.
| enum bj_audio_format_t |
Audio sample format descriptor.
Encodes sample width, sign, float/integer, and endianness flags. Use the helper macros to inspect properties.
| Enumerator | |
|---|---|
| BJ_AUDIO_FORMAT_UNKNOWN | Unknown/unspecified format. |
| BJ_AUDIO_FORMAT_INT16 | 16-bit signed integer PCM. |
| BJ_AUDIO_FORMAT_F32 | 32-bit IEEE-754 float PCM. |
| bj_bool bj_audio_playing | ( | const bj_audio_device * | p_device | ) |
Query whether the device is currently playing audio.
| p_device | Pointer to the audio device. |
| void bj_close_audio_device | ( | bj_audio_device * | p_device | ) |
Close an audio device and release all associated resources.
Stops playback and joins the audio thread before cleanup.
| p_device | Pointer to the audio device to close. |
| 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.
Initializes the audio backend and starts playback immediately using the provided callback.
| p_properties | Optional pointer to requested properties, or NULL. The opened device may differ from the request. |
| p_callback | User audio callback used to produce samples. |
| p_callback_user_data | Opaque pointer passed to the callback on each call. |
| p_error | Optional pointer to receive error information on failure. |
| void bj_pause_audio_device | ( | bj_audio_device * | p_device | ) |
Pause audio playback.
While paused, the audio thread continues running and outputs silence.
| p_device | Pointer to the audio device. |
| void bj_play_audio_device | ( | bj_audio_device * | p_device | ) |
Resume audio playback.
Playback resumes from where it was previously paused.
| p_device | Pointer to the audio device. |
| void bj_play_audio_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.
Can be used as a bj_audio_callback_t and uses bj_audio_play_note_data_t.
| buffer | Output buffer to write samples into. |
| frames | Number of frames to generate. |
| audio | Audio device properties. |
| user_data | Pointer to a bj_audio_play_note_data_t instance. |
| base_sample_index | Starting sample index (for phase computation). |
| void bj_reset_audio_device | ( | bj_audio_device * | p_device | ) |
Reset the playback stream sample index to 0.
Does not stop or pause playback. Only resets timing.
| p_device | Pointer to the audio device. |
| void bj_stop_audio_device | ( | bj_audio_device * | p_device | ) |
Stop playback and reset the sample stream.
Equivalent to calling pause followed by reset.
| p_device | Pointer to the audio device. |