[Scummvm-cvs-logs] SF.net SVN: scummvm:[51327] scummvm/trunk
mthreepwood at users.sourceforge.net
mthreepwood at users.sourceforge.net
Mon Jul 26 20:13:35 CEST 2010
Revision: 51327
http://scummvm.svn.sourceforge.net/scummvm/?rev=51327&view=rev
Author: mthreepwood
Date: 2010-07-26 18:13:35 +0000 (Mon, 26 Jul 2010)
Log Message:
-----------
SOUND: Move the Mac snd decoder from SCI to /sound
For use with Kyra1 Mac instrument samples. T7G Mac and Loom Mac also use this format for their custom instrument samples.
Modified Paths:
--------------
scummvm/trunk/engines/sci/sound/audio.cpp
scummvm/trunk/sound/module.mk
Added Paths:
-----------
scummvm/trunk/sound/decoders/mac_snd.cpp
scummvm/trunk/sound/decoders/mac_snd.h
Modified: scummvm/trunk/engines/sci/sound/audio.cpp
===================================================================
--- scummvm/trunk/engines/sci/sound/audio.cpp 2010-07-26 17:55:54 UTC (rev 51326)
+++ scummvm/trunk/engines/sci/sound/audio.cpp 2010-07-26 18:13:35 UTC (rev 51327)
@@ -36,6 +36,7 @@
#include "sound/audiostream.h"
#include "sound/decoders/aiff.h"
#include "sound/decoders/flac.h"
+#include "sound/decoders/mac_snd.h"
#include "sound/decoders/mp3.h"
#include "sound/decoders/raw.h"
#include "sound/decoders/vorbis.h"
@@ -338,19 +339,9 @@
} else if (audioRes->size > 14 && READ_BE_UINT16(audioRes->data) == 1 && READ_BE_UINT16(audioRes->data + 2) == 1
&& READ_BE_UINT16(audioRes->data + 4) == 5 && READ_BE_UINT32(audioRes->data + 10) == 0x00018051) {
// Mac snd detected
- // See http://developer.apple.com/legacy/mac/library/documentation/mac/Sound/Sound-60.html#HEADING60-15 for more details
+ Common::MemoryReadStream *sndStream = new Common::MemoryReadStream(audioRes->data, audioRes->size, DisposeAfterUse::NO);
- uint32 soundHeaderOffset = READ_BE_UINT32(audioRes->data + 16);
- assert(READ_BE_UINT32(audioRes->data + soundHeaderOffset) == 0);
- size = READ_BE_UINT32(audioRes->data + soundHeaderOffset + 4);
- _audioRate = READ_BE_UINT16(audioRes->data + soundHeaderOffset + 8); // Really floating point, but we're just truncating
-
- if (*(audioRes->data + soundHeaderOffset + 20) != 0)
- error("Unhandled Mac snd extended/compressed header");
-
- data = (byte *)malloc(size);
- memcpy(data, audioRes->data + soundHeaderOffset + 22, size);
- flags = Audio::FLAG_UNSIGNED;
+ audioSeekStream = Audio::makeMacSndStream(sndStream, DisposeAfterUse::YES);
} else {
// SCI1 raw audio
size = audioRes->size;
Added: scummvm/trunk/sound/decoders/mac_snd.cpp
===================================================================
--- scummvm/trunk/sound/decoders/mac_snd.cpp (rev 0)
+++ scummvm/trunk/sound/decoders/mac_snd.cpp 2010-07-26 18:13:35 UTC (rev 51327)
@@ -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 floating 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
Property changes on: scummvm/trunk/sound/decoders/mac_snd.cpp
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Added: scummvm/trunk/sound/decoders/mac_snd.h
===================================================================
--- scummvm/trunk/sound/decoders/mac_snd.h (rev 0)
+++ scummvm/trunk/sound/decoders/mac_snd.h 2010-07-26 18:13:35 UTC (rev 51327)
@@ -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
Property changes on: scummvm/trunk/sound/decoders/mac_snd.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Modified: scummvm/trunk/sound/module.mk
===================================================================
--- scummvm/trunk/sound/module.mk 2010-07-26 17:55:54 UTC (rev 51326)
+++ scummvm/trunk/sound/module.mk 2010-07-26 18:13:35 UTC (rev 51327)
@@ -17,6 +17,7 @@
decoders/aiff.o \
decoders/flac.o \
decoders/iff_sound.o \
+ decoders/mac_snd.o \
decoders/mp3.o \
decoders/raw.o \
decoders/vag.o \
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