 	}
 
 	// Get an available OPL2 channel and setup instrument parameters.
-	byte i = getFreeChannel(channel);
+	byte opl2Channel = getFreeChannel(channel);
 	if (channel != MIDI_DRUM_CHANNEL) {
-		opl2.setInstrument(i, midiInstruments[programMap[channel]]);
+		opl2.setInstrument(opl2Channel, midiInstruments[programMap[channel]]);
 	} else {
 		if (note >= DRUM_NOTE_BASE && note < DRUM_NOTE_BASE + NUM_MIDI_DRUMS) {
-			opl2.setInstrument(i, midiDrums[note - DRUM_NOTE_BASE]);
+			opl2.setInstrument(opl2Channel, midiDrums[note - DRUM_NOTE_BASE]);
 		} else {
 			return;
 		}
 	}
 
 	// Register channel mapping.
-	channelMap[i].midiChannel  = channel;
-	channelMap[i].midiNote     = note;
-	channelMap[i].midiVelocity = round(velocity / 127.0);
-	channelMap[i].op1Level     = round((63 - opl2.getVolume(i, OPERATOR1)) / 63.0);
-	channelMap[i].op2Level     = round((63 - opl2.getVolume(i, OPERATOR2)) / 63.0);
+	channelMap[opl2Channel].midiChannel  = channel;
+	channelMap[opl2Channel].midiNote     = note;
+	channelMap[opl2Channel].midiVelocity = min((float)velocity / 64.0, 1.0);
+	channelMap[opl2Channel].op1Level     = (float)(63 - opl2.getVolume(opl2Channel, OPERATOR1)) / 63.0;
+	channelMap[opl2Channel].op2Level     = (float)(63 - opl2.getVolume(opl2Channel, OPERATOR2)) / 63.0;
 
 	// Set operator output levels based on note velocity.
-	setOpl2ChannelVolume(i, channel);
+	setOpl2ChannelVolume(opl2Channel, channel);
 
 	// Calculate octave and note number and play note!
 	byte opl2Octave = 4;

 */
byte getFreeChannel(byte midiChannel) {  
	byte opl2Channel = 255;

	// Look for a free OPL2 channel.
	for (byte i = 0; i < OPL2_NUM_CHANNELS; i ++) {
		if (!opl2.getKeyOn(i)) {
			opl2Channel = i;
			break;
		}
	}

		for (byte i = 0; i < OPL2_NUM_CHANNELS; i ++) {
			if (channelMap[oldestChannel[i]].midiChannel == MIDI_DRUM_CHANNEL) {
				opl2Channel = oldestChannel[i];
				oldestIndex = i;
				break;
			}
		}
		opl2.setKeyOn(opl2Channel, false);
	}

	// Update the list of last used channels by moving the current channel to the bottom so the last updated channel
	// will move to the front of the list. If no more OPL2 channels are free then the last updated one will be recycled.
	for (byte i = oldestIndex; i < OPL2_NUM_CHANNELS - 1; i ++) {
		oldestChannel[i] = oldestChannel[i + 1];
	}
	oldestChannel[OPL2_NUM_CHANNELS - 1] = opl2Channel;

	return opl2Channel;
}
