2 * This file is part of ShapeFusion (Copyright 2000 Tito Dal Canton)
4 * ShapeFusion is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * ShapeFusion is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with ShapeFusion; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #ifndef SOUNDSELEMENTS_H
20 #define SOUNDSELEMENTS_H
26 #include "../BigEndianBuffer.h"
28 /* ---------- constants */
30 #define MAXIMUM_PERMUTATIONS_PER_SOUND 5
31 #define SOUND_FILE_VERSION 1
32 #define SIZEOF_sound_file_header 260
33 #define SIZEOF_sound_definition 64
35 enum /* sound behaviors */
40 NUMBER_OF_SOUND_BEHAVIOR_DEFINITIONS
45 _sound_cannot_be_restarted= 0x0001,
46 _sound_does_not_self_abort= 0x0002,
47 _sound_resists_pitch_changes= 0x0004, // 0.5 external pitch changes
48 _sound_cannot_change_pitch= 0x0008, // no external pitch changes
49 _sound_cannot_be_obstructed= 0x0010, // ignore obstructions
50 _sound_cannot_be_media_obstructed= 0x0020, // ignore media obstructions
51 _sound_is_ambient= 0x0040 // will not be loaded unless _ambient_sound_flag is asserted
54 enum /* sound chances */
56 _ten_percent= 32768*9/10,
57 _twenty_percent= 32768*8/10,
58 _thirty_percent= 32768*7/10,
59 _fourty_percent= 32768*6/10,
60 _fifty_percent= 32768*5/10,
61 _sixty_percent= 32768*4/10,
62 _seventy_percent= 32768*3/10,
63 _eighty_percent= 32768*2/10,
64 _ninty_percent= 32768*1/10,
68 /* ---------- structures */
72 } ambient_sound_definition;
76 } random_sound_definition;*/
78 class SoundsElement // : public wxObject
84 // So that subclasses can change their status
88 SoundsElement(bool verbose) : mVerboseLoading(verbose), mGoodData(false) {}
89 ~SoundsElement(void) {}
91 bool IsGood() const {return mGoodData;}
92 bool IsVerbose() const {return mVerboseLoading;}
95 class AppleSoundHeader : public SoundsElement
98 // Stuff for reading System 7 Sound info
99 /*sampled sound header encoding options*/
101 standardSoundHeader = 0x00,
102 extendedSoundHeader = 0xFF,
103 compressedSoundHeader = 0xFE
110 unsigned int mSampleRate; // 16.16 unsigned fixed
113 unsigned char mBaseFrequency;
115 std::vector<unsigned char> mData;
117 bool SaveToWaveOrAiff(wxString path, bool aiff);
120 AppleSoundHeader(bool verbose = false);
123 bool operator==(const AppleSoundHeader& right) const;
125 bool LoadFromFile(wxString path);
126 bool LoadFromWave(wxString path);
127 bool SaveToWave(wxString path) { return SaveToWaveOrAiff(path, false); }
128 bool LoadFromAiff(wxString path);
129 bool SaveToAiff(wxString path) { return SaveToWaveOrAiff(path, true); }
130 void PlaySound(void);
132 bool IsSixteenBit() const { return mSixteenBit; }
133 bool IsStereo() const { return mStereo; }
134 bool IsSigned() const { return mSigned; }
135 int GetBytesPerFrame() const { return mBytesPerFrame; }
136 unsigned int GetSampleRate() const { return mSampleRate; }
138 void SetSixteenBit(bool s) { mSixteenBit = s; }
139 void SetStereo(bool s) { mStereo = s; }
140 void SetSigned(bool s) { mSigned = s; }
141 void SetBytesPerFrame(int b) { mBytesPerFrame = b; }
142 void SetSampleRate(unsigned int sr) { mSampleRate = sr; }
145 unsigned int Size(void);
146 unsigned char* Data(void);
147 BigEndianBuffer& SaveObject(BigEndianBuffer& buffer);
148 BigEndianBuffer& LoadObject(BigEndianBuffer& buffer);
151 class SoundsDefinition : public SoundsElement
154 /* Marathon Sound Definition */
156 short mBehaviorIndex;
157 unsigned short mFlags;
158 unsigned short mChance; // play sound if AbsRandom()>=chance
159 /* if low_pitch==0, use FIXED_ONE;
160 * if high_pitch==0 use low pitch;
161 * else choose in [low_pitch,high_pitch]
163 float mLowPitch, mHighPitch;
164 /* filled in later */
165 // short mPermutations;
166 unsigned short mPermutationsPlayed;
167 // int mGroupOffset, mSingleLength, mTotalLength; // magic numbers necessary to load sounds
168 // std::vector<int> mSoundOffsets;
169 std::vector<AppleSoundHeader> mSounds;
170 unsigned int mLastPlayed; // machine ticks
171 // Pointer to loaded sound and size of sound object pointed to
178 SoundsDefinition(bool verbose = false);
181 bool HaveSameAttributesAs(const SoundsDefinition& right) const;
182 bool HaveSameSoundsAs(const SoundsDefinition& right) const;
183 bool operator== (const SoundsDefinition& right) const;
184 bool operator!=(const SoundsDefinition& right) const;
186 short GetSoundCode(void) const {return mSoundCode;}
187 short GetBehaviorIndex(void) const {return mBehaviorIndex;}
189 bool IsNotRestartable(void) const {return mFlags & _sound_cannot_be_restarted;}
190 bool IsNotSelfAbortable(void) const {return mFlags & _sound_does_not_self_abort;}
191 bool IsPitchChangeResistant(void) const {return mFlags & _sound_resists_pitch_changes;}
192 bool IsNotPitchChangeable(void) const {return mFlags & _sound_cannot_change_pitch;}
193 bool IsNotObstructed(void) const {return mFlags & _sound_cannot_be_obstructed;}
194 bool IsNotMediaObstructed(void) const {return mFlags & _sound_cannot_be_media_obstructed;}
195 bool IsAmbient(void) const {return mFlags & _sound_is_ambient;}
197 short GetChance(void) const;
199 float GetLowPitch(void) const {return mLowPitch;}
200 float GetHighPitch(void) const {return mHighPitch;}
202 void SetSoundCode(short s) {mSoundCode = s;}
203 void SetBehaviorIndex(int i) {mBehaviorIndex = i;}
205 void SetNotRestartable(bool f) {mFlags |= _sound_cannot_be_restarted;}
206 void SetNotSelfAbortable(bool f) {mFlags |= _sound_does_not_self_abort;}
207 void SetPitchChangeResistant(bool b) {mFlags |= _sound_resists_pitch_changes;}
208 void SetNotPitchChangeable(bool b) {mFlags |= _sound_cannot_change_pitch;}
209 void SetNotObstructed(bool b) {mFlags |= _sound_cannot_be_obstructed;}
210 void SetNotMediaObstructed(bool b) {mFlags |= _sound_cannot_be_media_obstructed;}
211 void SetAmbient(bool b) {mFlags |= _sound_is_ambient;}
213 void SetChance(short i);
215 void SetLowPitch(int p) {mLowPitch = p;}
216 void SetHighPitch(int p) {mHighPitch = p;}
218 unsigned int GetPermutationCount(void) const {return mSounds.size();}
219 void DeletePermutation(unsigned int permutation_index);
220 AppleSoundHeader* GetPermutation(unsigned int permutation_index);
221 AppleSoundHeader* NewPermutation(wxString path);
224 unsigned int GetSizeInFile(void);
225 BigEndianBuffer& SaveObject(BigEndianBuffer& buffer, unsigned int& offset);
226 BigEndianBuffer& LoadObject(BigEndianBuffer& buffer);