2 * Copyright (C) 2003 Robert Kooima
4 * NEVERPUTT is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published
6 * by the Free Software Foundation; either version 2 of the License,
7 * or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
16 #include <SDL_mixer.h>
21 /*---------------------------------------------------------------------------*/
23 static int audio_state
= 0;
25 static Mix_Music
*song
;
26 static Mix_Chunk
*buff
[AUD_COUNT
];
27 static int chan
[AUD_COUNT
];
35 /*---------------------------------------------------------------------------*/
37 static void chunk_load(int i
, const char *filename
, int channel
)
39 buff
[i
] = Mix_LoadWAV(config_data(filename
));
43 static void chunk_free(int i
)
47 Mix_FreeChunk(buff
[i
]);
52 /*---------------------------------------------------------------------------*/
56 int r
= config_get_d(CONFIG_AUDIO_RATE
);
57 int b
= config_get_d(CONFIG_AUDIO_BUFF
);
61 if (Mix_OpenAudio(r
, MIX_DEFAULT_FORMAT
, 1, b
) == 0)
63 chunk_load(AUD_BIRDIE
, "snd/birdie.ogg", CH_VOICE
);
64 chunk_load(AUD_BOGEY
, "snd/bogey.ogg", CH_VOICE
);
65 chunk_load(AUD_BUMP
, "snd/bink.wav", CH_VOICE
);
66 chunk_load(AUD_DOUBLE
, "snd/double.ogg", CH_VOICE
);
67 chunk_load(AUD_EAGLE
, "snd/eagle.ogg", CH_VOICE
);
68 chunk_load(AUD_JUMP
, "snd/jump.ogg", CH_BUMP
);
69 chunk_load(AUD_MENU
, "snd/menu.wav", CH_MENU
);
70 chunk_load(AUD_ONE
, "snd/one.ogg", CH_VOICE
);
71 chunk_load(AUD_PAR
, "snd/par.ogg", CH_VOICE
);
72 chunk_load(AUD_PENALTY
, "snd/penalty.ogg", CH_VOICE
);
73 chunk_load(AUD_PLAYER1
, "snd/player1.ogg", CH_VOICE
);
74 chunk_load(AUD_PLAYER2
, "snd/player2.ogg", CH_VOICE
);
75 chunk_load(AUD_PLAYER3
, "snd/player3.ogg", CH_VOICE
);
76 chunk_load(AUD_PLAYER4
, "snd/player4.ogg", CH_VOICE
);
77 chunk_load(AUD_SUCCESS
, "snd/success.ogg", CH_VOICE
);
81 audio_volume(config_get_d(CONFIG_SOUND_VOLUME
),
82 config_get_d(CONFIG_MUSIC_VOLUME
));
84 else fprintf(stderr
, "Sound disabled\n");
88 void audio_play(int i
, float v
)
90 if (audio_state
== 1 && buff
[i
])
92 Mix_VolumeChunk(buff
[i
], (int) (v
* MIX_MAX_VOLUME
));
93 Mix_PlayChannel(chan
[i
], buff
[i
], 0);
103 chunk_free(AUD_SUCCESS
);
104 chunk_free(AUD_PLAYER4
);
105 chunk_free(AUD_PLAYER3
);
106 chunk_free(AUD_PLAYER2
);
107 chunk_free(AUD_PLAYER1
);
108 chunk_free(AUD_PENALTY
);
111 chunk_free(AUD_MENU
);
112 chunk_free(AUD_JUMP
);
113 chunk_free(AUD_EAGLE
);
114 chunk_free(AUD_DOUBLE
);
115 chunk_free(AUD_BUMP
);
116 chunk_free(AUD_BOGEY
);
117 chunk_free(AUD_BIRDIE
);
123 /*---------------------------------------------------------------------------*/
125 void audio_music_play(const char *filename
)
131 if ((config_get_d(CONFIG_MUSIC_VOLUME
) > 0) &&
132 (song
= Mix_LoadMUS(config_data(filename
))))
133 Mix_PlayMusic(song
, -1);
137 void audio_music_fade(float t
)
139 if (audio_state
&& song
&& Mix_PlayingMusic())
140 Mix_FadeOutMusic((int) (t
* 1000.f
));
143 void audio_music_stop(void)
147 if (Mix_PlayingMusic())
157 void audio_volume(int s
, int m
)
161 Mix_Volume(-1, s
* MIX_MAX_VOLUME
/ 10);
162 Mix_VolumeMusic(m
* MIX_MAX_VOLUME
/ 10);
166 /*---------------------------------------------------------------------------*/