Change the bit depth of PCM samples.
npm install bitdepth
npm install bitdepth
`
Use
$3
`javascript
const changeBitDepth = require("bitdepth").changeBitDepth;
// The params, in order:
// - the original sample array
// - the original bit depth
// - the output array for the new samples
// - the target bit depth
changeBitDepth(originalArray, "32f", outputArray, "16");
`
The outputArray must be a typed array.
Browser
Use the bitdepth.js file in the /dist folder:
`html
`
Or get it from the jsDelivr CDN:
`html
`
Or get it from unpkg:
`html
`
Bit depth codes
The params informing the original and target bit depths are strings representing the bit depth code. Their values can be:
- A string representing any integer from "8" to "53" (integer samples)
- "32f" for 32 bit floating-point
- "64" for 64 bit floating-point
Range of the samples
This lib is inteded to be used with PCM data. Note that:
- 8-bit samples range from 0 to 255 (unsigned)
- Other integers are all signed
- 32 fp and 64 range from -1 to 1
Dithering
This lib does not apply any dither to the samples.
API
`javascript
/**
* Change the bit depth of PCM samples.
* @param {!Array|!TypedArray} samples The original samples.
* @param {string} bithDepth The original bit depth.
* @param {!TypedArray} newSamples The output array.
* @param {string} targetBitDepth The target bit depth.
* @throws {Error} If original or target bit depths are not valid.
*/
function changeBitDepth(samples, bithDepth, newSamples, targetBitDepth) {};
``