ref: bad402578da34451e9a228d913817d0e6b3a532b
parent: 044b3e839ac50ec92e5a72616a30f703e00df5d7
author: Alex Mayfield <alexmax2742@gmail.com>
date: Wed Mar 8 19:03:22 EST 2017
Pass sample rate to midiproc
--- 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 @@
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 @@
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 ")
@@ -402,6 +405,14 @@
TEXT(PACKAGE_STRING), MB_OK | MB_ICONASTERISK);
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())
--- a/src/i_midipipe.c
+++ b/src/i_midipipe.c
@@ -367,6 +367,7 @@
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 @@
}
*(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))