src/OPL2.cpp
/**
 * Set the given drum instrument that can be used in percussion mode. Depending on the type of drum the instrument
 * parameters will be loaded into the appropriate channel operator(s). An optional volume may be provided to set the
 * proper output levels for the operator(s).
 */
Set the given drum instrument that can be used in percussion mode. Depending on the type of drum the instrument
parameters will be loaded into the appropriate channel operator(s). An optional volume may be provided to set the
proper output levels for the operator(s).
Set the given drum instrument that can be used in percussion mode . Depending on the type of drum the instrument parameters will be loaded into the appropriate channel operator ( s ) . An optional volume may be provided to set the proper output levels for the operator ( s ) .
void OPL2::setDrumInstrument(Instrument instrument, float volume) {
	volume = max(VOLUME_MIN, min(volume, VOLUME_MAX));
	setWaveFormSelect(true);
	for (byte op = OPERATOR1; op <= OPERATOR2; op ++) {
		byte outputLevel = 63 - (byte)((63.0 - (float)instrument.operators[op].outputLevel) * volume);
		byte registerOffset = drumRegisterOffsets[op][instrument.type - INSTRUMENT_TYPE_BASS];
		if (registerOffset != 0xFF) {
			write(0x20 + registerOffset,
				(instrument.operators[0].hasTremolo ? 0x80 : 0x00) +
				(instrument.operators[0].hasVibrato ? 0x40 : 0x00) +
				(instrument.operators[0].hasSustain ? 0x20 : 0x00) +
				(instrument.operators[0].hasEnvelopeScaling ? 0x10 : 0x00) +
				(instrument.operators[0].frequencyMultiplier & 0x0F));
			write(0x40 + registerOffset,
				((instrument.operators[0].keyScaleLevel & 0x03) << 6) +
				(outputLevel & 0x3F));
			write(0x60 + registerOffset,
				((instrument.operators[0].attack & 0x0F) << 4) +
				(instrument.operators[0].decay & 0x0F));
			write(0x80 + registerOffset,
				((instrument.operators[0].sustain & 0x0F) << 4) +
				(instrument.operators[0].release & 0x0F));
			write(0xE0 + registerOffset,
				(instrument.operators[0].waveForm & 0x03));
		}
	}
	write(0xC0 + drumChannels[instrument.type - INSTRUMENT_TYPE_BASS], 0x00);
}
void OPL2 :: setDrumInstrument ( Instrument instrument , float volume ) { volume = max ( VOLUME_MIN , min ( volume , VOLUME_MAX ) ) ; setWaveFormSelect ( true ) ; for ( byte op = OPERATOR1 ; op <= OPERATOR2 ; op ++ ) { byte outputLevel = 63 - ( byte ) ( ( 63.0 - ( float ) instrument . operators [ op ] . outputLevel ) * volume ) ; byte registerOffset = drumRegisterOffsets [ op ] [ instrument . type - INSTRUMENT_TYPE_BASS ] ; if ( registerOffset != 0xFF ) { write ( 0x20 + registerOffset , ( instrument . operators [ 0 ] . hasTremolo ? 0x80 : 0x00 ) + ( instrument . operators [ 0 ] . hasVibrato ? 0x40 : 0x00 ) + ( instrument . operators [ 0 ] . hasSustain ? 0x20 : 0x00 ) + ( instrument . operators [ 0 ] . hasEnvelopeScaling ? 0x10 : 0x00 ) + ( instrument . operators [ 0 ] . frequencyMultiplier & 0x0F ) ) ; write ( 0x40 + registerOffset , ( ( instrument . operators [ 0 ] . keyScaleLevel & 0x03 ) << 6 ) + ( outputLevel & 0x3F ) ) ; write ( 0x60 + registerOffset , ( ( instrument . operators [ 0 ] . attack & 0x0F ) << 4 ) + ( instrument . operators [ 0 ] . decay & 0x0F ) ) ; write ( 0x80 + registerOffset , ( ( instrument . operators [ 0 ] . sustain & 0x0F ) << 4 ) + ( instrument . operators [ 0 ] . release & 0x0F ) ) ; write ( 0xE0 + registerOffset , ( instrument . operators [ 0 ] . waveForm & 0x03 ) ) ; } } write ( 0xC0 + drumChannels [ instrument . type - INSTRUMENT_TYPE_BASS ] , 0x00 ) ; }
Set the given drum instrument that can be used in percussion mode.
Set the given drum instrument that can be used in percussion mode .