2003-12-16 02:10:15 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
2006-01-18 17:39:49 +00:00
|
|
|
* Copyright (C) 2003-2006 The ScummVM project
|
2003-12-16 02:10:15 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2003-12-16 02:10:15 +00:00
|
|
|
*
|
2006-02-11 10:01:01 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2003-12-16 02:10:15 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef BSMUSIC_H
|
|
|
|
#define BSMUSIC_H
|
|
|
|
|
2005-06-24 15:23:51 +00:00
|
|
|
#include "common/scummsys.h"
|
2005-01-10 22:06:49 +00:00
|
|
|
#include "common/mutex.h"
|
2003-12-16 02:10:15 +00:00
|
|
|
#include "common/file.h"
|
2004-01-01 15:22:15 +00:00
|
|
|
#include "sound/audiostream.h"
|
|
|
|
#include "sound/rate.h"
|
|
|
|
|
2005-05-10 23:48:48 +00:00
|
|
|
namespace Audio {
|
|
|
|
class Mixer;
|
|
|
|
}
|
2004-01-11 15:47:41 +00:00
|
|
|
|
|
|
|
namespace Sword1 {
|
|
|
|
|
2003-12-16 02:10:15 +00:00
|
|
|
#define TOTAL_TUNES 270
|
|
|
|
|
2004-10-12 15:50:00 +00:00
|
|
|
enum MusicMode {
|
|
|
|
MusicNone = 0,
|
|
|
|
MusicWave,
|
|
|
|
MusicMp3,
|
|
|
|
MusicVorbis
|
|
|
|
};
|
|
|
|
|
|
|
|
class WaveAudioStream : public AudioStream {
|
|
|
|
public:
|
2005-05-10 22:56:25 +00:00
|
|
|
WaveAudioStream(Common::File *source, uint32 pSize);
|
2004-10-12 15:50:00 +00:00
|
|
|
virtual ~WaveAudioStream();
|
|
|
|
virtual int readBuffer(int16 *buffer, const int numSamples);
|
|
|
|
virtual bool isStereo(void) const { return _isStereo; };
|
|
|
|
virtual bool endOfData(void) const;
|
|
|
|
virtual int getRate(void) const { return _rate; };
|
|
|
|
private:
|
2005-05-10 22:56:25 +00:00
|
|
|
Common::File *_sourceFile;
|
2004-12-10 18:26:08 +00:00
|
|
|
uint8 *_sampleBuf;
|
2004-10-12 15:50:00 +00:00
|
|
|
uint32 _rate;
|
|
|
|
bool _isStereo;
|
|
|
|
uint32 _samplesLeft;
|
|
|
|
uint16 _bitsPerSample;
|
|
|
|
};
|
|
|
|
|
2004-01-11 15:47:41 +00:00
|
|
|
class MusicHandle : public AudioStream {
|
2004-01-01 15:22:15 +00:00
|
|
|
private:
|
2005-05-10 22:56:25 +00:00
|
|
|
Common::File _file;
|
2004-01-01 15:22:15 +00:00
|
|
|
bool _looping;
|
|
|
|
int32 _fading;
|
2004-01-01 16:56:00 +00:00
|
|
|
int32 _fadeSamples;
|
2004-10-12 15:50:00 +00:00
|
|
|
MusicMode _musicMode;
|
|
|
|
AudioStream *_audioSource;
|
|
|
|
AudioStream *createAudioSource(void);
|
2004-01-01 15:22:15 +00:00
|
|
|
public:
|
2004-10-12 15:50:00 +00:00
|
|
|
MusicHandle() : _looping(false), _fading(0), _audioSource(NULL) {}
|
2004-01-01 15:22:15 +00:00
|
|
|
virtual int readBuffer(int16 *buffer, const int numSamples);
|
|
|
|
bool play(const char *filename, bool loop);
|
|
|
|
void stop();
|
|
|
|
void fadeUp();
|
|
|
|
void fadeDown();
|
2004-10-12 15:50:00 +00:00
|
|
|
bool streaming() const;
|
2004-01-01 15:22:15 +00:00
|
|
|
int32 fading() { return _fading; }
|
|
|
|
bool endOfData() const;
|
|
|
|
bool endOfStream() const { return false; }
|
2004-10-12 15:50:00 +00:00
|
|
|
bool isStereo() const;
|
|
|
|
int getRate() const;
|
2004-01-01 15:22:15 +00:00
|
|
|
};
|
|
|
|
|
2004-11-27 16:18:25 +00:00
|
|
|
class Music : public AudioStream {
|
2003-12-16 02:10:15 +00:00
|
|
|
public:
|
2005-05-10 23:48:48 +00:00
|
|
|
Music(Audio::Mixer *pMixer);
|
2004-01-11 15:47:41 +00:00
|
|
|
~Music();
|
2003-12-16 02:10:15 +00:00
|
|
|
void startMusic(int32 tuneId, int32 loopFlag);
|
2004-01-01 15:22:15 +00:00
|
|
|
void fadeDown();
|
2004-01-07 17:47:46 +00:00
|
|
|
void setVolume(uint8 volL, uint8 volR);
|
|
|
|
void giveVolume(uint8 *volL, uint8 *volR);
|
2004-11-27 16:18:25 +00:00
|
|
|
|
|
|
|
// AudioStream API
|
|
|
|
int readBuffer(int16 *buffer, const int numSamples) {
|
|
|
|
mixer(buffer, numSamples / 2);
|
|
|
|
return numSamples;
|
|
|
|
}
|
|
|
|
bool isStereo() const { return true; }
|
|
|
|
bool endOfData() const { return false; }
|
|
|
|
int getRate() const { return _sampleRate; }
|
|
|
|
|
2003-12-16 02:10:15 +00:00
|
|
|
private:
|
2005-05-11 00:01:44 +00:00
|
|
|
Audio::st_volume_t _volumeL, _volumeR;
|
2004-01-11 15:47:41 +00:00
|
|
|
MusicHandle _handles[2];
|
2005-05-11 00:01:44 +00:00
|
|
|
Audio::RateConverter *_converter[2];
|
2005-05-10 23:48:48 +00:00
|
|
|
Audio::Mixer *_mixer;
|
2004-11-27 16:18:25 +00:00
|
|
|
uint32 _sampleRate;
|
2005-01-28 22:05:51 +00:00
|
|
|
Common::Mutex _mutex;
|
2004-11-27 16:18:25 +00:00
|
|
|
|
2003-12-16 02:10:15 +00:00
|
|
|
static void passMixerFunc(void *param, int16 *buf, uint len);
|
2003-12-22 02:47:43 +00:00
|
|
|
void mixer(int16 *buf, uint32 len);
|
2004-11-27 16:18:25 +00:00
|
|
|
|
2003-12-16 02:10:15 +00:00
|
|
|
static const char _tuneList[TOTAL_TUNES][8]; // in staticres.cpp
|
|
|
|
};
|
|
|
|
|
2005-07-30 21:11:48 +00:00
|
|
|
} // End of namespace Sword1
|
2004-01-11 15:47:41 +00:00
|
|
|
|
2003-12-16 02:10:15 +00:00
|
|
|
#endif // BSMUSIC_H
|