Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jgranick
Created July 29, 2014 05:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgranick/026efc8addaf6cbca353 to your computer and use it in GitHub Desktop.
Save jgranick/026efc8addaf6cbca353 to your computer and use it in GitHub Desktop.
Basic Lime/OpenAL sample
//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