-
Notifications
You must be signed in to change notification settings - Fork 0
/
WavPackJS.html
125 lines (83 loc) · 2.58 KB
/
WavPackJS.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
<html>
<head><title>haXe WavPack JS</title>
<script type="text/javascript" src="XAudioJS/XAudioServerMediaStreamWorker.js"></script>
<script type="text/javascript" src="XAudioJS/XAudioServer.js"></script>
<script type="text/javascript" src="XAudioJS/resampler.js"></script>
<script type="text/javascript" src="XAudioJS/swfobject.js"></script>
</head>
<body>
<article>
<b>WavPack Javascript player</b>
<br />
Use the file browser button below to select a WavPack file.
This player works on both Firefox and Chrome.
</article>
<article>
<input type="file" id="files" name="files[]" multiple />
</article>
<script>
var audioHandle = null;
var vblankEvent = null;
var gonogo = 0;
if (document.addEventListener){
document.getElementById('files').addEventListener('change', handleFileSelect, false);
} else if (document.attachEvent){
document.getElementById('files').attachEvent('change', handleFileSelect);
}
//document.getElementById('files').addEventListener('change', handleFileSelect, false);
function handleFileSelect(evt) {
var files = evt.target.files; // FileList object
// files is a FileList of File objects
this.className = '';
var file = files[0], reader = new FileReader();
reader.onload = function (event) {
audioHandle = null;
var myByteArray = new Uint8Array(reader.result);
my_wpc = JSWvDemo.setUpPlayer(myByteArray);
alert("Ready to start playing the file now");
numchannels = WavPackUtils.WavpackGetReducedChannels(my_wpc);
sampleRate = WavPackUtils.WavpackGetSampleRate(my_wpc);
//alert("sample rate is " + sampleRate);
audioHandle = new XAudioServer(numchannels, sampleRate, sampleRate >> 2, sampleRate << 1, audioCheck, 1, failureCallback);
gonogo = 1;
if (!vblankEvent) {
vblankEvent = function (dummy1) { setTimeout(VBlankSyncHandler, 20); };
vblankEvent(VBlankSyncHandler);
}
};
reader.readAsArrayBuffer(file);
return false;
};
function audioCheck(samplesRequested)
{
//console.log("generate audio");
if(samplesRequested > 0)
{
retVal = JSWvDemo.decodeWavPackData(samplesRequested);
if(retVal == 0) {
gonogo = 0;
}
var buffer = new Array();
for (var i=0; i<retVal; i++)
{
buffer[i] = JSWvDemo.floatSamples[i];
}
return buffer; //We return a buffer of the samples.
}
return [];
}
function VBlankSyncHandler() {
if(gonogo==1) {
audioHandle.executeCallback();
}
vblankEvent(VBlankSyncHandler);
}
function failureCallback ()
{
//console.log("failure");
}
</script>
<div id="haxe:trace"></div>
<script type="text/javascript" src="MyWavPack.js"></script>
</body>
</html>