-
Notifications
You must be signed in to change notification settings - Fork 47
/
test.js
85 lines (70 loc) · 2.03 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// For testing with node.js
var sys = require("util");
var RIFFWAVE = require("./riffwave.js").RIFFWAVE;
var sfxr = require("./sfxr.js");
function dump(that, title) {
if (title) console.log('\n' + title + '\n');
for (var i in that)
if (typeof that[i] !== 'function')
console.log(i, that[i]);
}
function diff(a, b, title) {
if (title) console.log('\n' + title + '\n');
for (var i in a) {
if (a.hasOwnProperty(i) && typeof a[i] !== 'function') {
if (b.hasOwnProperty(i)) {
if (a[i] !== b[i])
console.log('%', i, a[i], b[i])
} else
console.log('<', i, a[i]);
}
}
for (var i in b) {
if (b.hasOwnProperty(i) && !a.hasOwnProperty(i)) {
console.log('>', i, b[i]);
}
}
}
//var sound = new sfxr.SoundEffect((new sfxr.Params()).tone()).generate();
/*
var knobs = new sfxr.Knobs({
shape: sfxr.SAWTOOTH,
attack: 0.1,
decay: 0.1,
sustain: 1,
frequency: 440,
});
var sound = new sfxr.SoundEffect(knobs).generate();
*/
/*
console.log("\nKNOBS TONE\n")
var a, b;
dump(a = new sfxr.SoundEffect(new sfxr.Knobs().tone()))
console.log("\nKNOBS FOR IT\n");
dump(new sfxr.Knobs().tone());
console.log("\nPARAMS TONE\n")
dump(b = new sfxr.SoundEffect(new sfxr.Params().tone()));
console.log("\nPARAMS FOR IT\n")
dump(new sfxr.Params().tone());
console.log('\nDIFF <knobs >params\n');
diff(a, b)
*/
var x = 'random';
var sound = new sfxr.SoundEffect(new sfxr.Knobs()[x]()).generate();
require("fs").writeFile("./test.wav", new Buffer(sound.wav), 'binary',
function(err) {
if(err) {
sys.puts(err);
} else {
sys.puts("test.wav saved!");
}
});
var p0 = new sfxr.Params()[x](0);
var p1 = new sfxr.Params()[x](1);
var q0 = new sfxr.Knobs().translate(p0);
var q1 = new sfxr.Knobs().translate(p1);
dump(p0, 'PARAMS 0');
dump(p1, 'PARAMS 1');
dump(q0, 'KNOBS 0');
dump(q1, 'KNOBS 1');
diff(q0, q1, 'DIFF KNOBS');