crates/veilvoice-core/src/stft.rs
veilvoice-core · 264 lines · read the source here · or on GitHub
Streaming short-time Fourier transform with overlap-add resynthesis.
Structure follows the classic FIFO/overlap-add pipeline (as popularised by Bernsee's SMB pitch shifter): samples flow in and out one-for-one with a fixed latency of n - hop samples, and a full frame is analysed/synthesised every hop input samples. The caller supplies a closure that rewrites the complex spectrum in place, keeping the FFT plumbing and the de-identification maths cleanly separated.
The closure also receives the raw (unwindowed) analysis frame. Accent neutralisation needs a time-domain view to track f0, because the FFT resolution at useful frame sizes is far too coarse for that, and handing over the frame that produced the spectrum keeps the two perfectly aligned. Its newest hop samples are the tail.
In plain words
Sound arrives as a long stream of numbers. To change a voice you have to look at it in terms of pitch and tone rather than raw numbers, and this is the part that converts back and forth.
It takes a short slice of sound, works out which frequencies are in it, hands that picture to the code that alters it, and turns the result back into sound. The slices overlap and are faded together, so the joins cannot be heard.
Everything else in the engine is written in terms of those pictures. This file is the door between the two ways of looking at the same thing.
WHAT THIS FILE CONTAINS
264 lines defining 4 functions (3 public), 1 type and 0 constants. Everything below is read out of the source, so it cannot disagree with the code.
The types it owns.
struct StftEngineline 36 · Reusable streaming STFT engine (single channel).
What happens when it runs. These are the ways in: public, and nothing else in this file calls them, so they are what an outside caller reaches first.
StftEngine::newline 60 · n must be even; hop must divide evenly for constant overlap-add (typical: hop = n/4).StftEngine::latency_samplesline 98 · End-to-end algorithmic latency (group delay) in samples.StftEngine::processline 105 · Process input into output (equal length).
reachesprocess_frame
WHAT CALLS WHAT
The functions this file defines, and the calls between them. An edge means the callee's name appears, called, inside the caller's body. This is a syntactic reading, not a type-resolved one.
The same graph as Mermaid source
%%{init: {"theme":"base","themeVariables":{"background":"#1a1b26","primaryColor":"#1f2335","primaryTextColor":"#c0caf5","primaryBorderColor":"#7aa2f7","secondaryColor":"#16161e","tertiaryColor":"#16161e","lineColor":"#737aa2","textColor":"#c0caf5","mainBkg":"#1f2335","nodeBorder":"#7aa2f7","clusterBkg":"#16161e","clusterBorder":"#2f3549","fontFamily":"ui-monospace, SFMono-Regular, Consolas, monospace","fontSize":"14px"}}}%%
flowchart TD
n_new(["StftEngine::new<br/>line 60"])
n_latency_samples(["StftEngine::latency_samples<br/>line 98"])
n_process(["StftEngine::process<br/>line 105"])
n_process_frame["StftEngine::process_frame<br/>line 159"]
n_process --> n_process_frame
click n_new href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-core/src/stft.rs#L60" "open the source"
click n_latency_samples href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-core/src/stft.rs#L98" "open the source"
click n_process href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-core/src/stft.rs#L105" "open the source"
click n_process_frame href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-core/src/stft.rs#L159" "open the source"
classDef entry fill:#1f2335,stroke:#7aa2f7,color:#c0caf5
class n_new,n_latency_samples,n_process entry
classDef helper fill:#1f2335,stroke:#bb9af7,color:#c0caf5
class n_process_frame helper
This site loads no third-party script, so it cannot run Mermaid; the diagram above is the same nodes and edges drawn by the generator instead. GitHub renders the source below directly.
ITEMS
| Item | Line | Documentation |
|---|---|---|
StftEngine pub struct | 36 | Reusable streaming STFT engine (single channel). |
StftEngine::new pub fn | 60 | n must be even; hop must divide evenly for constant overlap-add (typical: hop = n/4). |
StftEngine::latency_samples pub fn | 98 | End-to-end algorithmic latency (group delay) in samples. |
StftEngine::process pub fn | 105 | Process input into output (equal length). |
StftEngine::process_frame fn | 159 | Window, transform, hand the spectrum to transform, and overlap-add the result back into the output queue. |