Do some stuff to fix loom cd-music syncro. Sequences now run without 'speeding' by.. but they are still slightly out of sync.

svn-id: r3781
This commit is contained in:
James Brown 2002-03-18 11:50:09 +00:00
parent 32186f8614
commit ac19e7001a
6 changed files with 35 additions and 31 deletions

View file

@ -22,7 +22,7 @@
#define CD_MUSIC_H
void cd_stop();
void cd_play(int track, int num_loops, int start_frame);
void cd_play(int track, int num_loops, int start_frame, int end_track);
int cd_is_running();
void cd_music_loop();

View file

@ -35,7 +35,7 @@ void Scumm::runScript(int script, int a, int b, int16 *lvarptr) {
if (b==0)
stopScriptNr(script);
if (script < _numGlobalScripts) {
scriptPtr = getResourceAddress(rtScript, script);
if(_features & GF_SMALL_HEADER)

View file

@ -22,6 +22,7 @@
#include "stdafx.h"
#include "scumm.h"
#include "cdmusic.h"
void Scumm::setupOpcodes() {
static const OpcodeProc opcode_list[] = {
@ -2450,14 +2451,16 @@ void Scumm::decodeParseString() {
case 7: /* overhead */
string[textSlot].overhead = true;
break;
case 8: { /* play loom talkie sound - use in other games ? */
int offset = getVarOrDirectWord(0x80);
int delay = getVarOrDirectWord(0x40);
case 8: { /* play loom talkie sound - use in other games ? */
int offset = (int)(getVarOrDirectWord(0x80) * 7.5 - 22650);
int delay = (int)(getVarOrDirectWord(0x40) * 7.5) + 10;
if (_gameId == GID_LOOM256)
cd_playtrack(1, offset, delay);
break;
}
if (_gameId == GID_LOOM256)
cd_play(1, 0, offset, delay);
else
warning("parseString: 8");
}
break;
case 15:
_messagePtr = _scriptPointer;
switch(textSlot) {

View file

@ -341,7 +341,7 @@ int Scumm::scummLoop(int delta) {
_vars[VAR_MI1_TIMER]+=5;
else
if(_features & GF_OLD256)
_vars[VAR_MUSIC_FLAG]++;
_vars[VAR_MUSIC_FLAG]++; // ENDERFIX
if (_saveLoadFlag) {
if (_saveLoadFlag==1) {
@ -432,7 +432,7 @@ int Scumm::scummLoop(int delta) {
if (!(++_expire_counter)) {
increaseResourceCounter();
}
_vars[VAR_TIMER] = 0;
return _vars[VAR_TIMER_NEXT];

39
sdl.cpp
View file

@ -666,32 +666,25 @@ void fill_sound(void *userdata, Uint8 *stream, int len) {
scumm.mixWaves((int16*)stream, len>>1);
}
void cd_playtrack(int track, int offset, int delay) {
if (!cdrom) return;
SDL_CDStatus(cdrom);
SDL_CDPlayTracks(cdrom, track, (int)((offset * 7.5) - 22650), 0, (int)(delay * 7.5));
}
static int cd_track, cd_num_loops = 0, cd_start_frame;
static int cd_track, cd_num_loops = 0, cd_start_frame, cd_end_frame;
// On my system, calling SDL_CDStatus all the time slows things down a
// lot and prevents music from playing at all :( So this saves the
// time the track is expected to be finished.
static Uint32 cd_end_time;
static Uint32 cd_end_time, cd_stop_time, cd_next_second;
static Uint32 cd_stop_time;
void cd_play(int track, int num_loops, int start_frame) {
// warning("cd_play(%d,%d,%d)", track, num_loops, start_frame);
void cd_play(int track, int num_loops, int start_frame, int end_frame) {
// warning("cd_play(%d,%d,%d,%d)", track, num_loops, start_frame, end_frame);
if (!cdrom) return;
scumm._vars[14] = 0;
cd_track = track;
cd_num_loops = num_loops;
cd_start_frame = start_frame;
SDL_CDStatus(cdrom);
SDL_CDPlayTracks(cdrom, track, start_frame, 1, 0);
SDL_CDPlayTracks(cdrom, track, start_frame, 0, end_frame);
cd_end_frame = end_frame;
cd_stop_time = 0;
cd_end_time = SDL_GetTicks() +
cdrom->track[track].length * 1000 / CD_FPS;
@ -721,26 +714,34 @@ static void cd_shutdown() {
void cd_music_loop() {
if (!cdrom) return;
/* if (SDL_GetTicks() >= cd_next_second) {
/ printf("%d started at %d, fps\n", scumm._vars[14], cd_start_frame, CD_FPS);
//scumm._vars[14]++; //varmusicflag
cd_next_second = SDL_GetTicks() + 1;
} */
if (cd_stop_time != 0 && SDL_GetTicks() >= cd_stop_time) {
SDL_CDStop(cdrom);
cd_num_loops = 0;
cd_stop_time = 0;
return;
}
if (cd_num_loops == 0 || SDL_GetTicks() < cd_end_time)
return;
if (cd_num_loops != 1 && SDL_CDStatus(cdrom) != CD_STOPPED) {
// Wait another second for it to be done
cd_end_time += 1000;
return;
}
if (cd_num_loops > 0)
cd_num_loops--;
if (cd_num_loops != 0) {
SDL_CDPlayTracks(cdrom, cd_track, cd_start_frame, 1, 0);
cd_end_time = SDL_GetTicks() +
cdrom->track[cd_track].length * 1000 / CD_FPS;
SDL_CDPlayTracks(cdrom, cd_track, cd_start_frame, 0, cd_end_frame);
cd_end_time = SDL_GetTicks() + cdrom->track[cd_track].length * 1000 / CD_FPS;
}
}

View file

@ -106,7 +106,7 @@ void Scumm::playSound(int sound) {
if (ptr != NULL && READ_UINT32_UNALIGNED(ptr) == MKID('SOUN')) {
ptr += 8;
cd_play(ptr[16], ptr[17] == 0xff ? -1 : ptr[17],
(ptr[18] * 60 + ptr[19]) * 75 + ptr[20]);
(ptr[18] * 60 + ptr[19]) * 75 + ptr[20], 0);
current_cd_sound = sound;
return;
}