AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Open Audio Library

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Zippo



Joined: 21 Apr 2006
Posts: 56
Location: East Coast, USA

PostPosted: Thu May 22, 2008 7:40 am    Post subject: Open Audio Library Reply with quote

I finally have all the wrappers and equates translated for OpenAL. I had a pretty hard time with this as there aren't many tutorials on it. So if you go looking, good luck. But after playing with it for a while you start to realize why there aren't many tutorials on it: there isn't much to it. After you get past the initial learning curve it is easy going.

Main advantages of this over something like SoundPlay is speed and control. You can pan, add effects etc. Speed was my main reason for messing with it. Once you have a sound buffered there is minimal wait when you call on it to play.

Here is a sample script:
Code:
#include al.ahk
#include al_functions.ahk
#include alc_functions.ahk
#include alut.ahk
#include alut_functions.ahk
#Persistent
#SingleInstance, Ignore

OnExit, Exit

hOpenAL32 := DllCall("LoadLibrary", Str, "OpenAL32.dll")
hAlut := DllCall("LoadLibrary", Str, "alut.dll")

NULL := 0

alutInitWithoutContext(NULL,0)
Device := alcOpenDevice("DirectSound3D")
Context := alcCreateContext(Device, NULL)
alcMakeContextCurrent(Context)
alGetError()

; The file must be a .wav file to load it this way. I've read that older
; versions of alut would only load 16-bit mono wav files, but the newest
; version handles 32-bit stereo (at least for me). For other file types
; you have to roll-your-own-loader.
file := "dust.wav"
buffer := alutCreateBufferFromFile(&file)

; Quote out the above and unquote this to play a simple built-in
; sample.
;buffer := alutCreateBufferHelloWorld()

If (buffer = AL_NONE)
{
   a := alutGetErrorString(alutGetError())
   DllCall("MessageBoxA", UInt, 0, UInt, a, UInt, 0, Int, 0)
   ExitApp
}

VarSetCapacity(source,4,0)
alGenSources(1, &source)
source := NumGet(source,0,"UInt")
alSourcei(source, AL_BUFFER, buffer)

; Quote out this line to prevent the sound from looping.
alSourcei(source,AL_LOOPING,1)

alSourcePlay(source)

Return

Esc::ExitApp


; Cleanup
Exit:
   alSourceStop(source)
   alDeleteSources(1, source)
   alDeleteBuffers(1, buffer)
   Context := alcGetCurrentContext()
   Device := alcGetContextsDevice(Context)
   alcMakeContextCurrent(0)
   alcDestroyContext(Context)
   alcCloseDevice(Device)
   alutExit()

   If hOpenAL32
      DllCall("FreeLibrary", UInt, hOpenAL32)
   If hAult
      DllCall("FreeLibrary", UInt, hAult)
ExitApp


The #includes and a sample wav file is here: http://www.autohotkey.net/~Zippo/opengl/openal.zip

That zip also contains alut.dll which is needed for the wav file loading (and does not install with OpenAL). You will need to install the OpenAL library anyhow, so you might grab your own alut sdk (includes the dll). If you have some OpenGL games installed (America's Army, Doom, Lineage....) you probably already have OpenAL installed.

If you need it, get the OpenAL library here: http://www.openal.org
_________________
____________________
Back to top
View user's profile Send private message
k3ph



Joined: 20 Jul 2006
Posts: 174

PostPosted: Sun Aug 17, 2008 9:07 am    Post subject: Reply with quote

yeah its very hard to get some information about sound libraries...

thank you very much for this, very useful.
_________________
                                  [ profile | ahk.net | ahk.talk ]
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group