dlgconfigaudiotab.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766
  1. /*
  2. ** Command & Conquer Renegade(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. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : commando *
  23. * *
  24. * $Archive:: /Commando/Code/Commando/dlgconfigaudiotab.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 1/25/02 7:12p $*
  29. * *
  30. * $Revision:: 11 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "dlgconfigaudiotab.h"
  36. #include "resource.h"
  37. #include "sliderctrl.h"
  38. #include "wwaudio.h"
  39. #include "comboboxctrl.h"
  40. #include "listctrl.h"
  41. #include "_globals.h"
  42. #include "string_ids.h"
  43. #include "translatedb.h"
  44. #include "audiblesound.h"
  45. #include "dialogmgr.h"
  46. ////////////////////////////////////////////////////////////////
  47. //
  48. // DlgConfigAudioTabClass
  49. //
  50. ////////////////////////////////////////////////////////////////
  51. DlgConfigAudioTabClass::DlgConfigAudioTabClass (void) :
  52. InitialDeviceIndex (0),
  53. InitialIsStereo (true),
  54. InitialHertz (44100),
  55. InitialBits (16),
  56. SoundVolumeTestSound (NULL),
  57. MusicVolumeTestSound (NULL),
  58. DialogVolumeTestSound (NULL),
  59. CinematicVolumeTestSound (NULL),
  60. SoundVolumeTestSoundStartTime (0),
  61. MusicVolumeTestSoundStartTime (0),
  62. DialogVolumeTestSoundStartTime (0),
  63. CinematicVolumeTestSoundStartTime (0),
  64. ChildDialogClass (IDD_CONFIG_AUDIO)
  65. {
  66. SoundVolumeTestSound = WWAudioClass::Get_Instance ()->Create_Sound_Effect ("laser_rifle_fire_01.wav");
  67. if (SoundVolumeTestSound != NULL) {
  68. SoundVolumeTestSound->Set_Loop_Count (0);
  69. SoundVolumeTestSound->Set_Type (AudibleSoundClass::TYPE_SOUND_EFFECT);
  70. }
  71. MusicVolumeTestSound = WWAudioClass::Get_Instance ()->Create_Sound_Effect ("sakura battle theme.mp3");
  72. if (MusicVolumeTestSound != NULL) {
  73. MusicVolumeTestSound->Set_Type (AudibleSoundClass::TYPE_MUSIC);
  74. }
  75. DialogVolumeTestSound = WWAudioClass::Get_Instance ()->Create_Sound_Effect ("m00s1_s1s1gbmg_snd.wav");
  76. if (DialogVolumeTestSound != NULL) {
  77. DialogVolumeTestSound->Set_Loop_Count (0);
  78. DialogVolumeTestSound->Set_Type (AudibleSoundClass::TYPE_DIALOG);
  79. }
  80. CinematicVolumeTestSound = WWAudioClass::Get_Instance ()->Create_Sound_Effect ("00-n000e.wav");
  81. if (CinematicVolumeTestSound != NULL) {
  82. CinematicVolumeTestSound->Set_Loop_Count (0);
  83. CinematicVolumeTestSound->Set_Type (AudibleSoundClass::TYPE_CINEMATIC);
  84. }
  85. return ;
  86. }
  87. ////////////////////////////////////////////////////////////////
  88. //
  89. // ~DlgConfigAudioTabClass
  90. //
  91. ////////////////////////////////////////////////////////////////
  92. DlgConfigAudioTabClass::~DlgConfigAudioTabClass (void)
  93. {
  94. if (SoundVolumeTestSound != NULL) {
  95. SoundVolumeTestSound->Stop ();
  96. REF_PTR_RELEASE (SoundVolumeTestSound);
  97. }
  98. if (MusicVolumeTestSound != NULL) {
  99. MusicVolumeTestSound->Stop ();
  100. REF_PTR_RELEASE (MusicVolumeTestSound);
  101. }
  102. if (DialogVolumeTestSound != NULL) {
  103. DialogVolumeTestSound->Stop ();
  104. REF_PTR_RELEASE (DialogVolumeTestSound);
  105. }
  106. if (CinematicVolumeTestSound != NULL) {
  107. CinematicVolumeTestSound->Stop ();
  108. REF_PTR_RELEASE (CinematicVolumeTestSound);
  109. }
  110. return ;
  111. }
  112. ////////////////////////////////////////////////////////////////
  113. //
  114. // On_Init_Dialog
  115. //
  116. ////////////////////////////////////////////////////////////////
  117. void
  118. DlgConfigAudioTabClass::On_Init_Dialog (void)
  119. {
  120. ChildDialogClass::On_Init_Dialog ();
  121. //
  122. // Read the audio library's settings from the registry
  123. //
  124. bool is_stereo = WWAudioClass::Get_Instance ()->Get_Playback_Stereo ();
  125. float sound_vol = WWAudioClass::Get_Instance ()->Get_Sound_Effects_Volume ();
  126. float music_vol = WWAudioClass::Get_Instance ()->Get_Music_Volume ();
  127. float dialog_vol = WWAudioClass::Get_Instance ()->Get_Dialog_Volume ();
  128. float cinematic_vol = WWAudioClass::Get_Instance ()->Get_Cinematic_Volume ();
  129. bool sound_on = WWAudioClass::Get_Instance ()->Are_Sound_Effects_On ();
  130. bool music_on = WWAudioClass::Get_Instance ()->Is_Music_On ();
  131. bool dialog_on = WWAudioClass::Get_Instance ()->Is_Dialog_On ();
  132. bool cinematic_on = WWAudioClass::Get_Instance ()->Is_Cinematic_Sound_On ();
  133. SliderCtrlClass *snd_vol_slider = (SliderCtrlClass *)Get_Dlg_Item (IDC_SOUND_EFFECTS_SLIDER);
  134. SliderCtrlClass *mus_vol_slider = (SliderCtrlClass *)Get_Dlg_Item (IDC_MUSIC_SLIDER);
  135. SliderCtrlClass *dia_vol_slider = (SliderCtrlClass *)Get_Dlg_Item (IDC_DIALOG_SLIDER);
  136. SliderCtrlClass *cin_vol_slider = (SliderCtrlClass *)Get_Dlg_Item (IDC_CINEMATIC_SLIDER);
  137. //
  138. // Setup the sound volume controls
  139. //
  140. Check_Dlg_Button (IDC_SOUND_EFFECTS_CHECK, sound_on);
  141. if (snd_vol_slider != NULL) {
  142. snd_vol_slider->Set_Range (0, 100);
  143. snd_vol_slider->Set_Pos (static_cast<int>(sound_vol * 100), false);
  144. }
  145. //
  146. // Setup the music volume controls
  147. //
  148. Check_Dlg_Button (IDC_MUSIC_CHECK, music_on);
  149. if (mus_vol_slider != NULL) {
  150. mus_vol_slider->Set_Range (0, 100);
  151. mus_vol_slider->Set_Pos (static_cast<int>(music_vol * 100), false);
  152. }
  153. //
  154. // Setup the dialog volume controls
  155. //
  156. Check_Dlg_Button (IDC_DIALOG_CHECK, dialog_on);
  157. if (dia_vol_slider != NULL) {
  158. dia_vol_slider->Set_Range (0, 100);
  159. dia_vol_slider->Set_Pos (static_cast<int>(dialog_vol * 100), false);
  160. }
  161. //
  162. // Setup the dialog volume controls
  163. //
  164. Check_Dlg_Button (IDC_CINEMATIC_CHECK, cinematic_on);
  165. if (cin_vol_slider != NULL) {
  166. cin_vol_slider->Set_Range (0, 100);
  167. cin_vol_slider->Set_Pos (static_cast<int>(cinematic_vol * 100), false);
  168. }
  169. //
  170. // Check the stereo box if necessary
  171. //
  172. Check_Dlg_Button (IDC_STEREO_CHECK, is_stereo);
  173. InitialIsStereo = is_stereo;
  174. //
  175. // Configure the comboboxes and list control
  176. //
  177. Configure_Quality_Combobox ();
  178. Configure_Rate_Combobox ();
  179. Configure_Speaker_Combobox ();
  180. Configure_Driver_List ();
  181. //
  182. // Update the enabled state of the volume sliders
  183. //
  184. Update_Slider_Enable_State ();
  185. return ;
  186. }
  187. /////////////////////////////////////////////////////////////////////////////
  188. //
  189. // Update_Slider_Enable_State
  190. //
  191. /////////////////////////////////////////////////////////////////////////////
  192. void
  193. DlgConfigAudioTabClass::Update_Slider_Enable_State (void)
  194. {
  195. bool sound_enabled = Is_Dlg_Button_Checked (IDC_SOUND_EFFECTS_CHECK);
  196. bool music_enabled = Is_Dlg_Button_Checked (IDC_MUSIC_CHECK);
  197. bool dialog_enabled = Is_Dlg_Button_Checked (IDC_DIALOG_CHECK);
  198. bool cinematic_enabled = Is_Dlg_Button_Checked (IDC_CINEMATIC_CHECK);
  199. //
  200. // Enable the slider's based on the state of the check boxes
  201. //
  202. Enable_Dlg_Item (IDC_SOUND_EFFECTS_SLIDER, sound_enabled);
  203. Enable_Dlg_Item (IDC_MUSIC_SLIDER, music_enabled);
  204. Enable_Dlg_Item (IDC_DIALOG_SLIDER, dialog_enabled);
  205. Enable_Dlg_Item (IDC_CINEMATIC_SLIDER, cinematic_enabled);
  206. //
  207. // Update the audio itself
  208. //
  209. WWAudioClass::Get_Instance ()->Allow_Sound_Effects (sound_enabled);
  210. WWAudioClass::Get_Instance ()->Allow_Music (music_enabled);
  211. WWAudioClass::Get_Instance ()->Allow_Dialog (dialog_enabled);
  212. WWAudioClass::Get_Instance ()->Allow_Cinematic_Sound (cinematic_enabled);
  213. return ;
  214. }
  215. //////////////////////////////////////////////////////////////////////
  216. //
  217. // Configure_Rate_Combobox
  218. //
  219. //////////////////////////////////////////////////////////////////////
  220. void
  221. DlgConfigAudioTabClass::Configure_Rate_Combobox (void)
  222. {
  223. ComboBoxCtrlClass *combo_box = (ComboBoxCtrlClass *)Get_Dlg_Item (IDC_RATE_COMBO);
  224. if (combo_box == NULL) {
  225. return ;
  226. }
  227. //
  228. // Add an entry for each locale to the combobox
  229. //
  230. combo_box->Add_String (TRANSLATE (IDS_SND_RATE_11));
  231. combo_box->Add_String (TRANSLATE (IDS_SND_RATE_22));
  232. combo_box->Add_String (TRANSLATE (IDS_SND_RATE_44));
  233. InitialHertz = WWAudioClass::Get_Instance ()->Get_Playback_Rate ();
  234. switch (InitialHertz)
  235. {
  236. case 11025:
  237. combo_box->Set_Curr_Sel (0);
  238. break;
  239. case 22050:
  240. combo_box->Set_Curr_Sel (1);
  241. break;
  242. default:
  243. case 44100:
  244. combo_box->Set_Curr_Sel (2);
  245. break;
  246. }
  247. return ;
  248. }
  249. //////////////////////////////////////////////////////////////////////
  250. //
  251. // Configure_Speaker_Combobox
  252. //
  253. //////////////////////////////////////////////////////////////////////
  254. void
  255. DlgConfigAudioTabClass::Configure_Speaker_Combobox (void)
  256. {
  257. ComboBoxCtrlClass *combo_box = (ComboBoxCtrlClass *)Get_Dlg_Item (IDC_SPEAKER_SETUP_COMBO);
  258. if (combo_box == NULL) {
  259. return ;
  260. }
  261. //
  262. // Add an entry for each speaker type to the combobox
  263. //
  264. combo_box->Add_String (TRANSLATE (IDS_MENU_SPEAKER_2));
  265. combo_box->Add_String (TRANSLATE (IDS_MENU_SPEAKER_HEADPHONE));
  266. combo_box->Add_String (TRANSLATE (IDS_MENU_SPEAKER_SURROUND));
  267. combo_box->Add_String (TRANSLATE (IDS_MENU_SPEAKER_4));
  268. //
  269. // Select the current setting
  270. //
  271. int type = WWAudioClass::Get_Instance ()->Get_Speaker_Type ();
  272. switch (type)
  273. {
  274. default:
  275. case AIL_3D_2_SPEAKER:
  276. combo_box->Set_Curr_Sel (0);
  277. break;
  278. case AIL_3D_HEADPHONE:
  279. combo_box->Set_Curr_Sel (1);
  280. break;
  281. case AIL_3D_SURROUND:
  282. combo_box->Set_Curr_Sel (2);
  283. break;
  284. case AIL_3D_4_SPEAKER:
  285. combo_box->Set_Curr_Sel (3);
  286. break;
  287. }
  288. return ;
  289. }
  290. //////////////////////////////////////////////////////////////////////
  291. //
  292. // Configure_Quality_Combobox
  293. //
  294. //////////////////////////////////////////////////////////////////////
  295. void
  296. DlgConfigAudioTabClass::Configure_Quality_Combobox (void)
  297. {
  298. ComboBoxCtrlClass *combo_box = (ComboBoxCtrlClass *)Get_Dlg_Item (IDC_QUALITY_COMBO);
  299. if (combo_box == NULL) {
  300. return ;
  301. }
  302. //
  303. // Add an entry for each locale to the combobox
  304. //
  305. combo_box->Add_String (TRANSLATE (IDS_SND_8_BIT));
  306. combo_box->Add_String (TRANSLATE (IDS_SND_16_BIT));
  307. InitialBits = WWAudioClass::Get_Instance ()->Get_Playback_Bits ();
  308. //
  309. // Select the appropriate quality combobox entry
  310. //
  311. switch (InitialBits)
  312. {
  313. case 8:
  314. combo_box->Set_Curr_Sel (0);
  315. break;
  316. default:
  317. case 16:
  318. combo_box->Set_Curr_Sel (1);
  319. break;
  320. }
  321. return ;
  322. }
  323. //////////////////////////////////////////////////////////////////////
  324. //
  325. // On_Command
  326. //
  327. //////////////////////////////////////////////////////////////////////
  328. void
  329. DlgConfigAudioTabClass::On_Command (int ctrl_id, int message_id, DWORD param)
  330. {
  331. switch (ctrl_id)
  332. {
  333. case IDC_SOUND_EFFECTS_CHECK:
  334. case IDC_MUSIC_CHECK:
  335. case IDC_DIALOG_CHECK:
  336. case IDC_CINEMATIC_CHECK:
  337. Update_Slider_Enable_State ();
  338. break;
  339. case IDC_DEFAULTS_BUTTON:
  340. Set_Default_Volumes ();
  341. break;
  342. }
  343. ChildDialogClass::On_Command (ctrl_id, message_id, param);
  344. return ;
  345. }
  346. //////////////////////////////////////////////////////////////////////
  347. //
  348. // Configure_Driver_List
  349. //
  350. //////////////////////////////////////////////////////////////////////
  351. void
  352. DlgConfigAudioTabClass::Configure_Driver_List (void)
  353. {
  354. ListCtrlClass *list_ctrl = (ListCtrlClass *)Get_Dlg_Item (IDC_DRIVER_LIST);
  355. if (list_ctrl == NULL) {
  356. return ;
  357. }
  358. //
  359. // Get the name of the current 3D driver
  360. //
  361. StringClass device_name = WWAudioClass::Get_Instance ()->Get_3D_Driver_Name ();
  362. //
  363. // Configure the column
  364. //
  365. list_ctrl->Add_Column (TRANSLATE (IDS_SND_DRIVER_COL), 1.0F, Vector3 (1, 1, 1));
  366. //
  367. // Loop over all the drivers
  368. //
  369. bool selected_default = false;
  370. int driver_count = WWAudioClass::Get_Instance ()->Get_3D_Device_Count ();
  371. for (int index = 0; index < driver_count; index ++) {
  372. //
  373. // Get information about this sound driver
  374. //
  375. WWAudioClass::DRIVER_INFO_STRUCT *driver_info = NULL;
  376. if (WWAudioClass::Get_Instance ()->Get_3D_Device (index, &driver_info)) {
  377. WideStringClass wide_driver_name;
  378. wide_driver_name.Convert_From (driver_info->name);
  379. //
  380. // Add an entry to the list for this driver
  381. //
  382. int item_index = list_ctrl->Insert_Entry (index, wide_driver_name);
  383. if (item_index >= 0) {
  384. list_ctrl->Set_Entry_Data (item_index, 0, (DWORD)driver_info->driver);
  385. //
  386. // Select this entry if its the default
  387. //
  388. if (::lstrcmpi (device_name, driver_info->name) == 0) {
  389. list_ctrl->Set_Curr_Sel (item_index);
  390. selected_default = true;
  391. }
  392. }
  393. }
  394. }
  395. //
  396. // Select the first entry by default (if necessary)
  397. //
  398. if (selected_default == false) {
  399. list_ctrl->Set_Curr_Sel (0);
  400. }
  401. //
  402. // Record the initial device index so we don't have
  403. // to recreate the device if its not necessary
  404. //
  405. InitialDeviceIndex = list_ctrl->Get_Curr_Sel ();
  406. return ;
  407. }
  408. /////////////////////////////////////////////////////////////////////////////
  409. //
  410. // On_Apply
  411. //
  412. /////////////////////////////////////////////////////////////////////////////
  413. bool
  414. DlgConfigAudioTabClass::On_Apply (void)
  415. {
  416. StringClass device_name;
  417. int hertz = 44100;
  418. int bits = 16;
  419. int speaker_type = 0;
  420. bool is_stereo = true;
  421. float sound_vol = 1.0F;
  422. float music_vol = 1.0F;
  423. float dialog_vol = 1.0F;
  424. float cinematic_vol = 1.0F;
  425. bool sound_on = true;
  426. bool music_on = true;
  427. bool dialog_on = true;
  428. bool cinematic_on = true;
  429. SliderCtrlClass *snd_vol_slider = (SliderCtrlClass *)Get_Dlg_Item (IDC_SOUND_EFFECTS_SLIDER);
  430. SliderCtrlClass *mus_vol_slider = (SliderCtrlClass *)Get_Dlg_Item (IDC_MUSIC_SLIDER);
  431. SliderCtrlClass *dia_vol_slider = (SliderCtrlClass *)Get_Dlg_Item (IDC_DIALOG_SLIDER);
  432. SliderCtrlClass *cin_vol_slider = (SliderCtrlClass *)Get_Dlg_Item (IDC_CINEMATIC_SLIDER);
  433. //
  434. // Get the volume settings
  435. //
  436. sound_vol = snd_vol_slider->Get_Pos () / 100.0F;
  437. music_vol = mus_vol_slider->Get_Pos () / 100.0F;
  438. dialog_vol = dia_vol_slider->Get_Pos () / 100.0F;
  439. cinematic_vol = cin_vol_slider->Get_Pos () / 100.0F;
  440. //
  441. // Setup the music volume controls
  442. //
  443. sound_on = Is_Dlg_Button_Checked (IDC_SOUND_EFFECTS_CHECK);
  444. music_on = Is_Dlg_Button_Checked (IDC_MUSIC_CHECK);
  445. dialog_on = Is_Dlg_Button_Checked (IDC_DIALOG_CHECK);
  446. cinematic_on = Is_Dlg_Button_Checked (IDC_CINEMATIC_CHECK);
  447. //
  448. // Get the name of the selected device
  449. //
  450. ListCtrlClass *list_ctrl = (ListCtrlClass *)Get_Dlg_Item (IDC_DRIVER_LIST);
  451. int device_index = list_ctrl->Get_Curr_Sel ();
  452. if (device_index >= 0) {
  453. WideStringClass wide_device_name = list_ctrl->Get_Entry_Text (device_index, 0);
  454. wide_device_name.Convert_To (device_name);
  455. }
  456. //
  457. // Get the stereo flag from the dialog
  458. //
  459. is_stereo = Is_Dlg_Button_Checked (IDC_STEREO_CHECK);
  460. //
  461. // Get the playback bit rate from the dialog
  462. //
  463. ComboBoxCtrlClass *combo_box = (ComboBoxCtrlClass *)Get_Dlg_Item (IDC_QUALITY_COMBO);
  464. int quality_cursel = combo_box->Get_Curr_Sel ();
  465. if (quality_cursel == 0) {
  466. bits = 8;
  467. } else if (quality_cursel == 1) {
  468. bits = 16;
  469. }
  470. //
  471. // Get the playback rate from the controls
  472. //
  473. combo_box = (ComboBoxCtrlClass *)Get_Dlg_Item (IDC_RATE_COMBO);
  474. int rate_cursel = combo_box->Get_Curr_Sel ();
  475. if (rate_cursel == 0) {
  476. hertz = 11025;
  477. } else if (rate_cursel == 1) {
  478. hertz = 22050;
  479. } else if (rate_cursel == 2) {
  480. hertz = 44100;
  481. }
  482. //
  483. // Get the playback rate from the controls
  484. //
  485. combo_box = (ComboBoxCtrlClass *)Get_Dlg_Item (IDC_SPEAKER_SETUP_COMBO);
  486. speaker_type = combo_box->Get_Curr_Sel ();
  487. //
  488. // Store these settings in the registry
  489. //
  490. WWAudioClass::Get_Instance ()->Save_To_Registry (APPLICATION_SUB_KEY_NAME_SOUND,
  491. device_name, is_stereo, bits, hertz, sound_on,
  492. music_on, dialog_on, cinematic_on, sound_vol, music_vol,
  493. dialog_vol, cinematic_vol, speaker_type);
  494. //
  495. // Don't change drivers unless necessary
  496. //
  497. if (InitialBits != bits || InitialHertz != hertz || InitialDeviceIndex != device_index || is_stereo != InitialIsStereo) {
  498. WWAudioClass::Get_Instance ()->Open_2D_Device (is_stereo, bits, hertz);
  499. WWAudioClass::Get_Instance ()->Select_3D_Device (device_name);
  500. }
  501. //
  502. // Apply the simple changes
  503. //
  504. WWAudioClass::Get_Instance ()->Set_Sound_Effects_Volume (sound_vol);
  505. WWAudioClass::Get_Instance ()->Set_Music_Volume (music_vol);
  506. WWAudioClass::Get_Instance ()->Set_Dialog_Volume (dialog_vol);
  507. WWAudioClass::Get_Instance ()->Set_Cinematic_Volume (cinematic_vol);
  508. WWAudioClass::Get_Instance ()->Allow_Sound_Effects (sound_on);
  509. WWAudioClass::Get_Instance ()->Allow_Music (music_on);
  510. WWAudioClass::Get_Instance ()->Allow_Dialog (dialog_on);
  511. WWAudioClass::Get_Instance ()->Allow_Cinematic_Sound (cinematic_on);
  512. WWAudioClass::Get_Instance ()->Set_Speaker_Type (speaker_type);
  513. return true;
  514. }
  515. /////////////////////////////////////////////////////////////////////////////
  516. //
  517. // On_SliderCtrl_Pos_Changed
  518. //
  519. /////////////////////////////////////////////////////////////////////////////
  520. void
  521. DlgConfigAudioTabClass::On_SliderCtrl_Pos_Changed
  522. (
  523. SliderCtrlClass * slider_ctrl,
  524. int ctrl_id,
  525. int new_pos
  526. )
  527. {
  528. if (ctrl_id == IDC_SOUND_EFFECTS_SLIDER) {
  529. //
  530. // Update the sound effects volume...
  531. //
  532. float sound_vol = slider_ctrl->Get_Pos () / 100.0F;
  533. WWAudioClass::Get_Instance ()->Set_Sound_Effects_Volume (sound_vol);
  534. //
  535. // Start the sound effect sound playing
  536. //
  537. if ( SoundVolumeTestSound != NULL &&
  538. (SoundVolumeTestSound->Is_Playing () == false || ((DialogMgrClass::Get_Time () - SoundVolumeTestSoundStartTime) > 150)))
  539. {
  540. SoundVolumeTestSound->Stop ();
  541. SoundVolumeTestSound->Set_Loop_Count (0);
  542. SoundVolumeTestSound->Play ();
  543. //
  544. // Record a time stamp for this sound...
  545. //
  546. SoundVolumeTestSoundStartTime = DialogMgrClass::Get_Time ();
  547. }
  548. } else if (ctrl_id == IDC_MUSIC_SLIDER) {
  549. //
  550. // Update the music volume...
  551. //
  552. float music_vol = slider_ctrl->Get_Pos () / 100.0F;
  553. WWAudioClass::Get_Instance ()->Set_Music_Volume (music_vol);
  554. //
  555. // Start the music sound playing
  556. //
  557. if (MusicVolumeTestSound != NULL && MusicVolumeTestSound->Is_Playing () == false) {
  558. MusicVolumeTestSound->Play ();
  559. }
  560. //
  561. // Record a time stamp for this sound...
  562. //
  563. MusicVolumeTestSoundStartTime = DialogMgrClass::Get_Time ();
  564. } else if (ctrl_id == IDC_DIALOG_SLIDER) {
  565. //
  566. // Update the dialog volume...
  567. //
  568. float dialog_vol = slider_ctrl->Get_Pos () / 100.0F;
  569. WWAudioClass::Get_Instance ()->Set_Dialog_Volume (dialog_vol);
  570. //
  571. // Start the dialog effect sound playing
  572. //
  573. if (DialogVolumeTestSound != NULL) {
  574. DialogVolumeTestSound->Set_Loop_Count (0);
  575. DialogVolumeTestSound->Play ();
  576. //
  577. // Record a time stamp for this sound...
  578. //
  579. DialogVolumeTestSoundStartTime = DialogMgrClass::Get_Time ();
  580. }
  581. } else if (ctrl_id == IDC_CINEMATIC_SLIDER) {
  582. //
  583. // Update the dialog volume...
  584. //
  585. float cinematic_vol = slider_ctrl->Get_Pos () / 100.0F;
  586. WWAudioClass::Get_Instance ()->Set_Cinematic_Volume (cinematic_vol);
  587. //
  588. // Start the dialog effect sound playing
  589. //
  590. if (CinematicVolumeTestSound != NULL) {
  591. CinematicVolumeTestSound->Set_Loop_Count (0);
  592. CinematicVolumeTestSound->Play ();
  593. //
  594. // Record a time stamp for this sound...
  595. //
  596. CinematicVolumeTestSoundStartTime = DialogMgrClass::Get_Time ();
  597. }
  598. }
  599. return ;
  600. }
  601. /////////////////////////////////////////////////////////////////////////////
  602. //
  603. // On_Frame_Update
  604. //
  605. /////////////////////////////////////////////////////////////////////////////
  606. void
  607. DlgConfigAudioTabClass::On_Frame_Update (void)
  608. {
  609. int curr_time = DialogMgrClass::Get_Time ();
  610. //
  611. // Stop the sound volume test sound if necessary
  612. //
  613. if (SoundVolumeTestSound != NULL && (curr_time - SoundVolumeTestSoundStartTime) > 500) {
  614. SoundVolumeTestSound->Set_Loop_Count (1);
  615. }
  616. //
  617. // Stop the sound volume test sound if necessary
  618. //
  619. if (MusicVolumeTestSound != NULL && (curr_time - MusicVolumeTestSoundStartTime) > 2000) {
  620. MusicVolumeTestSound->Stop ();
  621. }
  622. //
  623. // Stop the dialog test sound if necessary
  624. //
  625. if (DialogVolumeTestSound != NULL && (curr_time - DialogVolumeTestSoundStartTime) > 2000) {
  626. DialogVolumeTestSound->Set_Loop_Count (1);
  627. }
  628. //
  629. // Stop the cinematic test sound if necessary
  630. //
  631. if (CinematicVolumeTestSound != NULL && (curr_time - CinematicVolumeTestSoundStartTime) > 2000) {
  632. CinematicVolumeTestSound->Set_Loop_Count (1);
  633. }
  634. ChildDialogClass::On_Frame_Update ();
  635. return ;
  636. }
  637. /////////////////////////////////////////////////////////////////////////////
  638. //
  639. // Set_Default_Volumes
  640. //
  641. /////////////////////////////////////////////////////////////////////////////
  642. void
  643. DlgConfigAudioTabClass::Set_Default_Volumes (void)
  644. {
  645. int defaultmusicvolume, defaultsoundvolume, defaultdialogvolume, defaultcinematicvolume;
  646. SliderCtrlClass *snd_vol_slider = (SliderCtrlClass *)Get_Dlg_Item (IDC_SOUND_EFFECTS_SLIDER);
  647. SliderCtrlClass *mus_vol_slider = (SliderCtrlClass *)Get_Dlg_Item (IDC_MUSIC_SLIDER);
  648. SliderCtrlClass *dia_vol_slider = (SliderCtrlClass *)Get_Dlg_Item (IDC_DIALOG_SLIDER);
  649. SliderCtrlClass *cin_vol_slider = (SliderCtrlClass *)Get_Dlg_Item (IDC_CINEMATIC_SLIDER);
  650. // IML: Get the default settings from the audio system.
  651. WWAudioClass::Get_Instance()->Load_Default_Volume (defaultmusicvolume, defaultsoundvolume, defaultdialogvolume, defaultcinematicvolume);
  652. snd_vol_slider->Set_Pos (defaultsoundvolume);
  653. mus_vol_slider->Set_Pos (defaultmusicvolume);
  654. dia_vol_slider->Set_Pos (defaultdialogvolume);
  655. cin_vol_slider->Set_Pos (defaultcinematicvolume);
  656. return ;
  657. }