diff options
author | Paweł Kołodziejski | 2002-09-21 09:21:50 +0000 |
---|---|---|
committer | Paweł Kołodziejski | 2002-09-21 09:21:50 +0000 |
commit | a2a3fb5636b3d12301490db715c5732f5e211915 (patch) | |
tree | cd9f7bedd48e7bd334192f33237d6ee1f2aacd50 | |
parent | 24533e6e2d0777082e93d5643932820691fd987f (diff) | |
download | scummvm-rg350-a2a3fb5636b3d12301490db715c5732f5e211915.tar.gz scummvm-rg350-a2a3fb5636b3d12301490db715c5732f5e211915.tar.bz2 scummvm-rg350-a2a3fb5636b3d12301490db715c5732f5e211915.zip |
added support for sound volume for smush samples(IACT) in the dig (propably bad)
svn-id: r4985
-rw-r--r-- | scumm/smush/channel.h | 5 | ||||
-rw-r--r-- | scumm/smush/imuse_channel.cpp | 67 | ||||
-rw-r--r-- | scumm/smush/player.cpp | 26 |
3 files changed, 63 insertions, 35 deletions
diff --git a/scumm/smush/channel.h b/scumm/smush/channel.h index 8ba1c44a08..a69df70de4 100644 --- a/scumm/smush/channel.h +++ b/scumm/smush/channel.h @@ -122,6 +122,7 @@ private: int32 _frequency; //!< the target frequency of the ::mixer int32 _dataSize; //!< remaining size of sound data in the iMUS buffer bool _inData; + int32 _volume; int32 _bitsize; //!< the bitsize of the original data int32 _rate; //!< the sampling rate of the original data @@ -142,8 +143,8 @@ public: ImuseChannel(int32 track, int32 freq); virtual ~ImuseChannel(); bool isTerminated() const; - bool setParameters(int32 nbframes, int32 size, int32 unk1, int32 unk2); - bool checkParameters(int32 index, int32 nbframes, int32 size, int32 unk1, int32 unk2); + bool setParameters(int32 nbframes, int32 size, int32 track_flags, int32 unk1); + bool checkParameters(int32 index, int32 nbframes, int32 size, int32 track_flags, int32 unk1); bool appendData(Chunk & b, int32 size); int32 availableSoundData() const; void getSoundData(int16 * sound_buffer, int32 size); diff --git a/scumm/smush/imuse_channel.cpp b/scumm/smush/imuse_channel.cpp index 89cef462bb..df870696a4 100644 --- a/scumm/smush/imuse_channel.cpp +++ b/scumm/smush/imuse_channel.cpp @@ -52,11 +52,23 @@ bool ImuseChannel::isTerminated() const { return (_dataSize <= 0 && _sbuffer == 0); } -bool ImuseChannel::setParameters(int32 nbframes, int32 size, int32 unk1, int32 unk2) { +bool ImuseChannel::setParameters(int32 nb, int32 size, int32 flags, int32 unk1) { + // flags: 0 - 8 bits + // values: + // 1 - Voice + // 2 - Background music + // 0, 3-511 - SFX and volume + // FIXME: this should be better + if ((flags != 1) && (flags != 2) && ((flags >> 2) != 0)) { + _volume = 300 - ((flags >> 3) << 2); + } + else { + _volume = 127; + } return true; } -bool ImuseChannel::checkParameters(int32 index, int32 nbframes, int32 size, int32 unk1, int32 unk2) { +bool ImuseChannel::checkParameters(int32 index, int32 nbframes, int32 size, int32 track_flags, int32 unk1) { return true; } @@ -171,18 +183,21 @@ void ImuseChannel::decode() { } int loop_size = _sbufferSize / 3; int new_size = loop_size * 2; - short * keep, * decoded; - keep = decoded = new int16[new_size]; + byte * keep, * decoded; + uint32 value; + keep = decoded = new byte[new_size * 2]; assert(keep); unsigned char * source = _sbuffer; - while(loop_size--) { - int v1 = *source++; - int v2 = *source++; - int v3 = *source++; - int value = (((v2 & 0x0f) << 12) | (v1 << 4)) - 0x8000; - *decoded++ = (int16)value; - value = (((v2 & 0xf0) << 8) | (v3 << 4)) - 0x8000; - *decoded++ = (int16)value; + while(loop_size--) { + byte v1 = *source++; + byte v2 = *source++; + byte v3 = *source++; + value = ((((v2 & 0x0f) << 8) | v1) << 4) - 0x8000; + *decoded++ = (byte)((value >> 8) & 0xff); + *decoded++ = (byte)(value & 0xff); + value = ((((v2 & 0xf0) << 4) | v3) << 4) - 0x8000; + *decoded++ = (byte)((value >> 8) & 0xff); + *decoded++ = (byte)(value & 0xff); } delete []_sbuffer; _sbuffer = (byte *)keep; @@ -306,14 +321,25 @@ int32 ImuseChannel::availableSoundData(void) const { void ImuseChannel::getSoundData(int16 * snd, int32 size) { if(_dataSize <= 0 || _bitsize <= 8) error("invalid call to imuse_channel::read_sound_data()"); if(_channels == 2) size *= 2; + byte * buf = (byte*)snd; if(_rate == 11025) { for(int32 i = 0; i < size; i++) { - snd[i * 2] = READ_BE_UINT16(_sbuffer + 2 * i); - snd[i * 2 + 1] = snd[i * 2]; + byte sample1 = *(_sbuffer + i * 2); + byte sample2 = *(_sbuffer + i * 2 + 1); + uint16 sample = (uint16)(((int16)((sample1 << 8) | sample2) * _volume) >> 8); + buf[i * 4 + 0] = (byte)(sample >> 8); + buf[i * 4 + 1] = (byte)(sample & 0xff); + buf[i * 4 + 2] = buf[i * 4 + 0]; + buf[i * 4 + 3] = buf[i * 4 + 1]; } } else { - for(int32 i = 0; i < size; i++) - snd[i] = READ_BE_UINT16(_sbuffer + 2 * i); + for(int32 i = 0; i < size; i++){ + byte sample1 = *(_sbuffer + i * 2); + byte sample2 = *(_sbuffer + i * 2 + 1); + uint16 sample = (uint16)(((int16)((sample1 << 8) | sample2) * _volume) >> 8); + buf[i * 2 + 0] = (byte)(sample >> 8); + buf[i * 2 + 1] = (byte)(sample & 0xff); + } } delete []_sbuffer; assert(_sbufferSize == 2 * size); @@ -327,12 +353,13 @@ void ImuseChannel::getSoundData(int8 * snd, int32 size) { if(_channels == 2) size *= 2; if(_rate == 11025) { for(int32 i = 0; i < size; i++) { - snd[i * 2] = _sbuffer[i]; - snd[i * 2 + 1] = _sbuffer[i]; + snd[i * 2] = (int8)(((int8)(_sbuffer[i] ^ 0x80) * _volume) >> 8) ^ 0x80; + snd[i * 2 + 1] = snd[i * 2]; } } else { - for(int32 i = 0; i < size; i++) - snd[i] = _sbuffer[i]; + for(int32 i = 0; i < size; i++){ + snd[i] = (int8)(((int8)(_sbuffer[i] ^ 0x80) * _volume) >> 8) ^ 0x80; + } } delete []_sbuffer; _sbuffer = 0; diff --git a/scumm/smush/player.cpp b/scumm/smush/player.cpp index 7154b4b38e..b87aed7d9a 100644 --- a/scumm/smush/player.cpp +++ b/scumm/smush/player.cpp @@ -291,28 +291,28 @@ void SmushPlayer::handleFetch(Chunk & b) { debug(6, "SmushPlayer::handleFetch()"); } -void SmushPlayer::handleImuseBuffer(int32 track_id, int32 index, int32 nbframes, int32 size, int32 unk1, int32 unk2, Chunk & b, int32 bsize) { - _Channel * c = _mixer->findChannel(track_id); +void SmushPlayer::handleImuseBuffer(int32 track_id, int32 index, int32 nbframes, int32 size, int32 unk1, int32 track_flags, Chunk & b, int32 bsize) { + int32 track = (track_flags << 16) | track_id; + _Channel * c = _mixer->findChannel(track); if(c == 0) { - c = new ImuseChannel(track_id, _soundFrequency); + c = new ImuseChannel(track, _soundFrequency); _mixer->addChannel(c); } if(index == 0) - c->setParameters(nbframes, size, unk1, unk2); + c->setParameters(nbframes, size, track_flags, unk1); else - c->checkParameters(index, nbframes, size, unk1, unk2); + c->checkParameters(index, nbframes, size, track_flags, unk1); c->appendData(b, bsize); } -void SmushPlayer::handleImuseAction8(Chunk & b, int32 flags, int32 unknown, int32 track_id) { +void SmushPlayer::handleImuseAction8(Chunk & b, int32 flags, int32 unknown, int32 track_flags) { assert(flags == 46 && unknown == 0); - int32 unknown2 = b.getWord(); - track_id |= unknown2 << 16; + int32 track_id = b.getWord(); int32 index = b.getWord(); int32 nbframes = b.getWord(); int32 size = b.getDword(); int32 bsize = b.getSize() - 18; - handleImuseBuffer(track_id, index, nbframes, size, unknown, unknown2, b, bsize); + handleImuseBuffer(track_id, index, nbframes, size, unknown, track_flags, b, bsize); } void SmushPlayer::handleImuseAction(Chunk & b) { @@ -322,17 +322,17 @@ void SmushPlayer::handleImuseAction(Chunk & b) { int32 code = b.getWord(); int32 flags = b.getWord(); int32 unknown = b.getShort(); - int32 track_id = b.getWord(); + int32 track_flags = b.getWord(); #ifdef DEBUG - debug(5, "handleImuseAction(%d, %d, %d, %d)", code, flags, unknown, track_id); + debug(5, "handleImuseAction(%d, %d, %d, %d)", code, flags, unknown, track_flags); #endif switch(code) { case 8: - handleImuseAction8(b, flags, unknown, track_id); + handleImuseAction8(b, flags, unknown, track_flags); break; #ifdef DEBUG default: { - debug(9, "%5.5d %d %8.8d %4.4d", track_id, flags, unknown); + debug(9, "%5.5d %d %8.8d %4.4d", track_flags, flags, unknown); } #endif } |