MIDI Synthesis
I'll consider three approaches to synthesizing MIDI sound at runtime:
Send note-playing messages to a MIDI channel. The
MidiChannel
class offersnoteOn()
andnoteOff()
methods that transmitNOTE_ON
andNOTE_OFF
MIDI messages.Send MIDI messages to the synthesizer's receiver port. This is a generalization of the first approach. The advantages include the ability to deliver messages to different channels, and the ability to send a wider variety of messages.
Create a sequence, which is passed to the sequencer. This is a generalization of the second approach. Rather than send individual notes to the synthesizer, I build a complete sequence.
These approaches are labeled in the MIDI devices diagram in Figure 10-4.
Figure 10-4. Different MIDI synthesis approaches
Tip
There is a good Java Tech Tip on these topics at http://java.sun.com/jdc/JDCTechTips/2003/tt0805.html.
Sending Note-Playing Message to a MIDI Channel
The MidiChannel
class offers noteOn()
and noteOff()
methods that correspond to the NOTE_ON
and NOTE_OFF
MIDI messages:
void noteOn(int noteNumber, int velocity); void noteOff(int noteNumber, int velocity); void noteOff(int noteNumber);
The note number is the MIDI number assigned to a musical note, and velocity is equivalent to the loudness. A note will keep playing after a noteOn()
call until it's terminated with noteOff()
. The two-argument form of noteOff()
can affect how ...
Get Killer Game Programming in Java now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.