Created
July 29, 2014 05:06
-
-
Save jgranick/026efc8addaf6cbca353 to your computer and use it in GitHub Desktop.
Basic Lime/OpenAL sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//var bytes = Assets.getBytes ("soundTheme"); | |
//var sound = lime.audio.Sound.loadFromBytes (bytes); | |
var sound = lime.audio.Sound.loadFromFile ("sounds/theme.ogg"); | |
var format = 0; | |
if (sound.channels == 1) { | |
if (sound.bitsPerSample == 8) { | |
format = AL.FORMAT_MONO8; | |
} else if (sound.bitsPerSample == 16) { | |
format = AL.FORMAT_MONO16; | |
} | |
} else if (sound.channels == 2) { | |
if (sound.bitsPerSample == 8) { | |
format = AL.FORMAT_STEREO8; | |
} else if (sound.bitsPerSample == 16) { | |
format = AL.FORMAT_STEREO16; | |
} | |
} | |
var device = ALC.openDevice (); | |
var context = ALC.createContext (device); | |
ALC.makeContextCurrent (context); | |
ALC.processContext (context); | |
var buffer = AL.genBuffer (); | |
AL.bufferData (buffer, format, new Float32Array (sound.data), sound.data.length, sound.sampleRate); | |
var source = AL.genSource (); | |
AL.sourcei (source, AL.BUFFER, buffer); | |
/* | |
AL.sourcef (source, AL.PITCH, 1.0); | |
AL.sourcef (source, AL.GAIN, 1.0); | |
AL.source3f (source, AL.POSITION, Math.cos ((pan - 1) * (1.5707)), 0.0, Math.sin ((pan + 1) * (1.5707))); | |
*/ | |
AL.sourcePlay (source); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment