[Scummvm-cvs-logs] CVS: scummvm/sword2/driver d_sound.cpp,1.139,1.140
Torbjörn Andersson
eriktorbjorn at users.sourceforge.net
Tue Feb 8 00:34:42 CET 2005
- Previous message: [Scummvm-cvs-logs] CVS: scummvm/sword2 controls.cpp,1.83,1.84 function.cpp,1.75,1.76 resman.cpp,1.104,1.105 sound.cpp,1.52,1.53 sound.h,1.14,1.15
- Next message: [Scummvm-cvs-logs] CVS: scummvm/scumm intern.h,2.331,2.332 script_v100he.cpp,2.42,2.43
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/scummvm/scummvm/sword2/driver
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14091/driver
Modified Files:
d_sound.cpp
Log Message:
Now there are two file handles for the music: one for each CD. This is not
the same thing as one for each music stream. If both music streams are
playing music from the same CD, they will both take turns at using the same
file handle.
The only case where both file handles are used is when music from one CD is
fading in while music from the other CD is fading out. Which of course can
only happen if you play the game from hard disk. If the game has to ask for
the other CD, it kills the music immediately.
The reason for doing this is that there was some concern about whether
having two file handles open to the same file was portable or not. I don't
think that question was ever fully answered, so I avoid the situation.
Index: d_sound.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/driver/d_sound.cpp,v
retrieving revision 1.139
retrieving revision 1.140
diff -u -d -r1.139 -r1.140
--- d_sound.cpp 7 Feb 2005 10:51:48 -0000 1.139
+++ d_sound.cpp 8 Feb 2005 08:32:50 -0000 1.140
@@ -41,8 +41,6 @@
static AudioStream *makeCLUStream(File *fp, int size);
-static File fpMus;
-
static AudioStream *getAudioStream(File *fp, const char *base, int cd, uint32 id, uint32 *numSamples) {
struct {
const char *ext;
@@ -228,10 +226,17 @@
// The length of a fade-in/out, in milliseconds.
#define FADE_LENGTH 3000
-MusicInputStream::MusicInputStream(int cd, uint32 musicId, bool looping)
- : _cd(cd), _musicId(musicId), _bufferEnd(_buffer + BUFFER_SIZE),
- _remove(false), _looping(looping), _fading(0) {
- _decoder = getAudioStream(&fpMus, "music", _cd, _musicId, &_numSamples);
+MusicInputStream::MusicInputStream(int cd, File *fp, uint32 musicId, bool looping) {
+ _cd = cd;
+ _file = fp;
+ _musicId = musicId;
+ _looping = looping;
+
+ _bufferEnd = _buffer + BUFFER_SIZE;
+ _remove = false;
+ _fading = 0;
+
+ _decoder = getAudioStream(fp, "music", _cd, _musicId, &_numSamples);
if (_decoder) {
_samplesLeft = _numSamples;
_fadeSamples = (getRate() * FADE_LENGTH) / 1000;
@@ -349,7 +354,7 @@
if (!_samplesLeft) {
if (_looping) {
delete _decoder;
- _decoder = getAudioStream(&fpMus, "music", _cd, _musicId, &_numSamples);
+ _decoder = getAudioStream(_file, "music", _cd, _musicId, &_numSamples);
_samplesLeft = _numSamples;
} else
_remove = true;
@@ -429,15 +434,36 @@
}
}
- if (!_music[0] && !_music[1] && fpMus.isOpen())
- fpMus.close();
+ bool inUse[MAXMUS];
+
+ for (i = 0; i < MAXMUS; i++)
+ inUse[i] = false;
+
+ for (i = 0; i < MAXMUS; i++) {
+ if (_music[i]) {
+ if (_music[i]->whichCd() == 1)
+ inUse[0] = true;
+ else
+ inUse[1] = true;
+ }
+ }
+
+ for (i = 0; i < MAXMUS; i++) {
+ if (!inUse[i] && _musicFile[i].isOpen())
+ _musicFile[i].close();
+ }
return numSamples;
}
-bool Sound::isStereo() const { return false; }
-bool Sound::endOfData() const { return !fpMus.isOpen(); }
-int Sound::getRate() const { return 22050; }
+bool Sound::endOfData() const {
+ for (int i = 0; i < MAXMUS; i++) {
+ if (_musicFile[i].isOpen())
+ return false;
+ }
+
+ return true;
+}
// ----------------------------------------------------------------------------
// MUSIC
@@ -468,14 +494,20 @@
* Fades out and stops the music.
*/
-void Sound::stopMusic() {
+void Sound::stopMusic(bool immediately) {
Common::StackLock lock(_mutex);
_loopingMusicId = 0;
- for (int i = 0; i < MAXMUS; i++)
- if (_music[i])
- _music[i]->fadeDown();
+ for (int i = 0; i < MAXMUS; i++) {
+ if (_music[i]) {
+ if (immediately) {
+ delete _music[i];
+ _music[i] = NULL;
+ } else
+ _music[i]->fadeDown();
+ }
+ }
}
/**
@@ -489,19 +521,6 @@
int cd = _vm->_resman->whichCd();
- // HACK: We only have one music file handle, so if any music from the
- // "wrong" CD is playing, kill it immediately.
-
- for (int i = 0; i < MAXMUS; i++) {
- if (_music[i] && _music[i]->whichCd() != cd) {
- delete _music[i];
- _music[i] = NULL;
-
- if (fpMus.isOpen())
- fpMus.close();
- }
- }
-
if (loop)
_loopingMusicId = musicId;
else
@@ -560,7 +579,9 @@
if (secondary != -1)
_music[secondary]->fadeDown();
- _music[primary] = new MusicInputStream(cd, musicId, loop);
+ File *fp = (cd == 1) ? &_musicFile[0] : &_musicFile[1];
+
+ _music[primary] = new MusicInputStream(cd, fp, musicId, loop);
if (!_music[primary]->isReady()) {
delete _music[primary];
- Previous message: [Scummvm-cvs-logs] CVS: scummvm/sword2 controls.cpp,1.83,1.84 function.cpp,1.75,1.76 resman.cpp,1.104,1.105 sound.cpp,1.52,1.53 sound.h,1.14,1.15
- Next message: [Scummvm-cvs-logs] CVS: scummvm/scumm intern.h,2.331,2.332 script_v100he.cpp,2.42,2.43
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Scummvm-git-logs
mailing list