00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
00036
00037
00038
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
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);
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
00131 if (strlen(soundName) == 0)
00132 return false;
00133
00134 track = findTrack(soundName);
00135
00136 if (track == nullptr || !g_system->getMixer()->isSoundHandleActive(track->handle)) {
00137
00138
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
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 }