00001 #ifndef MERCURYSOUNDSOURCEWAV_H 00002 #define MERCURYSOUNDSOURCEWAV_H 00003 00004 #include "MercuryString.h" 00005 #include "MercuryFiles.h" 00006 #include "MercuryUtil.h" 00007 00008 struct RiffChunk 00009 { 00010 int id; //4 (big endian) 00011 unsigned int size; //4 00012 }; 00013 00014 struct WaveHead 00015 { 00016 RiffChunk info; 00017 int type; //4 (big endian) 00018 }; 00019 00020 struct FmtChunk 00021 { 00022 //the compiler pads this to size 28, it should be 26 00023 // RiffChunk info; 00024 unsigned short comp; //2 00025 unsigned short channels; //2 00026 unsigned int srate; //4 00027 unsigned int aBPS; //4 00028 unsigned short align; //2 00029 unsigned short sigBPS; //2 00030 unsigned short extraFormat; //2 00031 }; 00032 00033 enum SoundPlayState 00034 { 00035 STOPPED, 00036 PLAYING, 00037 PAUSED 00038 }; 00039 00040 class MercurySoundSourceWAV 00041 { 00042 // CLASS_RTTI( MercurySoundSourceWAV, MercurySoundSource ); 00043 00044 public: 00045 MercurySoundSourceWAV(); 00046 ~MercurySoundSourceWAV(); 00047 bool Open(const MString& path); 00048 float* ReadData(unsigned long samples); 00049 00050 bool Play(); 00051 bool Stop(); 00052 void Pause(bool pause); 00053 inline bool IsPaused() const { return m_playState==PAUSED; } 00054 00055 virtual MString GetType() { return "MercurySoundSourceWAV"; } 00056 virtual void GetAllTypes( MVector<MString> & vOut ) { vOut.push_back( "MercurySoundSourceWAV" ); } 00057 virtual bool IsTypeOf( const MString & sType ) { return sType == "MercurySoundSourceWAV"; } 00058 00059 void SetDestroyOnStop(bool destroy) { m_destroyOnStop = destroy; } 00060 private: 00061 bool LocateAudioData(); 00062 00063 bool m_atAudioChunk; 00064 00065 MercuryFile* m_file; 00066 unsigned long m_chunkSize; 00067 unsigned long m_chunkPosition; 00068 00069 SoundPlayState m_playState; 00070 bool m_destroyOnStop; 00071 }; 00072 00073 #endif 00074 00075 /* 00076 * Copyright (c) 2007 Joshua Allen 00077 * All rights reserved. 00078 * 00079 * Redistribution and use in source and binary forms, with or 00080 * without modification, are permitted provided that the following 00081 * conditions are met: 00082 * - Redistributions of source code must retain the above 00083 * copyright notice, this list of conditions and the following disclaimer. 00084 * - Redistributions in binary form must reproduce the above copyright 00085 * notice, this list of conditions and the following disclaimer in 00086 * the documentation and/or other materials provided with the distribution. 00087 * - Neither the name of the Mercury Engine nor the names of its 00088 * contributors may be used to endorse or promote products derived from 00089 * this software without specific prior written permission. 00090 * 00091 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00092 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00093 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00094 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 00095 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00096 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00097 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00098 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00099 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 00100 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00101 */