aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaweł Kołodziejski2003-09-02 20:34:22 +0000
committerPaweł Kołodziejski2003-09-02 20:34:22 +0000
commit7c4e678a874eee9e1de7d9e476f737892e773de0 (patch)
tree79c53d11b0012fef0b89af655e203b513d6fd776
parent47a2bc6eb62c99d212ea83ae56402241a871f733 (diff)
downloadscummvm-rg350-7c4e678a874eee9e1de7d9e476f737892e773de0.tar.gz
scummvm-rg350-7c4e678a874eee9e1de7d9e476f737892e773de0.tar.bz2
scummvm-rg350-7c4e678a874eee9e1de7d9e476f737892e773de0.zip
moved volume and pan control into flow func
svn-id: r9976
-rw-r--r--sound/mixer.cpp17
-rw-r--r--sound/rate.cpp19
-rw-r--r--sound/rate.h2
3 files changed, 19 insertions, 19 deletions
diff --git a/sound/mixer.cpp b/sound/mixer.cpp
index 557d9d37ce..cf11e62848 100644
--- a/sound/mixer.cpp
+++ b/sound/mixer.cpp
@@ -487,17 +487,6 @@ void Channel::destroy() {
delete this;
}
-static void changeVolumeAndPan(int16 *data, uint len, byte volume, int8 pan) {
- byte volumeLeft = abs(pan - 128);
- byte volumeRight = abs(pan + 128);
- for (uint32 i = 0; i < len; i++) {
- int16 sampleL = data[i * 2 + 0];
- int16 sampleR = data[i * 2 + 1];
- data[i * 2 + 0] = (sampleL * volume * volumeLeft) / (256 * 256);
- data[i * 2 + 1] = (sampleR * volume * volumeRight) / (256 * 256);
- }
-}
-
/* len indicates the number of sample *pairs*. So a value of
10 means that the buffer contains twice 10 sample, each
16 bits, for a total of 40 bytes.
@@ -509,8 +498,7 @@ void Channel::mix(int16 *data, uint len) {
destroy();
} else {
assert(_converter);
- _converter->flow(*_input, data, len, getVolume());
- changeVolumeAndPan(data, len, _volume, _pan);
+ _converter->flow(*_input, data, len, getVolume(), _volume, _pan);
}
}
@@ -586,8 +574,7 @@ void ChannelStream::mix(int16 *data, uint len) {
}
assert(_converter);
- _converter->flow(*_input, data, len, getVolume());
- changeVolumeAndPan(data, len, _volume, _pan);
+ _converter->flow(*_input, data, len, getVolume(), _volume, _pan);
}
#ifdef USE_MAD
diff --git a/sound/rate.cpp b/sound/rate.cpp
index a99794c6ef..e4f9fb6b19 100644
--- a/sound/rate.cpp
+++ b/sound/rate.cpp
@@ -80,7 +80,7 @@ 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 flow(AudioInputStream &input, st_sample_t *obuf, st_size_t osamp, st_volume_t vol, byte vol_p, int8 pan);
int drain(st_sample_t *obuf, st_size_t osamp, st_volume_t vol) {
return (ST_SUCCESS);
}
@@ -124,7 +124,7 @@ 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, byte vol_p, int8 pan)
{
st_sample_t *ostart, *oend;
st_sample_t out[2], tmpOut;
@@ -170,6 +170,13 @@ int LinearRateConverter<stereo, reverseStereo>::flow(AudioInputStream &input, st
out[reverseStereo ? 0 : 1] = (st_sample_t)((tmpOut * vol) >> 8);
}
+ byte pan_l = abs(pan - 128);
+ byte pan_r = abs(pan + 128);
+ out[0] = (st_sample_t)((out[0] * vol_p) >> 8);
+ out[1] = (st_sample_t)((out[1] * vol_p) >> 8);
+ out[0] = (st_sample_t)((out[0] * pan_l) >> 8);
+ out[1] = (st_sample_t)((out[1] * pan_r) >> 8);
+
// output left channel
clampedAdd(*obuf++, out[0]);
@@ -201,7 +208,7 @@ 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, byte vol_p, int8 pan) {
int16 tmp[2];
st_size_t len = osamp;
assert(input.isStereo() == stereo);
@@ -209,6 +216,12 @@ public:
tmp[0] = tmp[1] = (input.read() * vol) >> 8;
if (stereo)
tmp[reverseStereo ? 0 : 1] = (input.read() * vol) >> 8;
+ byte pan_l = abs(pan - 128);
+ byte pan_r = abs(pan + 128);
+ tmp[0] = ((tmp[0] * vol_p) >> 8);
+ tmp[1] = ((tmp[1] * vol_p) >> 8);
+ tmp[0] = ((tmp[0] * pan_l) >> 8);
+ tmp[1] = ((tmp[1] * pan_r) >> 8);
clampedAdd(*obuf++, tmp[0]);
clampedAdd(*obuf++, tmp[1]);
}
diff --git a/sound/rate.h b/sound/rate.h
index 67224b2377..c693a165bd 100644
--- a/sound/rate.h
+++ b/sound/rate.h
@@ -62,7 +62,7 @@ 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 flow(AudioInputStream &input, st_sample_t *obuf, st_size_t osamp, st_volume_t vol, byte vol_p, int8 pan) = 0;
virtual int drain(st_sample_t *obuf, st_size_t osamp, st_volume_t vol) = 0;
};