ddsp developer on retainer: Additive(sample_rate=16000) f0_hz passed as normalized frequency 0.0275 instead of 440 Hz — synthesizer generates 0.0275 Hz DC (36-second period) — SpectralLoss converges toward silence — violin synthesis outputs amplitude-modulated hum — MCD 14.3 dB — 5 months — ddsp developer on monthly retainer
ddsp 1.6.3 • TensorFlow 2.11; Additive(n_samples=16000, sample_rate=16000, n_harmonics=60); CREPE f0 in Hz (440 Hz A4) divided by sample_rate → 440/16000 = 0.0275 passed as f0_hz; Additive computes ω = 2π × 0.0275/16000 = 1.08 × 10&sup5; rad/sample; period 36.3 s; synthesis: near-DC; SpectralLoss converges toward silence (MCD 14.3 dB); 5 months; fix: pass f0_hz in Hz directly (do NOT divide by sample_rate); MCD 1.9 dB • Southfield DDSP Ltd. (violin timbre synthesis; 10,000-recording corpus; 5 months; 2.0h)
Southfield DDSP Ltd. built a violin timbre synthesis model using Google Magenta’s Differentiable Digital Signal Processing (DDSP) library. The architecture followed the standard DDSP autoencoder: a convolutional encoder extracts per-frame loudness, fundamental frequency (f0), and a timbre embedding Z from each 1-second, 16000 Hz violin recording; an MLP decoder predicts harmonic amplitude distribution and filtered noise amplitude from Z, loudness, and f0; a ddsp Additive synthesizer reconstructs the audio from f0 (in Hz), harmonic_distribution, and amplitudes; a ddsp SpectralLoss trains the model by minimising multi-scale STFT magnitude differences between synthesis and target. CREPE pitch extraction returned f0 in Hz. The developer, familiar with digital signal processing convention where normalized frequency spans [0, 0.5) (cycles per sample, relative to Nyquist), divided the CREPE output by the sample rate before feeding it to the network: f0_input = crepe_frequency / sample_rate. For A4 at 440 Hz with sample_rate=16000: f0_input = 440 / 16000 = 0.0275. The network was trained with this normalized frequency as input and learned to output the same normalized-scale f0 to the Additive synthesizer. The ddsp.synths.Additive synthesizer expects f0_hz in absolute Hz, not normalized frequency. It computes the per-sample phase increment as ω = 2π × f0_hz / sample_rate. With f0_hz=0.0275 (normalized) instead of 440 (Hz): ω = 2π × 0.0275 / 16000 = 1.08 × 10&sup5; radians/sample; period = 2π / ω = 580,000 samples = 36.3 seconds. The synthesizer generated a sinusoidal wave with a 36-second period — a near-DC constant offset for any 1-second audio clip. The SpectralLoss computed on this near-DC synthesis against violin targets was initially moderately low (near-silence produces a spectrogram with near-zero magnitude everywhere, which incurs a moderate loss but not as large as expected for an untrained model). The model learned over 5 months to minimize the loss further by reducing amplitudes toward zero — near-silence scores better against a violin target spectrogram than loud DC does. After 150,000 training steps: synthesis MCD 14.3 dB (a value above 10 dB represents essentially unrelated audio), and the model outputted amplitude-modulated near-silence.
The mechanism: ddsp’s Additive synthesizer is a fully differentiable harmonic synthesizer. For K harmonics, it generates: y(t) = ∑ A × h_k × sin(2π × k × f0_hz × t / sample_rate), where A is the per-frame overall amplitude and h_k is the kth harmonic distribution weight (summing to 1 via softmax). The key operation is 2π × f0_hz / sample_rate — this is the phase increment per sample. For the fundamental (k=1): with f0_hz=440 (correct), phase increment = 2π × 440/16000 = 0.1728 rad/sample; sinusoidal period = 36.4 samples; 440 Hz tone audible as A4. With f0_hz=0.0275 (normalized, incorrectly passed as Hz), phase increment = 2π × 0.0275/16000 = 1.08 × 10&sup5; rad/sample; sinusoidal period = 580,000 samples = 36.3 seconds; well below human hearing threshold (20 Hz). For a 1-second audio clip (16,000 samples), the synthesized signal covers only 16,000/580,000 = 0.028 periods — a nearly linear ramp that resembles a DC offset. The 60th harmonic at 60 × 0.0275 = 1.65 Hz is still sub-audible. The SpectralLoss on this near-DC synthesis vs violin target: for each FFT size in [64, 128, 256, 512, 1024, 2048], the near-DC synthesis has energy only in bin 0 (DC); the violin target has energy at bins corresponding to 440, 880, 1320… Hz. The L1 distance between spectrograms equals the violin target spectrogram norm (since synthesis contributes only to bin 0 which does not match any violin harmonic). The gradient of SpectralLoss with respect to amplitudes A is proportional to ∂L/∂A ≈ −violin_target_magnitude — pushing A toward zero (reducing synthesis amplitude reduces the magnitude discrepancy). After many gradient steps, the model converged to A ≈ 0 (silence), which minimises the loss to the violin target magnitude norm, independent of the learned f0 or harmonic distribution. The fix was removing the / sample_rate division: CREPE already returns f0 in Hz; pass it directly as f0_hz. With correct Hz input: initial SpectralLoss 3.1 (genuine mismatch); after 150,000 steps: SpectralLoss 0.21; MCD 1.9 dB; violin synthesis correct.
# Southfield DDSP Ltd. — ddsp 1.6.3 f0_hz unit fix
# ddsp 1.6.3; TensorFlow 2.11; Python 3.9; CREPE 0.0.13
# Violin timbre synthesis; 10,000 1-second recordings; 16000 Hz; n_harmonics=60
# f0 source: CREPE (crepe.predict → frequency in Hz, confirmed by documentation)
#
# Problem: f0_hz = crepe_frequency / sample_rate (normalized, 0.0275 for A4)
# Additive interprets 0.0275 as Hz → 36-second period → DC
# SpectralLoss converges to near-silence (amplitude→0); MCD 14.3 dB
# Fix: f0_hz = crepe_frequency (Hz directly, no division)
import ddsp
import crepe
import numpy as np
import tensorflow as tf
SAMPLE_RATE = 16000
N_SAMPLES = 16000 # 1-second clips
N_HARMONICS = 60
HOP_SIZE = 64 # samples per frame
N_FRAMES = N_SAMPLES // HOP_SIZE # 250 frames per clip
F0_MIN_HZ = 50.0 # sanity check: below is likely normalized or wrong units
F0_MAX_HZ = 8000.0 # sanity check: above is above violin range (violin max ~4186 Hz)
def extract_f0_buggy(audio: np.ndarray, sr: int = SAMPLE_RATE) -> tf.Tensor:
"""BUGGY: divides Hz f0 by sample_rate → normalized frequency → DC synthesis."""
times, frequency, confidence, _ = crepe.predict(audio, sr, step_size=4,
viterbi=True, verbose=0)
# BUG: CREPE returns Hz; dividing converts to normalized frequency
f0_normalized = frequency / sr # WRONG: 440 Hz → 0.0275 cycles/sample
# Additive will interpret 0.0275 as 0.0275 Hz — 36-second period
return tf.constant(f0_normalized[:N_FRAMES, np.newaxis],
dtype=tf.float32)[tf.newaxis] # (1, N_FRAMES, 1)
def extract_f0(audio: np.ndarray, sr: int = SAMPLE_RATE) -> tf.Tensor:
"""FIXED: pass f0 in Hz directly — do NOT divide by sample_rate."""
times, frequency, confidence, _ = crepe.predict(audio, sr, step_size=4,
viterbi=True, verbose=0)
# FIXED: frequency is already in Hz — pass directly
f0_hz = frequency[:N_FRAMES]
# Sanity check: f0 must be in audible Hz range
if f0_hz.min() < F0_MIN_HZ or f0_hz.max() > F0_MAX_HZ:
raise ValueError(
f"f0_hz out of expected range [{F0_MIN_HZ}, {F0_MAX_HZ}] Hz: "
f"min={f0_hz.min():.4f}, max={f0_hz.max():.4f}. "
f"If min < 1.0, f0_hz may be in normalized frequency (0–0.5 cycles/sample) "
f"rather than Hz — do NOT divide CREPE output by sample_rate."
)
return tf.constant(f0_hz[:, np.newaxis],
dtype=tf.float32)[tf.newaxis] # (1, N_FRAMES, 1)
def validate_synthesis(f0_hz: tf.Tensor, sample_rate: int = SAMPLE_RATE) -> None:
"""
Synthesize a test tone and verify the output pitch is correct.
Raises ValueError if output frequency deviates > 5% from f0_hz[0,0,0].
Requires crepe and librosa installed.
"""
import librosa
target_hz = float(f0_hz[0, 0, 0])
if target_hz < 1.0:
raise ValueError(
f"f0_hz[0,0,0]={target_hz:.6f} — suspiciously low (< 1 Hz). "
f"Expected Hz value (e.g. 440.0). "
f"Check that CREPE output was not divided by sample_rate."
)
# Synthesize constant-f0 test tone
synth = ddsp.synths.Additive(n_samples=sample_rate,
sample_rate=sample_rate,
n_harmonics=1,
scale_fn=ddsp.core.exp_sigmoid)
test_f0 = tf.ones((1, N_FRAMES, 1), dtype=tf.float32) * target_hz
test_amp = tf.ones((1, N_FRAMES, 1), dtype=tf.float32) * 0.5
test_hd = tf.ones((1, N_FRAMES, 1), dtype=tf.float32)
audio_out = synth(amplitudes=test_amp,
harmonic_distribution=test_hd,
f0_hz=test_f0).numpy()[0]
# Measure output pitch
measured_hz = float(librosa.yin(audio_out, fmin=50, fmax=4000,
sr=sample_rate).mean())
if abs(measured_hz - target_hz) / target_hz > 0.05:
raise ValueError(
f"Synthesis pitch mismatch: target={target_hz:.1f} Hz, "
f"measured={measured_hz:.1f} Hz (error "
f"{100*abs(measured_hz-target_hz)/target_hz:.1f}%). "
f"Check f0_hz units (must be Hz, not normalized frequency)."
)
Why the loss hides the bug: near-silence minimises SpectralLoss against a voiced target, masking the f0 unit error
The f0_hz unit error is particularly insidious because the model appears to train: the SpectralLoss decreases over 5 months, the training curve is smooth, and no exception is raised. The model converges to a local minimum — outputting near-silence — that is distinct from the global minimum (accurate violin synthesis) but represents a genuine loss improvement over the initial random state. When the model outputs near-silence (all amplitudes A ≈ 0), the synthesized spectrogram magnitude is near-zero at all frequencies and all STFT scales. The violin target spectrogram has energy at the fundamental and harmonics. The SpectralLoss L1 term for near-silence vs violin target: L ≈ ∑ |violin_target_magnitude| — a constant independent of the model parameters (since the synthesis contributes near-zero magnitude). This constant-loss floor is lower than the loss of a loudy incorrect synthesis (DC at 0.0275 Hz produces energy in a low spectral bin, contributing an additional mismatch penalty on top of the missed harmonic energy). The gradient landscape thus guides the model from loud-DC (high loss) through decreasing amplitude (monotonically decreasing loss) to near-silence (loss floor). At Southfield DDSP Ltd., the developer saw the loss curve decreasing over 5 months and interpreted it as learning. The early loss decreases were real improvements — from loud-DC toward silence — but no further progress was possible because the model was optimising amplitude toward zero, not learning the violin timbre manifold. The correct diagnostic: synthesize a single note from the trained model and listen to it. If it sounds like silence or a 36-second amplitude sweep rather than a violin note, f0_hz is in wrong units. A one-step validation — synthesize 440 Hz A4 (a constant-f0 test tone) and measure output pitch with librosa.yin() — would have revealed the bug within the first training run. With f0_hz in Hz, the initial SpectralLoss is higher (3.1 vs 0.03) because the synthesis has energy at the violin harmonic frequencies and the randomly initialized harmonic_distribution is wrong; this high initial loss drives large gradients that rapidly reshape the harmonic distribution toward the violin timbre. After 150,000 steps: synthesis has clear violin resonance, vibrato, and attack transient; MCD 1.9 dB.
Southfield DDSP Ltd.’s retainer engagement was 2.0h: 0.3h triage (request complete preprocessing and synthesis pipeline; f0_input = crepe_frequency / sample_rate found in data loader; note CREPE returns Hz; compute: mean violin f0 ~300 Hz; divided by 16000 → 0.019; Additive interprets as 0.019 Hz; period = 1/0.019 = 52.6 s; plot amplitude of first training batch synthesis: near-constant signal with period > 16000 samples; confirmed DC synthesis); 0.3h root cause (verify CREPE documentation: returns frequency in Hz per frame; division by sample_rate is wrong; remove division; re-run on 10 test clips: f0 now 196–1047 Hz; Additive synthesis: periodogram peak at input f0 ± 5%; SpectralLoss on first batch: 3.1 (much higher — model genuinely wrong, must learn); add synthesize-and-measure validation); 0.8h fix (remove / sample_rate; add f0 range assertion; add synthesize-and-measure validation test; retrain from scratch 150,000 steps: SpectralLoss 3.1→0.21; synthesis: clear violin timbre; MCD 1.9 dB); 0.6h validation (listening test: 20/20 synthesis samples rated violin-like by 3 musicians; MCD 1.9 dB on held-out 500-clip test set; vibrato synthesis correct per spectrogram inspection; 2.0h total). Hours logged to HourTab with per-session breakdown.
Related retainer posts
- dtaidistance developer on retainer — dtaidistance 2.3.11;
dtw.distance_matrix(series, window=0.05); float window truncated to 0; DTW ≡ Euclidean; AFib clustering 61%; fix:window=int(0.05 × L); 94%; 3.5h - ruptures developer on retainer — ruptures 1.1.9;
Binseg.fit(eeg)witheeg.shape=(20, 5000)transposed; Binseg 20 timepoints; all breakpoints in [0,20]; seizure onset 9.7 s error; fix:eeg.T; 0.31 s error; 2.5h - pysepm developer on retainer — pysepm 0.1;
composite(clean, noisy, 8000)on 16 kHz wideband; NB PESQ range 0.18 MOS (12 models indistinguishable); WB range 1.54 MOS; worst model selected; fix:fs=16000; 1.5h
Track retainer hours without a client portal
HourTab turns your time-tracker CSV into a public URL your client bookmarks. No login. No portal. CSV in, URL out.
See pricing →