lunes, 18 de octubre de 2010

Primeros pasos: Sonido

Una perla que ya iremos ampliando.

Para generar sonidos con el telefono o ponerle musica a nuestra aplicacion podemos usar un Player. Hay diferentes tipos de Player, desde uno de tonos (tipo 8bits) hasta un reproductor multimedia de video.

Pero para empezar por algo facil os dejo un ejemplo de un arpegio con el Player de MIDI.

Para ello usamos el Manger, que es un objeto que nos permite crear diferentes reproductoes.
Y un MIDIControl que es el objeto que configura la secuencia de sonidos, el sintetizador.
Player player = Manager.createPlayer(Manager.MIDI_DEVICE_LOCATOR);
player.realize();
// get volume control for player and set volume to max
MIDIControl synth = (MIDIControl)player.getControl("javax.microedition.media.control.MIDIControl");
// the player can start with the smallest latency
player.prefetch();
// non-blocking start
player.start();
synth.setChannelVolume(channel, 100);
synth.setProgram(channel,-1,program);
//59 is G/Do
static final int[] TONES=new int[]{59,61,63,64,66,68,70,71};               
synth.shortMidiEvent(MIDIControl.NOTE_ON, TONES[0],100);
synth.shortMidiEvent(MIDIControl.NOTE_ON, TONES[2],100);
synth.shortMidiEvent(MIDIControl.NOTE_ON, TONES[4],100);
synth.shortMidiEvent(MIDIControl.NOTE_ON, TONES[7],100);
 Mas informacion en el API de multimedia

No hay comentarios:

Publicar un comentario