ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

mac_snd.cpp

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 /*
00024  * The code in this file is based on information found at
00025  * http://developer.apple.com/legacy/mac/library/documentation/mac/Sound/Sound-60.html#HEADING60-15
00026  *
00027  * We implement both type 1 and type 2 snd resources, but only those that are sampled
00028  */
00029 
00030 #include "common/textconsole.h"
00031 #include "common/stream.h"
00032 
00033 #include "audio/decoders/mac_snd.h"
00034 #include "audio/decoders/raw.h"
00035 
00036 namespace Audio {
00037 
00038 SeekableAudioStream *makeMacSndStream(Common::SeekableReadStream *stream,
00039     DisposeAfterUse::Flag disposeAfterUse) {
00040 
00041     uint16 sndType = stream->readUint16BE();
00042 
00043     if (sndType == 1) {
00044         // "normal" snd resources
00045         if (stream->readUint16BE() != 1) {
00046             warning("makeMacSndStream(): Unsupported data type count");
00047             return 0;
00048         }
00049 
00050         if (stream->readUint16BE() != 5) {
00051             // 5 == sampled
00052             warning("makeMacSndStream(): Unsupported data type");
00053             return 0;
00054         }
00055 
00056         stream->readUint32BE(); // initialization option
00057     } else if (sndType == 2) {
00058         // old HyperCard snd resources
00059         stream->readUint16BE(); // reference count (unused)
00060     } else {
00061         warning("makeMacSndStream(): Unknown format type %d", sndType);
00062         return 0;
00063     }
00064 
00065     // We really should never get this as long as we have sampled data only
00066     if (stream->readUint16BE() != 1) {
00067         warning("makeMacSndStream(): Unsupported command count");
00068         return 0;
00069     }
00070 
00071     uint16 command = stream->readUint16BE();
00072 
00073     // 0x8050 - soundCmd  (with dataOffsetFlag set): install a sampled sound as a voice
00074     // 0x8051 - bufferCmd (with dataOffsetFlag set): play a sample sound
00075     if (command != 0x8050 && command != 0x8051) {
00076         warning("makeMacSndStream(): Unsupported command %04x", command);
00077         return 0;
00078     }
00079 
00080     stream->readUint16BE(); // 0
00081     uint32 soundHeaderOffset = stream->readUint32BE();
00082 
00083     stream->seek(soundHeaderOffset);
00084 
00085     uint32 soundDataOffset = stream->readUint32BE();
00086     uint32 size = stream->readUint32BE();
00087     uint16 rate = stream->readUint32BE() >> 16; // Really fixed point, but we only support integer rates
00088     stream->readUint32BE(); // loop start
00089     stream->readUint32BE(); // loop end
00090     byte encoding = stream->readByte();
00091     stream->readByte(); // base frequency
00092 
00093     if (encoding != 0) {
00094         // 0 == PCM
00095         warning("makeMacSndStream(): Unsupported compression %d", encoding);
00096         return 0;
00097     }
00098 
00099     stream->skip(soundDataOffset);
00100 
00101     byte *data = (byte *)malloc(size);
00102     assert(data);
00103     stream->read(data, size);
00104 
00105     if (disposeAfterUse == DisposeAfterUse::YES)
00106         delete stream;
00107 
00108     // Since we allocated our own buffer for the data, we must specify DisposeAfterUse::YES.
00109     return makeRawStream(data, size, rate, Audio::FLAG_UNSIGNED);
00110 }
00111 
00112 } // End of namespace Audio


Generated on Sat Oct 19 2019 05:00:46 for ResidualVM by doxygen 1.7.1
curved edge   curved edge