summaryrefslogtreecommitdiff
path: root/lib/rbcodec/codecs/libgme/multi_buffer.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rbcodec/codecs/libgme/multi_buffer.h')
-rw-r--r--lib/rbcodec/codecs/libgme/multi_buffer.h114
1 files changed, 114 insertions, 0 deletions
diff --git a/lib/rbcodec/codecs/libgme/multi_buffer.h b/lib/rbcodec/codecs/libgme/multi_buffer.h
new file mode 100644
index 0000000000..e5efa5a230
--- /dev/null
+++ b/lib/rbcodec/codecs/libgme/multi_buffer.h
@@ -0,0 +1,114 @@
1// Multi-channel sound buffer interface, stereo and effects buffers
2
3// Blip_Buffer 0.4.1
4#ifndef MULTI_BUFFER_H
5#define MULTI_BUFFER_H
6
7#include "blargg_common.h"
8#include "blip_buffer.h"
9
10// Get indexed channel, from 0 to channel count - 1
11struct channel_t {
12 struct Blip_Buffer* center;
13 struct Blip_Buffer* left;
14 struct Blip_Buffer* right;
15};
16
17enum { type_index_mask = 0xFF };
18enum { wave_type = 0x100, noise_type = 0x200, mixed_type = wave_type | noise_type };
19enum { stereo = 2 };
20enum { bufs_size = 3 };
21
22// Tracked_Blip_Buffer
23struct Tracked_Blip_Buffer {
24 struct Blip_Buffer blip;
25 int last_non_silence;
26};
27
28void Tracked_init( struct Tracked_Blip_Buffer* this );
29unsigned Tracked_non_silent( struct Tracked_Blip_Buffer* this );
30void Tracked_remove_all_samples( struct Tracked_Blip_Buffer * this );
31int Tracked_read_samples( struct Tracked_Blip_Buffer* this, blip_sample_t [], int );
32void Tracked_remove_silence( struct Tracked_Blip_Buffer* this, int );
33void Tracked_remove_samples( struct Tracked_Blip_Buffer* this, int );
34void Tracked_clear( struct Tracked_Blip_Buffer* this );
35void Tracked_end_frame( struct Tracked_Blip_Buffer* this, blip_time_t );
36
37static inline delta_t unsettled( struct Blip_Buffer* this )
38{
39 return this->reader_accum_ >> delta_bits;
40}
41
42// Stereo Mixer
43struct Stereo_Mixer {
44 struct Tracked_Blip_Buffer* bufs [3];
45 int samples_read;
46};
47
48void Mixer_init( struct Stereo_Mixer* this );
49void Mixer_read_pairs( struct Stereo_Mixer* this, blip_sample_t out [], int count );
50
51typedef struct Tracked_Blip_Buffer buf_t;
52
53// Multi_Buffer
54struct Multi_Buffer {
55 unsigned channels_changed_count_;
56 int sample_rate_;
57 int length_;
58 int channel_count_;
59 int samples_per_frame_;
60 int const *channel_types_;
61 bool immediate_removal_;
62
63 buf_t bufs [bufs_size];
64 struct Stereo_Mixer mixer;
65 struct channel_t chan;
66};
67
68blargg_err_t Buffer_set_channel_count( struct Multi_Buffer* this, int n, int const* types );
69
70// Buffers used for all channels
71static inline struct Blip_Buffer* center( struct Multi_Buffer* this ) { return &this->bufs [2].blip; }
72static inline struct Blip_Buffer* left( struct Multi_Buffer* this ) { return &this->bufs [0].blip; }
73static inline struct Blip_Buffer* right( struct Multi_Buffer* this ) { return &this->bufs [1].blip; }
74
75// Initializes Multi_Buffer structure
76void Buffer_init( struct Multi_Buffer* this );
77
78blargg_err_t Buffer_set_sample_rate( struct Multi_Buffer* this, int, int msec );
79void Buffer_clock_rate( struct Multi_Buffer* this, int );
80void Buffer_bass_freq( struct Multi_Buffer* this, int );
81void Buffer_clear( struct Multi_Buffer* this );
82void Buffer_end_frame( struct Multi_Buffer* this, blip_time_t ) ICODE_ATTR;
83
84static inline int Buffer_length( struct Multi_Buffer* this )
85{
86 return this->length_;
87}
88
89// Count of changes to channel configuration. Incremented whenever
90// a change is made to any of the Blip_Buffers for any channel.
91static inline unsigned Buffer_channels_changed_count( struct Multi_Buffer* this )
92{
93 return this->channels_changed_count_;
94}
95
96static inline void Buffer_disable_immediate_removal( struct Multi_Buffer* this )
97{
98 this->immediate_removal_ = false;
99}
100
101static inline int Buffer_sample_rate( struct Multi_Buffer* this )
102{
103 return this->sample_rate_;
104}
105
106static inline int Buffer_samples_avail( struct Multi_Buffer* this )
107{
108 return (Blip_samples_avail(&this->bufs [0].blip) - this->mixer.samples_read) * 2;
109}
110
111int Buffer_read_samples( struct Multi_Buffer* this, blip_sample_t*, int ) ICODE_ATTR;
112struct channel_t Buffer_channel( struct Multi_Buffer* this, int i );
113
114#endif