npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ndarray-wav

v0.2.4

Published

Read WAV files into ndarray

Downloads

10

Readme

ndarray-wav

Read/write RIFF WAVE files as ndarrays.

Supported formats

Currently supported formats (for read and write) are:

  • 16-bit linear (CD standard)
  • 24-bit linear (CD standard)
  • 32-bit IEEE floating-point

Adding new (uncompressed) sample formats is relatively easy, though, so if you need one just raise an issue on GitHub and I'll put in.

API

Reading

var ndarrayWav = require('ndarray-wav');

ndarrayWav.open('input.wav', function (err, chunkMap, chunkArr) {
    var format = chunks.fmt;
    var ndSamples = chunks.data; // the wave data as an ndarray
    assert(format.channels == ndSamples.shape[0]);
    var numSamples = arr.shape[1];
});

Regardless of the sample format of the WAV file itself, the data is always returned as floating-point.

Writing

ndarrayWav.write('output.wav', ndSamples, format, function (error) {...});

In the write() method, format is optional. If omitted, it defaults to 44100Hz. 16-bit audio.

The structure of format is the same as chunkMap.fmt when you read:

var format = {
	sampleRate: 44100,
	format: 1, // 1 is the default "linear" format (two's complement integer), 3 is floating-point.
	bitsPerSample: 16, //
	extraChunks: {...}
};

All properties are optional.

What's all this about "chunks"?

WAV files are organised into chunks. Each is labelled with a four-character ID - the main ones are "fmt " and "data".

When reading, this ID is stripped of whitespace and placed in chunkMap (second argument in callback). Additionally, chunkArr is an array that holds the same chunks in the order they appeared in the file (where each entry has two keys "id" and "data").

There are built-in parsers for fmt and data chunks. This means that the format will always be available (parsed) as chunkMap.fmt, and the wave data is in chunkMap.data.

When writing extraChunks can contain additional chunks to write (e.g. bext). It can be an object (like chunkMap) that maps IDs to Buffers, or if order is important it can be an array (like chunkArr).

Chunk parsers

You can add parsers for particular types of chunk (e.g. bext for the broadcast-extension chunk). It works like this:

ndarrayWav.addChunkParser('bext', function (buffer) {
    return buffer.toString('ascii');
});

You can register more than one parser for a particular type of chunk. If you return something true-ish, then it stops, otherwise it continues. Parsers are tried in reverse order (most recently-registered first).

This is actually the mechanism that is used to parse the format and wave data (fmt and data).

Thanks

Thanks to Chinmay Pendharkar (notthetup) for 24-bit write support plus some other details.