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

aifftrack.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/mutex.h"
00024 #include "audio/mixer.h"
00025 #include "audio/audiostream.h"
00026 #include "audio/decoders/aiff.h"
00027 #include "engines/grim/debug.h"
00028 #include "engines/grim/resource.h"
00029 #include "engines/grim/emi/sound/aifftrack.h"
00030 
00031 namespace Grim {
00032 
00033 AIFFTrack::AIFFTrack(Audio::Mixer::SoundType soundType) {
00034     _soundType = soundType;
00035     _looping = false;
00036     // A preloaded AIFF track may be played multiple times, so we don't
00037     // want to dispose after playing. The destructor of SoundTrack will
00038     // take care of disposing the stream instead.
00039     _disposeAfterPlaying = DisposeAfterUse::NO;
00040 }
00041 
00042 AIFFTrack::~AIFFTrack() {
00043     stop();
00044     if (_handle) {
00045         g_system->getMixer()->stopHandle(*_handle);
00046         delete _handle;
00047     }
00048 }
00049 
00050 bool AIFFTrack::openSound(const Common::String &filename, const Common::String &soundName, const Audio::Timestamp *start) {
00051     Common::SeekableReadStream *file = g_resourceloader->openNewStreamFile(filename, true);
00052     if (!file) {
00053         Debug::debug(Debug::Sound, "Stream for %s not open", soundName.c_str());
00054         return false;
00055     }
00056     _soundName = soundName;
00057     Audio::RewindableAudioStream *aiffStream = Audio::makeAIFFStream(file, DisposeAfterUse::YES);
00058     Audio::SeekableAudioStream *seekStream = dynamic_cast<Audio::SeekableAudioStream *>(aiffStream);
00059     _stream = aiffStream;
00060     if (start)
00061         seekStream->seek(*start);
00062     if (!_stream)
00063         return false;
00064     _handle = new Audio::SoundHandle();
00065     return true;
00066 }
00067 
00068 void AIFFTrack::setLooping(bool looping) {
00069     if (_looping == looping)
00070         return;
00071     _looping = looping;
00072     if (looping && _stream) {
00073         _stream = Audio::makeLoopingAudioStream(dynamic_cast<Audio::SeekableAudioStream *>(_stream), 0);
00074     }
00075 }
00076 
00077 bool AIFFTrack::play() {
00078     if (_stream) {
00079         Audio::RewindableAudioStream *stream = dynamic_cast<Audio::RewindableAudioStream *>(_stream);
00080         if (!_looping) {
00081             stream->rewind();
00082         }
00083         return SoundTrack::play();
00084     }
00085     return false;
00086 }
00087 
00088 bool AIFFTrack::isPlaying() {
00089     if (!_handle)
00090         return false;
00091 
00092     return g_system->getMixer()->isSoundHandleActive(*_handle);
00093 }
00094 
00095 Audio::Timestamp AIFFTrack::getPos() {
00096     // FIXME: Return actual stream position.
00097     return g_system->getMixer()->getSoundElapsedTime(*_handle);
00098 }
00099 
00100 } // end of namespace Grim


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