scummvm/engine/imuse/imuse_script.cpp

192 lines
6.1 KiB
C++
Raw Normal View History

2006-04-02 14:20:45 +00:00
/* Residual - Virtual machine to run LucasArts' 3D adventure games
* Copyright (C) 2003-2006 The ScummVM-Residual Team (www.scummvm.org)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library 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
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
* $URL$
* $Id$
*
*/
2004-12-26 13:43:43 +00:00
#include "common/sys.h"
#include "common/debug.h"
#include "common/timer.h"
#include "common/mutex.h"
#include "engine/backend/driver.h"
2004-12-26 13:43:43 +00:00
2005-01-01 12:27:57 +00:00
#include "mixer/mixer.h"
#include "mixer/audiostream.h"
2004-12-26 13:43:43 +00:00
#include "engine/imuse/imuse.h"
#include "engine/imuse/imuse_sndmgr.h"
2004-12-29 06:32:07 +00:00
void Imuse::flushTrack(Track *track) {
track->toBeRemoved = true;
if (track->stream) {
// Finalize the appendable stream, then remove our reference to it.
// Note that there might still be some data left in the buffers of the
// appendable stream. We play it nice and wait till all of it
// played. The audio mixer will take care of it afterwards (and dispose it).
track->stream->finish();
track->stream = 0;
if (track->soundDesc) {
_sound->closeSound(track->soundDesc);
track->soundDesc = 0;
}
}
if (!g_mixer->isSoundHandleActive(track->handle)) {
memset(track, 0, sizeof(Track));
}
}
2004-12-26 13:43:43 +00:00
void Imuse::flushTracks() {
Common::StackLock lock(_mutex);
2004-12-29 06:32:07 +00:00
for (int l = 0; l < MAX_IMUSE_TRACKS + MAX_IMUSE_FADETRACKS; l++) {
2004-12-26 13:43:43 +00:00
Track *track = _track[l];
if (track->used && track->toBeRemoved && !g_mixer->isSoundHandleActive(track->handle)) {
memset(track, 0, sizeof(Track));
2004-12-26 13:43:43 +00:00
}
}
}
void Imuse::refreshScripts() {
Common::StackLock lock(_mutex);
2004-12-26 13:43:43 +00:00
bool found = false;
2004-12-29 06:32:07 +00:00
for (int l = 0; l < MAX_IMUSE_TRACKS; l++) {
2004-12-26 13:43:43 +00:00
Track *track = _track[l];
if (track->used && !track->toBeRemoved && (track->volGroupId == IMUSE_VOLGRP_MUSIC)) {
found = true;
}
}
if (!found && _curMusicState) {
setMusicSequence(0);
2004-12-26 13:43:43 +00:00
}
}
2005-01-02 22:48:38 +00:00
void Imuse::startVoice(const char *soundName, int volume, int pan) {
if (debugLevel == DEBUG_IMUSE || debugLevel == DEBUG_ALL)
printf("Imuse::startVoice(): SoundName %s, vol:%d, pan:%d\n", soundName, volume, pan);
startSound(soundName, IMUSE_VOLGRP_VOICE, 0, volume, pan, 127, NULL);
2004-12-26 13:43:43 +00:00
}
2004-12-28 18:25:14 +00:00
void Imuse::startMusic(const char *soundName, int hookId, int volume, int pan) {
if (debugLevel == DEBUG_IMUSE || debugLevel == DEBUG_ALL)
printf("Imuse::startMusic(): SoundName %s, hookId:%d, vol:%d, pan:%d\n", soundName, hookId, volume, pan);
startSound(soundName, IMUSE_VOLGRP_MUSIC, hookId, volume, pan, 126, NULL);
}
void Imuse::startMusicWithOtherPos(const char *soundName, int hookId, int volume, int pan, Track *otherTrack) {
if (debugLevel == DEBUG_IMUSE || debugLevel == DEBUG_ALL)
2008-03-11 05:26:29 +00:00
printf("Imuse::startMusicWithOtherPos(): SoundName %s, hookId:%d, vol:%d, pan:%d\n", soundName, hookId, volume, pan);
startSound(soundName, IMUSE_VOLGRP_MUSIC, hookId, volume, pan, 126, otherTrack);
2004-12-26 13:43:43 +00:00
}
2004-12-28 18:25:14 +00:00
void Imuse::startSfx(const char *soundName, int priority) {
if (debugLevel == DEBUG_IMUSE || debugLevel == DEBUG_ALL)
printf("Imuse::startSfx(): SoundName %s, priority:%d\n", soundName, priority);
startSound(soundName, IMUSE_VOLGRP_SFX, 0, 127, 0, priority, NULL);
2004-12-26 13:43:43 +00:00
}
2005-01-01 21:07:52 +00:00
int32 Imuse::getPosIn60HzTicks(const char *soundName) {
Common::StackLock lock(_mutex);
Track *getTrack = NULL;
getTrack = findTrack(soundName);
// Warn the user if the track was not found
if (getTrack == NULL) {
if (debugLevel == DEBUG_IMUSE || debugLevel == DEBUG_WARN || debugLevel == DEBUG_ALL)
warning("Sound '%s' could not be found to get ticks!", soundName);
return false;
2004-12-26 13:43:43 +00:00
}
int32 pos = (5 * (getTrack->dataOffset + getTrack->regionOffset)) / (getTrack->feedSize / 200);
return pos;
2004-12-26 13:43:43 +00:00
}
2005-01-01 21:07:52 +00:00
bool Imuse::isVoicePlaying() {
Common::StackLock lock(_mutex);
2004-12-29 06:32:07 +00:00
for (int l = 0; l < MAX_IMUSE_TRACKS; l++) {
2004-12-26 13:43:43 +00:00
Track *track = _track[l];
if (track->used && track->volGroupId == IMUSE_VOLGRP_VOICE) {
if (g_mixer->isSoundHandleActive(track->handle))
2004-12-28 18:25:14 +00:00
return true;
2004-12-26 13:43:43 +00:00
}
}
return false;
}
bool Imuse::getSoundStatus(const char *soundName) {
Common::StackLock lock(_mutex);
Track *track = NULL;
// If there's no name then don't try to get the status!
if (strlen(soundName) == 0)
return false;
track = findTrack(soundName);
// Warn the user if the track was not found
if (track == NULL || !g_mixer->isSoundHandleActive(track->handle)) {
// This debug warning should be "light" since this function gets called
// on occassion to see if a sound has stopped yet
if (debugLevel == DEBUG_IMUSE || debugLevel == DEBUG_NORMAL || debugLevel == DEBUG_ALL)
printf("Sound '%s' could not be found to get status, assume inactive.\n", soundName);
return false;
2004-12-26 13:43:43 +00:00
}
return true;
2005-01-01 21:07:52 +00:00
}
2004-12-26 13:43:43 +00:00
2005-01-01 21:07:52 +00:00
void Imuse::stopSound(const char *soundName) {
Common::StackLock lock(_mutex);
if (debugLevel == DEBUG_IMUSE || debugLevel == DEBUG_ALL)
printf("Imuse::stopSound(): SoundName %s\n", soundName);
Track *removeTrack = NULL;
removeTrack = findTrack(soundName);
// Warn the user if the track was not found
if (removeTrack == NULL) {
if (debugLevel == DEBUG_IMUSE || debugLevel == DEBUG_WARN || debugLevel == DEBUG_ALL)
warning("Sound track '%s' could not be found to stop!", soundName);
return;
2004-12-26 13:43:43 +00:00
}
flushTrack(removeTrack);
2004-12-26 13:43:43 +00:00
}
void Imuse::stopAllSounds() {
Common::StackLock lock(_mutex);
if (debugLevel == DEBUG_IMUSE || debugLevel == DEBUG_ALL)
printf("Imuse::stopAllSounds()\n");
for (int l = 0; l < MAX_IMUSE_TRACKS + MAX_IMUSE_FADETRACKS; l++) {
Track *track = _track[l];
if (track->used) {
g_mixer->stopHandle(track->handle);
if (track->soundDesc) {
_sound->closeSound(track->soundDesc);
2004-12-26 13:43:43 +00:00
}
memset(track, 0, sizeof(Track));
2004-12-26 13:43:43 +00:00
}
}
}
void Imuse::pause(bool p) {
_pause = p;
}