Skip to content

Commit

Permalink
SOUND: Use given size instead of stream size to calculate ADPCM length
Browse files Browse the repository at this point in the history
  • Loading branch information
DrMcCoy committed Aug 18, 2018
1 parent 1c36e60 commit 4f514b0
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/sound/decoders/adpcm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ namespace Sound {
class ADPCMStream : public RewindableAudioStream {
protected:
Common::DisposablePtr<Common::SeekableReadStream> _stream;
const size_t _size;
const size_t _startpos;
const size_t _endpos;
const int _channels;
Expand Down Expand Up @@ -102,8 +103,9 @@ class ADPCMStream : public RewindableAudioStream {

ADPCMStream::ADPCMStream(Common::SeekableReadStream *stream, bool disposeAfterUse, size_t size, int rate, int channels, uint32 blockAlign)
: _stream(stream, disposeAfterUse),
_size(size),
_startpos(stream->pos()),
_endpos(_startpos + size),
_endpos(_startpos + _size),
_channels(channels),
_blockAlign(blockAlign),
_rate(rate),
Expand Down Expand Up @@ -137,7 +139,7 @@ class Ima_ADPCMStream : public ADPCMStream {
std::memset(&_status, 0, sizeof(_status));

// 2 samples per input byte
_length = stream->size() * 2 / _channels;
_length = _size * 2 / _channels;
}

virtual size_t readBuffer(int16 *buffer, const size_t numSamples);
Expand Down Expand Up @@ -181,7 +183,7 @@ class Apple_ADPCMStream : public Ima_ADPCMStream {
_streamPos[1] = _blockAlign;

// 2 samples per input byte, but 2 byte header per block
_length = ((stream->size() / _blockAlign) * (_blockAlign - 2) * 2) / channels;
_length = ((_size / _blockAlign) * (_blockAlign - 2) * 2) / channels;
}

virtual size_t readBuffer(int16 *buffer, const size_t numSamples);
Expand Down Expand Up @@ -266,7 +268,7 @@ class MSIma_ADPCMStream : public Ima_ADPCMStream {
_samplesLeft[1] = 0;

// 2 samples per input byte, but 4 byte header per block per channel
_length = ((stream->size() / _blockAlign) * (_blockAlign - (4 * channels)) * 2) / channels;
_length = ((_size / _blockAlign) * (_blockAlign - (4 * channels)) * 2) / channels;
}

size_t readBuffer(int16 *buffer, const size_t numSamples);
Expand Down Expand Up @@ -369,7 +371,7 @@ class MS_ADPCMStream : public ADPCMStream {
std::memset(&_status, 0, sizeof(_status));

// 2 samples per input byte, but 7 byte header per block per channel
_length = ((stream->size() / _blockAlign) * (_blockAlign - (7 * channels)) * 2) / channels;
_length = ((_size / _blockAlign) * (_blockAlign - (7 * channels)) * 2) / channels;
}

virtual size_t readBuffer(int16 *buffer, const size_t numSamples);
Expand Down Expand Up @@ -521,8 +523,8 @@ class Xbox_ADPCMStream : public ADPCMStream {
* If we have overhang, i.e. a non-full block at the end of the stream,
* we need to add one for the header, and 8 for each 4 following bytes. */

const uint32 wholeBlocks = (size / (channels * _blockAlign));
const uint32 overhang = (size % (channels * _blockAlign));
const uint32 wholeBlocks = (_size / (channels * _blockAlign));
const uint32 overhang = (_size % (channels * _blockAlign));

if ((overhang % 4) != 0)
throw Common::Exception("Xbox_ADPCMStream(): unaligned input size");
Expand Down

0 comments on commit 4f514b0

Please sign in to comment.