Skip to content

suldashi/pcm-f32-to-i16

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

pcm-f32-to-i16

This module provides a Transform (read/write) stream for converting headerless PCM files from 32-bit Floating point format (-1.0 to 1.0) into 16-bit signed integer (-32768 to 32767). The incoming stream should be little-endian, and the outgoing stream is little-endian as well.

The purpose of this package is to act as a intermediate step for libraries that don't accept float PCM data, such as node-opus.

Installation

pcm-f32-to-i16 has no dependencies other than the native Node stream.Transform.

Simply install pcm-f32-to-i16 using npm:

$ npm install pcm-f32-to-i16

Example

Here's an example of using the PCMf32toi16 class, in which we pipe the stream from a raw 32-bit float PCM file. This stream is converted piece by piece into a raw 16-bit signed integer PCM file.

let fs = require("fs");
let PCMf32toi16 = require("pcm-f32-to-i16");

let inputFile = fs.createReadStream("sine.raw");
let outputFile = fs.createWriteStream("sineint.raw");
let floatToInt = new PCMf32toi16();
inputFile.pipe(floatToInt).pipe(outputFile);

If you examine the waveforms of both files using a program such as Audacity, the differences will be imperceptibly small.

License: MIT

About

A Node.js Transform stream that converts a raw PCM input from Float32(-1.0 to 1.0) into Int16(-32768 to 32767).

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published