diff options
author | Max Horn | 2003-08-02 19:09:52 +0000 |
---|---|---|
committer | Max Horn | 2003-08-02 19:09:52 +0000 |
commit | 7ec38f5f02ebd44332b34e059d209165fa68fa14 (patch) | |
tree | 5a7ae973eed9741c8693213eed423fe75ffe1c9f | |
parent | 20ba0865117ed865bc92a0e1e633dfc10c431587 (diff) | |
download | scummvm-rg350-7ec38f5f02ebd44332b34e059d209165fa68fa14.tar.gz scummvm-rg350-7ec38f5f02ebd44332b34e059d209165fa68fa14.tar.bz2 scummvm-rg350-7ec38f5f02ebd44332b34e059d209165fa68fa14.zip |
some more tweaks
svn-id: r9424
-rw-r--r-- | sound/mixer.cpp | 15 | ||||
-rw-r--r-- | sound/rate.cpp | 42 | ||||
-rw-r--r-- | sound/rate.h | 20 |
3 files changed, 36 insertions, 41 deletions
diff --git a/sound/mixer.cpp b/sound/mixer.cpp index 69d4e0d5af..dbc87f01f7 100644 --- a/sound/mixer.cpp +++ b/sound/mixer.cpp @@ -716,8 +716,7 @@ void ChannelRaw::mix(int16 *data, uint len) { } const int volume = _mixer->getVolume(); - st_size_t tmpLen = len; - _converter->flow(*_input, data, &tmpLen, volume); + _converter->flow(*_input, data, len, volume); #else byte *s, *end; @@ -837,8 +836,7 @@ void ChannelStream::mix(int16 *data, uint len) { } const int volume = _mixer->getVolume(); - st_size_t tmpLen = len; - _converter->flow(*_input, data, &tmpLen, volume); + _converter->flow(*_input, data, len, volume); #else if (_pos == _endOfData) { // Normally, the stream stays around even if all its data is used up. @@ -960,8 +958,7 @@ void ChannelMP3::mix(int16 *data, uint len) { } const int volume = _mixer->getVolume(); - st_size_t tmpLen = len; - _converter->flow(*_input, data, &tmpLen, volume); + _converter->flow(*_input, data, len, volume); #else const int volume = _mixer->getVolume(); @@ -1044,8 +1041,7 @@ void ChannelMP3CDMusic::mix(int16 *data, uint len) { } const int volume = _mixer->getMusicVolume(); - st_size_t tmpLen = len; - _converter->flow(*_input, data, &tmpLen, volume); + _converter->flow(*_input, data, len, volume); #else mad_timer_t frame_duration; const int volume = _mixer->getMusicVolume(); @@ -1198,8 +1194,7 @@ void ChannelVorbis::mix(int16 *data, uint len) { } const int volume = isMusicChannel() ? _mixer->getMusicVolume() : _mixer->getVolume(); - st_size_t tmpLen = len; - _converter->flow(*_input, data, &tmpLen, volume); + _converter->flow(*_input, data, len, volume); #else if (_end_pos > 0 && ov_pcm_tell(_ov_file) >= _end_pos) { destroy(); diff --git a/sound/rate.cpp b/sound/rate.cpp index 4f05dd326e..5498f48202 100644 --- a/sound/rate.cpp +++ b/sound/rate.cpp @@ -66,8 +66,8 @@ protected: public: LinearRateConverter(st_rate_t inrate, st_rate_t outrate); - int flow(AudioInputStream &input, st_sample_t *obuf, st_size_t *osamp, st_volume_t vol); - int drain(st_sample_t *obuf, st_size_t *osamp, st_volume_t vol) { + int flow(AudioInputStream &input, st_sample_t *obuf, st_size_t osamp, st_volume_t vol); + int drain(st_sample_t *obuf, st_size_t osamp, st_volume_t vol) { return (ST_SUCCESS); } }; @@ -108,14 +108,13 @@ LinearRateConverter<stereo, reverseStereo>::LinearRateConverter(st_rate_t inrate * Return number of samples processed. */ template<bool stereo, bool reverseStereo> -int LinearRateConverter<stereo, reverseStereo>::flow(AudioInputStream &input, st_sample_t *obuf, st_size_t *osamp, st_volume_t vol) +int LinearRateConverter<stereo, reverseStereo>::flow(AudioInputStream &input, st_sample_t *obuf, st_size_t osamp, st_volume_t vol) { st_sample_t *ostart, *oend; - st_sample_t out; - unsigned long tmp; + st_sample_t out[2], tmpOut; ostart = obuf; - oend = obuf + *osamp * 2; + oend = obuf + osamp * 2; while (obuf < oend) { @@ -140,25 +139,25 @@ int LinearRateConverter<stereo, reverseStereo>::flow(AudioInputStream &input, st while (ipos > opos + 1) { // interpolate - out = (st_sample_t) (ilast[reverseStereo ? 1 : 0] + (((icur[reverseStereo ? 1 : 0] - ilast[reverseStereo ? 1 : 0]) * opos_frac + (1UL << (FRAC_BITS-1))) >> FRAC_BITS)); + tmpOut = (st_sample_t)(ilast[0] + (((icur[0] - ilast[0]) * opos_frac + (1UL << (FRAC_BITS-1))) >> FRAC_BITS)); // adjust volume - out = out * vol / 256; - - // output left channel sample - clampedAdd(*obuf++, out); + out[0] = out[1] = (st_sample_t)((tmpOut * vol) >> 8); if (stereo) { // interpolate - out = (st_sample_t) (ilast[reverseStereo ? 0 : 1] + (((icur[reverseStereo ? 0 : 1] - ilast[reverseStereo ? 0 : 1]) * opos_frac + (1UL << (FRAC_BITS-1))) >> FRAC_BITS)); + tmpOut = (st_sample_t)(ilast[1] + (((icur[1] - ilast[1]) * opos_frac + (1UL << (FRAC_BITS-1))) >> FRAC_BITS)); // adjust volume - out = out * vol / 256; + out[reverseStereo ? 0 : 1] = (st_sample_t)((tmpOut * vol) >> 8); } - // output right channel sample - clampedAdd(*obuf++, out); + // output left channel + clampedAdd(*obuf++, out[0]); + + // output right channel + clampedAdd(*obuf++, out[1]); // Increment output position - tmp = opos_frac + opos_inc_frac; + unsigned long tmp = opos_frac + opos_inc_frac; opos += opos_inc + (tmp >> FRAC_BITS); opos_frac = tmp & ((1UL << FRAC_BITS) - 1); @@ -169,7 +168,6 @@ int LinearRateConverter<stereo, reverseStereo>::flow(AudioInputStream &input, st } the_end: - *osamp = (obuf - ostart) / 2; return (ST_SUCCESS); } @@ -183,20 +181,20 @@ the_end: template<bool stereo, bool reverseStereo> class CopyRateConverter : public RateConverter { public: - virtual int flow(AudioInputStream &input, st_sample_t *obuf, st_size_t *osamp, st_volume_t vol) { + virtual int flow(AudioInputStream &input, st_sample_t *obuf, st_size_t osamp, st_volume_t vol) { int16 tmp[2]; - st_size_t len = *osamp; + st_size_t len = osamp; assert(input.isStereo() == stereo); while (!input.eof() && len--) { - tmp[0] = tmp[1] = input.read() * vol / 256; + tmp[0] = tmp[1] = (input.read() * vol) >> 8; if (stereo) - tmp[reverseStereo ? 0 : 1] = input.read() * vol / 256; + tmp[reverseStereo ? 0 : 1] = (input.read() * vol) >> 8; clampedAdd(*obuf++, tmp[0]); clampedAdd(*obuf++, tmp[1]); } return (ST_SUCCESS); } - virtual int drain(st_sample_t *obuf, st_size_t *osamp, st_volume_t vol) { + virtual int drain(st_sample_t *obuf, st_size_t osamp, st_volume_t vol) { return (ST_SUCCESS); } }; diff --git a/sound/rate.h b/sound/rate.h index b55897caad..694dbe0b16 100644 --- a/sound/rate.h +++ b/sound/rate.h @@ -48,14 +48,14 @@ typedef eff_struct *eff_t; #define ST_SUCCESS (0) static inline void clampedAdd(int16& a, int b) { - int val = a + b; + register int val = a + b; if (val > ST_SAMPLE_MAX) - a = ST_SAMPLE_MAX; + val = ST_SAMPLE_MAX; else if (val < ST_SAMPLE_MIN) - a = ST_SAMPLE_MIN; - else - a = val; + val = ST_SAMPLE_MIN; + + a = val; } // Q&D hack to get this SOX stuff to work @@ -68,19 +68,21 @@ class RateConverter { public: RateConverter() {} virtual ~RateConverter() {} - virtual int flow(AudioInputStream &input, st_sample_t *obuf, st_size_t *osamp, st_volume_t vol) = 0; - virtual int drain(st_sample_t *obuf, st_size_t *osamp, st_volume_t vol) = 0; + virtual int flow(AudioInputStream &input, st_sample_t *obuf, st_size_t osamp, st_volume_t vol) = 0; + virtual int drain(st_sample_t *obuf, st_size_t osamp, st_volume_t vol) = 0; }; +/* class ResampleRateConverter : public RateConverter { protected: eff_struct effp; public: ResampleRateConverter(st_rate_t inrate, st_rate_t outrate, int quality); ~ResampleRateConverter(); - virtual int flow(AudioInputStream &input, st_sample_t *obuf, st_size_t *osamp, st_volume_t vol); - virtual int drain(st_sample_t *obuf, st_size_t *osamp, st_volume_t vol); + virtual int flow(AudioInputStream &input, st_sample_t *obuf, st_size_t osamp, st_volume_t vol); + virtual int drain(st_sample_t *obuf, st_size_t osamp, st_volume_t vol); }; +*/ RateConverter *makeRateConverter(st_rate_t inrate, st_rate_t outrate, bool stereo, bool reverseStereo = false); |