aboutsummaryrefslogtreecommitdiff
path: root/audio/decoders
diff options
context:
space:
mode:
authorDreammaster2013-02-15 08:25:09 -0500
committerDreammaster2013-02-15 08:25:09 -0500
commitbb3285d933419b6bdefadc55a6e320855ff0dd27 (patch)
tree2df613c52f854c33cff660ed1b064e2996ed80bb /audio/decoders
parentd1a19a1d4c3e20b57250e73141d81e8d9b44a2a1 (diff)
parentadc338cd719179a94ff470b28e9584262d7b47e8 (diff)
downloadscummvm-rg350-bb3285d933419b6bdefadc55a6e320855ff0dd27.tar.gz
scummvm-rg350-bb3285d933419b6bdefadc55a6e320855ff0dd27.tar.bz2
scummvm-rg350-bb3285d933419b6bdefadc55a6e320855ff0dd27.zip
Merge branch 'master' into hopkins
Diffstat (limited to 'audio/decoders')
-rw-r--r--audio/decoders/adpcm.cpp55
-rw-r--r--audio/decoders/adpcm_intern.h7
-rw-r--r--audio/decoders/aiff.h2
-rw-r--r--audio/decoders/quicktime.cpp2
-rw-r--r--audio/decoders/quicktime_intern.h2
5 files changed, 38 insertions, 30 deletions
diff --git a/audio/decoders/adpcm.cpp b/audio/decoders/adpcm.cpp
index 2fe509e1f3..f069ee3417 100644
--- a/audio/decoders/adpcm.cpp
+++ b/audio/decoders/adpcm.cpp
@@ -268,7 +268,6 @@ static const int MSADPCMAdaptationTable[] = {
768, 614, 512, 409, 307, 230, 230, 230
};
-
int16 MS_ADPCMStream::decodeMS(ADPCMChannelStatus *c, byte code) {
int32 predictor;
@@ -290,40 +289,42 @@ int16 MS_ADPCMStream::decodeMS(ADPCMChannelStatus *c, byte code) {
int MS_ADPCMStream::readBuffer(int16 *buffer, const int numSamples) {
int samples;
byte data;
- int i = 0;
-
- samples = 0;
+ int i;
- while (samples < numSamples && !_stream->eos() && _stream->pos() < _endpos) {
- if (_blockPos[0] == _blockAlign) {
- // read block header
- for (i = 0; i < _channels; i++) {
- _status.ch[i].predictor = CLIP(_stream->readByte(), (byte)0, (byte)6);
- _status.ch[i].coeff1 = MSADPCMAdaptCoeff1[_status.ch[i].predictor];
- _status.ch[i].coeff2 = MSADPCMAdaptCoeff2[_status.ch[i].predictor];
- }
+ for (samples = 0; samples < numSamples && !endOfData(); samples++) {
+ if (_decodedSampleCount == 0) {
+ if (_blockPos[0] == _blockAlign) {
+ // read block header
+ for (i = 0; i < _channels; i++) {
+ _status.ch[i].predictor = CLIP(_stream->readByte(), (byte)0, (byte)6);
+ _status.ch[i].coeff1 = MSADPCMAdaptCoeff1[_status.ch[i].predictor];
+ _status.ch[i].coeff2 = MSADPCMAdaptCoeff2[_status.ch[i].predictor];
+ }
- for (i = 0; i < _channels; i++)
- _status.ch[i].delta = _stream->readSint16LE();
+ for (i = 0; i < _channels; i++)
+ _status.ch[i].delta = _stream->readSint16LE();
- for (i = 0; i < _channels; i++)
- _status.ch[i].sample1 = _stream->readSint16LE();
+ for (i = 0; i < _channels; i++)
+ _status.ch[i].sample1 = _stream->readSint16LE();
- for (i = 0; i < _channels; i++)
- buffer[samples++] = _status.ch[i].sample2 = _stream->readSint16LE();
+ for (i = 0; i < _channels; i++)
+ _decodedSamples[_decodedSampleCount++] = _status.ch[i].sample2 = _stream->readSint16LE();
- for (i = 0; i < _channels; i++)
- buffer[samples++] = _status.ch[i].sample1;
+ for (i = 0; i < _channels; i++)
+ _decodedSamples[_decodedSampleCount++] = _status.ch[i].sample1;
- _blockPos[0] = _channels * 7;
+ _blockPos[0] = _channels * 7;
+ } else {
+ data = _stream->readByte();
+ _blockPos[0]++;
+ _decodedSamples[_decodedSampleCount++] = decodeMS(&_status.ch[0], (data >> 4) & 0x0f);
+ _decodedSamples[_decodedSampleCount++] = decodeMS(&_status.ch[_channels - 1], data & 0x0f);
+ }
}
- for (; samples < numSamples && _blockPos[0] < _blockAlign && !_stream->eos() && _stream->pos() < _endpos; samples += 2) {
- data = _stream->readByte();
- _blockPos[0]++;
- buffer[samples] = decodeMS(&_status.ch[0], (data >> 4) & 0x0f);
- buffer[samples + 1] = decodeMS(&_status.ch[_channels - 1], data & 0x0f);
- }
+ // (1 - (count - 1)) ensures that _decodedSamples acts as a FIFO of depth 2
+ buffer[samples] = _decodedSamples[1 - (_decodedSampleCount - 1)];
+ _decodedSampleCount--;
}
return samples;
diff --git a/audio/decoders/adpcm_intern.h b/audio/decoders/adpcm_intern.h
index 3b8d8c74d0..66a1aa605f 100644
--- a/audio/decoders/adpcm_intern.h
+++ b/audio/decoders/adpcm_intern.h
@@ -206,12 +206,19 @@ public:
if (blockAlign == 0)
error("MS_ADPCMStream(): blockAlign isn't specified for MS ADPCM");
memset(&_status, 0, sizeof(_status));
+ _decodedSampleCount = 0;
}
+ virtual bool endOfData() const { return (_stream->eos() || _stream->pos() >= _endpos) && (_decodedSampleCount == 0); }
+
virtual int readBuffer(int16 *buffer, const int numSamples);
protected:
int16 decodeMS(ADPCMChannelStatus *c, byte);
+
+private:
+ uint8 _decodedSampleCount;
+ int16 _decodedSamples[4];
};
// Duck DK3 IMA ADPCM Decoder
diff --git a/audio/decoders/aiff.h b/audio/decoders/aiff.h
index afcdb6ae6c..0d96e73c26 100644
--- a/audio/decoders/aiff.h
+++ b/audio/decoders/aiff.h
@@ -48,7 +48,7 @@ class SeekableAudioStream;
* successful. In that case, the stream's seek position will be set to the
* start of the audio data, and size, rate and flags contain information
* necessary for playback. Currently this function only supports uncompressed
- * raw PCM data as well as IMA ADPCM.
+ * raw PCM.
*/
extern bool loadAIFFFromStream(Common::SeekableReadStream &stream, int &size, int &rate, byte &flags);
diff --git a/audio/decoders/quicktime.cpp b/audio/decoders/quicktime.cpp
index 0588650ec6..787b547495 100644
--- a/audio/decoders/quicktime.cpp
+++ b/audio/decoders/quicktime.cpp
@@ -134,7 +134,7 @@ void QuickTimeAudioDecoder::init() {
_audioTracks.push_back(new QuickTimeAudioTrack(this, _tracks[i]));
}
-Common::QuickTimeParser::SampleDesc *QuickTimeAudioDecoder::readSampleDesc(Track *track, uint32 format) {
+Common::QuickTimeParser::SampleDesc *QuickTimeAudioDecoder::readSampleDesc(Track *track, uint32 format, uint32 descSize) {
if (track->codecType == CODEC_TYPE_AUDIO) {
debug(0, "Audio Codec FourCC: \'%s\'", tag2str(format));
diff --git a/audio/decoders/quicktime_intern.h b/audio/decoders/quicktime_intern.h
index f1ab037d89..bb5ff0cf5c 100644
--- a/audio/decoders/quicktime_intern.h
+++ b/audio/decoders/quicktime_intern.h
@@ -131,7 +131,7 @@ protected:
};
// Common::QuickTimeParser API
- virtual Common::QuickTimeParser::SampleDesc *readSampleDesc(Track *track, uint32 format);
+ virtual Common::QuickTimeParser::SampleDesc *readSampleDesc(Track *track, uint32 format, uint32 descSize);
void init();