Banjo API 0.0.1
C99 game development API
Loading...
Searching...
No Matches
audio.h
Go to the documentation of this file.
1
22#ifndef BJ_AUDIO_H
23#define BJ_AUDIO_H
24
25#include <banjo/error.h>
26#include <banjo/api.h>
27#include <stdint.h>
28
38typedef struct bj_audio_device_t bj_audio_device;
39
57
64#define BJ_AUDIO_FORMAT_WIDTH(x) ((x) & (0xFFu))
65
72#define BJ_AUDIO_FORMAT_FLOAT(x) ((x) & (1u<<8))
73
80#define BJ_AUDIO_FORMAT_INT(x) (!((x) & (1u<<8)))
81
88#define BJ_AUDIO_FORMAT_BIG_ENDIAN(x) ((x) & (1u<<12))
89
96#define BJ_AUDIO_FORMAT_SIGNED(x) ((x) & (1u<<15))
97
112
128typedef void (*bj_audio_callback_t)(
129 void* buffer,
130 unsigned frames,
131 const bj_audio_properties* audio,
132 void* user_data,
133 uint64_t base_sample_index
134);
135
155 const bj_audio_properties* p_properties,
156 bj_audio_callback_t p_callback,
157 void* p_callback_user_data,
158 bj_error** p_error
159);
160
171 bj_audio_device* p_device
172);
173
186 bj_audio_device* p_device
187);
188
201 bj_audio_device* p_device
202);
203
215 bj_audio_device* p_device
216);
217
229 bj_audio_device* p_device
230);
231
242 const bj_audio_device* p_device
243);
244
262
278 void* buffer,
279 unsigned frames,
280 const bj_audio_properties* audio,
281 void* user_data,
282 uint64_t base_sample_index
283);
284
290typedef struct bj_audio_layer_t {
299 void (*end)(struct bj_audio_layer_t* self, bj_error** p_error);
300
309 void (*close_device)(struct bj_audio_layer_t* self, bj_audio_device* device);
310
323 bj_audio_device* (*open_device)(
324 struct bj_audio_layer_t* self,
325 const bj_audio_properties* p_properties,
326 bj_audio_callback_t callback,
327 void* user_data,
328 bj_error** p_error
329 );
330
336 struct bj_audio_layer_data_t* data;
338
347typedef struct {
348 const char* name;
349 bj_audio_layer* (*create)(bj_error**);
351
352#endif /* BJ_AUDIO_H */
General-purpose definitions for Banjo API.
Recoverable error handling.
const char * name
Name of the backend (e.g., "alsa", "mme").
Definition audio.h:348
void(* close_device)(struct bj_audio_layer_t *self, bj_audio_device *device)
Close an audio device managed by this backend.
Definition audio.h:309
bj_audio_format format
Sampling format.
Definition audio.h:107
unsigned int sample_rate
Number of samples per second (Hz).
Definition audio.h:110
int16_t amplitude
Maximum amplitude of the output samples.
Definition audio.h:108
struct bj_audio_layer_data_t * data
Backend-specific data pointer.
Definition audio.h:336
void(* end)(struct bj_audio_layer_t *self, bj_error **p_error)
Shutdown and clean up the backend.
Definition audio.h:299
unsigned int channels
Number of channels (currently always 1).
Definition audio.h:109
bj_audio_format_t
Audio sample format descriptor.
Definition audio.h:52
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.
bj_bool bj_audio_playing(const bj_audio_device *p_device)
Query whether the device is currently playing audio.
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.
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.
Definition audio.h:128
struct bj_audio_device_t bj_audio_device
Opaque handle to an audio device instance.
Definition audio.h:38
struct bj_audio_layer_t bj_audio_layer
Represent an audio backend (ALSA, MME, etc).
enum bj_audio_format_t bj_audio_format
Audio sample format descriptor.
void bj_play_audio_device(bj_audio_device *p_device)
Resume audio playback.
void bj_pause_audio_device(bj_audio_device *p_device)
Pause audio playback.
void bj_stop_audio_device(bj_audio_device *p_device)
Stop playback and reset the sample stream.
struct bj_audio_play_note_data_t bj_audio_play_note_data
Define parameters for generating simple waveforms.
void bj_reset_audio_device(bj_audio_device *p_device)
Reset the playback stream sample index to 0.
void bj_close_audio_device(bj_audio_device *p_device)
Close an audio device and release all associated resources.
@ BJ_AUDIO_FORMAT_F32
32-bit IEEE-754 float PCM.
Definition audio.h:55
@ BJ_AUDIO_FORMAT_UNKNOWN
Unknown/unspecified format.
Definition audio.h:53
@ BJ_AUDIO_FORMAT_INT16
16-bit signed integer PCM.
Definition audio.h:54
Declare a backend and its constructor function.
Definition audio.h:347
Represent an audio backend (ALSA, MME, etc).
Definition audio.h:290
Describe properties of an audio device.
Definition audio.h:106
#define BANJO_EXPORT
Definition api.h:139
uint32_t bj_bool
Boolean type used throughout the Banjo API.
Definition api.h:276
Error structure.
Definition error.h:131
Define parameters for generating simple waveforms.
Definition audio.h:252
enum bj_audio_play_note_data_t::@240042340022345302376151237345105167321121277363 function
Type of waveform to generate.
@ BJ_AUDIO_PLAY_TRIANGLE
Generate a triangle wave.
Definition audio.h:256
@ BJ_AUDIO_PLAY_SQUARE
Generate a square wave.
Definition audio.h:255
@ BJ_AUDIO_PLAY_SINE
Generate a sine wave.
Definition audio.h:254
@ BJ_AUDIO_PLAY_SAWTOOTH
Generate a sawtooth wave.
Definition audio.h:257
double frequency
Frequency of the waveform (Hz).
Definition audio.h:259
double phase
Internal phase accumulator.
Definition audio.h:260