ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

imuse_script.cpp

Go to the documentation of this file.
00001 /* ResidualVM - A 3D game interpreter
00002  *
00003  * ResidualVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #include "common/textconsole.h"
00024 
00025 #include "engines/grim/imuse/imuse.h"
00026 
00027 #include "engines/grim/debug.h"
00028 
00029 namespace Grim {
00030 
00031 void Imuse::flushTrack(Track *track) {
00032     track->toBeRemoved = true;
00033 
00034     if (track->stream) {
00035         // Finalize the appendable stream, then remove our reference to it.
00036         // Note that there might still be some data left in the buffers of the
00037         // appendable stream. We play it nice and wait till all of it
00038         // played. The audio mixer will take care of it afterwards (and dispose it).
00039         track->stream->finish();
00040         track->stream = nullptr;
00041         if (track->soundDesc) {
00042             _sound->closeSound(track->soundDesc);
00043             track->soundDesc = nullptr;
00044         }
00045     }
00046 
00047     if (!g_system->getMixer()->isSoundHandleActive(track->handle)) {
00048         memset(track, 0, sizeof(Track));
00049     }
00050 }
00051 
00052 void Imuse::flushTracks() {
00053     Common::StackLock lock(_mutex);
00054     for (int l = 0; l < MAX_IMUSE_TRACKS + MAX_IMUSE_FADETRACKS; l++) {
00055         Track *track = _track[l];
00056         if (track->used && track->toBeRemoved && !g_system->getMixer()->isSoundHandleActive(track->handle)) {
00057             memset(track, 0, sizeof(Track));
00058         }
00059     }
00060 }
00061 
00062 void Imuse::refreshScripts() {
00063     Common::StackLock lock(_mutex);
00064     bool found = false;
00065 
00066     for (int l = 0; l < MAX_IMUSE_TRACKS; l++) {
00067         Track *track = _track[l];
00068         if (track->used && !track->toBeRemoved && (track->volGroupId == IMUSE_VOLGRP_MUSIC)) {
00069             found = true;
00070         }
00071     }
00072 
00073     if (!found && _curMusicState) {
00074         setMusicSequence(0);
00075     }
00076 }
00077 
00078 bool Imuse::startVoice(const char *soundName, int volume, int pan) {
00079     Debug::debug(Debug::Sound, "Imuse::startVoice(): SoundName %s, vol:%d, pan:%d", soundName, volume, pan);
00080     return startSound(soundName, IMUSE_VOLGRP_VOICE, 0, volume, pan, 127, nullptr);
00081 }
00082 
00083 void Imuse::startMusic(const char *soundName, int hookId, int volume, int pan) {
00084     Debug::debug(Debug::Sound, "Imuse::startMusic(): SoundName %s, hookId:%d, vol:%d, pan:%d", soundName, hookId, volume, pan);
00085     startSound(soundName, IMUSE_VOLGRP_MUSIC, hookId, volume, pan, 126, nullptr);
00086 }
00087 
00088 void Imuse::startMusicWithOtherPos(const char *soundName, int hookId, int volume, int pan, Track *otherTrack) {
00089     Debug::debug(Debug::Sound, "Imuse::startMusicWithOtherPos(): SoundName %s, hookId:%d, vol:%d, pan:%d", soundName, hookId, volume, pan);
00090     startSound(soundName, IMUSE_VOLGRP_MUSIC, hookId, volume, pan, 126, otherTrack);
00091 }
00092 
00093 void Imuse::startSfx(const char *soundName, int priority) {
00094     Debug::debug(Debug::Sound, "Imuse::startSfx(): SoundName %s, priority:%d", soundName, priority);
00095     startSound(soundName, IMUSE_VOLGRP_SFX, 0, 127, 0, priority, nullptr);
00096 }
00097 
00098 int32 Imuse::getPosIn16msTicks(const char *soundName) {
00099     Common::StackLock lock(_mutex);
00100     Track *getTrack = nullptr;
00101 
00102     getTrack = findTrack(soundName);
00103     // Warn the user if the track was not found
00104     if (getTrack == nullptr) {
00105         Debug::warning(Debug::Sound, "Sound '%s' could not be found to get ticks", soundName);
00106         return false;
00107     }
00108 
00109     int32 pos = (62.5 / 60.0) * (5 * (getTrack->dataOffset + getTrack->regionOffset)) / (getTrack->feedSize / 12); // 16ms is 62.5 Hz
00110     return pos;
00111 }
00112 
00113 bool Imuse::isVoicePlaying() {
00114     Common::StackLock lock(_mutex);
00115     for (int l = 0; l < MAX_IMUSE_TRACKS; l++) {
00116         Track *track = _track[l];
00117         if (track->used && track->volGroupId == IMUSE_VOLGRP_VOICE) {
00118             if (g_system->getMixer()->isSoundHandleActive(track->handle))
00119                 return true;
00120         }
00121     }
00122 
00123     return false;
00124 }
00125 
00126 bool Imuse::getSoundStatus(const char *soundName) {
00127     Common::StackLock lock(_mutex);
00128     Track *track = nullptr;
00129 
00130     // If there's no name then don't try to get the status!
00131     if (strlen(soundName) == 0)
00132         return false;
00133 
00134     track = findTrack(soundName);
00135     // Warn the user if the track was not found
00136     if (track == nullptr || !g_system->getMixer()->isSoundHandleActive(track->handle)) {
00137         // This debug warning should be "light" since this function gets called
00138         // on occassion to see if a sound has stopped yet
00139         Debug::debug(Debug::Sound, "Sound '%s' could not be found to get status, assume inactive.", soundName);
00140         return false;
00141     }
00142     return true;
00143 }
00144 
00145 void Imuse::stopSound(const char *soundName) {
00146     Common::StackLock lock(_mutex);
00147     Debug::debug(Debug::Sound, "Imuse::stopSound(): SoundName %s", soundName);
00148     Track *removeTrack = nullptr;
00149 
00150     removeTrack = findTrack(soundName);
00151     // Warn the user if the track was not found
00152     if (removeTrack == nullptr) {
00153         Debug::warning(Debug::Sound, "Sound track '%s' could not be found to stop", soundName);
00154         return;
00155     }
00156     flushTrack(removeTrack);
00157 }
00158 
00159 void Imuse::stopAllSounds() {
00160     Common::StackLock lock(_mutex);
00161     Debug::debug(Debug::Sound, "Imuse::stopAllSounds()");
00162 
00163     for (int l = 0; l < MAX_IMUSE_TRACKS + MAX_IMUSE_FADETRACKS; l++) {
00164         Track *track = _track[l];
00165         if (track->used) {
00166             g_system->getMixer()->stopHandle(track->handle);
00167             if (track->soundDesc) {
00168                 _sound->closeSound(track->soundDesc);
00169             }
00170             memset(track, 0, sizeof(Track));
00171         }
00172     }
00173 }
00174 
00175 void Imuse::pause(bool p) {
00176     _pause = p;
00177 }
00178 
00179 } // end of namespace Grim


Generated on Sat May 25 2019 05:00:47 for ResidualVM by doxygen 1.7.1
curved edge   curved edge