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

default-audiocd.cpp

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM 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 "backends/audiocd/default/default-audiocd.h"
00024 #include "audio/audiostream.h"
00025 #include "common/config-manager.h"
00026 #include "common/system.h"
00027 
00028 DefaultAudioCDManager::DefaultAudioCDManager() {
00029     _cd.playing = false;
00030     _cd.track = 0;
00031     _cd.start = 0;
00032     _cd.duration = 0;
00033     _cd.numLoops = 0;
00034     _cd.volume = Audio::Mixer::kMaxChannelVolume;
00035     _cd.balance = 0;
00036     _mixer = g_system->getMixer();
00037     _emulating = false;
00038     assert(_mixer);
00039 }
00040 
00041 DefaultAudioCDManager::~DefaultAudioCDManager() {
00042     // Subclasses should call close as well
00043     close();
00044 }
00045 
00046 bool DefaultAudioCDManager::open() {
00047     // For emulation, opening is always valid
00048     close();
00049     return true;
00050 }
00051 
00052 void DefaultAudioCDManager::close() {
00053     // Only need to stop for emulation
00054     stop();
00055 }
00056 
00057 bool DefaultAudioCDManager::play(int track, int numLoops, int startFrame, int duration, bool onlyEmulate,
00058         Audio::Mixer::SoundType soundType) {
00059     stop();
00060 
00061     if (numLoops != 0 || startFrame != 0) {
00062         _cd.track = track;
00063         _cd.numLoops = numLoops;
00064         _cd.start = startFrame;
00065         _cd.duration = duration;
00066 
00067         // Try to load the track from a compressed data file, and if found, use
00068         // that. If not found, attempt to start regular Audio CD playback of
00069         // the requested track.
00070         char trackName[2][16];
00071         sprintf(trackName[0], "track%d", track);
00072         sprintf(trackName[1], "track%02d", track);
00073         Audio::SeekableAudioStream *stream = 0;
00074 
00075         for (int i = 0; !stream && i < 2; ++i)
00076             stream = Audio::SeekableAudioStream::openStreamFile(trackName[i]);
00077 
00078         if (stream != 0) {
00079             Audio::Timestamp start = Audio::Timestamp(0, startFrame, 75);
00080             Audio::Timestamp end = duration ? Audio::Timestamp(0, startFrame + duration, 75) : stream->getLength();
00081 
00082             /*
00083             FIXME: Seems numLoops == 0 and numLoops == 1 both indicate a single repetition,
00084             while all other positive numbers indicate precisely the number of desired
00085             repetitions. Finally, -1 means infinitely many
00086             */
00087             _emulating = true;
00088             _mixer->playStream(soundType, &_handle,
00089                                     Audio::makeLoopingAudioStream(stream, start, end, (numLoops < 1) ? numLoops + 1 : numLoops), -1, _cd.volume, _cd.balance);
00090             return true;
00091         }
00092     }
00093 
00094     return false;
00095 }
00096 
00097 void DefaultAudioCDManager::stop() {
00098     if (_emulating) {
00099         // Audio CD emulation
00100         _mixer->stopHandle(_handle);
00101         _emulating = false;
00102     }
00103 }
00104 
00105 bool DefaultAudioCDManager::isPlaying() const {
00106     // Audio CD emulation
00107     if (_emulating)
00108         return _mixer->isSoundHandleActive(_handle);
00109 
00110     // The default class only handles emulation
00111     return false;
00112 }
00113 
00114 void DefaultAudioCDManager::setVolume(byte volume) {
00115     _cd.volume = volume;
00116 
00117     // Audio CD emulation
00118     if (_emulating && isPlaying())
00119         _mixer->setChannelVolume(_handle, _cd.volume);
00120 }
00121 
00122 void DefaultAudioCDManager::setBalance(int8 balance) {
00123     _cd.balance = balance;
00124 
00125     // Audio CD emulation
00126     if (_emulating && isPlaying())
00127         _mixer->setChannelBalance(_handle, _cd.balance);
00128 }
00129 
00130 void DefaultAudioCDManager::update() {
00131     if (_emulating) {
00132         // Check whether the audio track stopped playback
00133         if (!_mixer->isSoundHandleActive(_handle)) {
00134             // FIXME: We do not update the numLoops parameter here (and in fact,
00135             // currently can't do that). Luckily, only one engine ever checks
00136             // this part of the AudioCD status, namely the SCUMM engine; and it
00137             // only checks whether the track is currently set to infinite looping
00138             // or not.
00139             _emulating = false;
00140         }
00141     }
00142 }
00143 
00144 DefaultAudioCDManager::Status DefaultAudioCDManager::getStatus() const {
00145     Status info = _cd;
00146     info.playing = isPlaying();
00147     return info;
00148 }
00149 
00150 bool DefaultAudioCDManager::openRealCD() {
00151     Common::String cdrom = ConfMan.get("cdrom");
00152 
00153     // Try to parse it as an int
00154     char *endPos;
00155     int drive = strtol(cdrom.c_str(), &endPos, 0);
00156 
00157     // If not an integer, treat as a drive path
00158     if (endPos == cdrom.c_str())
00159         return openCD(cdrom);
00160 
00161     if (drive < 0)
00162         return false;
00163 
00164     return openCD(drive);
00165 }
00166 


Generated on Sat Mar 16 2019 05:01:24 for ResidualVM by doxygen 1.7.1
curved edge   curved edge