1 //////////////////////////////////////////////////////////////////////////////////////// 2 // 3 // Nestopia - NES/Famicom emulator written in C++ 4 // 5 // Copyright (C) 2003-2008 Martin Freij 6 // 7 // This file is part of Nestopia. 8 // 9 // Nestopia 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 2 of the License, or 12 // (at your option) any later version. 13 // 14 // Nestopia 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 Nestopia; if not, write to the Free Software 21 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 // 23 //////////////////////////////////////////////////////////////////////////////////////// 24 25 #ifndef NST_DIALOG_SOUND_H 26 #define NST_DIALOG_SOUND_H 27 28 #pragma once 29 30 #include "NstWindowDialog.hpp" 31 #include "NstDirectSound.hpp" 32 33 namespace Nestopia 34 { 35 namespace Managers 36 { 37 class Paths; 38 } 39 40 namespace Window 41 { 42 class Sound 43 { 44 typedef DirectX::DirectSound::Adapter Adapter; 45 typedef DirectX::DirectSound::Adapters Adapters; 46 typedef DirectX::DirectSound DirectSound; 47 48 public: 49 50 Sound(Managers::Emulator&,const Adapters&,const Managers::Paths&,const Configuration&); 51 ~Sound(); 52 53 void Save(Configuration&) const; 54 uint GetVolume(uint) const; 55 56 private: 57 58 enum 59 { 60 DEFAULT_BITS = 16, 61 DEFAULT_RATE = 44100, 62 LATENCY_MAX = 10, 63 DEFAULT_LATENCY = 1, 64 VOLUME_MAX = 100, 65 DEFAULT_VOLUME = Nes::Sound::DEFAULT_VOLUME, 66 DEFAULT_MONO = 0, 67 NUM_CHANNELS = 12 68 }; 69 70 struct Handlers; 71 72 uint GetDefaultAdapter() const; 73 void Enable(bool) const; 74 void ResetVolumeSliders() const; 75 void UpdateVolumeReset() const; 76 77 ibool OnInitDialog (Param&); 78 ibool OnVScroll (Param&); 79 ibool OnCmdDevice (Param&); 80 ibool OnCmdResetSliders (Param&); 81 ibool OnCmdDefault (Param&); 82 ibool OnCmdOk (Param&); 83 84 const Adapters& adapters; 85 Nes::Sound nes; 86 87 struct 88 { 89 uint adapter; 90 uint latency; 91 DirectX::DirectSound::Pool pool; 92 uchar volumes[NUM_CHANNELS]; 93 } settings; 94 95 Dialog dialog; 96 97 struct ChannelLut 98 { 99 cstring cfgCategory; 100 cstring cfgChannel; 101 ushort ctrlSlider; 102 ushort ctrlValue; 103 ushort ctrlText; 104 ushort channel; 105 }; 106 107 static const ChannelLut channelLut[NUM_CHANNELS]; 108 109 public: 110 111 class Recorder 112 { 113 public: 114 115 explicit Recorder(const Managers::Paths&); 116 ~Recorder(); 117 118 const Path WaveFile() const; 119 120 private: 121 122 struct Handlers; 123 124 ibool OnInitDialog (Param&); 125 ibool OnCmdBrowse (Param&); 126 ibool OnCmdClear (Param&); 127 ibool OnCmdOk (Param&); 128 129 Dialog dialog; 130 const Managers::Paths& paths; 131 Path waveFile; 132 133 public: 134 Open()135 void Open() 136 { 137 dialog.Open(); 138 } 139 }; 140 141 private: 142 143 Recorder recorder; 144 145 public: 146 Open()147 void Open() 148 { 149 dialog.Open(); 150 } 151 GetRecorder()152 Recorder& GetRecorder() 153 { 154 return recorder; 155 } 156 SoundEnabled() const157 bool SoundEnabled() const 158 { 159 return settings.adapter != UINT_MAX; 160 } 161 GetAdapter() const162 uint GetAdapter() const 163 { 164 return settings.adapter; 165 } 166 GetLatency() const167 uint GetLatency() const 168 { 169 return settings.latency; 170 } 171 GetPool() const172 DirectX::DirectSound::Pool GetPool() const 173 { 174 return settings.pool; 175 } 176 }; 177 } 178 } 179 180 #endif 181