diff --git a/js_version/airgap.html b/js_version/airgap.html new file mode 100644 index 0000000..48a5559 --- /dev/null +++ b/js_version/airgap.html @@ -0,0 +1,24 @@ + + + + + + + System Bus Radio + + + + + +
+ System Bus Radio +
+
+
+

+ +
Ported by Yeo Quan Yang. Credits to the original author William Entriken @https://github.com/fulldecent

+
+ + \ No newline at end of file diff --git a/js_version/airgap.js b/js_version/airgap.js new file mode 100644 index 0000000..8d5eca0 --- /dev/null +++ b/js_version/airgap.js @@ -0,0 +1,87 @@ +//Credits to https://github.com/fulldecent/system-bus-radio +//As well as Jordan Harband for the nodejs simd library +//Tested to be working on Chrome at 1560khz + +var _i32x4 = new Int32Array(4); +Int32x4 = function(x, y, z, w) { + if (!(this instanceof Int32x4)) { + return new Int32x4(x, y, z, w); + } + + this.x_ = x|0; + this.y_ = y|0; + this.z_ = z|0; + this.w_ = w|0; +} + +Int32x4store = function(tarray, index, value) { + var bpe = tarray.BYTES_PER_ELEMENT; + _i32x4[0] = value.x_; + _i32x4[1] = value.y_; + _i32x4[2] = value.z_; + _i32x4[3] = value.w_; + var array = bpe == 1 ? _i8x16 : + bpe == 2 ? _i16x8 : + bpe == 4 ? (tarray instanceof Float32Array ? _f32x4 : _i32x4) : + _f64x2; + var n = 16 / bpe; + for (var i = 0; i < n; ++i) + tarray[index + i] = array[i]; + return value; +} + +function now() { + return performance.now()*1000000; +} + +var tarray = new Int32Array(4); +var zero = Int32x4(0,0,0,0); +var one = Int32x4(-1,-1,-1,-1); +var NSEC_PER_SEC = 1000000000; + +function square_am_signal(time,freq) { + document.getElementById('logs').value += "Playing / "+time+" seconds / "+freq+"Hz\n"; + var period = NSEC_PER_SEC/freq; + var start = now(); + var end = now()+time*NSEC_PER_SEC; + while (now() < end) { + var mid = start+period/2; + var reset = start+period; + while (now()