Java Reference
In-Depth Information
the value “device://tone”, which kind of means a “device” protocol and an “audio/x-tone-seq”
content type. You may remember seeing this in the output of MediaInformationMIDlet . As we
said, it's kind of a kluge.
Once you've obtained the tone sequence Player , you can give it a tone sequence using
its associated ToneControl object. To get this control, call getControl("ToneControl") .
(Remember, the Player needs to be REALIZED first.)
ToneControl encapsulates a byte array whose syntax and construction is obtusely described
in the API documentation. Master it and you'll be able to make any song into a monophonic
masterpiece, Bobby McFerrin style. We'll describe the byte array format and present several
examples.
The tones themselves are defined with note number and duration pairs. Note numbers are
the same as for Manager 's playTone() method, where 60 is middle C and 69 is the 440-Hz A
above middle C. Duration is specified as multiples of the resolution . By default, the resolution
of a tone sequence is 1/64 of one measure of 4/4 time (four beats). Therefore, a duration of 64
corresponds to a whole note (four beats), 16 corresponds to a quarter note (one beat), 8 is an
eighth note, and so on.
All tone sequences must begin with a version. This is not the version of your data, but
rather the version of the tone sequence format you're using. Currently the only accepted
version is 1. A simple tone sequence looks like this:
byte[] sequence = new byte[] {
ToneControl.VERSION, 1,
67, 16, // The
69, 16, // hills
67, 8, // are
65, 8, // a -
64, 48, // live
62, 8, // with
60, 8, // the
59, 16, // sound
57, 16, // of
59, 32, // mu -
59, 32 // sic
};
This tone sequence relies on several default values. The default tempo is 120 beats per
minute (bpm) and the default resolution is 1/64. The default volume is 100 (the loudest).
Other features are available in tone sequences. A reasonable amount of control is possible:
Set the tempo by using the TEMPO constant and passing the tempo, in beats per minute,
divided by four. For example, ToneControl.TEMPO, 15 sets the tempo to 60 bpm, or one
beat per second. This may be done only once at the beginning of a sequence (following
the VERSION ).
The resolution can be changed from its default of 1/64 using the RESOLUTION
constant. The argument that is passed is the denominator, for example, using
ToneControl.RESOLUTION, 64 will restore the default resolution of 1/64. This may
be done only once at the beginning of a sequence (following the TEMPO ).
Search WWH ::




Custom Search