summaryrefslogtreecommitdiff
path: root/apps/codecs/libgme/multi_buffer.h
diff options
context:
space:
mode:
Diffstat (limited to 'apps/codecs/libgme/multi_buffer.h')
-rw-r--r--apps/codecs/libgme/multi_buffer.h108
1 files changed, 75 insertions, 33 deletions
diff --git a/apps/codecs/libgme/multi_buffer.h b/apps/codecs/libgme/multi_buffer.h
index cfdae4f077..e5efa5a230 100644
--- a/apps/codecs/libgme/multi_buffer.h
+++ b/apps/codecs/libgme/multi_buffer.h
@@ -1,4 +1,4 @@
1// Multi-channel sound buffer interface, and basic mono and stereo buffers 1// Multi-channel sound buffer interface, stereo and effects buffers
2 2
3// Blip_Buffer 0.4.1 3// Blip_Buffer 0.4.1
4#ifndef MULTI_BUFFER_H 4#ifndef MULTI_BUFFER_H
@@ -16,57 +16,99 @@ struct channel_t {
16 16
17enum { type_index_mask = 0xFF }; 17enum { type_index_mask = 0xFF };
18enum { wave_type = 0x100, noise_type = 0x200, mixed_type = wave_type | noise_type }; 18enum { wave_type = 0x100, noise_type = 0x200, mixed_type = wave_type | noise_type };
19enum { buf_count = 3 }; 19enum { stereo = 2 };
20 20enum { bufs_size = 3 };
21struct Stereo_Buffer { 21
22 struct Blip_Buffer bufs [buf_count]; 22// Tracked_Blip_Buffer
23 struct channel_t chan; 23struct Tracked_Blip_Buffer {
24 int stereo_added; 24 struct Blip_Buffer blip;
25 int was_stereo; 25 int last_non_silence;
26 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 {
27 unsigned channels_changed_count_; 55 unsigned channels_changed_count_;
28 long sample_rate_; 56 int sample_rate_;
29 int length_; 57 int length_;
58 int channel_count_;
30 int samples_per_frame_; 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;
31}; 66};
32 67
33// Initializes Stereo_Buffer structure 68blargg_err_t Buffer_set_channel_count( struct Multi_Buffer* this, int n, int const* types );
34void Buffer_init( struct Stereo_Buffer* this ); 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; }
35 74
36blargg_err_t Buffer_set_sample_rate( struct Stereo_Buffer* this, long, int msec ); 75// Initializes Multi_Buffer structure
37void Buffer_clock_rate( struct Stereo_Buffer* this, long ); 76void Buffer_init( struct Multi_Buffer* this );
38void Buffer_bass_freq( struct Stereo_Buffer* this, int );
39void Buffer_clear( struct Stereo_Buffer* this );
40struct channel_t Buffer_channel( struct Stereo_Buffer* this );
41void Buffer_end_frame( struct Stereo_Buffer* this, blip_time_t );
42 77
43long Buffer_read_samples( struct Stereo_Buffer* this, blip_sample_t*, long ); 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}
44 88
45// Count of changes to channel configuration. Incremented whenever 89// Count of changes to channel configuration. Incremented whenever
46// a change is made to any of the Blip_Buffers for any channel. 90// a change is made to any of the Blip_Buffers for any channel.
47unsigned Buffer_channels_changed_count( struct Stereo_Buffer* this ); 91static inline unsigned Buffer_channels_changed_count( struct Multi_Buffer* this )
48void Buffer_channels_changed( struct Stereo_Buffer* this ); 92{
49 93 return this->channels_changed_count_;
50void Buffer_mix_stereo_no_center( struct Stereo_Buffer* this, blip_sample_t*, blargg_long ); 94}
51void Buffer_mix_stereo( struct Stereo_Buffer* this, blip_sample_t*, blargg_long );
52void Buffer_mix_mono( struct Stereo_Buffer* this, blip_sample_t*, blargg_long );
53 95
54// Number of samples per output frame (1 = mono, 2 = stereo) 96static inline void Buffer_disable_immediate_removal( struct Multi_Buffer* this )
55static inline int Buffer_samples_per_frame( struct Stereo_Buffer* this )
56{ 97{
57 return this->samples_per_frame_; 98 this->immediate_removal_ = false;
58} 99}
59 100
60// See Blip_Buffer.h 101static inline int Buffer_sample_rate( struct Multi_Buffer* this )
61static inline long Buffer_sample_rate( struct Stereo_Buffer* this )
62{ 102{
63 return this->sample_rate_; 103 return this->sample_rate_;
64} 104}
65 105
66// Length of buffer, in milliseconds 106static inline int Buffer_samples_avail( struct Multi_Buffer* this )
67static inline int Buffer_length( struct Stereo_Buffer* this )
68{ 107{
69 return this->length_; 108 return (Blip_samples_avail(&this->bufs [0].blip) - this->mixer.samples_read) * 2;
70} 109}
71 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
72#endif 114#endif