diff options
author | Paweł Kołodziejski | 2002-10-02 17:31:55 +0000 |
---|---|---|
committer | Paweł Kołodziejski | 2002-10-02 17:31:55 +0000 |
commit | 98d90696ada9377e958280dee3037f452934d50f (patch) | |
tree | eba170fd52d09c25731832c7adf329886cd9a475 /scumm | |
parent | f3281f93c5ccd751c1aa89f42944d0b44eb4a5e6 (diff) | |
download | scummvm-rg350-98d90696ada9377e958280dee3037f452934d50f.tar.gz scummvm-rg350-98d90696ada9377e958280dee3037f452934d50f.tar.bz2 scummvm-rg350-98d90696ada9377e958280dee3037f452934d50f.zip |
added panning control in imuse and reverse stereo support
svn-id: r5076
Diffstat (limited to 'scumm')
-rw-r--r-- | scumm/imuse.cpp | 86 | ||||
-rw-r--r-- | scumm/sound.cpp | 13 | ||||
-rw-r--r-- | scumm/sound.h | 2 |
3 files changed, 83 insertions, 18 deletions
diff --git a/scumm/imuse.cpp b/scumm/imuse.cpp index 6217040778..dfb3fa91b3 100644 --- a/scumm/imuse.cpp +++ b/scumm/imuse.cpp @@ -4855,7 +4855,7 @@ IMuseDigital::~IMuseDigital() { void IMuseDigital::handler() { bool new_mixer; - int32 l, idx = 0; + uint32 l, i, idx = 0; for (l = 0; l < MAX_DIGITAL_CHANNELS;l ++) { if (_channel[l]._used) { @@ -4887,6 +4887,29 @@ void IMuseDigital::handler() { memcpy(buf + new_size, _channel[l]._data + _channel[l]._jump[0]._dest, _channel[l]._mixerSize - new_size); } + if (_channel[l]._bits == 12) { + for(i = 0; i < (mixer_size / 4); i++) { + byte sample1 = buf[i * 4 + 0]; + byte sample2 = buf[i * 4 + 1]; + byte sample3 = buf[i * 4 + 2]; + byte sample4 = buf[i * 4 + 3]; + uint16 sample_a = (uint16)(((int16)((sample1 << 8) | sample2) * _channel[l]._volumeLeft) >> 8); + uint16 sample_b = (uint16)(((int16)((sample3 << 8) | sample4) * _channel[l]._volumeRight) >> 8); + buf[i * 4 + 0] = (byte)(sample_a >> 8); + buf[i * 4 + 1] = (byte)(sample_a & 0xff); + buf[i * 4 + 2] = (byte)(sample_b >> 8); + buf[i * 4 + 3] = (byte)(sample_b & 0xff); + } + } else if (_channel[l]._bits == 8) { + for(i = 0; i < (mixer_size / 2); i++) { + byte sample1 = buf[i * 2 + 0]; + byte sample2 = buf[i * 2 + 1]; + uint16 sample_a = (uint16)(((int16)((sample1 << 8) | sample2) * _channel[l]._volumeLeft) >> 8); + buf[i * 2 + 0] = (byte)(sample_a >> 8); + buf[i * 2 + 1] = (byte)(sample_a & 0xff); + } + } + new_mixer = false; if (_channel[l]._mixerTrack == -1) { _scumm->_system->lock_mutex(_scumm->_mixer->_mutex); @@ -4937,6 +4960,8 @@ void IMuseDigital::startSound(int sound) { _channel[l]._offset = 0; _channel[l]._numRegions = 0; _channel[l]._numJumps = 0; + _channel[l]._volumeLeft = 127; + _channel[l]._volumeRight = 127; ptr += 16; uint32 tag, size = 0; @@ -4996,7 +5021,7 @@ void IMuseDigital::startSound(int sound) { if (_channel[l]._bits == 12) { _channel[l]._offsetStop = (_channel[l]._offsetStop / 3) * 4; } - uint32 r; + uint32 r, t; for (r = 0; r < _channel[l]._numRegions; r++) { _channel[l]._region[r]._offset -= header_size; if (_channel[l]._bits == 12) { @@ -5015,23 +5040,29 @@ void IMuseDigital::startSound(int sound) { } } _channel[l]._mixerTrack = -1; - _channel[l]._mixerSize = 22050 / 5; - _channel[l]._mixerFlags = SoundMixer::FLAG_AUTOFREE; + _channel[l]._mixerSize = (22050 / 5) * 2; + _channel[l]._mixerFlags = SoundMixer::FLAG_AUTOFREE | SoundMixer::FLAG_STEREO | SoundMixer::FLAG_REVERSE_STEREO; if (_channel[l]._bits == 12) { _channel[l]._mixerSize *= 2; _channel[l]._mixerFlags |= SoundMixer::FLAG_16BITS; - _channel[l]._size = _scumm->_sound->decode12BitsSample(ptr, &_channel[l]._data, size); + _channel[l]._size = _scumm->_sound->decode12BitsSample(ptr, &_channel[l]._data, size, (_channel[l]._channels == 1) ? false : true); } if (_channel[l]._bits == 8) { _channel[l]._mixerFlags |= SoundMixer::FLAG_UNSIGNED; - _channel[l]._data = (byte *)malloc(size); - memcpy(_channel[l]._data, ptr, size); + if (_channel[l]._channels == 1) { + size *= 2; + _channel[l]._channels = 2; + _channel[l]._data = (byte *)malloc(size); + for (t = 0; t < size; t++) { + *(_channel[l]._data + l * 2 + 0) = *(ptr + l); + *(_channel[l]._data + l * 2 + 1) = *(ptr + l); + } + } else { + _channel[l]._data = (byte *)malloc(size); + memcpy(_channel[l]._data, ptr, size); + } _channel[l]._size = size; } - if (_channel[l]._channels == 2) { - _channel[l]._mixerSize *= 2; - _channel[l]._mixerFlags |= SoundMixer::FLAG_STEREO; - } if (_channel[l]._freq == 11025) { _channel[l]._mixerSize /= 2; } @@ -5067,6 +5098,7 @@ int32 IMuseDigital::doCommand(int a, int b, int c, int d, int e, int f, int g, i byte param = a >> 8; byte sample = b; byte sub_cmd = c >> 8; + int8 channel = -1, l; if (!(cmd || param)) return 1; @@ -5078,11 +5110,33 @@ int32 IMuseDigital::doCommand(int a, int b, int c, int d, int e, int f, int g, i case 5: // param seems always set 0 (maybe reset) debug(1, "IMuseDigital::doCommand stub cmd=%d,param=%d,sample=%d,sub_cmd=%d,params=(%d,%d,%d)", param, cmd, sample, sub_cmd, d, e, f); return 0; - case 6: // left pan control (0-127) i think - debug(1, "IMuseDigital::doCommand stub cmd=%d,param=%d,sample=%d,sub_cmd=%d,params=(%d,%d,%d)", param, cmd, sample, sub_cmd, d, e, f); + case 6: // right pan control (0-127) i think + debug(1, "IMuseDigital::doCommand setting right sample(%d), volume(%d)", sample, d); + for (l = 0; l < MAX_DIGITAL_CHANNELS; l++) { + if ((_channel[l]._idSound == sample) && (_channel[l]._used == true)) { + channel = l; + break; + } + } + if (channel == -1) { + warning("IMuseDigital::doCommand Sample %d not exist", sample); + return 1; + } + _channel[channel]._volumeRight = d; return 0; - case 7: // right pan control (0-127) i think - debug(1, "IMuseDigital::doCommand stub cmd=%d,param=%d,sample=%d,sub_cmd=%d,params=(%d,%d,%d)", param, cmd, sample, sub_cmd, d, e, f); + case 7: // left pan control (0-127) i think + debug(1, "IMuseDigital::doCommand setting left sample(%d), volume(%d)", sample, d); + for (l = 0; l < MAX_DIGITAL_CHANNELS; l++) { + if ((_channel[l]._idSound == sample) && (_channel[l]._used == true)) { + channel = l; + break; + } + } + if (channel == -1) { + warning("IMuseDigital::doCommand Sample %d not exist", sample); + return 1; + } + _channel[channel]._volumeLeft = d; return 0; default: warning("IMuseDigital::doCommand (param=0, cmd=12) default sub command %d", sub_cmd); @@ -5097,7 +5151,7 @@ int32 IMuseDigital::doCommand(int a, int b, int c, int d, int e, int f, int g, i warning("IMuseDigital::doCommand (param=0) default command %d", cmd); return 1; } - } else if (param == 16) { // unknown commands + } else if (param == 16) { // maybe music related switch (cmd) { case 0: debug(1, "IMuseDigital::doCommand %d,%d(%d,%d,%d,%d,%d)", param, cmd, b, c, d, e, f); diff --git a/scumm/sound.cpp b/scumm/sound.cpp index 59be2d7367..879d8a42e4 100644 --- a/scumm/sound.cpp +++ b/scumm/sound.cpp @@ -847,9 +847,12 @@ bool Sound::isSfxFinished() { return !_scumm->_mixer->hasActiveChannel(); } -uint32 Sound::decode12BitsSample(byte * src, byte ** dst, uint32 size) { +uint32 Sound::decode12BitsSample(byte * src, byte ** dst, uint32 size, bool stereo = false) { uint32 s_size = (size / 3) * 4; uint32 loop_size = s_size / 4; + if (stereo == true) { + s_size *= 2; + } byte *ptr = *dst = (byte*)malloc(s_size); uint32 tmp; @@ -860,9 +863,17 @@ uint32 Sound::decode12BitsSample(byte * src, byte ** dst, uint32 size) { tmp = ((((v2 & 0x0f) << 8) | v1) << 4) - 0x8000; *ptr++ = (byte)((tmp >> 8) & 0xff); *ptr++ = (byte)(tmp & 0xff); + if (stereo == true) { + *ptr++ = (byte)((tmp >> 8) & 0xff); + *ptr++ = (byte)(tmp & 0xff); + } tmp = ((((v2 & 0xf0) << 4) | v3) << 4) - 0x8000; *ptr++ = (byte)((tmp >> 8) & 0xff); *ptr++ = (byte)(tmp & 0xff); + if (stereo == true) { + *ptr++ = (byte)((tmp >> 8) & 0xff); + *ptr++ = (byte)(tmp & 0xff); + } } return s_size; } diff --git a/scumm/sound.h b/scumm/sound.h index 6c206dc3fb..b0986f455a 100644 --- a/scumm/sound.h +++ b/scumm/sound.h @@ -117,7 +117,7 @@ public: File * openSfxFile(); void stopSfxSound(); bool isSfxFinished(); - uint32 decode12BitsSample(byte * src, byte ** dst, uint32 size); + uint32 decode12BitsSample(byte * src, byte ** dst, uint32 size, bool stereo); void playBundleMusic(int32 song); void pauseBundleMusic(bool state); void bundleMusicHandler(Scumm * scumm); |