-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
77 lines (56 loc) · 1.64 KB
/
test.js
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
/**
* Return arraybuffer with lena.wav
*
* @module audio-lena
*/
'use strict';
//build script
// var request = new XMLHttpRequest();
// request.open( 'GET', './lena.mp3', true );
// request.responseType = 'arraybuffer';
// document.body.style.wordBreak = 'break-all';
// request.onload = function() {
// let buf = request.response;
// let bytes = new Uint8Array(buf);
// let binary = '';
// let len = bytes.byteLength;
// for (var i = 0; i < len; i++) {
// binary += String.fromCharCode( bytes[ i ] );
// }
// document.body.innerHTML = window.btoa( binary );
// }
// request.send();
//test sound
// let lena = require('./');
// context.decodeAudioData(lena, (buffer) => {
// source = context.createBufferSource();
// source.buffer = buffer;
// source.connect(context.destination);
// source.loop = true;
// source.start();
// });
if (typeof document !== 'undefined') {
const context = new AudioContext();
//open raw samples data
let lenaBuf = require('./raw');
let lenaSamples = new Float32Array(lenaBuf)
let buffer = context.createBuffer(1, lenaSamples.length, 44100)
buffer.getChannelData(0).set(lenaSamples)
let source = context.createBufferSource();
source.buffer = buffer;
source.connect(context.destination);
source.loop = false;
source.start();
setTimeout(() => source.stop(), 500)
//ogg-datauri
var ogg = require('./')({format: 'ogg', type: 'data-uri'})
var audio = new Audio()
audio.addEventListener('canplay', () => {
console.log("Can play!")
audio.play()
setTimeout(() => audio.pause(), 500)
})
audio.src = ogg
//raw-datauri is not audio
// var raw = require('./raw-datauri')
}