 |
| View previous topic :: View next topic |
| Author |
Message |
cweiske
Joined: 08 Dec 2005 Posts: 454 Location: Leipzig/Germany
|
Posted: Fri Jul 21, 2006 8:29 pm Post subject: Playing sound |
|
|
Since this question comes up pretty often, here is one solution to play wav files. It uses the PHP OpenAL extension that is *not* delivered with Gnope. Go to the php downloads page and get the latest win32 zip, it will be in there.
Another way would be to use the ecasound extension for php, or to call an external program like alsaplayer, mplayer, aplay and such. Using the win32 api could work, too - but is limited to win32 only.
Seems this would make a nice PEAR package - providing a nice API that chooses the best available way to play the file. If somebody volunteers?
| Code: | <?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));
?> |
|
|
| Back to top |
|
 |
leon_pegg
Joined: 12 Jun 2006 Posts: 113 Location: hemel / UK
|
Posted: Fri Jul 21, 2006 9:00 pm Post subject: |
|
|
i downloaded the pecl zip form php.net and there seems to be no php_openal.dll.
i have the openal sdk from openal.org.
would it be posible for you to tell me the name of the php openal dll
regards leon |
|
| Back to top |
|
 |
cweiske
Joined: 08 Dec 2005 Posts: 454 Location: Leipzig/Germany
|
Posted: Fri Jul 21, 2006 9:07 pm Post subject: |
|
|
| Normally, the extensions from pecl in a win32 version can be found at http://pecl4win.php.net/ . Unfortunately, php_openal.dll can't be found there... too bad. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
 |