v3 — Synthesis pipeline
Header yune-v3/synth.hpp (the engine core). You normally never call it directly — Singer does — but it is public and usable for tooling.
Pipeline
- Notes → events.
Singer::prepare_notes()sorts notes, expands event tags into ordinary notes (per-event deterministic seeds) and applies humanisation, auto-expression and pressure.SynthNoteholdsstart,dur,midi,vel,style,morae,art,bend,glide_from,lanes,event. - Articulation.
build_events()and theArticulatorturn morae into aKeyTrack: key-frames ofPVparameter vectors (indicesF1 F2 F3 B1 B2 B3 TRK AMP VOICE ASP FRIC FRIC_F FRIC_BW …). Mora timing comes frommora_cum(). Vowel formants, consonant loci (v3), coarticulation, voiceless-vowel devoicing, nasals, bursts and frication are all expressed as key-frames; each parameter has its own motion law (param_motion: log or linear, with a speed). - Pitch and expression.
build_pitch_track()andbuild_expr_track()produce millisecond-rate tracks. - Rendering.
VoiceRenderer(vm, sr)produces audio from the three tracks viarender(...)(whole buffer) orstream(...)(VoiceStream). The voice is a glottal source (LF-model-style, using precomputedGlottalTables) through a formant tract chain with a parallel upper-formant bank, singer’s formant, nasal anti-formant (notch), aspiration and frication noise, optional growl/fry/tremor/air and per-sample expression (apply_expr).
VoiceStream
Block-based synthesiser with fixed score at construction. read(dst, n) returns the samples written (0 when finished); read_all(), position(), position_seconds(), total_samples(), finished(), sample_rate(). Output is independent of chunking (read(1), read(100) and read(all) produce identical samples), which makes it suitable for real-time pulling.
Determinism
The voice uses its own counter-hash noise generator (VoiceNoise) instead of std::uniform_real_distribution, because the standard does not specify the latter bit-for-bit across libraries: the same seed yields the same noise on every compiler. Variation helpers (vary, vnoise) are hash-based.
Full API listing
wauvio/vocal/yune-v3/synth.hpp
wauvio::vocal::v3::class GlottalTables
// LF glottal flow-derivative tables, parameterised by Rd (Fant 1995)
// Rd ~0.4 pressed/tense, ~1.0 modal, ~2 breathy.
class GlottalTables
public:
static constexpr int N = 2048; // samples per period
static constexpr int NR = 12; // Rd steps
static constexpr int NL = 9; // band-limit levels: level l keeps (N/2)>>l harmonics (1024, 512, ... 4)
static constexpr float RD_MIN = 0.35f, RD_MAX = 2.55f;
GlottalTables()
/// phase in [0,1); inc = f0 / sample_rate (phase increment per sample). V3: the table is read from
/// the mip level whose harmonics all fit below Nyquist, so the source cannot alias at high pitch.
float read(float phase, float rd, float inc) const
inline const GlottalTables& glottal_tables() { static const GlottalTables t; return t; }
wauvio::vocal::v3::enum PIdx
// Parameter vector + key-frames
enum PIdx { F1, F2, F3, B1, B2, B3, TRK, AMP, VOICE, ASP, FRIC, FRIC_F, FRIC_BW,
NASAL, NZ, RD, TILT, HI, SING,
RF1, RF2, RF3, RTRK, // formants of the vowel this state belongs to (loudness reference)
TRK2, RTRK2, // F2 follows F0 (very high notes)
FSC, // V3: tract-size scale applied to the fixed upper formants (F4..F6, singer's formant)
N_P };
wauvio::vocal::v3::struct PV
struct PV
std::array<float, N_P> v{};
float& operator[](int i) { return v[static_cast<size_t>(i)]; }
float operator[](int i) const { return v[static_cast<size_t>(i)]; }
inline PV lerp_pv(const PV& a, const PV& b, float t)
wauvio::vocal::v3::struct Key
struct Key { double t; PV p; };
wauvio::vocal::v3::struct ParamMotion
// V3: how each parameter moves between two key-frames.
// log : interpolate geometrically (formant/filter frequencies and bandwidths move proportionally in
// pitch space rather than linearly in Hz)
// speed : >1 = the parameter lags (starts late), <1 = it leads (starts early). F2/F3 are the fast
// articulators (tongue body/front), F1 (jaw) is slower.
struct ParamMotion { bool log; float speed; };
inline ParamMotion param_motion(int i)
inline PV interp_pv(const PV& a, const PV& b, double u_raw)
wauvio::vocal::v3::class KeyTrack
class KeyTrack
public:
std::vector<Key> keys;
void push(double t, const PV& p)
PV at(double t) const
double last_t() const { return keys.empty() ? 0.0 : keys.back().t; }
wauvio::vocal::v3::enum class NoteKind
// Kind of note. (An ingressive "Inhale" kind existed in early V2 and was removed: it did not sound right.)
enum class NoteKind : uint8_t { Normal };
wauvio::vocal::v3::struct SynthNote
// Timed morae
struct SynthNote
double start = 0.0, dur = 0.5;
int midi = 60;
float vel = 0.7f;
Style style;
std::vector<Mora> morae;
wauvio::music::Articulation art = wauvio::music::Articulation::Sustain;
Curve bend;
double glide_from = -1.0;
std::vector<Lane> lanes; // V2 automation lanes (seconds from note start)
NoteKind kind = NoteKind::Normal;
std::string event; // non-empty: an unexpanded event tag, e.g. "laugh:ha,intensity=0.7"
wauvio::vocal::v3::struct Ev
struct Ev
Mora m; SurfaceMora sm;
double t0 = 0, t1 = 0; // vowel onset .. end of mora
Style st; float vel = 0.7f;
wauvio::music::Articulation art = wauvio::music::Articulation::Sustain;
Vowel v = Vowel::A;
bool devoiced = false;
bool first_in_note = false;
Surf next_surf = Surf::None; // for ん place assimilation
NoteKind kind = NoteKind::Normal;
float bid = 1.f; // ガ行 nasalisation amount (Surf::NG from bidakuon)
bool next_vowel = false; // the next sounding mora starts with a vowel/glide/h (for ん nasalisation)
/// Cumulative mora boundaries (0..1, size = morae + 1) for one note. Uniform split when mora_weighting is 0
/// and no explicit weights are given; otherwise weighted by mora type (ん/っ shorter, ー longer).
inline std::vector<double> mora_cum(const std::vector<Mora>& ms, float mora_weighting)
inline std::vector<Ev> build_events(const std::vector<SynthNote>& notes)
// Articulation: events -> key-frames
/// V3: deterministic variation for one event (a mora): same seed and same time give the same number, a different
/// take (seed) gives a different one. Roughly triangular in [-1, 1], so most values are small.
inline float vary(uint32_t seed, double t, uint32_t k)
wauvio::vocal::v3::class Articulator
class Articulator
public:
Articulator(const VoiceModel& vm, int sr, uint32_t seed = 0xA17E5u) : vm_(vm), sr_(sr), seed_(seed) {}
KeyTrack build(const std::vector<Ev>& evs, double& end_time)
wauvio::vocal::v3::class VoiceNoise
// Portable white noise (V3). std::uniform_real_distribution is not specified bit-for-bit across standard
// libraries, so the voice uses its own counter-hash generator: the same seed gives the same noise on every compiler.
class VoiceNoise
public:
explicit VoiceNoise(uint32_t seed = 1u) : s_(seed * 2654435761u + 0x9E3779B9u) {}
uint32_t next()
float tick_white() { return static_cast<float>(static_cast<int32_t>(next())) * 4.6566129e-10f; } // [-1, 1)
wauvio::vocal::v3::struct Notch
// RBJ notch (the nasal anti-formant). Transposed direct form II: safe to retune every block.
struct Notch
float b0 = 1, b1 = 0, b2 = 1, a1 = 0, a2 = 0, z1 = 0, z2 = 0;
void set(float f, float q, int sr)
float tick(float x) { const float y = b0 * x + z1; z1 = b1 * x - a1 * y + z2; z2 = b2 * x - a2 * y; return y; }
wauvio::vocal::v3::struct TractChain
// The vocal-tract filter chain. Two instances run in parallel: the real one, and
// a reference fed with a constant fully-voiced source whose RMS drives a slow
// loudness normaliser, so loudness does not depend on where harmonics happen to
// land relative to F1 (vibrato, high notes, vowel changes).
struct TractChain
wauvio::filter::SVFilter r1, r2, r3, q2, q3, u4, u5, u6, sg;
float pre_lp = 0.f, tilt_state = 0.f;
float q2v = 1, q3v = 1, pre_a = 0, tilt_a = 0, k4 = 1, k5 = 1, k6 = 1, ksg = 1;
TractChain()
// fsc: tract-size scale (V3). F4..F6 and the singer's formant move with the voice's formant scale,
// not only F1..F3, so a formant shift changes the whole tract instead of just its lower half.
void set(const VoiceModel& vm, const PV& p, float f1, float f2, float f3, int sr, float fsc = 1.f)
// src: excitation entering the tract; hsrc: voiced-only excitation for the parallel parts
float tick(float src, float hsrc, float hi, float sing, int sr, const Tune& tn)
// Applies the expression channels to a parameter frame. Written so every channel is a
// strict no-op at 0.
inline void apply_expr(PV& p, const Expr& e, double f0)
wauvio::vocal::v3::class VoiceStream
/// Block-based voice synthesiser (V3). The score (key-frames, pitch, expression) is fixed when the stream is
/// created; samples are then produced on demand in any chunk size. The output does not depend on how it is
/// chunked: read(1), read(100) and read(all) give identical samples.
class VoiceStream
public:
VoiceStream(const VoiceModel& vm, int sr, KeyTrack kt, PitchTrack pt, ExprTrack ex, bool has_ex,
double total_sec, uint32_t seed = 0xA17E5u)
: vm_(vm), sr_(sr), kt_(std::move(kt)), pt_(std::move(pt)), ex_(std::move(ex)), has_ex_(has_ex), seed_(seed),
nz_asp_(seed), nz_fric_(seed ^ 0x5bd1e995u), nz_irr_(seed ^ 0x9e3779b9u)
size_t total_samples() const noexcept { return total_; }
size_t position() const noexcept { return s0_ - (blen_ - bpos_); }
double position_seconds() const noexcept { return static_cast<double>(position()) / sr_; }
bool finished() const noexcept { return position() >= total_; }
int sample_rate() const noexcept { return sr_; }
/// Writes up to n samples; returns how many were written (0 once the stream is finished).
size_t read(float* dst, size_t n)
Buffer read_all() { Buffer out(total_ - position(), 0.0f); const size_t got = read(out.data(), out.size()); out.resize(got); return out; }
wauvio::vocal::v3::class VoiceRenderer
class VoiceRenderer
public:
VoiceRenderer(const VoiceModel& vm, int sr) : vm_(vm), sr_(sr) {}
/// Whole-buffer render (a VoiceStream read to the end).
Buffer render(const KeyTrack& kt, const PitchTrack& pt, double total_sec, uint32_t seed = 0xA17E5u,
const ExprTrack* ex = nullptr) const
/// On-demand render: pull samples with VoiceStream::read().
VoiceStream stream(const KeyTrack& kt, const PitchTrack& pt, double total_sec, uint32_t seed = 0xA17E5u,
const ExprTrack* ex = nullptr) const