22 #ifndef AGI_SOUND_2GS_H 23 #define AGI_SOUND_2GS_H 25 #include "common/frac.h" 26 #include "audio/audiostream.h" 39 #define ZERO_OFFSET 0x80 43 #define ENVELOPE_COEF 100 / _sampleRate 46 #define MIDI_NOTE_OFF 0x8 47 #define MIDI_NOTE_ON 0x9 48 #define MIDI_CONTROLLER 0xB 49 #define MIDI_PROGRAM_CHANGE 0xC 50 #define MIDI_PITCH_WHEEL 0xE 52 #define MIDI_STOP_SEQUENCE 0xFC 53 #define MIDI_TIMER_SYNC 0xF8 56 #define SIERRASTANDARD_SIZE 65536 60 #define MAX_INSTRUMENTS 28 65 #define MAX_GENERATORS 16 67 #define ENVELOPE_SEGMENT_COUNT 8 68 #define MAX_OSCILLATOR_WAVES 127 // Maximum is one for every MIDI key 74 } env[ENVELOPE_SEGMENT_COUNT];
89 } wave[2][MAX_OSCILLATOR_WAVES];
100 bool finalize(int8 *wavetable, uint32 wavetableSize);
106 uint8 unknownByte_Ofs3;
119 bool finalize(int8 *sampleData);
125 memset(&osc, 0,
sizeof(osc));
151 IIgsMidi(byte resourceNr, byte *data, uint32 length, uint16 type);
152 virtual const uint8 *getPtr() {
return _ptr; }
153 virtual void setPtr(
const uint8 *ptr) { _ptr = ptr; }
154 virtual void rewind() { _ptr = _data + 2; _ticks = 0; }
163 IIgsSample(byte resourceNr, byte *data, uint32 length, uint16 type);
165 uint16 type()
override {
return _header.type; }
167 bool isValid()
override {
return _isValid; }
176 byte midiProgToInst[44];
180 byte map(uint midiProg)
const {
181 return midiProg <
ARRAYSIZE(midiProgToInst) ? midiProgToInst[midiProg] : undefinedInst;
196 enum AgiGameID gameid;
209 void setVolume(
int volume) { _volume = volume; }
210 int getVolume() {
return _volume; }
221 void play(
int resnum)
override;
222 void stop()
override;
224 int readBuffer(int16 *buffer,
const int numSamples)
override;
228 int getRate()
const override {
return _sampleRate; }
232 bool loadInstruments();
236 const IIgsExeInfo *getIIgsExeInfo(
enum AgiGameID gameid)
const;
240 void advancePlayer();
241 void advanceMidiPlayer();
242 uint generateOutput();
244 void haltGenerators();
245 uint activeGenerators();
247 void midiNoteOff(
int channel,
int note,
int velocity);
248 void midiNoteOn(
int channel,
int note,
int velocity);
249 double midiKeyToFreq(
int key,
double finetune);
250 IIgsInstrumentHeader *getInstrument(uint8 program) {
return &_instruments[_progToInst->map(program)]; }
267 static const int kSfxMidiChannel = 15;
#define ARRAYSIZE(x)
Definition: util.h:91
int getRate() const override
Definition: sound_2gs.h:228
uint byteCount
Length of the whole instrument set in bytes.
Definition: sound_2gs.h:187
int8 * base
Sample base pointer.
Definition: sound_2gs.h:136
const char * waveFileMd5
MD5 hex digest of the wave file (i.e. the sample data used by the instruments)
Definition: sound_2gs.h:190
uint size
Sample size.
Definition: sound_2gs.h:137
Definition: sound_2gs.h:149
bool loop
Is looping enabled?
Definition: sound_2gs.h:141
Definition: sound_2gs.h:175
bool endOfData() const override
Definition: sound_2gs.h:227
const char * md5
MD5 hex digest of the whole instrument set.
Definition: sound_2gs.h:189
Definition: sound_2gs.h:122
const IIgsMidiProgramMapping * progToInst
Program change to instrument number mapping.
Definition: sound_2gs.h:191
uint agiVer
Apple IIGS AGI version number, not strictly needed.
Definition: sound_2gs.h:198
int seg
Current envelope segment.
Definition: sound_2gs.h:145
Definition: sound_2gs.h:204
byte undefinedInst
The undefined instrument number.
Definition: sound_2gs.h:177
const IIgsInstrumentSetInfo * instSet
Information about the used instrument set.
Definition: sound_2gs.h:201
uint instSetStart
Starting offset of the instrument set inside the executable file.
Definition: sound_2gs.h:200
uint _ticks
MIDI song position in ticks (1/60ths of a second)
Definition: sound_2gs.h:158
const char * exePrefix
Prefix of the Apple IIGS AGI executable (e.g. "SQ", "PQ", "KQ4" etc)
Definition: sound_2gs.h:197
bool halt
Is oscillator halted?
Definition: sound_2gs.h:140
Definition: audiostream.h:50
int key
MIDI key.
Definition: sound_2gs.h:132
uint exeSize
Size of the Apple IIGS AGI executable file in bytes.
Definition: sound_2gs.h:199
Definition: sound_2gs.h:186
int channel
MIDI channel.
Definition: sound_2gs.h:134
bool isStereo() const override
Definition: sound_2gs.h:226
Definition: sound_2gs.h:216
int8 * _sample
Sample data (8-bit signed format)
Definition: sound_2gs.h:170
const uint8 * _ptr
Pointer to the current position in the MIDI data.
Definition: sound_2gs.h:156
bool rightChannel
Output channel (left / right)
Definition: sound_2gs.h:143
int velocity
MIDI velocity (& channel volume)
Definition: sound_2gs.h:133
IIgsSampleHeader _header
Apple IIGS AGI sample header.
Definition: sound_2gs.h:169
uint instCount
Amount of instrument in the set.
Definition: sound_2gs.h:188
bool swap
Is swapping enabled?
Definition: sound_2gs.h:142
Definition: sound_2gs.h:195
int32 frac_t
Definition: frac.h:52
frac_t pd
Sample pointer delta.
Definition: sound_2gs.h:139
Definition: sound_2gs.h:161
const IIgsInstrumentHeader * curInstrument
Currently used instrument.
Definition: sound_2gs.h:131
frac_t a
Current envelope amplitude.
Definition: sound_2gs.h:146
frac_t p
Sample pointer.
Definition: sound_2gs.h:138