File size: 1,377 Bytes
ab1b068
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// Source-filter synthesizer of the Hindi tiny-voca TTS: a C++ port of tiny_voca.model.SourceFilter.forward and
// pulse_train (tts_hi/tiny_voca/model.py). Plain C++, no ggml: the network only predicts the per-frame heads.
#pragma once
#include <cstdint>
#include <vector>

struct SynthConfig {
    int sample_rate = 24000, hop = 256;
    int synth_fft = 512, synth_hop = 128, noise_fft = 256, noise_hop = 64;
    int cep_causal = 80, cep_anti = 16, noise_cep = 32;
    float harmonic_limit = 0.47f;
    std::vector<float> causal_lifter, anti_lifter, noise_lifter;
};

// harmonic: [T][cep_causal + cep_anti + hop/synth_hop] row-major, noise_head: [T][noise_cep + hop/noise_hop],
// f0: [T] Hz, noise: T*hop white-noise samples. Returns T*hop samples.
std::vector<float> synthesize_wave(const SynthConfig& c, const float* harmonic, const float* noise_head, const float* f0,
                                   int T, const float* noise);

// Vocos ISTFTHead after its Linear: head [frames][n_fft + 2] = (log magnitude, phase) per bin -> torch.istft
// (center=True, periodic Hann, window = n_fft). Returns hop * (frames - 1) samples.
std::vector<float> vocos_istft(const float* head, int frames, int n_fft, int hop);

// Band-limited pulse train (unit power), as model.pulse_train.
std::vector<float> pulse_train(const float* f0, int T, int sample_rate, int hop, double limit);