| 1 |
/** \file |
| 2 |
Sample buffer that resamples from input clock rate to output sample rate */ |
| 3 |
|
| 4 |
/* blip_buf 1.1.0 */ |
| 5 |
#ifndef BLIP_BUF_H |
| 6 |
#define BLIP_BUF_H |
| 7 |
|
| 8 |
#ifdef __cplusplus |
| 9 |
extern "C" { |
| 10 |
#endif |
| 11 |
|
| 12 |
/** First parameter of most functions is blip_t*, or const blip_t* if nothing |
| 13 |
is changed. */ |
| 14 |
typedef struct blip_t blip_t; |
| 15 |
|
| 16 |
/** Creates new buffer that can hold at most sample_count samples. Sets rates |
| 17 |
so that there are blip_max_ratio clocks per sample. Returns pointer to new |
| 18 |
buffer, or NULL if insufficient memory. */ |
| 19 |
blip_t* blip_new( int sample_count ); |
| 20 |
|
| 21 |
/** Sets approximate input clock rate and output sample rate. For every |
| 22 |
clock_rate input clocks, approximately sample_rate samples are generated. */ |
| 23 |
void blip_set_rates( blip_t*, double clock_rate, double sample_rate ); |
| 24 |
|
| 25 |
enum { /** Maximum clock_rate/sample_rate ratio. For a given sample_rate, |
| 26 |
clock_rate must not be greater than sample_rate*blip_max_ratio. */ |
| 27 |
blip_max_ratio = 1 << 20 }; |
| 28 |
|
| 29 |
/** Clears entire buffer. Afterwards, blip_samples_avail() == 0. */ |
| 30 |
void blip_clear( blip_t* ); |
| 31 |
|
| 32 |
/** Adds positive/negative delta into buffer at specified clock time. */ |
| 33 |
void blip_add_delta( blip_t*, unsigned int clock_time, int delta ); |
| 34 |
|
| 35 |
/** Same as blip_add_delta(), but uses faster, lower-quality synthesis. */ |
| 36 |
void blip_add_delta_fast( blip_t*, unsigned int clock_time, int delta ); |
| 37 |
|
| 38 |
/** Length of time frame, in clocks, needed to make sample_count additional |
| 39 |
samples available. |
| 40 |
|
| 41 |
Returns negative value if buffer cannnot hold many more samples. |
| 42 |
*/ |
| 43 |
int blip_clocks_needed( const blip_t*, int sample_count ); |
| 44 |
|
| 45 |
enum { /** Maximum number of samples that can be generated from one time frame. */ |
| 46 |
blip_max_frame = 4000 }; |
| 47 |
|
| 48 |
/** Makes input clocks before clock_duration available for reading as output |
| 49 |
samples. Also begins new time frame at clock_duration, so that clock time 0 in |
| 50 |
the new time frame specifies the same clock as clock_duration in the old time |
| 51 |
frame specified. Deltas can have been added slightly past clock_duration (up to |
| 52 |
however many clocks there are in two output samples). */ |
| 53 |
void blip_end_frame( blip_t*, unsigned int clock_duration ); |
| 54 |
|
| 55 |
/** Number of buffered samples available for reading. */ |
| 56 |
int blip_samples_avail( const blip_t* ); |
| 57 |
|
| 58 |
/** Reads and removes at most 'count' samples and writes them to 'out'. If |
| 59 |
'stereo' is true, writes output to every other element of 'out', allowing easy |
| 60 |
interleaving of two buffers into a stereo sample stream. Outputs 16-bit signed |
| 61 |
samples. Returns number of samples actually read. */ |
| 62 |
int blip_read_samples( blip_t*, short out [], int count, int stereo ); |
| 63 |
|
| 64 |
/** Frees buffer. No effect if NULL is passed. */ |
| 65 |
void blip_delete( blip_t* ); |
| 66 |
|
| 67 |
|
| 68 |
/* Deprecated */ |
| 69 |
typedef blip_t blip_buffer_t; |
| 70 |
|
| 71 |
#ifdef __cplusplus |
| 72 |
} |
| 73 |
#endif |
| 74 |
|
| 75 |
#endif |