From adb69a5a39bb58a0ac6866b64ede228692a80488 Mon Sep 17 00:00:00 2001 From: Matthew Hoops Date: Wed, 24 Aug 2011 09:38:46 -0400 Subject: AUDIO: Rename Vag to XA Vag is really an XA container, and one that we do not have a decoder for (nor need) --- audio/decoders/vag.cpp | 147 ------------------------------------------------- audio/decoders/vag.h | 56 ------------------- audio/decoders/xa.cpp | 147 +++++++++++++++++++++++++++++++++++++++++++++++++ audio/decoders/xa.h | 56 +++++++++++++++++++ audio/module.mk | 2 +- 5 files changed, 204 insertions(+), 204 deletions(-) delete mode 100644 audio/decoders/vag.cpp delete mode 100644 audio/decoders/vag.h create mode 100644 audio/decoders/xa.cpp create mode 100644 audio/decoders/xa.h (limited to 'audio') diff --git a/audio/decoders/vag.cpp b/audio/decoders/vag.cpp deleted file mode 100644 index 10ef69708c..0000000000 --- a/audio/decoders/vag.cpp +++ /dev/null @@ -1,147 +0,0 @@ -/* 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. - * - */ - -#include "audio/decoders/vag.h" -#include "audio/audiostream.h" -#include "common/stream.h" - -namespace Audio { - -class VagStream : public Audio::RewindableAudioStream { -public: - VagStream(Common::SeekableReadStream *stream, int rate); - ~VagStream(); - - bool isStereo() const { return false; } - bool endOfData() const { return _stream->pos() == _stream->size(); } - int getRate() const { return _rate; } - int readBuffer(int16 *buffer, const int numSamples); - - bool rewind(); -private: - Common::SeekableReadStream *_stream; - - byte _predictor; - double _samples[28]; - byte _samplesRemaining; - int _rate; - double _s1, _s2; -}; - -VagStream::VagStream(Common::SeekableReadStream *stream, int rate) : _stream(stream) { - _samplesRemaining = 0; - _predictor = 0; - _s1 = _s2 = 0.0; - _rate = rate; -} - - -VagStream::~VagStream() { - delete _stream; -} - -static const double s_vagDataTable[5][2] = - { - { 0.0, 0.0 }, - { 60.0 / 64.0, 0.0 }, - { 115.0 / 64.0, -52.0 / 64.0 }, - { 98.0 / 64.0, -55.0 / 64.0 }, - { 122.0 / 64.0, -60.0 / 64.0 } - }; - -int VagStream::readBuffer(int16 *buffer, const int numSamples) { - int32 samplesDecoded = 0; - - if (_samplesRemaining) { - byte i = 0; - - for (i = 28 - _samplesRemaining; i < 28 && samplesDecoded < numSamples; i++) { - _samples[i] = _samples[i] + _s1 * s_vagDataTable[_predictor][0] + _s2 * s_vagDataTable[_predictor][1]; - _s2 = _s1; - _s1 = _samples[i]; - int16 d = (int) (_samples[i] + 0.5); - buffer[samplesDecoded] = d; - samplesDecoded++; - } - -#if 0 - assert(i == 28); // We're screwed if this fails :P -#endif - // This might mean the file is corrupted, or that the stream has - // been closed. - if (i != 28) return 0; - - _samplesRemaining = 0; - } - - while (samplesDecoded < numSamples) { - byte i = 0; - - _predictor = _stream->readByte(); - byte shift = _predictor & 0xf; - _predictor >>= 4; - - if (_stream->readByte() == 7) - return samplesDecoded; - - for (i = 0; i < 28; i += 2) { - byte d = _stream->readByte(); - int16 s = (d & 0xf) << 12; - if (s & 0x8000) - s |= 0xffff0000; - _samples[i] = (double)(s >> shift); - s = (d & 0xf0) << 8; - if (s & 0x8000) - s |= 0xffff0000; - _samples[i + 1] = (double)(s >> shift); - } - - for (i = 0; i < 28 && samplesDecoded < numSamples; i++) { - _samples[i] = _samples[i] + _s1 * s_vagDataTable[_predictor][0] + _s2 * s_vagDataTable[_predictor][1]; - _s2 = _s1; - _s1 = _samples[i]; - int16 d = (int) (_samples[i] + 0.5); - buffer[samplesDecoded] = d; - samplesDecoded++; - } - - if (i != 27) - _samplesRemaining = 28 - i; - } - - return samplesDecoded; -} - -bool VagStream::rewind() { - _stream->seek(0); - _samplesRemaining = 0; - _predictor = 0; - _s1 = _s2 = 0.0; - - return true; -} - -RewindableAudioStream *makeVagStream(Common::SeekableReadStream *stream, int rate) { - return new VagStream(stream, rate); -} - -} diff --git a/audio/decoders/vag.h b/audio/decoders/vag.h deleted file mode 100644 index b80fbdb98f..0000000000 --- a/audio/decoders/vag.h +++ /dev/null @@ -1,56 +0,0 @@ -/* 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. - * - */ - -/** - * @file - * Sound decoder used in engines: - * - sword1 (PSX port of the game) - * - sword2 (PSX port of the game) - * - tinsel (PSX port of the game) - */ - -#ifndef SOUND_VAG_H -#define SOUND_VAG_H - -namespace Common { -class SeekableReadStream; -} - -namespace Audio { - -class RewindableAudioStream; - -/** - * Takes an input stream containing Vag sound data and creates - * an RewindableAudioStream from that. - * - * @param stream the SeekableReadStream from which to read the ADPCM data - * @param rate the sampling rate - * @return a new RewindableAudioStream, or NULL, if an error occurred - */ -RewindableAudioStream *makeVagStream( - Common::SeekableReadStream *stream, - int rate = 11025); - -} // End of namespace Sword1 - -#endif diff --git a/audio/decoders/xa.cpp b/audio/decoders/xa.cpp new file mode 100644 index 0000000000..2b8c9b2d99 --- /dev/null +++ b/audio/decoders/xa.cpp @@ -0,0 +1,147 @@ +/* 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. + * + */ + +#include "audio/decoders/xa.h" +#include "audio/audiostream.h" +#include "common/stream.h" + +namespace Audio { + +class XAStream : public Audio::RewindableAudioStream { +public: + XAStream(Common::SeekableReadStream *stream, int rate); + ~XAStream(); + + bool isStereo() const { return false; } + bool endOfData() const { return _stream->pos() == _stream->size(); } + int getRate() const { return _rate; } + int readBuffer(int16 *buffer, const int numSamples); + + bool rewind(); +private: + Common::SeekableReadStream *_stream; + + byte _predictor; + double _samples[28]; + byte _samplesRemaining; + int _rate; + double _s1, _s2; +}; + +XAStream::XAStream(Common::SeekableReadStream *stream, int rate) : _stream(stream) { + _samplesRemaining = 0; + _predictor = 0; + _s1 = _s2 = 0.0; + _rate = rate; +} + + +XAStream::~XAStream() { + delete _stream; +} + +static const double s_xaDataTable[5][2] = + { + { 0.0, 0.0 }, + { 60.0 / 64.0, 0.0 }, + { 115.0 / 64.0, -52.0 / 64.0 }, + { 98.0 / 64.0, -55.0 / 64.0 }, + { 122.0 / 64.0, -60.0 / 64.0 } + }; + +int XAStream::readBuffer(int16 *buffer, const int numSamples) { + int32 samplesDecoded = 0; + + if (_samplesRemaining) { + byte i = 0; + + for (i = 28 - _samplesRemaining; i < 28 && samplesDecoded < numSamples; i++) { + _samples[i] = _samples[i] + _s1 * s_xaDataTable[_predictor][0] + _s2 * s_xaDataTable[_predictor][1]; + _s2 = _s1; + _s1 = _samples[i]; + int16 d = (int) (_samples[i] + 0.5); + buffer[samplesDecoded] = d; + samplesDecoded++; + } + +#if 0 + assert(i == 28); // We're screwed if this fails :P +#endif + // This might mean the file is corrupted, or that the stream has + // been closed. + if (i != 28) return 0; + + _samplesRemaining = 0; + } + + while (samplesDecoded < numSamples) { + byte i = 0; + + _predictor = _stream->readByte(); + byte shift = _predictor & 0xf; + _predictor >>= 4; + + if (_stream->readByte() == 7) + return samplesDecoded; + + for (i = 0; i < 28; i += 2) { + byte d = _stream->readByte(); + int16 s = (d & 0xf) << 12; + if (s & 0x8000) + s |= 0xffff0000; + _samples[i] = (double)(s >> shift); + s = (d & 0xf0) << 8; + if (s & 0x8000) + s |= 0xffff0000; + _samples[i + 1] = (double)(s >> shift); + } + + for (i = 0; i < 28 && samplesDecoded < numSamples; i++) { + _samples[i] = _samples[i] + _s1 * s_xaDataTable[_predictor][0] + _s2 * s_xaDataTable[_predictor][1]; + _s2 = _s1; + _s1 = _samples[i]; + int16 d = (int) (_samples[i] + 0.5); + buffer[samplesDecoded] = d; + samplesDecoded++; + } + + if (i != 27) + _samplesRemaining = 28 - i; + } + + return samplesDecoded; +} + +bool XAStream::rewind() { + _stream->seek(0); + _samplesRemaining = 0; + _predictor = 0; + _s1 = _s2 = 0.0; + + return true; +} + +RewindableAudioStream *makeXAStream(Common::SeekableReadStream *stream, int rate) { + return new XAStream(stream, rate); +} + +} // End of namespace Audio diff --git a/audio/decoders/xa.h b/audio/decoders/xa.h new file mode 100644 index 0000000000..ed3213f350 --- /dev/null +++ b/audio/decoders/xa.h @@ -0,0 +1,56 @@ +/* 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. + * + */ + +/** + * @file + * Sound decoder used in engines: + * - sword1 (PSX port of the game) + * - sword2 (PSX port of the game) + * - tinsel (PSX port of the game) + */ + +#ifndef AUDIO_DECODERS_XA_H +#define AUDIO_DECODERS_XA_H + +namespace Common { +class SeekableReadStream; +} + +namespace Audio { + +class RewindableAudioStream; + +/** + * Takes an input stream containing XA ADPCM sound data and creates + * an RewindableAudioStream from that. + * + * @param stream the SeekableReadStream from which to read the XA ADPCM data + * @param rate the sampling rate + * @return a new RewindableAudioStream, or NULL, if an error occurred + */ +RewindableAudioStream *makeXAStream( + Common::SeekableReadStream *stream, + int rate = 11025); + +} // End of namespace Audio + +#endif diff --git a/audio/module.mk b/audio/module.mk index 46cb9944e1..e3aa0aaa81 100644 --- a/audio/module.mk +++ b/audio/module.mk @@ -23,10 +23,10 @@ MODULE_OBJS := \ decoders/qdm2.o \ decoders/quicktime.o \ decoders/raw.o \ - decoders/vag.o \ decoders/voc.o \ decoders/vorbis.o \ decoders/wave.o \ + decoders/xa.o \ mods/infogrames.o \ mods/maxtrax.o \ mods/module.o \ -- cgit v1.2.3