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

Go to the source code of this file.

Functions

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)
 

Function Documentation

◆ audio_duration_expand_token_major_f32()

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 
)

Definition at line 6 of file audio_duration_expand_token_major.c.

16 {
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}
@ 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

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