-
Notifications
You must be signed in to change notification settings - Fork 0
/
mono-to-stereo.html
88 lines (72 loc) · 2.28 KB
/
mono-to-stereo.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
<link rel="import" href="../polymer/polymer.html">
<dom-module id="mono-to-stereo">
<template>
</template>
<script>
/**
* An element that provides a simple way of generating stereo sound from audio
*
* Example:
* <mono-to-stereo></mono-to-stereo>
*
* @demo demo/index.html
*/
Polymer({
is: 'mono-to-stereo',
properties: {
/**
* `input` represents the input mono stream
*/
input: {
type: Object,
notify: true,
reflectToAttribute: true
},
/**
* `output` represents the output stereo stream
*/
output: {
type: Object,
notify: true,
reflectToAttribute: true
},
/**
* `outputUrl` represents a url to the output stereo stream
*/
outputUrl: {
type: String,
notify: true,
reflectToAttribute: true
}
},
attached: function(){
setTimeout(function(){
console.log(this.input);
var context = new (window.AudioContext || window.webkitAudioContext)();
// var source = context.createMediaStreamSource(this.input);
this.output = context.createMediaStreamDestination();
// split
var leftClone = context.createMediaStreamSource(this.input.clone()),
rightClone = context.createMediaStreamSource(this.input.clone());
// pan left
var panLeft = context.createStereoPanner();
panLeft.pan.value = -1;
leftClone.connect(panLeft);
// delay left by 50 ms
var delay = context.createDelay(100);
panLeft.connect(delay);
// pan right
var panRight = context.createStereoPanner();
panRight.pan.value = 1;
leftClone.connect(panRight);
// merge
var merger = context.createChannelMerger(2);
delay.connect(merger, 0, 0);
panRight.connect(merger, 0, 1);
merger.connect(this.output);
this.outputUrl = window.URL.createObjectURL(this.output.stream);
}.bind(this),1000)
}
});
</script>
</dom-module>