WDF Compiler is a code generation system for developing circuit simulations using Wave Digital Filters (WDFs).
WDF Compiler is intended to be used as follows:
- Write your circuit description
- Use
wdf_compilerto generate your circuit simulation code - Compile the generated code into your own executable
wdf_compiler uses its own circuit description language. To write a circuit description, you can declare each WDF element in your circuit, followed by that element's "children". For example, here is a circuit description for a simple RC lowpass filter:
circuit:
IVs(Vin);
Series(S1);
R(R1, 1k);
C(C1, 1u);
inputs:
Vin
outputs:
V:C1
For more examples of the circuit description language, see the tests/ directory.
Let's say that you've written your circuit description in a file called my_circuit.wdf. Simulation code can be generated for the circuit using the command:
wdf_compiler my_circuit.wdf my_circuit.hBy default, wdf_compiler will generate C++ code, using float as the base data type. wdf_compiler also supports generating code in C, JAI, and Rust:
wdf_compiler -lang jai my_circuit.wdf my_circuit.jaiwdf_compiler also supports generating code using arbitrary data types:
wdf_compiler -dtype double my_circuit.wdf my_circuit.hRun wdf_compiler -help to see additional options.
To build the wdf_compiler for yourself, you must have the JAI compiler installed. wdf_compiler is currently built with JAI beta version 0.2.023, but most recent versions should work.
To build the compiler, run:
jai compiler/wdf_compiler.jaiTo run the wdf_compiler tests, run:
./tests/test_runner.shTo run the wdf_compiler performance benchmarks, run:
./tests/test_runner.sh clang benchThe following tables show the output of the performance benchmarks for wdf_compiler version 1.1.0. Along with wdf_compiler, the benchmarks compare these other WDF libraries: chowdsp_wdf, wdmodels, and RT-WDF.
CPU: Apple M1
| Circuit | Framework | ns/sample | instructions/sample | cycles/sample | instructions/cycle |
|---|---|---|---|---|---|
| RC Lowpass | RT-WDF |
22.54 | 251.02 | 72.07 | 3.48 |
| RC Lowpass | wdmodels |
6.02 | 17.01 | 19.04 | 0.89 |
| RC Lowpass | chowdsp_wdf |
6.97 | 18.01 | 22.09 | 0.82 |
| RC Lowpass | wdf_compiler |
1.37 | 12.00 | 4.42 | 2.71 |
| Pre-Amp EQ | RT-WDF |
107.66 | 1007.10 | 346.18 | 2.91 |
| Pre-Amp EQ | wdmodels |
22.91 | 83.02 | 73.30 | 1.13 |
| Pre-Amp EQ | chowdsp_wdf |
20.71 | 56.01 | 66.33 | 0.84 |
| Pre-Amp EQ | wdf_compiler |
18.42 | 66.02 | 59.18 | 1.12 |
| Diode Clipper | wdmodels |
116.52 | 566.93 | 374.53 | 1.51 |
| Diode Clipper | chowdsp_wdf |
41.05 | 102.04 | 131.78 | 0.77 |
| Diode Clipper | wdf_compiler |
35.08 | 76.02 | 112.79 | 0.67 |
| Baxandall EQ | RT-WDF |
183.01 | 2028.18 | 588.16 | 3.45 |
| Baxandall EQ | wdmodels |
18.54 | 163.02 | 59.23 | 2.75 |
| Baxandall EQ | chowdsp_wdf |
20.52 | 156.01 | 65.55 | 2.38 |
| Baxandall EQ | wdf_compiler |
11.35 | 55.01 | 36.56 | 1.50 |
CPU: AMD Ryzen Zen 4
| Circuit | Framework | ns/sample | instructions/sample | cycles/sample | instructions/cycle |
|---|---|---|---|---|---|
| RC Lowpass | RT-WDF |
20.31 | 268.06 | 99.85 | 2.68 |
| RC Lowpass | wdmodels |
2.98 | 14.51 | 15.03 | 0.97 |
| RC Lowpass | chowdsp_wdf |
6.44 | 38.02 | 31.73 | 1.20 |
| RC Lowpass | wdf_compiler |
1.21 | 9.51 | 6.06 | 1.57 |
| Pre-Amp EQ | RT-WDF |
99.98 | 1132.51 | 505.42 | 2.24 |
| Pre-Amp EQ | wdmodels |
15.92 | 128.05 | 80.29 | 1.59 |
| Pre-Amp EQ | chowdsp_wdf |
18.96 | 136.05 | 95.77 | 1.42 |
| Pre-Amp EQ | wdf_compiler |
12.77 | 83.03 | 63.35 | 1.31 |
| Diode Clipper | wdmodels |
90.17 | 354.14 | 389.10 | 0.91 |
| Diode Clipper | chowdsp_wdf |
28.31 | 126.24 | 141.86 | 0.89 |
| Diode Clipper | wdf_compiler |
22.84 | 96.07 | 113.12 | 0.85 |
| Baxandall EQ | RT-WDF |
160.94 | 2406.47 | 805.60 | 2.99 |
| Baxandall EQ | wdmodels |
14.66 | 261.04 | 72.95 | 3.58 |
| Baxandall EQ | chowdsp_wdf |
22.17 | 199.19 | 112.25 | 1.77 |
| Baxandall EQ | wdf_compiler |
8.58 | 95.02 | 43.62 | 2.18 |
wdf_compiler has been successfully used for several prototype and professional projects, including:
wdf_compiler_plugin: An audio plugin for prototyping WDF circuit models, with hot reloading.- Tekno: A drum machine plugin containing several WDF circuit models.
wdf_compilerwas able to improve the performance of these circuit models by 20-50%.
WDF Compiler is open-source software published under the MIT.