doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
snd_efxfile.cpp
Go to the documentation of this file.
1 /*
2 ===========================================================================
3 
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
8 
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
21 
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
23 
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
25 
26 ===========================================================================
27 */
28 #include "../idlib/precompiled.h"
29 #pragma hdrstop
30 
31 #include "snd_local.h"
32 
33 /*
34 ===============
35 idEFXFile::idEFXFile
36 ===============
37 */
39 
40 /*
41 ===============
42 idEFXFile::Clear
43 ===============
44 */
45 void idEFXFile::Clear( void ) {
46  effects.DeleteContents( true );
47 }
48 
49 /*
50 ===============
51 idEFXFile::~idEFXFile
52 ===============
53 */
55  Clear();
56 }
57 
58 /*
59 ===============
60 idEFXFile::FindEffect
61 ===============
62 */
64  int i;
65 
66  for ( i = 0; i < effects.Num(); i++ ) {
67  if ( ( effects[i] ) && ( effects[i]->name == name ) ) {
68  *effect = effects[i];
69  *index = i;
70  return true;
71  }
72  }
73  return false;
74 }
75 
76 /*
77 ===============
78 idEFXFile::ReadEffect
79 ===============
80 */
82  idToken name, token;
83 
84  if ( !src.ReadToken( &token ) )
85  return false;
86 
87  // reverb effect
88  if ( token == "reverb" ) {
90  if ( reverb ) {
91  src.ReadTokenOnLine( &token );
92  name = token;
93 
94  if ( !src.ReadToken( &token ) ) {
95  Mem_Free( reverb );
96  return false;
97  }
98 
99  if ( token != "{" ) {
100  src.Error( "idEFXFile::ReadEffect: { not found, found %s", token.c_str() );
101  Mem_Free( reverb );
102  return false;
103  }
104 
105  do {
106  if ( !src.ReadToken( &token ) ) {
107  src.Error( "idEFXFile::ReadEffect: EOF without closing brace" );
108  Mem_Free( reverb );
109  return false;
110  }
111 
112  if ( token == "}" ) {
113  effect->name = name;
114  effect->data = ( void * )reverb;
115  effect->datasize = sizeof( EAXREVERBPROPERTIES );
116  break;
117  }
118 
119  if ( token == "environment" ) {
120  src.ReadTokenOnLine( &token );
121  reverb->ulEnvironment = token.GetUnsignedLongValue();
122  } else if ( token == "environment size" ) {
123  reverb->flEnvironmentSize = src.ParseFloat();
124  } else if ( token == "environment diffusion" ) {
125  reverb->flEnvironmentDiffusion = src.ParseFloat();
126  } else if ( token == "room" ) {
127  reverb->lRoom = src.ParseInt();
128  } else if ( token == "room hf" ) {
129  reverb->lRoomHF = src.ParseInt();
130  } else if ( token == "room lf" ) {
131  reverb->lRoomLF = src.ParseInt();
132  } else if ( token == "decay time" ) {
133  reverb->flDecayTime = src.ParseFloat();
134  } else if ( token == "decay hf ratio" ) {
135  reverb->flDecayHFRatio = src.ParseFloat();
136  } else if ( token == "decay lf ratio" ) {
137  reverb->flDecayLFRatio = src.ParseFloat();
138  } else if ( token == "reflections" ) {
139  reverb->lReflections = src.ParseInt();
140  } else if ( token == "reflections delay" ) {
141  reverb->flReflectionsDelay = src.ParseFloat();
142  } else if ( token == "reflections pan" ) {
143  reverb->vReflectionsPan.x = src.ParseFloat();
144  reverb->vReflectionsPan.y = src.ParseFloat();
145  reverb->vReflectionsPan.z = src.ParseFloat();
146  } else if ( token == "reverb" ) {
147  reverb->lReverb = src.ParseInt();
148  } else if ( token == "reverb delay" ) {
149  reverb->flReverbDelay = src.ParseFloat();
150  } else if ( token == "reverb pan" ) {
151  reverb->vReverbPan.x = src.ParseFloat();
152  reverb->vReverbPan.y = src.ParseFloat();
153  reverb->vReverbPan.z = src.ParseFloat();
154  } else if ( token == "echo time" ) {
155  reverb->flEchoTime = src.ParseFloat();
156  } else if ( token == "echo depth" ) {
157  reverb->flEchoDepth = src.ParseFloat();
158  } else if ( token == "modulation time" ) {
159  reverb->flModulationTime = src.ParseFloat();
160  } else if ( token == "modulation depth" ) {
161  reverb->flModulationDepth = src.ParseFloat();
162  } else if ( token == "air absorption hf" ) {
163  reverb->flAirAbsorptionHF = src.ParseFloat();
164  } else if ( token == "hf reference" ) {
165  reverb->flHFReference = src.ParseFloat();
166  } else if ( token == "lf reference" ) {
167  reverb->flLFReference = src.ParseFloat();
168  } else if ( token == "room rolloff factor" ) {
169  reverb->flRoomRolloffFactor = src.ParseFloat();
170  } else if ( token == "flags" ) {
171  src.ReadTokenOnLine( &token );
172  reverb->ulFlags = token.GetUnsignedLongValue();
173  } else {
174  src.ReadTokenOnLine( &token );
175  src.Error( "idEFXFile::ReadEffect: Invalid parameter in reverb definition" );
176  Mem_Free( reverb );
177  }
178  } while ( 1 );
179 
180  return true;
181  }
182  } else {
183  // other effect (not supported at the moment)
184  src.Error( "idEFXFile::ReadEffect: Unknown effect definition" );
185  }
186 
187  return false;
188 }
189 
190 
191 /*
192 ===============
193 idEFXFile::LoadFile
194 ===============
195 */
196 bool idEFXFile::LoadFile( const char *filename, bool OSPath ) {
198  idToken token;
199 
200  src.LoadFile( filename, OSPath );
201  if ( !src.IsLoaded() ) {
202  return false;
203  }
204 
205  if ( !src.ExpectTokenString( "Version" ) ) {
206  return NULL;
207  }
208 
209  if ( src.ParseInt() != 1 ) {
210  src.Error( "idEFXFile::LoadFile: Unknown file version" );
211  return false;
212  }
213 
214  while ( !src.EndOfFile() ) {
215  idSoundEffect *effect = new idSoundEffect;
216  if ( ReadEffect( src, effect ) ) {
217  effects.Append( effect );
218  }
219  };
220 
221  return true;
222 }
223 
224 
225 /*
226 ===============
227 idEFXFile::UnloadFile
228 ===============
229 */
230 void idEFXFile::UnloadFile( void ) {
231  Clear();
232 }
float flModulationTime
Definition: eax4.h:728
float z
Definition: eax3.h:136
unsigned long ulFlags
Definition: eax4.h:734
float flEchoDepth
Definition: eax4.h:727
idStr name
Definition: efxlib.h:26
float flModulationDepth
Definition: eax4.h:729
unsigned long GetUnsignedLongValue(void)
Definition: Token.h:142
float flEnvironmentDiffusion
Definition: eax4.h:713
void UnloadFile(void)
Definition: Token.h:71
float ParseFloat(bool *errorFlag=NULL)
Definition: Lexer.cpp:1264
GLuint src
Definition: glext.h:5390
float flEnvironmentSize
Definition: eax4.h:712
int ReadTokenOnLine(idToken *token)
Definition: Lexer.cpp:1172
float flAirAbsorptionHF
Definition: eax4.h:730
int i
Definition: process.py:33
unsigned long ulEnvironment
Definition: eax4.h:711
int ParseInt(void)
Definition: Lexer.cpp:1227
EAXVECTOR vReflectionsPan
Definition: eax4.h:722
Definition: Lexer.h:137
void Error(const char *str,...) id_attribute((format(printf
Definition: Lexer.cpp:215
bool LoadFile(const char *filename, bool OSPath=false)
GLuint index
Definition: glext.h:3476
float flDecayTime
Definition: eax4.h:717
EAXVECTOR vReverbPan
Definition: eax4.h:725
float flDecayHFRatio
Definition: eax4.h:718
#define NULL
Definition: Lib.h:88
float flEchoTime
Definition: eax4.h:726
float flRoomRolloffFactor
Definition: eax4.h:733
void DeleteContents(bool clear)
Definition: List.h:207
void Mem_Free(void *ptr)
Definition: Heap.cpp:1087
float flHFReference
Definition: eax4.h:731
float flDecayLFRatio
Definition: eax4.h:719
int datasize
Definition: efxlib.h:27
int EndOfFile(void)
Definition: Lexer.cpp:1573
float x
Definition: eax3.h:134
int ExpectTokenString(const char *string)
Definition: Lexer.cpp:919
int Append(const type &obj)
Definition: List.h:646
int Num(void) const
Definition: List.h:265
const GLcharARB * name
Definition: glext.h:3629
float flReverbDelay
Definition: eax4.h:724
Definition: Str.h:116
float y
Definition: eax3.h:135
bool ReadEffect(idLexer &lexer, idSoundEffect *effect)
Definition: snd_efxfile.cpp:81
float flLFReference
Definition: eax4.h:732
const char * c_str(void) const
Definition: Str.h:487
void * Mem_Alloc(const int size)
Definition: Heap.cpp:1067
int IsLoaded(void)
Definition: Lexer.h:158
float flReflectionsDelay
Definition: eax4.h:721
idList< idSoundEffect * > effects
Definition: efxlib.h:53
int ReadToken(idToken *token)
Definition: Lexer.cpp:820
void * data
Definition: efxlib.h:28
struct _EAXREVERBPROPERTIES EAXREVERBPROPERTIES
bool FindEffect(idStr &name, idSoundEffect **effect, int *index)
Definition: snd_efxfile.cpp:63
void Clear(void)
Definition: snd_efxfile.cpp:45
int LoadFile(const char *filename, bool OSPath=false)
Definition: Lexer.cpp:1591