all repos — mgba @ 38cb3eeaa857e744917d3ed57263f7585bf74233

mGBA Game Boy Advance Emulator

src/third-party/blip_buf/blip_buf.h (view raw)

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