byte tempo = 30;
// set tempo to 120 bpm
byte d = 8;
// eighth-note
byte C4 = ToneControl.C4;
byte D4 = (byte)(C4 + 2);
// a whole step
byte E4 = (byte)(C4 + 4);
// a major third
byte G4 = (byte)(C4 + 7);
// a fifth
byte rest = ToneControl.SILENCE;
// rest
byte[] mySequence = {
ToneControl.VERSION, 1,
// version 1
ToneControl.TEMPO, tempo,
// set tempo
ToneControl.BLOCK_START, 0,
// start define "A" section
E4,d, D4,d, C4,d, E4,d,
// content of "A" section
E4,d, E4,d, E4,d, rest,d,
ToneControl.BLOCK_END, 0,
// end define "A" section
ToneControl.PLAY_BLOCK, 0,
// play "A" section
D4,d, D4,d, D4,d, rest,d,
// play "B" section
E4,d, G4,d, G4,d, rest,d,
ToneControl.PLAY_BLOCK, 0,
// repeat "A" section
D4,d, D4,d, E4,d, D4,d, C4,d
// play "C" section
};
try{
Player p = Manager.createPlayer
(Manager.TONE_DEVICE_LOCATOR);
p.realize();
ToneControl c = (ToneControl)
p.getControl("ToneControl");
c.setSequence(mySequence);
p.start();
} catch (IOException ioe)
{
} catch (MediaException me)
{
} |