|
2 | 2 | //As well as Jordan Harband for the nodejs simd library |
3 | 3 | //Tested to be working on Chrome at 1560khz |
4 | 4 |
|
5 | | -var _i32x4 = new Int32Array(4); |
6 | | -Int32x4 = function(x, y, z, w) { |
7 | | - if (!(this instanceof Int32x4)) { |
8 | | - return new Int32x4(x, y, z, w); |
9 | | - } |
10 | | - |
11 | | - this.x_ = x|0; |
12 | | - this.y_ = y|0; |
13 | | - this.z_ = z|0; |
14 | | - this.w_ = w|0; |
15 | | -} |
16 | | - |
17 | | -Int32x4store = function(tarray, index, value) { |
18 | | - var bpe = tarray.BYTES_PER_ELEMENT; |
19 | | - _i32x4[0] = value.x_; |
20 | | - _i32x4[1] = value.y_; |
21 | | - _i32x4[2] = value.z_; |
22 | | - _i32x4[3] = value.w_; |
23 | | - var array = bpe == 1 ? _i8x16 : |
24 | | - bpe == 2 ? _i16x8 : |
25 | | - bpe == 4 ? (tarray instanceof Float32Array ? _f32x4 : _i32x4) : |
26 | | - _f64x2; |
27 | | - var n = 16 / bpe; |
28 | | - for (var i = 0; i < n; ++i) |
29 | | - tarray[index + i] = array[i]; |
30 | | - return value; |
31 | | -} |
32 | | - |
33 | 5 | function now() { |
34 | 6 | return performance.now()*1000000; |
35 | 7 | } |
36 | 8 |
|
37 | | -var tarray = new Int32Array(4); |
38 | | -var zero = Int32x4(0,0,0,0); |
39 | | -var one = Int32x4(-1,-1,-1,-1); |
40 | 9 | var NSEC_PER_SEC = 1000000000; |
| 10 | +var register = 3.1415 |
41 | 11 |
|
42 | 12 | function square_am_signal(time,freq) { |
43 | | - document.getElementById('logs').value += "Playing / "+time+" seconds / "+freq+"Hz\n"; |
| 13 | + document.getElementById('logs').value += "Playing / "+time+" seconds / "+freq+"Hz\n"; |
44 | 14 | var period = NSEC_PER_SEC/freq; |
45 | 15 | var start = now(); |
46 | 16 | var end = now()+time*NSEC_PER_SEC; |
47 | 17 | while (now() < end) { |
48 | 18 | var mid = start+period/2; |
49 | 19 | var reset = start+period; |
50 | 20 | while (now()<mid) { |
51 | | - Int32x4store(tarray, 0, one); |
52 | | - Int32x4store(tarray, 0, zero); |
| 21 | + for (i = 0; i < 100; i++) { |
| 22 | + register = 1 - Math.log(register) / 1.7193 |
| 23 | + } |
53 | 24 | } |
54 | 25 | while(now() < reset){ |
55 | 26 | } |
|
0 commit comments