Skip to content

Commit

Permalink
Make DosBeep volume configurable.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Jul 10, 2018
1 parent 1fd6bab commit b8f6764
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
16 changes: 16 additions & 0 deletions lib2ine.c
Expand Up @@ -384,6 +384,17 @@ static void cfgProcessBoolString(const char *fname, const int lineno, int *outpu
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];
Expand Down Expand Up @@ -426,6 +437,8 @@ static void cfgProcessSystem(const char *fname, const int lineno, const char *va
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);
}
Expand Down Expand Up @@ -818,6 +831,9 @@ LX_NATIVE_CONSTRUCTOR(lib2ine)
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();

Expand Down
1 change: 1 addition & 0 deletions lib2ine.h
Expand Up @@ -299,6 +299,7 @@ typedef struct LxLoaderState
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;
Expand Down
3 changes: 2 additions & 1 deletion native/doscalls.c
Expand Up @@ -3151,6 +3151,7 @@ static DosBeepGeneratorInfo dos_beep_info;

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);

Expand All @@ -3177,7 +3178,7 @@ static int DosBeepGenerator(void *userdata, float *stream, int samples, int freq
}
} 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;
Expand Down

0 comments on commit b8f6764

Please sign in to comment.