69c980bc136c7508a689ab612efeb9ff91c90ba7
[supertux.git] / src / sound.c
1 /*
2   sound.c
3   
4   Super Tux - Audio Functions
5   
6   by Bill Kendrick
7   bill@newbreedsoftware.com
8   http://www.newbreedsoftware.com/supertux/
9  
10   April 22, 2000 - July 15, 2002
11 */
12
13 #ifndef NOSOUND
14
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <string.h>
18 #include <errno.h>
19 #include <unistd.h>
20 #include <SDL.h>
21 #include <SDL_image.h>
22
23 #include <SDL_mixer.h>
24
25 #ifdef LINUX
26 #include <pwd.h>
27 #include <sys/types.h>
28 #include <ctype.h>
29 #endif
30
31 #include "defines.h"
32 #include "globals.h"
33 #include "sound.h"
34 #include "setup.h"
35
36
37 /* --- LOAD A SOUND --- */
38
39 Mix_Chunk * load_sound(char * file)
40 {
41   Mix_Chunk * snd;
42   
43   if (use_sound)
44   {
45     snd = Mix_LoadWAV(file);
46   
47     if (snd == NULL)
48       st_abort("Can't load", file);
49   }
50   else
51     snd = NULL;
52
53   return(snd);
54 }
55
56
57 /* --- PLAY A SOUND --- */
58
59 void playsound(Mix_Chunk * snd)
60 {
61   Mix_PlayChannel(-1, snd, 0);
62 }
63
64
65 /* --- LOAD A SONG --- */
66
67 Mix_Music * load_song(char * file)
68 {
69   Mix_Music * sng;
70
71   if (use_sound)
72   {
73     sng = Mix_LoadMUS(file);
74
75     if (sng == NULL)
76       st_abort("Can't load", file);
77   }
78   else
79     sng = NULL;
80
81   return (sng);
82 }
83
84 #endif