[Scummvm-cvs-logs] SF.net SVN: scummvm:[35425] scummvm/trunk/graphics/smk_player.cpp
thebluegr at users.sourceforge.net
thebluegr at users.sourceforge.net
Thu Dec 18 20:18:46 CET 2008
Revision: 35425
http://scummvm.svn.sourceforge.net/scummvm/?rev=35425&view=rev
Author: thebluegr
Date: 2008-12-18 19:18:45 +0000 (Thu, 18 Dec 2008)
Log Message:
-----------
Audio support for Smacker videos. Audio doesn't sound right yet, though
Modified Paths:
--------------
scummvm/trunk/graphics/smk_player.cpp
Modified: scummvm/trunk/graphics/smk_player.cpp
===================================================================
--- scummvm/trunk/graphics/smk_player.cpp 2008-12-18 18:46:24 UTC (rev 35424)
+++ scummvm/trunk/graphics/smk_player.cpp 2008-12-18 19:18:45 UTC (rev 35425)
@@ -419,7 +419,7 @@
_header.audioInfo[i].sampleRate = audioInfo & 0xFFFFFF;
if (_header.audioInfo[i].hasAudio && i == 0) {
- byte flags = Audio::Mixer::FLAG_UNSIGNED | Audio::Mixer::FLAG_LITTLE_ENDIAN;
+ byte flags = 0;
if (_header.audioInfo[i].is16Bits)
flags = flags | Audio::Mixer::FLAG_16BITS;
@@ -463,20 +463,12 @@
if (!_fileStream)
return;
- if (_audioStarted) {
- _audioStream->finish();
+ if (_audioStarted && _audioStream) {
_mixer->stopHandle(_audioHandle);
+ _audioStream = 0;
_audioStarted = false;
}
- // FIXME
- /*
- if (_audioStream) {
- delete _audioStream;
- _audioStream = 0;
- }
- */
-
delete _fileStream;
delete _MMapTree;
@@ -536,9 +528,7 @@
dataSizeUnpacked = 0;
}
- // TODO: sound support is deactivated for now, till queueCompressedBuffer() is finished
- if (false) {
- //if (_header.audioInfo[i].hasAudio && chunkSize > 0 && i == 0) {
+ if (_header.audioInfo[i].hasAudio && chunkSize > 0 && i == 0) {
// If it's track 0, play the audio data
byte *soundBuffer = new byte[chunkSize];
@@ -555,7 +545,7 @@
}
if (!_audioStarted) {
- _mixer->playInputStream(Audio::Mixer::kPlainSoundType, &_audioHandle, _audioStream);
+ _mixer->playInputStream(Audio::Mixer::kPlainSoundType, &_audioHandle, _audioStream, -1, 255);
_audioStarted = true;
}
} else {
@@ -734,11 +724,13 @@
byte *unpackedBuffer = new byte[unpackedSize];
int curPos = 0;
byte *curPointer = unpackedBuffer;
- uint16 lo, hi, cur;
+ uint16 cur;
if (!dataPresent)
return;
+ // FIXME: The audio doesn't sound right yet
+
isStereo = audioBS.getBit();
assert(isStereo == _header.audioInfo[streamNum].isStereo);
is16Bits = audioBS.getBit();
@@ -750,6 +742,8 @@
for (k = 0; k < numBytes; k++)
audioTrees[k] = new SmallHuffmanTree(audioBS);
+ // Base values, stored as big endian
+
// Right channel
bases[0] = (!is16Bits) ? audioBS.getBits8() : (audioBS.getBits8() << 8) || audioBS.getBits8();
@@ -757,6 +751,9 @@
if (isStereo)
bases[1] = (!is16Bits) ? audioBS.getBits8() : (audioBS.getBits8() << 8) || audioBS.getBits8();
+ // Next follow the deltas, which are added to the corresponding base values and are stored as little endian
+ // We store the unpacked bytes in big endian format
+
while (curPos < unpackedSize) {
// If the sample is stereo, we get first the data for the left and then for the right channel
if (!is16Bits) {
@@ -765,28 +762,23 @@
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
+ for (k = 0; k < (isStereo ? 2 : 1); k++) {
+ cur = bases[k];
+ // adding takes care of possible overflows
+ cur += audioTrees[k * 2]->getCode(audioBS); // low byte
+ cur += (audioTrees[k * 2 + 1]->getCode(audioBS) << 8); // high byte
+ *curPointer++ = (cur >> 8) & 0xFF; // high byte
curPos++;
- *curPointer++ = (cur >> 8) & 0xFF; // high
+ *curPointer++ = cur & 0xFF; // low byte
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 >> 8) & 0xFF; // high
- curPos++;
}
}
+ for (k = 0; k < numBytes; k++)
+ delete audioTrees[k];
+
_audioStream->queueBuffer(unpackedBuffer, unpackedSize);
// unpackedBuffer will be deleted by AppendableAudioStream
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list