libdragon
Loading...
Searching...
No Matches
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 int wnext;
121
127
131 void *wv_ctx;
133
148void samplebuffer_init(samplebuffer_t *buf, uint8_t *uncached_mem, int size);
149
160void samplebuffer_set_bps(samplebuffer_t *buf, int bps);
161
178
207void* samplebuffer_get(samplebuffer_t *buf, int wpos, int *wlen);
208
240void* samplebuffer_append(samplebuffer_t *buf, int wlen);
241
255void samplebuffer_discard(samplebuffer_t *buf, int wpos);
256
263
273
274#ifdef __cplusplus
275}
276#endif
277
278#endif /* __LIBDRAGON_SAMPLEBUFFER_H */
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:140
int size
Definition samplebuffer.h:91
void samplebuffer_close(samplebuffer_t *buf)
Definition samplebuffer.c:57
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:61
int ridx
Definition samplebuffer.h:113
WaveformRead wv_read
Definition samplebuffer.h:126
void samplebuffer_set_bps(samplebuffer_t *buf, int bps)
Configure the bit width of the samples stored in the buffer.
Definition samplebuffer.c:40
int wnext
Definition samplebuffer.h:120
void * wv_ctx
Definition samplebuffer.h:131
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:52
void samplebuffer_flush(samplebuffer_t *buf)
Definition samplebuffer.c:229
uint32_t sample_ptr_t
Definition samplebuffer.h:21
void samplebuffer_discard(samplebuffer_t *buf, int wpos)
Definition samplebuffer.c:177
Definition samplebuffer.h:82
int read(int fileno, char *ptr, int len)
Read data from a file.
Definition system.c:927