1 /***************************************************************************
2 * Copyright (C) 2004-2005 by *
3 * Paolo Sacconier <axa1981@tin.it> *
4 * Francesco Tamagni <minchiahead@hacari.org> *
5 * *
6 * This program 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 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
20 ***************************************************************************/
21 #include "sound.h"
22
23 namespace gillo {
24
Sound()25 Sound::Sound()
26 : enabled(true), sched(44100)
27 {
28 sched.setSafetyMargin ( 0.128f ) ;
29
30 // load all the samples
31 samples[BOING] = new slSample (SND_BOING, &sched);
32 samples[GOAL] = new slSample (SND_GOAL, &sched);
33 samples[TIEGOAL] = new slSample (SND_TIEGOAL, &sched);
34 samples[END] = new slSample (SND_END, &sched);
35 samples[ENDTIE] = new slSample (SND_ENDTIE, &sched);
36 samples[FIRE] = new slSample (SND_FIRE, &sched);
37 samples[MENUSEL] = new slSample (SND_MENU_SEL, &sched);
38 samples[MENUSEL]->adjustVolume(10.0);
39 samples[PWRUP_CHARGE_INVERTER] = new slSample (SND_PWRUP_CHARGE_INVERTER, &sched);
40 samples[PWRUP_CHARGE_INVERTER]->adjustVolume(10.0);
41 samples[PWRUP_GRAVITY_ROTATOR] = new slSample (SND_PWRUP_GRAVITY_ROTATOR, &sched);
42 samples[PWRUP_GRAVITY_ROTATOR]->adjustVolume(6.0);
43 samples[PWRUP_BALL_INFLATE] = new slSample (SND_PWRUP_BALL_INFLATE, &sched);
44 samples[PWRUP_BALL_DEFLATE] = new slSample (SND_PWRUP_BALL_DEFLATE, &sched);
45 samples[PWRUP_BALL_ADD] = new slSample (SND_PWRUP_BALL_ADD, &sched);
46 samples[PWRUP_NEW] = new slSample (SND_PWRUP_NEW, &sched);
47 samples[POWERSHOOT] = new slSample (SND_POWERSHOOT, &sched);
48
49 //slSample *s3 = new slSample ( "cuckoo.au", & sched ) ;
50 //slSample *s4 = new slSample ( "wheeee.ub", & sched ) ;
51
52 /* Mess about with some of the samples... */
53
54 //s1 -> adjustVolume ( 10.0f ) ;
55 //s2 -> adjustVolume ( 0.5f ) ;
56 //s3 -> adjustVolume ( 0.2f ) ;
57 //s3 -> adjustVolume ( 0.3f ) ;
58
59 /* Play the engine sample continuously. */
60 //sched.loopSample ( s ) ;
61 //sched.loopSample ( s4 ) ;
62 }
63
~Sound()64 Sound::~ Sound()
65 {
66 printf("Sound(%p): destroyed\n",this);
67 }
68
play(Effect e)69 void Sound::play(Effect e) {
70 sched.playSample(samples[e]);
71 }
music(Music m)72 void Sound::music(Music m) {
73 sched.stopMusic();
74 switch (m) {
75 case GAME1:
76 sched.loopMusic(MOD_GAME1);
77 break;
78 case MENU:
79 sched.loopMusic(MOD_MENU);
80 break;
81 case TRAINING:
82 sched.loopMusic(MOD_TRAINING);
83 break;
84 default:
85 //@fixme throw something
86 break;
87 }
88 }
update(double t)89 void Sound::update(double t) {
90 if (enabled)
91 sched.update();
92 }
93 };
94