INIAudioEventInfo.cpp 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /*
  2. ** Command & Conquer Generals Zero Hour(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program 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. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. ////////////////////////////////////////////////////////////////////////////////
  19. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // FILE: INIAudioEventInfo.cpp ////////////////////////////////////////////////////////////////////////
  24. // Author: Colin Day, July 2002
  25. // Desc: Parsing AudioEvent, MusicTrack and DialogEvent INI entries
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  28. #include "Common/INI.h"
  29. #include "Common/GameAudio.h"
  30. #include "Common/AudioEventInfo.h"
  31. AudioEventInfo::~AudioEventInfo()
  32. {
  33. }
  34. // @todo: Get these functions unified.
  35. //-------------------------------------------------------------------------------------------------
  36. void INI::parseMusicTrackDefinition( INI* ini )
  37. {
  38. AsciiString name;
  39. AudioEventInfo *track;
  40. // read the name
  41. const char* c = ini->getNextToken();
  42. name.set( c );
  43. track = TheAudio->newAudioEventInfo( name );
  44. if (!track) {
  45. return;
  46. }
  47. AudioEventInfo *defaultInfo = TheAudio->findAudioEventInfo("DefaultMusicTrack");
  48. if (defaultInfo) {
  49. (*track) = (*defaultInfo);
  50. TheAudio->addTrackName( name );
  51. }
  52. track->m_audioName = name;
  53. track->m_soundType = AT_Music;
  54. // parse the ini definition
  55. ini->initFromINI( track, track->getFieldParse() );
  56. } // end parseMusicTrackDefinition
  57. //-------------------------------------------------------------------------------------------------
  58. void INI::parseAudioEventDefinition( INI* ini )
  59. {
  60. AsciiString name;
  61. AudioEventInfo *track;
  62. // read the name
  63. const char* c = ini->getNextToken();
  64. name.set( c );
  65. track = TheAudio->newAudioEventInfo( name );
  66. if (!track) {
  67. return;
  68. }
  69. AudioEventInfo *defaultInfo = TheAudio->findAudioEventInfo("DefaultSoundEffect");
  70. if (defaultInfo) {
  71. (*track) = (*defaultInfo);
  72. }
  73. track->m_audioName = name;
  74. track->m_soundType = AT_SoundEffect;
  75. // parse the ini definition
  76. ini->initFromINI( track, track->getFieldParse() );
  77. } // end parseAudioEventDefinition
  78. //-------------------------------------------------------------------------------------------------
  79. void INI::parseDialogDefinition( INI* ini )
  80. {
  81. AsciiString name;
  82. AudioEventInfo *track;
  83. // read the name
  84. const char* c = ini->getNextToken();
  85. name.set( c );
  86. track = TheAudio->newAudioEventInfo( name );
  87. if (!track) {
  88. return;
  89. }
  90. AudioEventInfo *defaultInfo = TheAudio->findAudioEventInfo("DefaultDialog");
  91. if (defaultInfo) {
  92. (*track) = (*defaultInfo);
  93. }
  94. track->m_audioName = name;
  95. track->m_soundType = AT_Streaming;
  96. // parse the ini definition
  97. ini->initFromINI( track, track->getFieldParse() );
  98. } // end parseAudioEventDefinition
  99. //-------------------------------------------------------------------------------------------------
  100. static void parseDelay( INI* ini, void *instance, void *store, const void* /*userData*/ );
  101. static void parsePitchShift( INI* ini, void *instance, void *store, const void* /*userData*/ );
  102. //-------------------------------------------------------------------------------------------------
  103. const FieldParse AudioEventInfo::m_audioEventInfo[] =
  104. {
  105. { "Filename", INI::parseAsciiString, NULL, offsetof( AudioEventInfo, m_filename) },
  106. { "Volume", INI::parsePercentToReal, NULL, offsetof( AudioEventInfo, m_volume ) },
  107. { "VolumeShift", INI::parsePercentToReal, NULL, offsetof( AudioEventInfo, m_volumeShift ) },
  108. { "MinVolume", INI::parsePercentToReal, NULL, offsetof( AudioEventInfo, m_minVolume ) },
  109. { "PitchShift", parsePitchShift, NULL, 0 },
  110. { "Delay", parseDelay, NULL, 0 },
  111. { "Limit", INI::parseInt, NULL, offsetof( AudioEventInfo, m_limit ) },
  112. { "LoopCount", INI::parseInt, NULL, offsetof( AudioEventInfo, m_loopCount ) },
  113. { "Priority", INI::parseIndexList, theAudioPriorityNames, offsetof( AudioEventInfo, m_priority ) },
  114. { "Type", INI::parseBitString32, theSoundTypeNames, offsetof( AudioEventInfo, m_type ) },
  115. { "Control", INI::parseBitString32, theAudioControlNames, offsetof( AudioEventInfo, m_control ) },
  116. { "Sounds", INI::parseSoundsList, NULL, offsetof( AudioEventInfo, m_sounds ) },
  117. { "SoundsNight", INI::parseSoundsList, NULL, offsetof( AudioEventInfo, m_soundsNight ) },
  118. { "SoundsEvening", INI::parseSoundsList, NULL, offsetof( AudioEventInfo, m_soundsEvening ) },
  119. { "SoundsMorning", INI::parseSoundsList, NULL, offsetof( AudioEventInfo, m_soundsMorning ) },
  120. { "Attack", INI::parseSoundsList, NULL, offsetof( AudioEventInfo, m_attackSounds ) },
  121. { "Decay", INI::parseSoundsList, NULL, offsetof( AudioEventInfo, m_decaySounds ) },
  122. { "MinRange", INI::parseReal, NULL, offsetof( AudioEventInfo, m_minDistance) },
  123. { "MaxRange", INI::parseReal, NULL, offsetof( AudioEventInfo, m_maxDistance) },
  124. { "LowPassCutoff", INI::parsePercentToReal, NULL, offsetof( AudioEventInfo, m_lowPassFreq) },
  125. };
  126. //-------------------------------------------------------------------------------------------------
  127. static void parseDelay( INI* ini, void *instance, void *store, const void* /*userData*/ )
  128. {
  129. AudioEventInfo *attribs = (AudioEventInfo*) store;
  130. Int min = ini->scanInt(ini->getNextToken());
  131. Int max = ini->scanInt(ini->getNextToken());
  132. DEBUG_ASSERTCRASH( min >= 0 && max >= min, ("Bad delay values for audio event %s", attribs->m_audioName.str()));
  133. attribs->m_delayMax = max;
  134. attribs->m_delayMin = min;
  135. }
  136. //-------------------------------------------------------------------------------------------------
  137. static void parsePitchShift( INI* ini, void *instance, void *store, const void* /*userData*/ )
  138. {
  139. AudioEventInfo *attribs = (AudioEventInfo*) store;
  140. Real min = ini->scanReal(ini->getNextToken());
  141. Real max = ini->scanReal(ini->getNextToken());
  142. DEBUG_ASSERTCRASH( min > -100 && max >= min, ("Bad pitch shift values for audio event %s", attribs->m_audioName.str()));
  143. attribs->m_pitchShiftMin = 1.0f + min/100;
  144. attribs->m_pitchShiftMax = 1.0f + max/100;
  145. }
  146. // STATIC DEFINIITIONS ////////////////////////////////////////////////////////////////////////////
  147. char *theAudioPriorityNames[] =
  148. {
  149. "LOWEST",
  150. "LOW",
  151. "NORMAL",
  152. "HIGH",
  153. "CRITICAL",
  154. NULL
  155. };
  156. char *theSoundTypeNames[] =
  157. {
  158. "UI",
  159. "WORLD",
  160. "SHROUDED",
  161. "GLOBAL",
  162. "VOICE",
  163. "PLAYER",
  164. "ALLIES",
  165. "ENEMIES",
  166. "EVERYONE",
  167. NULL
  168. };
  169. char *theAudioControlNames[] =
  170. {
  171. "LOOP",
  172. "RANDOM",
  173. "ALL",
  174. "POSTDELAY",
  175. "INTERRUPT",
  176. NULL
  177. };