UNPKG

openfl

Version:

A fast, productive library for 2D cross-platform development.

107 lines (90 loc) 4.22 kB
// Class: openfl.events.SampleDataEvent var $global = typeof window != "undefined" ? window : typeof global != "undefined" ? global : typeof self != "undefined" ? self : this $global.Object.defineProperty(exports, "__esModule", {value: true}); var __map_reserved = {}; // Imports var $hxClasses = require("./../../hxClasses_stub").default; var $hxEnums = require("./../../hxEnums_stub").default; var $import = require("./../../import_stub").default; var $extend = require("./../../extend_stub").default; function openfl_events_Event() {return require("./../../openfl/events/Event");} function openfl_utils_ByteArrayData() {return require("./../../openfl/utils/ByteArrayData");} function Std() {return require("./../../Std");} function _$UInt_UInt_$Impl_$() {return require("./../../_UInt/UInt_Impl_");} function openfl_utils__$ByteArray_ByteArray_$Impl_$() {return require("./../../openfl/utils/_ByteArray/ByteArray_Impl_");} function js__$Boot_HaxeError() {return require("./../../js/_Boot/HaxeError");} function openfl_errors_Error() {return require("./../../openfl/errors/Error");} function haxe_io__$Float32Array_Float32Array_$Impl_$() {return require("./../../haxe/io/_Float32Array/Float32Array_Impl_");} // Constructor var SampleDataEvent = function(type,bubbles,cancelable) { if(cancelable == null) { cancelable = false; } if(bubbles == null) { bubbles = false; } (openfl_events_Event().default).call(this,type,bubbles,cancelable); var this1 = new (openfl_utils_ByteArrayData().default)(0); this.data = this1; this.data.set_endian("littleEndian"); this.position = 0.0; } // Meta SampleDataEvent.__name__ = "openfl.events.SampleDataEvent"; SampleDataEvent.__isInterface__ = false; SampleDataEvent.__super__ = (openfl_events_Event().default); SampleDataEvent.prototype = $extend((openfl_events_Event().default).prototype, { clone: function() { var event = new SampleDataEvent(this.type,this.bubbles,this.cancelable); event.target = this.target; event.currentTarget = this.currentTarget; event.eventPhase = this.eventPhase; event.data = this.data; event.position = this.position; return event; }, toString: function() { return this.__formatToString("SampleDataEvent",["type","bubbles","cancelable"]); }, __init: function() { (openfl_events_Event().default).prototype.__init.call(this); var this1 = new (openfl_utils_ByteArrayData().default)(0); this.data = this1; this.data.set_endian("littleEndian"); this.position = 0.0; }, getBufferSize: function() { var bufferSize = (Std().default).int((_$UInt_UInt_$Impl_$().default).toFloat((openfl_utils__$ByteArray_ByteArray_$Impl_$().default).get_length(this.data)) / (_$UInt_UInt_$Impl_$().default).toFloat(4) / 2); if(bufferSize > 0) { if(bufferSize != 0 && (bufferSize & bufferSize - 1) == 0 && bufferSize >= 2048 && bufferSize <= 8192) { var this1 = new Float32Array(bufferSize * 2); this.tempBuffer = this1; return bufferSize; } else { throw new (js__$Boot_HaxeError().default)(new (openfl_errors_Error().default)("To be consistent with flash the listener function registered to SampleDataEvent has to provide 2048, 4096 or 8192 samples if targeting HTML5.")); } } return 0; }, getSamples: function(event) { this.data.position = 0; this.tempBuffer = (haxe_io__$Float32Array_Float32Array_$Impl_$().default).fromBytes((openfl_utils__$ByteArray_ByteArray_$Impl_$().default).toBytes(this.data)); this.leftChannel = event.outputBuffer.getChannelData(0); this.rightChannel = event.outputBuffer.getChannelData(1); var pos = 0; var bufferLength = (Std().default).int((_$UInt_UInt_$Impl_$().default).toFloat((openfl_utils__$ByteArray_ByteArray_$Impl_$().default).get_length(this.data)) / (_$UInt_UInt_$Impl_$().default).toFloat(2)); var _g = 0; var _g1 = bufferLength; while(_g < _g1) { var i = _g++; this.leftChannel[i] = this.tempBuffer[pos++]; this.rightChannel[i] = this.tempBuffer[pos++]; } } }); SampleDataEvent.prototype.__class__ = SampleDataEvent.prototype.constructor = $hxClasses["openfl.events.SampleDataEvent"] = SampleDataEvent; // Init // Statics SampleDataEvent.SAMPLE_DATA = "sampleData" // Export exports.default = SampleDataEvent;