Rev 1 | Rev 18 | 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) |
||
| 11 | pmbaty | 22 | swprintf_s (soundfile_path, WCHAR_SIZEOF (soundfile_path), L"%s/data/sounds/click.wav", app_path); |
| 1 | pmbaty | 23 | else if (queued_sound == SOUNDTYPE_ILLEGALMOVE) |
| 11 | pmbaty | 24 | swprintf_s (soundfile_path, WCHAR_SIZEOF (soundfile_path), L"%s/data/sounds/illegal.wav", app_path); |
| 1 | pmbaty | 25 | else if (queued_sound == SOUNDTYPE_VICTORY) |
| 11 | pmbaty | 26 | swprintf_s (soundfile_path, WCHAR_SIZEOF (soundfile_path), L"%s/data/sounds/win.wav", app_path); |
| 1 | pmbaty | 27 | else if (queued_sound == SOUNDTYPE_DEFEAT) |
| 11 | pmbaty | 28 | swprintf_s (soundfile_path, WCHAR_SIZEOF (soundfile_path), L"%s/data/sounds/lose.wav", app_path); |
| 1 | pmbaty | 29 | else if (queued_sound == SOUNDTYPE_CHECK) |
| 11 | pmbaty | 30 | swprintf_s (soundfile_path, WCHAR_SIZEOF (soundfile_path), L"%s/data/sounds/check.wav", app_path); |
| 1 | pmbaty | 31 | else if (queued_sound == SOUNDTYPE_PIECETAKEN) |
| 11 | pmbaty | 32 | swprintf_s (soundfile_path, WCHAR_SIZEOF (soundfile_path), L"%s/data/sounds/take.wav", app_path); |
| 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) |
||
| 11 | pmbaty | 37 | swprintf_s (soundfile_path, WCHAR_SIZEOF (soundfile_path), L"%s/data/sounds/move1.wav", app_path); |
| 1 | pmbaty | 38 | else if (sound_index == 1) |
| 11 | pmbaty | 39 | swprintf_s (soundfile_path, WCHAR_SIZEOF (soundfile_path), L"%s/data/sounds/move2.wav", app_path); |
| 1 | pmbaty | 40 | else if (sound_index == 2) |
| 11 | pmbaty | 41 | swprintf_s (soundfile_path, WCHAR_SIZEOF (soundfile_path), L"%s/data/sounds/move3.wav", app_path); |
| 1 | pmbaty | 42 | else if (sound_index == 3) |
| 11 | pmbaty | 43 | swprintf_s (soundfile_path, WCHAR_SIZEOF (soundfile_path), L"%s/data/sounds/move4.wav", app_path); |
| 1 | pmbaty | 44 | else if (sound_index == 4) |
| 11 | pmbaty | 45 | swprintf_s (soundfile_path, WCHAR_SIZEOF (soundfile_path), L"%s/data/sounds/move5.wav", app_path); |
| 1 | pmbaty | 46 | else |
| 11 | pmbaty | 47 | swprintf_s (soundfile_path, WCHAR_SIZEOF (soundfile_path), L"%s/data/sounds/move6.wav", app_path); |
| 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 | } |