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.
- Todo
Add support for audio push-based API
Add support for audio WAVE format
Add support for audio MIDI format
◆ bj_audio_properties
| struct 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.
- See also
- bj_audio_callback_fn
| Data Fields |
|
int16_t |
amplitude |
Maximum amplitude of the output samples. |
|
unsigned int |
channels |
Number of channels (currently always 1). |
|
enum bj_audio_format |
format |
Sampling format. |
|
unsigned int |
sample_rate |
Number of samples per second (Hz). |
◆ BJ_AUDIO_FORMAT_BIG_ENDIAN
| #define BJ_AUDIO_FORMAT_BIG_ENDIAN |
( |
| x | ) |
|
Value:
Test whether the audio format uses big-endian byte order.
- Parameters
-
- Returns
- Non-zero if big-endian, zero otherwise.
◆ BJ_AUDIO_FORMAT_FLOAT
| #define BJ_AUDIO_FORMAT_FLOAT |
( |
| x | ) |
|
Value:
Test whether the audio format is floating point.
- Parameters
-
- Returns
- Non-zero if float, zero otherwise.
◆ BJ_AUDIO_FORMAT_INT
| #define BJ_AUDIO_FORMAT_INT |
( |
| x | ) |
|
Value:
Test whether the audio format is integer PCM.
- Parameters
-
- Returns
- Non-zero if integer PCM, zero otherwise.
◆ BJ_AUDIO_FORMAT_SIGNED
| #define BJ_AUDIO_FORMAT_SIGNED |
( |
| x | ) |
|
Value:
Test whether integer samples are signed.
- Parameters
-
- Returns
- Non-zero if signed, zero otherwise.
◆ BJ_AUDIO_FORMAT_WIDTH
| #define BJ_AUDIO_FORMAT_WIDTH |
( |
| x | ) |
|
Value:
Extract the sample width (in bits) from an audio format code.
- Parameters
-
- Returns
- Unsigned integer width in bits (e.g., 16 or 32).
◆ bj_audio_callback_fn
| typedef void(* bj_audio_callback_fn) (void *buffer, unsigned frames, const struct 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.
- Parameters
-
| 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. |
- See also
- bj_open_audio_device
-
struct bj_audio_properties
◆ bj_audio_format
◆ bj_audio_playing()
Query whether the device is currently playing audio.
- Parameters
-
| device | Pointer to the audio device. |
- Returns
- BJ_TRUE if playing, BJ_FALSE if paused or stopped.
- See also
- bj_play_audio_device
-
bj_pause_audio_device
◆ bj_close_audio_device()
Close an audio device and release all associated resources.
Stops playback and joins the audio thread before cleanup.
- Parameters
-
| device | Pointer to the audio device to close. |
- See also
- bj_open_audio_device
◆ bj_open_audio_device()
Open the default audio device for playback.
Initializes the audio backend and starts playback immediately using the provided callback.
- Parameters
-
| properties | Optional pointer to requested properties, or NULL. The opened device may differ from the request. |
| callback | User audio callback used to produce samples. |
| callback_user_data | Opaque pointer passed to the callback on each call. |
| error | Optional pointer to receive error information on failure. |
- Returns
- A handle to the opened audio device, or NULL on failure.
- See also
- bj_audio_callback_fn
-
bj_close_audio_device
-
bj_play_audio_device
-
bj_pause_audio_device
◆ bj_pause_audio_device()
◆ bj_play_audio_device()
◆ bj_play_audio_note()
| void bj_play_audio_note |
( |
void * | buffer, |
|
|
unsigned | frames, |
|
|
const struct bj_audio_properties * | audio, |
|
|
void * | user_data, |
|
|
uint64_t | base_sample_index ) |
◆ bj_reset_audio_device()
◆ bj_stop_audio_device()