← Back to C-Kernel-Engine Docs Doxygen Source Documentation
 
Loading...
Searching...
No Matches
audio_duration_expand_token_major.c
Go to the documentation of this file.
2#include "ckernel_tts.h"
3
4#include <stdint.h>
5
7 const float *features,
8 size_t input_elements,
9 size_t channels,
10 size_t phoneme_count,
11 size_t input_stride,
12 const int32_t *durations,
13 size_t expanded_frames,
14 float *output,
15 size_t output_elements,
16 size_t output_stride) {
17 if (!features || !durations || !output || !channels || !phoneme_count ||
18 !expanded_frames || input_stride < channels ||
19 output_stride < expanded_frames) return CK_AUDIO_EXTENT_INVALID;
20 if (phoneme_count - 1 > (SIZE_MAX - channels) / input_stride ||
21 channels - 1 > (SIZE_MAX - expanded_frames) / output_stride)
23 const size_t required_input = (phoneme_count - 1) * input_stride + channels;
24 const size_t required_output = (channels - 1) * output_stride + expanded_frames;
25 if (required_input > SIZE_MAX / sizeof(float) ||
26 required_output > SIZE_MAX / sizeof(float)) return CK_AUDIO_EXTENT_OVERFLOW;
27 if (input_elements < required_input || output_elements < required_output)
29
30 size_t sum = 0;
31 for (size_t token = 0; token < phoneme_count; ++token) {
32 if (durations[token] <= 0) return CK_AUDIO_EXTENT_INVALID;
33 if ((size_t)durations[token] > expanded_frames - sum)
35 sum += (size_t)durations[token];
36 }
37 if (sum != expanded_frames) return CK_AUDIO_EXTENT_INVALID;
38
39 size_t frame = 0;
40 for (size_t token = 0; token < phoneme_count; ++token) {
41 const float *row = features + token * input_stride;
42 for (int32_t repeat = 0; repeat < durations[token]; ++repeat) {
43 for (size_t channel = 0; channel < channels; ++channel)
44 output[channel * output_stride + frame] = row[channel];
45 ++frame;
46 }
47 }
48 return CK_AUDIO_EXTENT_OK;
49}
int audio_duration_expand_token_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)
@ 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
const char * token
Definition tokenizer.h:307