Crate dtmf_table

Crate dtmf_table 

Source
Expand description

§DTMF Table

A zero-heap, no_std, const-first implementation of the standard DTMF keypad frequencies with ergonomic runtime helpers for real-world audio decoding.

§Features

  • Type-safe closed enum for DTMF keys — invalid keys are unrepresentable.
  • Fully const forward and reverse mappings (key ↔ frequencies).
  • Runtime helpers for tolerance-based reverse lookup and nearest snapping.
  • No heap, no allocations, no dependencies.

§Example

use dtmf_table::{DtmfTable, DtmfKey};

// Construct a zero-sized table instance
let table = DtmfTable::new();

// Forward lookup from key to canonical frequencies
let (low, high) = DtmfTable::lookup_key(DtmfKey::K8);
assert_eq!((low, high), (852, 1336));

// Reverse lookup with tolerance (e.g. from FFT bin centres)
let key = table.from_pair_tol_f64(770.2, 1335.6, 6.0).unwrap();
assert_eq!(key.to_char(), '5');

// Nearest snapping for noisy estimates
let (k, snapped_low, snapped_high) = table.nearest_u32(768, 1342);
assert_eq!(k.to_char(), '5');
assert_eq!((snapped_low, snapped_high), (770, 1336));

This makes it easy to integrate DTMF tone detection directly into audio processing pipelines (e.g., FFT bin peak picking) with robust tolerance handling and compile-time validation of key mappings.

Structs§

DtmfTable
Zero-sized table wrapper for const and runtime utilities.
DtmfTone
Tone record (ties the key to its canonical freqs).

Enums§

DtmfKey
Type-safe, closed set of DTMF keys.