TorchFX 0.4.0: Production-Ready Audio DSP ๐#
Iโm thrilled to announce TorchFX 0.4.0, the biggest release yet. This version transforms TorchFX from a research library into a audio DSP toolkit with real-time processing, and a powerful CLI interface.
This release represents months of work implementing the core features needed for v1.0.0. Letโs dive into whatโs new!
๐ฏ Release Highlights#
1. Full-Featured CLI Application#
The crown jewel of 0.4.0 is a complete command-line interface that brings GPU-accelerated audio processing to your terminal:
11 Commands:
processโ Apply effects to audio (single/batch/pipes)infoโ Display file metadataplayโ Play audio with effectsrecordโ Record from microphoneconvertโ Format/rate/channel conversion (sox-compatible)trimโ Extract time ranges (sox-compatible)concatโ Join multiple files (sox-compatible)statsโ Signal statistics (sox-compatible)presetโ Manage reusable effect chains (save/load/list/show/delete/apply)interactiveโ Launch the REPLwatchโ Monitor directories for auto-processing
Example workflows:
# Batch processing on GPU
torchfx --device cuda process "*.wav" -O ./processed/ -e normalize
# Unix pipes
cat input.wav | torchfx process - - -e normalize | aplay
# Watch DAW export folder
torchfx watch ./bounces/ ./mastered/ --preset mastering
# Interactive mode with live performance
torchfx interactive
See the CLI blog post for full details.
2. Interactive REPL with Live Performance Mode#
The REPL enables real-time audio manipulation with instant effect changes:
torchfx> load song.wav
torchfx> live
โถ Live playback started (looping)
torchfx> add reverb:decay=0.8,mix=0.5
โ [1] Added reverb:decay=0.8,mix=0.5
# โ Effect applies while playing
torchfx> preset load mastering
โ Loaded preset 'mastering' (3 effects)
# โ Entire chain switches in real-time
Key features:
Lock-free circular buffer for glitch-free playback
Effect hot-swapping at buffer boundaries (~46ms latency)
prompt_toolkit with tab completion and persistent history
Perfect for sound design, education, and live performance
Read the REPL blog post for the full story.
3. Input Validation Layer (torchfx.validation)#
Error handling with context-aware messages:
Exception hierarchy:
TorchFXError(base โ catch all library errors)InvalidParameterErrorInvalidSampleRateErrorInvalidRangeErrorInvalidShapeErrorInvalidTypeErrorAudioProcessingErrorCoefficientComputationErrorFilterInstabilityError
Validator functions:
validate_sample_rate()โ Ensure valid sampling ratesvalidate_positive()โ Check positive numbersvalidate_range()โ Verify parameter boundsvalidate_in_set()โ Enum-like validationvalidate_tensor_ndim()โ Tensor shape checkingvalidate_audio_tensor()โ Audio-specific validationvalidate_type()โ Type checking with suggestionsvalidate_cutoff_frequency()โ Filter cutoff validationvalidate_filter_order()โ Order constraintsvalidate_q_factor()โ Q parameter validation
Example:
from torchfx.validation import validate_sample_rate, InvalidSampleRateError
try:
validate_sample_rate(48000) # OK
validate_sample_rate(-100) # Raises with helpful message
except InvalidSampleRateError as e:
print(e) # "Invalid sample rate: -100 (must be positive)"
All exceptions include:
Parameter name
Actual value
Expected value/range
Suggestion for fixing
4. Logging Infrastructure (torchfx.logging)#
Production-grade logging following Python best practices:
import torchfx.logging as tfx_log
# Enable logging (NullHandler by default)
tfx_log.enable_logging() # INFO level
tfx_log.enable_debug_logging() # DEBUG level
# Get module-specific loggers
logger = tfx_log.get_logger("torchfx.filter")
# Performance profiling
with tfx_log.log_performance("Heavy operation"):
# ... code ...
pass # Logs execution time at INFO level
# Or as decorator
from torchfx.logging import LogPerformance
@LogPerformance("My function")
def process_audio():
pass
Features:
Hierarchical loggers:
torchfx,torchfx.performance,torchfx.<module>Opt-in by default (follows Python logging conventions)
Performance utilities for profiling
DEBUG logs include detailed parameter info
5. Real-Time Processing Module (torchfx.realtime)#
Complete real-time audio infrastructure:
Core classes:
RealtimeProcessorโ Orchestrates backend + effect chainStreamProcessorโ Chunk-based file processingTensorRingBufferโ Lock-free SPSC ring bufferSoundDeviceBackendโ PortAudio integrationStreamConfigโ Stream configurationAudioBackendโ Abstract backend interface
Example:
from torchfx.realtime import RealtimeProcessor, StreamConfig, SoundDeviceBackend
from torchfx.effect import Gain, Reverb
config = StreamConfig(
sample_rate=48000,
buffer_size=512,
channels_in=1,
channels_out=1,
)
processor = RealtimeProcessor(
effects=[Gain(0.8), Reverb()],
backend=SoundDeviceBackend(),
config=config,
)
with processor:
# Real-time processing active
processor.set_parameter("0.gain", 0.5) # Thread-safe parameter update
# ... processing continues ...
Features:
<10ms latency at 48kHz, 512 buffer
Thread-safe parameter updates at buffer boundaries
GPU/CPU hybrid processing
Ring buffer for smooth I/O
Automatic
fspropagation to effects
6. Biquad Filter Suite#
Six new biquad implementations with Audio EQ Cookbook formulas:
BiquadLPFโ Lowpass filterBiquadHPFโ Highpass filterBiquadBPFโ Bandpass filter (constant skirt gain)BiquadBPFPeakโ Bandpass filter (constant 0 dB peak gain)BiquadNotchโ Notch filterBiquadAllPassโ All-pass filter
All support:
Stateful processing (IIR state management)
Stateless processing (for one-shot operations)
Device transfer (CPU โ GPU)
Standard
cutoffandqparameters
7. TOML Configuration & Preset System#
Reproducible effect chains with TOML:
# mastering.toml
device = "cuda"
chunk_size = 131072
[[effects]]
name = "normalize"
peak = 0.9
[[effects]]
name = "parametriceq"
frequency = 2000
q = 1.5
gain = 3
[[effects]]
name = "reverb"
decay = 0.5
mix = 0.2
Use with CLI:
torchfx process input.wav output.wav --config mastering.toml
Or save as preset:
torchfx preset save mastering --from mastering.toml
torchfx preset apply mastering input.wav output.wav
Presets stored in ~/.config/torchfx/presets/ for easy sharing.
8. Effect Chain Parser#
30+ effects/filters registered with intuitive CLI syntax:
# Simple effect
-e normalize
# Positional parameter
-e "gain:0.5"
# Keyword parameters
-e "reverb:decay=0.6,mix=0.3"
# Mixed
-e "parametriceq:frequency=2000,q=1.5,gain=6"
Registered effects include:
Effects:
gain,normalize,reverb,delayBiquad filters:
lowpass,highpass,bandpass,notch,allpassIIR filters:
lobutterworth,hibutterworth,butterworth,lochebyshev1,hichebyshev1,chebyshev1,lochebyshev2,hichebyshev2,chebyshev2,loelliptic,hielliptic,ellipticShelving/EQ:
loshelving,hishelving,parametriceq,peaking
๐ Test Coverage#
393 tests across the codebase with >90% coverage:
Wave class: 72 tests
Filters (IIR/FIR/Biquad): 85+ tests
Effects: 43 tests
Real-time processing: 62 tests
Validation: 76 tests
Logging: 25 tests
CLI: 71 tests
All tests pass on Linux, macOS, and Windows with Python 3.10-3.13.
๐ Documentation Updates#
Complete overhaul of documentation:
CLI Guide: Comprehensive tutorial with examples for all commands
API Reference: Complete docstrings with examples
Developer Guides: Roadmap, style guide, contributing guide
๐ง Installation#
# Core library
pip install torchfx
# With CLI tools
pip install torchfx[cli]
# With real-time audio (for play/record/REPL live mode)
pip install torchfx[realtime]
# Everything
pip install torchfx[cli,realtime]
๐ Project Status#
With 0.4.0, weโve completed Phase 1 and Phase 2 of the roadmap to v1.0.0:
โ
Phase 1 (Foundation): Core stabilization, API stability, error handling, testing
โ
Phase 2 (Major Features): Real-time processing, CLI application, documentation
Next up โ Phase 3 (Optimization):
Custom CUDA kernels for IIR filters
Batch processing optimizations
Additional effects (compressor, phaser, pitch shift)
Weโre now ~85% complete toward v1.0.0!
๐ Try It Now#
pip install torchfx[cli,realtime]
torchfx interactive
Load a file, type live, and experience real-time audio magic.
๐ Complete Changelog#
Added#
Input validation layer with custom exception hierarchy (
torchfx.validationmodule)Base exception
TorchFXErrorfor catching all library errorsSpecific exceptions:
InvalidParameterError,InvalidSampleRateError,InvalidRangeError,InvalidShapeError,InvalidTypeError,AudioProcessingError,CoefficientComputationError,FilterInstabilityErrorValidator functions for sample rates, parameter ranges, tensor shapes, types, and audio-specific validation
Logging infrastructure (
torchfx.loggingmodule)Structured logging following Python best practices (NullHandler by default)
Convenience functions:
enable_logging(),enable_debug_logging(),disable_logging(),get_logger()Performance profiling:
log_performance()context manager andLogPerformancedecoratorHierarchical logger support for fine-grained control
Realtime processing module (
torchfx.realtime)RealtimeProcessorwith thread-safe parameter updatesStreamProcessorfor chunk-based file processingTensorRingBufferwith lock-free SPSC patternSoundDeviceBackendfor PortAudio integrationStreamConfigandAudioBackendabstractions
Biquad filter implementations
BiquadLPF,BiquadHPF,BiquadBPF,BiquadBPFPeak,BiquadNotch,BiquadAllPassStateful and stateless processing paths
Audio EQ Cookbook formulas
CLI application (Epic 3 โ Phase 1)
torchfx process: single-file, batch (glob + progress bar), and Unix pipe processingtorchfx info: display audio file metadata in Rich tablestorchfx play: play audio through speakers with optional effectstorchfx record: record from microphonetorchfx convert: format/rate/channel conversion (sox-compatible)torchfx trim: extract time ranges (sox-compatible)torchfx concat: join multiple files (sox-compatible)torchfx stats: signal statistics (sox-compatible)torchfx preset: save/load/list/show/delete/apply presetstorchfx interactive: launch REPL with live performance modetorchfx watch: monitor directories for auto-processingEffect-chain parser with 30+ registered effects/filters
TOML configuration file support
Preset management in
~/.config/torchfx/presets/GPU acceleration via
--device cuda
Changed#
Improved error messages throughout library with context and suggestions
Enhanced logging with performance profiling capabilities
Real-time processing now uses ring buffers for smooth I/O
Technical Details#
Lines of Code: ~12,000 (including tests and docs)
Test Count: 393 (up from 95 in v0.2.1)
Coverage: >90% (up from ~70%)
Documentation Pages: 50+ (up from ~20)
Supported Python: 3.10, 3.11, 3.12, 3.13
Optional Dependencies:
sounddevice,typer,rich,prompt_toolkit,watchdog
๐ฎ Whatโs Next?#
v1.0.0 Release Candidate is the immediate goal. After community testing and final polish, weโll ship v1.0.0 with:
Semantic versioning guarantees
Long-term API stability
Custom CUDA kernels for 2-3x speedup
Post-1.0 roadmap includes:
Advanced effects (compressor, phaser, pitch shift)
VST3 wrapper (long-term)
๐ฌ Get Involved#
GitHub: matteospanio/torchfx
Issues: Report bugs, request features
Discussions: Ask questions, share workflows
Contributing: See CONTRIBUTING.md
TorchFX 0.4.0 is available now. Install it, explore the CLI, try the REPL, and let us know what you think!
pip install torchfx[cli,realtime]
torchfx --help
Happy audio processing! ๐ต