forked from mohayonao/pico.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
390 lines (370 loc) · 13.6 KB
/
index.html
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>pico.js - Write Once, Play Anywhere!</title>
<link rel="stylesheet" href="misc/bootstrap.min.css" type="text/css" />
<link rel="stylesheet" href="misc/prettify.css" type="text/css" />
<link rel="shortcut icon" href="./favicon.ico">
<style>
.header h1 {font-size:8em;line-height:1.2em;}
h1 {color:#00a497}
h2 {margin:25px 0 15px}
h2:before {content:"- "}
p {margin:4px 0}
button {margin-left:2px}
footer {margin-bottom:15px}
#social_button{margin-top:15px}
#social_button>div{float:left;min-width:70px}
#env li {display:inline}
code {color:#007b43}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>pico.js</h1>
</div>
<div class="pull-right">
<a href="./index-ja.html">日本語</a>
</div>
<hr/>
<h2>INTRODUCTION</h2>
<div class="row">
<div class="span6">
<h3>What is?</h3>
<p>Pico.js is a JavaScript library for real-time audio processing that runs a browser and node.js.</p>
</div>
<div class="span6">
<h3>Support</h3>
<ul id="env">
<li><img src="misc/chrome.png" title="chrome"></li>
<li><img src="misc/safari.png" title="safari"></li>
<li><img src="misc/firefox.png" title="firefox"></li>
<li><img src="misc/opera.png" title="opera"></li>
<li><img src="misc/ie.png" title="IE9"></li>
<li><img src="misc/nodejs.png" title="node.js"></li>
</ul>
</div>
</div>
<h2>USAGE</h2>
<div class="row">
<div class="span6">
<h3>Tutorial</h3>
<ol>
<li>
<h4>Make an object implemented a function <code>process(L, R)</code></h4>
<p>Arguments L and R are instanceof Float32Array</p>
</li>
<li>
<h4>Start processing: <code>pico.play(gen);</code></h4>
<p>Write signal into L and R in <code>gen.process(L, R)</code></p>
</li>
<li>
<h4>Stop processing: <code>pico.pause();</code></h4>
<p>The silence come</p>
</li>
</ol>
</div>
<div class="span6">
<h3>
ex.01
<button class="btn btn-mini pull-right">
<i class="icon-pause"></i> Pause
</button>
<button class="btn btn-mini pull-right" data="1">
<i class="icon-play"></i> Play
</button>
</h3>
<pre class="prettyprint lang-js">// Generate whitenoise
var noise = {
process: function(L, R) {
for (var i = 0; i < L.length; i++) {
L[i] = R[i] = Math.random() * 0.25;
}
}
};
pico.play(noise);
</pre>
</div>
</div>
<div class="row">
<div class="span6">
<h3>Others features</h3>
<ol>
<li>
<h4>Change the samplerate</h4>
<p><code>pico.setup({samplerate:24000})</code></p>
<p>You can choose some one [8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000]</p>
</li>
<li>
<h4>via Flash Player (Optional)</h4>
<p>Load a script</p>
<p><code><script src="libs/PicoFlashPlayer.js"></script></code></p>
<p>and</p>
<p><code>pico.bind(pico.FlashPlayer,{src:"libs/PicoFlashPlayer.swf"})</code></p>
</li>
<li>
<h4>node.js support</h4>
<p>You can install with npm.</p>
<p><code>$ npm install node-pico</code></p>
<p>See: repository <a href="https://github.com/mohayonao/pico.js/blob/master/demo/node-demo.js">demo/node-demo.js</a></p>
</li>
</ol>
</div>
<div class="span6">
<h3>
ex.02
<button class="btn btn-mini pull-right">
<i class="icon-pause"></i> Pause
</button>
<button class="btn btn-mini pull-right" data="2">
<i class="icon-play"></i> Play
</button>
</h3>
<pre class="prettyprint lang-js">// Generate sinetone
function sinetone(freq) {
var phase = 0,
phaseStep = freq / pico.samplerate;
return {
process: function(L, R) {
for (var i = 0; i < L.length; i++) {
L[i] = R[i] = Math.sin(6.28318 * phase) * 0.25;
phase += phaseStep;
}
}
};
}
pico.play(sinetone(880));
</pre>
</div>
</div>
<h2>REFERENCE</h2>
<div class="row">
<div class="span6">
<h3>Methods</h3>
<ol>
<li>
<h4><code>pico.play(gen)</code></h4>
<p>Start processing</p>
</li>
<li>
<h4><code>pico.pause()</code></h4>
<p>Stop processing</p>
</li>
<li>
<h4><code>pico.setup(opts)</code></h4>
<p>Setup samplerate and cellsize</p>
</li>
<li>
<h4><code>pico.bind(PlayerClass, opts)</code></h4>
<p>Use another PlayerClass (for example via Flash)</p>
</li>
</ol>
<h3>Properties</h3>
<ul>
<li>
<h4><code>pico.isPlaying</code></h4>
<p>Return true if processing</p>
</li>
<li>
<h4><code>pico.env</code></h4>
<p>Return environment (webkit, moz, nop=no operation)</p>
</li>
<li>
<h4><code>pico.samplerate</code></h4>
<p>Return samplerate</p>
</li>
<li>
<h4><code>pico.channels</code></h4>
<p>Return channels (always return 2)</p>
</li>
<li>
<h4><code>pico.cellsize</code></h4>
<p>Return length of samples to be processed</p>
</li>
</ul>
</div>
<div class="span6">
<h3>
ex.03
<button class="btn btn-mini pull-right">
<i class="icon-pause"></i> Pause
</button>
<button class="btn btn-mini pull-right" data="3">
<i class="icon-play"></i> Play
</button>
</h3>
<pre class="prettyprint lang-js">// Generate music from one-liner function
window.f1 = function(t) {
return Math.sin(t*(0.001+Math.sin(t>>10)))*64;
};
window.f2 = function(t) {
return (t>>9)&((t<<5)|(Math.sin(t*1.4142)*3000))+(t>>3);
};
function oneliner() {
var t = 0, dt = 8000 / pico.samplerate;
var dlyL = new pico.DelayNode({time:225, feedback:0.8});
var dlyR = new pico.DelayNode({time:225, feedback:0.8});
return {
process: function(L, R) {
for (var i = 0; i < L.length; i++) {
L[i] = (window.f1(t|0) % 256) / 512;
R[i] = (window.f2(t|0) % 256) / 512;
t += dt;
}
dlyL.process(L, true);
dlyR.process(R, true);
}
};
}
pico.play(oneliner());
</pre>
</div>
</div>
<h2>OTHERS</h2>
<div class="row">
<div class="span6">
<h3>Source</h3>
<ul>
<li><a href="./pico.js">pico.js</a> (minified)</li>
<li><a href="./pico.dev.js">pico.dev.js</a> (uncompressed)</li>
<li><a href="https://github.com/mohayonao/pico.js" target="github">Hosted on GitHub</a></li>
</ul>
<h3>License</h3>
<ul><li>MIT</li></ul>
<div id="social_button">
<div>
<a href="https://twitter.com/share" class="twitter-share-button" data-url="http://mohayonao.github.com/pico.js/">Tweet</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
</div>
<div>
<script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>
<g:plusone href="http://mohayonao.github.com/pico.js/" size="medium"></g:plusone>
</div>
<div>
<a href="http://b.hatena.ne.jp/entry/http://mohayonao.github.com/pico.js/" class="hatena-bookmark-button" data-hatena-bookmark-layout="simple-balloon" title="このエントリーをはてなブックマークに追加"><img src="http://b.st-hatena.com/images/entry-button/button-only.gif" alt="このエントリーをはてなブックマークに追加" width="20" height="20" style="border: none;" /></a><script type="text/javascript" src="http://b.st-hatena.com/js/bookmark_button.js" charset="utf-8" async="async"></script>
</div>
<div>
<div id="fb-root"></div>
<script>(function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(d.getElementById(id))return;js=d.createElement(s);js.id=id;js.src="//connect.facebook.net/ja_JP/all.js#xfbml=1";fjs.parentNode.insertBefore(js,fjs);}(document,'script','facebook-jssdk'));</script>
<div class="fb-like" data-href="http://mohayonao.github.com/pico.js/" data-send="false" data-layout="button_count" data-width="450" data-show-faces="false"></div>
</div>
</div>
</div>
<div class="span6">
<h3>
ex.04
<button class="btn btn-mini pull-right">
<i class="icon-pause"></i> Pause
</button>
<button class="btn btn-mini pull-right" data="4">
<i class="icon-play"></i> Play
</button>
</h3>
<pre class="prettyprint lang-js">// Demo song of MML and FM synthesis
// TO MAKE THE END OF BATTLE/Ys2
// Copyright© Nihon Falcom Corporation
//
// Original MML Data
// http://d.hatena.ne.jp/mosshm/20071013/p1
pico.play(demo());
</pre>
</div>
</div>
<footer>
<hr/>
2012 <a href="http://twitter.com/mohayonao" target="twitter">@mohayonao</a> / pico.js - "Write Once, Play Anywhere" JavaScript Library for real-time audio processing
</footer>
</div><!-- /container -->
<script>
if (!window.Float32Array) {
window.Float32Array = function(n) {
if (typeof n === "number") {
var array = new Array(n);
while (n--) array[n] = 0;
return array;
} else if (Array.isArray(n)) {
var array = new Array(n.length);
var i = n.length;
while (i--) array[i] = n[i];
return array;
}
};
}
</script>
<script src="misc/jquery.min.js"></script>
<script src="misc/prettify.js"></script>
<script src="pico.dev.js"></script>
<script src="libs/PicoFlashPlayer.js"></script>
<script src="libs/PicoDelayNode.js"></script>
<script src="demo/demo.js"></script>
<script>
$(function() {
var noise = {
process: function(L, R) {
for (var i = 0; i < L.length; i++) {
L[i] = R[i] = Math.random() * 0.25;
}
}
};
function sinetone(freq) {
var phase = 0,
phaseStep = freq / pico.samplerate;
return {
process: function(L, R) {
for (var i = 0; i < L.length; i++) {
L[i] = R[i] = Math.sin(2 * Math.PI * phase) * 0.25;
phase += phaseStep;
}
}
};
}
window.f1 = function(t) {
return Math.sin(t*(0.001+Math.sin(t>>10)))*64;
};
window.f2 = function(t) {
return (t>>9)&((t<<5)|(Math.sin(t*1.4142)*3000))+(t>>3);
};
function oneliner() {
var t = 0, dt = 8000 / pico.samplerate;
var dlyL = new pico.DelayNode({time:225, feedback:0.8});
var dlyR = new pico.DelayNode({time:225, feedback:0.8});
return {
process: function(L, R) {
for (var i = 0; i < L.length; i++) {
L[i] = (window.f1(t|0) % 256) / 512;
R[i] = (window.f2(t|0) % 256) / 512;
t += dt;
}
dlyL.process(L, true);
dlyR.process(R, true);
}
};
}
if (pico.env === "nop") {
pico.bind(pico.FlashPlayer, {src:"libs/PicoFlashPlayer.swf"});
}
prettyPrint();
var gen = [ null,
function() {
return noise;
},
function() {
return sinetone(880);
},
function() {
return oneliner();
},
function() {
return demo();
} ];
$("button").on("click", function() {
var id = $(this).attr("data")|0;
pico.pause();
if (id > 0) pico.play(gen[id]());
});
});
</script>
</body>
</html>