From d4c75d26d9279510c5d770f1c8295d20ab498767 Mon Sep 17 00:00:00 2001 From: David Griffith Date: Wed, 5 Jun 2019 01:36:39 -0700 Subject: [PATCH] Don't activate sound subsystem if SOUND_FLAG or OLD_SOUND_FLAG is not set. --- src/common/err.c | 3 ++- src/common/frotz.h | 5 +++-- src/common/setup.h | 1 + src/common/sound.c | 16 ++++++++++++---- src/curses/ux_audio.c | 7 +++++++ 5 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/common/err.c b/src/common/err.c index e1c6f1b..296e602 100644 --- a/src/common/err.c +++ b/src/common/err.c @@ -62,7 +62,8 @@ static char *err_messages[] = { "@move_object called moving object 0", "@move_object called moving into object 0", "@remove_object called with object 0", - "@get_next_prop called with object 0" + "@get_next_prop called with object 0", + "@play_sound called without SOUND_FLAG or OLD_SOUND_FLAG set" }; static void print_long (unsigned long value, int base); diff --git a/src/common/frotz.h b/src/common/frotz.h index 09bd0c4..3abad43 100644 --- a/src/common/frotz.h +++ b/src/common/frotz.h @@ -740,8 +740,9 @@ void runtime_error (int); #define ERR_MOVE_OBJECT_TO_0 30 /* @move_object called moving into object 0 */ #define ERR_REMOVE_OBJECT_0 31 /* @remove_object called with object 0 */ #define ERR_GET_NEXT_PROP_0 32 /* @get_next_prop called with object 0 */ -#define ERR_NUM_ERRORS (32) - +#define ERR_PLAY_SOUND 33 /* @play_sound called without SOUND_FLAG or OLD_SOUND_FLAG set */ +#define ERR_NUM_ERRORS (33) + /* There are four error reporting modes: never report errors; report only the first time a given error type occurs; report every time an error occurs; or treat all errors as fatal diff --git a/src/common/setup.h b/src/common/setup.h index c2a43eb..e81e5e8 100644 --- a/src/common/setup.h +++ b/src/common/setup.h @@ -18,6 +18,7 @@ typedef struct frotz_setup_struct { int expand_abbreviations; int script_cols; int sound; + int sound_flag; int err_report_mode; char *story_file; diff --git a/src/common/sound.c b/src/common/sound.c index e5e29e7..7c2e656 100644 --- a/src/common/sound.c +++ b/src/common/sound.c @@ -48,10 +48,13 @@ static bool playing = FALSE; */ void init_sound (void) { - locked = FALSE; - playing = FALSE; - - os_init_sound(); + if ((h_flags & SOUND_FLAG) || (h_flags & OLD_SOUND_FLAG)) { + f_setup.sound_flag = TRUE; + locked = FALSE; + playing = FALSE; + os_init_sound(); + } else + f_setup.sound_flag = FALSE; } /* init_sound */ @@ -155,6 +158,11 @@ void z_sound_effect (void) if (zargc < 3) volume = 8; + if (!f_setup.sound_flag) { + runtime_error(ERR_PLAY_SOUND); + return; + } + if (number >= 3 || number == 0) { locked = TRUE; diff --git a/src/curses/ux_audio.c b/src/curses/ux_audio.c index a178ffe..73a49e6 100644 --- a/src/curses/ux_audio.c +++ b/src/curses/ux_audio.c @@ -41,8 +41,11 @@ #include "../blorb/blorb.h" #include "../blorb/blorblow.h" +#include "ux_frotz.h" #include "ux_audio.h" +f_setup_t f_setup; + #ifndef NO_SOUND #include @@ -777,6 +780,8 @@ os_init_sound(void) int err; static pthread_attr_t attr; + if (!f_setup.sound_flag) return; + /*Initialize sound engine*/ /*audio_log = fopen("audio_log.txt", "w");*/ /*fprintf(audio_log, "os_init_sound...\n");*/ @@ -833,6 +838,7 @@ os_start_sample(int number, int volume, int repeats, zword eos) const float vol = volume_factor(volume); sound_stream_t *s = 0; + if (!f_setup.sound_flag) return; /*Load resource from BLORB data*/ if(blorb_map == NULL) return; @@ -882,6 +888,7 @@ void os_prepare_sample(int id) void os_stop_sample(int id) { /*fprintf(audio_log, "os_stop_sample(%d)...\n", id);*/ + if (!f_setup.sound_flag) return; sound_stop_id(id); } -- 2.34.1