commit bad402578da34451e9a228d913817d0e6b3a532b
Author: Alex Mayfield <alexmax2742@gmail.com>
AuthorDate: Thu Mar 9 00:03:22 2017 -0500
Commit: Alex Mayfield <alexmax2742@gmail.com>
CommitDate: Thu Mar 9 00:03:22 2017 -0500
Pass sample rate to midiproc
---
midiproc/main.c | 15 +++++++++++++--
src/i_midipipe.c | 8 +++++++-
2 files changed, 20 insertions(+), 3 deletions(-)
diff --git a/midiproc/main.c b/midiproc/main.c
index 1908bc75..42ffa07d 100644
--- a/midiproc/main.c
+++ b/midiproc/main.c
@@ -42,6 +42,9 @@
static HANDLE midi_process_in; // Standard In.
static HANDLE midi_process_out; // Standard Out.
+// Sound sample rate to use for digital output (Hz)
+static int snd_samplerate = 0;
+
// Currently playing music track.
static Mix_Music *music = NULL;
@@ -335,7 +338,7 @@ boolean InitSDL()
return false;
}
- if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048) < 0)
+ if (Mix_OpenAudio(snd_samplerate, MIX_DEFAULT_FORMAT, 2, 2048) < 0)
{
return false;
}
@@ -382,7 +385,7 @@ fail:
int main(int argc, char *argv[])
{
// Make sure we're not launching this process by itself.
- if (argc < 2)
+ if (argc < 3)
{
MessageBox(NULL, TEXT("This program is tasked with playing Native ")
TEXT("MIDI music, and is intended to be launched by ")
@@ -404,6 +407,14 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
}
+ // Parse out the sample rate - if we can't, default to 44100.
+ snd_samplerate = strtol(argv[2], NULL, 10);
+ if (snd_samplerate == LONG_MAX || snd_samplerate == LONG_MIN ||
+ snd_samplerate == 0)
+ {
+ snd_samplerate = 44100;
+ }
+
if (!InitPipes())
{
return EXIT_FAILURE;
diff --git a/src/i_midipipe.c b/src/i_midipipe.c
index fdc61864..0d80ccfc 100644
--- a/src/i_midipipe.c
+++ b/src/i_midipipe.c
@@ -367,6 +367,7 @@ boolean I_MidiPipe_InitServer()
char *fp = NULL;
char *module = NULL;
char *cmdline = NULL;
+ char snd_samplerate_buf[8];
SECURITY_ATTRIBUTES sec_attrs;
PROCESS_INFORMATION proc_info;
STARTUPINFO startup_info;
@@ -391,7 +392,12 @@ boolean I_MidiPipe_InitServer()
}
*(fp + 1) = '\0';
module = M_StringJoin(filename, PROGRAM_PREFIX "midiproc.exe", NULL);
- cmdline = M_StringJoin(module, " \"" PACKAGE_STRING "\"", NULL);
+
+ // Add package string and current sample rate value to command line
+ M_snprintf(snd_samplerate_buf, sizeof(snd_samplerate_buf),
+ "%d", snd_samplerate);
+ cmdline = M_StringJoin(module, " \"" PACKAGE_STRING "\"", " ",
+ snd_samplerate_buf, NULL);
// Look for executable file
if(stat(module, &sbuf))