Playing a wav file:
<?php
function printok($b) {
echo $b ? " ok\n" : " error\n";
}
echo "Opening device";
$device = openal_device_open();
printok($device);
echo "Creating context";
$context = openal_context_create($device);
printok($context);
echo "Making context the current";
printok(openal_context_current($context));
//where we are
//echo "Setting listener position";
//printok(openal_listener_set(AL_POSITION, array(0, 0, 0)));
//echo "Setting listener orientation";
//printok(openal_listener_set(AL_ORIENTATION, array(0=>0,1 => 1, 2=>0, 3=> 0, 4=>4, 5=>5)));
echo "Creating buffer";
$buffer = openal_buffer_create();
echo "Loading wav";
printok(openal_buffer_loadwav($buffer, '/data/shared/vmware/newmessage.wav'));
echo "buffer stats\n";
echo " Frequency: " . openal_buffer_get($buffer, AL_FREQUENCY) . "\n";
echo " Bits : " . openal_buffer_get($buffer, AL_BITS) . "\n";
echo " Channels : " . openal_buffer_get($buffer, AL_CHANNELS) . "\n";
echo " Size : " . openal_buffer_get($buffer, AL_SIZE) . "\n";
echo "Creating source";
$source = openal_source_create();
echo "Setting source buffer";
printok(openal_source_set($source, AL_BUFFER, $buffer));
//echo "Setting source position";
//printok(openal_source_set($source, AL_POSITION, array(1, 0, 0)));
echo "Playing source";
printok(openal_source_play($source));
echo "sleeping\n";
//sleep(1);
//we wait 300msecs beause the sound
// has no time to be played otherwise
//since playing sound is done concurrently
// to the script
usleep(300000);
echo "Destroying source";
printok(openal_source_destroy($source));
echo "Destroying buffer";
printok(openal_buffer_destroy($buffer));
echo "Destroying context";
printok(openal_context_destroy($context));
echo "Closing device";
printok(openal_device_close($device));
?>