ScummVM API documentation
c64.music.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#ifndef FREESCAPE_CASTLE_C64_MUSIC_H
23#define FREESCAPE_CASTLE_C64_MUSIC_H
24
25#include "audio/sid.h"
26#include "audio/audiostream.h"
27#include "audio/mixer.h"
28#include "common/array.h"
29#include "freescape/music.h"
30
31namespace Freescape {
32
33class Sound;
34Sound *createCastleC64Sound(Audio::Mixer *mixer, const Common::Array<byte> &data);
35void enableCastleC64Sound(Sound *sound, bool enabled);
36void updateCastleC64GhostSound(Sound *sound, bool active);
37
39public:
41 ~CastleC64MusicPlayer() override;
42
43 void startMusic() override;
44 void stopMusic() override;
45 bool isPlaying() const override;
46 int readBuffer(int16 *buffer, int numSamples) override;
47 int getRate() const override;
48 bool isStereo() const override { return false; }
49 bool endOfData() const override { return false; }
50
51private:
52 enum {
53 kChannelCount = 3,
54 kMaxNote = 95
55 };
56
57 struct ChannelState {
58 const byte *orderList;
59 uint16 orderPosition;
60 byte patternIndex;
61 uint16 patternDataOffset;
62 uint16 patternOffset;
63 uint16 delay;
64 byte instrument;
65 int8 transpose;
66 byte currentNote;
67 uint16 baseFrequency;
68 int16 frequencyOffset;
69 byte vibratoStep;
70 bool vibratoReverse;
71 byte control;
72 bool active;
73
74 void reset(const byte *channelOrderList);
75 };
76
77 SID::SID *_sid;
78 Audio::Mixer *_mixer;
79 Audio::SoundHandle _handle;
80 bool _musicActive;
81 int _samplesUntilTick;
82 int _sampleRemainder;
83 uint32 _tick;
84 ChannelState _channels[kChannelCount];
85
86 void initSID();
87 void destroySID();
88 void sidWrite(int reg, byte data);
89 void silenceAll();
90 void setupSong();
91 void onTimer();
92 void loadNextPattern(int channel);
93 byte readPatternByte(int channel);
94 void parseCommands(int channel);
95 void noteOn(int channel, byte note);
96 void rest(int channel);
97 void gateOff(int channel);
98 void writeFrequency(int channel, uint16 frequency);
99 uint16 noteToSIDFrequency(int note) const;
100 void applyFrameEffects(int channel);
101 byte sidControlForInstrument(byte instrument) const;
102};
103
104} // namespace Freescape
105
106#endif
Definition: audiostream.h:50
Definition: mixer.h:70
Definition: mixer.h:49
Definition: c64.music.h:38
int readBuffer(int16 *buffer, int numSamples) override
int getRate() const override
bool endOfData() const override
Definition: c64.music.h:49
bool isStereo() const override
Definition: c64.music.h:48
Definition: music.h:29
Definition: sid.h:50
Definition: area.h:36