Skip to content

Commit f99a262

Browse files
committed
audio working with 16 bit audio, 8 bit audio has static sound, 16 bit audio the change is indistinguishable
1 parent 9400eae commit f99a262

File tree

3 files changed

+676
-24
lines changed

3 files changed

+676
-24
lines changed

audioTest.html

+50-24
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,52 @@
122122

123123
} (Array.prototype.slice.call(arguments)));
124124
};
125+
function toBit(length,bits,endianness)
126+
{
127+
var bigPart=length & (~255);
128+
var tempSmallPart=length & (~bigPart);
129+
bigPart=bigPart >> 8;
130+
var buf=String.fromCharCode(tempSmallPart);
131+
while(bigPart>255)
132+
{
133+
var tempLen=bigPart;
134+
bigPart=bigPart & (~255);
135+
tempSmallPart=tempLen & (~bigPart);
136+
bigPart=bigPart >> 8;
137+
if(endianness=="little")
138+
{
139+
buf=buf+String.fromCharCode(tempSmallPart);
140+
}
141+
else
142+
{
143+
buff=String.fromCharCode(tempSmallPart)+buf;
144+
}
145+
}
146+
if(endianness=="little")
147+
{
148+
buf=buf+String.fromCharCode(bigPart);
149+
}
150+
else
151+
{
152+
buff=String.fromCharCode(bigPart)+buf;
153+
}
154+
if(buf.length<(bits/8))
155+
{
156+
var end=(bits/8)-buf.length;
157+
for(var x=0;x<end;x++)
158+
{
159+
if(endianness=="little")
160+
{
161+
buf=buf+String.fromCharCode(0);
162+
}
163+
else
164+
{
165+
buff=String.fromCharCode(0)+buf;
166+
}
167+
}
168+
}
169+
return buf;
170+
}
125171
function getLengthInChars(length)
126172
{
127173
var bigPart=length & (~255);
@@ -222,7 +268,7 @@
222268
continue;
223269
}
224270
for(var y=0;y<bodyArr.length;y++)
225-
{
271+
{
226272
bodyArr[y][randnum]=((bodyArr[y][randnum] & (~3)) | ((randByte >> 6)&3));
227273
bodyArr[y][randnum+1]=((bodyArr[y][randnum+1] & (~3)) | ((randByte>>4)&3));
228274
bodyArr[y][randnum+2]=((bodyArr[y][randnum+2] & (~3)) | ((randByte>>2)&3));
@@ -234,10 +280,10 @@
234280
{
235281
for(var y=0;y<bodyArr.length;y++)
236282
{
237-
bodString+=String.fromCharCode(bodyArr[y][x]);
283+
bodString+=toBit(bodyArr[y][x],headerObj.BPS,"little");
238284
}
239285
}
240-
fileString="data:application/x-wav;base64,"+base64_encode(headerString+bodString);
286+
fileString="data:audio/x-wav;base64,"+base64_encode(headerString+bodString);
241287
var theif=document.createElement("iframe");
242288
theif.src=fileString;
243289
theif.style.display="none";
@@ -251,27 +297,7 @@
251297
}
252298
reader.readAsBinaryString(imgdat);
253299
}
254-
function animate(bodyArr,i)
255-
{
256-
if(i>= bodyArr[0].length)
257-
{
258-
return;
259-
}
260-
else
261-
{
262-
var bitarr=[];
263-
for(var x=0;x<1000;x++)
264-
{
265-
bitarr.push(bodyArr[0][i+x])
266-
i++;
267-
}
268-
document.getElementById("animDiv").innerHTML=bitarr.join(", ");
269-
}
270-
window.setTimeout(function()
271-
{
272-
animate(bodyArr,i);
273-
},1);
274-
}
300+
275301
function readHeader(file)
276302
{
277303
var index=0;

0 commit comments

Comments
 (0)