← Back to C-Kernel-Engine Docs Doxygen Source Documentation
 
Loading...
Searching...
No Matches
ckernel_tts.h File Reference
#include <stddef.h>
#include <stdint.h>

Go to the source code of this file.

Data Structures

struct  CKKokoroShapeLimitsV8
 
struct  CKKokoroShapeV8
 

Enumerations

enum  CKAudioExtentStatus { CK_AUDIO_EXTENT_OK = 0 , CK_AUDIO_EXTENT_INVALID = -1 , CK_AUDIO_EXTENT_LIMIT = -2 , CK_AUDIO_EXTENT_OVERFLOW = -3 }
 

Functions

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)
 
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_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_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_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 audio_noise_counter_gaussian_f32 (float *output, size_t output_capacity, size_t count, uint64_t seed, uint64_t stream)
 
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_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_plan_f32 (size_t samples, size_t n_fft, size_t hop, size_t *frames, size_t *spectral_elements)
 
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 ck_kokoro_plan_shape_v8 (const int32_t *durations, size_t phoneme_count, const CKKokoroShapeLimitsV8 *limits, CKKokoroShapeV8 *shape)
 

Enumeration Type Documentation

◆ CKAudioExtentStatus

Enumerator
CK_AUDIO_EXTENT_OK 
CK_AUDIO_EXTENT_INVALID 
CK_AUDIO_EXTENT_LIMIT 
CK_AUDIO_EXTENT_OVERFLOW 

Definition at line 40 of file ckernel_tts.h.

40 {
45};
@ 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

Function Documentation

◆ audio_duration_expand_channel_major_f32()

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 
)

Definition at line 5 of file audio_duration_expand.c.

15 {
16 if (!features || !durations || !output || !channels || !phoneme_count ||
17 !expanded_frames || input_stride < phoneme_count ||
18 output_stride < expanded_frames) return CK_AUDIO_EXTENT_INVALID;
19 if (channels - 1 > (SIZE_MAX - phoneme_count) / input_stride ||
20 channels - 1 > (SIZE_MAX - expanded_frames) / output_stride)
22 const size_t required_input = (channels - 1) * input_stride + phoneme_count;
23 const size_t required_output = (channels - 1) * output_stride + expanded_frames;
24 if (required_input > SIZE_MAX / sizeof(float) ||
25 required_output > SIZE_MAX / sizeof(float)) return CK_AUDIO_EXTENT_OVERFLOW;
26 if (input_elements < required_input || output_elements < required_output)
28
29 size_t sum = 0;
30 for (size_t token = 0; token < phoneme_count; ++token) {
31 if (durations[token] <= 0) return CK_AUDIO_EXTENT_INVALID;
32 if ((size_t)durations[token] > expanded_frames - sum)
34 sum += (size_t)durations[token];
35 }
36 if (sum != expanded_frames) return CK_AUDIO_EXTENT_INVALID;
37
38 for (size_t channel = 0; channel < channels; ++channel) {
39 size_t frame = 0;
40 for (size_t token = 0; token < phoneme_count; ++token) {
41 const float value = features[channel * input_stride + token];
42 for (int32_t j = 0; j < durations[token]; ++j) {
43 output[channel * output_stride + frame++] = value;
44 }
45 }
46 }
47 return CK_AUDIO_EXTENT_OK;
48}
const char * token
Definition tokenizer.h:307

References CK_AUDIO_EXTENT_INVALID, CK_AUDIO_EXTENT_LIMIT, CK_AUDIO_EXTENT_OK, CK_AUDIO_EXTENT_OVERFLOW, and token.

◆ audio_duration_logits_to_frames_f32()

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 
)

Definition at line 43 of file audio_duration_logits.c.

47 {
48 if (!logits || !durations || !expanded_frames || !tokens || !bins ||
49 input_stride < bins || !isfinite(speed) || speed <= 0.0f ||
50 !max_duration_per_token || max_duration_per_token > INT32_MAX ||
51 !max_expanded_frames || max_expanded_frames > INT32_MAX)
53 if (tokens - 1 > (SIZE_MAX - bins) / input_stride ||
54 tokens > SIZE_MAX / sizeof(int32_t))
56 const size_t required_input = (tokens - 1) * input_stride + bins;
57 if (required_input > SIZE_MAX / sizeof(float))
59 if (input_elements < required_input || duration_capacity < tokens)
61
62 size_t total = 0;
63 for (size_t token = 0; token < tokens; ++token) {
64 int32_t frames = 0;
65 const int rc = token_frames(logits + token * input_stride, bins, speed,
66 max_duration_per_token, &frames);
67 if (rc != CK_AUDIO_EXTENT_OK) return rc;
68 if ((size_t)frames > max_expanded_frames - total)
70 total += (size_t)frames;
71 }
72
73 for (size_t token = 0; token < tokens; ++token) {
74 int32_t frames = 0;
75 /* The first pass validated all inputs and capacities. */
76 (void)token_frames(logits + token * input_stride, bins, speed,
77 max_duration_per_token, &frames);
78 durations[token] = frames;
79 }
80 *expanded_frames = (int32_t)total;
81 return CK_AUDIO_EXTENT_OK;
82}
static int token_frames(const float *logits, size_t bins, float speed, size_t max_duration_per_token, int32_t *frames)

References CK_AUDIO_EXTENT_INVALID, CK_AUDIO_EXTENT_LIMIT, CK_AUDIO_EXTENT_OK, CK_AUDIO_EXTENT_OVERFLOW, token, and token_frames().

◆ audio_harmonic_source_checked_f32()

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 
)

Definition at line 106 of file audio_harmonic_source_checked.c.

113 {
114 return audio_harmonic_source_impl_f32(f0, f0_capacity, gaussian,
115 gaussian_capacity, output, output_capacity, phase_scratch,
116 scratch_capacity, frames, upsample, harmonics, sample_rate,
117 voiced_threshold, sine_amp, noise_std, 0);
118}
static int audio_harmonic_source_impl_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 weighted_fma_interpolation)

References audio_harmonic_source_impl_f32().

◆ audio_harmonic_source_weighted_fma_checked_f32()

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 
)

Definition at line 120 of file audio_harmonic_source_checked.c.

127 {
128 return audio_harmonic_source_impl_f32(f0, f0_capacity, gaussian,
129 gaussian_capacity, output, output_capacity, phase_scratch,
130 scratch_capacity, frames, upsample, harmonics, sample_rate,
131 voiced_threshold, sine_amp, noise_std, 1);
132}

References audio_harmonic_source_impl_f32().

◆ audio_istft_mag_phase_f32()

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 
)

Definition at line 50 of file audio_istft_mag_phase.c.

60 {
61 if (!magnitude || !phase || !output || !scratch)
63 size_t required_spectrum, output_samples, required_scratch;
65 frames, n_fft, hop, &required_spectrum, &output_samples,
66 &required_scratch);
67 if (status != CK_AUDIO_EXTENT_OK) return status;
68 if (spectral_elements < required_spectrum ||
69 output_capacity < output_samples ||
70 scratch_elements < required_scratch) return CK_AUDIO_EXTENT_LIMIT;
71 for (size_t i = 0; i < required_spectrum; ++i) {
72 if (!isfinite(magnitude[i]) || !isfinite(phase[i]) || magnitude[i] < 0.0f)
74 }
75
76 const size_t padded_samples = output_samples + n_fft;
77 float *overlap = scratch;
78 float *window_sum = overlap + padded_samples;
79 float *window = window_sum + padded_samples;
80 memset(overlap, 0, padded_samples * sizeof(float));
81 memset(window_sum, 0, padded_samples * sizeof(float));
82 const float tau = 6.2831853071795864769f;
83 for (size_t n = 0; n < n_fft; ++n)
84 window[n] = 0.5f - 0.5f * cosf(tau * (float)n / (float)n_fft);
85
86 const size_t bins = n_fft / 2 + 1;
87 const float inverse_n = 1.0f / (float)n_fft;
88 for (size_t frame = 0; frame < frames; ++frame) {
89 const size_t base = frame * bins;
90 const size_t offset = frame * hop;
91 for (size_t n = 0; n < n_fft; ++n) {
92 float acc = magnitude[base] * cosf(phase[base]);
93 const size_t nyquist = bins - 1;
94 float end = magnitude[base + nyquist] * cosf(phase[base + nyquist]);
95 acc += (n & 1) ? -end : end;
96 for (size_t k = 1; k < nyquist; ++k) {
97 const float real = magnitude[base + k] * cosf(phase[base + k]);
98 const float imag = magnitude[base + k] * sinf(phase[base + k]);
99 const float angle = tau * (float)k * (float)n / (float)n_fft;
100 acc += 2.0f * (real * cosf(angle) - imag * sinf(angle));
101 }
102 const float w = window[n];
103 overlap[offset + n] += acc * inverse_n * w;
104 window_sum[offset + n] += w * w;
105 }
106 }
107
108 const size_t left_trim = n_fft / 2;
109 for (size_t i = 0; i < output_samples; ++i) {
110 const size_t pos = left_trim + i;
111 const float norm = window_sum[pos];
112 if (!(norm > 1e-11f)) return CK_AUDIO_EXTENT_INVALID;
113 if (!isfinite(overlap[pos] / norm)) return CK_AUDIO_EXTENT_INVALID;
114 }
115 for (size_t i = 0; i < output_samples; ++i) {
116 const size_t pos = left_trim + i;
117 output[i] = overlap[pos] / window_sum[pos];
118 }
119 return CK_AUDIO_EXTENT_OK;
120}
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)
uint32_t end
Definition utf8.c:215

References audio_istft_mag_phase_plan_f32(), CK_AUDIO_EXTENT_INVALID, CK_AUDIO_EXTENT_LIMIT, CK_AUDIO_EXTENT_OK, and end.

◆ audio_istft_mag_phase_plan_f32()

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 
)

Definition at line 19 of file audio_istft_mag_phase.c.

25 {
26 if (!spectral_elements || !output_samples || !scratch_elements ||
27 frames < 2 || n_fft < 2 || (n_fft & 1) || !hop || hop > n_fft / 2) {
29 }
30 size_t bins = n_fft / 2 + 1;
31 size_t spectrum, output, padded, scratch;
32 if (!mul_size(frames, bins, &spectrum) ||
33 !mul_size(frames - 1, hop, &output) ||
34 !add_size(output, n_fft, &padded) ||
35 !mul_size(padded, 2, &scratch) ||
36 !add_size(scratch, n_fft, &scratch)) {
38 }
39 if (spectrum > SIZE_MAX / sizeof(float) ||
40 output > SIZE_MAX / sizeof(float) ||
41 scratch > SIZE_MAX / sizeof(float)) {
43 }
44 *spectral_elements = spectrum;
45 *output_samples = output;
46 *scratch_elements = scratch;
47 return CK_AUDIO_EXTENT_OK;
48}
static int mul_size(size_t a, size_t b, size_t *out)
static int add_size(size_t a, size_t b, size_t *out)

References add_size(), CK_AUDIO_EXTENT_INVALID, CK_AUDIO_EXTENT_OK, CK_AUDIO_EXTENT_OVERFLOW, and mul_size().

Referenced by audio_istft_mag_phase_f32().

◆ audio_noise_counter_gaussian_f32()

int audio_noise_counter_gaussian_f32 ( float *  output,
size_t  output_capacity,
size_t  count,
uint64_t  seed,
uint64_t  stream 
)

Definition at line 18 of file audio_noise_counter.c.

19 {
20 if (!count) return CK_AUDIO_EXTENT_INVALID;
21 if (count > (1u << 24) || output_capacity < count)
24 const uint64_t domain = mix64(seed ^ mix64(stream));
25 for (size_t index = 0; index < count; ++index) {
26 const uint64_t counter = (uint64_t)index * UINT64_C(2);
27 const uint64_t first = mix64(domain + counter);
28 const uint64_t second = mix64(domain + counter + UINT64_C(1));
29 const double uniform_positive =
30 ((double)(first >> 11) + 0.5) * 0x1.0p-53;
31 const double uniform_angle = (double)(second >> 11) * 0x1.0p-53;
32 const double radius = sqrt(-2.0 * log(uniform_positive));
33 output[index] = (float)(radius * cos(
34 6.283185307179586476925286766559 * uniform_angle));
35 }
36 return CK_AUDIO_EXTENT_OK;
37}
static uint64_t mix64(uint64_t value)
static int ck_checked_region(const float *ptr, size_t n)
const uint8_t size_t count
Definition true_bpe.h:209

References CK_AUDIO_EXTENT_INVALID, CK_AUDIO_EXTENT_LIMIT, CK_AUDIO_EXTENT_OK, ck_checked_region(), count, and mix64().

◆ audio_spectral_head_mag_phase_f32()

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 
)

Definition at line 21 of file audio_spectral_head.c.

25 {
26 if (!input || !magnitude || !phase || !bins || !frames ||
27 input_stride < frames) return CK_AUDIO_EXTENT_INVALID;
28
29 size_t channels, input_required, output_required;
30 if (!product(bins, 2, &channels) ||
31 !product(channels, input_stride, &input_required) ||
32 !product(bins, frames, &output_required) ||
33 input_required > SIZE_MAX / sizeof(float) ||
34 output_required > SIZE_MAX / sizeof(float))
36 if (input_elements < input_required ||
37 magnitude_elements < output_required ||
38 phase_elements < output_required) return CK_AUDIO_EXTENT_LIMIT;
39
40 const size_t input_bytes = input_required * sizeof(float);
41 const size_t output_bytes = output_required * sizeof(float);
42 if (overlaps(input, input_bytes, magnitude, output_bytes) ||
43 overlaps(input, input_bytes, phase, output_bytes) ||
44 overlaps(magnitude, output_bytes, phase, output_bytes))
46
47 for (size_t bin = 0; bin < bins; ++bin) {
48 for (size_t frame = 0; frame < frames; ++frame) {
49 const float log_magnitude = input[bin * input_stride + frame];
50 const float raw_phase = input[(bins + bin) * input_stride + frame];
51 if (!isfinite(log_magnitude) || !isfinite(raw_phase) ||
52 !isfinite(expf(log_magnitude)))
54 }
55 }
56 for (size_t frame = 0; frame < frames; ++frame) {
57 for (size_t bin = 0; bin < bins; ++bin) {
58 const size_t output_index = frame * bins + bin;
59 magnitude[output_index] = expf(input[bin * input_stride + frame]);
60 phase[output_index] = sinf(input[(bins + bin) * input_stride + frame]);
61 }
62 }
63 return CK_AUDIO_EXTENT_OK;
64}
static int overlaps(const void *a, size_t a_bytes, const void *b, size_t b_bytes)
static int product(size_t a, size_t b, size_t *out)

References CK_AUDIO_EXTENT_INVALID, CK_AUDIO_EXTENT_LIMIT, CK_AUDIO_EXTENT_OK, CK_AUDIO_EXTENT_OVERFLOW, overlaps(), and product().

◆ audio_stft_mag_phase_checked_f32()

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 
)

Definition at line 133 of file audio_stft_mag_phase_checked.c.

138 {
139 return stft_mag_phase_impl(samples, samples_capacity, window,
140 window_capacity, cos_table, sin_table, table_capacity, output,
141 output_capacity, output_stride, scratch, scratch_capacity,
142 samples_count, n_fft, hop, frames, NULL, 0);
143}
static int stft_mag_phase_impl(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)

References stft_mag_phase_impl().

◆ audio_stft_mag_phase_plan_f32()

int audio_stft_mag_phase_plan_f32 ( size_t  samples,
size_t  n_fft,
size_t  hop,
size_t *  frames,
size_t *  spectral_elements 
)

Definition at line 8 of file audio_stft_mag_phase_checked.c.

9 {
10 if (!frames || !spectral_elements || n_fft < 2 || (n_fft & 1) ||
11 !hop || samples <= n_fft / 2 || samples > INT64_MAX / 2 ||
12 n_fft > INT64_MAX / 2 || samples > SIZE_MAX / sizeof(float) ||
13 n_fft > SIZE_MAX / sizeof(float)) return CK_AUDIO_EXTENT_INVALID;
14 const size_t count = samples / hop + 1;
15 const size_t bins = n_fft / 2 + 1;
16 if (count > SIZE_MAX / (2 * bins) ||
17 count * (2 * bins) > SIZE_MAX / sizeof(float))
19 *frames = count;
20 *spectral_elements = count * 2 * bins;
21 return CK_AUDIO_EXTENT_OK;
22}

References CK_AUDIO_EXTENT_INVALID, CK_AUDIO_EXTENT_OK, CK_AUDIO_EXTENT_OVERFLOW, and count.

Referenced by stft_mag_phase_impl().

◆ audio_stft_mag_phase_trace_checked_f32()

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 
)

Definition at line 147 of file audio_stft_mag_phase_checked.c.

153 {
154 if (!complex_trace) return CK_AUDIO_EXTENT_INVALID;
155 return stft_mag_phase_impl(samples, samples_capacity, window,
156 window_capacity, cos_table, sin_table, table_capacity, output,
157 output_capacity, output_stride, scratch, scratch_capacity,
158 samples_count, n_fft, hop, frames, complex_trace,
159 complex_trace_capacity);
160}

References CK_AUDIO_EXTENT_INVALID, and stft_mag_phase_impl().

◆ ck_kokoro_plan_shape_v8()

int ck_kokoro_plan_shape_v8 ( const int32_t *  durations,
size_t  phoneme_count,
const CKKokoroShapeLimitsV8 *  limits,
CKKokoroShapeV8 *  shape 
)

Definition at line 18 of file kokoro_shape_bounds.c.

22 {
23 if (!durations || !limits || !shape || !phoneme_count ||
24 !limits->max_phonemes || !limits->max_duration_per_phoneme ||
25 !limits->max_expanded_frames || !limits->max_generator_samples ||
26 !limits->max_output_samples || !limits->max_alignment_elements ||
27 !limits->alignment_channels || !limits->decoder_upsample_factor ||
29 !limits->istft_hop_size || !limits->istft_fft_size) {
31 }
32 memset(shape, 0, sizeof(*shape));
33 if (phoneme_count > limits->max_phonemes) return CK_AUDIO_EXTENT_LIMIT;
34
35 size_t frames = 0;
36 for (size_t i = 0; i < phoneme_count; ++i) {
37 if (durations[i] <= 0) return CK_AUDIO_EXTENT_INVALID;
38 if ((size_t)durations[i] > limits->max_duration_per_phoneme)
40 if (!checked_add(frames, (size_t)durations[i], &frames))
42 if (frames > limits->max_expanded_frames)
44 }
45
46 size_t align, decoder, generator, istft_frames, padded, output;
47 if (!checked_mul(frames, limits->alignment_channels, &align) ||
48 !checked_mul(frames, limits->decoder_upsample_factor, &decoder) ||
49 !checked_mul(decoder, limits->generator_upsample_rate_0, &generator) ||
50 !checked_mul(generator, limits->generator_upsample_rate_1, &generator) ||
51 !checked_add(generator / limits->istft_hop_size, 1, &istft_frames) ||
52 !checked_add(generator, limits->istft_fft_size, &padded) ||
53 !checked_add(generator, limits->istft_fft_size, &output)) {
55 }
56 if (align > SIZE_MAX / sizeof(float) ||
57 decoder > SIZE_MAX / sizeof(float) ||
58 generator > SIZE_MAX / sizeof(float) ||
59 padded > SIZE_MAX / sizeof(float) ||
60 output > SIZE_MAX / sizeof(float)) {
62 }
63 if (align > limits->max_alignment_elements ||
64 generator > limits->max_generator_samples ||
65 output > limits->max_output_samples) {
67 }
68
69 shape->phonemes = phoneme_count;
70 shape->expanded_frames = frames;
71 shape->alignment_elements = align;
72 shape->decoder_frames = decoder;
73 shape->generator_samples = generator;
74 shape->istft_frames = istft_frames;
75 shape->istft_padded_samples = padded;
76 shape->output_samples_upper_bound = output;
77 return CK_AUDIO_EXTENT_OK;
78}
static int checked_add(size_t a, size_t b, size_t *out)
static int checked_mul(size_t a, size_t b, size_t *out)
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

References CKKokoroShapeLimitsV8::alignment_channels, CKKokoroShapeV8::alignment_elements, checked_add(), checked_mul(), CK_AUDIO_EXTENT_INVALID, CK_AUDIO_EXTENT_LIMIT, CK_AUDIO_EXTENT_OK, CK_AUDIO_EXTENT_OVERFLOW, CKKokoroShapeV8::decoder_frames, CKKokoroShapeLimitsV8::decoder_upsample_factor, CKKokoroShapeV8::expanded_frames, CKKokoroShapeV8::generator_samples, CKKokoroShapeLimitsV8::generator_upsample_rate_0, CKKokoroShapeLimitsV8::generator_upsample_rate_1, CKKokoroShapeLimitsV8::istft_fft_size, CKKokoroShapeV8::istft_frames, CKKokoroShapeLimitsV8::istft_hop_size, CKKokoroShapeV8::istft_padded_samples, CKKokoroShapeLimitsV8::max_alignment_elements, CKKokoroShapeLimitsV8::max_duration_per_phoneme, CKKokoroShapeLimitsV8::max_expanded_frames, CKKokoroShapeLimitsV8::max_generator_samples, CKKokoroShapeLimitsV8::max_output_samples, CKKokoroShapeLimitsV8::max_phonemes, CKKokoroShapeV8::output_samples_upper_bound, and CKKokoroShapeV8::phonemes.