13 releases

Uses new Rust 2024

new 0.3.4 Jun 10, 2026
0.3.3 May 23, 2026
0.3.0 Feb 15, 2026
0.2.4 Feb 1, 2026
0.1.2 Nov 9, 2025

#1684 in Algorithms

Download history 246/week @ 2026-05-28 243/week @ 2026-06-04

489 downloads per month

BSD-3-Clause OR Apache-2.0

4MB
85K SLoC

Pxdct — Discrete Cosine and Sine Transform Factory

Pxdct is a high-performance DCT/DST library for Rust supporting arbitrary transform lengths, not just powers of 2.

Why Pxdct

Most DCT libraries require power-of-2 window sizes. Pxdct efficiently handles any length by automatically selecting the best algorithm:

  • Split-radix for power-of-2 sizes
  • Mixed-radix decomposition for sizes with small prime factors (3, 5, 7, 11, 13…)
  • Prime Factor Algorithm (PFA) for coprime factorizations
  • Butterflies for sizes up to 512

Sizes that are products of small primes (2, 3, 5, 7, 11, 13) perform best. Large prime sizes fall back to a general FFT-based path and are still O(n log n) but slower than smooth numbers of similar magnitude.

Hardware acceleration is applied automatically where available (AVX2, NEON).

Hardware acceleration is applied automatically:

  • AVX2
  • NEON

Supported Transforms

Transform Description
DCT-I / DST-I Type 1
DCT-II / DST-II The classic DCT / DST
DCT-III / DST-III Inverse of type II
DCT-IV Used in MDCT
MDCT/IMDCT Modified cosine transform
DCT-VII / DST-VII Type 7
DCT-VIII / DST-VIII Type 8

Both f32 and f64 precision are supported.


Example

use pxdct::Pxdct;
use pxdct::PxdctExecutor;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut data = vec![1.0f32, 2.0, 3.0, 4.0];

    // Create a DCT-II executor for f32
    let dct2 = Pxdct::make_dct2_f32(data.len())?;
    dct2.execute(&mut data)?;

    println!("Transformed data: {:?}", data);
    Ok(())
}

This project is licensed under either of

  • BSD-3-Clause License (see LICENSE)
  • Apache License, Version 2.0 (see LICENSE)

at your option.

Dependencies

~10MB
~200K SLoC