Banjo API 0.0.1
C99 game development API
Loading...
Searching...
No Matches
audio.h
Go to the documentation of this file.
1
21#ifndef BJ_AUDIO_H
22#define BJ_AUDIO_H
23
24#include <banjo/error.h>
25#include <banjo/api.h>
26#include <stdint.h>
27
37struct bj_audio_device;
38
56
63#define BJ_AUDIO_FORMAT_WIDTH(x) ((x) & (0xFFu))
64
71#define BJ_AUDIO_FORMAT_FLOAT(x) ((x) & (1u<<8))
72
79#define BJ_AUDIO_FORMAT_INT(x) (!((x) & (1u<<8)))
80
87#define BJ_AUDIO_FORMAT_BIG_ENDIAN(x) ((x) & (1u<<12))
88
95#define BJ_AUDIO_FORMAT_SIGNED(x) ((x) & (1u<<15))
96
107 int16_t amplitude;
108 unsigned int channels;
109 unsigned int sample_rate;
110};
111
127typedef void (*bj_audio_callback_fn)(
128 void* buffer,
129 unsigned frames,
130 const struct bj_audio_properties* audio,
131 void* user_data,
132 uint64_t base_sample_index
133);
134
154 const struct bj_audio_properties* properties,
155 bj_audio_callback_fn callback,
156 void* callback_user_data,
157 struct bj_error** error
158);
159
170 struct bj_audio_device* device
171);
172
185 struct bj_audio_device* device
186);
187
200 struct bj_audio_device* device
201);
202
214 struct bj_audio_device* device
215);
216
228 struct bj_audio_device* device
229);
230
241 const struct bj_audio_device* device
242);
243
261
277 void* buffer,
278 unsigned frames,
279 const struct bj_audio_properties* audio,
280 void* user_data,
281 uint64_t base_sample_index
282);
283
284#endif /* BJ_AUDIO_H */
General-purpose definitions for Banjo API.
Recoverable error handling.
int16_t amplitude
Maximum amplitude of the output samples.
Definition audio.h:107
enum bj_audio_format format
Sampling format.
Definition audio.h:106
unsigned int sample_rate
Number of samples per second (Hz).
Definition audio.h:109
unsigned int channels
Number of channels (currently always 1).
Definition audio.h:108
void bj_play_audio_note(void *buffer, unsigned frames, const struct bj_audio_properties *audio, void *user_data, uint64_t base_sample_index)
Generate a basic waveform tone using a built-in callback.
bj_bool bj_audio_playing(const struct bj_audio_device *device)
Query whether the device is currently playing audio.
bj_audio_format
Audio sample format descriptor.
Definition audio.h:51
void bj_reset_audio_device(struct bj_audio_device *device)
Reset the playback stream sample index to 0.
void bj_pause_audio_device(struct bj_audio_device *device)
Pause audio playback.
void bj_close_audio_device(struct bj_audio_device *device)
Close an audio device and release all associated resources.
void bj_stop_audio_device(struct bj_audio_device *device)
Stop playback and reset the sample stream.
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.
Definition audio.h:127
struct bj_audio_device * bj_open_audio_device(const struct bj_audio_properties *properties, bj_audio_callback_fn callback, void *callback_user_data, struct bj_error **error)
Open the default audio device for playback.
void bj_play_audio_device(struct bj_audio_device *device)
Resume audio playback.
@ BJ_AUDIO_FORMAT_F32
32-bit IEEE-754 float PCM.
Definition audio.h:54
@ BJ_AUDIO_FORMAT_UNKNOWN
Unknown/unspecified format.
Definition audio.h:52
@ BJ_AUDIO_FORMAT_INT16
16-bit signed integer PCM.
Definition audio.h:53
Describe properties of an audio device.
Definition audio.h:105
#define BANJO_EXPORT
Definition api.h:155
uint32_t bj_bool
Boolean type used throughout the Banjo API.
Definition api.h:249
struct bj_audio_device bj_audio_device
Definition api.h:328
Error structure.
Definition error.h:131
Define parameters for generating simple waveforms.
Definition audio.h:251
enum bj_audio_play_note_data::@240042340022345302376151237345105167321121277363 function
Type of waveform to generate.
@ BJ_AUDIO_PLAY_SINE
Generate a sine wave.
Definition audio.h:253
@ BJ_AUDIO_PLAY_SQUARE
Generate a square wave.
Definition audio.h:254
@ BJ_AUDIO_PLAY_TRIANGLE
Generate a triangle wave.
Definition audio.h:255
@ BJ_AUDIO_PLAY_SAWTOOTH
Generate a sawtooth wave.
Definition audio.h:256
double frequency
Frequency of the waveform (Hz).
Definition audio.h:258
double phase
Internal phase accumulator.
Definition audio.h:259