Ticket #7941: mi1_cdmusic.diff

File mi1_cdmusic.diff, 7.5 KB (added by SF/dschepler, 22 years ago)

MI1 CD music patch

  • CVS/Entries

    diff -urN scummvm/CVS/Entries scumm_cd/CVS/Entries
    old new  
    4040/whatsnew.txt/1.3/Sun Jan 13 19:49:26 2002//
    4141/windows.cpp/1.29/Sun Mar 10 17:33:04 2002//
    4242/x11.cpp/1.3/Wed Mar  6 23:14:16 2002//
    43 D/PocketSCUMM////
    4443D/dc////
    4544D/debian////
    4645D/mac////
  • CVS/Entries.Log

    diff -urN scummvm/CVS/Entries.Log scumm_cd/CVS/Entries.Log
    old new  
     1A D/PocketSCUMM////
    12R D/PocketSCUMM////
  • cdmusic.h

    diff -urN scummvm/cdmusic.h scumm_cd/cdmusic.h
    old new  
     1/* ScummVM - Scumm Interpreter
     2 * Copyright (C) 2002 The ScummVM project
     3 *
     4 * This program is free software; you can redistribute it and/or
     5 * modify it under the terms of the GNU General Public License
     6 * as published by the Free Software Foundation; either version 2
     7 * of the License, or (at your option) any later version.
     8 *
     9 * This program is distributed in the hope that it will be useful,
     10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12 * GNU General Public License for more details.
     13 *
     14 * You should have received a copy of the GNU General Public License
     15 * along with this program; if not, write to the Free Software
     16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
     17 *
     18 * $Header: /cvsroot/scummvm/scummvm/cdmusic.h 1.1 2002/03/14 17:36:13 ender Exp $
     19 */
     20
     21#ifndef CD_MUSIC_H
     22#define CD_MUSIC_H
     23
     24void cd_stop();
     25void cd_play(int track, int num_loops, int start_frame);
     26int cd_is_running();
     27void cd_music_loop();
     28
     29#endif
  • resource.cpp

    diff -urN scummvm/resource.cpp scumm_cd/resource.cpp
    old new  
    666666                        fileRead(_fileHandle,createResource(type, idx, total_size+8), total_size+8);
    667667                        return 1;
    668668                }
    669         } else {
     669        } else if (basetag == MKID('SOU ')) {
    670670                best_pri = -1;
    671671                while (pos < total_size) {
    672672                        tag = fileReadDword();
     
    697697                        fileRead(_fileHandle,createResource(type, idx, best_size), best_size);
    698698                        return 1;
    699699                }               
     700        } else if (FROM_LE_32(basetag) == 24) {
     701                fileSeek(_fileHandle, -12, SEEK_CUR);
     702                total_size = fileReadDwordBE();
     703                fileSeek(_fileHandle, -8, SEEK_CUR);
     704                fileRead(_fileHandle, createResource(type, idx, total_size), total_size);
     705                return 1;
     706        } else {
     707                error("Unrecognized base tag %c%c%c%c in sound %d",
     708                      basetag&0xff, basetag>>8, basetag>>16, basetag>>24,
     709                      idx);
    700710        }
    701711        res.roomoffs[type][idx] = 0xFFFFFFFF;
    702712        return 0;
  • scumm.h

    diff -urN scummvm/scumm.h scumm_cd/scumm.h
    old new  
    12041204        OffsetTable *offset_table;
    12051205        int num_sound_effects;
    12061206#endif
    1207  
     1207
     1208        int current_cd_sound;
     1209
    12081210        void openRoom(int room);
    12091211        void deleteRoomOffsets();
    12101212        void readRoomsOffsets();
  • sdl.cpp

    diff -urN scummvm/sdl.cpp scumm_cd/sdl.cpp
    old new  
    2727#include "sound.h"
    2828#include "SDL_thread.h"
    2929
     30#include "cdmusic.h"
     31
    3032static unsigned int scale;
    3133
    3234Scumm scumm;
     
    176178                        }
    177179                }
    178180
     181                cd_music_loop(); // Loop CD Music if necessary
     182
    179183                if (SDL_GetTicks() >= start_time + msec_delay)
    180184                        break;
    181185                SDL_Delay(10);
     
    667671        SDL_CDPlayTracks(cdrom, track, (int)((offset * 7.5) - 22650), 0, (int)(delay * 7.5));
    668672}
    669673
     674static int cd_track, cd_num_loops = 0, cd_start_frame;
     675
     676// On my system, calling SDL_CDStatus all the time slows things down a
     677// lot and prevents music from playing at all :( So this saves the
     678// time the track is expected to be finished.
     679static Uint32 cd_end_time;
     680
     681static Uint32 cd_stop_time;
     682
     683void cd_play(int track, int num_loops, int start_frame) {
     684        warning("cd_play(%d,%d,%d)", track, num_loops, start_frame);
     685        cd_track = track;
     686        cd_num_loops = num_loops;
     687        cd_start_frame = start_frame;
     688
     689        SDL_CDStatus(cdrom);
     690        SDL_CDPlayTracks(cdrom, track, start_frame, 1, 0);
     691        cd_stop_time = 0;
     692        cd_end_time = SDL_GetTicks() +
     693                cdrom->track[track].length * 1000 / CD_FPS;
     694}
     695
     696// Schedule the music to be stopped after 1/10 sec, unless another
     697// track is started in the meantime.  (On my machine, stopping and
     698// then restarting the CD takes a few seconds.)
     699void cd_stop() {
     700        cd_stop_time = SDL_GetTicks() + 100;
     701        cd_num_loops = 0;
     702}
     703
     704int cd_is_running() {
     705        return (cd_num_loops != 0 && (SDL_GetTicks() < cd_end_time ||
     706                                      SDL_CDStatus(cdrom) != CD_STOPPED));
     707}
     708
     709static void cd_shutdown() {
     710        if (cd_num_loops != 0)
     711                SDL_CDStop(cdrom);
     712}
     713
     714void cd_music_loop() {
     715        if (cd_stop_time != 0 && SDL_GetTicks() >= cd_stop_time) {
     716                SDL_CDStop(cdrom);
     717                cd_num_loops = 0;
     718                cd_stop_time = 0;
     719                return;
     720        }
     721        if (cd_num_loops == 0 || SDL_GetTicks() < cd_end_time)
     722                return;
     723        if (cd_num_loops != 1 && SDL_CDStatus(cdrom) != CD_STOPPED) {
     724                // Wait another second for it to be done
     725                cd_end_time += 1000;
     726                return;
     727        }
     728        if (cd_num_loops > 0)
     729                cd_num_loops--;
     730        if (cd_num_loops != 0) {
     731                SDL_CDPlayTracks(cdrom, cd_track, cd_start_frame, 1, 0);
     732                cd_end_time = SDL_GetTicks() +
     733                        cdrom->track[cd_track].length * 1000 / CD_FPS;
     734        }
     735}
     736
    670737int music_thread(Scumm *s) {
    671738        int old_time, cur_time;
    672739
     
    703770
    704771        /* Clean up on exit */
    705772        atexit(SDL_Quit);
     773        atexit(cd_shutdown);
    706774        atexit(resetCursor);
    707775
    708776        char buf[512], *gameName;
  • sound/CVS/Entries

    diff -urN scummvm/sound/CVS/Entries scumm_cd/sound/CVS/Entries
    old new  
    33/fmopl.h/1.1/Sat Dec  1 17:06:13 2001//
    44/gmidi.cpp/1.8/Thu Mar 14 13:28:32 2002//
    55/gmidi.h/1.2/Thu Mar 14 08:04:21 2002//
    6 /imuse.cpp/1.15/Thu Mar 14 17:36:13 2002//
     6/imuse.cpp/1.15/Sat Mar 16 01:38:43 2002//
    77D
  • sound.cpp

    diff -urN scummvm/sound.cpp scumm_cd/sound.cpp
    old new  
    2121
    2222#include "stdafx.h"
    2323#include "scumm.h"
    24 #include "sound.h"
    25 
    26 #ifdef _WIN32_WCE
    27 extern void *bsearch(const void *, const void *, size_t,
    28                           size_t, int (*x)(const void *, const void *));
     24#include "sound.h"
     25#include "cdmusic.h"
     26
     27#ifdef _WIN32_WCE
     28extern void *bsearch(const void *, const void *, size_t,
     29                          size_t, int (*x)(const void *, const void *));
    2930#endif
    3031
    3132void Scumm::addSoundToQueue(int sound) {
     
    9899}
    99100
    100101void Scumm::playSound(int sound) {
     102        byte *ptr;
    101103        SoundEngine *se = (SoundEngine*)_soundEngine;
     104
     105        ptr = getResourceAddress(rtSound, sound);
     106        if (ptr != NULL && READ_UINT32_UNALIGNED(ptr) == MKID('SOUN')) {
     107                ptr += 8;
     108                cd_play(ptr[16], ptr[17] == 0xff ? -1 : ptr[17],
     109                        (ptr[18] * 60 + ptr[19]) * 75 + ptr[20]);
     110                current_cd_sound = sound;
     111                return;
     112        }
     113
    102114        if (_features & GF_OLD256) return; /* FIXME */
    103115
    104116        if (se) {
     
    233245        SoundEngine *se;
    234246        int i;
    235247
     248        if (sound == current_cd_sound)
     249                return cd_is_running();
     250
    236251        i = _soundQue2Pos;
    237252        while (i--) {
    238253                if (_soundQue2[i] == sound)
     
    275290        SoundEngine *se;
    276291        int i;
    277292
     293        if (a == current_cd_sound) {
     294                current_cd_sound = 0;
     295                cd_stop();
     296        }
     297
    278298        se = (SoundEngine*)_soundEngine;
    279299        if (se)
    280300                se->stop_sound(a);
     
    286306
    287307void Scumm::stopAllSounds() {
    288308        SoundEngine *se = (SoundEngine*)_soundEngine;
     309
     310        if (current_cd_sound != 0) {
     311                current_cd_sound = 0;
     312                cd_stop();
     313        }
     314
    289315        if (se) {
    290316                se->stop_all_sounds();
    291317                se->clear_queue();