Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/blip_buf/blip_buf.h
2 views
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
int blip_clocks_needed( const blip_t*, int sample_count );
41
42
enum { /** Maximum number of samples that can be generated from one time frame. */
43
blip_max_frame = 4000 };
44
45
/** Makes input clocks before clock_duration available for reading as output
46
samples. Also begins new time frame at clock_duration, so that clock time 0 in
47
the new time frame specifies the same clock as clock_duration in the old time
48
frame specified. Deltas can have been added slightly past clock_duration (up to
49
however many clocks there are in two output samples). */
50
void blip_end_frame( blip_t*, unsigned int clock_duration );
51
52
/** Number of buffered samples available for reading. */
53
int 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
57
interleaving of two buffers into a stereo sample stream. Outputs 16-bit signed
58
samples. Returns number of samples actually read. */
59
int blip_read_samples( blip_t*, short out [], int count, int stereo );
60
61
/** Frees buffer. No effect if NULL is passed. */
62
void blip_delete( blip_t* );
63
64
65
/* Deprecated */
66
typedef blip_t blip_buffer_t;
67
68
#ifdef __cplusplus
69
}
70
#endif
71
72
#endif
73
74