Digital Signal Processing
All of it lives in Core/Sources/ORIXAudioCore/DSP and …/Analysis, has no UI dependency, and is validated against signals whose answers are known (validation report).
Conventions
- Samples are floating point in −1…1; full scale (FS) is 1.0.
- dBFS for amplitude is 20·log₁₀ of a peak value: a full-scale sine reads 0 dBFS as amplitude and −3.01 dBFS as RMS.
- Levels describe the digital file. They are not sound pressure levels: a phone microphone is not a calibrated instrument and the app never says "dB SPL".
- Logarithms of zero are floored at −160 dB.
FFT and scaling
RealFFT wraps vDSP_fft_zrip. vDSP's real forward transform returns twice the mathematical DFT, so squared magnitudes are multiplied by ¼ first. With X[k] = Σ w[n]·x[n]·e^(−j2πkn/N):
| Quantity | One-sided value for 0 < k < N/2 | Meaning |
|---|---|---|
| Amplitude | 2·|X[k]| / (N·CG) | peak amplitude of the sinusoid in the bin |
| Power | 2·|X[k]|² / (N²·CG²) | its mean-square power, A²/2 |
| Power spectral density | 2·|X[k]|² / (fs·N·NPG) | power per hertz; Σ PSD·(fs/N) equals the mean-square power |
CG is the window's coherent gain (its mean) and NPG its noise power gain (the mean of its square). DC and Nyquist are not doubled. Mixing these up is the usual way a spectrum analyser ends up showing "decibels" that mean nothing, which is why the three are separate choices with separate unit labels.
Windows
Cosine-sum windows in periodic form, w[n] = Σ (−1)^k·a_k·cos(2πkn/N).
| Window | a₀ … | CG | ENBW (bins) | Use |
|---|---|---|---|---|
| Rectangular | 1 | 1.000 | 1.000 | transients, bin-exact tones |
| Hann | 0.5, 0.5 | 0.500 | 1.500 | default |
| Hamming | 0.54, 0.46 | 0.540 | 1.363 | slightly narrower main lobe |
| Blackman | 0.42, 0.5, 0.08 | 0.420 | 1.727 | lower side lobes |
| Blackman–Harris | 0.35875, 0.48829, 0.14128, 0.01168 | 0.359 | 2.004 | very low leakage |
| Flat top | 0.21557895, 0.41663158, 0.277263158, 0.083578947, 0.006947368 | 0.216 | 3.770 | amplitude accuracy off-bin |
ENBW = NPG / CG². Summing coherent-gain-corrected power bins over a band over-counts by the ENBW, so band power divides by it.
Spectrum analyser
SpectrumAnalyzer averages |X|² over time with an exponential factor (power is the quantity for which averaging is meaningful), converts to the chosen scaling, and keeps a peak-hold trace that decays at a set number of dB per second. The dominant frequency is the strongest bin above 20 Hz refined by a parabola through the log magnitudes of its neighbours; it is nil below −90 dBFS. For display, bins are mapped to columns on a linear or logarithmic axis taking the maximum of the bins a column covers, so a narrow peak is never averaged away.
Bands
| # | Band | Range |
|---|---|---|
| 0 | Sub-bass | 20–60 Hz |
| 1 | Bass | 60–250 Hz |
| 2 | Low-mid | 250–500 Hz |
| 3 | Mid | 500–2000 Hz |
| 4 | Upper-mid | 2000–4000 Hz |
| 5 | Presence | 4000–6000 Hz |
| 6 | Brilliance | 6000–20 000 Hz |
FrequencyBandLayout.orix holds these; another layout can be passed to the processors.
Waveform summary
Per bucket of 512 samples: exact minimum, maximum and mean square (vDSP), and seven band powers from a 4096-point Hann FFT of the samples ending at the bucket. Higher levels of the pyramid merge pairs: minimum of minima, maximum of maxima, RMS combined in power, band powers averaged. The summary serialises to 40 bytes per bucket behind a versioned header.
Spectrogram
SpectrogramProcessor is a streaming STFT producing columns of amplitude in dBFS; column c is centred at sample c·hop + N/2. Streaming and one-shot results are identical (tested). SpectrogramRasterizer maps a dB range onto a 256-entry palette table for each output row, linear or logarithmic in frequency, again taking the maximum over the bins a row covers.
Time-domain metrics
TimeDomainAccumulator keeps double-precision running sums, so an hour of audio pushed in chunks reads the same RMS as the first second (tested to 0.001 dB). Clipping counts samples at or above 0.999 FS that belong to a run of at least three — a clean full-scale sine touches the limit for one sample per half-cycle and is not a clip. Silences are stretches of at least 0.5 s whose 400 ms RMS stays below −50 dBFS. Background level and dynamic spread are the 10th percentile and the 95th-minus-10th percentile of those 400 ms levels; they are indicators, not standard measures.
Spectral metrics
From a 2048-point Hann STFT at 50 % overlap, averaged over frames above −80 dBFS: centroid (power-weighted mean frequency), bandwidth (power-weighted standard deviation), rolloff (85 % of power), flatness (geometric over arithmetic mean of power), flux (positive change of the L2-normalised magnitude spectrum between frames).
Loudness
LoudnessMeter implements ITU-R BS.1770-4 for one or two channels.
- K-weighting. A high shelf and the RLB high-pass, from closed-form coefficients that match the standard's 48 kHz table to 1e-8 and give the equivalent analogue response at other sample rates.
- Integration. Mean square per 100 ms; 400 ms blocks at 75 % overlap are sums of four. Loudness = −0.691 + 10·log₁₀(Σ channels).
- Gating. Absolute gate at −70 LUFS, then a relative gate 10 LU below the mean of what survived.
- Short-term uses 3 s windows; loudness range follows EBU Tech 3342 (absolute gate −70, relative gate −20 LU, 10th to 95th percentile).
- True peak. 4× oversampling with a 48-tap Kaiser-windowed sinc run as four polyphase branches.
Surround channel weights are not implemented, and the verification signals are synthesised rather than the official EBU files, so the app says "ITU-R BS.1770-4" and makes no certification claim.
Speech activity
VoiceActivityDetector band-limits to 300–3400 Hz, measures 20 ms frame levels, and marks a frame active when it exceeds the larger of −55 dBFS and the 10th-percentile level plus 9 dB, with a 250 ms hangover. It is a heuristic: loud non-speech sound in that band counts as activity. Every figure derived from it is labelled "Estimate".
Filters and effects
Biquad sections use the RBJ cookbook designs in transposed direct form II, double precision. High- and low-pass are two cascaded sections with Butterworth Q values (0.5412 and 1.3066) for 24 dB/octave. The compressor is feed-forward with an RMS detector and a 6 dB soft knee. Noise reduction is spectral subtraction: 1024-point Hann analysis and synthesis at 75 % overlap, a noise profile averaged from the 200 quietest non-silent frames, over-subtraction 1–3×, a gain floor of −6 to −24 dB, and smoothing of gains across frames. Its 768-sample latency is compensated by the renderer (tested: a tone still starts within 5 ms of where it should).