libdragon
Loading...
Searching...
No Matches
samplebuffer.h
Go to the documentation of this file.
1
8#ifndef __LIBDRAGON_SAMPLEBUFFER_H
9#define __LIBDRAGON_SAMPLEBUFFER_H
10
11#include <stdint.h>
12#include <stdbool.h>
13
14#ifdef __cplusplus
15extern "C" {
16#endif
17
22typedef uint32_t sample_ptr_t;
23
30#define SAMPLES_BPS_SHIFT(buf) ((buf)->ptr_and_flags & 3)
31
37#define SAMPLES_PTR(buf) (void*)((buf)->ptr_and_flags ^ SAMPLES_BPS_SHIFT(buf))
38
43#define SAMPLES_PTR_MAKE(ptr, bps) ((sample_ptr_t)(ptr) | (bps))
44
83typedef struct samplebuffer_s {
88
92 int size;
93
99 int wpos;
100
106 int widx;
107
114 int ridx;
115
121 int wnext;
122
128
132 void *wv_ctx;
134
149void samplebuffer_init(samplebuffer_t *buf, uint8_t *uncached_mem, int size);
150
159
170void samplebuffer_set_bps(samplebuffer_t *buf, int bps);
171
188
217void* samplebuffer_get(samplebuffer_t *buf, int wpos, int *wlen);
218
250void* samplebuffer_append(samplebuffer_t *buf, int wlen);
251
269void samplebuffer_undo(samplebuffer_t *buf, int wlen);
270
284void samplebuffer_discard(samplebuffer_t *buf, int wpos);
285
292
302
303#ifdef __cplusplus
304}
305#endif
306
307#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:419
void * samplebuffer_append(samplebuffer_t *buf, int wlen)
Append samples into the buffer (zero-copy).
Definition samplebuffer.c:149
int size
Definition samplebuffer.h:92
void samplebuffer_close(samplebuffer_t *buf)
Definition samplebuffer.c:63
bool samplebuffer_is_inited(samplebuffer_t *buf)
Return true if the samplebuffer is initialized.
Definition samplebuffer.c:58
sample_ptr_t ptr_and_flags
Definition samplebuffer.h:87
int wpos
Definition samplebuffer.h:99
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:70
int ridx
Definition samplebuffer.h:114
WaveformRead wv_read
Definition samplebuffer.h:127
void samplebuffer_set_bps(samplebuffer_t *buf, int bps)
Configure the bit width of the samples stored in the buffer.
Definition samplebuffer.c:41
int wnext
Definition samplebuffer.h:121
void samplebuffer_undo(samplebuffer_t *buf, int wlen)
Remove the a specified number of samples from the tail of the buffer.
Definition samplebuffer.c:186
void * wv_ctx
Definition samplebuffer.h:132
int widx
Definition samplebuffer.h:106
void samplebuffer_init(samplebuffer_t *buf, uint8_t *uncached_mem, int size)
Definition samplebuffer.c:27
void samplebuffer_set_waveform(samplebuffer_t *buf, WaveformRead read, void *ctx)
Definition samplebuffer.c:53
void samplebuffer_flush(samplebuffer_t *buf)
Definition samplebuffer.c:243
uint32_t sample_ptr_t
Definition samplebuffer.h:22
void samplebuffer_discard(samplebuffer_t *buf, int wpos)
Definition samplebuffer.c:191
Definition samplebuffer.h:83
int read(int fileno, char *ptr, int len)
Read data from a file.
Definition system.c:928