Banjo API 1.0.0-rc.2
Low-level C99 game development API
Loading...
Searching...
No Matches
audio.h
Go to the documentation of this file.
1
99#ifndef BJ_AUDIO_H
100#define BJ_AUDIO_H
101
102#include <banjo/error.h>
103#include <banjo/api.h>
104#include <stdint.h>
105
115struct bj_audio_device;
116
134#ifndef BJ_NO_TYPEDEF
136#endif
137
144#define BJ_AUDIO_FORMAT_WIDTH(x) ((x) & (0xFFu))
145
152#define BJ_AUDIO_FORMAT_FLOAT(x) ((x) & (1u<<8))
153
160#define BJ_AUDIO_FORMAT_INT(x) (!((x) & (1u<<8)))
161
168#define BJ_AUDIO_FORMAT_BIG_ENDIAN(x) ((x) & (1u<<12))
169
176#define BJ_AUDIO_FORMAT_SIGNED(x) ((x) & (1u<<15))
177
188 int16_t amplitude;
189 unsigned int channels;
190 unsigned int sample_rate;
191};
192
208typedef void (*bj_audio_callback_fn)(
209 void* buffer,
210 unsigned frames,
211 const struct bj_audio_properties* audio,
212 void* user_data,
213 uint64_t base_sample_index
214);
215
235 const struct bj_audio_properties* properties,
236 bj_audio_callback_fn callback,
237 void* callback_user_data,
238 struct bj_error** error
239);
240
251 struct bj_audio_device* device
252);
253
266 struct bj_audio_device* device
267);
268
281 struct bj_audio_device* device
282);
283
295 struct bj_audio_device* device
296);
297
309 struct bj_audio_device* device
310);
311
322 const struct bj_audio_device* device
323);
324
342
358 void* buffer,
359 unsigned frames,
360 const struct bj_audio_properties* audio,
361 void* user_data,
362 uint64_t base_sample_index
363);
364
365#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:188
enum bj_audio_format format
Sampling format.
Definition audio.h:187
unsigned int sample_rate
Number of samples per second (Hz).
Definition audio.h:190
unsigned int channels
Number of interleaved channels (1 = mono, 2 = stereo, ...). The opened device may negotiate a differe...
Definition audio.h:189
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:129
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:208
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:132
@ BJ_AUDIO_FORMAT_UNKNOWN
Unknown/unspecified format.
Definition audio.h:130
@ BJ_AUDIO_FORMAT_INT16
16-bit signed integer PCM.
Definition audio.h:131
Describe properties of an audio device.
Definition audio.h:186
struct bj_error bj_error
Definition api.h:333
#define BANJO_EXPORT
Definition api.h:163
uint32_t bj_bool
Boolean type used throughout the Banjo API.
Definition api.h:257
struct bj_audio_device bj_audio_device
Definition api.h:325
Define parameters for generating simple waveforms.
Definition audio.h:332
enum bj_audio_play_note_data::@240042340022345302376151237345105167321121277363 function
Type of waveform to generate.
@ BJ_AUDIO_PLAY_SINE
Generate a sine wave.
Definition audio.h:334
@ BJ_AUDIO_PLAY_SQUARE
Generate a square wave.
Definition audio.h:335
@ BJ_AUDIO_PLAY_TRIANGLE
Generate a triangle wave.
Definition audio.h:336
@ BJ_AUDIO_PLAY_SAWTOOTH
Generate a sawtooth wave.
Definition audio.h:337
double frequency
Frequency of the waveform (Hz).
Definition audio.h:339
double phase
Internal phase accumulator.
Definition audio.h:340