2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
2006-05-23 23:43:52 +00:00
|
|
|
*
|
2007-05-30 21:56:52 +00:00
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
2006-05-23 23:43:52 +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.
|
2014-02-18 01:34:17 +00:00
|
|
|
*
|
2006-05-23 23:43:52 +00:00
|
|
|
* 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.
|
2014-02-18 01:34:17 +00:00
|
|
|
*
|
2006-05-23 23:43:52 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2006-05-24 14:25:42 +00:00
|
|
|
#ifndef AGI_SOUND_H
|
|
|
|
#define AGI_SOUND_H
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2011-02-09 01:09:01 +00:00
|
|
|
#include "audio/mixer.h"
|
2006-05-23 23:43:52 +00:00
|
|
|
|
|
|
|
namespace Agi {
|
|
|
|
|
|
|
|
#define SOUND_EMU_NONE 0
|
|
|
|
#define SOUND_EMU_PC 1
|
2010-06-15 10:36:10 +00:00
|
|
|
#define SOUND_EMU_PCJR 2
|
2006-05-23 23:43:52 +00:00
|
|
|
#define SOUND_EMU_MAC 3
|
|
|
|
#define SOUND_EMU_AMIGA 4
|
2007-08-17 13:10:57 +00:00
|
|
|
#define SOUND_EMU_APPLE2GS 5
|
2009-06-17 23:16:21 +00:00
|
|
|
#define SOUND_EMU_COCO3 6
|
2010-06-15 10:34:45 +00:00
|
|
|
#define SOUND_EMU_MIDI 7
|
2006-05-23 23:43:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* AGI sound note structure.
|
|
|
|
*/
|
2007-01-16 12:40:51 +00:00
|
|
|
struct AgiNote {
|
2007-08-15 15:55:38 +00:00
|
|
|
uint16 duration; ///< Note duration
|
|
|
|
uint16 freqDiv; ///< Note frequency divisor (10-bit)
|
|
|
|
uint8 attenuation; ///< Note volume attenuation (4-bit)
|
|
|
|
|
|
|
|
/** Reads an AgiNote through the given pointer. */
|
2007-08-15 22:00:31 +00:00
|
|
|
void read(const uint8 *ptr) {
|
2007-08-15 15:55:38 +00:00
|
|
|
duration = READ_LE_UINT16(ptr);
|
|
|
|
uint16 freqByte0 = *(ptr + 2); // Bits 4-9 of the frequency divisor
|
|
|
|
uint16 freqByte1 = *(ptr + 3); // Bits 0-3 of the frequency divisor
|
|
|
|
// Merge the frequency divisor's bits together into a single variable
|
|
|
|
freqDiv = ((freqByte0 & 0x3F) << 4) | (freqByte1 & 0x0F);
|
|
|
|
attenuation = *(ptr + 4) & 0x0F;
|
|
|
|
}
|
2006-05-23 23:43:52 +00:00
|
|
|
};
|
|
|
|
|
2009-06-17 23:16:21 +00:00
|
|
|
/**
|
|
|
|
* AGI sound resource types.
|
|
|
|
* It's probably coincidence that all the values here are powers of two
|
|
|
|
* as they're simply the different used values in AGI sound resources'
|
|
|
|
* starts (The first 16-bit little endian word, to be precise).
|
|
|
|
*/
|
2010-06-15 10:35:10 +00:00
|
|
|
enum AgiSoundEmuType {
|
2009-06-17 23:16:21 +00:00
|
|
|
AGI_SOUND_SAMPLE = 0x0001,
|
|
|
|
AGI_SOUND_MIDI = 0x0002,
|
|
|
|
AGI_SOUND_4CHN = 0x0008
|
|
|
|
};
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2007-08-15 22:00:31 +00:00
|
|
|
class SoundMgr;
|
|
|
|
|
2010-06-15 10:36:10 +00:00
|
|
|
class SoundGen {
|
|
|
|
public:
|
2011-08-14 17:08:44 +00:00
|
|
|
SoundGen(AgiBase *vm, Audio::Mixer *pMixer) : _vm(vm), _mixer(pMixer) {
|
2010-06-15 10:36:54 +00:00
|
|
|
_sampleRate = pMixer->getOutputRate();
|
|
|
|
}
|
|
|
|
|
2010-06-15 10:36:10 +00:00
|
|
|
virtual ~SoundGen() {}
|
|
|
|
|
2010-06-15 10:36:54 +00:00
|
|
|
virtual void play(int resnum) = 0;
|
2010-06-15 10:36:10 +00:00
|
|
|
virtual void stop(void) = 0;
|
|
|
|
|
2011-08-14 17:08:44 +00:00
|
|
|
AgiBase *_vm;
|
2010-06-15 10:36:54 +00:00
|
|
|
|
|
|
|
Audio::Mixer *_mixer;
|
|
|
|
Audio::SoundHandle _soundHandle;
|
|
|
|
|
|
|
|
uint32 _sampleRate;
|
2010-06-15 10:36:10 +00:00
|
|
|
};
|
|
|
|
|
2007-08-15 18:37:52 +00:00
|
|
|
/**
|
|
|
|
* AGI sound resource structure.
|
|
|
|
*/
|
|
|
|
class AgiSound {
|
|
|
|
public:
|
2013-04-18 18:07:39 +00:00
|
|
|
AgiSound() : _isPlaying(false), _isValid(false) {}
|
2007-08-16 18:42:28 +00:00
|
|
|
virtual ~AgiSound() {}
|
2007-08-15 18:37:52 +00:00
|
|
|
virtual void play() { _isPlaying = true; }
|
|
|
|
virtual void stop() { _isPlaying = false; }
|
|
|
|
virtual bool isPlaying() { return _isPlaying; }
|
2007-08-15 22:00:31 +00:00
|
|
|
virtual uint16 type() = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A named constructor for creating different types of AgiSound objects
|
|
|
|
* from a raw sound resource.
|
|
|
|
*
|
|
|
|
* NOTE: This function should take responsibility for freeing the raw resource
|
|
|
|
* from memory using free() or delegate the responsibility onwards to some other
|
|
|
|
* function!
|
|
|
|
*/
|
2013-04-18 18:07:39 +00:00
|
|
|
static AgiSound *createFromRawResource(uint8 *data, uint32 len, int resnum, int soundemu);
|
2007-08-15 22:00:31 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
bool _isPlaying; ///< Is the sound playing?
|
|
|
|
bool _isValid; ///< Is this a valid sound object?
|
|
|
|
};
|
|
|
|
|
|
|
|
class PCjrSound : public AgiSound {
|
|
|
|
public:
|
2013-04-18 18:07:39 +00:00
|
|
|
PCjrSound(uint8 *data, uint32 len, int resnum);
|
2010-06-15 10:34:45 +00:00
|
|
|
~PCjrSound() { free(_data); }
|
2007-08-15 22:00:31 +00:00
|
|
|
virtual uint16 type() { return _type; }
|
|
|
|
const uint8 *getVoicePointer(uint voiceNum);
|
2011-05-25 09:30:44 +00:00
|
|
|
uint8 *getData() { return _data; }
|
|
|
|
uint32 getLength() { return _len; }
|
2007-08-15 22:00:31 +00:00
|
|
|
protected:
|
|
|
|
uint8 *_data; ///< Raw sound resource data
|
|
|
|
uint32 _len; ///< Length of the raw sound resource
|
|
|
|
uint16 _type; ///< Sound resource type
|
|
|
|
};
|
|
|
|
|
2010-06-15 10:36:54 +00:00
|
|
|
class SoundMgr {
|
2006-05-23 23:43:52 +00:00
|
|
|
|
|
|
|
public:
|
2011-08-14 17:08:44 +00:00
|
|
|
SoundMgr(AgiBase *agi, Audio::Mixer *pMixer);
|
2006-12-06 19:27:02 +00:00
|
|
|
~SoundMgr();
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2010-06-15 10:36:54 +00:00
|
|
|
void setVolume(uint8 volume);
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2010-06-15 10:36:54 +00:00
|
|
|
void unloadSound(int);
|
|
|
|
void playSound();
|
|
|
|
void startSound(int, int);
|
|
|
|
void stopSound();
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2010-06-15 10:36:54 +00:00
|
|
|
void soundIsFinished();
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2010-06-15 10:36:54 +00:00
|
|
|
private:
|
2010-06-15 10:34:45 +00:00
|
|
|
int _endflag;
|
2011-08-14 17:08:44 +00:00
|
|
|
AgiBase *_vm;
|
2010-06-15 10:34:45 +00:00
|
|
|
|
2010-06-15 10:36:10 +00:00
|
|
|
SoundGen *_soundGen;
|
|
|
|
|
2010-06-15 10:36:54 +00:00
|
|
|
int _playingSound;
|
2006-05-23 23:43:52 +00:00
|
|
|
};
|
|
|
|
|
2006-05-24 14:00:08 +00:00
|
|
|
} // End of namespace Agi
|
2006-12-06 19:27:02 +00:00
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
#endif /* AGI_SOUND_H */
|