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 🙏

© 2026 – Pkg Stats / Ryan Hefner

lanczos-resampler

v0.2.2

Published

Audio resampler for Rust/JS that uses Lanczos filter.

Readme

Lanczos resampler

crates.io docs.rs npmjs.com JS docs

An audio resampler that uses Lanczos filter as an alternative to traditional windowed sinc filters. The main advantage of such approach is small number of coefficients required to store the filter state; this results in small memory footprint and high performance.

Features

Small memory footprint

The library doesn't use memory allocation by default, and resampler's internal state occupies less than a hundred bytes.

High performance

Thanks to small kernel size the processing time of a typical audio chunk is very fast (below 100 μs on a typical laptop).

Robustness

When you're resampling from N Hz to M Hz, for each N input samples you will get exactly M output samples[^1]. This results in predictable audio stream playback and simplifies time synchronization between different streams (e.g. video and audio).

[^1]: Seriously, why other libraries don't have this feature?

JS-compatible

This library can be used in web browsers and in general in any JS engine that supports WASM. All of the abovementioned features are inherent to both Rust and WASM versions of the library.

Usage

Kernel parameters

This library uses Lanczos kernel approximated by 2N - 1 points and defined on interval [-A; A]. The kernel is interpolated using cubic Hermite splines with second-order finite differences at spline endpoints. The output is clamped to [-1; 1].

The recommended parameters are N = 16, A = 3. Using A = 2 might improve performance a little bit. Using larger N will techincally improve precision, but precision isn't a good metric for audio signal. With N = 16 the kernel fits into exactly 64 B (the size of a cache line).

Interleaved vs. non-interleaved format

Non-interleaved format means that audio samples for each channel are stored in separate arrays. To resample such data you need to call resample for each channel individually.

Interleaved format on the other hand means that samples for each channel are stored in a single array using frames; a frame is a sequence of samples, one sample for each channel. To resample such data you need to call resample only once.

Usually resampling interleaved data is much faster than processing each channel individually because a CPU can process such data efficiently with SIMD instructions.

Rust

Resampling audio stream in chunks

use lanczos_resampler::ChunkedResampler;

let n = 1024;
let chunk = vec![0.1; n];
let mut resampler = ChunkedResampler::new(44100, 48000);
let mut output: Vec<f32> = Vec::with_capacity(resampler.max_num_output_frames(n));
let num_processed = resampler.resample(&chunk[..], &mut output);
assert_eq!(n, num_processed);

Resampling the whole audio track

use lanczos_resampler::WholeResampler;

let n = 1024;
let track = vec![0.1; n];
let output_len = lanczos_resampler::num_output_frames(n, 44100, 48000);
let mut output = vec![0.0; output_len];
let resampler = WholeResampler::new();
let mut output_slice = &mut output[..];
let num_processed = resampler.resample_into(&track[..], &mut output_slice);
assert_eq!(n, num_processed);
assert!(output_slice.is_empty());

JS

Installation

npm install lanczos-resampler

Resampling audio stream in chunks

import { ChunkedResampler } from 'lanczos-resampler';

const resampler = new ChunkedResampler(44100, 48000);
const input = new Float32Array(1024);
input.fill(0.1);
const output = new Float32Array(resampler.maxNumOutputFrames(input.length));
const { numRead, numWritten } = resampler.resample(input, output);
assert.equal(input.length, numRead);

Resampling the whole audio track

import { WholeResampler, numOutputFrames } as lanczos from 'lanczos-resampler';

const input = new Float32Array(1024);
input.fill(0.1);
const outputLen = numOutputFrames(1024, 44100, 48000);
const output = new Float32Array(outputLen);
const resampler = new WholeResampler();
const { numRead, numWritten } = resampler.resampleInto(input, output);
assert.equal(input.length, numRead);
console.log(output)

Documentation

Rust: https://docs.rs/lanczos-resampler/latest/lanczos_resampler/

JS: https://igankevich.github.io/lanczos-resampler

No-std support

This crate supports no_std via libm. When std feature is enabled (the default), it uses built-in mathematical functions which are typically much faster than libm.