diff options
author | Sean Bartell <wingedtachikoma@gmail.com> | 2011-06-25 21:32:25 -0400 |
---|---|---|
committer | Nils Wallménius <nils@rockbox.org> | 2012-04-25 22:13:20 +0200 |
commit | f40bfc9267b13b54e6379dfe7539447662879d24 (patch) | |
tree | 9b20069d5e62809ff434061ad730096836f916f2 /lib/rbcodec/codecs/libgme/multi_buffer.h | |
parent | a0009907de7a0107d49040d8a180f140e2eff299 (diff) | |
download | rockbox-f40bfc9267b13b54e6379dfe7539447662879d24.tar.gz rockbox-f40bfc9267b13b54e6379dfe7539447662879d24.zip |
Add codecs to librbcodec.
Change-Id: Id7f4717d51ed02d67cb9f9cb3c0ada4a81843f97
Reviewed-on: http://gerrit.rockbox.org/137
Reviewed-by: Nils Wallménius <nils@rockbox.org>
Tested-by: Nils Wallménius <nils@rockbox.org>
Diffstat (limited to 'lib/rbcodec/codecs/libgme/multi_buffer.h')
-rw-r--r-- | lib/rbcodec/codecs/libgme/multi_buffer.h | 114 |
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 | ||
11 | struct channel_t { | ||
12 | struct Blip_Buffer* center; | ||
13 | struct Blip_Buffer* left; | ||
14 | struct Blip_Buffer* right; | ||
15 | }; | ||
16 | |||
17 | enum { type_index_mask = 0xFF }; | ||
18 | enum { wave_type = 0x100, noise_type = 0x200, mixed_type = wave_type | noise_type }; | ||
19 | enum { stereo = 2 }; | ||
20 | enum { bufs_size = 3 }; | ||
21 | |||
22 | // Tracked_Blip_Buffer | ||
23 | struct Tracked_Blip_Buffer { | ||
24 | struct Blip_Buffer blip; | ||
25 | int last_non_silence; | ||
26 | }; | ||
27 | |||
28 | void Tracked_init( struct Tracked_Blip_Buffer* this ); | ||
29 | unsigned Tracked_non_silent( struct Tracked_Blip_Buffer* this ); | ||
30 | void Tracked_remove_all_samples( struct Tracked_Blip_Buffer * this ); | ||
31 | int Tracked_read_samples( struct Tracked_Blip_Buffer* this, blip_sample_t [], int ); | ||
32 | void Tracked_remove_silence( struct Tracked_Blip_Buffer* this, int ); | ||
33 | void Tracked_remove_samples( struct Tracked_Blip_Buffer* this, int ); | ||
34 | void Tracked_clear( struct Tracked_Blip_Buffer* this ); | ||
35 | void Tracked_end_frame( struct Tracked_Blip_Buffer* this, blip_time_t ); | ||
36 | |||
37 | static inline delta_t unsettled( struct Blip_Buffer* this ) | ||
38 | { | ||
39 | return this->reader_accum_ >> delta_bits; | ||
40 | } | ||
41 | |||
42 | // Stereo Mixer | ||
43 | struct Stereo_Mixer { | ||
44 | struct Tracked_Blip_Buffer* bufs [3]; | ||
45 | int samples_read; | ||
46 | }; | ||
47 | |||
48 | void Mixer_init( struct Stereo_Mixer* this ); | ||
49 | void Mixer_read_pairs( struct Stereo_Mixer* this, blip_sample_t out [], int count ); | ||
50 | |||
51 | typedef struct Tracked_Blip_Buffer buf_t; | ||
52 | |||
53 | // Multi_Buffer | ||
54 | struct 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 | |||
68 | blargg_err_t Buffer_set_channel_count( struct Multi_Buffer* this, int n, int const* types ); | ||
69 | |||
70 | // Buffers used for all channels | ||
71 | static inline struct Blip_Buffer* center( struct Multi_Buffer* this ) { return &this->bufs [2].blip; } | ||
72 | static inline struct Blip_Buffer* left( struct Multi_Buffer* this ) { return &this->bufs [0].blip; } | ||
73 | static inline struct Blip_Buffer* right( struct Multi_Buffer* this ) { return &this->bufs [1].blip; } | ||
74 | |||
75 | // Initializes Multi_Buffer structure | ||
76 | void Buffer_init( struct Multi_Buffer* this ); | ||
77 | |||
78 | blargg_err_t Buffer_set_sample_rate( struct Multi_Buffer* this, int, int msec ); | ||
79 | void Buffer_clock_rate( struct Multi_Buffer* this, int ); | ||
80 | void Buffer_bass_freq( struct Multi_Buffer* this, int ); | ||
81 | void Buffer_clear( struct Multi_Buffer* this ); | ||
82 | void Buffer_end_frame( struct Multi_Buffer* this, blip_time_t ) ICODE_ATTR; | ||
83 | |||
84 | static 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. | ||
91 | static inline unsigned Buffer_channels_changed_count( struct Multi_Buffer* this ) | ||
92 | { | ||
93 | return this->channels_changed_count_; | ||
94 | } | ||
95 | |||
96 | static inline void Buffer_disable_immediate_removal( struct Multi_Buffer* this ) | ||
97 | { | ||
98 | this->immediate_removal_ = false; | ||
99 | } | ||
100 | |||
101 | static inline int Buffer_sample_rate( struct Multi_Buffer* this ) | ||
102 | { | ||
103 | return this->sample_rate_; | ||
104 | } | ||
105 | |||
106 | static 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 | |||
111 | int Buffer_read_samples( struct Multi_Buffer* this, blip_sample_t*, int ) ICODE_ATTR; | ||
112 | struct channel_t Buffer_channel( struct Multi_Buffer* this, int i ); | ||
113 | |||
114 | #endif | ||