(sampleRate)
| 2189 | } |
| 2190 | |
| 2191 | function dump (sampleRate) { |
| 2192 | var bufferLength = recorded.length ? recorded[0].length : 0 |
| 2193 | var length = recorded.length * bufferLength |
| 2194 | var wav = new Uint8Array(44 + length) |
| 2195 | var view = new DataView(wav.buffer) |
| 2196 | |
| 2197 | // RIFF identifier 'RIFF' |
| 2198 | view.setUint32(0, 1380533830, false) |
| 2199 | // file length minus RIFF identifier length and file description length |
| 2200 | view.setUint32(4, 36 + length, true) |
| 2201 | // RIFF type 'WAVE' |
| 2202 | view.setUint32(8, 1463899717, false) |
| 2203 | // format chunk identifier 'fmt ' |
| 2204 | view.setUint32(12, 1718449184, false) |
| 2205 | // format chunk length |
| 2206 | view.setUint32(16, 16, true) |
| 2207 | // sample format (raw) |
| 2208 | view.setUint16(20, 1, true) |
| 2209 | // channel count |
| 2210 | view.setUint16(22, 1, true) |
| 2211 | // sample rate |
| 2212 | view.setUint32(24, sampleRate, true) |
| 2213 | // byte rate (sample rate * block align) |
| 2214 | view.setUint32(28, sampleRate * BYTES_PER_SAMPLE, true) |
| 2215 | // block align (channel count * bytes per sample) |
| 2216 | view.setUint16(32, BYTES_PER_SAMPLE, true) |
| 2217 | // bits per sample |
| 2218 | view.setUint16(34, 8 * BYTES_PER_SAMPLE, true) |
| 2219 | // data chunk identifier 'data' |
| 2220 | view.setUint32(36, 1684108385, false) |
| 2221 | // data chunk length |
| 2222 | view.setUint32(40, length, true) |
| 2223 | |
| 2224 | for (var i = 0; i < recorded.length; i++) { |
| 2225 | wav.set(recorded[i], i * bufferLength + 44) |
| 2226 | } |
| 2227 | |
| 2228 | recorded = [] |
| 2229 | postMessage(wav.buffer, [wav.buffer]) |
| 2230 | } |
| 2231 | |
| 2232 | onmessage = function (e) { |
| 2233 | if (e.data[0] === 'encode') { |
no test coverage detected