DTMF Table
A zero-heap, no_std friendly, const-first implementation of the standard DTMF (Dual-Tone Multi-Frequency) keypad used in telephony systems.
This crate provides compile-time safe mappings between keypad keys and their canonical low/high frequencies, along with runtime helpers for practical audio processing.
Features
- Const-evaluated forward and reverse mappings between DTMF keys and frequencies
- Closed enum for keys — invalid keys are unrepresentable
- Zero allocations, works in
no_stdenvironments - Runtime helpers:
- Tolerance-based reverse lookup (e.g., from FFT peaks)
- Nearest snapping for noisy frequency estimates
- Iteration over all tones and keys
Installation
This crate is no_std by default and does not pull in any dependencies.
Quick Example
use ;
Why Const-First?
Most DTMF tone mappings are fixed, known at compile time, and tiny (4×4 keypad).
By making the mapping fully const, you can:
- Use it inside
const fn, static initialisers, orconstgeneric contexts - Catch invalid keys at compile time
- Eliminate runtime table lookups entirely
API Overview
| Function | Description | const |
|---|---|---|
DtmfKey::from_char |
Convert a char to a key (fallible) | ✅ |
DtmfKey::from_char_or_panic |
Convert a char to a key, panics at compile time if invalid | ✅ |
DtmfKey::to_char |
Convert key to char | ✅ |
DtmfTable::lookup_key |
Forward lookup: key → (low, high) | ✅ |
DtmfTable::from_pair_exact |
Reverse lookup: exact pair → key | ✅ |
DtmfTable::from_pair_normalised |
Reverse lookup: order-insensitive | ✅ |
DtmfTable::from_pair_tol_f64 |
Reverse lookup with tolerance | ❌ |
DtmfTable::nearest_u32 |
Snap noisy frequencies to nearest canonical pair | ❌ |
DtmfTable::iter_tones |
Iterate over all tones | ❌ |
Integration Example
This crate pairs naturally with audio analysis pipelines. For example:
- Take an audio segment
- Compute FFT magnitude
- Pick two frequency peaks
- Use
from_pair_tol_f64ornearest_f64to resolve the DTMF key
// freq1 and freq2 are the peak frequencies extracted from your FFT
let key = table.from_pair_tol_f64;
if let Some = key
License
This project is licensed under the MIT License.