Headers should now be correctly handled and get installed in $(includedir)/supertux/ .
[supertux.git] / lib / audio / sound.cpp
1 //  $Id$
2 //
3 //  SuperTux -  A Jump'n Run
4 //  Copyright (C) 2000 Bill Kendrick <bill@newbreedsoftware.com>
5 //  Copyright (C) 2004 Duong-Khang NGUYEN <neoneurone@users.sf.net>
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20
21 #include <string>
22 #include "audio/sound.h"
23
24 /*global variable*/
25 bool use_sound = true;    /* handle sound on/off menu and command-line option */
26 bool use_music = true;    /* handle music on/off menu and command-line option */
27 bool audio_device = true; /* != 0: available and initialized */
28
29 #include <SDL_mixer.h>
30
31 std::vector<Mix_Chunk*> sounds;
32
33 /* --- OPEN THE AUDIO DEVICE --- */
34
35 int open_audio (int frequency, Uint16 format, int channels, int chunksize)
36 {
37   if (Mix_OpenAudio( frequency, format, channels, chunksize ) < 0)
38     return -1;
39
40   // allocate 16 channels for mixing
41   if (Mix_AllocateChannels(8)  != 8)
42     return -2;
43   
44   return 0;
45 }
46
47
48 /* --- CLOSE THE AUDIO DEVICE --- */
49
50 void close_audio( void )
51 {
52   if (audio_device) {
53     Mix_CloseAudio();
54   }
55 }
56
57
58 /* --- LOAD A SOUND --- */
59
60 Mix_Chunk* load_sound(const std::string& file)
61 {
62   if(!audio_device)
63     return 0;
64   
65   Mix_Chunk* snd = Mix_LoadWAV(file.c_str());
66
67   /*if (snd == 0)
68     st_abort("Can't load", file);*/
69
70   return(snd);
71 }
72
73 void free_chunk(Mix_Chunk *chunk)
74 {
75   Mix_FreeChunk( chunk );
76 }
77