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/mutex.h" 00024 #include "common/textconsole.h" 00025 #include "audio/mixer.h" 00026 #include "audio/audiostream.h" 00027 #include "engines/grim/debug.h" 00028 #include "engines/grim/resource.h" 00029 #include "engines/grim/emi/sound/codecs/scx.h" 00030 #include "engines/grim/emi/sound/scxtrack.h" 00031 00032 namespace Grim { 00033 00034 SCXTrack::SCXTrack(Audio::Mixer::SoundType soundType) { 00035 _disposeAfterPlaying = DisposeAfterUse::NO; 00036 _soundType = soundType; 00037 _looping = false; 00038 } 00039 00040 SCXTrack::~SCXTrack() { 00041 stop(); 00042 if (_handle) { 00043 g_system->getMixer()->stopHandle(*_handle); 00044 delete _handle; 00045 } 00046 } 00047 00048 bool SCXTrack::openSound(const Common::String &filename, const Common::String &soundName, const Audio::Timestamp *start) { 00049 Common::SeekableReadStream *file = g_resourceloader->openNewStreamFile(filename); 00050 if (!file) { 00051 Debug::debug(Debug::Sound, "Stream for %s not open", soundName.c_str()); 00052 return false; 00053 } 00054 _soundName = soundName; 00055 Audio::RewindableAudioStream *scxStream = makeSCXStream(file, start, DisposeAfterUse::YES); 00056 _stream = scxStream; 00057 _handle = new Audio::SoundHandle(); 00058 return true; 00059 } 00060 00061 bool SCXTrack::isPlaying() { 00062 if (!_handle) 00063 return false; 00064 00065 return g_system->getMixer()->isSoundHandleActive(*_handle); 00066 } 00067 00068 Audio::Timestamp SCXTrack::getPos() { 00069 if (!_stream || _looping) 00070 return Audio::Timestamp(0); 00071 return dynamic_cast<SCXStream*>(_stream)->getPos(); 00072 } 00073 00074 bool SCXTrack::play() { 00075 if (_stream) { 00076 Audio::RewindableAudioStream *stream = dynamic_cast<Audio::RewindableAudioStream *>(_stream); 00077 if (!_looping) { 00078 stream->rewind(); 00079 } 00080 return SoundTrack::play(); 00081 } 00082 return false; 00083 } 00084 00085 void SCXTrack::setLooping(bool looping) { 00086 if (_looping == looping) 00087 return; 00088 _looping = looping; 00089 if (looping && _stream) { 00090 _stream = Audio::makeLoopingAudioStream(dynamic_cast<Audio::RewindableAudioStream *>(_stream), 0); 00091 } 00092 } 00093 00094 } // end of namespace Grim