Debian Codegraph @

webaudio/exampleOptions.html

raw
1 <!DOCTYPE html>
2 <html xmlns="http://www.w3.org/1999/xhtml" lang="en">
3 <head>
4 <meta charset="utf-8" />
5 <meta name="viewport" content="width=device-width, initial-scale=1" />
6
7 <title>LibMikMod Web Audio Example (with options)</title>
8
9 <style type="text/css">
10 body {
11 font-family: sans-serif;
12 }
13 </style>
14 </head>
15 <body>
16 <noscript>Sorry! You need to enable JavaScript in order to run the example :(</noscript>
17
18 <h1>
19 LibMikMod Web Audio Example (with options)
20 </h1>
21
22 <h2>
23 Load Options <small>(can only be changed when (re)loading a module)</small>
24 </h2>
25
26 <p>
27 <label>
28 <input type="checkbox" id="inputHqMixer" checked />
29 Use high-quality (slower) software mixer
30 </label>
31 </p>
32
33 <p>
34 <label>
35 <input type="checkbox" id="inputWrap" />
36 Wrap module
37 </label>
38 </p>
39
40 <p>
41 <label>
42 <input type="checkbox" id="inputLoop" />
43 Allow module to loop
44 </label>
45 </p>
46
47 <p>
48 <label>
49 <input type="checkbox" id="inputFadeout" checked />
50 Volume fade out during last pattern
51 </label>
52 </p>
53
54 <h2>
55 General Options
56 </h2>
57
58 <p>
59 <label for="inputReverb">Reverb (0 to 15)</label>
60 <br />
61 <input id="inputReverb" type="number" min="0" max="15" value="0" />
62 </p>
63
64 <p>
65 <label>
66 <input type="checkbox" id="inputInterpolation" checked />
67 Interpolation
68 </label>
69 </p>
70
71 <p>
72 <label>
73 <input type="checkbox" id="inputNoiseReduction" checked />
74 Noise reduction
75 </label>
76 </p>
77
78 <h2>
79 Module File
80 </h2>
81
82 <p>
83 <label for="inputModuleFile">Module file (669, amf, asy, dsm, far, gdm, gt2, imf, it, m15, med, mod, mtm, okt, s3m, stm, stx, ult, umx, uni, xm)</label>
84 <br />
85 <input type="file" id="inputModuleFile" accept=".669,.amf,.asy,.dsm,.far,.gdm,.gt2,.imf,.it,.m15,.med,.mod,.mtm,.okt,.s3m,.stm,.stx,.ult,.umx,.uni,.xm" />
86 </p>
87
88 <h2>
89 Commands
90 </h2>
91
92 <p>
93 <button type="button" onclick="load()" id="buttonLoad" disabled>(Re)Load module file</button>
94 <button type="button" onclick="changeGeneralOptions()" id="buttonChangeGeneralOptions" disabled>Change general options</button>
95 </p>
96
97 <p>
98 <button type="button" onclick="play()" id="buttonPlay" disabled>Play</button>
99 <button type="button" onclick="pause()" id="buttonPause" disabled>Pause</button>
100 </p>
101
102 <h2>
103 Song information
104 </h2>
105
106 <pre id="songInfo"></pre>
107
108 <h2>
109 More information
110 </h2>
111
112 <pre id="versionInfo"></pre>
113
114 <ul>
115 <li>
116 <a target="_blank" href="https://github.com/sezero/mikmod">https://github.com/sezero/mikmod</a>
117 </li>
118 <li>
119 <a target="_blank" href="https://github.com/carlosrafaelgn/mikmod/tree/master/libmikmod/webaudio">https://github.com/carlosrafaelgn/mikmod/tree/master/libmikmod/webaudio</a>
120 </li>
121 </ul>
122
123 <script type="text/javascript" src="dist/libmikmod.min.js"></script>
124 <script type="text/javascript">
125 //<![CDATA[
126 "use strict";
127
128 // According to Can I Use, we can assume that if a browser supports AudioWorkletNode it
129 // also supports WebAssembly (but not the other way around).
130 // Promises, ES6 and all other dependencies are also present in a browser which
131 // supports these two features:
132 // https://caniuse.com/wasm
133 // https://caniuse.com/mdn-api_audioworkletnode
134 if (!LibMikMod.isSupported())
135 alert("Sorry, but your browser does not meet the minimum requirements :(");
136
137 var inputReverb = document.getElementById("inputReverb"),
138 inputInterpolation = document.getElementById("inputInterpolation"),
139 inputNoiseReduction = document.getElementById("inputNoiseReduction"),
140 inputHqMixer = document.getElementById("inputHqMixer"),
141 inputWrap = document.getElementById("inputWrap"),
142 inputLoop = document.getElementById("inputLoop"),
143 inputFadeout = document.getElementById("inputFadeout"),
144 inputModuleFile = document.getElementById("inputModuleFile"),
145 buttonChangeGeneralOptions = document.getElementById("buttonChangeGeneralOptions"),
146 buttonPlay = document.getElementById("buttonPlay"),
147 buttonPause = document.getElementById("buttonPause"),
148 songInfo = document.getElementById("songInfo"),
149 fileLoaded = false,
150 audioNode = null,
151 audioContext = new AudioContext();
152
153 audioContext.suspend();
154
155 if (LibMikMod.isSupported())
156 LibMikMod.init(audioContext, "dist/").then(function () {
157 document.getElementById("versionInfo").textContent = "WEB_VERSION: " + LibMikMod.WEB_VERSION + "\nLIB_VERSION: " + LibMikMod.LIB_VERSION;
158 document.getElementById("buttonLoad").removeAttribute("disabled");
159 }, function (reason) {
160 alert("Error loading LibMikMod: " + reason);
161 });
162
163 function cleanUp() {
164 songInfo.textContent = "";
165 buttonChangeGeneralOptions.setAttribute("disabled", "disabled");
166 buttonPlay.setAttribute("disabled", "disabled");
167 buttonPause.setAttribute("disabled", "disabled");
168 fileLoaded = false;
169 audioContext.suspend();
170 if (audioNode)
171 audioNode.disconnect();
172 }
173
174 function load() {
175 if (!LibMikMod.initialized)
176 return;
177
178 if (!inputModuleFile.files || !inputModuleFile.files.length) {
179 alert("Please, select a file first");
180 return;
181 }
182
183 cleanUp();
184
185 LibMikMod.loadModule({
186 audioContext: audioContext,
187 source: inputModuleFile.files[0],
188 onload: moduleOnload,
189 onerror: moduleOnerror,
190 onended: moduleOnended,
191
192 hqMixer: inputHqMixer.checked,
193 wrap: inputWrap.checked,
194 loop: inputLoop.checked,
195 fadeout: inputFadeout.checked,
196
197 reverb: parseInt(inputReverb.value),
198 interpolation: inputInterpolation.checked,
199 noiseReduction: inputNoiseReduction.checked
200 });
201 }
202
203 function changeGeneralOptions() {
204 LibMikMod.changeGeneralOptions({
205 reverb: parseInt(inputReverb.value),
206 interpolation: inputInterpolation.checked,
207 noiseReduction: inputNoiseReduction.checked
208 });
209 }
210
211 function play() {
212 if (fileLoaded)
213 audioContext.resume();
214 }
215
216 function pause() {
217 if (fileLoaded)
218 audioContext.suspend();
219 }
220
221 function moduleOnload(newAudioNode) {
222 songInfo.textContent =
223 "Song name: " + LibMikMod.infoSongName + "\n" +
224 "Module type: " + LibMikMod.infoModType + "\n" +
225 "Comment: " + LibMikMod.infoComment
226 ;
227
228 newAudioNode.connect(audioContext.destination);
229 audioNode = newAudioNode;
230 buttonChangeGeneralOptions.removeAttribute("disabled");
231 buttonPlay.removeAttribute("disabled");
232 buttonPause.removeAttribute("disabled");
233 fileLoaded = true;
234 audioContext.resume();
235 }
236
237 function moduleOnerror(errorCode, reason) {
238 songInfo.textContent = "";
239
240 switch (errorCode) {
241 case LibMikMod.ERROR_FILE_READ:
242 alert("Error reading the file: " + reason);
243 break;
244
245 case LibMikMod.ERROR_MODULE_LOAD:
246 alert("Error loading the module: " + reason);
247 break;
248
249 //case LibMikMod.ERROR_PLAYBACK:
250 default:
251 alert("Error during module playback: " + reason);
252 break;
253 }
254 }
255
256 function moduleOnended() {
257 cleanUp();
258 alert("Playback ended!");
259 }
260
261 //]]>
262 </script>
263 </body>
264 </html>