Last change
on this file since 28388 was 28388, checked in by davidb, 11 years ago |
Set of JS, CSS, PNG etc web resources to support a mixture of audio player/document display capabilities
|
File size:
1.1 KB
|
Line | |
---|
1 | <!DOCTYPE html>
|
---|
2 | <html>
|
---|
3 | <head>
|
---|
4 | <script src="pcmdata.js"></script>
|
---|
5 | <script src="../sink.js"></script>
|
---|
6 | <script>
|
---|
7 | (function(){
|
---|
8 |
|
---|
9 | var sampleRate, phase = 0, lfo = 0, lfo2 = 0, sink;
|
---|
10 |
|
---|
11 | window.onload = function () {
|
---|
12 | sink = new Sink.sinks.wav();
|
---|
13 |
|
---|
14 | if (!sink.type === 'wav') return console.error('Not an instance of the WAV sink.');
|
---|
15 |
|
---|
16 | sink.on('audioprocess', function (buffer, channelCount) {
|
---|
17 | var i, n;
|
---|
18 | for (i=0; i<buffer.length; i+=channelCount) {
|
---|
19 | phase = (phase + 440 / sampleRate / 2) % 1;
|
---|
20 | for (n=0; n<channelCount; n++) {
|
---|
21 | buffer[i+n] += Math.sin(phase * Math.PI * 2) * 0.5;
|
---|
22 | }
|
---|
23 | }
|
---|
24 | });
|
---|
25 |
|
---|
26 | sink.on('audioprocess', function (buffer, channelCount) {
|
---|
27 | var i, n;
|
---|
28 | for (i=0; i<buffer.length; i+=channelCount) {
|
---|
29 | lfo2 = (lfo2 + 0.1 / sampleRate / 2) % 1;
|
---|
30 | lfo = (lfo + (Math.sin(lfo2 * Math.PI * 2) + 2) * 111 / sampleRate / 2) % 1;
|
---|
31 | for (n=0; n<channelCount; n++) {
|
---|
32 | buffer[i+n] *= Math.sin(lfo * Math.PI * 2);
|
---|
33 | }
|
---|
34 | }
|
---|
35 | });
|
---|
36 |
|
---|
37 | sampleRate = Sink.singleton().sampleRate;
|
---|
38 |
|
---|
39 | sink.on('error', function(e){
|
---|
40 | console.error(e);
|
---|
41 | });
|
---|
42 | };
|
---|
43 |
|
---|
44 | }());
|
---|
45 |
|
---|
46 | </script>
|
---|
47 | </head>
|
---|
48 | <body>
|
---|
49 | </body>
|
---|
50 | </html>
|
---|
Note:
See
TracBrowser
for help on using the repository browser.