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

Go to the source code of this file.

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)
 

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}
@ 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.