-
Notifications
You must be signed in to change notification settings - Fork 1
/
music.html
204 lines (195 loc) · 14.6 KB
/
music.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
<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript" src="wavdata.js"></script>
<script type="text/javascript" src="magic.js"></script>
<link type="text/css" href="style.css" rel="stylesheet"/>
</head>
<body>
<br/>
<form onsubmit="return false;">
<table class="centered_table">
<tr>
<td class="rightaligned">Left</td>
<td><input type="text" id="oneliner" value="t * ((t>>12|t>>8)&63&t>>4)"/></td>
</tr>
<tr>
<td class="rightaligned">Right</td>
<td><input type="text" id="oneliner2" value=""/></td>
</tr>
</table>
<table class="centered_table">
<tr>
<td class="rightaligned">t<sub>0</sub></td>
<td><input type="text" id="t0" value="0"/> (start value of sequence)</td>
<td rowspan="3">
Sample rate<br/>
<input type="radio" name="samplerate" value="44100"/>44,100<br/>
<input type="radio" name="samplerate" value="22050"/>22,050<br/>
<input type="radio" name="samplerate" value="11025"/>11,025<br/>
<input type="radio" name="samplerate" value="8000" checked/>8,000
</td>
</tr>
<tr>
<td class="rightaligned">t<sub>mod</sub></td>
<td><input type="text" id="tmod" value="0"/> (% running t with this value, 0 to turn off)</td>
</tr>
<tr>
<td class="rightaligned">duration</td>
<td><input type="text" id="duration" value="30"/>seconds</td>
</tr>
<tr>
<td class="rightaligned">Stereo separation</td>
<td><input type="range" id="separation" min="0" max="100" value="100" step="5"/>%</td>
</tr>
<tr>
<td colspan="3"><input type="submit" value="Generate Sound" id="gen"/></td>
</tr>
<tr>
<td colspan="3">
<canvas id="canvas" width="1024" height="128"></canvas>
</td>
</tr>
</table>
</form>
<span id="error"></span>
<div id="player"></div>
<br/>
<table class="link_table">
<tr>
<td>
For example: (t*(t>>8+t>>9)*100)+sin(t)<br/>
Or try some from <a href="http://www.youtube.com/watch?v=GtQdIYUtAHg" target="_new">viznut's video</a> or <a
href="http://www.youtube.com/watch?v=qlrs2Vorw2Y" target="_new">viznut's other video</a>.<br/><br/>
PLEASE NOTE THAT IS MOSTLY NOT MY CREATION. I just added some stuff. <a
href="http://www.bemmu.com/music/index.html" target="_new">The original</a> is from Bemmu & viznut.
Some improvements came from mjau. Thanks!
</td>
</tr>
</table>
<br/><br/><br/>
<table class="link_table">
<tr>
<td class="rightaligned">"Perma"link</td>
<td><input type="text" id="link" value=""/> (hinthint: use this as an URL)</td>
</tr>
<tr>
<td class="rightaligned">BBcode</td>
<td><input type="text" id="bbcode" value=""/> (for them lazy ones)</td>
</tr>
</table>
<script>
function play() {
//check if oneliner one is empty, but two filled
if (document.getElementById("oneliner").value == "" && document.getElementById("oneliner2").value != "") {
//copy string over
document.getElementById("oneliner").value = document.getElementById("oneliner2").value;
document.getElementById("oneliner2").value = "";
}
//create links
document.getElementById("link").value = makeLink();
document.getElementById("bbcode").value = makeBbcode();
try {
playDataURI(makeURL());
document.getElementById('error').innerText = "";
} catch (err) {
document.getElementById('error').innerText = "" + err;
}
}
function getParams() {
var idx = document.URL.indexOf('?');
if (idx != -1) {
var tempParams = new Object();
var pairs = document.URL.substring(idx + 1, document.URL.length).split('&');
for (var i = 0; i < pairs.length; i++) {
nameVal = pairs[i].split('=');
tempParams[nameVal[0]] = nameVal[1];
}
return tempParams;
}
}
function makeLink() {
var link;
var idx = document.URL.indexOf('?');
if (idx != -1) {
link = document.URL.substring(0, idx);
}
else {
link = document.URL;
}
link += "?oneliner=" + encodeURIComponent(document.getElementById('oneliner').value);
link += "&oneliner2=" + encodeURIComponent(document.getElementById('oneliner2').value);
link += "&t0=" + document.getElementById('t0').value;
link += "&tmod=" + document.getElementById('tmod').value;
link += "&duration=" + document.getElementById('duration').value;
link += "&separation=" + document.getElementById('separation').value;
link += "&rate=" + getFrequency();
return link;
}
function makeBbcode() {
var bbcode = "[url=" + makeLink() + "]";
//do we have a stereo tune?
if (document.getElementById('oneliner2').value != "") {
bbcode += "[b]L:[/b] " + document.getElementById('oneliner').value;
bbcode += " [b]| R:[/b] " + document.getElementById('oneliner2').value;
}
else {
bbcode += document.getElementById('oneliner').value;
}
bbcode += "[/url]";
return bbcode;
}
var x = document.createElement('audio');
var hasAudio = typeof(x.play) !== 'undefined';
if (!hasAudio) {
alert("You don't seem to have a browser that supports audio. It's ok, you're not a bad person. But this app will now fail.");
}
document.getElementById("oneliner").focus();
document.getElementById("gen").onclick = function () {
play();
};
params = getParams();
if (params) {
var shouldPlay = false;
if (params["rate"]) {
if (params["rate"] >= 44100) {
document.forms[0].samplerate[0].checked = true;
}
else if (params["rate"] == 22050) {
document.forms[0].samplerate[1].checked = true;
}
else if (params["rate"] == 11025) {
document.forms[0].samplerate[2].checked = true;
}
else {
document.forms[0].samplerate[3].checked = true;
}
}
if (params["t0"]) {
document.getElementById("t0").value = params["t0"];
}
if (params["tmod"]) {
document.getElementById("tmod").value = params["tmod"];
}
if (params["duration"]) {
document.getElementById("duration").value = params["duration"];
}
if (params["separation"]) {
document.getElementById("separation").value = params["separation"];
}
if (params["oneliner"]) {
document.getElementById("oneliner").value = decodeURIComponent(params["oneliner"]);
shouldPlay = true;
}
if (params["oneliner2"]) {
document.getElementById("oneliner2").value = decodeURIComponent(params["oneliner2"]);
shouldPlay = true;
}
if (shouldPlay) {
play();
generatePreview(soundData,1);
}
}
</script>
</body>
</html>