libdragon
samplebuffer.h
Go to the documentation of this file.
1
7#ifndef __LIBDRAGON_SAMPLEBUFFER_H
8#define __LIBDRAGON_SAMPLEBUFFER_H
9
10#include <stdint.h>
11#include <stdbool.h>
12
13#ifdef __cplusplus
14extern "C" {
15#endif
16
21typedef uint32_t sample_ptr_t;
22
29#define SAMPLES_BPS_SHIFT(buf) ((buf)->ptr_and_flags & 3)
30
36#define SAMPLES_PTR(buf) (void*)((buf)->ptr_and_flags ^ SAMPLES_BPS_SHIFT(buf))
37
42#define SAMPLES_PTR_MAKE(ptr, bps) ((sample_ptr_t)(ptr) | (bps))
43
82typedef struct samplebuffer_s {
87
91 int size;
92
98 int wpos;
99
105 int widx;
106
113 int ridx;
114
120
124 void *wv_ctx;
126
141void samplebuffer_init(samplebuffer_t *buf, uint8_t *uncached_mem, int size);
142
153void samplebuffer_set_bps(samplebuffer_t *buf, int bps);
154
171
200void* samplebuffer_get(samplebuffer_t *buf, int wpos, int *wlen);
201
233void* samplebuffer_append(samplebuffer_t *buf, int wlen);
234
248void samplebuffer_discard(samplebuffer_t *buf, int wpos);
249
256
266
267#ifdef __cplusplus
268}
269#endif
270
271#endif /* __LIBDRAGON_SAMPLEBUFFER_H */
int read(int file, char *ptr, int len)
Read data from a file.
Definition: system.c:940
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
void * samplebuffer_append(samplebuffer_t *buf, int wlen)
Append samples into the buffer (zero-copy).
Definition: samplebuffer.c:129
int size
Definition: samplebuffer.h:91
void samplebuffer_close(samplebuffer_t *buf)
Definition: samplebuffer.c:56
sample_ptr_t ptr_and_flags
Definition: samplebuffer.h:86
int wpos
Definition: samplebuffer.h:98
void * samplebuffer_get(samplebuffer_t *buf, int wpos, int *wlen)
Get a pointer to specific set of samples in the buffer (zero-copy).
Definition: samplebuffer.c:60
int ridx
Definition: samplebuffer.h:113
WaveformRead wv_read
Definition: samplebuffer.h:119
void samplebuffer_set_bps(samplebuffer_t *buf, int bps)
Configure the bit width of the samples stored in the buffer.
Definition: samplebuffer.c:39
void * wv_ctx
Definition: samplebuffer.h:124
int widx
Definition: samplebuffer.h:105
void samplebuffer_init(samplebuffer_t *buf, uint8_t *uncached_mem, int size)
Definition: samplebuffer.c:26
void samplebuffer_set_waveform(samplebuffer_t *buf, WaveformRead read, void *ctx)
Definition: samplebuffer.c:51
void samplebuffer_flush(samplebuffer_t *buf)
Definition: samplebuffer.c:218
uint32_t sample_ptr_t
Definition: samplebuffer.h:21
void samplebuffer_discard(samplebuffer_t *buf, int wpos)
Definition: samplebuffer.c:166
Definition: samplebuffer.h:82