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

iff_sound.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 #include "audio/decoders/iff_sound.h"
00024 #include "audio/audiostream.h"
00025 #include "audio/decoders/raw.h"
00026 #include "common/iff_container.h"
00027 #include "common/func.h"
00028 
00029 namespace Audio {
00030 
00031 struct Voice8Header {
00032     uint32  oneShotHiSamples;
00033     uint32  repeatHiSamples;
00034     uint32  samplesPerHiCycle;
00035     uint16  samplesPerSec;
00036     byte    octaves;
00037     byte    compression;
00038     uint32  volume;
00039 
00040     Voice8Header() {
00041         memset(this, 0, sizeof(Voice8Header));
00042     }
00043 
00044     void load(Common::ReadStream &stream);
00045 };
00046 
00047 void Voice8Header::load(Common::ReadStream &stream) {
00048     oneShotHiSamples = stream.readUint32BE();
00049     repeatHiSamples = stream.readUint32BE();
00050     samplesPerHiCycle = stream.readUint32BE();
00051     samplesPerSec = stream.readUint16BE();
00052     octaves = stream.readByte();
00053     compression = stream.readByte();
00054     volume = stream.readUint32BE();
00055 }
00056 
00057 
00058 
00059 struct A8SVXLoader {
00060     Voice8Header _header;
00061     int8 *_data;
00062     uint32 _dataSize;
00063 
00064     void load(Common::ReadStream &input) {
00065         Common::IFFParser parser(&input);
00066         Common::Functor1Mem< Common::IFFChunk&, bool, A8SVXLoader > c(this, &A8SVXLoader::callback);
00067         parser.parse(c);
00068     }
00069 
00070     bool callback(Common::IFFChunk &chunk) {
00071         switch (chunk._type) {
00072         case ID_VHDR:
00073             _header.load(*chunk._stream);
00074             break;
00075 
00076         case ID_BODY:
00077             _dataSize = chunk._size;
00078             _data = (int8 *)malloc(_dataSize);
00079             assert(_data);
00080             loadData(chunk._stream);
00081             return true;
00082         }
00083 
00084         return false;
00085     }
00086 
00087     void loadData(Common::ReadStream *stream) {
00088         switch (_header.compression) {
00089         case 0:
00090             stream->read(_data, _dataSize);
00091             break;
00092 
00093         case 1:
00094             // implement other formats here
00095             error("compressed IFF audio is not supported");
00096             break;
00097         }
00098 
00099     }
00100 };
00101 
00102 
00103 AudioStream *make8SVXStream(Common::ReadStream &input, bool loop) {
00104     A8SVXLoader loader;
00105     loader.load(input);
00106 
00107     SeekableAudioStream *stream = Audio::makeRawStream((byte *)loader._data, loader._dataSize, loader._header.samplesPerSec, 0);
00108 
00109     uint32 loopStart = 0, loopEnd = 0;
00110     if (loop) {
00111         // the standard way to loop 8SVX audio implies use of the oneShotHiSamples and
00112         // repeatHiSamples fields
00113         loopStart = 0;
00114         loopEnd = loader._header.oneShotHiSamples + loader._header.repeatHiSamples;
00115 
00116         if (loopStart != loopEnd) {
00117             return new SubLoopingAudioStream(stream, 0,
00118                     Timestamp(0, loopStart, loader._header.samplesPerSec),
00119                     Timestamp(0, loopEnd, loader._header.samplesPerSec));
00120         }
00121     }
00122 
00123     return stream;
00124 }
00125 
00126 }


Generated on Sat May 18 2019 05:01:04 for ResidualVM by doxygen 1.7.1
curved edge   curved edge