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.
|
|
|
|
|
|
|
|
* 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
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* $URL$
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2006-05-24 14:25:42 +00:00
|
|
|
#ifndef AGI_SOUND_H
|
|
|
|
#define AGI_SOUND_H
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2006-12-06 19:27:02 +00:00
|
|
|
#include "sound/audiostream.h"
|
2007-02-20 18:50:17 +00:00
|
|
|
#include "sound/mixer.h"
|
2006-05-23 23:43:52 +00:00
|
|
|
|
|
|
|
namespace Agi {
|
|
|
|
|
|
|
|
#define BUFFER_SIZE 410
|
2008-04-21 04:04:24 +00:00
|
|
|
|
2006-05-23 23:43:52 +00:00
|
|
|
#define SOUND_EMU_NONE 0
|
|
|
|
#define SOUND_EMU_PC 1
|
|
|
|
#define SOUND_EMU_TANDY 2
|
|
|
|
#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
|
2006-05-23 23:43:52 +00:00
|
|
|
|
|
|
|
#define WAVEFORM_SIZE 64
|
|
|
|
#define ENV_ATTACK 10000 /**< envelope attack rate */
|
|
|
|
#define ENV_DECAY 1000 /**< envelope decay rate */
|
|
|
|
#define ENV_SUSTAIN 100 /**< envelope sustain level */
|
|
|
|
#define ENV_RELEASE 7500 /**< envelope release rate */
|
|
|
|
#define NUM_CHANNELS 7 /**< number of sound channels */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
struct CoCoNote {
|
|
|
|
uint8 freq;
|
|
|
|
uint8 volume;
|
|
|
|
uint16 duration; ///< Note duration
|
|
|
|
|
|
|
|
/** Reads a CoCoNote through the given pointer. */
|
|
|
|
void read(const uint8 *ptr) {
|
|
|
|
freq = *ptr;
|
|
|
|
volume = *(ptr + 1);
|
|
|
|
duration = READ_LE_UINT16(ptr + 2);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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).
|
|
|
|
*/
|
|
|
|
enum AgiSoundType {
|
|
|
|
AGI_SOUND_SAMPLE = 0x0001,
|
|
|
|
AGI_SOUND_MIDI = 0x0002,
|
|
|
|
AGI_SOUND_4CHN = 0x0008
|
|
|
|
};
|
|
|
|
enum AgiSoundFlags {
|
|
|
|
AGI_SOUND_LOOP = 0x0001,
|
|
|
|
AGI_SOUND_ENVELOPE = 0x0002
|
|
|
|
};
|
|
|
|
enum AgiSoundEnv {
|
|
|
|
AGI_SOUND_ENV_ATTACK = 3,
|
|
|
|
AGI_SOUND_ENV_DECAY = 2,
|
|
|
|
AGI_SOUND_ENV_SUSTAIN = 1,
|
|
|
|
AGI_SOUND_ENV_RELEASE = 0
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2006-05-23 23:43:52 +00:00
|
|
|
/**
|
|
|
|
* AGI engine sound channel structure.
|
|
|
|
*/
|
2007-01-16 12:40:51 +00:00
|
|
|
struct ChannelInfo {
|
2007-08-19 20:48:11 +00:00
|
|
|
AgiSoundType type;
|
2007-08-15 22:00:31 +00:00
|
|
|
const uint8 *ptr; // Pointer to the AgiNote data
|
2007-08-19 20:48:11 +00:00
|
|
|
const int16 *ins;
|
2006-05-23 23:43:52 +00:00
|
|
|
int32 size;
|
|
|
|
uint32 phase;
|
2007-08-19 20:48:11 +00:00
|
|
|
uint32 flags; // ORs values from AgiSoundFlags
|
|
|
|
AgiSoundEnv adsr;
|
2006-05-23 23:43:52 +00:00
|
|
|
int32 timer;
|
|
|
|
uint32 end;
|
|
|
|
uint32 freq;
|
|
|
|
uint32 vol;
|
|
|
|
uint32 env;
|
|
|
|
};
|
|
|
|
|
2007-08-15 22:00:31 +00:00
|
|
|
class SoundMgr;
|
|
|
|
|
2007-08-15 18:37:52 +00:00
|
|
|
/**
|
|
|
|
* AGI sound resource structure.
|
|
|
|
*/
|
|
|
|
class AgiSound {
|
|
|
|
public:
|
2007-08-15 22:00:31 +00:00
|
|
|
AgiSound(SoundMgr &manager) : _manager(manager), _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!
|
|
|
|
*/
|
|
|
|
static AgiSound *createFromRawResource(uint8 *data, uint32 len, int resnum, SoundMgr &manager);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
SoundMgr &_manager; ///< AGI sound manager object
|
|
|
|
bool _isPlaying; ///< Is the sound playing?
|
|
|
|
bool _isValid; ///< Is this a valid sound object?
|
|
|
|
};
|
|
|
|
|
|
|
|
class PCjrSound : public AgiSound {
|
|
|
|
public:
|
|
|
|
PCjrSound(uint8 *data, uint32 len, int resnum, SoundMgr &manager);
|
|
|
|
~PCjrSound() { if (_data != NULL) free(_data); }
|
|
|
|
virtual uint16 type() { return _type; }
|
|
|
|
const uint8 *getVoicePointer(uint voiceNum);
|
|
|
|
protected:
|
|
|
|
uint8 *_data; ///< Raw sound resource data
|
|
|
|
uint32 _len; ///< Length of the raw sound resource
|
|
|
|
uint16 _type; ///< Sound resource type
|
|
|
|
};
|
|
|
|
|
2006-12-06 19:27:02 +00:00
|
|
|
class AgiEngine;
|
2007-09-03 09:39:15 +00:00
|
|
|
class AgiBase;
|
2010-06-15 10:33:57 +00:00
|
|
|
class IIgsSoundMgr;
|
|
|
|
|
|
|
|
struct IIgsExeInfo;
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2006-12-06 19:27:02 +00:00
|
|
|
class SoundMgr : public Audio::AudioStream {
|
2007-09-03 09:39:15 +00:00
|
|
|
AgiBase *_vm;
|
2006-05-23 23:43:52 +00:00
|
|
|
|
|
|
|
public:
|
2007-09-03 09:39:15 +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
|
|
|
virtual void setVolume(uint8 volume);
|
|
|
|
|
|
|
|
// AudioStream API
|
2006-12-06 19:27:02 +00:00
|
|
|
int readBuffer(int16 *buffer, const int numSamples) {
|
2006-05-23 23:43:52 +00:00
|
|
|
premixerCall(buffer, numSamples / 2);
|
|
|
|
return numSamples;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isStereo() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool endOfData() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int getRate() const {
|
2006-05-24 05:17:48 +00:00
|
|
|
// FIXME: Ideally, we should use _sampleRate.
|
|
|
|
return 22050;
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2006-12-06 19:27:02 +00:00
|
|
|
Audio::Mixer *_mixer;
|
2007-02-20 18:50:17 +00:00
|
|
|
Audio::SoundHandle _soundHandle;
|
2006-05-23 23:43:52 +00:00
|
|
|
uint32 _sampleRate;
|
|
|
|
|
2007-08-19 20:48:11 +00:00
|
|
|
bool _playing;
|
|
|
|
ChannelInfo _chn[NUM_CHANNELS];
|
2010-06-15 10:33:57 +00:00
|
|
|
IIgsSoundMgr *_gsSound;
|
2007-08-19 20:48:11 +00:00
|
|
|
int _endflag;
|
|
|
|
int _playingSound;
|
|
|
|
uint8 _env;
|
2008-10-13 19:17:51 +00:00
|
|
|
bool _disabledMidi;
|
2007-08-19 20:48:11 +00:00
|
|
|
|
2008-08-13 11:36:45 +00:00
|
|
|
int16 *_sndBuffer;
|
2007-08-19 20:48:11 +00:00
|
|
|
const int16 *_waveform;
|
|
|
|
|
2009-10-20 12:22:30 +00:00
|
|
|
bool _useChorus;
|
|
|
|
|
2006-12-06 19:27:02 +00:00
|
|
|
void premixerCall(int16 *buf, uint len);
|
2008-08-13 11:57:48 +00:00
|
|
|
void fillAudio(void *udata, int16 *stream, uint len);
|
2006-12-06 19:27:02 +00:00
|
|
|
|
|
|
|
public:
|
2007-01-16 12:40:51 +00:00
|
|
|
void unloadSound(int);
|
|
|
|
void playSound();
|
|
|
|
int initSound();
|
|
|
|
void deinitSound();
|
|
|
|
void startSound(int, int);
|
|
|
|
void stopSound();
|
|
|
|
void stopNote(int i);
|
|
|
|
void playNote(int i, int freq, int vol);
|
|
|
|
void playAgiSound();
|
2009-06-17 23:16:21 +00:00
|
|
|
void playCoCoSound();
|
2007-01-16 12:40:51 +00:00
|
|
|
uint32 mixSound();
|
2007-08-09 17:44:07 +00:00
|
|
|
bool loadInstruments();
|
2007-01-16 12:40:51 +00:00
|
|
|
void playMidiSound();
|
|
|
|
void playSampleSound();
|
2007-08-14 12:44:44 +00:00
|
|
|
const IIgsExeInfo *getIIgsExeInfo(enum AgiGameID gameid) const;
|
2008-04-15 23:00:34 +00:00
|
|
|
static bool convertWave(Common::SeekableReadStream &source, int8 *dest, uint length);
|
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 */
|