Skip to content

Commit 4270d38

Browse files
Autofireneilmoore
authored andcommitted
Enhanced sound support (PR #450)
This fork features some enhancements for the sound system. Although my plans initially were more ambitious, this will do for now. Adds sound_file_path option, making the current sound option much easier to use. Moved all the sound code to its own set of files for future expansion (I have some plans). Also, makes it painless to fiddle around with PLAY_SOUND_COMMAND, which previously was in AppHdr.h despite being used in just one function. (UPDATE) Adds multiple cues that can be used in place of typical regular expressions. Some examples are PICKUP, MEMORISE_SPELL, and CHANGE QUIVER. See sound.h for a full list. I intend of expanding this. Very incomplete support for a hold_sound option, which is supposed to pause the game while the sound is playing. This pause is intended to be sequential, delaying the rest of the message until the sound finishes. I have two purposes for this: giving battles a real-time feel, and to highlight those epic victories. This feature doesn't work as intended, so I dropped the in-game documentation for now. (UPDATE) Adds one_SDL_sound_channel. Originally, sound behavior depended on whether you were playing with SDL or using the SOUND_PLAY_COMMAND define; if playing with SDL/Tiles, only one sound would play at once, whereas SOUND_PLAY_COMMAND allowed as many sounds as were necessary. By default, one_SDL_sound_channel is set to false, making it behave as SOUND_PLAY_COMMAND. However, players can restore the old behavior by setting this option to true. (UPDATE) The version screen now tells the user how sounds will be played. (i.e. "Windows Multimedia API," "External command," or "SDL_mixer") Anyway, I know this works as intended on Linux and Cygwin, and I did run crawl -test to double check stuff. UPDATE: I have now verified that it works with Tiles! However, I can't test with Windows, Mac, etc. I may or may not have broken the sound stuff. At worst, some more files need to be included in sound.cc. Finally, the game works as normal when compiled without sound support. I only tested this in Linux, but I'm certain that it should be the same everywhere else. Happy crawling! ~Autofire
1 parent f3a60fd commit 4270d38

25 files changed

+341
-78
lines changed

crawl-ref/INSTALL.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ changes to the level compiler, you'll need the flex and bison/byacc tools
8989
(Other lex/yaccs may also work). More details are available below.
9090

9191
Sound can be provided by SDL2_mixer (the default), by WINMM on Windows (defined
92-
by WINMM_PLAY_SOUNDS in AppHdr.h), or by an external command on Unix systems
93-
(SOUND_PLAY_COMMAND in AppHdr.h). To enable this, append SOUND=y to the make
92+
by WINMM_PLAY_SOUNDS in sound.h), or by an external command on Unix systems
93+
(SOUND_PLAY_COMMAND in sound.h). To enable this, append SOUND=y to the make
9494
invocation.
9595

9696
Crawl includes Lua 5.1.4 in its submodules. Crawl uses Lua for dungeon

crawl-ref/docs/keybind.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ Meta-commands
111111
^A CMD_TOGGLE_AUTOPICKUP
112112
^C CMD_CLEAR_MAP
113113
^D, ~ CMD_MACRO_ADD
114+
<unbound> CMD_TOGGLE_SOUND (only when compiled with sound)
114115
^Q CMD_QUIT
115116
^R CMD_REDRAW_SCREEN
116117
S CMD_SAVE_GAME

crawl-ref/docs/options_guide.txt

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ The contents of this text are:
1919
restart_after_game, restart_after_save,
2020
default_manual_training, autopickup_starting_ammo
2121
2- File System and Sound.
22-
crawl_dir, morgue_dir, save_dir, macro_dir, sound
22+
crawl_dir, morgue_dir, save_dir, macro_dir, sound, hold_sound,
23+
sound_file_path
2324
3- Interface.
2425
3-a Dropping and Picking up.
2526
autopickup, autopickup_exceptions, default_autopickup,
@@ -397,10 +398,36 @@ macro_dir = settings/
397398
It should end with the path delimiter.
398399

399400
sound ^= <regex>:<path to sound file>, <regex>:<path>, ...
401+
(Requires "Sound support"; check your version info)
400402
(Ordered list option)
401403
Plays the sound file if a message contains regex. The regex
402404
should not include commas or colons. For example
403405
sound += LOW HITPOINT WARNING:sound\sounds2\danger3.wav
406+
There are certain pre-defined regexes, as well, which can be
407+
used to get a sound to trigger for something that cannot
408+
otherwise be matched using a regex string. For example,
409+
using FIRE_PROMPT_SOUND for the regex will cause Crawl to
410+
play a sound whenever the fire prompt is opened. Check
411+
sound.h for a full listing of all these pre-defined regex
412+
strings.
413+
414+
sound_file_path = <path>
415+
When playing sounds (with the option above), the contents of
416+
this variable is appended to the start of the path. This is
417+
intended to make it easier to take one configuration across
418+
several platforms. These two lines are equivalent to the
419+
example above:
420+
sound_file_path = sound\sounds2\
421+
sound += LOW HITPOINT WARNING:danger3.wav
422+
The most recent instance of this option is the one that
423+
takes effect, and is not applied retroactively to previous
424+
instances of the sound option.
425+
426+
one_SDL_sound_channel = false
427+
When true, only one sound can play at a time (if using SDL).
428+
Is false by default since non-SDL sound backends don't
429+
support such control.
430+
404431

405432
3- Interface.
406433
==============

crawl-ref/source/AppHdr.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,6 @@ static inline double pow(int x, double y) { return std::pow((double)x, y); }
148148
// uncomment the line below and add -lpcre to your makefile.
149149
// #define REGEX_PCRE
150150

151-
// Uncomment (and edit as appropriate) to play sounds.
152-
//
153-
// WARNING: Filenames passed to this command *are not validated in any way*.
154-
//
155-
// #define SOUND_PLAY_COMMAND "/usr/bin/play -v .5 \"%s\" 2>/dev/null &"
156-
157151
#include "libunix.h"
158152

159153
#elif defined(TARGET_OS_WINDOWS)
@@ -172,9 +166,6 @@ static inline double pow(int x, double y) { return std::pow((double)x, y); }
172166
#define FILE_SEPARATOR '/'
173167
#define ALT_FILE_SEPARATOR '\\'
174168

175-
// Uncomment to play sounds. winmm must be linked in if this is uncommented.
176-
// #define WINMM_PLAY_SOUNDS
177-
178169
// Use Perl-compatible regular expressions. libpcre must be available and
179170
// linked in. Required in the absence of POSIX regexes.
180171
#ifndef REGEX_PCRE

crawl-ref/source/MSVC/crawl.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ perl.exe "util/gen-cflg.pl" compflag.h "&lt;UNKNOWN&gt;" "&lt;UNKNOWN&gt;"
468468
<ClCompile Include="..\skills.cc" />
469469
<ClCompile Include="..\skill-menu.cc" />
470470
<ClCompile Include="..\species.cc" />
471+
<ClCompile Include="..\sound.cc" />
471472
<ClCompile Include="..\spl-book.cc" />
472473
<ClCompile Include="..\spl-cast.cc" />
473474
<ClCompile Include="..\spl-clouds.cc" />

crawl-ref/source/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
# Typical parameters:
1919
# TILES -- set to anything to enable tiles build
2020
#
21-
# SOUND -- set to anything to enable sound
21+
# SOUND -- set to anything to enable sound; note that you will need to
22+
# uncomment some lines in sound.h if not building tiles
2223
#
2324
# CROSSHOST -- target system, eg, i386-pc-msdosdjgpp or i586-mingw32msvc
2425
#

crawl-ref/source/Makefile.obj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ show.o \
202202
showsymb.o \
203203
skill-menu.o \
204204
skills.o \
205+
sound.o \
205206
species.o \
206207
spl-book.o \
207208
spl-cast.o \

crawl-ref/source/android-project/jni/src/Android.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ LOCAL_SRC_FILES := $(SDL_PATH)/src/main/android/SDL_android_main.c \
222222
$(CRAWL_PATH)/showsymb.cc \
223223
$(CRAWL_PATH)/skill-menu.cc \
224224
$(CRAWL_PATH)/skills.cc \
225+
$(CRAWL_PATH)/sound.cc \
225226
$(CRAWL_PATH)/species.cc \
226227
$(CRAWL_PATH)/spl-book.cc \
227228
$(CRAWL_PATH)/spl-cast.cc \

crawl-ref/source/command-type.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ enum command_type
5151
CMD_GO_UPSTAIRS,
5252
CMD_GO_DOWNSTAIRS,
5353
CMD_TOGGLE_AUTOPICKUP,
54+
CMD_TOGGLE_SOUND,
5455
CMD_TOGGLE_TRAVEL_SPEED,
5556
CMD_PICKUP,
5657
CMD_PICKUP_QUANTITY,

crawl-ref/source/command.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "output.h"
2828
#include "prompt.h"
2929
#include "showsymb.h"
30+
#include "sound.h"
3031
#include "state.h"
3132
#include "stringutil.h"
3233
#include "syscalls.h"
@@ -65,8 +66,8 @@ static const char *features[] =
6566
"Glob patterns",
6667
#endif
6768

68-
#if defined(SOUND_PLAY_COMMAND) || defined(WINMM_PLAY_SOUNDS)
69-
"Sound support",
69+
#if defined(USE_SOUND) && defined(SOUND_BACKEND)
70+
SOUND_BACKEND,
7071
#endif
7172

7273
#ifdef DGL_MILESTONES
@@ -1026,6 +1027,9 @@ static void _add_formatted_keyhelp(column_composer &cols)
10261027
_add_command(cols, 1, CMD_SHOW_TERRAIN, "toggle view layers");
10271028
_add_command(cols, 1, CMD_DISPLAY_OVERMAP, "show dungeon Overview");
10281029
_add_command(cols, 1, CMD_TOGGLE_AUTOPICKUP, "toggle auto-pickup");
1030+
#ifdef USE_SOUND
1031+
_add_command(cols, 1, CMD_TOGGLE_SOUND, "mute/unmute sound effects");
1032+
#endif
10291033
_add_command(cols, 1, CMD_TOGGLE_TRAVEL_SPEED, "set your travel speed to your");
10301034
cols.add_formatted(1, " slowest ally\n",
10311035
false);

0 commit comments

Comments
 (0)