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