MCPcopy
hub / github.com/mattdiamond/Recorderjs / encodeWAV

Function encodeWAV

lib/recorder.js:170–204  ·  view source on GitHub ↗
(samples)

Source from the content-addressed store, hash-verified

168 }
169
170 function encodeWAV(samples) {
171 var buffer = new ArrayBuffer(44 + samples.length * 2);
172 var view = new DataView(buffer);
173
174 /* RIFF identifier */
175 writeString(view, 0, 'RIFF');
176 /* RIFF chunk length */
177 view.setUint32(4, 36 + samples.length * 2, true);
178 /* RIFF type */
179 writeString(view, 8, 'WAVE');
180 /* format chunk identifier */
181 writeString(view, 12, 'fmt ');
182 /* format chunk length */
183 view.setUint32(16, 16, true);
184 /* sample format (raw) */
185 view.setUint16(20, 1, true);
186 /* channel count */
187 view.setUint16(22, numChannels, true);
188 /* sample rate */
189 view.setUint32(24, sampleRate, true);
190 /* byte rate (sample rate * block align) */
191 view.setUint32(28, sampleRate * 4, true);
192 /* block align (channel count * bytes per sample) */
193 view.setUint16(32, numChannels * 2, true);
194 /* bits per sample */
195 view.setUint16(34, 16, true);
196 /* data chunk identifier */
197 writeString(view, 36, 'data');
198 /* data chunk length */
199 view.setUint32(40, samples.length * 2, true);
200
201 floatTo16BitPCM(view, 44, samples);
202
203 return view;
204 }
205 }, self);
206
207 this.worker.postMessage({

Callers 2

exportWAVFunction · 0.85
exportWAVMethod · 0.85

Calls 2

writeStringFunction · 0.85
floatTo16BitPCMFunction · 0.85

Tested by

no test coverage detected