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

@echogarden/wave-codec

v0.2.1

Published

A fully-featured WAVE format encoder and decoder. Written in pure TypeScript.

Downloads

312

Readme

WAVE encoder and decoder

Fully-featured encoder and decoder for the standard WAVE format.

  • Written in pure TypeScript
  • Supports all sample formats and bit-depths included in the core WAVE standard, including GUID-based sub-formats for PCM and Float sample formats, and the 8-bit A-law and Mu-law codecs
  • Ignores unsupported or unknown sub-chunks like LIST, fact, plst and junk
  • Supports reading and writing WAVE buffers larger than 4 GiB, by interpreting a chunk of length 2^32 - 1 to extend up to the end of the buffer (even if it's much larger). This is compatible with FFMpeg's input and output approach for long or streaming WAVE data
  • Runs on Node.js, Deno, Bun, browsers
  • No dependencies

Installation

npm install @echogarden/wave-codec

Basic usage

Encodes and decodes raw audio data given as a channel array of 32-bit float samples:

import { encodeWaveFromFloat32Channels, decodeWaveToFloat32Channels } from '@echogarden/wave-codec'

// A stereo pair with a few silent samples
const float32Channels = [
	new Float32Array([0, 0, 0, 0]),
	new Float32Array([0, 0, 0, 0]),
]

const waveData = encodeWaveFromFloat32Channels(float32Channels, 44100)

const decodedChannels = decodeWaveToFloat32Channels(waveData)

Encoding and decoding to and from a raw data buffer

The data is given as a Uin8Array, and may contain any sample format supported by the WAVE standard, like 8-bit 16-bit, 24-bit, 32-bit integer raw integer PCM, 32-bit or 64-bit float, Alaw or Mulaw. Multiple channels should be interleaved.

import { encodeWaveFromDataBuffer, decodeWaveToDataBuffer, SampleFormat } from '@echogarden/wave-codec'

const audioBuffer = new Uint8Array([0, 0, 0, 0])

const waveData = encodeWaveFromBuffer(
	audioBuffer, // Audio data
	44100, // Sample rate
	1, // Channel count
	16, // Bit depth, can be 8, 16, 24, or 32 for PCM, 32 or 64 for Float, 8 for Alaw and Mulaw
	SampleFormat.PCM, // Sample format, can be PCM, Float, Alaw or Mulaw
	0 // Speaker position mask (used for multichannel audio)
)

const {	decodedAudioBuffer,
		sampleRate,
		channelCount,
		bitDepth,
		sampleFormat,
		speakerPositionMask } = decodeWaveToBuffer(waveData)

Converting between 32-bit float channels and data buffers

These methods are used internally to convert any supported sample format to and from 32-bit float channels, and are exposed as utility methods.

32-bit float channel array -> audio data buffer:

float32ChannelsToBuffer(
	audioChannels: Float32Array[],
	targetBitDepth: BitDepth = 16,
	targetSampleFormat: SampleFormat = SampleFormat.PCM): Uint8Array

Audio data buffer -> 32-bit float channel array:

bufferToFloat32Channels(
	audioBuffer: Uint8Array,
	channelCount: number,
	sourceBitDepth: BitDepth,
	sourceSampleFormat: SampleFormat): Float32Array[]

License

MIT