Ver Mensaje Individual
  #4  
Antiguo 27-07-2006
dicatek dicatek is offline
Miembro
 
Registrado: jun 2006
Posts: 46
Reputación: 0
dicatek Va por buen camino
Múltiples sonidos en movimiento

LECCIÓN3
Un sonido en movimiento no tiene demasiada complicación, pero ¿qué ocurre cuando tenemos varios sonidos en movimiento? Para realizar la siguiente lección, necesitaremos como base, el código hecho en la lección2.
El uso de sonidos múltiples no tiene la complicación que parece. En la unidad de la lección2 debemos añadir una sección de constantes (
Código Delphi [-]
const
) que contenga el siguiente codigo:

Código Delphi [-]
numbuffers = 3;
numsources = 3;
walk = 0;
ding = 1;
zap = 2;

Este código significa que tendremos tres buffers y tres sources. Tambien debemos dar nombres sencillos a dichos recursos.
La variable buffer y source necesitan ser modificados de la siguiente manera:

Código Delphi [-]
buffer : array [0..numbuffers] of TALuint;
source : array [0..numsources] of TALuint;

That gives you an array of buffers and an array of sources. Now every buffer has to be initialised in the oncreate event:

Código Delphi [-]
alGenBuffers(numbuffers, buffer);
alGenSources(numsources, source);


y cada sonido debe ser cargado:

Código Delphi [-]
AlutLoadWavFile(’footsteps.wav’, format, data, size, freq, loop);
AlBufferData(buffer[walk], format, data, size, freq);
AlutUnloadWav(format, data, size, freq);

AlutLoadWavFile(’ding.wav’, format, data, size, freq, loop);
AlBufferData(buffer[ding], format, data, size, freq);
AlutUnloadWav(format, data, size, freq);

AlutLoadWavFile(’phaser.wav’, format, data, size, freq, loop);
AlBufferData(buffer[zap], format, data, size, freq);
AlutUnloadWav(format, data, size, freq);


Tambien hemos de localizar cada source:

Código Delphi [-]
AlSourcei ( source[walk], AL_BUFFER, buffer[walk]);
AlSourcef ( source[walk], AL_PITCH, 1.0 );
AlSourcef ( source[walk], AL_GAIN, 1.0 );
AlSourcefv ( source[walk], AL_POSITION, @sourcepos);
AlSourcefv ( source[walk], AL_VELOCITY, @sourcevel);
AlSourcei ( source[walk], AL_LOOPING, AL_TRUE);


Debes añadir lo mismo para el sondidp "ding" y "zap".

Para reproducir un único sonido debemos de aplicar la siguiente función:

Código Delphi [-]
AlSourcePlay(source[walk]);
AlSourcePlay(source[ding]);
AlSourcePlay(source[zap]);


Lo mismo ocurre si queremos detener o pausar un sonido. Puedes crear botones para reproducir, pausar o detener cada sonido o bien crear un botón para reproducirlos todos a la vez.
The ontimer event also needs calls to multiple sources instead of one. You should have an idea on thow to change this.

Ahora todos los sonidos se mueven en la misma dirección y esto no es muy interesante. Change the ontimer event so that it only updates the walk source. In front of setting the source for ding and zap place something like this:

Código Delphi [-]
SourcePos[0] := 8.0;
SourcePos[1] := 1.0;
SourcePos[2] := -8.0;


You may also want to lower the gain (loudnes) of ding and zap to 0.2 The walk could use a boost to 1.5 . But you could place ding and zap further away to make them sound softer.
Lección3
Responder Con Cita