2 ===========================================================================
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
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.
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.
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/>.
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.
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.
26 ===========================================================================
28 #include "../idlib/precompiled.h"
31 #include "snd_local.h"
38 idEFXFile::idEFXFile( void ) { }
45 void idEFXFile::Clear( void ) {
46 effects.DeleteContents( true );
54 idEFXFile::~idEFXFile( void ) {
63 bool idEFXFile::FindEffect( idStr &name, idSoundEffect **effect, int *index ) {
66 for ( i = 0; i < effects.Num(); i++ ) {
67 if ( ( effects[i] ) && ( effects[i]->name == name ) ) {
81 bool idEFXFile::ReadEffect( idLexer &src, idSoundEffect *effect ) {
84 if ( !src.ReadToken( &token ) )
88 if ( token == "reverb" ) {
89 EAXREVERBPROPERTIES *reverb = ( EAXREVERBPROPERTIES * )Mem_Alloc( sizeof( EAXREVERBPROPERTIES ) );
91 src.ReadTokenOnLine( &token );
94 if ( !src.ReadToken( &token ) ) {
100 src.Error( "idEFXFile::ReadEffect: { not found, found %s", token.c_str() );
106 if ( !src.ReadToken( &token ) ) {
107 src.Error( "idEFXFile::ReadEffect: EOF without closing brace" );
112 if ( token == "}" ) {
114 effect->data = ( void * )reverb;
115 effect->datasize = sizeof( EAXREVERBPROPERTIES );
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();
174 src.ReadTokenOnLine( &token );
175 src.Error( "idEFXFile::ReadEffect: Invalid parameter in reverb definition" );
183 // other effect (not supported at the moment)
184 src.Error( "idEFXFile::ReadEffect: Unknown effect definition" );
196 bool idEFXFile::LoadFile( const char *filename, bool OSPath ) {
197 idLexer src( LEXFL_NOSTRINGCONCAT );
200 src.LoadFile( filename, OSPath );
201 if ( !src.IsLoaded() ) {
205 if ( !src.ExpectTokenString( "Version" ) ) {
209 if ( src.ParseInt() != 1 ) {
210 src.Error( "idEFXFile::LoadFile: Unknown file version" );
214 while ( !src.EndOfFile() ) {
215 idSoundEffect *effect = new idSoundEffect;
216 if ( ReadEffect( src, effect ) ) {
217 effects.Append( effect );
227 idEFXFile::UnloadFile
230 void idEFXFile::UnloadFile( void ) {