MCPcopy Create free account
hub / github.com/Vanilagy/webcodecs-polyfill / getWriteFunction

Function getWriteFunction

src/audio_data.ts:396–414  ·  view source on GitHub ↗
(format: AudioSampleFormat)

Source from the content-addressed store, hash-verified

394};
395
396const getWriteFunction = (format: AudioSampleFormat): (view: DataView, offset: number, value: number) => void => {
397 switch (format) {
398 case 'u8':
399 case 'u8-planar':
400 return (view, offset, value) =>
401 view.setUint8(offset, clamp((value + 1) * 127.5, 0, 255));
402 case 's16':
403 case 's16-planar':
404 return (view, offset, value) =>
405 view.setInt16(offset, clamp(Math.round(value * 32767), -32768, 32767), true);
406 case 's32':
407 case 's32-planar':
408 return (view, offset, value) =>
409 view.setInt32(offset, clamp(Math.round(value * 2147483647), -2147483648, 2147483647), true);
410 case 'f32':
411 case 'f32-planar':
412 return (view, offset, value) => view.setFloat32(offset, value, true);
413 }
414};

Callers 1

copyToMethod · 0.85

Calls 1

clampFunction · 0.85

Tested by

no test coverage detected