diff options
author | Jussi Pitkanen | 2011-04-12 18:07:35 +0300 |
---|---|---|
committer | Jussi Pitkanen | 2011-04-12 18:07:35 +0300 |
commit | 506f3bdc101b301e93a99fc4626701b32b4f66b3 (patch) | |
tree | e2c85e4e9c9e22c0a3eaa5800becd9fbea85433d /engines/agi | |
parent | d099ad3a48a15472b634317ac9acf3438e684850 (diff) | |
download | scummvm-rg350-506f3bdc101b301e93a99fc4626701b32b4f66b3.tar.gz scummvm-rg350-506f3bdc101b301e93a99fc4626701b32b4f66b3.tar.bz2 scummvm-rg350-506f3bdc101b301e93a99fc4626701b32b4f66b3.zip |
AGI: Formatting
Diffstat (limited to 'engines/agi')
-rw-r--r-- | engines/agi/sound_2gs.cpp | 114 | ||||
-rw-r--r-- | engines/agi/sound_2gs.h | 130 |
2 files changed, 127 insertions, 117 deletions
diff --git a/engines/agi/sound_2gs.cpp b/engines/agi/sound_2gs.cpp index 7d33f963bd..71cc2d4183 100644 --- a/engines/agi/sound_2gs.cpp +++ b/engines/agi/sound_2gs.cpp @@ -138,10 +138,10 @@ void SoundGen2GS::stop() { * @return Number of generated samples */ uint32 SoundGen2GS::generateOutput() { - memset(_out, 0, _outSize*2*2); + memset(_out, 0, _outSize * 2 * 2); if (!_playing || _playingSound == -1) - return _outSize*2; + return _outSize * 2; int16 *p = _out; int n = _outSize; @@ -207,25 +207,35 @@ uint32 SoundGen2GS::generateOutput() { // Take envelope and MIDI volume information into account. // Also amplify. - s0 *= vol * g->vel/127 * 80/256; - s1 *= vol * g->vel/127 * 80/256; + s0 *= vol * g->vel / 127 * 80 / 256; + s1 *= vol * g->vel / 127 * 80 / 256; - if (g->osc[0].chn) outl += s0; - else outr += s0; - if (g->osc[1].chn) outl += s1; - else outr += s1; + // Select output channel. + if (g->osc[0].chn) + outl += s0; + else + outr += s0; + + if (g->osc[1].chn) + outl += s1; + else + outr += s1; } - if (outl > 32768) outl = 32768; - if (outl <-32767) outl =-32767; - if (outr > 32768) outr = 32768; - if (outr <-32767) outr =-32767; + if (outl > 32768) + outl = 32768; + if (outl < -32767) + outl = -32767; + if (outr > 32768) + outr = 32768; + if (outr < -32767) + outr = -32767; *p++ = outl; *p++ = outr; } - return _outSize*2; + return _outSize * 2; } void SoundGen2GS::advancePlayer() { @@ -388,26 +398,26 @@ void SoundGen2GS::midiNoteOn(int channel, int note, int velocity) { wb++; // Prepare the generator. - g->osc[0].base = i->wave[0][wa].base; - g->osc[0].size = i->wave[0][wa].size; - g->osc[0].pd = doubleToFrac(midiKeyToFreq(note, (double)i->wave[0][wa].tune / 256.0) / (double)_sampleRate); - g->osc[0].p = 0; - g->osc[0].halt = i->wave[0][wa].halt; - g->osc[0].loop = i->wave[0][wa].loop; - g->osc[0].swap = i->wave[0][wa].swap; - g->osc[0].chn = i->wave[0][wa].chn; - - g->osc[1].base = i->wave[1][wb].base; - g->osc[1].size = i->wave[1][wb].size; - g->osc[1].pd = doubleToFrac(midiKeyToFreq(note, (double)i->wave[1][wb].tune / 256.0) / (double)_sampleRate); - g->osc[1].p = 0; - g->osc[1].halt = i->wave[1][wb].halt; - g->osc[1].loop = i->wave[1][wb].loop; - g->osc[1].swap = i->wave[1][wb].swap; - g->osc[1].chn = i->wave[1][wb].chn; - - g->seg = 0; - g->a = 0; + g->osc[0].base = i->wave[0][wa].base; + g->osc[0].size = i->wave[0][wa].size; + g->osc[0].pd = doubleToFrac(midiKeyToFreq(note, (double)i->wave[0][wa].tune / 256.0) / (double)_sampleRate); + g->osc[0].p = 0; + g->osc[0].halt = i->wave[0][wa].halt; + g->osc[0].loop = i->wave[0][wa].loop; + g->osc[0].swap = i->wave[0][wa].swap; + g->osc[0].chn = i->wave[0][wa].chn; + + g->osc[1].base = i->wave[1][wb].base; + g->osc[1].size = i->wave[1][wb].size; + g->osc[1].pd = doubleToFrac(midiKeyToFreq(note, (double)i->wave[1][wb].tune / 256.0) / (double)_sampleRate); + g->osc[1].p = 0; + g->osc[1].halt = i->wave[1][wb].halt; + g->osc[1].loop = i->wave[1][wb].loop; + g->osc[1].swap = i->wave[1][wb].swap; + g->osc[1].chn = i->wave[1][wb].chn; + + g->seg = 0; + g->a = 0; // Print debug messages for instruments with swap mode or vibrato enabled if (g->osc[0].swap || g->osc[1].swap) @@ -442,7 +452,7 @@ void SoundGen2GS::setProgramChangeMapping(const IIgsMidiProgramMapping *mapping) IIgsMidi::IIgsMidi(uint8 *data, uint32 len, int resnum, SoundMgr &manager) : AgiSound(manager) { _data = data; // Save the resource pointer _ptr = _data + 2; // Set current position to just after the header - _len = len; // Save the resource's length + _len = len; // Save the resource's length _type = READ_LE_UINT16(data); // Read sound resource's type _ticks = 0; _isValid = (_type == AGI_SOUND_MIDI) && (_data != NULL) && (_len >= 2); @@ -505,21 +515,21 @@ IIgsSample::IIgsSample(uint8 *data, uint32 len, int resnum, SoundMgr &manager) : bool IIgsInstrumentHeader::read(Common::SeekableReadStream &stream, bool ignoreAddr) { for (int i = 0; i < ENVELOPE_SEGMENT_COUNT; i++) { - env[i].bp = intToFrac(stream.readByte()); + env[i].bp = intToFrac(stream.readByte()); env[i].inc = intToFrac(stream.readUint16LE()) >> 8; } - seg = stream.readByte(); - /*priority =*/ stream.readByte(); // Not needed. 32 in all tested data. - bend = stream.readByte(); - vibDepth = stream.readByte(); - vibSpeed = stream.readByte(); + seg = stream.readByte(); + /*priority =*/ stream.readByte(); // Not needed. 32 in all tested data. + bend = stream.readByte(); + vibDepth = stream.readByte(); + vibSpeed = stream.readByte(); stream.readByte(); // Not needed? 0 in all tested data. waveCount[0] = stream.readByte(); waveCount[1] = stream.readByte(); for (int i = 0; i < 2; i++) for (int k = 0; k < waveCount[i]; k++) { - wave[i][k].key = stream.readByte(); + wave[i][k].key = stream.readByte(); wave[i][k].base = (int8*)(stream.readByte() << 8); wave[i][k].size = 0x100 << (stream.readByte() & 7); uint8 b = stream.readByte(); @@ -536,10 +546,10 @@ bool IIgsInstrumentHeader::read(Common::SeekableReadStream &stream, bool ignoreA } // Parse the generator mode byte to separate fields. - wave[i][k].halt = b & 0x1; // Bit 0 = HALT - wave[i][k].loop = !(b & 0x2); // Bit 1 =!LOOP - wave[i][k].swap = (b & 0x6) == 0x6; // Bit 1&2 = SWAP - wave[k][k].chn = (b >> 4) > 0; // Output channel (left or right) + wave[i][k].halt = b & 0x1; // Bit 0 = HALT + wave[i][k].loop = !(b & 0x2); // Bit 1 =!LOOP + wave[i][k].swap = (b & 0x6) == 0x6; // Bit 1&2 = SWAP + wave[k][k].chn = (b >> 4) > 0; // Output channel (left or right) } return !(stream.eos() || stream.err()); @@ -564,13 +574,13 @@ bool IIgsInstrumentHeader::finalize(int8 *wavetable) { } bool IIgsSampleHeader::read(Common::SeekableReadStream &stream) { - type = stream.readUint16LE(); - pitch = stream.readByte(); - unknownByte_Ofs3 = stream.readByte(); - volume = stream.readByte(); - unknownByte_Ofs5 = stream.readByte(); - instrumentSize = stream.readUint16LE(); - sampleSize = stream.readUint16LE(); + type = stream.readUint16LE(); + pitch = stream.readByte(); + unknownByte_Ofs3 = stream.readByte(); + volume = stream.readByte(); + unknownByte_Ofs5 = stream.readByte(); + instrumentSize = stream.readUint16LE(); + sampleSize = stream.readUint16LE(); // Read the instrument header *ignoring* its wave address info return instrument.read(stream, true); } diff --git a/engines/agi/sound_2gs.h b/engines/agi/sound_2gs.h index d60ea16d14..2d08ef101c 100644 --- a/engines/agi/sound_2gs.h +++ b/engines/agi/sound_2gs.h @@ -47,14 +47,14 @@ namespace Agi { #define ENVELOPE_COEF 100 / _sampleRate // MIDI player commands -#define MIDI_NOTE_OFF 0x8 -#define MIDI_NOTE_ON 0x9 -#define MIDI_CONTROLLER 0xB -#define MIDI_PROGRAM_CHANGE 0xC -#define MIDI_PITCH_WHEEL 0xE +#define MIDI_NOTE_OFF 0x8 +#define MIDI_NOTE_ON 0x9 +#define MIDI_CONTROLLER 0xB +#define MIDI_PROGRAM_CHANGE 0xC +#define MIDI_PITCH_WHEEL 0xE -#define MIDI_STOP_SEQUENCE 0xFC -#define MIDI_TIMER_SYNC 0xF8 +#define MIDI_STOP_SEQUENCE 0xFC +#define MIDI_TIMER_SYNC 0xF8 // Size of the SIERRASTANDARD file (i.e. the wave file i.e. the sample data used by the instruments). #define SIERRASTANDARD_SIZE 65536 @@ -73,23 +73,23 @@ namespace Agi { struct IIgsInstrumentHeader { struct { - frac_t bp; // Envelope segment breakpoint - frac_t inc; // Envelope segment velocity + frac_t bp; ///< Envelope segment breakpoint + frac_t inc; ///< Envelope segment velocity } env[ENVELOPE_SEGMENT_COUNT]; - uint8 seg; // Envelope release segment - uint8 bend; // Maximum range for pitch bend - uint8 vibDepth; // Vibrato depth - uint8 vibSpeed; // Vibrato speed - uint8 waveCount[2]; // Wave count for both generators + uint8 seg; ///< Envelope release segment + uint8 bend; ///< Maximum range for pitch bend + uint8 vibDepth; ///< Vibrato depth + uint8 vibSpeed; ///< Vibrato speed + uint8 waveCount[2]; ///< Wave count for both generators struct { - uint8 key; // Highest MIDI key to use this wave - int8* base; // Pointer to wave data - uint size; // Wave size - bool halt; // Oscillator halted? - bool loop; // Loop mode? - bool swap; // Swap mode? - bool chn; // Output channel (left / right) - int16 tune; // Fine tune in semitones (8.8 fixed point) + uint8 key; ///< Highest MIDI key to use this wave + int8* base; ///< Pointer to wave data + uint size; ///< Wave size + bool halt; ///< Oscillator halted? + bool loop; ///< Loop mode? + bool swap; ///< Swap mode? + bool chn; ///< Output channel (left / right) + int16 tune; ///< Fine tune in semitones (8.8 fixed point) } wave[2][MAX_OSCILLATOR_WAVES]; /** @@ -126,21 +126,21 @@ public: IIgsGenerator() : ins(NULL), key(-1), chn(-1) {} const IIgsInstrumentHeader *ins; ///< Currently used instrument - int key; ///< MIDI key - int vel; ///< MIDI velocity (& channel volume) - int chn; ///< MIDI channel + int key; ///< MIDI key + int vel; ///< MIDI velocity (& channel volume) + int chn; ///< MIDI channel struct { - int8 *base; ///< Sample base pointer - uint size; ///< Sample size - frac_t p; ///< Sample pointer - frac_t pd; ///< Sample pointer delta - bool halt; ///< Is oscillator halted? - bool loop; ///< Is looping enabled? - bool swap; ///< Is swapping enabled? - bool chn; ///< Output channel (left / right) + int8 *base; ///< Sample base pointer + uint size; ///< Sample size + frac_t p; ///< Sample pointer + frac_t pd; ///< Sample pointer delta + bool halt; ///< Is oscillator halted? + bool loop; ///< Is looping enabled? + bool swap; ///< Is swapping enabled? + bool chn; ///< Output channel (left / right) } osc[2]; - int seg; ///< Current envelope segment - frac_t a; ///< Current envelope amplitude + int seg; ///< Current envelope segment + frac_t a; ///< Current envelope amplitude }; class IIgsMidi : public AgiSound { @@ -168,8 +168,8 @@ public: const IIgsSampleHeader &getHeader() const { return _header; } const int8 *getSample() const { return _sample; } protected: - IIgsSampleHeader _header; ///< Apple IIGS AGI sample header - int8 *_sample; ///< Sample data (8-bit signed format) + IIgsSampleHeader _header; ///< Apple IIGS AGI sample header + int8 *_sample; ///< Sample data (8-bit signed format) }; /** Apple IIGS MIDI program change to instrument number mapping. */ @@ -185,21 +185,21 @@ struct IIgsMidiProgramMapping { /** Apple IIGS AGI instrument set information. */ struct IIgsInstrumentSetInfo { - uint byteCount; ///< Length of the whole instrument set in bytes - uint instCount; ///< Amount of instrument in the set - const char *md5; ///< MD5 hex digest of the whole instrument set + uint byteCount; ///< Length of the whole instrument set in bytes + uint instCount; ///< Amount of instrument in the set + const char *md5; ///< MD5 hex digest of the whole instrument set const char *waveFileMd5; ///< MD5 hex digest of the wave file (i.e. the sample data used by the instruments) const IIgsMidiProgramMapping *progToInst; ///< Program change to instrument number mapping }; /** Apple IIGS AGI executable file information. */ struct IIgsExeInfo { - enum AgiGameID gameid; ///< Game ID - const char *exePrefix; ///< Prefix of the Apple IIGS AGI executable (e.g. "SQ", "PQ", "KQ4" etc) - uint agiVer; ///< Apple IIGS AGI version number, not strictly needed - uint exeSize; ///< Size of the Apple IIGS AGI executable file in bytes - uint instSetStart; ///< Starting offset of the instrument set inside the executable file - const IIgsInstrumentSetInfo *instSet; ///< Information about the used instrument set + enum AgiGameID gameid; ///< Game ID + const char *exePrefix; ///< Prefix of the Apple IIGS AGI executable (e.g. "SQ", "PQ", "KQ4" etc) + uint agiVer; ///< Apple IIGS AGI version number, not strictly needed + uint exeSize; ///< Size of the Apple IIGS AGI executable file in bytes + uint instSetStart; ///< Starting offset of the instrument set inside the executable file + const IIgsInstrumentSetInfo *instSet; ///< Information about the used instrument set }; class IIgsMidiChannel { @@ -238,12 +238,12 @@ private: void setProgramChangeMapping(const IIgsMidiProgramMapping *mapping); // Player methods - void advancePlayer(); ///< Advance the player - void advanceMidiPlayer(); ///< Advance MIDI player - uint generateOutput(); ///< Fill the output buffer + void advancePlayer(); ///< Advance the player + void advanceMidiPlayer(); ///< Advance MIDI player + uint generateOutput(); ///< Fill the output buffer - void haltGenerators(); ///< Halt all generators - uint activeGenerators(); ///< How many generators are active? + void haltGenerators(); ///< Halt all generators + uint activeGenerators(); ///< How many generators are active? void midiNoteOff(int channel, int note, int velocity); void midiNoteOn(int channel, int note, int velocity); @@ -251,21 +251,21 @@ private: IIgsInstrumentHeader* getInstrument(uint8 program) { return &_instruments[_progToInst->map(program)]; }; IIgsGenerator* allocateGenerator() { IIgsGenerator* g = &_generators[_nextGen++]; _nextGen %= 16; return g; } - bool _disableMidi; ///< Disable MIDI if loading instruments fail - int _playingSound; ///< Resource number for the currently playing sound - bool _playing; ///< True when the resource is still playing - - IIgsGenerator _generators[MAX_GENERATORS]; ///< IIGS sound generators that are used to play single notes - uint _nextGen; ///< Next generator available for allocation - IIgsMidiChannel _channels[16]; ///< MIDI channels - Common::Array<IIgsInstrumentHeader> _instruments; ///< Instrument data - const IIgsMidiProgramMapping *_progToInst; ///< MIDI program number to instrument mapping - int8 *_wavetable; ///< Sample data used by the instruments - uint _ticks; ///< MIDI ticks (60Hz) - int16 *_out; ///< Output buffer - uint _outSize; ///< Output buffer size + bool _disableMidi; ///< Disable MIDI if loading instruments fail + int _playingSound; ///< Resource number for the currently playing sound + bool _playing; ///< True when the resource is still playing + + IIgsGenerator _generators[MAX_GENERATORS]; ///< IIGS sound generators that are used to play single notes + uint _nextGen; ///< Next generator available for allocation + IIgsMidiChannel _channels[16]; ///< MIDI channels + Common::Array<IIgsInstrumentHeader> _instruments; ///< Instrument data + const IIgsMidiProgramMapping *_progToInst; ///< MIDI program number to instrument mapping + int8 *_wavetable; ///< Sample data used by the instruments + uint _ticks; ///< MIDI ticks (60Hz) + int16 *_out; ///< Output buffer + uint _outSize; ///< Output buffer size - static const int kSfxMidiChannel = 15; ///< MIDI channel used for playing sample resources + static const int kSfxMidiChannel = 15; ///< MIDI channel used for playing sample resources }; } // End of namespace Agi |