2010-10-25 16:41:39 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SCUMM_PLAYER_V2CMS_H
|
|
|
|
#define SCUMM_PLAYER_V2CMS_H
|
|
|
|
|
2010-10-25 16:42:24 +00:00
|
|
|
#include "scumm/player_v2base.h" // for channel_data
|
2010-10-25 16:41:39 +00:00
|
|
|
|
|
|
|
class CMSEmulator;
|
|
|
|
|
|
|
|
namespace Scumm {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Scumm V2 CMS/Gameblaster MIDI driver.
|
|
|
|
*/
|
2010-10-25 16:42:24 +00:00
|
|
|
class Player_V2CMS : public Player_V2Base {
|
2010-10-25 16:41:39 +00:00
|
|
|
public:
|
|
|
|
Player_V2CMS(ScummEngine *scumm, Audio::Mixer *mixer);
|
|
|
|
virtual ~Player_V2CMS();
|
|
|
|
|
2010-10-25 16:42:24 +00:00
|
|
|
// MusicEngine API
|
2010-10-25 16:41:39 +00:00
|
|
|
virtual void setMusicVolume(int vol);
|
|
|
|
virtual void startSound(int sound);
|
|
|
|
virtual void stopSound(int sound);
|
|
|
|
virtual void stopAllSounds();
|
2011-08-05 20:46:26 +00:00
|
|
|
virtual int getMusicTimer();
|
2010-10-25 16:41:39 +00:00
|
|
|
virtual int getSoundStatus(int sound) const;
|
|
|
|
|
|
|
|
// AudioStream API
|
2011-08-07 13:58:27 +00:00
|
|
|
virtual int readBuffer(int16 *buffer, const int numSamples);
|
|
|
|
virtual bool isStereo() const { return true; }
|
2010-10-25 16:41:39 +00:00
|
|
|
|
2011-08-07 13:56:49 +00:00
|
|
|
private:
|
2010-10-25 16:41:39 +00:00
|
|
|
struct Voice {
|
|
|
|
byte attack;
|
|
|
|
byte decay;
|
|
|
|
byte sustain;
|
|
|
|
byte release;
|
|
|
|
byte octadd;
|
|
|
|
int16 vibrato;
|
|
|
|
int16 vibrato2;
|
|
|
|
int16 noise;
|
2011-08-09 17:16:24 +00:00
|
|
|
};
|
2010-10-25 16:41:39 +00:00
|
|
|
|
|
|
|
struct Voice2 {
|
|
|
|
byte *amplitudeOutput;
|
|
|
|
byte *freqOutput;
|
|
|
|
byte *octaveOutput;
|
|
|
|
|
|
|
|
uint8 channel;
|
|
|
|
int8 sustainLevel;
|
2011-08-05 20:46:26 +00:00
|
|
|
uint8 attackRate;
|
2010-10-25 16:41:39 +00:00
|
|
|
uint8 maxAmpl;
|
2011-08-05 20:46:26 +00:00
|
|
|
uint8 decayRate;
|
|
|
|
uint8 sustainRate;
|
|
|
|
uint8 releaseRate;
|
|
|
|
uint8 releaseTime;
|
2010-10-25 16:41:39 +00:00
|
|
|
int8 vibratoRate;
|
|
|
|
int8 vibratoDepth;
|
|
|
|
|
|
|
|
int8 curVibratoRate;
|
|
|
|
int8 curVibratoUnk;
|
|
|
|
|
|
|
|
int8 unkVibratoRate;
|
|
|
|
int8 unkVibratoDepth;
|
|
|
|
|
|
|
|
int8 unkRate;
|
|
|
|
int8 unkCount;
|
|
|
|
|
2011-08-07 13:56:49 +00:00
|
|
|
enum EnvelopeState {
|
|
|
|
kEnvelopeAttack,
|
|
|
|
kEnvelopeDecay,
|
|
|
|
kEnvelopeSustain,
|
|
|
|
kEnvelopeRelease
|
|
|
|
};
|
|
|
|
|
|
|
|
EnvelopeState nextProcessState;
|
2011-08-05 20:46:26 +00:00
|
|
|
uint8 curVolume;
|
|
|
|
uint8 curOctave;
|
|
|
|
uint8 curFreq;
|
2010-10-25 16:41:39 +00:00
|
|
|
|
|
|
|
int8 octaveAdd;
|
|
|
|
|
|
|
|
int8 playingNote;
|
|
|
|
Voice2 *nextVoice;
|
|
|
|
|
|
|
|
byte chanNumber;
|
2011-08-09 17:16:24 +00:00
|
|
|
};
|
2010-10-25 16:41:39 +00:00
|
|
|
|
|
|
|
struct MusicChip {
|
|
|
|
byte ampl[4];
|
|
|
|
byte freq[4];
|
|
|
|
byte octave[2];
|
2011-08-09 17:16:24 +00:00
|
|
|
};
|
2010-10-25 16:41:39 +00:00
|
|
|
|
|
|
|
Voice _cmsVoicesBase[16];
|
|
|
|
Voice2 _cmsVoices[8];
|
|
|
|
MusicChip _cmsChips[2];
|
|
|
|
|
2011-08-05 20:46:26 +00:00
|
|
|
uint8 _tempo;
|
|
|
|
uint8 _tempoSum;
|
2010-10-25 16:41:39 +00:00
|
|
|
byte _looping;
|
|
|
|
byte _octaveMask;
|
|
|
|
int16 _midiDelay;
|
|
|
|
Voice2 *_midiChannel[16];
|
|
|
|
byte _midiChannelUse[16];
|
|
|
|
byte *_midiData;
|
|
|
|
byte *_midiSongBegin;
|
|
|
|
|
|
|
|
int _loadedMidiSong;
|
|
|
|
|
2011-08-09 21:47:41 +00:00
|
|
|
byte _sfxFreq[4], _sfxAmpl[4], _sfxOctave[2];
|
|
|
|
|
2010-10-25 16:41:39 +00:00
|
|
|
byte _lastMidiCommand;
|
|
|
|
uint _outputTableReady;
|
2011-08-06 01:26:40 +00:00
|
|
|
byte _voiceTimer;
|
2010-10-25 16:41:39 +00:00
|
|
|
|
2011-08-05 20:46:26 +00:00
|
|
|
int _musicTimer, _musicTimerTicks;
|
|
|
|
|
2010-10-25 16:41:39 +00:00
|
|
|
void loadMidiData(byte *data, int sound);
|
|
|
|
void play();
|
|
|
|
|
|
|
|
void processChannel(Voice2 *channel);
|
|
|
|
void processRelease(Voice2 *channel);
|
|
|
|
void processAttack(Voice2 *channel);
|
|
|
|
void processDecay(Voice2 *channel);
|
|
|
|
void processSustain(Voice2 *channel);
|
|
|
|
void processVibrato(Voice2 *channel);
|
|
|
|
|
|
|
|
void playMusicChips(const MusicChip *table);
|
|
|
|
void playNote(byte *&data);
|
|
|
|
void clearNote(byte *&data);
|
|
|
|
void offAllChannels();
|
|
|
|
void playVoice();
|
2011-08-05 20:46:26 +00:00
|
|
|
void processMidiData();
|
2010-10-25 16:41:39 +00:00
|
|
|
|
|
|
|
Voice2 *getFreeVoice();
|
|
|
|
Voice2 *getPlayVoice(byte param);
|
|
|
|
|
2011-08-07 14:49:25 +00:00
|
|
|
struct MidiNote {
|
|
|
|
byte frequency;
|
|
|
|
byte baseOctave;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const MidiNote _midiNotes[132];
|
|
|
|
static const byte _attackRate[16];
|
|
|
|
static const byte _decayRate[16];
|
|
|
|
static const byte _sustainRate[16];
|
|
|
|
static const byte _releaseRate[16];
|
|
|
|
static const byte _volumeTable[16];
|
|
|
|
static const byte _cmsInitData[26];
|
2010-10-25 16:41:39 +00:00
|
|
|
|
2011-08-07 14:49:25 +00:00
|
|
|
CMSEmulator *_cmsEmu;
|
2010-10-25 16:41:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // End of namespace Scumm
|
|
|
|
|
|
|
|
#endif
|