aboutsummaryrefslogtreecommitdiff
path: root/graphics
diff options
context:
space:
mode:
Diffstat (limited to 'graphics')
-rw-r--r--graphics/smk_player.cpp42
1 files changed, 40 insertions, 2 deletions
diff --git a/graphics/smk_player.cpp b/graphics/smk_player.cpp
index 415285bd12..c066d945db 100644
--- a/graphics/smk_player.cpp
+++ b/graphics/smk_player.cpp
@@ -419,7 +419,7 @@ bool SMKPlayer::loadFile(const char *fileName) {
_header.audioInfo[i].sampleRate = audioInfo & 0xFFFFFF;
if (_header.audioInfo[i].hasAudio && i == 0) {
- byte flags = Audio::Mixer::FLAG_UNSIGNED;
+ byte flags = Audio::Mixer::FLAG_UNSIGNED | Audio::Mixer::FLAG_LITTLE_ENDIAN;
if (_header.audioInfo[i].is16Bits)
flags = flags | Audio::Mixer::FLAG_16BITS;
@@ -469,10 +469,13 @@ void SMKPlayer::closeFile() {
_audioStarted = false;
}
+ // FIXME
+ /*
if (_audioStream) {
delete _audioStream;
_audioStream = 0;
}
+ */
delete _fileStream;
@@ -728,6 +731,10 @@ void SMKPlayer::queueCompressedBuffer(byte *buffer, int bufferSize, int unpacked
SmallHuffmanTree *audioTrees[4];
int16 bases[2];
int k;
+ byte *unpackedBuffer = new byte[unpackedSize];
+ int curPos = 0;
+ byte *curPointer = unpackedBuffer;
+ uint16 lo, hi, cur;
if (!dataPresent)
return;
@@ -750,7 +757,38 @@ void SMKPlayer::queueCompressedBuffer(byte *buffer, int bufferSize, int unpacked
if (isStereo)
bases[1] = (!is16Bits) ? audioBS.getBits8() : (audioBS.getBits8() << 8) || audioBS.getBits8();
- // TODO: Finish the rest of this
+ while (curPos < unpackedSize) {
+ // If the sample is stereo, we get first the data for the left and then for the right channel
+ if (!is16Bits) {
+ for (k = 0; k < (isStereo ? 2 : 1); k++) {
+ *curPointer++ = (byte)(bases[k] + audioTrees[k]->getCode(audioBS));
+ curPos++;
+ }
+ } else {
+ if (isStereo) {
+ // Left channel
+ lo = (bases[1] & 0xFF) + audioTrees[3]->getCode(audioBS);
+ hi = (bases[1] & 0xFF00) + (audioTrees[2]->getCode(audioBS) << 8);
+ cur = hi + lo; // adding takes care of possible overflows
+ *curPointer++ = cur & 0xFF; // low
+ curPos++;
+ *curPointer++ = cur & 0xFF00; // high
+ curPos++;
+ }
+
+ // Right channel
+ lo = (bases[0] & 0xFF) + audioTrees[1]->getCode(audioBS);
+ hi = (bases[0] & 0xFF00) + (audioTrees[0]->getCode(audioBS) << 8);
+ cur = hi + lo; // adding takes care of possible overflows
+ *curPointer++ = cur & 0xFF; // low
+ curPos++;
+ *curPointer++ = cur & 0xFF00; // high
+ curPos++;
+ }
+ }
+
+ _audioStream->queueBuffer(unpackedBuffer, unpackedSize);
+ // unpackedBuffer will be deleted by AppendableAudioStream
}
void SMKPlayer::unpackPalette() {