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

super-tiny-wave-decoder

v0.1.3

Published

A super tiny WAVE parser and decoder, without any dependencies or unnecessary abstraction layers

Downloads

6

Readme

super-tiny-wave-decoder

npm version

A super tiny WAVE parser and decoder, without any dependencies or unnecessary abstraction layers.

Most of the logic was directly ported from parts of aurora.js, so lots of ❤️ from here to there!

Why?

Sometimes I just want to decode WAVE audio. Sometimes I even just want to parse a WAVE header. All libraries I have found have either too much other stuff I don't need, too abstraced APIs (I don't need it to make the HTTP request for me) or is specifically targeted towards either Node or the web browser.

This library is just a utility that parses WAVE headers and decodes WAVE audio. Nothing more, nothing less.

Installation

npm install --save super-tiny-wave-decoder

Usage

import { getWaveHeader, decodeWaveData } from 'super-tiny-wave-decoder'

// Read a wave file somehow
const waveContents = readAudioFileAsAnArrayBufferSomehow('sound.wav')
const waveData = new Uint8Array(waveContents)

// Get WAVE header
const header = getWaveHeader(waveData)

// Get a chunk of 4096 bytes starting after the header and
// decode that chunk
const audioDataChunk = waveData.slice(44, 44 + 4096)
const decodedAudio = decodeWaveData(audioDataChunk, header)

// decodedAudio is now a Float32Array ready to be used as an
// audio buffer

## API

Functions

getAsDataView(data) ⇒ DataView

Wraps and returns a typed array or ArrayBuffer in a DataView

Returns: DataView - A DataView wrapping the passed data
Throws:

  • TypeError The passed data needs to be of a supported type

Params

  • data: Mixed - A DataView, ArrayBuffer, TypedArray or node Buffer

getString(data, offset, bytes, encoding) ⇒ String

Returns a string read from some data.

This code is directly ported and rewritten from aurora.js's stream.coffee. I have no idea how it works! Might use a library for this if it doesn't work properly.

Returns: String - A string
Link: https://github.com/audiocogs/aurora.js/blob/master/src/core/stream.coffee#L303
Params

  • data: Mixed - A DataView, ArrayBuffer, TypedArray or node Buffer
  • offset: Number - An offset in bytes to start read the string from
  • bytes: Number - The number of bytes to read
  • encoding: String - The encoding to parse the text as

getWaveHeader(data) ⇒ Object

Parses a chunk of wave data and tries to extract all wave header info from it.

You can see an overview of the WAVE header format here: http://www.topherlee.com/software/pcm-tut-wavformat.html

Returns: Object - An object containing the WAVE header info
Throws:

  • Error The passed data needs to be at least 44 bytes long
  • Error The passed data needs to match the WAVE header spec

Params

  • data: Mixed - A DataView, ArrayBuffer, TypedArray or node Buffer containing WAVE audio data, more specifically the beginning of a WAVE audio file

getWaveDuration(header) ⇒ Number

Returns the duration of some wave audio given its header info

Returns: Number - The duration of the WAVE audio in seconds
Params

  • header: Object - A WAVE header object

decodeWaveData(header, data) ⇒ Float32Array

Decodes a chunk of wave audio data

Returns: Float32Array - A Float32Array containing decoded audio
Throws:

  • Error The bit depth passed in header must be 8, 16, 24, 32 or 64

Params

  • header: Object - A WAVE header object
  • data: Mixed - A DataView, ArrayBuffer, TypedArray or node Buffer containing WAVE audio data

Contributing

Do npm run to see what's available, and don't be shy sending a pull request!