← Back to C-Kernel-Engine Docs Doxygen Source Documentation
 
Loading...
Searching...
No Matches
ckernel_tts.h
Go to the documentation of this file.
1#ifndef CKE_V8_KOKORO_SHAPE_BOUNDS_H
2#define CKE_V8_KOKORO_SHAPE_BOUNDS_H
3
4#include <stddef.h>
5#include <stdint.h>
6
7#ifdef __cplusplus
8extern "C" {
9#endif
10
11/* This plans output extents only. Generated graph scratch is a separate,
12 * mandatory per-operation declaration; these values must not be used as an
13 * implicit allocation policy. All counts are elements/frames, not bytes. */
28
39
46
47/* Deterministic request-local Gaussian excitation. The caller owns output;
48 * invalid geometry leaves it untouched. Samples are counter-indexed with
49 * explicit seed/stream domain separation. FP64 Box-Muller/libm arithmetic is
50 * independent of PyTorch's RNG and is not bit-identical across all libm
51 * implementations. */
52int audio_noise_counter_gaussian_f32(float *output, size_t output_capacity,
53 size_t count, uint64_t seed, uint64_t stream);
54
55/* Called after model duration postprocessing (round, clamp min=1), before
56 * alignment expansion or waveform writes. A conservative output bound includes
57 * the inverse-STFT FFT halo; actual output length must be checked again. */
59 const int32_t *durations,
60 size_t phoneme_count,
61 const CKKokoroShapeLimitsV8 *limits,
62 CKKokoroShapeV8 *shape);
63
64/* Expand [channels, phonemes] features to [channels, valid_frames]. The
65 * physical row strides may exceed valid extents. Caller owns both buffers;
66 * padding is never read or written. Input and output must not overlap. */
68 const float *features,
69 size_t input_elements,
70 size_t channels,
71 size_t phoneme_count,
72 size_t input_stride,
73 const int32_t *durations,
74 size_t expanded_frames,
75 float *output,
76 size_t output_elements,
77 size_t output_stride);
78
79/* Reduce token-major [tokens, bins] duration logits as Kokoro's inference
80 * path does: FP32 sigmoid, ascending-bin FP32 sum, divide by positive speed,
81 * round to nearest even, clamp to at least one frame. The output is int32
82 * durations plus their checked total valid extent. The two-pass validation
83 * leaves both outputs untouched on any error, including a total above
84 * max_expanded_frames. All pointers are caller-owned and nonaliasing. */
86 const float *logits,
87 size_t input_elements,
88 size_t tokens,
89 size_t bins,
90 size_t input_stride,
91 float speed,
92 int32_t *durations,
93 size_t duration_capacity,
94 size_t max_duration_per_token,
95 size_t max_expanded_frames,
96 int32_t *expanded_frames);
97
98/* Centered inverse STFT from frame-major [frame, fft/2+1] magnitude/phase.
99 * Periodic Hann, inverse DFT scaled by 1/n_fft, overlap-add normalization, then
100 * removal of n_fft/2 samples at each end. Supported geometry is frames >= 2,
101 * even n_fft >= 2, and 1 <= hop <= n_fft/2. The output is
102 * (frames-1)*hop samples. Scratch is two padded sample arrays plus one Hann
103 * window, all caller-owned and disjoint from input/output. The planner rejects
104 * overflow before any write. */
106 size_t frames,
107 size_t n_fft,
108 size_t hop,
109 size_t *spectral_elements,
110 size_t *output_samples,
111 size_t *scratch_elements);
112
114 const float *magnitude,
115 const float *phase,
116 size_t spectral_elements,
117 size_t frames,
118 size_t n_fft,
119 size_t hop,
120 float *output,
121 size_t output_capacity,
122 float *scratch,
123 size_t scratch_elements);
124
125/* Apply exp to the first bin_count channels and sin to the next bin_count
126 * channels of a channel-major spectral head, transposing valid frames into
127 * separate frame-major [frame, bin] outputs. All capacities are element
128 * counts. Inputs and outputs must be disjoint. Rejection preserves outputs. */
130 const float *input, size_t input_elements, size_t input_stride,
131 float *magnitude, size_t magnitude_elements,
132 float *phase, size_t phase_elements,
133 size_t bins, size_t frames);
134
135/* Centered reflect-padded forward STFT. The caller supplies a periodic Hann
136 * window and unnormalized forward-DFT cosine/sine tables. Output is channel
137 * major [magnitude bins, phase bins] with an explicit frame stride. Scratch
138 * holds 2*(n_fft/2+1)*frames floats; a rejected call preserves output. */
139int audio_stft_mag_phase_plan_f32(size_t samples, size_t n_fft, size_t hop,
140 size_t *frames, size_t *spectral_elements);
141
142int audio_stft_mag_phase_checked_f32(const float *samples, size_t samples_capacity,
143 const float *window, size_t window_capacity,
144 const float *cos_table, const float *sin_table, size_t table_capacity,
145 float *output, size_t output_capacity, size_t output_stride,
146 float *scratch, size_t scratch_capacity,
147 size_t samples_count, size_t n_fft, size_t hop, size_t frames);
148
149/* Diagnostic-only variant of the same arithmetic path. complex_trace is an
150 * interleaved [bin, frame, real/imag] FP64 caller-owned buffer. It records
151 * the actual values entering atan2, after the exact-real Nyquist adjustment.
152 * Not a model provider; production generated calls use the function above. */
153int audio_stft_mag_phase_trace_checked_f32(const float *samples,
154 size_t samples_capacity, const float *window, size_t window_capacity,
155 const float *cos_table, const float *sin_table, size_t table_capacity,
156 float *output, size_t output_capacity, size_t output_stride,
157 float *scratch, size_t scratch_capacity,
158 size_t samples_count, size_t n_fft, size_t hop, size_t frames,
159 double *complex_trace, size_t complex_trace_capacity);
160
161/* Frame F0 and explicit Gaussian excitation to sample-major harmonic waves.
162 * Scratch holds frame*harmonic phases plus sample*harmonic staged output;
163 * rejection preserves output. The random stream is supplied by the caller. */
165 const float *f0, size_t f0_capacity,
166 const float *gaussian, size_t gaussian_capacity,
167 float *output, size_t output_capacity,
168 float *phase_scratch, size_t scratch_capacity,
169 size_t frames, size_t upsample, size_t harmonics,
170 float sample_rate, float voiced_threshold,
171 float sine_amp, float noise_std);
172
173/* Same geometry/state contract, with an explicit weighted FP32 FMA phase
174 * interpolation order matching the pinned PyTorch 2.8 CPU upsample path. */
176 const float *f0, size_t f0_capacity,
177 const float *gaussian, size_t gaussian_capacity,
178 float *output, size_t output_capacity,
179 float *phase_scratch, size_t scratch_capacity,
180 size_t frames, size_t upsample, size_t harmonics,
181 float sample_rate, float voiced_threshold,
182 float sine_amp, float noise_std);
183
184#ifdef __cplusplus
185}
186#endif
187
188#endif
int audio_stft_mag_phase_checked_f32(const float *samples, size_t samples_capacity, const float *window, size_t window_capacity, const float *cos_table, const float *sin_table, size_t table_capacity, float *output, size_t output_capacity, size_t output_stride, float *scratch, size_t scratch_capacity, size_t samples_count, size_t n_fft, size_t hop, size_t frames)
int audio_stft_mag_phase_trace_checked_f32(const float *samples, size_t samples_capacity, const float *window, size_t window_capacity, const float *cos_table, const float *sin_table, size_t table_capacity, float *output, size_t output_capacity, size_t output_stride, float *scratch, size_t scratch_capacity, size_t samples_count, size_t n_fft, size_t hop, size_t frames, double *complex_trace, size_t complex_trace_capacity)
int audio_stft_mag_phase_plan_f32(size_t samples, size_t n_fft, size_t hop, size_t *frames, size_t *spectral_elements)
int audio_istft_mag_phase_f32(const float *magnitude, const float *phase, size_t spectral_elements, size_t frames, size_t n_fft, size_t hop, float *output, size_t output_capacity, float *scratch, size_t scratch_elements)
int audio_istft_mag_phase_plan_f32(size_t frames, size_t n_fft, size_t hop, size_t *spectral_elements, size_t *output_samples, size_t *scratch_elements)
int ck_kokoro_plan_shape_v8(const int32_t *durations, size_t phoneme_count, const CKKokoroShapeLimitsV8 *limits, CKKokoroShapeV8 *shape)
int audio_duration_logits_to_frames_f32(const float *logits, size_t input_elements, size_t tokens, size_t bins, size_t input_stride, float speed, int32_t *durations, size_t duration_capacity, size_t max_duration_per_token, size_t max_expanded_frames, int32_t *expanded_frames)
int audio_duration_expand_channel_major_f32(const float *features, size_t input_elements, size_t channels, size_t phoneme_count, size_t input_stride, const int32_t *durations, size_t expanded_frames, float *output, size_t output_elements, size_t output_stride)
CKAudioExtentStatus
Definition ckernel_tts.h:40
@ CK_AUDIO_EXTENT_INVALID
Definition ckernel_tts.h:42
@ CK_AUDIO_EXTENT_LIMIT
Definition ckernel_tts.h:43
@ CK_AUDIO_EXTENT_OVERFLOW
Definition ckernel_tts.h:44
@ CK_AUDIO_EXTENT_OK
Definition ckernel_tts.h:41
int audio_harmonic_source_weighted_fma_checked_f32(const float *f0, size_t f0_capacity, const float *gaussian, size_t gaussian_capacity, float *output, size_t output_capacity, float *phase_scratch, size_t scratch_capacity, size_t frames, size_t upsample, size_t harmonics, float sample_rate, float voiced_threshold, float sine_amp, float noise_std)
int audio_spectral_head_mag_phase_f32(const float *input, size_t input_elements, size_t input_stride, float *magnitude, size_t magnitude_elements, float *phase, size_t phase_elements, size_t bins, size_t frames)
int audio_harmonic_source_checked_f32(const float *f0, size_t f0_capacity, const float *gaussian, size_t gaussian_capacity, float *output, size_t output_capacity, float *phase_scratch, size_t scratch_capacity, size_t frames, size_t upsample, size_t harmonics, float sample_rate, float voiced_threshold, float sine_amp, float noise_std)
int audio_noise_counter_gaussian_f32(float *output, size_t output_capacity, size_t count, uint64_t seed, uint64_t stream)
size_t max_duration_per_phoneme
Definition ckernel_tts.h:16
size_t generator_upsample_rate_0
Definition ckernel_tts.h:23
size_t generator_upsample_rate_1
Definition ckernel_tts.h:24
size_t alignment_elements
Definition ckernel_tts.h:32
size_t output_samples_upper_bound
Definition ckernel_tts.h:37
size_t expanded_frames
Definition ckernel_tts.h:31
size_t istft_padded_samples
Definition ckernel_tts.h:36
size_t istft_frames
Definition ckernel_tts.h:35
size_t generator_samples
Definition ckernel_tts.h:34
size_t decoder_frames
Definition ckernel_tts.h:33
const uint8_t size_t count
Definition true_bpe.h:209