/** Sample buffer that resamples from input clock rate to output sample rate \file */12/* blip_buf $vers */3#ifndef BLIP_BUF_H4#define BLIP_BUF_H56#ifdef __cplusplus7extern "C" {8#endif910/** First parameter of most functions is blip_t*, or const blip_t* if nothing11is changed. */12typedef struct blip_t blip_t;1314/** Creates new buffer that can hold at most sample_count samples. Sets rates15so that there are blip_max_ratio clocks per sample. Returns pointer to new16buffer, or NULL if insufficient memory. */17blip_t* blip_new( int sample_count );1819/** Sets approximate input clock rate and output sample rate. For every20clock_rate input clocks, approximately sample_rate samples are generated. */21void blip_set_rates( blip_t*, double clock_rate, double sample_rate );2223enum { /** Maximum clock_rate/sample_rate ratio. For a given sample_rate,24clock_rate must not be greater than sample_rate*blip_max_ratio. */25blip_max_ratio = 1 << 20 };2627/** Clears entire buffer. Afterwards, blip_samples_avail() == 0. */28void blip_clear( blip_t* );2930/** Adds positive/negative delta into buffer at specified clock time. */31void blip_add_delta( blip_t*, unsigned int clock_time, int delta );3233/** Same as blip_add_delta(), but uses faster, lower-quality synthesis. */34void blip_add_delta_fast( blip_t*, unsigned int clock_time, int delta );3536/** Length of time frame, in clocks, needed to make sample_count additional37samples available. */38int blip_clocks_needed( const blip_t*, int sample_count );3940enum { /** Maximum number of samples that can be generated from one time frame. */41blip_max_frame = 4000 };4243/** Makes input clocks before clock_duration available for reading as output44samples. Also begins new time frame at clock_duration, so that clock time 0 in45the new time frame specifies the same clock as clock_duration in the old time46frame specified. Deltas can have been added slightly past clock_duration (up to47however many clocks there are in two output samples). */48void blip_end_frame( blip_t*, unsigned int clock_duration );4950/** Number of buffered samples available for reading. */51int blip_samples_avail( const blip_t* );5253/** Reads and removes at most 'count' samples and writes them to to every other54element of 'out', allowing easy interleaving of two buffers into a stereo sample55stream. Outputs 16-bit signed samples. Returns number of samples actually read. */56int blip_read_samples( blip_t*, short out [], int count);5758/* Same as above function except sample is added to output buffer previous value */59/* This allows easy mixing of different blip buffers into a single output stream */60int blip_mix_samples( blip_t* m, short out [], int count);6162/** Frees buffer. No effect if NULL is passed. */63void blip_delete( blip_t* );646566/* Deprecated */67typedef blip_t blip_buffer_t;6869#ifdef __cplusplus70}71#endif7273#endif747576