1 /* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 *
21 */
22
23 #include "audio/softsynth/pcspk.h"
24
25 #include "backends/audiocd/audiocd.h"
26
27 #include "common/config-manager.h"
28
29 #include "testbed/sound.h"
30
31 namespace Testbed {
32
33 enum {
34 kPlayChannel1 = 'pch1',
35 kPlayChannel2 = 'pch2',
36 kPlayChannel3 = 'pch3',
37 kPauseChannel1 = 'pac1',
38 kPauseChannel2 = 'pac2',
39 kPauseChannel3 = 'pac3'
40 };
41
SoundSubsystemDialog()42 SoundSubsystemDialog::SoundSubsystemDialog() : TestbedInteractionDialog(80, 60, 400, 170) {
43 _xOffset = 25;
44 _yOffset = 0;
45 Common::String text = "Sound Subsystem Tests: Test Mixing of Audio Streams.";
46 addText(350, 20, text, Graphics::kTextAlignCenter, _xOffset, 15);
47 addButton(200, 20, "Play Channel #1", kPlayChannel1);
48 addButton(200, 20, "Play Channel #2", kPlayChannel2);
49 addButton(200, 20, "Play Channel #3", kPlayChannel3);
50 addButton(50, 20, "Close", GUI::kCloseCmd, 160, 15);
51
52 _mixer = g_system->getMixer();
53
54 // the three streams to be mixed
55 Audio::PCSpeaker *s1 = new Audio::PCSpeaker();
56 Audio::PCSpeaker *s2 = new Audio::PCSpeaker();
57 Audio::PCSpeaker *s3 = new Audio::PCSpeaker();
58
59 s1->play(Audio::PCSpeaker::kWaveFormSine, 1000, -1);
60 s2->play(Audio::PCSpeaker::kWaveFormSine, 1200, -1);
61 s3->play(Audio::PCSpeaker::kWaveFormSine, 1400, -1);
62
63 _mixer->playStream(Audio::Mixer::kPlainSoundType, &_h1, s1);
64 _mixer->pauseHandle(_h1, true);
65
66 _mixer->playStream(Audio::Mixer::kSpeechSoundType, &_h2, s2);
67 _mixer->pauseHandle(_h2, true);
68
69 _mixer->playStream(Audio::Mixer::kSFXSoundType, &_h3, s3);
70 _mixer->pauseHandle(_h3, true);
71
72 }
73
74
handleCommand(GUI::CommandSender * sender,uint32 cmd,uint32 data)75 void SoundSubsystemDialog::handleCommand(GUI::CommandSender *sender, uint32 cmd, uint32 data) {
76
77 switch (cmd) {
78 case kPlayChannel1:
79 _buttonArray[0]->setLabel("Pause Channel #1");
80 _buttonArray[0]->setCmd(kPauseChannel1);
81 _mixer->pauseHandle(_h1, false);
82 break;
83 case kPlayChannel2:
84 _buttonArray[1]->setLabel("Pause Channel #2");
85 _buttonArray[1]->setCmd(kPauseChannel2);
86 _mixer->pauseHandle(_h2, false);
87 break;
88 case kPlayChannel3:
89 _buttonArray[2]->setLabel("Pause Channel #3");
90 _buttonArray[2]->setCmd(kPauseChannel3);
91 _mixer->pauseHandle(_h3, false);
92 break;
93 case kPauseChannel1:
94 _buttonArray[0]->setLabel("Play Channel #1");
95 _buttonArray[0]->setCmd(kPlayChannel1);
96 _mixer->pauseHandle(_h1, true);
97 break;
98 case kPauseChannel2:
99 _buttonArray[1]->setLabel("Play Channel #2");
100 _buttonArray[1]->setCmd(kPlayChannel2);
101 _mixer->pauseHandle(_h2, true);
102 break;
103 case kPauseChannel3:
104 _buttonArray[2]->setLabel("Play Channel #3");
105 _buttonArray[2]->setCmd(kPlayChannel3);
106 _mixer->pauseHandle(_h3, true);
107 break;
108 default:
109 _mixer->stopAll();
110 GUI::Dialog::handleCommand(sender, cmd, data);
111 }
112 }
113
playBeeps()114 TestExitStatus SoundSubsystem::playBeeps() {
115 Testsuite::clearScreen();
116 TestExitStatus passed = kTestPassed;
117 Common::String info = "Testing Sound Output by generating beeps\n"
118 "You should hear a left beep followed by a right beep\n";
119
120 if (Testsuite::handleInteractiveInput(info, "OK", "Skip", kOptionRight)) {
121 Testsuite::logPrintf("Info! Skipping test : Play Beeps\n");
122 return kTestSkipped;
123 }
124
125 Audio::PCSpeaker *speaker = new Audio::PCSpeaker();
126 Audio::Mixer *mixer = g_system->getMixer();
127 Audio::SoundHandle handle;
128 mixer->playStream(Audio::Mixer::kPlainSoundType, &handle, speaker);
129
130 // Left Beep
131 Testsuite::writeOnScreen("Left Beep", Common::Point(0, 100));
132 mixer->setChannelBalance(handle, -127);
133 speaker->play(Audio::PCSpeaker::kWaveFormSine, 1000, -1);
134 g_system->delayMillis(500);
135 mixer->pauseHandle(handle, true);
136
137 if (Testsuite::handleInteractiveInput(" Were you able to hear the left beep? ", "Yes", "No", kOptionRight)) {
138 Testsuite::logDetailedPrintf("Error! Left Beep couldn't be detected : Error with Mixer::setChannelBalance()\n");
139 passed = kTestFailed;
140 }
141
142 // Right Beep
143 Testsuite::writeOnScreen("Right Beep", Common::Point(0, 100));
144 mixer->setChannelBalance(handle, 127);
145 mixer->pauseHandle(handle, false);
146 g_system->delayMillis(500);
147 mixer->stopAll();
148
149 if (Testsuite::handleInteractiveInput("Were you able to hear the right beep?", "Yes", "No", kOptionRight)) {
150 Testsuite::logDetailedPrintf("Error! Right Beep couldn't be detected : Error with Mixer::setChannelBalance()\n");
151 passed = kTestFailed;
152 }
153 return passed;
154 }
155
mixSounds()156 TestExitStatus SoundSubsystem::mixSounds() {
157 Testsuite::clearScreen();
158 TestExitStatus passed = kTestPassed;
159 Common::String info = "Testing Mixer Output by generating multichannel sound output using PC speaker emulator.\n"
160 "The mixer should be able to play them simultaneously\n";
161
162 if (Testsuite::handleInteractiveInput(info, "OK", "Skip", kOptionRight)) {
163 Testsuite::logPrintf("Info! Skipping test : Mix Sounds\n");
164 return kTestSkipped;
165 }
166
167 SoundSubsystemDialog sDialog;
168 sDialog.runModal();
169 if (Testsuite::handleInteractiveInput("Was the mixer able to simultaneously play multiple channels?", "Yes", "No", kOptionRight)) {
170 Testsuite::logDetailedPrintf("Error! Multiple channels couldn't be played : Error with Mixer Class\n");
171 passed = kTestFailed;
172 }
173 return passed;
174 }
175
audiocdOutput()176 TestExitStatus SoundSubsystem::audiocdOutput() {
177 Testsuite::clearScreen();
178 TestExitStatus passed = kTestPassed;
179 Common::String info = "Testing AudioCD API implementation.\n"
180 "Here we have four tracks, we play them in order i.e 1-2-3-last.\n"
181 "The user should verify if the tracks were run in correct order or not.";
182
183 if (Testsuite::handleInteractiveInput(info, "OK", "Skip", kOptionRight)) {
184 Testsuite::logPrintf("Info! Skipping test : AudioCD API\n");
185 return kTestSkipped;
186 }
187
188 Common::Point pt(0, 100);
189 Testsuite::writeOnScreen("Playing the tracks of testCD in order i.e 1-2-3-last", pt);
190
191
192 // Play all tracks
193 for (int i = 1; i < 5; i++) {
194 g_system->getAudioCDManager()->play(i, 1, 0, 0);
195 while (g_system->getAudioCDManager()->isPlaying()) {
196 g_system->delayMillis(500);
197 Testsuite::writeOnScreen(Common::String::format("Playing Now: track%02d", i), pt);
198 }
199 g_system->delayMillis(500);
200 }
201
202 Testsuite::clearScreen();
203 if (Testsuite::handleInteractiveInput("Were all the tracks played in order i.e 1-2-3-last ?", "Yes", "No", kOptionRight)) {
204 Testsuite::logPrintf("Error! Error in _system->getAudioCDManager()->play() or probably sound files were not detected, try -d1 (debuglevel 1)\n");
205 passed = kTestFailed;
206 }
207
208 return passed;
209 }
210
sampleRates()211 TestExitStatus SoundSubsystem::sampleRates() {
212
213 Common::String info = "Testing Multiple Sample Rates.\n"
214 "Here we try to play sounds at three different sample rates.";
215
216 if (Testsuite::handleInteractiveInput(info, "OK", "Skip", kOptionRight)) {
217 Testsuite::logPrintf("Info! Skipping test : Sample Rates\n");
218 return kTestSkipped;
219 }
220
221 TestExitStatus passed = kTestPassed;
222 Audio::Mixer *mixer = g_system->getMixer();
223
224 Audio::PCSpeaker *s1 = new Audio::PCSpeaker();
225 // Stream at half sampling rate
226 Audio::PCSpeaker *s2 = new Audio::PCSpeaker(s1->getRate() - 10000);
227 // Stream at twice sampling rate
228 Audio::PCSpeaker *s3 = new Audio::PCSpeaker(s1->getRate() + 10000);
229
230 s1->play(Audio::PCSpeaker::kWaveFormSine, 1000, -1);
231 s2->play(Audio::PCSpeaker::kWaveFormSine, 1000, -1);
232 s3->play(Audio::PCSpeaker::kWaveFormSine, 1000, -1);
233
234 Audio::SoundHandle handle;
235 Common::Point pt(0, 100);
236
237 mixer->playStream(Audio::Mixer::kPlainSoundType, &handle, s1);
238 Testsuite::writeOnScreen(Common::String::format("Playing at sample rate: %d", s1->getRate()), pt);
239 g_system->delayMillis(1000);
240 mixer->stopHandle(handle);
241 g_system->delayMillis(1000);
242
243 mixer->playStream(Audio::Mixer::kSpeechSoundType, &handle, s2);
244 Testsuite::writeOnScreen(Common::String::format("Playing at sample rate : %d", s2->getRate()), pt);
245 g_system->delayMillis(1000);
246 mixer->stopHandle(handle);
247 g_system->delayMillis(1000);
248
249 mixer->playStream(Audio::Mixer::kSFXSoundType, &handle, s3);
250 Testsuite::writeOnScreen(Common::String::format("Playing at sample rate : %d", s3->getRate()), pt);
251 g_system->delayMillis(1000);
252 mixer->stopHandle(handle);
253 g_system->delayMillis(1000);
254
255 Testsuite::clearScreen();
256 if (Testsuite::handleInteractiveInput("Was the mixer able to play beeps with variable sample rates?", "Yes", "No", kOptionRight)) {
257 Testsuite::logDetailedPrintf("Error! Error with variable sample rates\n");
258 passed = kTestFailed;
259 }
260
261 return passed;
262 }
263
SoundSubsystemTestSuite()264 SoundSubsystemTestSuite::SoundSubsystemTestSuite() {
265 addTest("SimpleBeeps", &SoundSubsystem::playBeeps, true);
266 addTest("MixSounds", &SoundSubsystem::mixSounds, true);
267
268 // Make audio-files discoverable
269 Common::FSNode gameRoot(ConfMan.get("path"));
270 if (gameRoot.exists()) {
271 SearchMan.addSubDirectoryMatching(gameRoot, "audiocd-files");
272 if (SearchMan.hasFile("track01.mp3") && SearchMan.hasFile("track02.mp3") && SearchMan.hasFile("track03.mp3") && SearchMan.hasFile("track04.mp3")) {
273 addTest("AudiocdOutput", &SoundSubsystem::audiocdOutput, true);
274 } else {
275 Testsuite::logPrintf("Warning! Skipping test AudioCD: Required data files missing, check game-dir/audiocd-files\n");
276 }
277 }
278 addTest("SampleRates", &SoundSubsystem::sampleRates, true);
279 }
280
281 } // End of namespace Testbed
282