/** \file1Sample buffer that resamples from input clock rate to output sample rate */23/* blip_buf 1.1.0 */4#ifndef BLIP_BUF_H5#define BLIP_BUF_H67#ifdef __cplusplus8extern "C" {9#endif1011/** First parameter of most functions is blip_t*, or const blip_t* if nothing12is changed. */13typedef struct blip_t blip_t;1415/** Creates new buffer that can hold at most sample_count samples. Sets rates16so that there are blip_max_ratio clocks per sample. Returns pointer to new17buffer, or NULL if insufficient memory. */18blip_t* blip_new( int sample_count );1920/** Sets approximate input clock rate and output sample rate. For every21clock_rate input clocks, approximately sample_rate samples are generated. */22void blip_set_rates( blip_t*, double clock_rate, double sample_rate );2324enum { /** Maximum clock_rate/sample_rate ratio. For a given sample_rate,25clock_rate must not be greater than sample_rate*blip_max_ratio. */26blip_max_ratio = 1 << 20 };2728/** Clears entire buffer. Afterwards, blip_samples_avail() == 0. */29void blip_clear( blip_t* );3031/** Adds positive/negative delta into buffer at specified clock time. */32void blip_add_delta( blip_t*, unsigned int clock_time, int delta );3334/** Same as blip_add_delta(), but uses faster, lower-quality synthesis. */35void blip_add_delta_fast( blip_t*, unsigned int clock_time, int delta );3637/** Length of time frame, in clocks, needed to make sample_count additional38samples available. */39int blip_clocks_needed( const blip_t*, int sample_count );4041enum { /** Maximum number of samples that can be generated from one time frame. */42blip_max_frame = 4000 };4344/** Makes input clocks before clock_duration available for reading as output45samples. Also begins new time frame at clock_duration, so that clock time 0 in46the new time frame specifies the same clock as clock_duration in the old time47frame specified. Deltas can have been added slightly past clock_duration (up to48however many clocks there are in two output samples). */49void blip_end_frame( blip_t*, unsigned int clock_duration );5051/** Number of buffered samples available for reading. */52int blip_samples_avail( const blip_t* );5354/** Reads and removes at most 'count' samples and writes them to 'out'. If55'stereo' is true, writes output to every other element of 'out', allowing easy56interleaving of two buffers into a stereo sample stream. Outputs 16-bit signed57samples. Returns number of samples actually read. */58int blip_read_samples( blip_t*, short out [], int count, int stereo );5960/** Frees buffer. No effect if NULL is passed. */61void blip_delete( blip_t* );626364/* Deprecated */65typedef blip_t blip_buffer_t;6667#ifdef __cplusplus68}69#endif7071#endif727374