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         default:
00084             break;
00085         }
00086 
00087         return false;
00088     }
00089 
00090     void loadData(Common::ReadStream *stream) {
00091         switch (_header.compression) {
00092         case 0:
00093             stream->read(_data, _dataSize);
00094             break;
00095 
00096         case 1:
00097             // implement other formats here
00098             error("compressed IFF audio is not supported");
00099             break;
00100 
00101         default:
00102             break;
00103         }
00104 
00105     }
00106 };
00107 
00108 
00109 AudioStream *make8SVXStream(Common::ReadStream &input, bool loop) {
00110     A8SVXLoader loader;
00111     loader.load(input);
00112 
00113     SeekableAudioStream *stream = Audio::makeRawStream((byte *)loader._data, loader._dataSize, loader._header.samplesPerSec, 0);
00114 
00115     uint32 loopStart = 0, loopEnd = 0;
00116     if (loop) {
00117         // the standard way to loop 8SVX audio implies use of the oneShotHiSamples and
00118         // repeatHiSamples fields
00119         loopStart = 0;
00120         loopEnd = loader._header.oneShotHiSamples + loader._header.repeatHiSamples;
00121 
00122         if (loopStart != loopEnd) {
00123             return new SubLoopingAudioStream(stream, 0,
00124                     Timestamp(0, loopStart, loader._header.samplesPerSec),
00125                     Timestamp(0, loopEnd, loader._header.samplesPerSec));
00126         }
00127     }
00128 
00129     return stream;
00130 }
00131 
00132 }


Generated on Sat May 30 2020 05:00:28 for ResidualVM by doxygen 1.7.1
curved edge   curved edge