2004-01-06 17:28:29 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
|
|
|
* Copyright (C) 2001-2004 The ScummVM project
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
* $Header$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "common/timer.h"
|
|
|
|
|
|
|
|
#include "scumm/actor.h"
|
|
|
|
#include "scumm/scumm.h"
|
|
|
|
#include "scumm/sound.h"
|
|
|
|
#include "scumm/imuse_digi/dimuse.h"
|
|
|
|
#include "scumm/imuse_digi/dimuse_bndmgr.h"
|
|
|
|
|
|
|
|
#include "sound/audiostream.h"
|
|
|
|
#include "sound/mixer.h"
|
|
|
|
|
|
|
|
namespace Scumm {
|
|
|
|
|
|
|
|
IMuseDigital::Track::Track()
|
2004-01-12 19:15:07 +00:00
|
|
|
: soundId(-1), used(false), stream(NULL) {
|
2004-01-06 17:28:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void IMuseDigital::timer_handler(void *refCon) {
|
|
|
|
IMuseDigital *imuseDigital = (IMuseDigital *)refCon;
|
|
|
|
imuseDigital->callback();
|
|
|
|
}
|
|
|
|
|
|
|
|
IMuseDigital::IMuseDigital(ScummEngine *scumm)
|
2004-01-08 20:37:26 +00:00
|
|
|
: _vm(scumm) {
|
2004-02-28 12:58:13 +00:00
|
|
|
_mutex = g_system->createMutex();
|
2004-01-06 17:28:29 +00:00
|
|
|
_pause = false;
|
2004-01-08 20:37:26 +00:00
|
|
|
_sound = new ImuseDigiSndMgr(_vm);
|
2004-04-05 18:24:36 +00:00
|
|
|
_volVoice = 0;
|
|
|
|
_volSfx = 0;
|
|
|
|
_volMusic = 0;
|
2004-03-27 17:03:42 +00:00
|
|
|
resetState();
|
2004-04-11 14:48:50 +00:00
|
|
|
for (int l = 0; l < MAX_DIGITAL_TRACKS + MAX_DIGITAL_FADETRACKS; l++) {
|
|
|
|
_track[l] = new Track;
|
|
|
|
_track[l]->used = false;
|
|
|
|
}
|
2004-01-08 20:37:26 +00:00
|
|
|
_vm->_timer->installTimerProc(timer_handler, 1000000 / 25, this);
|
2004-01-06 17:28:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
IMuseDigital::~IMuseDigital() {
|
2004-01-12 19:15:07 +00:00
|
|
|
stopAllSounds(true);
|
2004-03-27 17:03:42 +00:00
|
|
|
{
|
2004-03-28 20:31:18 +00:00
|
|
|
Common::StackLock lock(_mutex, "IMuseDigital::~IMuseDigital()");
|
2004-03-27 17:03:42 +00:00
|
|
|
_vm->_timer->removeTimerProc(timer_handler);
|
|
|
|
}
|
2004-04-11 14:48:50 +00:00
|
|
|
for (int l = 0; l < MAX_DIGITAL_TRACKS + MAX_DIGITAL_FADETRACKS; l++) {
|
|
|
|
delete _track[l];
|
|
|
|
}
|
2004-01-06 17:28:29 +00:00
|
|
|
delete _sound;
|
2004-02-28 12:58:13 +00:00
|
|
|
g_system->deleteMutex(_mutex);
|
2004-01-06 17:28:29 +00:00
|
|
|
}
|
|
|
|
|
2004-04-05 18:24:36 +00:00
|
|
|
void IMuseDigital::resetState() {
|
|
|
|
_curMusicState = 0;
|
|
|
|
_curMusicSeq = 0;
|
|
|
|
_curMusicCue = 0;
|
|
|
|
memset(_attributes, 0, sizeof(_attributes));
|
2004-04-09 03:57:18 +00:00
|
|
|
_nextSeqToPlay = 0;
|
2004-04-05 18:24:36 +00:00
|
|
|
}
|
|
|
|
|
2004-04-13 06:29:34 +00:00
|
|
|
#ifdef ENABLE_PULLMETHOD
|
|
|
|
|
|
|
|
int IMuseDigital::pullProcCallback(void *refCon, CustomProcInputStream *stream, byte *mixerBuffer, int pullSize) {
|
|
|
|
IMuseDigital *imuseDigital = (IMuseDigital *)refCon;
|
|
|
|
return imuseDigital->pullProc(stream, mixerBuffer, pullSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
int IMuseDigital::pullProc(CustomProcInputStream *stream, byte *mixerBuffer, int pullSize) {
|
|
|
|
Common::StackLock lock(_mutex, "IMuseDigital::pullProc()");
|
2004-04-24 20:41:30 +00:00
|
|
|
debug(5, "pullProc() pullSize:%d", pullSize);
|
2004-04-11 18:56:32 +00:00
|
|
|
for (int l = 0; l < MAX_DIGITAL_TRACKS + MAX_DIGITAL_FADETRACKS; l++) {
|
2004-04-24 20:02:17 +00:00
|
|
|
if ((_track[l]->used) && (_track[l]->stream == stream)) {
|
2004-04-24 20:41:30 +00:00
|
|
|
if (_track[l]->toBeRemoved) {
|
|
|
|
debug(5, "IMuseDigital::pullProc() stopped sound: %d", _track[l]->soundId);
|
|
|
|
_track[l]->stream->finish();
|
|
|
|
_track[l]->stream = NULL;
|
|
|
|
_sound->closeSound(_track[l]->soundHandle);
|
|
|
|
_track[l]->soundHandle = NULL;
|
|
|
|
_track[l]->used = false;
|
|
|
|
return 0;
|
|
|
|
}
|
2004-04-13 06:29:34 +00:00
|
|
|
_vm->_mixer->setChannelVolume(_track[l]->handle, _track[l]->mixerVol);
|
|
|
|
_vm->_mixer->setChannelBalance(_track[l]->handle, _track[l]->mixerPan);
|
2004-04-11 18:56:32 +00:00
|
|
|
int32 mixer_size = pullSize;
|
|
|
|
byte *data = NULL;
|
|
|
|
int32 result = 0, pos = 0;
|
|
|
|
|
2004-04-24 16:17:10 +00:00
|
|
|
if (_track[l]->curRegion == -1) {
|
2004-04-11 18:56:32 +00:00
|
|
|
switchToNextRegion(l);
|
2004-04-24 20:41:30 +00:00
|
|
|
if (_track[l]->toBeRemoved) {
|
|
|
|
return 0;
|
|
|
|
}
|
2004-04-24 16:17:10 +00:00
|
|
|
}
|
2004-04-11 18:56:32 +00:00
|
|
|
|
|
|
|
int bits = _sound->getBits(_track[l]->soundHandle);
|
2004-04-24 20:41:30 +00:00
|
|
|
int channels = _sound->getChannels(_track[l]->soundHandle);
|
|
|
|
|
|
|
|
if ((bits == 16) && (channels == 2))
|
|
|
|
assert((pullSize & 3) == 0);
|
|
|
|
else if ((bits == 16) || (channels == 2))
|
|
|
|
assert((pullSize & 1) == 0);
|
|
|
|
|
2004-04-11 18:56:32 +00:00
|
|
|
do {
|
|
|
|
if (bits == 12) {
|
|
|
|
byte *ptr = NULL;
|
|
|
|
|
|
|
|
mixer_size += _track[l]->mod;
|
|
|
|
int mixer_size_12 = (mixer_size * 3) / 4;
|
|
|
|
int length = (mixer_size_12 / 3) * 4;
|
|
|
|
_track[l]->mod = mixer_size - length;
|
|
|
|
|
|
|
|
int32 offset = (_track[l]->regionOffset * 3) / 4;
|
|
|
|
int result2 = _sound->getDataFromRegion(_track[l]->soundHandle, _track[l]->curRegion, &ptr, offset, mixer_size_12);
|
|
|
|
result = BundleCodecs::decode12BitsSample(ptr, &data, result2);
|
|
|
|
|
|
|
|
free(ptr);
|
|
|
|
} else if (bits == 16) {
|
|
|
|
result = _sound->getDataFromRegion(_track[l]->soundHandle, _track[l]->curRegion, &data, _track[l]->regionOffset, mixer_size);
|
|
|
|
if (_sound->getChannels(_track[l]->soundHandle) == 1) {
|
|
|
|
result &= ~1;
|
|
|
|
}
|
|
|
|
if (_sound->getChannels(_track[l]->soundHandle) == 2) {
|
|
|
|
if (result & 2)
|
|
|
|
result &= ~2;
|
|
|
|
}
|
|
|
|
} else if (bits == 8) {
|
|
|
|
result = _sound->getDataFromRegion(_track[l]->soundHandle, _track[l]->curRegion, &data, _track[l]->regionOffset, mixer_size);
|
|
|
|
if (_sound->getChannels(_track[l]->soundHandle) == 2) {
|
|
|
|
result &= ~1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result > mixer_size)
|
|
|
|
result = mixer_size;
|
|
|
|
|
|
|
|
memcpy(mixerBuffer + pos, data, result);
|
|
|
|
pos += result;
|
|
|
|
free(data);
|
|
|
|
|
|
|
|
_track[l]->regionOffset += result;
|
|
|
|
_track[l]->trackOffset += result;
|
|
|
|
|
|
|
|
if (_sound->isEndOfRegion(_track[l]->soundHandle, _track[l]->curRegion)) {
|
|
|
|
switchToNextRegion(l);
|
2004-04-13 06:29:34 +00:00
|
|
|
if (_track[l]->toBeRemoved) {
|
|
|
|
mixer_size -= result;
|
|
|
|
return pullSize - mixer_size;
|
|
|
|
}
|
2004-04-11 18:56:32 +00:00
|
|
|
}
|
|
|
|
mixer_size -= result;
|
|
|
|
assert(mixer_size >= 0);
|
|
|
|
} while (mixer_size != 0);
|
2004-04-13 06:29:34 +00:00
|
|
|
return pullSize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
error("IMuseDigital::pullProc() Can't match streams");
|
|
|
|
}
|
|
|
|
|
|
|
|
void IMuseDigital::callback() {
|
|
|
|
Common::StackLock lock(_mutex, "IMuseDigital::callback()");
|
|
|
|
int l = 0;
|
|
|
|
|
|
|
|
if (_pause || !_vm)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (l = 0; l < MAX_DIGITAL_TRACKS + MAX_DIGITAL_FADETRACKS; l++) {
|
|
|
|
if (_track[l]->used) {
|
|
|
|
if (_track[l]->stream2) {
|
|
|
|
if (!_track[l]->handle.isActive() && _track[l]->started) {
|
|
|
|
debug(5, "IMuseDigital::callback() A: stopped sound: %d", _track[l]->soundId);
|
|
|
|
delete _track[l]->stream2;
|
|
|
|
_track[l]->stream2 = NULL;
|
|
|
|
_track[l]->used = false;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_track[l]->volFadeUsed) {
|
|
|
|
if (_track[l]->volFadeStep < 0) {
|
|
|
|
if (_track[l]->vol > _track[l]->volFadeDest) {
|
|
|
|
_track[l]->vol += _track[l]->volFadeStep;
|
|
|
|
if (_track[l]->vol < _track[l]->volFadeDest) {
|
|
|
|
_track[l]->vol = _track[l]->volFadeDest;
|
|
|
|
_track[l]->volFadeUsed = false;
|
|
|
|
}
|
|
|
|
if (_track[l]->vol == 0) {
|
|
|
|
_track[l]->toBeRemoved = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (_track[l]->volFadeStep > 0) {
|
|
|
|
if (_track[l]->vol < _track[l]->volFadeDest) {
|
|
|
|
_track[l]->vol += _track[l]->volFadeStep;
|
|
|
|
if (_track[l]->vol > _track[l]->volFadeDest) {
|
|
|
|
_track[l]->vol = _track[l]->volFadeDest;
|
|
|
|
_track[l]->volFadeUsed = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
debug(5, "Fade: sound(%d), Vol(%d)", _track[l]->soundId, _track[l]->vol / 1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
int pan = (_track[l]->pan != 64) ? 2 * _track[l]->pan - 127 : 0;
|
|
|
|
int vol = _track[l]->vol / 1000;
|
|
|
|
|
|
|
|
if (_track[l]->volGroupId == 1)
|
|
|
|
vol = (vol * _volVoice) / 128;
|
|
|
|
if (_track[l]->volGroupId == 2)
|
|
|
|
vol = (vol * _volSfx) / 128;
|
|
|
|
if (_track[l]->volGroupId == 3)
|
|
|
|
vol = (vol * _volMusic) / 128;
|
|
|
|
|
|
|
|
_track[l]->mixerVol = vol;
|
|
|
|
_track[l]->mixerPan = pan;
|
|
|
|
|
|
|
|
if (_vm->_mixer->isReady()) {
|
|
|
|
if (_track[l]->stream2) {
|
|
|
|
if (!_track[l]->started) {
|
|
|
|
_track[l]->started = true;
|
|
|
|
_vm->_mixer->playInputStream(&_track[l]->handle, _track[l]->stream2, false, _track[l]->vol / 1000, _track[l]->pan, -1, false);
|
|
|
|
} else {
|
|
|
|
_vm->_mixer->setChannelVolume(_track[l]->handle, vol);
|
|
|
|
_vm->_mixer->setChannelBalance(_track[l]->handle, pan);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-04-11 18:56:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-04-13 06:29:34 +00:00
|
|
|
#else
|
|
|
|
|
2004-01-06 17:28:29 +00:00
|
|
|
void IMuseDigital::callback() {
|
2004-03-28 20:31:18 +00:00
|
|
|
Common::StackLock lock(_mutex, "IMuseDigital::callback()");
|
2004-01-06 17:28:29 +00:00
|
|
|
int l = 0;
|
|
|
|
|
2004-01-08 20:37:26 +00:00
|
|
|
if (_pause || !_vm)
|
2004-01-06 17:28:29 +00:00
|
|
|
return;
|
|
|
|
|
2004-04-11 14:48:50 +00:00
|
|
|
for (l = 0; l < MAX_DIGITAL_TRACKS + MAX_DIGITAL_FADETRACKS; l++) {
|
|
|
|
if (_track[l]->used) {
|
|
|
|
if (_track[l]->stream2) {
|
|
|
|
if (!_track[l]->handle.isActive() && _track[l]->started) {
|
|
|
|
debug(5, "IMuseDigital::callback() A: stopped sound: %d", _track[l]->soundId);
|
|
|
|
delete _track[l]->stream2;
|
|
|
|
_track[l]->stream2 = NULL;
|
|
|
|
_track[l]->used = false;
|
2004-01-06 17:28:29 +00:00
|
|
|
continue;
|
|
|
|
}
|
2004-04-11 14:48:50 +00:00
|
|
|
} else if (_track[l]->stream) {
|
|
|
|
if (_track[l]->toBeRemoved) {
|
|
|
|
debug(5, "IMuseDigital::callback() B: stopped sound: %d", _track[l]->soundId);
|
|
|
|
_track[l]->stream->finish();
|
|
|
|
_track[l]->stream = NULL;
|
|
|
|
_sound->closeSound(_track[l]->soundHandle);
|
|
|
|
_track[l]->soundHandle = NULL;
|
|
|
|
_track[l]->used = false;
|
2004-01-06 17:28:29 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-04-11 14:48:50 +00:00
|
|
|
if (_track[l]->volFadeUsed) {
|
|
|
|
if (_track[l]->volFadeStep < 0) {
|
|
|
|
if (_track[l]->vol > _track[l]->volFadeDest) {
|
|
|
|
_track[l]->vol += _track[l]->volFadeStep;
|
|
|
|
if (_track[l]->vol < _track[l]->volFadeDest) {
|
|
|
|
_track[l]->vol = _track[l]->volFadeDest;
|
|
|
|
_track[l]->volFadeUsed = false;
|
2004-01-06 17:28:29 +00:00
|
|
|
}
|
2004-04-11 14:48:50 +00:00
|
|
|
if (_track[l]->vol == 0) {
|
|
|
|
_track[l]->toBeRemoved = true;
|
2004-01-06 17:28:29 +00:00
|
|
|
}
|
|
|
|
}
|
2004-04-11 14:48:50 +00:00
|
|
|
} else if (_track[l]->volFadeStep > 0) {
|
|
|
|
if (_track[l]->vol < _track[l]->volFadeDest) {
|
|
|
|
_track[l]->vol += _track[l]->volFadeStep;
|
|
|
|
if (_track[l]->vol > _track[l]->volFadeDest) {
|
|
|
|
_track[l]->vol = _track[l]->volFadeDest;
|
|
|
|
_track[l]->volFadeUsed = false;
|
2004-01-06 17:28:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-04-11 14:48:50 +00:00
|
|
|
debug(5, "Fade: sound(%d), Vol(%d)", _track[l]->soundId, _track[l]->vol / 1000);
|
2004-01-06 17:28:29 +00:00
|
|
|
}
|
|
|
|
|
2004-04-11 14:48:50 +00:00
|
|
|
int pan = (_track[l]->pan != 64) ? 2 * _track[l]->pan - 127 : 0;
|
|
|
|
int vol = _track[l]->vol / 1000;
|
2004-04-05 18:24:36 +00:00
|
|
|
|
2004-04-11 14:48:50 +00:00
|
|
|
if (_track[l]->volGroupId == 1)
|
2004-04-05 18:24:36 +00:00
|
|
|
vol = (vol * _volVoice) / 128;
|
2004-04-11 14:48:50 +00:00
|
|
|
if (_track[l]->volGroupId == 2)
|
2004-04-05 18:24:36 +00:00
|
|
|
vol = (vol * _volSfx) / 128;
|
2004-04-11 14:48:50 +00:00
|
|
|
if (_track[l]->volGroupId == 3)
|
2004-04-05 18:24:36 +00:00
|
|
|
vol = (vol * _volMusic) / 128;
|
2004-01-06 17:28:29 +00:00
|
|
|
|
2004-01-08 20:37:26 +00:00
|
|
|
if (_vm->_mixer->isReady()) {
|
2004-04-11 14:48:50 +00:00
|
|
|
if (_track[l]->stream2) {
|
|
|
|
if (!_track[l]->started) {
|
|
|
|
_track[l]->started = true;
|
|
|
|
_vm->_mixer->playInputStream(&_track[l]->handle, _track[l]->stream2, false, _track[l]->vol / 1000, _track[l]->pan, -1, false);
|
2004-01-06 17:28:29 +00:00
|
|
|
} else {
|
2004-04-11 14:48:50 +00:00
|
|
|
_vm->_mixer->setChannelVolume(_track[l]->handle, vol);
|
|
|
|
_vm->_mixer->setChannelBalance(_track[l]->handle, pan);
|
2004-01-06 17:28:29 +00:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-04-11 14:48:50 +00:00
|
|
|
if (_track[l]->stream) {
|
|
|
|
int32 mixer_size = _track[l]->pullSize;
|
2004-01-06 17:28:29 +00:00
|
|
|
byte *data = NULL;
|
|
|
|
int32 result = 0;
|
|
|
|
|
2004-04-11 14:48:50 +00:00
|
|
|
if (_track[l]->stream->endOfData()) {
|
2004-01-06 17:28:29 +00:00
|
|
|
mixer_size *= 2;
|
2004-01-08 18:25:30 +00:00
|
|
|
}
|
|
|
|
|
2004-04-24 15:58:51 +00:00
|
|
|
if (_track[l]->curRegion == -1) {
|
2004-01-08 18:25:30 +00:00
|
|
|
switchToNextRegion(l);
|
2004-04-24 15:58:51 +00:00
|
|
|
if (_track[l]->toBeRemoved)
|
2004-04-24 16:15:01 +00:00
|
|
|
continue;
|
2004-04-24 15:58:51 +00:00
|
|
|
}
|
2004-01-06 17:28:29 +00:00
|
|
|
|
2004-04-11 14:48:50 +00:00
|
|
|
int bits = _sound->getBits(_track[l]->soundHandle);
|
2004-01-06 17:28:29 +00:00
|
|
|
do {
|
2004-01-07 20:17:51 +00:00
|
|
|
if (bits == 12) {
|
2004-01-06 17:28:29 +00:00
|
|
|
byte *ptr = NULL;
|
2004-01-07 19:38:37 +00:00
|
|
|
|
2004-04-11 14:48:50 +00:00
|
|
|
mixer_size += _track[l]->mod;
|
2004-01-07 19:38:37 +00:00
|
|
|
int mixer_size_12 = (mixer_size * 3) / 4;
|
|
|
|
int length = (mixer_size_12 / 3) * 4;
|
2004-04-11 14:48:50 +00:00
|
|
|
_track[l]->mod = mixer_size - length;
|
2004-01-06 17:28:29 +00:00
|
|
|
|
2004-04-11 14:48:50 +00:00
|
|
|
int32 offset = (_track[l]->regionOffset * 3) / 4;
|
|
|
|
int result2 = _sound->getDataFromRegion(_track[l]->soundHandle, _track[l]->curRegion, &ptr, offset, mixer_size_12);
|
2004-01-07 19:38:37 +00:00
|
|
|
result = BundleCodecs::decode12BitsSample(ptr, &data, result2);
|
|
|
|
|
2004-01-06 17:28:29 +00:00
|
|
|
free(ptr);
|
2004-01-07 20:17:51 +00:00
|
|
|
} else if (bits == 16) {
|
2004-04-11 14:48:50 +00:00
|
|
|
result = _sound->getDataFromRegion(_track[l]->soundHandle, _track[l]->curRegion, &data, _track[l]->regionOffset, mixer_size);
|
|
|
|
if (_sound->getChannels(_track[l]->soundHandle) == 1) {
|
2004-01-07 20:17:51 +00:00
|
|
|
result &= ~1;
|
2004-01-06 17:28:29 +00:00
|
|
|
}
|
2004-04-11 14:48:50 +00:00
|
|
|
if (_sound->getChannels(_track[l]->soundHandle) == 2) {
|
2004-01-09 13:16:06 +00:00
|
|
|
if (result & 2)
|
|
|
|
result &= ~2;
|
|
|
|
}
|
2004-01-07 20:17:51 +00:00
|
|
|
} else if (bits == 8) {
|
2004-04-11 14:48:50 +00:00
|
|
|
result = _sound->getDataFromRegion(_track[l]->soundHandle, _track[l]->curRegion, &data, _track[l]->regionOffset, mixer_size);
|
|
|
|
if (_sound->getChannels(_track[l]->soundHandle) == 2) {
|
2004-01-07 20:17:51 +00:00
|
|
|
result &= ~1;
|
2004-01-06 17:28:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-07 19:38:37 +00:00
|
|
|
if (result > mixer_size)
|
|
|
|
result = mixer_size;
|
|
|
|
|
2004-01-08 20:37:26 +00:00
|
|
|
if (_vm->_mixer->isReady()) {
|
2004-04-11 14:48:50 +00:00
|
|
|
_vm->_mixer->setChannelVolume(_track[l]->handle, vol);
|
|
|
|
_vm->_mixer->setChannelBalance(_track[l]->handle, pan);
|
|
|
|
_track[l]->stream->append(data, result);
|
|
|
|
_track[l]->regionOffset += result;
|
|
|
|
_track[l]->trackOffset += result;
|
2004-01-06 17:28:29 +00:00
|
|
|
free(data);
|
|
|
|
}
|
|
|
|
|
2004-04-11 14:48:50 +00:00
|
|
|
if (_sound->isEndOfRegion(_track[l]->soundHandle, _track[l]->curRegion)) {
|
2004-01-06 17:28:29 +00:00
|
|
|
switchToNextRegion(l);
|
2004-04-11 14:48:50 +00:00
|
|
|
if (_track[l]->toBeRemoved)
|
2004-01-06 17:28:29 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
mixer_size -= result;
|
2004-01-08 01:59:11 +00:00
|
|
|
assert(mixer_size >= 0);
|
2004-01-06 17:28:29 +00:00
|
|
|
} while (mixer_size != 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-04-13 06:29:34 +00:00
|
|
|
#endif
|
2004-01-06 17:28:29 +00:00
|
|
|
|
|
|
|
void IMuseDigital::switchToNextRegion(int track) {
|
2004-04-24 20:41:30 +00:00
|
|
|
debug(5, "switchToNextRegion(track:%d)", track);
|
|
|
|
|
2004-04-11 14:48:50 +00:00
|
|
|
if (track >= MAX_DIGITAL_TRACKS) {
|
|
|
|
_track[track]->toBeRemoved = true;
|
2004-04-24 20:41:30 +00:00
|
|
|
debug(5, "exit (fadetrack can't go next region) switchToNextRegion(track:%d)", track);
|
2004-04-11 14:48:50 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int num_regions = _sound->getNumRegions(_track[track]->soundHandle);
|
2004-01-07 05:58:12 +00:00
|
|
|
|
2004-04-11 14:48:50 +00:00
|
|
|
if (++_track[track]->curRegion == num_regions) {
|
|
|
|
_track[track]->toBeRemoved = true;
|
2004-04-24 20:41:30 +00:00
|
|
|
debug(5, "exit (end of regions) switchToNextRegion(track:%d)", track);
|
2004-01-06 17:28:29 +00:00
|
|
|
return;
|
|
|
|
}
|
2004-01-07 05:58:12 +00:00
|
|
|
|
2004-04-11 14:48:50 +00:00
|
|
|
int jumpId = _sound->getJumpIdByRegionAndHookId(_track[track]->soundHandle, _track[track]->curRegion, _track[track]->curHookId);
|
2004-04-09 21:44:29 +00:00
|
|
|
if (jumpId == -1)
|
2004-04-11 14:48:50 +00:00
|
|
|
jumpId = _sound->getJumpIdByRegionAndHookId(_track[track]->soundHandle, _track[track]->curRegion, 0);
|
2004-01-14 22:07:24 +00:00
|
|
|
if (jumpId != -1) {
|
2004-04-11 14:48:50 +00:00
|
|
|
int region = _sound->getRegionIdByJumpId(_track[track]->soundHandle, jumpId);
|
2004-04-08 21:13:25 +00:00
|
|
|
assert(region != -1);
|
2004-04-11 14:48:50 +00:00
|
|
|
int sampleHookId = _sound->getJumpHookId(_track[track]->soundHandle, jumpId);
|
2004-04-08 21:13:25 +00:00
|
|
|
assert(sampleHookId != -1);
|
2004-04-11 14:48:50 +00:00
|
|
|
int fadeDelay = (60 * _sound->getJumpFade(_track[track]->soundHandle, jumpId)) / 1000;
|
2004-04-08 21:13:25 +00:00
|
|
|
if (sampleHookId != 0) {
|
2004-04-11 14:48:50 +00:00
|
|
|
if (_track[track]->curHookId == sampleHookId) {
|
2004-04-11 14:56:11 +00:00
|
|
|
if (fadeDelay != 0) {
|
|
|
|
int fadeTrack = cloneToFadeOutTrack(track, fadeDelay, false);
|
|
|
|
_track[fadeTrack]->dataOffset = _sound->getRegionOffset(_track[fadeTrack]->soundHandle, _track[fadeTrack]->curRegion);
|
|
|
|
_track[fadeTrack]->regionOffset = 0;
|
|
|
|
debug(5, "switchToNextRegion-sound(%d) select %d region, curHookId: %d", _track[fadeTrack]->soundId, _track[fadeTrack]->curRegion, _track[fadeTrack]->curHookId);
|
|
|
|
_track[fadeTrack]->curHookId = 0;
|
|
|
|
}
|
2004-04-11 14:48:50 +00:00
|
|
|
_track[track]->curRegion = region;
|
|
|
|
debug(5, "switchToNextRegion-sound(%d) jump to %d region, curHookId: %d", _track[track]->soundId, _track[track]->curRegion, _track[track]->curHookId);
|
|
|
|
_track[track]->curHookId = 0;
|
2004-03-23 22:51:44 +00:00
|
|
|
}
|
2004-04-08 21:13:25 +00:00
|
|
|
} else {
|
2004-04-11 14:56:11 +00:00
|
|
|
if (fadeDelay != 0) {
|
|
|
|
int fadeTrack = cloneToFadeOutTrack(track, fadeDelay, false);
|
|
|
|
_track[fadeTrack]->dataOffset = _sound->getRegionOffset(_track[fadeTrack]->soundHandle, _track[fadeTrack]->curRegion);
|
|
|
|
_track[fadeTrack]->regionOffset = 0;
|
|
|
|
debug(5, "switchToNextRegion-sound(%d) select %d region, curHookId: %d", _track[fadeTrack]->soundId, _track[fadeTrack]->curRegion, _track[fadeTrack]->curHookId);
|
|
|
|
}
|
2004-04-11 14:48:50 +00:00
|
|
|
_track[track]->curRegion = region;
|
|
|
|
debug(5, "switchToNextRegion-sound(%d) jump to %d region, curHookId: %d", _track[track]->soundId, _track[track]->curRegion, _track[track]->curHookId);
|
2004-01-08 18:25:30 +00:00
|
|
|
}
|
2004-01-08 08:39:25 +00:00
|
|
|
}
|
|
|
|
|
2004-04-11 14:48:50 +00:00
|
|
|
debug(5, "switchToNextRegion-sound(%d) select %d region, curHookId: %d", _track[track]->soundId, _track[track]->curRegion, _track[track]->curHookId);
|
|
|
|
_track[track]->dataOffset = _sound->getRegionOffset(_track[track]->soundHandle, _track[track]->curRegion);
|
|
|
|
_track[track]->regionOffset = 0;
|
2004-01-06 17:28:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // End of namespace Scumm
|