OpenAL aims to provide a standardized API for something called '3D' sound, just like OpenGL does for '3D' video rendering.
The fun part of OpenAL is that it does all the DSP for you, so you don't need to know a lot about audio. Since OpenAL comes from Creative Labs, it supports hardware rendering of audio with most if not all SoundBlaster audio controllers. They come with chips from EMU-systems and are specifically designed to mix down multichannel audio with DSP effects like reverb and chorus, which could consume a lot CPU speed.
The downside of OpenAL is that (at this time of writing) it is focus on games only. It doesn't do MIDI at all, it doesn't record anything, it doesn't work like a synthesizer. The only thing you can do with OpenAL is play sounds in a simulated 3D environment.
It probably doesn't work on the web.
To use OpenAL you need to read the documentation about OpenAL.
Note concerning audio users: there's no such thing as '3D' audio with speakers. Technically, when people have only two ears, they really can't distinguish sound from above or below, even in front or from behind. To achieve this people merely hear volume, the brightness of sound and the phase difference. One should be able to hear more '3D' sound with only two quality-class speakers than with a consumer class 5.1-set.
Funciones de OpenAL
Tabla de contenidos
- openal_buffer_create — Genera un buffer OpenAL
- openal_buffer_data — Carga un buffer con datos
- openal_buffer_destroy — Destruye un buffer OpenAL
- openal_buffer_get — Recupera una propiedad del buffer OpenAL
- openal_buffer_loadwav — Carga un archivo .wav dentro de un buffer
- openal_context_create — Crea un contexto de procesamiento de audio
- openal_context_current — Crea el corriente contexto especificado
- openal_context_destroy — Destruye un contexto
- openal_context_process — Procesa un contexto especificado
- openal_context_suspend — Suspende el contexto especificado
- openal_device_close — Cierra un dispositivo OpenAL
- openal_device_open — Inicia la capa de audio del OpenAL
- openal_listener_get — Devuelve una propiedad de oyente
- openal_listener_set — Establece una propiedad de oyente
- openal_source_create — Genera una fuente de recursos
- openal_source_destroy — Destruye una fuente de recursos
- openal_source_get — Recupera una propiedad de una fuente del OpenAL
- openal_source_pause — Pausa la fuente
- openal_source_play — Empieza la reproducción de la fuente
- openal_source_rewind — Rebobina la fuente
- openal_source_set — Establece la propiedad de la fuente
- openal_source_stop — Detiene la reproducción de la fuente
- openal_stream — Empieza la salida de una fuente
Tjeerd ¶
6 years ago
cweiske at cweiske dot de ¶
6 years ago
I made a PHP-Gtk2 OpenAL demo which allows you to define as many sound sources as you like and position them relative to the listener by drag and drop: http://gnope.org/p/Tools_OpenALdemo
cweiske at cweiske dot de ¶
6 years ago
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));
?>
