Ticket #7920: mididriver.diff
File mididriver.diff, 15.6 KB (added by , 23 years ago) |
---|
-
Makefile
Common subdirectories: scummvm.orig/CVS and scummvm.new/CVS diff -u scummvm.orig/Makefile scummvm.new/Makefile
old new 2 2 3 3 CC = gcc 4 4 CFLAGS = -g -Wno-multichar 5 DEFINES = -DUNIX -DHAVE_READLINE -DUSE_TIMIDITY5 DEFINES = -DUNIX -DHAVE_READLINE 6 6 LDFLAGS := 7 7 INCLUDES:= `sdl-config --cflags` 8 8 CPPFLAGS= $(DEFINES) $(INCLUDES) -
imuse.cpp
Common subdirectories: scummvm.orig/debian and scummvm.new/debian diff -u scummvm.orig/imuse.cpp scummvm.new/imuse.cpp
old new 26 26 #include "scumm.h" 27 27 #include "sound.h" 28 28 29 #ifdef USE_TIMIDITY 29 /* includes needed for unix midi support through timidity or internal sequencer */ 30 #ifndef WIN32 31 30 32 #include <sys/time.h> 31 33 #include <unistd.h> 32 34 #include <sys/types.h> … … 40 42 /* Copy-pasted from Timidity */ 41 43 #define SEQ_MIDIPUTC 5 42 44 43 #endif /* USE_TIMIDITY */45 #endif 44 46 45 47 #define ARRAYSIZE(x) (sizeof(x)/sizeof(x[0])) 46 48 … … 155 157 return 0; 156 158 } 157 159 160 void SoundEngine::midiSetDriver(int devicetype, int seq_device) { 161 _midi_driver.DeviceType = devicetype; 162 _midi_driver.SeqDevice = seq_device; 163 _midi_driver.midiInit(); 164 } 165 166 void SoundEngine::midiSetDriver(int devicetype) { 167 _midi_driver.DeviceType = devicetype; 168 _midi_driver.midiInit(); 169 } 170 171 int MidiDriver::connect_to_timidity(int port) { 172 struct hostent *serverhost; 173 struct sockaddr_in sadd; 174 int s; 175 176 serverhost = gethostbyname("localhost"); 177 if (serverhost == NULL) 178 error("Could not resolve host"); 179 sadd.sin_family = serverhost->h_addrtype; 180 sadd.sin_port = htons(port); 181 memcpy(&(sadd.sin_addr), serverhost->h_addr_list[0], serverhost->h_length); 182 183 s = socket(AF_INET,SOCK_STREAM,0); 184 if (s < 0) 185 error("Could not open socket"); 186 if (connect(s, (struct sockaddr *) &sadd, sizeof(struct sockaddr_in)) < 0) 187 error("Could not connect to server"); 188 189 return s; 190 } 191 192 int MidiDriver::open_sequencer_device() { 193 int device; 194 device = (open("/dev/sequencer", O_RDWR, 0)); 195 if (device < 0) { 196 warning("Cannot open sequencer device - using /dev/null (no music will be heard) "); 197 device = (open(("/dev/null"), O_RDWR, 0)); 198 if (device < 0) 199 error("Cannot open /dev/null to dump midi output"); 200 } 201 return device; 202 } 203 204 void MidiDriver::midiInitTimidity() { 205 int s, s2; 206 int len; 207 int dummy, newport; 208 char buf[256]; 209 210 SeqDevice = 0; 211 212 s = connect_to_timidity(7777); 213 len = read(s, buf, 256); 214 buf[len] = '\0'; 215 printf("%s", buf); 216 217 sprintf(buf, "SETBUF %f %f\n", 0.1, 0.15); 218 write(s, buf, strlen(buf)); 219 len = read(s, buf, 256); 220 buf[len] = '\0'; 221 printf("%s", buf); 222 223 sprintf(buf, "OPEN lsb\n"); 224 write(s, buf, strlen(buf)); 225 len = read(s, buf, 256); 226 buf[len] = '\0'; 227 printf("%s", buf); 228 229 sscanf(buf, "%d %d", &dummy, &newport); 230 printf(" => port = %d\n", newport); 231 232 s2 = connect_to_timidity(newport); 233 _mo = (void *) s2; 234 } 235 236 void MidiDriver::midiInitSeq() { 237 int device; 238 device = open_sequencer_device(); 239 _mo = (void *) device; 240 } 241 242 void MidiDriver::midiInitWindows() { 243 #ifdef WIN32 244 if (midiOutOpen((HMIDIOUT*)&_mo, MIDI_MAPPER, NULL, NULL, 0) != MMSYSERR_NOERROR) 245 error("midiOutOpen failed"); 246 #endif 247 } 248 249 void MidiDriver::midiInitNull() { 250 warning("Using the NULL midi driver, no music will be heard"); 251 } 252 253 void MidiDriver::midiInit() { 254 if (MidiInitialized != true) { 255 switch (DeviceType) { 256 case MIDI_NULL: 257 midiInitNull(); 258 break; 259 case MIDI_WINDOWS: 260 midiInitWindows(); 261 break; 262 case MIDI_TIMIDITY: 263 midiInitTimidity(); 264 break; 265 case MIDI_SEQ: 266 midiInitSeq(); 267 break; 268 default: 269 #ifdef WIN32 270 midiInitWindows(); 271 #else 272 DeviceType = 0; 273 midiInitNull(); 274 #endif 275 break; 276 } 277 MidiInitialized = true; 278 } else { 279 error("Midi driver already initialized"); 280 } 281 } 282 283 void MidiDriver::MidiOutSeq(void *a, int b) { 284 int s = (int) a; 285 unsigned char buf[256]; 286 int position = 0; 287 switch (b & 0xF0) { 288 case 0x80: 289 case 0x90: 290 case 0xA0: 291 case 0xB0: 292 case 0xE0: 293 buf[position++] = SEQ_MIDIPUTC; 294 buf[position++] = b; 295 buf[position++] = SeqDevice; 296 buf[position++] = 0; 297 buf[position++] = SEQ_MIDIPUTC; 298 buf[position++] = (b >> 8) & 0x7F; 299 buf[position++] = SeqDevice; 300 buf[position++] = 0; 301 buf[position++] = SEQ_MIDIPUTC; 302 buf[position++] = (b >> 16) & 0x7F; 303 buf[position++] = SeqDevice; 304 buf[position++] = 0; 305 break; 306 case 0xC0: 307 case 0xD0: 308 buf[position++] = SEQ_MIDIPUTC; 309 buf[position++] = b; 310 buf[position++] = SeqDevice; 311 buf[position++] = 0; 312 buf[position++] = SEQ_MIDIPUTC; 313 buf[position++] = (b >> 8) & 0x7F; 314 buf[position++] = SeqDevice; 315 buf[position++] = 0; 316 break; 317 default: 318 fprintf(stderr, "Unknown : %08x\n", b); 319 break; 320 } 321 write(s, buf, position); 322 } 323 324 void MidiDriver::MidiOutWindows(void *a, int b) { 325 #ifdef WIN32 326 midiOutShortMsg((HMIDIOUT) a, b); 327 #endif 328 } 329 330 void MidiDriver::MidiOut(void *a, int b) { 331 if (MidiInitialized != true) { 332 #ifdef WIN32 333 DeviceType = MIDI_WINDOWS; 334 midiInit(); 335 #else 336 DeviceType = MIDI_NULL; 337 midiInit(); 338 #endif 339 } 340 341 if (MidiInitialized == true) { 342 switch (DeviceType) { 343 case MIDI_NULL: 344 break; 345 case MIDI_WINDOWS: 346 MidiOutWindows(a, b); 347 break; 348 case MIDI_TIMIDITY: 349 case MIDI_SEQ: 350 MidiOutSeq(a, b); 351 break; 352 default: 353 error("Invalid midi device type "); 354 break; 355 } 356 } else { 357 warning("Trying to write midi data without the driver being initialized"); 358 } 359 } 360 158 361 /**********************************************************************/ 159 362 160 363 byte *SoundEngine::findTag(int sound, char *tag, int index) { … … 914 1117 init_volume_fader(); 915 1118 init_queue(); 916 1119 init_parts(); 917 midiInit();918 1120 919 1121 _initialized = true; 920 1122 … … 2462 2664 } 2463 2665 } 2464 2666 2465 #if defined(WIN32)2466 2467 void SoundEngine::midiInit() {2468 if (midiOutOpen((HMIDIOUT*)&_mo, MIDI_MAPPER, NULL, NULL, 0) != MMSYSERR_NOERROR)2469 error("midiOutOpen failed");2470 }2471 2472 #define MIDI_OUT(a,b) midiOutShortMsg((HMIDIOUT)(a), (b))2473 2474 #elif defined(USE_TIMIDITY)2475 2476 static int connect_to_timidity(int port)2477 {2478 struct hostent *serverhost;2479 struct sockaddr_in sadd;2480 int s;2481 2482 serverhost = gethostbyname("localhost");2483 if (serverhost == NULL)2484 error("Could not resolve host");2485 sadd.sin_family = serverhost->h_addrtype;2486 sadd.sin_port = htons(port);2487 memcpy(&(sadd.sin_addr), serverhost->h_addr_list[0], serverhost->h_length);2488 2489 s = socket(AF_INET,SOCK_STREAM,0);2490 if (s < 0)2491 error("Could not open socket");2492 if (connect(s, (struct sockaddr *) &sadd, sizeof(struct sockaddr_in)) < 0)2493 error("Could not connect to server");2494 2495 return s;2496 }2497 2498 void SoundEngine::midiInit() {2499 int s, s2;2500 int len;2501 int dummy, newport;2502 char buf[256];2503 2504 s = connect_to_timidity(7777);2505 len = read(s, buf, 256);2506 buf[len] = '\0';2507 printf("%s", buf);2508 2509 sprintf(buf, "SETBUF %f %f\n", 0.1, 0.15);2510 write(s, buf, strlen(buf));2511 len = read(s, buf, 256);2512 buf[len] = '\0';2513 printf("%s", buf);2514 2515 sprintf(buf, "OPEN lsb\n");2516 write(s, buf, strlen(buf));2517 len = read(s, buf, 256);2518 buf[len] = '\0';2519 printf("%s", buf);2520 2521 sscanf(buf, "%d %d", &dummy, &newport);2522 printf(" => port = %d\n", newport);2523 2524 s2 = connect_to_timidity(newport);2525 _mo = (void *) s2;2526 }2527 2528 #define DEVICE_NUM 02529 2530 static inline void MIDI_OUT(void *a, int b) {2531 int s = (int) a;2532 unsigned char buf[256];2533 int position = 0;2534 2535 switch (b & 0xF0) {2536 case 0x80:2537 case 0x90:2538 case 0xA0:2539 case 0xB0:2540 case 0xE0:2541 buf[position++] = SEQ_MIDIPUTC;2542 buf[position++] = b;2543 buf[position++] = DEVICE_NUM;2544 buf[position++] = 0;2545 buf[position++] = SEQ_MIDIPUTC;2546 buf[position++] = (b >> 8) & 0x7F;2547 buf[position++] = DEVICE_NUM;2548 buf[position++] = 0;2549 buf[position++] = SEQ_MIDIPUTC;2550 buf[position++] = (b >> 16) & 0x7F;2551 buf[position++] = DEVICE_NUM;2552 buf[position++] = 0;2553 break;2554 case 0xC0:2555 case 0xD0:2556 buf[position++] = SEQ_MIDIPUTC;2557 buf[position++] = b;2558 buf[position++] = DEVICE_NUM;2559 buf[position++] = 0;2560 buf[position++] = SEQ_MIDIPUTC;2561 buf[position++] = (b >> 8) & 0x7F;2562 buf[position++] = DEVICE_NUM;2563 buf[position++] = 0;2564 break;2565 default:2566 fprintf(stderr, "Unknown : %08x\n", b);2567 break;2568 }2569 write(s, buf, position);2570 }2571 2572 #else2573 #define MIDI_OUT(a,b)2574 void SoundEngine::midiInit() { }2575 #endif2576 2577 2667 void SoundEngine::midiPitchBend(byte chan, int16 pitchbend) { 2578 2668 uint16 tmp; 2579 2669 2580 2670 if (_midi_pitchbend_last[chan] != pitchbend) { 2581 2671 _midi_pitchbend_last[chan] = pitchbend; 2582 2672 tmp = (pitchbend<<2) + 0x2000; 2583 MIDI_OUT(_mo, ((tmp>>7)&0x7F)<<16 | (tmp&0x7F)<<8 | 0xE0 | chan);2673 _midi_driver.MidiOut(_midi_driver._mo, ((tmp>>7)&0x7F)<<16 | (tmp&0x7F)<<8 | 0xE0 | chan); 2584 2674 } 2585 2675 } 2586 2676 2587 2677 void SoundEngine::midiVolume(byte chan, byte volume) { 2588 2678 if (_midi_volume_last[chan] != volume) { 2589 2679 _midi_volume_last[chan] = volume; 2590 MIDI_OUT(_mo, volume<<16 | 7<<8 | 0xB0 | chan);2680 _midi_driver.MidiOut(_midi_driver._mo, volume<<16 | 7<<8 | 0xB0 | chan); 2591 2681 } 2592 2682 } 2593 2683 void SoundEngine::midiPedal(byte chan, bool pedal) { 2594 2684 if (_midi_pedal_last[chan] != pedal) { 2595 2685 _midi_pedal_last[chan] = pedal; 2596 MIDI_OUT(_mo, pedal<<16 | 64<<8 | 0xB0 | chan);2686 _midi_driver.MidiOut(_midi_driver._mo, pedal<<16 | 64<<8 | 0xB0 | chan); 2597 2687 } 2598 2688 } 2599 2689 2600 2690 void SoundEngine::midiModWheel(byte chan, byte modwheel) { 2601 2691 if (_midi_modwheel_last[chan] != modwheel) { 2602 2692 _midi_modwheel_last[chan] = modwheel; 2603 MIDI_OUT(_mo, modwheel<<16 | 1<<8 | 0xB0 | chan);2693 _midi_driver.MidiOut(_midi_driver._mo, modwheel<<16 | 1<<8 | 0xB0 | chan); 2604 2694 } 2605 2695 } 2606 2696 2607 2697 void SoundEngine::midiEffectLevel(byte chan, byte level) { 2608 2698 if (_midi_effectlevel_last[chan] != level) { 2609 2699 _midi_effectlevel_last[chan] = level; 2610 MIDI_OUT(_mo, level<<16 | 91<<8 | 0xB0 | chan);2700 _midi_driver.MidiOut(_midi_driver._mo, level<<16 | 91<<8 | 0xB0 | chan); 2611 2701 } 2612 2702 } 2613 2703 2614 2704 void SoundEngine::midiChorus(byte chan, byte chorus) { 2615 2705 if (_midi_chorus_last[chan] != chorus) { 2616 2706 _midi_chorus_last[chan] = chorus; 2617 MIDI_OUT(_mo, chorus<<16 | 93<<8 | 0xB0 | chan);2707 _midi_driver.MidiOut(_midi_driver._mo, chorus<<16 | 93<<8 | 0xB0 | chan); 2618 2708 } 2619 2709 } 2620 2710 2621 2711 void SoundEngine::midiControl0(byte chan, byte value) { 2622 MIDI_OUT(_mo, value<<16 | 0<<8 | 0xB0 | chan);2712 _midi_driver.MidiOut(_midi_driver._mo, value<<16 | 0<<8 | 0xB0 | chan); 2623 2713 } 2624 2714 2625 2715 void SoundEngine::midiProgram(byte chan, byte program) { 2626 MIDI_OUT(_mo, program<<8 | 0xC0 | chan);2716 _midi_driver.MidiOut(_midi_driver._mo, program<<8 | 0xC0 | chan); 2627 2717 } 2628 2718 2629 2719 void SoundEngine::midiPan(byte chan, int8 pan) { 2630 2720 if (_midi_pan_last[chan] != pan) { 2631 2721 _midi_pan_last[chan] = pan; 2632 MIDI_OUT(_mo, ((pan-64)&0x7F)<<16 | 10<<8 | 0xB0 | chan);2722 _midi_driver.MidiOut(_midi_driver._mo, ((pan-64)&0x7F)<<16 | 10<<8 | 0xB0 | chan); 2633 2723 } 2634 2724 } 2635 2725 2636 2726 void SoundEngine::midiNoteOn(byte chan, byte note, byte velocity) { 2637 MIDI_OUT(_mo, velocity<<16 | note<<8 | 0x90 | chan);2727 _midi_driver.MidiOut(_midi_driver._mo, velocity<<16 | note<<8 | 0x90 | chan); 2638 2728 } 2639 2729 2640 2730 void SoundEngine::midiNoteOff(byte chan, byte note) { 2641 MIDI_OUT(_mo, note<<8 | 0x80 | chan);2731 _midi_driver.MidiOut(_midi_driver._mo, note<<8 | 0x80 | chan); 2642 2732 } 2643 2733 2644 2734 void SoundEngine::midiSilence(byte chan) { 2645 MIDI_OUT(_mo, (64<<8)|0xB0|chan);2646 MIDI_OUT(_mo, (123<<8)|0xB0|chan);2735 _midi_driver.MidiOut(_midi_driver._mo, (64<<8)|0xB0|chan); 2736 _midi_driver.MidiOut(_midi_driver._mo, (123<<8)|0xB0|chan); 2647 2737 } -
readme.txt
diff -u scummvm.orig/readme.txt scummvm.new/readme.txt
old new 42 42 Ctrl-s shows memory consumption. 43 43 44 44 45 Playing sound with Timidity: 45 Playing music in Unix with a sound card 46 --------------------------------------- 47 *Compile ScummVM as per the instructions above 48 *Start ScummVM as follows: 49 50 $ scummvm -sX 51 where X is the device number of your midi output (On most cards, 0 is the external midi device and 1 is the internal midi synth. Be warned, very few cards apart from Soundblaster Live and Soundblaster AWE cards actually have an internal synth that works in linux) 52 53 54 Playing music in Unix with Timidity: 46 55 ---------------------------- 47 Start Timidity with the following command line : 56 *Compile ScummVM as per the instructions above 57 *Make sure you have timidity set up with a set of sounds (see the timidity docs for this) 58 *Start timidity with the following command line: 48 59 49 60 $ timidity -irv 7777 61 If you get errors about invalid interfaces, make sure you have compiled timidity with the configure option "--enable-server" 50 62 51 Then just start ScummVM and you should have sound.63 *Start ScummVM and you should have music. 52 64 53 65 54 66 Good Luck, 55 67 Ludvig Strigeus 56 57 58 59 60 61 62 63 64 65 66 -
scumm.h
diff -u scummvm.orig/scumm.h scummvm.new/scumm.h
old new 357 357 RF_USAGE_MAX = RF_USAGE 358 358 }; 359 359 360 enum { 361 MIDI_NULL = 0, 362 MIDI_WINDOWS = 1, 363 MIDI_TIMIDITY = 2, 364 MIDI_SEQ = 3, 365 }; 366 360 367 #define _maxRooms res.num[rtRoom] 361 368 #define _maxScripts res.num[rtScript] 362 369 #define _maxCostumes res.num[rtCostume] … … 686 693 687 694 int _keyPressed; 688 695 696 int _midi_driver; 697 int _midi_seq_device; 689 698 void *_soundDriver; 690 699 691 700 uint16 *_inventory; -
scummvm.cpp
diff -u scummvm.orig/scummvm.cpp scummvm.new/scummvm.cpp
old new 382 382 s++; 383 383 while (*s) { 384 384 switch(tolower(*s)) { 385 #ifndef WIN32 386 case 't': 387 _midi_driver = MIDI_TIMIDITY; 388 goto NextArg; 389 case 's': 390 _midi_driver = MIDI_SEQ; 391 _midi_seq_device = atoi(s+1); 392 goto NextArg; 393 #endif 385 394 case 'b': 386 395 _bootParam = atoi(s+1); 387 396 goto NextArg; … … 396 405 "\tscummvm [-b<num>] game\n" 397 406 "Flags:\n" 398 407 "\tb<num> - start in that room\n" 408 #ifndef WIN32 409 "\tt - use timidity for music output\n" 410 "\ts<num> - use a midi sequencer device <num> for music output\n" 411 #endif 399 412 "\tf - fullscreen mode\n"); 400 413 exit(1); 401 414 } -
sdl.cpp
diff -u scummvm.orig/sdl.cpp scummvm.new/sdl.cpp
old new 565 565 566 566 scumm._gui = &gui; 567 567 scumm.scummMain(argc, argv); 568 568 569 if (scumm._midi_driver == MIDI_SEQ) 570 sound.midiSetDriver(scumm._midi_driver, scumm._midi_seq_device); 571 else 572 sound.midiSetDriver(scumm._midi_driver); 573 569 574 gui.init(&scumm); 570 575 571 576 last_time = SDL_GetTicks(); -
sound.h
diff -u scummvm.orig/sound.h scummvm.new/sound.h
old new 30 30 struct HookDatas; 31 31 struct SoundEngine; 32 32 33 struct MidiDriver { 34 bool MidiInitialized; 35 int DeviceType; 36 int SeqDevice; 37 void *_mo; /* midi out */ 38 39 void midiInit(); 40 void midiInitTimidity(); 41 void midiInitSeq(); 42 void midiInitWindows(); 43 void midiInitNull(); 44 45 void MidiOut(void *a, int b); 46 void MidiOutSeq(void *a, int b); 47 void MidiOutWindows(void *a, int b); 48 49 int connect_to_timidity(int port); 50 int open_sequencer_device(); 51 }; 52 33 53 struct Part { 34 54 SoundEngine *_se; 35 55 Part *_next, *_prev; … … 236 256 }; 237 257 238 258 struct SoundEngine { 239 void *_mo; /* midi out */240 241 259 byte **_base_sounds; 242 260 243 261 Scumm *_s; … … 268 286 uint16 _channel_volume_eff[8]; /* NoSave */ 269 287 uint16 _volchan_table[8]; 270 288 289 MidiDriver _midi_driver; 271 290 Player _players[8]; 272 291 SustainingNotes _sustaining_notes[24]; 273 292 VolumeFader _volume_fader[8]; … … 341 360 void midiNoteOn(byte chan, byte note, byte velocity); 342 361 void midiNoteOff(byte chan, byte note); 343 362 void midiSilence(byte chan); 344 void midiInit();345 363 364 void midiSetDriver(int devicetype); 365 void midiSetDriver(int devicetype, int seq_device); 366 346 367 void adjust_priorities(); 347 368 348 369 void fix_parts_after_load();