GithubHelp home page GithubHelp logo

pcm-convert's Introduction

pcm-convert unstable Build Status Greenkeeper badge

Convert data from one pcm-format to another.

Usage

npm install pcm-convert

const convert = require('pcm-convert')

//convert data from float32 to uint8 array
let uint8arr = convert([0, 0.1, 0.1, 0], 'float32', 'uint8')

//convert interleaved uint8 to planar float32 array
let float32arr = convert(new Uint8Array([127, 200, 127, 200]), 'uint8 stereo interleaved', 'float32 planar')

//deinterleave keeping the same data type
let int8arr = convert(new Int8Array([-100,100,-100,100]), 'interleaved', 'planar')

//change endianness keeping the same data type
let float32be = convert(new Float32Array([1,.5,-.5,-1]), 'le', 'be')

//use objects as formats
let float64 = convert(float32be, {
	dtype: 'float32',
	channels: 2,
	interleaved: false,
	endianness: 'be'
}, {
	dtype: 'float64',
	interleaved: true,
	endianness: 'le'
})

//skip source format string, convert directly to data format
let uint16 = convert(new Uint8Array([0,255]), 'uint16')

//put data into target container skipping format strings
convert(new Uint8Array([0,255]), new Uint16Array(2))

//full arguments case
let uint16arr = convert([0, 0, 1, 1], 'float32 le stereo planar', 'uint16 interleaved be', new Uint16Array(4))

API

convert(src, srcFormat?, dstFormat?, dst?)

Takes data in src container and converts from srcFormat to dstFormat. Format can be whether a string with tags or an object with properties, see audio-format module. If srcFormat is skipped, it is detected from src. Optionally a destination container can be provided as dst, and in case if dstFormat is skipped, it will be detected from dst.

Source

Source format is inferred from src data type and extended with srcFormat properties. By default source is considered planar mono le. Source data types:

Type Dtype
Array float32
Float32Array float32
Float64Array float64
ArrayBuffer uint8
Buffer uint8
Uint8Array uint8
Uint8ClampedArray uint8
Uint16Array uint16
Uint32Array uint32
Int8Array int8
Int16Array int16
Int32Array int32

Format

Can be defined as dtype string with tags, eg. 'uint8 interleaved mono le', 'float64 planar quad' (some tags can be skipped), or an object with the following properties:

Property Meaning
dtype Data type string: uint8, uint16, uint32, int8, int16, int32, float32, float64, array (only dstFormat), arraybuffer (only dstFormat).
interleaved Boolean indicating if data has interleaved or planar layout.
channels Number of channels in source: mono, stereo, quad, 5.1.
endianness be or le, defaults to OS endianness.

Related

License

© 2017 Dima Yv. MIT License

pcm-convert's People

Contributors

dy avatar blainekasten avatar jamen avatar greenkeeper[bot] avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.