Código de ejemplo: reproducir una secuencia de tonos
La clase ToneControl se utiliza para reproducir una secuencia de notas definida por el usuario con una duración y ritmo específicos en un dispositivo BlackBerry.
// "Mary Had A Little Lamb" has "ABAC" structure
// Use block to repeat "A" section
// Tempos ranging from 20 to 508 beats per minute are divided by 4
// to create a tempo modifier range of 5 to 127.
byte tempo_mod = 30; // 120 bpm
// Note duration ranges from 128 (1/2 note) to 0 (128th of a note)
// with a default resolution of 64.
byte duration = 8; // Note length 8 (quaver) = 1/8th of a note duration
// Notes are determined from ToneControl.C4 (Middle C),
// which has a value of 60 and a frequency of 261.6 Hz.
byte C4 = ToneControl.C4; // C note value = 60 (middle C)
byte D4 = (byte)(C4 + 2); // D note value = 62 (a whole step)
byte E4 = (byte)(C4 + 4); // E note value = 64 (a major third)
byte G4 = (byte)(C4 + 7); // G note value = 67 (a fifth)
byte rest = ToneControl.SILENCE; // rest
byte[] mySequence = {
ToneControl.VERSION, 1, // version 1
ToneControl.TEMPO, tempo_mod,
//
// Start define "A" section
ToneControl.BLOCK_START, 0,
//
// Content of "A" section
E4, duration, D4, duration, C4, duration, E4, duration,
E4, duration, E4, duration, E4, duration, rest, duration,
//
// End define "A" section
ToneControl.BLOCK_END, 0, // end of block number 0
//
// Play "A" section
ToneControl.PLAY_BLOCK, 0,
//
// Play "B" section
D4, duration, D4, duration, D4, duration, rest, duration,
E4, duration, G4, duration, G4, duration, rest, duration,
//
// Repeat "A" section
ToneControl.PLAY_BLOCK, 0,
//
// Play "C" section
D4, duration, D4, duration, E4, duration, D4, duration, C4, duration
};
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) { }
Tema siguiente: Grabar audio en una aplicación del dispositivo BlackBerry
Tema anterior: Reproducir audio en BlackBerry Browser
¿Le ha resultado útil esta información? Envíenos sus comentarios.