[Scummvm-devel] Linux music progress report (with Timidity)
Lionel Ulmer
lionel.ulmer at free.fr
Sun Nov 18 15:19:01 CET 2001
Hi all,
Just wanted to inform all Penguin lovers that I made some progress in Linux
music support : I now have Timidity playing the MIDI music from Day of the
Tentacle...
I attached the patch that does it to this mail. For this you need first to
start Timidity with the following command line :
timidity -irv 7777
Then just start ScummVM and you should have sound.
Now, the last hurdle remains : mixing the sound output with Timidity's midi
output... I will try to continue a bit tonight, but it starts to get late
here :-)
Lionel
--
Lionel Ulmer - http://www.bbrox.org/
-------------- next part --------------
? scummvm
? test
? test.c
Index: imuse.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/imuse.cpp,v
retrieving revision 1.1
diff -u -r1.1 imuse.cpp
--- imuse.cpp 2001/11/14 18:37:38 1.1
+++ imuse.cpp 2001/11/18 23:16:51
@@ -23,6 +23,19 @@
#include "scumm.h"
#include "sound.h"
+#include <sys/time.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netdb.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+/* Copy-pasted from Timidity */
+#define SEQ_MIDIPUTC 5
+
#define ARRAYSIZE(x) (sizeof(x)/sizeof(x[0]))
#define TICKS_PER_BEAT 480
@@ -2443,17 +2456,110 @@
}
}
+#if defined(WIN32)
void SoundEngine::midiInit() {
-#ifdef WIN32
if (midiOutOpen((HMIDIOUT*)&_mo, MIDI_MAPPER, NULL, NULL, 0) != MMSYSERR_NOERROR)
error("midiOutOpen failed");
-#endif
}
-#ifdef WIN32
#define MIDI_OUT(a,b) midiOutShortMsg((HMIDIOUT)(a), (b))
+
#else
-#define MIDI_OUT(a,b)
+static int connect_to_timidity(int port) {
+ struct hostent *serverhost;
+ struct sockaddr_in sadd;
+ int s;
+
+ serverhost = gethostbyname("localhost");
+ if (serverhost == NULL)
+ error("Could not resolve host");
+ sadd.sin_family = serverhost->h_addrtype;
+ sadd.sin_port = htons(port);
+ memcpy(&(sadd.sin_addr), serverhost->h_addr_list[0], serverhost->h_length);
+
+ s = socket(AF_INET,SOCK_STREAM,0);
+ if (s < 0)
+ error("Could not open socket");
+ if (connect(s, (struct sockaddr *) &sadd, sizeof(struct sockaddr_in)) < 0)
+ error("Could not connect to server");
+
+ return s;
+}
+
+void SoundEngine::midiInit() {
+ int s, s2;
+ int len;
+ int dummy, newport;
+ char buf[256];
+
+ s = connect_to_timidity(7777);
+ len = read(s, buf, 256);
+ buf[len] = '\0';
+ printf("%s", buf);
+
+ sprintf(buf, "SETBUF %f %f\n", 0.1, 0.15);
+ write(s, buf, strlen(buf));
+ len = read(s, buf, 256);
+ buf[len] = '\0';
+ printf("%s", buf);
+
+
+ sprintf(buf, "OPEN lsb\n");
+ write(s, buf, strlen(buf));
+ len = read(s, buf, 256);
+ buf[len] = '\0';
+ printf("%s", buf);
+
+ sscanf(buf, "%d %d", &dummy, &newport);
+ printf(" => port = %d\n", newport);
+
+ s2 = connect_to_timidity(newport);
+ _mo = (void *) s2;
+}
+
+#define DEVICE_NUM 0
+
+static inline void MIDI_OUT(void *a, int b) {
+ int s = (int) a;
+ unsigned char buf[256];
+ int position = 0;
+
+ switch (b & 0xF0) {
+ case 0x80:
+ case 0x90:
+ case 0xA0:
+ case 0xB0:
+ case 0xE0:
+ buf[position++] = SEQ_MIDIPUTC;
+ buf[position++] = b;
+ buf[position++] = DEVICE_NUM;
+ buf[position++] = 0;
+ buf[position++] = SEQ_MIDIPUTC;
+ buf[position++] = (b >> 8) & 0x7F;
+ buf[position++] = DEVICE_NUM;
+ buf[position++] = 0;
+ buf[position++] = SEQ_MIDIPUTC;
+ buf[position++] = (b >> 16) & 0x7F;
+ buf[position++] = DEVICE_NUM;
+ buf[position++] = 0;
+ break;
+ case 0xC0:
+ case 0xD0:
+ buf[position++] = SEQ_MIDIPUTC;
+ buf[position++] = b;
+ buf[position++] = DEVICE_NUM;
+ buf[position++] = 0;
+ buf[position++] = SEQ_MIDIPUTC;
+ buf[position++] = (b >> 8) & 0x7F;
+ buf[position++] = DEVICE_NUM;
+ buf[position++] = 0;
+ break;
+ default:
+ fprintf(stderr, "Unknown : %08x\n", b);
+ break;
+ }
+ write(s, buf, position);
+}
#endif
void SoundEngine::midiPitchBend(byte chan, int16 pitchbend) {
@@ -2526,4 +2632,4 @@
void SoundEngine::midiSilence(byte chan) {
MIDI_OUT(_mo, (64<<8)|0xB0|chan);
MIDI_OUT(_mo, (123<<8)|0xB0|chan);
-}
\ No newline at end of file
+}
More information about the Scummvm-devel
mailing list