diff options
Diffstat (limited to 'engines/scumm/player_v2.h')
-rw-r--r-- | engines/scumm/player_v2.h | 173 |
1 files changed, 173 insertions, 0 deletions
diff --git a/engines/scumm/player_v2.h b/engines/scumm/player_v2.h index cd88d57602..25041f42a9 100644 --- a/engines/scumm/player_v2.h +++ b/engines/scumm/player_v2.h @@ -158,6 +158,179 @@ private: void next_freqs(ChannelInfo *channel); }; +/** + * Scumm V2 CMS/Gameblaster MIDI driver. + */ +class Player_V2CMS : public Audio::AudioStream, public MusicEngine { +public: + Player_V2CMS(ScummEngine *scumm, Audio::Mixer *mixer); + virtual ~Player_V2CMS(); + + virtual void setMusicVolume(int vol); + virtual void startSound(int sound); + virtual void stopSound(int sound); + virtual void stopAllSounds(); + virtual int getMusicTimer() const; + virtual int getSoundStatus(int sound) const; + + // AudioStream API + int readBuffer(int16 *buffer, const int numSamples); + bool isStereo() const { return true; } + bool endOfData() const { return false; } + int getRate() const { return _sample_rate; } + +protected: + +#include "common/pack-start.h" // START STRUCT PACKING + struct Voice { + byte attack; + byte decay; + byte sustain; + byte release; + byte octadd; + int16 vibrato; + int16 vibrato2; + int16 noise; + } PACKED_STRUCT; + + struct Voice2 { + byte *amplitudeOutput; + byte *freqOutput; + byte *octaveOutput; + + int8 channel; + int8 sustainLevel; + int8 attackRate; + int8 maxAmpl; + int8 decayRate; + int8 sustainRate; + int8 releaseRate; + int8 releaseTime; + int8 vibratoRate; + int8 vibratoDepth; + + int8 curVibratoRate; + int8 curVibratoUnk; + + int8 unkVibratoRate; + int8 unkVibratoDepth; + + int8 unkRate; + int8 unkCount; + + int nextProcessState; + int8 curVolume; + int8 curOctave; + int8 curFreq; + + int8 octaveAdd; + + int8 playingNote; + Voice2 *nextVoice; + + byte chanNumber; + } PACKED_STRUCT; + + struct MusicChip { + byte ampl[4]; + byte freq[4]; + byte octave[2]; + } PACKED_STRUCT; +#include "common/pack-end.h" // END STRUCT PACKING + + Voice _cmsVoicesBase[16]; + Voice2 _cmsVoices[8]; + MusicChip _cmsChips[2]; + + char _tempo; + char _tempoSum; + byte _looping; + byte _octaveMask; + int16 _midiDelay; + Voice2 *_midiChannel[16]; + byte _midiChannelUse[16]; + byte *_midiData; + byte *_midiSongBegin; + + int _loadedMidiSong; + + byte _lastMidiCommand; + uint _outputTableReady; + byte _clkFrequenz; + byte _restart; + byte _curSno; + + 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(); + void processMidiData(uint ticks); + + Voice2 *getFreeVoice(); + Voice2 *getPlayVoice(byte param); + + // from Player_V2 +protected: + bool _isV3Game; + Audio::Mixer *_mixer; + Audio::SoundHandle _soundHandle; + ScummEngine *_vm; + + int _header_len; + + uint32 _sample_rate; + uint32 _next_tick; + uint32 _tick_len; + + int _timer_count[4]; + int _timer_output; + + int _current_nr; + byte *_current_data; + int _next_nr; + byte *_next_data; + byte *_retaddr; + +private: + union ChannelInfo { + channel_data d; + uint16 array[sizeof(channel_data)/2]; + }; + + int _music_timer; + int _music_timer_ctr; + int _ticks_per_music_timer; + + Common::Mutex _mutex; + ChannelInfo _channels[5]; + +protected: + void mutex_up(); + void mutex_down(); + + virtual void nextTick(); + virtual void clear_channel(int i); + virtual void chainSound(int nr, byte *data); + virtual void chainNextSound(); + +private: + void do_mix(int16 *buf, uint len); + + void execute_cmd(ChannelInfo *channel); + void next_freqs(ChannelInfo *channel); +}; + } // End of namespace Scumm #endif |