..
const
numbuffers = 2;
numsources = 2;
schuss = 0;
explosion = 1;
var
buffer : array [0..numbuffers] of TALuint;
source : array [0..numsources] of TALuint;
sourcepos: array [0..2] of TALfloat= ( 0.0, 0.0, 0.0 );
sourcevel: array [0..2] of TALfloat= ( 0.0, 0.0, 0.0 );
listenerpos: array [0..2] of TALfloat= ( 0.0, 0.0, 0.0);
listenervel: array [0..2] of TALfloat= ( 0.0, 0.0, 0.0);
listenerori: array [0..5] of TALfloat= ( 0.0, 0.0, -1.0, 0.0, 1.0, 0.0);
implementation
constructor TSound.Create;
var
argv: array of PChar;
format: TALEnum;
size: TALSizei;
freq: TALSizei;
loop: TALInt;
data: TALVoid;
begin
AlutInit(nil,argv);
AlGenBuffers(numbuffers, @buffer);
AlutLoadWavFile('sounds/bomb.wav', format, data, size, freq, loop);
AlBufferData(buffer[explosion], format, data, size, freq);
AlutUnloadWav(format, data, size, freq);
AlutLoadWavFile('sounds/laserbeamz.wav', format, data, size, freq, loop);
AlBufferData(buffer[schuss], format, data, size, freq);
AlutUnloadWav(format, data, size, freq);
AlGenSources(numsources, @source);
AlSourcei ( source[schuss], AL_BUFFER, buffer[schuss]);
AlSourcef ( source[schuss], AL_PITCH, 1.0 );
AlSourcef ( source[schuss], AL_GAIN, 1.0 );
AlSourcefv ( source[schuss], AL_POSITION, @sourcepos);
AlSourcefv ( source[schuss], AL_VELOCITY, @sourcevel);
AlSourcei ( source[schuss], AL_LOOPING, loop);
AlSourcei ( source[explosion], AL_BUFFER, buffer[explosion]);
AlSourcef ( source[explosion], AL_PITCH, 1.0 );
AlSourcef ( source[explosion], AL_GAIN, 1.0 );
AlSourcefv ( source[explosion], AL_POSITION, @sourcepos);
AlSourcefv ( source[explosion], AL_VELOCITY, @sourcevel);
AlSourcei ( source[explosion], AL_LOOPING, loop );
AlListenerfv ( AL_POSITION, @listenerpos);
AlListenerfv ( AL_VELOCITY, @listenervel);
AlListenerfv ( AL_ORIENTATION, @listenerori);
end;
procedure TSound.playsound ( pname : string );
begin
if pname = 'schuss' then AlSourcePlay(source[schuss])
else if pname = 'explosion' then AlSourcePlay(source[explosion]);
end;