[Gambas-user] OpenAL (gb.openal) example code
Kevin Fishburne
kevinfishburne at ...1887...
Tue Sep 15 07:49:18 CEST 2015
On 09/10/2015 10:33 PM, Benoît Minisini wrote:
> Le 11/09/2015 04:12, Kevin Fishburne a écrit :
>>
>> I've only tested this on a 2.0 (stereo) audio setup, so there is some
>> chance that the front and rear speakers will be reversed, but these are
>> the two sets of values for the listener orientation for the two
>> coordinate orientations I mentioned.
>>
>> For a game where the Z axis goes "into" the screen and the Y axis is
>> height/elevation (the normal way things are done), this works:
>>
>> Al.Listenerfv(Al.ORIENTATION, [0, 0, -1, 0, 1, 0])
>>
>> For a game where the Y axis goes "into" the screen and the Z axis is
>> height/elevation (what Sylph uses), this works:
>>
>> Al.Listenerfv(Al.ORIENTATION, [0, -1, 0, 0, 0, -1])
>>
>> In a game where the camera's orientation is completely arbitrary (an FPS
>> or flight sim, for example) the listener orientation should correspond
>> to the "camera" orientation.
>>
>> Something else to note about OpenAL is that if a sample/sound file is
>> multichannel (stereo, for example) 3D positioning and doppler effects
>> will be ignored and the sound will play equally on all speakers (like
>> you were playing music in a media player). If you want a sound effect to
>> use 3D positioning and doppler effects it must be mono (one channel).
>> You can use a program like Audacity to check/correct this.
>>
> You should put that in a wiki article...
>
When I've gotten most everything I need figured out I'll write a
tutorial to accompany the example code. This hopefully will be sooner
than later.
Currently using Alure.BufferDataFromFile to load sound files into OpenAL
buffers I'm unable to get the buffer properties using the Al.GetBufferi
function. I don't know if this is because I'm using Alure versus the
regular Al method, but this code should work and doesn't (see attached
project):
' Load audio data from .wav file into audio buffer.
Print "Load buffer data from wav file:" & Gb.CrLf & " ";
Print Alure.BufferDataFromFile("./test.ogg", AudioBuffer[0])
' Display audio data properties.
Print "Audio frequency in Hz:" & Gb.CrLf & " ";
Print Al.GetBufferi(AudioBuffer[0], Al.FREQUENCY)
Print "Audio buffer bit depth:" & Gb.CrLf & " ";
Print Al.GetBufferi(AudioBuffer[0], Al.BITS)
Print "Audio channels:" & Gb.CrLf & " ";
Print Al.GetBufferi(AudioBuffer[0], Al.CHANNELS)
Print "Audio data size in bytes:" & Gb.CrLf & " ";
Print Al.GetBufferi(AudioBuffer[0], Al.SIZE)
It returns zeros instead of the proper values. In particular I need the
Size property returned, as this can be used to calculate an offset from
which to start playing a sample once attached to a source. This is
necessary because multiple sources created and played simultaneously
using the same buffer will result in the waveforms being combined at the
same sample point, which creates a metallic, flange-like effect. If I
can find a buffer's size I can offset the position at which a source
begins to play randomly between zero and the buffer's size like this:
Al.Sourcei(Ship[ShipIndex].AudioSourceVelocity[0], Al.BYTE_OFFSET,
Rnd(0, Al.GetBufferi(AudioBufferVelocity[0], Al.SIZE)))
For now I'm going to have to use something like Rnd(0, 100000) for the
offset and simply hope it doesn't exceed the buffer's size, which
silently returns an error and plays the source at zero (no offset).
--
Kevin Fishburne
Eight Virtues
www: http://sales.eightvirtues.com
e-mail: sales at ...1887...
phone: (770) 853-6271
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenAL.tar.gz
Type: application/gzip
Size: 109686 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20150915/82f6095c/attachment.gz>
More information about the User
mailing list