mirror of
https://github.com/danog/system-bus-radio.git
synced 2025-01-22 15:41:11 +01:00
simplify busy work
This commit is contained in:
parent
406465e207
commit
1029934c07
@ -2,45 +2,15 @@
|
||||
//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;
|
||||
var register = 3.1415
|
||||
|
||||
function square_am_signal(time,freq) {
|
||||
document.getElementById('logs').value += "Playing / "+time+" seconds / "+freq+"Hz\n";
|
||||
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;
|
||||
@ -48,8 +18,9 @@ function square_am_signal(time,freq) {
|
||||
var mid = start+period/2;
|
||||
var reset = start+period;
|
||||
while (now()<mid) {
|
||||
Int32x4store(tarray, 0, one);
|
||||
Int32x4store(tarray, 0, zero);
|
||||
for (i = 0; i < 100; i++) {
|
||||
register = 1 - Math.log(register) / 1.7193
|
||||
}
|
||||
}
|
||||
while(now() < reset){
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user