Rev 11 | Rev 116 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | pmbaty | 1 | // audio.cpp |
2 | |||
3 | #include "common.h" |
||
4 | |||
5 | |||
6 | // global variables used in this module only |
||
7 | static int queued_sound = 0; |
||
8 | |||
9 | |||
10 | void Audio_Think (void) |
||
11 | { |
||
12 | // this function plays the queued sounds on the right time |
||
13 | |||
11 | pmbaty | 14 | static wchar_t soundfile_path[MAX_PATH]; |
1 | pmbaty | 15 | int sound_index; |
16 | |||
17 | // do we have a sound to play ? if so, play it |
||
18 | if (queued_sound != 0) |
||
19 | { |
||
20 | // given the type of sound we want, enqueue the right one |
||
21 | if (queued_sound == SOUNDTYPE_CLICK) |
||
18 | pmbaty | 22 | swprintf_s (soundfile_path, WCHAR_SIZEOF (soundfile_path), L"%s/themes/%s/sounds/click.wav", app_path, theme->name); |
1 | pmbaty | 23 | else if (queued_sound == SOUNDTYPE_ILLEGALMOVE) |
18 | pmbaty | 24 | swprintf_s (soundfile_path, WCHAR_SIZEOF (soundfile_path), L"%s/themes/%s/sounds/illegal.wav", app_path, theme->name); |
1 | pmbaty | 25 | else if (queued_sound == SOUNDTYPE_VICTORY) |
18 | pmbaty | 26 | swprintf_s (soundfile_path, WCHAR_SIZEOF (soundfile_path), L"%s/themes/%s/sounds/win.wav", app_path, theme->name); |
1 | pmbaty | 27 | else if (queued_sound == SOUNDTYPE_DEFEAT) |
18 | pmbaty | 28 | swprintf_s (soundfile_path, WCHAR_SIZEOF (soundfile_path), L"%s/themes/%s/sounds/lose.wav", app_path, theme->name); |
1 | pmbaty | 29 | else if (queued_sound == SOUNDTYPE_CHECK) |
18 | pmbaty | 30 | swprintf_s (soundfile_path, WCHAR_SIZEOF (soundfile_path), L"%s/themes/%s/sounds/check.wav", app_path, theme->name); |
1 | pmbaty | 31 | else if (queued_sound == SOUNDTYPE_PIECETAKEN) |
18 | pmbaty | 32 | swprintf_s (soundfile_path, WCHAR_SIZEOF (soundfile_path), L"%s/themes/%s/sounds/take.wav", app_path, theme->name); |
1 | pmbaty | 33 | else if (queued_sound == SOUNDTYPE_MOVE) |
34 | { |
||
35 | sound_index = rand () % 6; // there are several movement sounds, pick one at random |
||
36 | if (sound_index == 0) |
||
18 | pmbaty | 37 | swprintf_s (soundfile_path, WCHAR_SIZEOF (soundfile_path), L"%s/themes/%s/sounds/move1.wav", app_path, theme->name); |
1 | pmbaty | 38 | else if (sound_index == 1) |
18 | pmbaty | 39 | swprintf_s (soundfile_path, WCHAR_SIZEOF (soundfile_path), L"%s/themes/%s/sounds/move2.wav", app_path, theme->name); |
1 | pmbaty | 40 | else if (sound_index == 2) |
18 | pmbaty | 41 | swprintf_s (soundfile_path, WCHAR_SIZEOF (soundfile_path), L"%s/themes/%s/sounds/move3.wav", app_path, theme->name); |
1 | pmbaty | 42 | else if (sound_index == 3) |
18 | pmbaty | 43 | swprintf_s (soundfile_path, WCHAR_SIZEOF (soundfile_path), L"%s/themes/%s/sounds/move4.wav", app_path, theme->name); |
1 | pmbaty | 44 | else if (sound_index == 4) |
18 | pmbaty | 45 | swprintf_s (soundfile_path, WCHAR_SIZEOF (soundfile_path), L"%s/themes/%s/sounds/move5.wav", app_path, theme->name); |
1 | pmbaty | 46 | else |
18 | pmbaty | 47 | swprintf_s (soundfile_path, WCHAR_SIZEOF (soundfile_path), L"%s/themes/%s/sounds/move6.wav", app_path, theme->name); |
1 | pmbaty | 48 | } |
49 | |||
11 | pmbaty | 50 | PlaySound (soundfile_path, NULL, SND_ASYNC | SND_FILENAME | SND_NODEFAULT); |
1 | pmbaty | 51 | queued_sound = 0; // play this sound then forget it |
52 | } |
||
53 | |||
54 | return; // finished, audio has been handled |
||
55 | } |
||
56 | |||
57 | |||
58 | void Audio_PlaySound (int sound_type) |
||
59 | { |
||
60 | // helper function to play a sound |
||
61 | |||
62 | if (!options.want_sounds) |
||
63 | return; // if we want no sound, don't play anything |
||
64 | |||
65 | queued_sound = sound_type; // enqueue the desired sound for playing |
||
66 | return; // finished |
||
67 | } |