libdragon
Loading...
Searching...
No Matches
mixer.h
Go to the documentation of this file.
1
7#ifndef __LIBDRAGON_MIXER_H
8#define __LIBDRAGON_MIXER_H
9
10#include <stdint.h>
11#include <stdbool.h>
12
13#ifdef __cplusplus
14extern "C" {
15#endif
16
58#define MIXER_MAX_CHANNELS 32
59
73#define MIXER_LOOP_OVERREAD 64
74
76typedef struct waveform_s waveform_t;
77typedef struct samplebuffer_s samplebuffer_t;
79
92void mixer_init(int num_channels);
93
97void mixer_close(void);
98
107void mixer_set_vol(float vol);
108
127void mixer_ch_set_vol(int ch, float lvol, float rvol);
128
147void mixer_ch_set_vol_pan(int ch, float vol, float pan);
148
167void mixer_ch_set_vol_dolby(int ch, float fl, float fr,
168 float c, float sl, float sr);
169
193void mixer_ch_play(int ch, waveform_t *wave);
194
207void mixer_ch_set_freq(int ch, float frequency);
208
222void mixer_ch_set_pos(int ch, float pos);
223
233float mixer_ch_get_pos(int ch);
234
236void mixer_ch_stop(int ch);
237
239bool mixer_ch_playing(int ch);
240
284void mixer_ch_set_limits(int ch, int max_bits, float max_frequency, int max_buf_sz);
285
306void mixer_poll(int16_t *out, int nsamples);
307
329typedef int (*MixerEvent)(void* ctx);
330
343void mixer_add_event(int64_t delay, MixerEvent cb, void *ctx);
344
355void mixer_remove_event(MixerEvent cb, void *ctx);
356
357
358/*********************************************************************
359 *
360 * WAVEFORMS
361 *
362 *********************************************************************/
363
418typedef void (*WaveformRead)(void *ctx, samplebuffer_t *sbuf, int wpos, int wlen, bool seeking);
419
439typedef struct waveform_s {
441 const char *name;
442
448 uint8_t bits;
449
456 uint8_t channels;
457
460
466 int len;
467
477
485
487 void *ctx;
488} waveform_t;
489
491#define WAVEFORM_MAX_LEN 0x1FFFFFFF
492
501#define WAVEFORM_UNKNOWN_LEN WAVEFORM_MAX_LEN
502
503#ifdef __cplusplus
504}
505#endif
506
507#endif /* __LIBDRAGON_MIXER_H */
bool mixer_ch_playing(int ch)
Return true if the channel is currently playing samples.
Definition mixer.c:448
void mixer_ch_play(int ch, waveform_t *wave)
Start playing the specified waveform on the specified channel.
Definition mixer.c:373
void * ctx
Opaque pointer provided as context to the read function.
Definition mixer.h:487
uint8_t bits
Width of a sample of this waveform, in bits.
Definition mixer.h:448
void mixer_add_event(int64_t delay, MixerEvent cb, void *ctx)
Register a time-based event into the mixer.
Definition mixer.c:700
void mixer_poll(int16_t *out, int nsamples)
Run the mixer to produce output samples.
Definition mixer.c:719
int loop_len
Length of the loop of the waveform (from the end).
Definition mixer.h:476
int(* MixerEvent)(void *ctx)
Callback invoked by mixer_poll at a specified time.
Definition mixer.h:329
void mixer_ch_set_vol(int ch, float lvol, float rvol)
Set channel volume (as left/right).
Definition mixer.c:265
WaveformRead read
Read function of the waveform.
Definition mixer.h:484
void mixer_ch_set_vol_pan(int ch, float vol, float pan)
Set channel volume (as volume and panning).
Definition mixer.c:272
void mixer_init(int num_channels)
Initialize the mixer.
Definition mixer.c:179
uint8_t channels
Number of interleaved audio channels in this waveforms.
Definition mixer.h:456
void mixer_ch_set_pos(int ch, float pos)
Change the current playback position within a waveform.
Definition mixer.c:422
int len
Length of the waveform, in number of samples.
Definition mixer.h:466
void mixer_close(void)
Deinitialize the mixer.
Definition mixer.c:244
void mixer_ch_set_vol_dolby(int ch, float fl, float fr, float c, float sl, float sr)
Set channel volume with Dolby Pro Logic II encoding.
Definition mixer.c:276
void mixer_ch_set_limits(int ch, int max_bits, float max_frequency, int max_buf_sz)
Configure the limits of a channel with respect to sample bit size, and frequency.
Definition mixer.c:454
void mixer_remove_event(MixerEvent cb, void *ctx)
Deregister a time-based event from the mixer.
Definition mixer.c:708
void(* WaveformRead)(void *ctx, samplebuffer_t *sbuf, int wpos, int wlen, bool seeking)
Waveform callback function invoked by the mixer to read/generate samples.
Definition mixer.h:418
float frequency
Desired playback frequency (in samples per second, aka Hz).
Definition mixer.h:459
const char * name
Name of the waveform (for debugging purposes)
Definition mixer.h:441
void mixer_ch_stop(int ch)
Stop playing samples on the specified channel.
Definition mixer.c:435
void mixer_set_vol(float vol)
Set master volume.
Definition mixer.c:240
void mixer_ch_set_freq(int ch, float frequency)
Change the frequency for the specified channel.
Definition mixer.c:258
float mixer_ch_get_pos(int ch)
Definition mixer.c:428
A waveform that can be played back through the mixer.
Definition mixer.h:439
Definition samplebuffer.h:82