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
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; }
180 byte map(uint midiProg)
const {
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)]; }
251 IIgsGenerator *allocateGenerator() { IIgsGenerator *g = &_generators[_nextGen++]; _nextGen %= 16;
return g; }
257 IIgsGenerator _generators[MAX_GENERATORS];
259 IIgsMidiChannel _channels[16];
261 const IIgsMidiProgramMapping *_progToInst;
267 static const int kSfxMidiChannel = 15;
Definition: sound_2gs.h:122
frac_t p
Sample pointer.
Definition: sound_2gs.h:138
int8 * base
Sample base pointer.
Definition: sound_2gs.h:136
bool loop
Is looping enabled?
Definition: sound_2gs.h:141
frac_t a
Current envelope amplitude.
Definition: sound_2gs.h:146
bool swap
Is swapping enabled?
Definition: sound_2gs.h:142
int seg
Current envelope segment.
Definition: sound_2gs.h:145
uint size
Sample size.
Definition: sound_2gs.h:137
bool halt
Is oscillator halted?
Definition: sound_2gs.h:140
int key
MIDI key.
Definition: sound_2gs.h:132
const IIgsInstrumentHeader * curInstrument
Currently used instrument.
Definition: sound_2gs.h:131
bool rightChannel
Output channel (left / right)
Definition: sound_2gs.h:143
int velocity
MIDI velocity (& channel volume)
Definition: sound_2gs.h:133
int channel
MIDI channel.
Definition: sound_2gs.h:134
frac_t pd
Sample pointer delta.
Definition: sound_2gs.h:139
Definition: sound_2gs.h:204
Definition: sound_2gs.h:149
uint _ticks
MIDI song position in ticks (1/60ths of a second)
Definition: sound_2gs.h:158
const uint8 * _ptr
Pointer to the current position in the MIDI data.
Definition: sound_2gs.h:156
Definition: sound_2gs.h:161
int8 * _sample
Sample data (8-bit signed format)
Definition: sound_2gs.h:170
IIgsSampleHeader _header
Apple IIGS AGI sample header.
Definition: sound_2gs.h:169
Definition: sound_2gs.h:216
int readBuffer(int16 *buffer, const int numSamples) override
bool endOfData() const override
Definition: sound_2gs.h:227
bool isStereo() const override
Definition: sound_2gs.h:226
int getRate() const override
Definition: sound_2gs.h:228
Definition: audiostream.h:50
int32 frac_t
Definition: frac.h:52
#define ARRAYSIZE(x)
Definition: util.h:114
Definition: sound_2gs.h:195
const char * exePrefix
Prefix of the Apple IIGS AGI executable (e.g. "SQ", "PQ", "KQ4" etc)
Definition: sound_2gs.h:197
uint instSetStart
Starting offset of the instrument set inside the executable file.
Definition: sound_2gs.h:200
uint agiVer
Apple IIGS AGI version number, not strictly needed.
Definition: sound_2gs.h:198
const IIgsInstrumentSetInfo * instSet
Information about the used instrument set.
Definition: sound_2gs.h:201
enum AgiGameID gameid
Game ID.
Definition: sound_2gs.h:196
uint exeSize
Size of the Apple IIGS AGI executable file in bytes.
Definition: sound_2gs.h:199
Definition: sound_2gs.h:186
uint instCount
Amount of instrument in the set.
Definition: sound_2gs.h:188
const char * md5
MD5 hex digest of the whole instrument set.
Definition: sound_2gs.h:189
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 byteCount
Length of the whole instrument set in bytes.
Definition: sound_2gs.h:187
const IIgsMidiProgramMapping * progToInst
Program change to instrument number mapping.
Definition: sound_2gs.h:191
Definition: sound_2gs.h:175
byte midiProgToInst[44]
Lookup table for the MIDI program number to instrument number mapping.
Definition: sound_2gs.h:176
byte undefinedInst
The undefined instrument number.
Definition: sound_2gs.h:177