Make DosBeep volume configurable.
authorRyan C. Gordon <icculus@icculus.org>
Tue, 10 Jul 2018 02:00:31 -0400
changeset 153 4dc11e50df15
parent 152 975c7b2f35a8
child 154 978ad040e00e
Make DosBeep volume configurable.
lib2ine.c
lib2ine.h
native/doscalls.c
--- a/lib2ine.c	Tue Jul 10 01:45:05 2018 -0400
+++ b/lib2ine.c	Tue Jul 10 02:00:31 2018 -0400
@@ -384,6 +384,17 @@
     cfgWarn(fname, lineno, "\"%s\" is not valid for this setting. Try 1 or 0.", val);
 }
 
+static void cfgProcessFloatString(const char *fname, const int lineno, float *output, const char *val)
+{
+    errno = 0;
+    const float converted = strtof(val, NULL);
+    if (!errno) {
+        *output = converted;
+    } else {
+        cfgWarn(fname, lineno, "\"%s\" is not valid for this setting. Try a number.", val);
+    }
+}
+
 static void cfgProcessMountPoint(const char *fname, const int lineno, const char *var, const char *val)
 {
     char letter = var[0];
@@ -426,6 +437,8 @@
         cfgProcessBoolString(fname, lineno, &GLoaderState.trace_native, val);
     } else if (strcmp(var, "trace_events") == 0) {
         cfgProcessBoolString(fname, lineno, &GLoaderState.trace_events, val);
+    } else if (strcmp(var, "beep_volume") == 0) {
+        cfgProcessFloatString(fname, lineno, &GLoaderState.beep_volume, val);
     } else {
         cfgWarn(fname, lineno, "Unknown variable system.%s", var);
     }
@@ -818,6 +831,9 @@
     GLoaderState.registerAudioGenerator = registerAudioGenerator_lib2ine;
     GLoaderState.lib2ine_shutdown = lib2ine_shutdown;
 
+    // VMware emulates the PC Speaker on a sound card _really_ quietly.
+    GLoaderState.beep_volume = 0.05f;
+
     cfgLoadFiles();
     prepOs2Drives();
 
--- a/lib2ine.h	Tue Jul 10 01:45:05 2018 -0400
+++ b/lib2ine.h	Tue Jul 10 02:00:31 2018 -0400
@@ -299,6 +299,7 @@
     char *current_dir[26];  // current directory, per-disk, A: through Z: ... NULL if unmounted.
     int current_disk;  // 1==A:\\, 2==B:\\, etc.
     uint32 diskmap;  // 1<<0==drive A mounted, 1<<1==drive B mounted, etc.
+    float beep_volume;
     uint8 main_tib_selector;
     uint32 mainstacksize;
     uint16 original_cs;
--- a/native/doscalls.c	Tue Jul 10 01:45:05 2018 -0400
+++ b/native/doscalls.c	Tue Jul 10 02:00:31 2018 -0400
@@ -3151,6 +3151,7 @@
 
 static int DosBeepGenerator(void *userdata, float *stream, int samples, int freq)
 {
+    const float beep_volume = GLoaderState.beep_volume;
     DosBeepGeneratorInfo *info = &dos_beep_info;
     assert(userdata == &dos_beep_info);
 
@@ -3177,7 +3178,7 @@
             }
         } else {  // still generating the current piece of the square wave, mix it into the stream.
             // VMware emulates the PC Speaker on a sound card _really_ quietly.
-            const float val = info->positive ? 0.05f : -0.05f;
+            const float val = info->positive ? beep_volume : -beep_volume;
             int total = info->square_remaining;
             if (info->samples_remaining < total) total = info->samples_remaining;
             if (samples < total) total = samples;