[Gambas-user] OpenAL (gb.openal) example code

Kevin Fishburne kevinfishburne at ...1887...
Sun Aug 23 06:43:37 CEST 2015


On 08/23/2015 12:29 AM, Kevin Fishburne wrote:
> On 08/22/2015 10:56 AM, Kevin Fishburne wrote:
>> Heh, yes I will. I test; you fix. :) Thanks everyone for the responses
>> and fix to the code. Now that I got the very basics working (can load
>> and play a sound) I'll start working on getting 3D positioning,
>> doppler, etc. working and will put together a nice demo. When it's
>> polished I'll upload it to the farm so others may benefit. Once that's
>> done I'll begin replacing the SDL audio code in Sylph and put a video
>> up on YouTube to show off the new audio capabilities.
> Okay, after searching through tons of shitty old web examples, actually
> reading the frakking manual from 2001 (not the movie) and some
> experimentation I've made a little progress. Here's the link to the new
> project revision:
>
> http://eightvirtues.com/misc/OpenAL.tar.gz
>
> To a limited degree I can get 3D positional audio and doppler based on
> velocity working, but only by changing the relevant parameters for the
> audio source and not the listener. I also have to set this to TRUE, not
> FALSE:
>
> Al.Sourcei(AudioSource[0], Al.SOURCE_RELATIVE, Al.TRUE)
>
> Ideally it should be FALSE as the "camera" (listener) moves as well as
> the audio sources (space ships and such), and having audio source
> positions calculated relative to the listener position doesn't allow me
> to use global/scene coordinates for both and would be unnatural for most
> 3D games.
>
> I'm wondering if the line:
>
> Al.Listenerfv(Al.ORIENTATION, [0, 0, -1])
>
> may be incorrect, as the Gambas documentation says it should have more
> parameters but online docs say otherwise.
>
> Right now I'm testing this using two-channel stereo. Once that's working
> I'll test it on a 5.1 system.
>

Okay, I found this code:

https://hackage.haskell.org/package/OpenAL-1.4.0.1/docs/src/Sound-OpenAL-AL-Listener.html

with perhaps this being the pertinent information in its comments:

-- | 'orientation' contains an \"at\" vector and an \"up\" vector, where the
-- \"at\" vector represents the \"forward\" direction of the listener 
and the
-- orthogonal projection of the \"up\" vector into the subspace 
perpendicular to
-- the \"at\" vector represents the \"up\" direction for the listener. 
OpenAL
-- expects two vectors that are linearly independent. These vectors are not
-- expected to be normalized. If the two vectors are linearly dependent,
-- behavior is undefined. The initial orientation is ('Vector3' 0 0 (-1),
-- 'Vector3' 0 1 0), i.e. looking down the Z axis with the Y axis pointing
-- upwards.

I changed the listener orientation vector assignment line to this:

Al.Listenerfv(Al.ORIENTATION, [0, 0, -1, 0, 1, 0])

and it seems to work with Al.SOURCE_RELATIVE set to FALSE for both 
listener and source position changes. Yummy. Let me know if any of this 
sounds correct and I'll continue testing/experimentation.

-- 
Kevin Fishburne
Eight Virtues
www: http://sales.eightvirtues.com
e-mail: sales at ...1887...
phone: (770) 853-6271





More information about the User mailing list