diff options
author | Filippos Karapetis | 2008-04-20 14:43:56 +0000 |
---|---|---|
committer | Filippos Karapetis | 2008-04-20 14:43:56 +0000 |
commit | d0590a09eac68d5cde64d37fb2e5bbd1471a676a (patch) | |
tree | 3e29857746449aaea4c9834bedad0d18ce487ff7 /engines/made/sound.cpp | |
parent | d484c7ed434e9f8e8267049fccbe3dbb5c39fe0b (diff) | |
download | scummvm-rg350-d0590a09eac68d5cde64d37fb2e5bbd1471a676a.tar.gz scummvm-rg350-d0590a09eac68d5cde64d37fb2e5bbd1471a676a.tar.bz2 scummvm-rg350-d0590a09eac68d5cde64d37fb2e5bbd1471a676a.zip |
Initial import of the work in progress MADE engine
svn-id: r31599
Diffstat (limited to 'engines/made/sound.cpp')
-rw-r--r-- | engines/made/sound.cpp | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/engines/made/sound.cpp b/engines/made/sound.cpp new file mode 100644 index 0000000000..520239135d --- /dev/null +++ b/engines/made/sound.cpp @@ -0,0 +1,131 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +#include "common/endian.h" +#include "common/util.h" + +#include "made/sound.h" + +namespace Made { + +void decompressSound(byte *source, byte *dest, uint16 chunkSize, uint16 chunkCount) { + + int16 prevSample = 0; + byte soundBuffer[1025]; + byte soundBuffer3[1024]; + int16 soundBuffer2[16]; + + while (chunkCount--) { + + byte deltaType = (*source) >> 6; + + uint16 workChunkSize = chunkSize; + if (deltaType == 1) + workChunkSize /= 2; + else if (deltaType == 2) + workChunkSize /= 4; + + byte type = (*source++) & 0x0F; + + int16 workSample = prevSample; + + switch (type) { + + case 0: + memset(soundBuffer, 0x80, workChunkSize); + workSample = 0; + break; + + case 1: + break; + + case 2: + case 3: + case 4: + { + + const int modeValues[3][4] = { + { 2, 8, 0x01, 1}, + { 4, 4, 0x03, 2}, + {16, 2, 0x0F, 4} + }; + + uint16 byteCount = modeValues[type - 2][0]; + uint16 bitCount = modeValues[type - 2][1]; + byte bitMask = modeValues[type - 2][2]; + byte bitShift = modeValues[type - 2][3]; + + uint16 ofs = 0; + + for (uint16 i = 0; i < byteCount; i++) + soundBuffer2[i] = (*source++) * 2 - 128; + + while (ofs < workChunkSize) { + byte val = *source++; + for (uint i = 0; i < bitCount; i++) { + workSample = CLIP<int16>(workSample + soundBuffer2[val & bitMask], -127, 127); + val >>= bitShift; + soundBuffer[ofs++] = workSample + 128; + } + } + + break; + } + + case 5: + { + for (uint16 i = 0; i < workChunkSize; i++) + soundBuffer[i] = *source++; + workSample = soundBuffer[workChunkSize - 1] - 128; + break; + } + + default: + return; + + } + + if (deltaType == 1) { + for (uint16 i = 0; i < chunkSize - 1; i += 2) { + uint16 l = i / 2; + soundBuffer3[i] = soundBuffer[l]; + soundBuffer3[i + 1] = (soundBuffer[l + 1] + soundBuffer[l]) / 2; + } + for (uint16 i = 0; i < chunkSize; i++) { + soundBuffer[i] = soundBuffer3[i]; + } + } else if (deltaType == 2) { + debug(2, "****************************************"); + } + + prevSample = workSample; + memcpy(dest, soundBuffer, chunkSize); + dest += chunkSize; + + } + +} + +} // End of namespace Made |