* [2SF] Used more up-to-date asmjit, despite the ugly looking code.
| ... | ... |
@@ -31,14 +31,14 @@ public: |
| 31 | 31 |
virtual channel_t channel(int index); |
| 32 | 32 |
|
| 33 | 33 |
// See Blip_Buffer.h |
| 34 |
- virtual void set_sample_rate(long rate, int msec = blip_default_length); |
|
| 34 |
+ virtual void set_sample_rate(long rate, long msec = blip_default_length); |
|
| 35 | 35 |
virtual void clock_rate(long) { }
|
| 36 | 36 |
virtual void bass_freq(int) { }
|
| 37 | 37 |
virtual void clear() { }
|
| 38 | 38 |
long sample_rate() const; |
| 39 | 39 |
|
| 40 | 40 |
// Length of buffer, in milliseconds |
| 41 |
- int length() const; |
|
| 41 |
+ int32_t length() const; |
|
| 42 | 42 |
|
| 43 | 43 |
// See Blip_Buffer.h |
| 44 | 44 |
virtual void end_frame(blip_time_t) { }
|
| ... | ... |
@@ -66,7 +66,7 @@ private: |
| 66 | 66 |
|
| 67 | 67 |
unsigned channels_changed_count_; |
| 68 | 68 |
long sample_rate_; |
| 69 |
- int length_; |
|
| 69 |
+ int32_t length_; |
|
| 70 | 70 |
int channel_count_; |
| 71 | 71 |
const int samples_per_frame_; |
| 72 | 72 |
const int *channel_types_; |
| ... | ... |
@@ -115,7 +115,7 @@ public: |
| 115 | 115 |
|
| 116 | 116 |
Stereo_Buffer(); |
| 117 | 117 |
~Stereo_Buffer(); |
| 118 |
- void set_sample_rate(long, int msec = blip_default_length); |
|
| 118 |
+ void set_sample_rate(long, long msec = blip_default_length); |
|
| 119 | 119 |
void clock_rate(long); |
| 120 | 120 |
void bass_freq(int); |
| 121 | 121 |
void clear(); |
| ... | ... |
@@ -134,7 +134,7 @@ private: |
| 134 | 134 |
long samples_avail_; |
| 135 | 135 |
}; |
| 136 | 136 |
|
| 137 |
-inline void Multi_Buffer::set_sample_rate(long rate, int msec) |
|
| 137 |
+inline void Multi_Buffer::set_sample_rate(long rate, long msec) |
|
| 138 | 138 |
{
|
| 139 | 139 |
this->sample_rate_ = rate; |
| 140 | 140 |
this->length_ = msec; |
| ... | ... |
@@ -144,7 +144,7 @@ inline int Multi_Buffer::samples_per_frame() const { return this->samples_per_fr
|
| 144 | 144 |
|
| 145 | 145 |
inline long Multi_Buffer::sample_rate() const { return this->sample_rate_; }
|
| 146 | 146 |
|
| 147 |
-inline int Multi_Buffer::length() const { return this->length_; }
|
|
| 147 |
+inline int32_t Multi_Buffer::length() const { return this->length_; }
|
|
| 148 | 148 |
|
| 149 | 149 |
inline void Multi_Buffer::set_channel_count(int n, const int *types) |
| 150 | 150 |
{
|
| ... | ... |
@@ -1,8 +1,7 @@ |
| 1 | 1 |
// Multi-channel sound buffer interface, and basic mono and stereo buffers |
| 2 | 2 |
|
| 3 | 3 |
// Blip_Buffer 0.4.1 |
| 4 |
-#ifndef MULTI_BUFFER_H |
|
| 5 |
-#define MULTI_BUFFER_H |
|
| 4 |
+#pragma once |
|
| 6 | 5 |
|
| 7 | 6 |
#include "blargg_common.h" |
| 8 | 7 |
#include "Blip_Buffer.h" |
| ... | ... |
@@ -19,7 +18,7 @@ public: |
| 19 | 18 |
// (type information used by Effects_Buffer) |
| 20 | 19 |
enum { type_index_mask = 0xFF };
|
| 21 | 20 |
enum { wave_type = 0x100, noise_type = 0x200, mixed_type = wave_type | noise_type };
|
| 22 |
- virtual void set_channel_count(int, const int* types = nullptr); |
|
| 21 |
+ virtual void set_channel_count(int, const int *types = nullptr); |
|
| 23 | 22 |
int channel_count() const { return this->channel_count_; }
|
| 24 | 23 |
|
| 25 | 24 |
// Gets indexed channel, from 0 to channel count - 1 |
| ... | ... |
@@ -152,5 +151,3 @@ inline void Multi_Buffer::set_channel_count(int n, const int *types) |
| 152 | 151 |
this->channel_count_ = n; |
| 153 | 152 |
this->channel_types_ = types; |
| 154 | 153 |
} |
| 155 |
- |
|
| 156 |
-#endif |
| ... | ... |
@@ -19,7 +19,7 @@ public: |
| 19 | 19 |
// (type information used by Effects_Buffer) |
| 20 | 20 |
enum { type_index_mask = 0xFF };
|
| 21 | 21 |
enum { wave_type = 0x100, noise_type = 0x200, mixed_type = wave_type | noise_type };
|
| 22 |
- virtual blargg_err_t set_channel_count(int, const int* types = nullptr); |
|
| 22 |
+ virtual void set_channel_count(int, const int* types = nullptr); |
|
| 23 | 23 |
int channel_count() const { return this->channel_count_; }
|
| 24 | 24 |
|
| 25 | 25 |
// Gets indexed channel, from 0 to channel count - 1 |
| ... | ... |
@@ -32,7 +32,7 @@ public: |
| 32 | 32 |
virtual channel_t channel(int index); |
| 33 | 33 |
|
| 34 | 34 |
// See Blip_Buffer.h |
| 35 |
- virtual blargg_err_t set_sample_rate(long rate, int msec = blip_default_length); |
|
| 35 |
+ virtual void set_sample_rate(long rate, int msec = blip_default_length); |
|
| 36 | 36 |
virtual void clock_rate(long) { }
|
| 37 | 37 |
virtual void bass_freq(int) { }
|
| 38 | 38 |
virtual void clear() { }
|
| ... | ... |
@@ -74,27 +74,6 @@ private: |
| 74 | 74 |
bool immediate_removal_; |
| 75 | 75 |
}; |
| 76 | 76 |
|
| 77 |
-// Uses a single buffer and outputs mono samples. |
|
| 78 |
-class Mono_Buffer : public Multi_Buffer |
|
| 79 |
-{
|
|
| 80 |
- Blip_Buffer buf; |
|
| 81 |
- channel_t chan; |
|
| 82 |
-public: |
|
| 83 |
- // Buffer used for all channels |
|
| 84 |
- Blip_Buffer *center() { return &this->buf; }
|
|
| 85 |
- |
|
| 86 |
- Mono_Buffer(); |
|
| 87 |
- ~Mono_Buffer(); |
|
| 88 |
- blargg_err_t set_sample_rate(long rate, int msec = blip_default_length); |
|
| 89 |
- void clock_rate(long rate) { this->buf.clock_rate(rate); }
|
|
| 90 |
- void bass_freq(int freq) { this->buf.bass_freq(freq); }
|
|
| 91 |
- void clear() { this->buf.clear(); }
|
|
| 92 |
- long samples_avail() const { return this->buf.samples_avail(); }
|
|
| 93 |
- long read_samples(blip_sample_t *p, long s) { return this->buf.read_samples(p, s); }
|
|
| 94 |
- channel_t channel(int) { return this->chan; }
|
|
| 95 |
- void end_frame(blip_time_t t) { this->buf.end_frame(t); }
|
|
| 96 |
-}; |
|
| 97 |
- |
|
| 98 | 77 |
class Tracked_Blip_Buffer : public Blip_Buffer |
| 99 | 78 |
{
|
| 100 | 79 |
public: |
| ... | ... |
@@ -137,7 +116,7 @@ public: |
| 137 | 116 |
|
| 138 | 117 |
Stereo_Buffer(); |
| 139 | 118 |
~Stereo_Buffer(); |
| 140 |
- blargg_err_t set_sample_rate(long, int msec = blip_default_length); |
|
| 119 |
+ void set_sample_rate(long, int msec = blip_default_length); |
|
| 141 | 120 |
void clock_rate(long); |
| 142 | 121 |
void bass_freq(int); |
| 143 | 122 |
void clear(); |
| ... | ... |
@@ -156,32 +135,10 @@ private: |
| 156 | 135 |
long samples_avail_; |
| 157 | 136 |
}; |
| 158 | 137 |
|
| 159 |
-// Silent_Buffer generates no samples, useful where no sound is wanted |
|
| 160 |
-class Silent_Buffer : public Multi_Buffer |
|
| 161 |
-{
|
|
| 162 |
- channel_t chan; |
|
| 163 |
-public: |
|
| 164 |
- Silent_Buffer(); |
|
| 165 |
- blargg_err_t set_sample_rate(long rate, int msec = blip_default_length); |
|
| 166 |
- void clock_rate(long) { }
|
|
| 167 |
- void bass_freq(int) { }
|
|
| 168 |
- void clear() { }
|
|
| 169 |
- channel_t channel(int) { return this->chan; }
|
|
| 170 |
- void end_frame(blip_time_t) { }
|
|
| 171 |
- long samples_avail() const { return 0; }
|
|
| 172 |
- long read_samples(blip_sample_t *, long) { return 0; }
|
|
| 173 |
-}; |
|
| 174 |
- |
|
| 175 |
-inline blargg_err_t Multi_Buffer::set_sample_rate(long rate, int msec) |
|
| 138 |
+inline void Multi_Buffer::set_sample_rate(long rate, int msec) |
|
| 176 | 139 |
{
|
| 177 | 140 |
this->sample_rate_ = rate; |
| 178 | 141 |
this->length_ = msec; |
| 179 |
- return 0; |
|
| 180 |
-} |
|
| 181 |
- |
|
| 182 |
-inline blargg_err_t Silent_Buffer::set_sample_rate(long rate, int msec) |
|
| 183 |
-{
|
|
| 184 |
- return Multi_Buffer::set_sample_rate(rate, msec); |
|
| 185 | 142 |
} |
| 186 | 143 |
|
| 187 | 144 |
inline int Multi_Buffer::samples_per_frame() const { return this->samples_per_frame_; }
|
| ... | ... |
@@ -190,11 +147,10 @@ inline long Multi_Buffer::sample_rate() const { return this->sample_rate_; }
|
| 190 | 147 |
|
| 191 | 148 |
inline int Multi_Buffer::length() const { return this->length_; }
|
| 192 | 149 |
|
| 193 |
-inline blargg_err_t Multi_Buffer::set_channel_count(int n, const int *types) |
|
| 150 |
+inline void Multi_Buffer::set_channel_count(int n, const int *types) |
|
| 194 | 151 |
{
|
| 195 | 152 |
this->channel_count_ = n; |
| 196 | 153 |
this->channel_types_ = types; |
| 197 |
- return 0; |
|
| 198 | 154 |
} |
| 199 | 155 |
|
| 200 | 156 |
#endif |
(As an aside, blargg's code style makes me go blarg myself.)
| ... | ... |
@@ -9,196 +9,191 @@ |
| 9 | 9 |
|
| 10 | 10 |
// Interface to one or more Blip_Buffers mapped to one or more channels |
| 11 | 11 |
// consisting of left, center, and right buffers. |
| 12 |
-class Multi_Buffer {
|
|
| 12 |
+class Multi_Buffer |
|
| 13 |
+{
|
|
| 13 | 14 |
public: |
| 14 |
- Multi_Buffer( int samples_per_frame ); |
|
| 15 |
+ Multi_Buffer(int samples_per_frame); |
|
| 15 | 16 |
virtual ~Multi_Buffer() { }
|
| 16 | 17 |
|
| 17 | 18 |
// Sets the number of channels available and optionally their types |
| 18 | 19 |
// (type information used by Effects_Buffer) |
| 19 | 20 |
enum { type_index_mask = 0xFF };
|
| 20 | 21 |
enum { wave_type = 0x100, noise_type = 0x200, mixed_type = wave_type | noise_type };
|
| 21 |
- virtual blargg_err_t set_channel_count( int, int const* types = 0 ); |
|
| 22 |
- int channel_count() const { return channel_count_; }
|
|
| 22 |
+ virtual blargg_err_t set_channel_count(int, const int* types = nullptr); |
|
| 23 |
+ int channel_count() const { return this->channel_count_; }
|
|
| 23 | 24 |
|
| 24 | 25 |
// Gets indexed channel, from 0 to channel count - 1 |
| 25 |
- struct channel_t {
|
|
| 26 |
- Blip_Buffer* center; |
|
| 27 |
- Blip_Buffer* left; |
|
| 28 |
- Blip_Buffer* right; |
|
| 26 |
+ struct channel_t |
|
| 27 |
+ {
|
|
| 28 |
+ Blip_Buffer *center; |
|
| 29 |
+ Blip_Buffer *left; |
|
| 30 |
+ Blip_Buffer *right; |
|
| 29 | 31 |
}; |
| 30 |
- virtual channel_t channel( int index ) BLARGG_PURE( ; ) |
|
| 32 |
+ virtual channel_t channel(int index); |
|
| 31 | 33 |
|
| 32 | 34 |
// See Blip_Buffer.h |
| 33 |
- virtual blargg_err_t set_sample_rate( long rate, int msec = blip_default_length ) BLARGG_PURE( ; ) |
|
| 34 |
- virtual void clock_rate( long ) BLARGG_PURE( { } )
|
|
| 35 |
- virtual void bass_freq( int ) BLARGG_PURE( { } )
|
|
| 36 |
- virtual void clear() BLARGG_PURE( { } )
|
|
| 35 |
+ virtual blargg_err_t set_sample_rate(long rate, int msec = blip_default_length); |
|
| 36 |
+ virtual void clock_rate(long) { }
|
|
| 37 |
+ virtual void bass_freq(int) { }
|
|
| 38 |
+ virtual void clear() { }
|
|
| 37 | 39 |
long sample_rate() const; |
| 38 | 40 |
|
| 39 | 41 |
// Length of buffer, in milliseconds |
| 40 | 42 |
int length() const; |
| 41 | 43 |
|
| 42 | 44 |
// See Blip_Buffer.h |
| 43 |
- virtual void end_frame( blip_time_t ) BLARGG_PURE( { } )
|
|
| 45 |
+ virtual void end_frame(blip_time_t) { }
|
|
| 44 | 46 |
|
| 45 | 47 |
// Number of samples per output frame (1 = mono, 2 = stereo) |
| 46 | 48 |
int samples_per_frame() const; |
| 47 | 49 |
|
| 48 | 50 |
// Count of changes to channel configuration. Incremented whenever |
| 49 | 51 |
// a change is made to any of the Blip_Buffers for any channel. |
| 50 |
- unsigned channels_changed_count() { return channels_changed_count_; }
|
|
| 52 |
+ unsigned channels_changed_count() { return this->channels_changed_count_; }
|
|
| 51 | 53 |
|
| 52 | 54 |
// See Blip_Buffer.h |
| 53 |
- virtual long read_samples( blip_sample_t*, long ) BLARGG_PURE( { return 0; } )
|
|
| 54 |
- virtual long samples_avail() const BLARGG_PURE( { return 0; } )
|
|
| 55 |
+ virtual long read_samples(blip_sample_t *, long) { return 0; }
|
|
| 56 |
+ virtual long samples_avail() const { return 0; }
|
|
| 55 | 57 |
|
| 56 |
-public: |
|
| 57 |
- BLARGG_DISABLE_NOTHROW |
|
| 58 |
- void disable_immediate_removal() { immediate_removal_ = false; }
|
|
| 58 |
+ void disable_immediate_removal() { this->immediate_removal_ = false; }
|
|
| 59 | 59 |
protected: |
| 60 |
- bool immediate_removal() const { return immediate_removal_; }
|
|
| 61 |
- int const* channel_types() const { return channel_types_; }
|
|
| 62 |
- void channels_changed() { channels_changed_count_++; }
|
|
| 60 |
+ bool immediate_removal() const { return this->immediate_removal_; }
|
|
| 61 |
+ const int *channel_types() const { return this->channel_types_; }
|
|
| 62 |
+ void channels_changed() { ++this->channels_changed_count_; }
|
|
| 63 | 63 |
private: |
| 64 | 64 |
// noncopyable |
| 65 |
- Multi_Buffer( const Multi_Buffer& ); |
|
| 66 |
- Multi_Buffer& operator = ( const Multi_Buffer& ); |
|
| 65 |
+ Multi_Buffer(const Multi_Buffer &); |
|
| 66 |
+ Multi_Buffer &operator=(const Multi_Buffer &); |
|
| 67 | 67 |
|
| 68 | 68 |
unsigned channels_changed_count_; |
| 69 | 69 |
long sample_rate_; |
| 70 | 70 |
int length_; |
| 71 | 71 |
int channel_count_; |
| 72 |
- int const samples_per_frame_; |
|
| 73 |
- int const* channel_types_; |
|
| 72 |
+ const int samples_per_frame_; |
|
| 73 |
+ const int *channel_types_; |
|
| 74 | 74 |
bool immediate_removal_; |
| 75 | 75 |
}; |
| 76 | 76 |
|
| 77 | 77 |
// Uses a single buffer and outputs mono samples. |
| 78 |
-class Mono_Buffer : public Multi_Buffer {
|
|
| 78 |
+class Mono_Buffer : public Multi_Buffer |
|
| 79 |
+{
|
|
| 79 | 80 |
Blip_Buffer buf; |
| 80 | 81 |
channel_t chan; |
| 81 | 82 |
public: |
| 82 | 83 |
// Buffer used for all channels |
| 83 |
- Blip_Buffer* center() { return &buf; }
|
|
| 84 |
+ Blip_Buffer *center() { return &this->buf; }
|
|
| 84 | 85 |
|
| 85 |
-public: |
|
| 86 | 86 |
Mono_Buffer(); |
| 87 | 87 |
~Mono_Buffer(); |
| 88 |
- blargg_err_t set_sample_rate( long rate, int msec = blip_default_length ); |
|
| 89 |
- void clock_rate( long rate ) { buf.clock_rate( rate ); }
|
|
| 90 |
- void bass_freq( int freq ) { buf.bass_freq( freq ); }
|
|
| 91 |
- void clear() { buf.clear(); }
|
|
| 92 |
- long samples_avail() const { return buf.samples_avail(); }
|
|
| 93 |
- long read_samples( blip_sample_t* p, long s ) { return buf.read_samples( p, s ); }
|
|
| 94 |
- channel_t channel( int ) { return chan; }
|
|
| 95 |
- void end_frame( blip_time_t t ) { buf.end_frame( t ); }
|
|
| 88 |
+ blargg_err_t set_sample_rate(long rate, int msec = blip_default_length); |
|
| 89 |
+ void clock_rate(long rate) { this->buf.clock_rate(rate); }
|
|
| 90 |
+ void bass_freq(int freq) { this->buf.bass_freq(freq); }
|
|
| 91 |
+ void clear() { this->buf.clear(); }
|
|
| 92 |
+ long samples_avail() const { return this->buf.samples_avail(); }
|
|
| 93 |
+ long read_samples(blip_sample_t *p, long s) { return this->buf.read_samples(p, s); }
|
|
| 94 |
+ channel_t channel(int) { return this->chan; }
|
|
| 95 |
+ void end_frame(blip_time_t t) { this->buf.end_frame(t); }
|
|
| 96 | 96 |
}; |
| 97 | 97 |
|
| 98 |
- class Tracked_Blip_Buffer : public Blip_Buffer {
|
|
| 99 |
- public: |
|
| 100 |
- // Non-zero if buffer still has non-silent samples in it. Requires that you call |
|
| 101 |
- // set_modified() appropriately. |
|
| 102 |
- blip_ulong non_silent() const; |
|
| 103 |
- |
|
| 104 |
- // remove_samples( samples_avail() ) |
|
| 105 |
- void remove_all_samples(); |
|
| 106 |
- |
|
| 107 |
- public: |
|
| 108 |
- BLARGG_DISABLE_NOTHROW |
|
| 109 |
- |
|
| 110 |
- long read_samples( blip_sample_t*, long ); |
|
| 111 |
- void remove_silence( long ); |
|
| 112 |
- void remove_samples( long ); |
|
| 113 |
- Tracked_Blip_Buffer(); |
|
| 114 |
- void clear(); |
|
| 115 |
- void end_frame( blip_time_t ); |
|
| 116 |
- private: |
|
| 117 |
- blip_long last_non_silence; |
|
| 118 |
- void remove_( long ); |
|
| 119 |
- }; |
|
| 98 |
+class Tracked_Blip_Buffer : public Blip_Buffer |
|
| 99 |
+{
|
|
| 100 |
+public: |
|
| 101 |
+ // Non-zero if buffer still has non-silent samples in it. Requires that you call |
|
| 102 |
+ // set_modified() appropriately. |
|
| 103 |
+ uint32_t non_silent() const; |
|
| 104 |
+ |
|
| 105 |
+ long read_samples(blip_sample_t *, long); |
|
| 106 |
+ void remove_silence(long); |
|
| 107 |
+ void remove_samples(long); |
|
| 108 |
+ Tracked_Blip_Buffer(); |
|
| 109 |
+ void clear(); |
|
| 110 |
+ void end_frame(blip_time_t); |
|
| 111 |
+private: |
|
| 112 |
+ int32_t last_non_silence; |
|
| 113 |
+ void remove_(long); |
|
| 114 |
+}; |
|
| 120 | 115 |
|
| 121 |
- class Stereo_Mixer {
|
|
| 122 |
- public: |
|
| 123 |
- Tracked_Blip_Buffer* bufs [3]; |
|
| 124 |
- blargg_long samples_read; |
|
| 116 |
+class Stereo_Mixer |
|
| 117 |
+{
|
|
| 118 |
+public: |
|
| 119 |
+ Tracked_Blip_Buffer *bufs[3]; |
|
| 120 |
+ int32_t samples_read; |
|
| 125 | 121 |
|
| 126 |
- Stereo_Mixer() : samples_read( 0 ) { }
|
|
| 127 |
- void read_pairs( blip_sample_t* out, int count ); |
|
| 128 |
- private: |
|
| 129 |
- void mix_mono ( blip_sample_t* out, int pair_count ); |
|
| 130 |
- void mix_stereo( blip_sample_t* out, int pair_count ); |
|
| 131 |
- }; |
|
| 122 |
+ Stereo_Mixer() : samples_read(0) { }
|
|
| 123 |
+ void read_pairs(blip_sample_t *out, int count); |
|
| 124 |
+private: |
|
| 125 |
+ void mix_mono(blip_sample_t *out, int pair_count); |
|
| 126 |
+ void mix_stereo(blip_sample_t *out, int pair_count); |
|
| 127 |
+}; |
|
| 132 | 128 |
|
| 133 | 129 |
// Uses three buffers (one for center) and outputs stereo sample pairs. |
| 134 |
-class Stereo_Buffer : public Multi_Buffer {
|
|
| 130 |
+class Stereo_Buffer : public Multi_Buffer |
|
| 131 |
+{
|
|
| 135 | 132 |
public: |
| 136 |
- |
|
| 137 | 133 |
// Buffers used for all channels |
| 138 |
- Blip_Buffer* center() { return &bufs [2]; }
|
|
| 139 |
- Blip_Buffer* left() { return &bufs [0]; }
|
|
| 140 |
- Blip_Buffer* right() { return &bufs [1]; }
|
|
| 134 |
+ Blip_Buffer *center() { return &this->bufs[2]; }
|
|
| 135 |
+ Blip_Buffer *left() { return &this->bufs[0]; }
|
|
| 136 |
+ Blip_Buffer *right() { return &this->bufs[1]; }
|
|
| 141 | 137 |
|
| 142 |
-public: |
|
| 143 | 138 |
Stereo_Buffer(); |
| 144 | 139 |
~Stereo_Buffer(); |
| 145 |
- blargg_err_t set_sample_rate( long, int msec = blip_default_length ); |
|
| 146 |
- void clock_rate( long ); |
|
| 147 |
- void bass_freq( int ); |
|
| 140 |
+ blargg_err_t set_sample_rate(long, int msec = blip_default_length); |
|
| 141 |
+ void clock_rate(long); |
|
| 142 |
+ void bass_freq(int); |
|
| 148 | 143 |
void clear(); |
| 149 |
- channel_t channel( int ) { return chan; }
|
|
| 150 |
- void end_frame( blip_time_t ); |
|
| 144 |
+ channel_t channel(int) { return this->chan; }
|
|
| 145 |
+ void end_frame(blip_time_t); |
|
| 151 | 146 |
|
| 152 |
- long samples_avail() const { return (bufs [0].samples_avail() - mixer.samples_read) * 2; }
|
|
| 153 |
- long read_samples( blip_sample_t*, long ); |
|
| 147 |
+ long samples_avail() const { return (this->bufs[0].samples_avail() - this->mixer.samples_read) * 2; }
|
|
| 148 |
+ long read_samples(blip_sample_t *, long); |
|
| 154 | 149 |
|
| 155 | 150 |
private: |
| 156 | 151 |
enum { bufs_size = 3 };
|
| 157 | 152 |
typedef Tracked_Blip_Buffer buf_t; |
| 158 |
- buf_t bufs [bufs_size]; |
|
| 153 |
+ buf_t bufs[bufs_size]; |
|
| 159 | 154 |
Stereo_Mixer mixer; |
| 160 | 155 |
channel_t chan; |
| 161 | 156 |
long samples_avail_; |
| 162 | 157 |
}; |
| 163 | 158 |
|
| 164 | 159 |
// Silent_Buffer generates no samples, useful where no sound is wanted |
| 165 |
-class Silent_Buffer : public Multi_Buffer {
|
|
| 160 |
+class Silent_Buffer : public Multi_Buffer |
|
| 161 |
+{
|
|
| 166 | 162 |
channel_t chan; |
| 167 | 163 |
public: |
| 168 | 164 |
Silent_Buffer(); |
| 169 |
- blargg_err_t set_sample_rate( long rate, int msec = blip_default_length ); |
|
| 170 |
- void clock_rate( long ) { }
|
|
| 171 |
- void bass_freq( int ) { }
|
|
| 165 |
+ blargg_err_t set_sample_rate(long rate, int msec = blip_default_length); |
|
| 166 |
+ void clock_rate(long) { }
|
|
| 167 |
+ void bass_freq(int) { }
|
|
| 172 | 168 |
void clear() { }
|
| 173 |
- channel_t channel( int ) { return chan; }
|
|
| 174 |
- void end_frame( blip_time_t ) { }
|
|
| 169 |
+ channel_t channel(int) { return this->chan; }
|
|
| 170 |
+ void end_frame(blip_time_t) { }
|
|
| 175 | 171 |
long samples_avail() const { return 0; }
|
| 176 |
- long read_samples( blip_sample_t*, long ) { return 0; }
|
|
| 172 |
+ long read_samples(blip_sample_t *, long) { return 0; }
|
|
| 177 | 173 |
}; |
| 178 | 174 |
|
| 179 |
- |
|
| 180 |
-inline blargg_err_t Multi_Buffer::set_sample_rate( long rate, int msec ) |
|
| 175 |
+inline blargg_err_t Multi_Buffer::set_sample_rate(long rate, int msec) |
|
| 181 | 176 |
{
|
| 182 |
- sample_rate_ = rate; |
|
| 183 |
- length_ = msec; |
|
| 177 |
+ this->sample_rate_ = rate; |
|
| 178 |
+ this->length_ = msec; |
|
| 184 | 179 |
return 0; |
| 185 | 180 |
} |
| 186 | 181 |
|
| 187 |
-inline blargg_err_t Silent_Buffer::set_sample_rate( long rate, int msec ) |
|
| 182 |
+inline blargg_err_t Silent_Buffer::set_sample_rate(long rate, int msec) |
|
| 188 | 183 |
{
|
| 189 |
- return Multi_Buffer::set_sample_rate( rate, msec ); |
|
| 184 |
+ return Multi_Buffer::set_sample_rate(rate, msec); |
|
| 190 | 185 |
} |
| 191 | 186 |
|
| 192 |
-inline int Multi_Buffer::samples_per_frame() const { return samples_per_frame_; }
|
|
| 187 |
+inline int Multi_Buffer::samples_per_frame() const { return this->samples_per_frame_; }
|
|
| 193 | 188 |
|
| 194 |
-inline long Multi_Buffer::sample_rate() const { return sample_rate_; }
|
|
| 189 |
+inline long Multi_Buffer::sample_rate() const { return this->sample_rate_; }
|
|
| 195 | 190 |
|
| 196 |
-inline int Multi_Buffer::length() const { return length_; }
|
|
| 191 |
+inline int Multi_Buffer::length() const { return this->length_; }
|
|
| 197 | 192 |
|
| 198 |
-inline blargg_err_t Multi_Buffer::set_channel_count( int n, int const* types ) |
|
| 193 |
+inline blargg_err_t Multi_Buffer::set_channel_count(int n, const int *types) |
|
| 199 | 194 |
{
|
| 200 |
- channel_count_ = n; |
|
| 201 |
- channel_types_ = types; |
|
| 195 |
+ this->channel_count_ = n; |
|
| 196 |
+ this->channel_types_ = types; |
|
| 202 | 197 |
return 0; |
| 203 | 198 |
} |
| 204 | 199 |
|
| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,205 @@ |
| 1 |
+// Multi-channel sound buffer interface, and basic mono and stereo 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 |
+// Interface to one or more Blip_Buffers mapped to one or more channels |
|
| 11 |
+// consisting of left, center, and right buffers. |
|
| 12 |
+class Multi_Buffer {
|
|
| 13 |
+public: |
|
| 14 |
+ Multi_Buffer( int samples_per_frame ); |
|
| 15 |
+ virtual ~Multi_Buffer() { }
|
|
| 16 |
+ |
|
| 17 |
+ // Sets the number of channels available and optionally their types |
|
| 18 |
+ // (type information used by Effects_Buffer) |
|
| 19 |
+ enum { type_index_mask = 0xFF };
|
|
| 20 |
+ enum { wave_type = 0x100, noise_type = 0x200, mixed_type = wave_type | noise_type };
|
|
| 21 |
+ virtual blargg_err_t set_channel_count( int, int const* types = 0 ); |
|
| 22 |
+ int channel_count() const { return channel_count_; }
|
|
| 23 |
+ |
|
| 24 |
+ // Gets indexed channel, from 0 to channel count - 1 |
|
| 25 |
+ struct channel_t {
|
|
| 26 |
+ Blip_Buffer* center; |
|
| 27 |
+ Blip_Buffer* left; |
|
| 28 |
+ Blip_Buffer* right; |
|
| 29 |
+ }; |
|
| 30 |
+ virtual channel_t channel( int index ) BLARGG_PURE( ; ) |
|
| 31 |
+ |
|
| 32 |
+ // See Blip_Buffer.h |
|
| 33 |
+ virtual blargg_err_t set_sample_rate( long rate, int msec = blip_default_length ) BLARGG_PURE( ; ) |
|
| 34 |
+ virtual void clock_rate( long ) BLARGG_PURE( { } )
|
|
| 35 |
+ virtual void bass_freq( int ) BLARGG_PURE( { } )
|
|
| 36 |
+ virtual void clear() BLARGG_PURE( { } )
|
|
| 37 |
+ long sample_rate() const; |
|
| 38 |
+ |
|
| 39 |
+ // Length of buffer, in milliseconds |
|
| 40 |
+ int length() const; |
|
| 41 |
+ |
|
| 42 |
+ // See Blip_Buffer.h |
|
| 43 |
+ virtual void end_frame( blip_time_t ) BLARGG_PURE( { } )
|
|
| 44 |
+ |
|
| 45 |
+ // Number of samples per output frame (1 = mono, 2 = stereo) |
|
| 46 |
+ int samples_per_frame() const; |
|
| 47 |
+ |
|
| 48 |
+ // Count of changes to channel configuration. Incremented whenever |
|
| 49 |
+ // a change is made to any of the Blip_Buffers for any channel. |
|
| 50 |
+ unsigned channels_changed_count() { return channels_changed_count_; }
|
|
| 51 |
+ |
|
| 52 |
+ // See Blip_Buffer.h |
|
| 53 |
+ virtual long read_samples( blip_sample_t*, long ) BLARGG_PURE( { return 0; } )
|
|
| 54 |
+ virtual long samples_avail() const BLARGG_PURE( { return 0; } )
|
|
| 55 |
+ |
|
| 56 |
+public: |
|
| 57 |
+ BLARGG_DISABLE_NOTHROW |
|
| 58 |
+ void disable_immediate_removal() { immediate_removal_ = false; }
|
|
| 59 |
+protected: |
|
| 60 |
+ bool immediate_removal() const { return immediate_removal_; }
|
|
| 61 |
+ int const* channel_types() const { return channel_types_; }
|
|
| 62 |
+ void channels_changed() { channels_changed_count_++; }
|
|
| 63 |
+private: |
|
| 64 |
+ // noncopyable |
|
| 65 |
+ Multi_Buffer( const Multi_Buffer& ); |
|
| 66 |
+ Multi_Buffer& operator = ( const Multi_Buffer& ); |
|
| 67 |
+ |
|
| 68 |
+ unsigned channels_changed_count_; |
|
| 69 |
+ long sample_rate_; |
|
| 70 |
+ int length_; |
|
| 71 |
+ int channel_count_; |
|
| 72 |
+ int const samples_per_frame_; |
|
| 73 |
+ int const* channel_types_; |
|
| 74 |
+ bool immediate_removal_; |
|
| 75 |
+}; |
|
| 76 |
+ |
|
| 77 |
+// Uses a single buffer and outputs mono samples. |
|
| 78 |
+class Mono_Buffer : public Multi_Buffer {
|
|
| 79 |
+ Blip_Buffer buf; |
|
| 80 |
+ channel_t chan; |
|
| 81 |
+public: |
|
| 82 |
+ // Buffer used for all channels |
|
| 83 |
+ Blip_Buffer* center() { return &buf; }
|
|
| 84 |
+ |
|
| 85 |
+public: |
|
| 86 |
+ Mono_Buffer(); |
|
| 87 |
+ ~Mono_Buffer(); |
|
| 88 |
+ blargg_err_t set_sample_rate( long rate, int msec = blip_default_length ); |
|
| 89 |
+ void clock_rate( long rate ) { buf.clock_rate( rate ); }
|
|
| 90 |
+ void bass_freq( int freq ) { buf.bass_freq( freq ); }
|
|
| 91 |
+ void clear() { buf.clear(); }
|
|
| 92 |
+ long samples_avail() const { return buf.samples_avail(); }
|
|
| 93 |
+ long read_samples( blip_sample_t* p, long s ) { return buf.read_samples( p, s ); }
|
|
| 94 |
+ channel_t channel( int ) { return chan; }
|
|
| 95 |
+ void end_frame( blip_time_t t ) { buf.end_frame( t ); }
|
|
| 96 |
+}; |
|
| 97 |
+ |
|
| 98 |
+ class Tracked_Blip_Buffer : public Blip_Buffer {
|
|
| 99 |
+ public: |
|
| 100 |
+ // Non-zero if buffer still has non-silent samples in it. Requires that you call |
|
| 101 |
+ // set_modified() appropriately. |
|
| 102 |
+ blip_ulong non_silent() const; |
|
| 103 |
+ |
|
| 104 |
+ // remove_samples( samples_avail() ) |
|
| 105 |
+ void remove_all_samples(); |
|
| 106 |
+ |
|
| 107 |
+ public: |
|
| 108 |
+ BLARGG_DISABLE_NOTHROW |
|
| 109 |
+ |
|
| 110 |
+ long read_samples( blip_sample_t*, long ); |
|
| 111 |
+ void remove_silence( long ); |
|
| 112 |
+ void remove_samples( long ); |
|
| 113 |
+ Tracked_Blip_Buffer(); |
|
| 114 |
+ void clear(); |
|
| 115 |
+ void end_frame( blip_time_t ); |
|
| 116 |
+ private: |
|
| 117 |
+ blip_long last_non_silence; |
|
| 118 |
+ void remove_( long ); |
|
| 119 |
+ }; |
|
| 120 |
+ |
|
| 121 |
+ class Stereo_Mixer {
|
|
| 122 |
+ public: |
|
| 123 |
+ Tracked_Blip_Buffer* bufs [3]; |
|
| 124 |
+ blargg_long samples_read; |
|
| 125 |
+ |
|
| 126 |
+ Stereo_Mixer() : samples_read( 0 ) { }
|
|
| 127 |
+ void read_pairs( blip_sample_t* out, int count ); |
|
| 128 |
+ private: |
|
| 129 |
+ void mix_mono ( blip_sample_t* out, int pair_count ); |
|
| 130 |
+ void mix_stereo( blip_sample_t* out, int pair_count ); |
|
| 131 |
+ }; |
|
| 132 |
+ |
|
| 133 |
+// Uses three buffers (one for center) and outputs stereo sample pairs. |
|
| 134 |
+class Stereo_Buffer : public Multi_Buffer {
|
|
| 135 |
+public: |
|
| 136 |
+ |
|
| 137 |
+ // Buffers used for all channels |
|
| 138 |
+ Blip_Buffer* center() { return &bufs [2]; }
|
|
| 139 |
+ Blip_Buffer* left() { return &bufs [0]; }
|
|
| 140 |
+ Blip_Buffer* right() { return &bufs [1]; }
|
|
| 141 |
+ |
|
| 142 |
+public: |
|
| 143 |
+ Stereo_Buffer(); |
|
| 144 |
+ ~Stereo_Buffer(); |
|
| 145 |
+ blargg_err_t set_sample_rate( long, int msec = blip_default_length ); |
|
| 146 |
+ void clock_rate( long ); |
|
| 147 |
+ void bass_freq( int ); |
|
| 148 |
+ void clear(); |
|
| 149 |
+ channel_t channel( int ) { return chan; }
|
|
| 150 |
+ void end_frame( blip_time_t ); |
|
| 151 |
+ |
|
| 152 |
+ long samples_avail() const { return (bufs [0].samples_avail() - mixer.samples_read) * 2; }
|
|
| 153 |
+ long read_samples( blip_sample_t*, long ); |
|
| 154 |
+ |
|
| 155 |
+private: |
|
| 156 |
+ enum { bufs_size = 3 };
|
|
| 157 |
+ typedef Tracked_Blip_Buffer buf_t; |
|
| 158 |
+ buf_t bufs [bufs_size]; |
|
| 159 |
+ Stereo_Mixer mixer; |
|
| 160 |
+ channel_t chan; |
|
| 161 |
+ long samples_avail_; |
|
| 162 |
+}; |
|
| 163 |
+ |
|
| 164 |
+// Silent_Buffer generates no samples, useful where no sound is wanted |
|
| 165 |
+class Silent_Buffer : public Multi_Buffer {
|
|
| 166 |
+ channel_t chan; |
|
| 167 |
+public: |
|
| 168 |
+ Silent_Buffer(); |
|
| 169 |
+ blargg_err_t set_sample_rate( long rate, int msec = blip_default_length ); |
|
| 170 |
+ void clock_rate( long ) { }
|
|
| 171 |
+ void bass_freq( int ) { }
|
|
| 172 |
+ void clear() { }
|
|
| 173 |
+ channel_t channel( int ) { return chan; }
|
|
| 174 |
+ void end_frame( blip_time_t ) { }
|
|
| 175 |
+ long samples_avail() const { return 0; }
|
|
| 176 |
+ long read_samples( blip_sample_t*, long ) { return 0; }
|
|
| 177 |
+}; |
|
| 178 |
+ |
|
| 179 |
+ |
|
| 180 |
+inline blargg_err_t Multi_Buffer::set_sample_rate( long rate, int msec ) |
|
| 181 |
+{
|
|
| 182 |
+ sample_rate_ = rate; |
|
| 183 |
+ length_ = msec; |
|
| 184 |
+ return 0; |
|
| 185 |
+} |
|
| 186 |
+ |
|
| 187 |
+inline blargg_err_t Silent_Buffer::set_sample_rate( long rate, int msec ) |
|
| 188 |
+{
|
|
| 189 |
+ return Multi_Buffer::set_sample_rate( rate, msec ); |
|
| 190 |
+} |
|
| 191 |
+ |
|
| 192 |
+inline int Multi_Buffer::samples_per_frame() const { return samples_per_frame_; }
|
|
| 193 |
+ |
|
| 194 |
+inline long Multi_Buffer::sample_rate() const { return sample_rate_; }
|
|
| 195 |
+ |
|
| 196 |
+inline int Multi_Buffer::length() const { return length_; }
|
|
| 197 |
+ |
|
| 198 |
+inline blargg_err_t Multi_Buffer::set_channel_count( int n, int const* types ) |
|
| 199 |
+{
|
|
| 200 |
+ channel_count_ = n; |
|
| 201 |
+ channel_types_ = types; |
|
| 202 |
+ return 0; |
|
| 203 |
+} |
|
| 204 |
+ |
|
| 205 |
+#endif |