diff options
Diffstat (limited to 'sound/decoders')
-rw-r--r-- | sound/decoders/adpcm.h | 2 | ||||
-rw-r--r-- | sound/decoders/aiff.cpp | 13 | ||||
-rw-r--r-- | sound/decoders/aiff.h | 9 | ||||
-rw-r--r-- | sound/decoders/flac.cpp | 6 | ||||
-rw-r--r-- | sound/decoders/flac.h | 4 | ||||
-rw-r--r-- | sound/decoders/mac_snd.cpp | 116 | ||||
-rw-r--r-- | sound/decoders/mac_snd.h | 58 | ||||
-rw-r--r-- | sound/decoders/mp3.cpp | 6 | ||||
-rw-r--r-- | sound/decoders/mp3.h | 4 | ||||
-rw-r--r-- | sound/decoders/vag.h | 2 | ||||
-rw-r--r-- | sound/decoders/voc.h | 2 | ||||
-rw-r--r-- | sound/decoders/vorbis.cpp | 2 | ||||
-rw-r--r-- | sound/decoders/vorbis.h | 4 | ||||
-rw-r--r-- | sound/decoders/wave.h | 4 |
14 files changed, 210 insertions, 22 deletions
diff --git a/sound/decoders/adpcm.h b/sound/decoders/adpcm.h index 7452478f35..04dbb1a521 100644 --- a/sound/decoders/adpcm.h +++ b/sound/decoders/adpcm.h @@ -71,7 +71,7 @@ enum typesADPCM { * @param rate the sampling rate * @param channels the number of channels * @param blockAlign block alignment ??? - * @return a new RewindableAudioStream, or NULL, if an error occured + * @return a new RewindableAudioStream, or NULL, if an error occurred */ RewindableAudioStream *makeADPCMStream( Common::SeekableReadStream *stream, diff --git a/sound/decoders/aiff.cpp b/sound/decoders/aiff.cpp index 2f12669072..ce8c6ad32c 100644 --- a/sound/decoders/aiff.cpp +++ b/sound/decoders/aiff.cpp @@ -161,16 +161,23 @@ bool loadAIFFFromStream(Common::SeekableReadStream &stream, int &size, int &rate return true; } -SeekableAudioStream *makeAIFFStream(Common::SeekableReadStream &stream) { +SeekableAudioStream *makeAIFFStream(Common::SeekableReadStream *stream, + DisposeAfterUse::Flag disposeAfterUse) { int size, rate; byte *data, flags; - if (!loadAIFFFromStream(stream, size, rate, flags)) + if (!loadAIFFFromStream(*stream, size, rate, flags)) { + if (disposeAfterUse == DisposeAfterUse::YES) + delete stream; return 0; + } data = (byte *)malloc(size); assert(data); - stream.read(data, size); + stream->read(data, size); + + if (disposeAfterUse == DisposeAfterUse::YES) + delete stream; // Since we allocated our own buffer for the data, we must specify DisposeAfterUse::YES. return makeRawStream(data, size, rate, flags); diff --git a/sound/decoders/aiff.h b/sound/decoders/aiff.h index e8a3b6f0b0..53f86c95fd 100644 --- a/sound/decoders/aiff.h +++ b/sound/decoders/aiff.h @@ -34,6 +34,7 @@ #define SOUND_AIFF_H #include "common/scummsys.h" +#include "common/types.h" namespace Common { class SeekableReadStream; } @@ -55,8 +56,14 @@ extern bool loadAIFFFromStream(Common::SeekableReadStream &stream, int &size, in * from that data. * * This function uses loadAIFFFromStream() internally. + * + * @param stream the SeekableReadStream from which to read the AIFF data + * @param disposeAfterUse whether to delete the stream after use + * @return a new SeekableAudioStream, or NULL, if an error occurred */ -SeekableAudioStream *makeAIFFStream(Common::SeekableReadStream &stream); +SeekableAudioStream *makeAIFFStream( + Common::SeekableReadStream *stream, + DisposeAfterUse::Flag disposeAfterUse); } // End of namespace Audio diff --git a/sound/decoders/flac.cpp b/sound/decoders/flac.cpp index 91c48199e3..e588aa872f 100644 --- a/sound/decoders/flac.cpp +++ b/sound/decoders/flac.cpp @@ -230,7 +230,7 @@ FLACStream::FLACStream(Common::SeekableReadStream *inStream, bool dispose) if (processUntilEndOfMetadata() && _streaminfo.channels > 0) { _lastSample = _streaminfo.total_samples + 1; _length = Timestamp(0, _lastSample - 1, getRate()); - return; // no error occured + return; // no error occurred } } @@ -355,7 +355,7 @@ int FLACStream::readBuffer(int16 *buffer, const int numSamples) { break; default: decoderOk = false; - warning("FLACStream: An error occured while decoding. DecoderState is: %s", + warning("FLACStream: An error occurred while decoding. DecoderState is: %s", FLAC__StreamDecoderStateString[getStreamDecoderState()]); } @@ -668,7 +668,7 @@ inline void FLACStream::callbackMetadata(const ::FLAC__StreamMetadata *metadata) } inline void FLACStream::callbackError(::FLAC__StreamDecoderErrorStatus status) { // some of these are non-critical-Errors - debug(1, "FLACStream: An error occured while decoding. DecoderState is: %s", + debug(1, "FLACStream: An error occurred while decoding. DecoderState is: %s", FLAC__StreamDecoderErrorStatusString[status]); } diff --git a/sound/decoders/flac.h b/sound/decoders/flac.h index 982450c045..3c00ec3d5d 100644 --- a/sound/decoders/flac.h +++ b/sound/decoders/flac.h @@ -41,8 +41,8 @@ #ifndef SOUND_FLAC_H #define SOUND_FLAC_H -#include "common/types.h" #include "common/scummsys.h" +#include "common/types.h" #ifdef USE_FLAC @@ -61,7 +61,7 @@ class SeekableAudioStream; * * @param stream the SeekableReadStream from which to read the FLAC data * @param disposeAfterUse whether to delete the stream after use - * @return a new SeekableAudioStream, or NULL, if an error occured + * @return a new SeekableAudioStream, or NULL, if an error occurred */ SeekableAudioStream *makeFLACStream( Common::SeekableReadStream *stream, diff --git a/sound/decoders/mac_snd.cpp b/sound/decoders/mac_snd.cpp new file mode 100644 index 0000000000..d6894f1144 --- /dev/null +++ b/sound/decoders/mac_snd.cpp @@ -0,0 +1,116 @@ +/* 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. + * + * $URL$ + * $Id$ + * + */ + +/* + * The code in this file is based on information found at + * http://developer.apple.com/legacy/mac/library/documentation/mac/Sound/Sound-60.html#HEADING60-15 + * + * We implement both type 1 and type 2 snd resources, but only those that are sampled + */ + +#include "common/util.h" +#include "common/stream.h" + +#include "sound/decoders/mac_snd.h" +#include "sound/audiostream.h" +#include "sound/decoders/raw.h" + +namespace Audio { + +SeekableAudioStream *makeMacSndStream(Common::SeekableReadStream *stream, + DisposeAfterUse::Flag disposeAfterUse) { + + uint16 sndType = stream->readUint16BE(); + + if (sndType == 1) { + // "normal" snd resources + if (stream->readUint16BE() != 1) { + warning("makeMacSndStream(): Unsupported data type count"); + return 0; + } + + if (stream->readUint16BE() != 5) { + // 5 == sampled + warning("makeMacSndStream(): Unsupported data type"); + return 0; + } + + stream->readUint32BE(); // initialization option + } else if (sndType == 2) { + // old HyperCard snd resources + stream->readUint16BE(); // reference count (unused) + } else { + warning("makeMacSndStream(): Unknown format type %d", sndType); + return 0; + } + + // We really should never get this as long as we have sampled data only + if (stream->readUint16BE() != 1) { + warning("makeMacSndStream(): Unsupported command count"); + return 0; + } + + uint16 command = stream->readUint16BE(); + + // 0x8050 - soundCmd (with dataOffsetFlag set): install a sampled sound as a voice + // 0x8051 - bufferCmd (with dataOffsetFlag set): play a sample sound + if (command != 0x8050 && command != 0x8051) { + warning("makeMacSndStream(): Unsupported command %04x", command); + return 0; + } + + stream->readUint16BE(); // 0 + uint32 soundHeaderOffset = stream->readUint32BE(); + + stream->seek(soundHeaderOffset); + + uint32 soundDataOffset = stream->readUint32BE(); + uint32 size = stream->readUint32BE(); + uint16 rate = stream->readUint32BE() >> 16; // Really fixed point, but we only support integer rates + stream->readUint32BE(); // loop start + stream->readUint32BE(); // loop end + byte encoding = stream->readByte(); + stream->readByte(); // base frequency + + if (encoding != 0) { + // 0 == PCM + warning("makeMacSndStream(): Unsupported compression %d", encoding); + return 0; + } + + stream->skip(soundDataOffset); + + byte *data = (byte *)malloc(size); + assert(data); + stream->read(data, size); + + if (disposeAfterUse == DisposeAfterUse::YES) + delete stream; + + // Since we allocated our own buffer for the data, we must specify DisposeAfterUse::YES. + return makeRawStream(data, size, rate, Audio::FLAG_UNSIGNED); +} + +} // End of namespace Audio diff --git a/sound/decoders/mac_snd.h b/sound/decoders/mac_snd.h new file mode 100644 index 0000000000..198a61333e --- /dev/null +++ b/sound/decoders/mac_snd.h @@ -0,0 +1,58 @@ +/* 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. + * + * $URL$ + * $Id$ + * + */ + +/** + * @file + * Sound decoder used in engines: + * - sci + */ + +#ifndef SOUND_MAC_SND_H +#define SOUND_MAC_SND_H + +#include "common/scummsys.h" +#include "common/types.h" + +namespace Common { class SeekableReadStream; } + +namespace Audio { + +class SeekableAudioStream; + +/** + * Try to load a Mac snd resource from the given seekable stream and create a SeekableAudioStream + * from that data. + * + * @param stream the SeekableReadStream from which to read the snd data + * @param disposeAfterUse whether to delete the stream after use + * @return a new SeekableAudioStream, or NULL, if an error occurred + */ +SeekableAudioStream *makeMacSndStream( + Common::SeekableReadStream *stream, + DisposeAfterUse::Flag disposeAfterUse); + +} // End of namespace Audio + +#endif diff --git a/sound/decoders/mp3.cpp b/sound/decoders/mp3.cpp index 732ae58b67..f22eae5102 100644 --- a/sound/decoders/mp3.cpp +++ b/sound/decoders/mp3.cpp @@ -349,13 +349,13 @@ int MP3Stream::readBuffer(int16 *buffer, const int numSamples) { SeekableAudioStream *makeMP3Stream( Common::SeekableReadStream *stream, DisposeAfterUse::Flag disposeAfterUse) { - + #if defined(__PSP__) SeekableAudioStream *s = 0; - + if (Mp3PspStream::isOkToCreateStream()) s = new Mp3PspStream(stream, disposeAfterUse); - + if (!s) // go to regular MAD mp3 stream if ME fails s = new MP3Stream(stream, disposeAfterUse); #else diff --git a/sound/decoders/mp3.h b/sound/decoders/mp3.h index 3175df5e92..ed54c8b013 100644 --- a/sound/decoders/mp3.h +++ b/sound/decoders/mp3.h @@ -41,8 +41,8 @@ #ifndef SOUND_MP3_H #define SOUND_MP3_H -#include "common/types.h" #include "common/scummsys.h" +#include "common/types.h" #ifdef USE_MAD @@ -61,7 +61,7 @@ class SeekableAudioStream; * * @param stream the SeekableReadStream from which to read the MP3 data * @param disposeAfterUse whether to delete the stream after use - * @return a new SeekableAudioStream, or NULL, if an error occured + * @return a new SeekableAudioStream, or NULL, if an error occurred */ SeekableAudioStream *makeMP3Stream( Common::SeekableReadStream *stream, diff --git a/sound/decoders/vag.h b/sound/decoders/vag.h index 7e0ed255be..cdf91a8ea1 100644 --- a/sound/decoders/vag.h +++ b/sound/decoders/vag.h @@ -49,7 +49,7 @@ class RewindableAudioStream; * * @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 occured + * @return a new RewindableAudioStream, or NULL, if an error occurred */ RewindableAudioStream *makeVagStream( Common::SeekableReadStream *stream, diff --git a/sound/decoders/voc.h b/sound/decoders/voc.h index 79956ee62a..82cc261f2c 100644 --- a/sound/decoders/voc.h +++ b/sound/decoders/voc.h @@ -38,8 +38,8 @@ #ifndef SOUND_VOC_H #define SOUND_VOC_H -#include "common/types.h" #include "common/scummsys.h" +#include "common/types.h" namespace Common { class ReadStream; } namespace Common { class SeekableReadStream; } diff --git a/sound/decoders/vorbis.cpp b/sound/decoders/vorbis.cpp index 64869d7843..7673c53010 100644 --- a/sound/decoders/vorbis.cpp +++ b/sound/decoders/vorbis.cpp @@ -35,7 +35,7 @@ #include "sound/audiocd.h" #ifdef USE_TREMOR -#if defined(ANDROID) || defined(__GP32__) // custom libtremor locations +#if defined(__GP32__) // custom libtremor locations #include <ivorbisfile.h> #else #include <tremor/ivorbisfile.h> diff --git a/sound/decoders/vorbis.h b/sound/decoders/vorbis.h index dd0a89bfdd..0a0cf43bc9 100644 --- a/sound/decoders/vorbis.h +++ b/sound/decoders/vorbis.h @@ -41,8 +41,8 @@ #ifndef SOUND_VORBIS_H #define SOUND_VORBIS_H -#include "common/types.h" #include "common/scummsys.h" +#include "common/types.h" #ifdef USE_VORBIS @@ -61,7 +61,7 @@ class SeekableAudioStream; * * @param stream the SeekableReadStream from which to read the Ogg Vorbis data * @param disposeAfterUse whether to delete the stream after use - * @return a new SeekableAudioStream, or NULL, if an error occured + * @return a new SeekableAudioStream, or NULL, if an error occurred */ SeekableAudioStream *makeVorbisStream( Common::SeekableReadStream *stream, diff --git a/sound/decoders/wave.h b/sound/decoders/wave.h index f0e3bb249b..edd37e7ac9 100644 --- a/sound/decoders/wave.h +++ b/sound/decoders/wave.h @@ -38,8 +38,8 @@ #ifndef SOUND_WAVE_H #define SOUND_WAVE_H -#include "common/types.h" #include "common/scummsys.h" +#include "common/types.h" namespace Common { class SeekableReadStream; } @@ -71,7 +71,7 @@ extern bool loadWAVFromStream( * * @param stream the SeekableReadStream from which to read the WAVE data * @param disposeAfterUse whether to delete the stream after use - * @return a new RewindableAudioStream, or NULL, if an error occured + * @return a new RewindableAudioStream, or NULL, if an error occurred */ RewindableAudioStream *makeWAVStream( Common::SeekableReadStream *stream, |