Mercurial > hg > webaudioevaluationtool
comparison js/WAVE.js @ 2683:15104a43089d
More cleanups for #180
author | Nicholas Jillings <nicholas.jillings@mail.bcu.ac.uk> |
---|---|
date | Wed, 01 Mar 2017 17:10:24 +0000 |
parents | 464c6c6692d6 |
children |
comparison
equal
deleted
inserted
replaced
2682:0a72855de078 | 2683:15104a43089d |
---|---|
1 // Decode and perform WAVE file byte level manipulation | 1 // Decode and perform WAVE file byte level manipulation |
2 /*globals console, Uint8Array, Float32Array, Float64Array */ | |
2 | 3 |
3 find_subarray = function (arr, subarr) { | 4 function find_subarray(arr, subarr) { |
4 var arr_length = arr.length; | 5 var arr_length = arr.length; |
5 var subarr_length = subarr.length; | 6 var subarr_length = subarr.length; |
6 var last_check_index = arr_length - subarr_length; | 7 var last_check_index = arr_length - subarr_length; |
7 | 8 |
8 positionLoop: | 9 positionLoop: |
13 } | 14 } |
14 } | 15 } |
15 return i; | 16 return i; |
16 } | 17 } |
17 return -1; | 18 return -1; |
18 }; | 19 } |
19 | 20 |
20 function convertToInteger(arr) { | 21 function convertToInteger(arr) { |
21 var value = 0; | 22 var value = 0; |
22 for (var i = 0; i < arr.length; i++) { | 23 for (var i = 0; i < arr.length; i++) { |
23 value += arr[i] << (i * 8); | 24 value += arr[i] << (i * 8); |
33 return str; | 34 return str; |
34 } | 35 } |
35 | 36 |
36 function WAVE() { | 37 function WAVE() { |
37 // The WAVE file object | 38 // The WAVE file object |
38 this.status == 'WAVE_DECLARED' | 39 this.status = 'WAVE_DECLARED'; |
39 | 40 |
40 this.decoded_data = null; | 41 this.decoded_data = null; |
41 | 42 |
42 this.RIFF = String(); //ChunkID | 43 this.RIFF = String(); //ChunkID |
43 this.size; //ChunkSize | 44 this.size = undefined; //ChunkSize |
44 this.FT_Header; //Format | 45 this.FT_Header = undefined; //Format |
45 this.fmt_marker; //Subchunk1ID | 46 this.fmt_marker = undefined; //Subchunk1ID |
46 this.formatDataLength; //Subchunk1Size | 47 this.formatDataLength = undefined; //Subchunk1Size |
47 this.type; //AudioFormat | 48 this.type = undefined; //AudioFormat |
48 this.num_channels; //NumChannels | 49 this.num_channels = undefined; //NumChannels |
49 this.sample_rate; //SampleRate | 50 this.sample_rate = undefined; //SampleRate |
50 this.byte_rate; //ByteRate | 51 this.byte_rate = undefined; //ByteRate |
51 this.block_align; //BlockAlign | 52 this.block_align = undefined; //BlockAlign |
52 this.bits_per_sample; //BitsPerSample | 53 this.bits_per_sample = undefined; //BitsPerSample |
53 this.data_header; //Subchunk2ID | 54 this.data_header = undefined; //Subchunk2ID |
54 this.data_size; //Subchunk2Size | 55 this.data_size = undefined; //Subchunk2Size |
55 this.num_samples; | 56 this.num_samples = undefined; |
56 | 57 |
57 this.open = function (IOArrayBuffer) { | 58 this.open = function (IOArrayBuffer) { |
58 var IOView8 = new Uint8Array(IOArrayBuffer); | 59 var IOView8 = new Uint8Array(IOArrayBuffer); |
59 this.RIFF = convertToString(IOView8.subarray(0, 4)); | 60 this.RIFF = convertToString(IOView8.subarray(0, 4)); |
60 if (this.RIFF != 'RIFF') { | 61 if (this.RIFF != 'RIFF') { |