Created
March 27, 2015 06:33
-
-
Save jonbro/4e007fec8c10aa8dd5a4 to your computer and use it in GitHub Desktop.
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
| import snow.platform.native.audio.openal.SoundStream; | |
| import snow.audio.Audio; | |
| import snow.types.Types; | |
| import snow.io.typedarray.Uint8Array; | |
| import snow.io.typedarray.Float32Array; | |
| import snow.Log; | |
| import luxe.Input; | |
| class Main extends luxe.Game { | |
| var myStream : MyStream; | |
| override function ready() { | |
| myStream = new MyStream(Luxe.core.app.audio, "streamname"); | |
| Luxe.core.app.audio.stream_list.set("streamname", myStream); | |
| Luxe.core.app.audio.sound_list.set("streamname", myStream); | |
| Luxe.audio.on("streamname", "load", function(_){ | |
| Luxe.audio.loop("streamname"); | |
| }); | |
| } //ready | |
| override function onkeyup( e:KeyEvent ) { | |
| if(e.keycode == Key.escape) { | |
| Luxe.shutdown(); | |
| } | |
| } //onkeyup | |
| override function onrender() { | |
| } //onrender | |
| } //Main | |
| class MyStream extends snow.platform.native.audio.openal.SoundStream { | |
| var sound : Uint8Array ; | |
| var audioData : AudioDataBlob; | |
| var floatCounter:Float; | |
| public function new( _manager:Audio, _name:String ) { | |
| is_stream = true; | |
| super( _manager , _name); //make sure it has a manager to do api calls with | |
| var adinfo:AudioDataInfo = { | |
| length: -1, | |
| length_pcm: -1, | |
| channels: 2, | |
| rate: 44100, | |
| bitrate: 16, | |
| bits_per_sample: 16, | |
| bytes: null | |
| }; | |
| var info:AudioInfo = { | |
| id: "test", | |
| format:1, | |
| handle: null, data: adinfo | |
| }; | |
| set_info(info); | |
| buffer_length = _manager.lib.config.native.audio_buffer_length; | |
| buffer_count = _manager.lib.config.native.audio_buffer_count; | |
| sound = new Uint8Array(buffer_length); | |
| audioData = { bytes : sound , complete : false}; | |
| data_seek = function( to:Int ) { return false; } | |
| floatCounter = 0; | |
| trace("in mystream"); | |
| data_get = myDataGet; | |
| } //new | |
| function myDataGet( _start:Int, _length:Int ) : AudioDataBlob{ | |
| trace("in data get"); | |
| var soundfloats = new Float32Array(_length); | |
| var floatLength:Int = Std.int(_length); | |
| for(i in 0...floatLength){ | |
| soundfloats[i] = Math.sin(floatCounter); | |
| floatCounter += Math.sin(floatCounter*0.001)*0.001+0.005; | |
| } | |
| for(i in 0...floatLength){ | |
| sound[i] = Std.int(soundfloats[i]*256); | |
| } | |
| // sound = Uint8Array.fromBytes(soundfloats.toBytes()); | |
| audioData = { bytes : sound , complete : false}; | |
| return audioData; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment