Skip to content

Commit 2dbc0c1

Browse files
committed
daisy
1 parent 6e163e7 commit 2dbc0c1

File tree

3 files changed

+19
-41
lines changed

3 files changed

+19
-41
lines changed

canon.js

+16-16
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function _createMod(t) {
5656

5757
function _createNote(m, idx, t) {
5858
var arr = new Float32Array(t), size = t.length;
59-
_mul(arr, _st[idx], size);
59+
_mul(arr, _st[idx-1], size);
6060
_cos(arr, size);
6161
_dotMul(arr, m, size);
6262
return arr;
@@ -80,20 +80,25 @@ function _linkArray(a1, a2/*,a3...*/) {
8080
}
8181

8282
function _createS(c1,v1,v2,v3){
83-
var m_size = Math.min(c1.length,v1.length,v2.length,v3.length),
84-
arr = new Float32Array(m_size);
83+
var m_size = Math.min(c1.length,v1.length,v2.length,v3.length);
84+
ab = context.createBuffer(1, m_size, fs),
85+
buf = ab.getChannelData(0);
8586
var max_s = 0;
87+
8688
for(var i=0;i<m_size;i++){
8789
var s = c1[i]+v1[i]+v2[i]+v3[i];
8890
if(s>max_s)
8991
max_s = s;
90-
arr[i] = s;
92+
buf[i] = s;
9193
}
92-
return {
93-
arr : arr,
94-
max : max_s
95-
}
94+
95+
_div(buf, max_s, m_size);
96+
97+
$.log(buf[1]);
9698
}
99+
100+
context = new webkitAudioContext(), ab = null, buf = null;
101+
97102
fs = 44100;
98103
dt = 1 / fs;
99104

@@ -117,11 +122,11 @@ f0 = 2 * 146.8;
117122

118123
_st = new Float32Array([2 / 3, 3 / 4, 5 / 6, 15 / 16, 1, 9 / 8, 5 / 4, 4 / 3, 3 / 2, 5 / 3, 9 / 5, 15 / 8, 2, 9 / 4, 5 / 2, 8 / 3, 3, 10 / 3, 15 / 4, 4, 1 / 2, 9 / 16, 5 / 8]);
119124

125+
120126
for(var x = 0; x < _st.length; x++) {
121-
_st[i] *= Math.PI * 2 * f0;
127+
_st[x] *= (Math.PI * 2 * f0);
122128
}
123129

124-
125130
do0f = _createNote(mod4, 21, t4);
126131
re0f = _createNote(mod4, 22, t4);
127132
mi0f = _createNote(mod4, 23, t4);
@@ -216,10 +221,5 @@ v2 = _linkArray(blkblock,blkblock,violin,blkblock);
216221
v3 = _linkArray(blkblock,blkblock,blkblock,violin);
217222

218223
// Get dirty
219-
s_m = _createS(c1,v1,v2,v3);
220-
221-
s = s_m.arr;
222-
223-
_div(s, s_m.max, s.length);
224+
_createS(c1,v1,v2,v3);
224225

225-
$.log(s(1))

canon.matlab

+2-2
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ v3 = [blkblock blkblock blkblock violin];
174174

175175

176176
% Get dirty
177-
s = c1+v1+v2+v3;
178-
s = s/max(s);
177+
s1 = c1+v1+v2+v3;
178+
s = s1/max(s1);
179179

180180
sound(s,fs);

index.html

+1-23
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,8 @@
1515
</button>
1616

1717
<script type="text/javascript">
18-
var context = new webkitAudioContext(), afterBuffer = null, afterSource = null;
19-
/* $(function() {
20-
var xhr = new XMLHttpRequest();
21-
xhr.open("GET", "music/after.mp3", true);
22-
xhr.responseType = 'arraybuffer';
23-
xhr.onload = function(e) {
24-
context.decodeAudioData(xhr.response, function(buffer) {
25-
afterBuffer = buffer;
26-
$("#btn-play").attr("disabled", false);
27-
$.log(buffer.length);
28-
}, null);
29-
30-
};
31-
xhr.send();
32-
}); */
18+
3319
function start() {
34-
var freq = 440,
35-
ab = context.createBuffer(1, 44100, 44100),
36-
buf = ab.getChannelData(0);
37-
$.log(ab);
38-
$.log(buf.length);
39-
for(var i = 0; i<44100; i++){
40-
buf[i] = Math.sin( freq * 2 * Math.PI * i / 44100);
41-
}
4220
afterSource = context.createBufferSource();
4321
afterSource.buffer = ab;
4422
afterSource.connect(context.destination);

0 commit comments

Comments
 (0)