snd_efxfile.cpp 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /*
  2. ===========================================================================
  3. Doom 3 GPL Source Code
  4. Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
  6. Doom 3 Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. 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.
  17. 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.
  18. ===========================================================================
  19. */
  20. #include "../idlib/precompiled.h"
  21. #pragma hdrstop
  22. #include "snd_local.h"
  23. /*
  24. ===============
  25. idEFXFile::idEFXFile
  26. ===============
  27. */
  28. idEFXFile::idEFXFile( void ) { }
  29. /*
  30. ===============
  31. idEFXFile::Clear
  32. ===============
  33. */
  34. void idEFXFile::Clear( void ) {
  35. effects.DeleteContents( true );
  36. }
  37. /*
  38. ===============
  39. idEFXFile::~idEFXFile
  40. ===============
  41. */
  42. idEFXFile::~idEFXFile( void ) {
  43. Clear();
  44. }
  45. /*
  46. ===============
  47. idEFXFile::FindEffect
  48. ===============
  49. */
  50. bool idEFXFile::FindEffect( idStr &name, idSoundEffect **effect, int *index ) {
  51. int i;
  52. for ( i = 0; i < effects.Num(); i++ ) {
  53. if ( ( effects[i] ) && ( effects[i]->name == name ) ) {
  54. *effect = effects[i];
  55. *index = i;
  56. return true;
  57. }
  58. }
  59. return false;
  60. }
  61. /*
  62. ===============
  63. idEFXFile::ReadEffect
  64. ===============
  65. */
  66. bool idEFXFile::ReadEffect( idLexer &src, idSoundEffect *effect ) {
  67. idToken name, token;
  68. if ( !src.ReadToken( &token ) )
  69. return false;
  70. // reverb effect
  71. if ( token == "reverb" ) {
  72. EAXREVERBPROPERTIES *reverb = ( EAXREVERBPROPERTIES * )Mem_Alloc( sizeof( EAXREVERBPROPERTIES ) );
  73. if ( reverb ) {
  74. src.ReadTokenOnLine( &token );
  75. name = token;
  76. if ( !src.ReadToken( &token ) ) {
  77. Mem_Free( reverb );
  78. return false;
  79. }
  80. if ( token != "{" ) {
  81. src.Error( "idEFXFile::ReadEffect: { not found, found %s", token.c_str() );
  82. Mem_Free( reverb );
  83. return false;
  84. }
  85. do {
  86. if ( !src.ReadToken( &token ) ) {
  87. src.Error( "idEFXFile::ReadEffect: EOF without closing brace" );
  88. Mem_Free( reverb );
  89. return false;
  90. }
  91. if ( token == "}" ) {
  92. effect->name = name;
  93. effect->data = ( void * )reverb;
  94. effect->datasize = sizeof( EAXREVERBPROPERTIES );
  95. break;
  96. }
  97. if ( token == "environment" ) {
  98. src.ReadTokenOnLine( &token );
  99. reverb->ulEnvironment = token.GetUnsignedLongValue();
  100. } else if ( token == "environment size" ) {
  101. reverb->flEnvironmentSize = src.ParseFloat();
  102. } else if ( token == "environment diffusion" ) {
  103. reverb->flEnvironmentDiffusion = src.ParseFloat();
  104. } else if ( token == "room" ) {
  105. reverb->lRoom = src.ParseInt();
  106. } else if ( token == "room hf" ) {
  107. reverb->lRoomHF = src.ParseInt();
  108. } else if ( token == "room lf" ) {
  109. reverb->lRoomLF = src.ParseInt();
  110. } else if ( token == "decay time" ) {
  111. reverb->flDecayTime = src.ParseFloat();
  112. } else if ( token == "decay hf ratio" ) {
  113. reverb->flDecayHFRatio = src.ParseFloat();
  114. } else if ( token == "decay lf ratio" ) {
  115. reverb->flDecayLFRatio = src.ParseFloat();
  116. } else if ( token == "reflections" ) {
  117. reverb->lReflections = src.ParseInt();
  118. } else if ( token == "reflections delay" ) {
  119. reverb->flReflectionsDelay = src.ParseFloat();
  120. } else if ( token == "reflections pan" ) {
  121. reverb->vReflectionsPan.x = src.ParseFloat();
  122. reverb->vReflectionsPan.y = src.ParseFloat();
  123. reverb->vReflectionsPan.z = src.ParseFloat();
  124. } else if ( token == "reverb" ) {
  125. reverb->lReverb = src.ParseInt();
  126. } else if ( token == "reverb delay" ) {
  127. reverb->flReverbDelay = src.ParseFloat();
  128. } else if ( token == "reverb pan" ) {
  129. reverb->vReverbPan.x = src.ParseFloat();
  130. reverb->vReverbPan.y = src.ParseFloat();
  131. reverb->vReverbPan.z = src.ParseFloat();
  132. } else if ( token == "echo time" ) {
  133. reverb->flEchoTime = src.ParseFloat();
  134. } else if ( token == "echo depth" ) {
  135. reverb->flEchoDepth = src.ParseFloat();
  136. } else if ( token == "modulation time" ) {
  137. reverb->flModulationTime = src.ParseFloat();
  138. } else if ( token == "modulation depth" ) {
  139. reverb->flModulationDepth = src.ParseFloat();
  140. } else if ( token == "air absorption hf" ) {
  141. reverb->flAirAbsorptionHF = src.ParseFloat();
  142. } else if ( token == "hf reference" ) {
  143. reverb->flHFReference = src.ParseFloat();
  144. } else if ( token == "lf reference" ) {
  145. reverb->flLFReference = src.ParseFloat();
  146. } else if ( token == "room rolloff factor" ) {
  147. reverb->flRoomRolloffFactor = src.ParseFloat();
  148. } else if ( token == "flags" ) {
  149. src.ReadTokenOnLine( &token );
  150. reverb->ulFlags = token.GetUnsignedLongValue();
  151. } else {
  152. src.ReadTokenOnLine( &token );
  153. src.Error( "idEFXFile::ReadEffect: Invalid parameter in reverb definition" );
  154. Mem_Free( reverb );
  155. }
  156. } while ( 1 );
  157. return true;
  158. }
  159. } else {
  160. // other effect (not supported at the moment)
  161. src.Error( "idEFXFile::ReadEffect: Unknown effect definition" );
  162. }
  163. return false;
  164. }
  165. /*
  166. ===============
  167. idEFXFile::LoadFile
  168. ===============
  169. */
  170. bool idEFXFile::LoadFile( const char *filename, bool OSPath ) {
  171. idLexer src( LEXFL_NOSTRINGCONCAT );
  172. idToken token;
  173. src.LoadFile( filename, OSPath );
  174. if ( !src.IsLoaded() ) {
  175. return false;
  176. }
  177. if ( !src.ExpectTokenString( "Version" ) ) {
  178. return NULL;
  179. }
  180. if ( src.ParseInt() != 1 ) {
  181. src.Error( "idEFXFile::LoadFile: Unknown file version" );
  182. return false;
  183. }
  184. while ( !src.EndOfFile() ) {
  185. idSoundEffect *effect = new idSoundEffect;
  186. if ( ReadEffect( src, effect ) ) {
  187. effects.Append( effect );
  188. }
  189. };
  190. return true;
  191. }
  192. /*
  193. ===============
  194. idEFXFile::UnloadFile
  195. ===============
  196. */
  197. void idEFXFile::UnloadFile( void ) {
  198. Clear();
  199. }