← Back to C-Kernel-Engine Docs Doxygen Source Documentation
 
Loading...
Searching...
No Matches
audio_noise_counter.c
Go to the documentation of this file.
1#include "ckernel_tts.h"
3
4#include <math.h>
5#include <stdint.h>
6
7/* Counter-based excitation. Each element depends only on its index, seed and
8 * stream, so requests cannot inherit RNG state from previous calls. The
9 * Box-Muller transform uses FP64 libm and stores FP32 samples. It does not
10 * promise the same random stream as PyTorch. */
11static uint64_t mix64(uint64_t value) {
12 value += UINT64_C(0x9e3779b97f4a7c15);
13 value = (value ^ (value >> 30)) * UINT64_C(0xbf58476d1ce4e5b9);
14 value = (value ^ (value >> 27)) * UINT64_C(0x94d049bb133111eb);
15 return value ^ (value >> 31);
16}
17
18int audio_noise_counter_gaussian_f32(float *output, size_t output_capacity,
19 size_t count, uint64_t seed, uint64_t stream) {
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)
int audio_noise_counter_gaussian_f32(float *output, size_t output_capacity, size_t count, uint64_t seed, uint64_t stream)
static int ck_checked_region(const float *ptr, size_t n)
@ CK_AUDIO_EXTENT_INVALID
Definition ckernel_tts.h:42
@ CK_AUDIO_EXTENT_LIMIT
Definition ckernel_tts.h:43
@ CK_AUDIO_EXTENT_OK
Definition ckernel_tts.h:41
const uint8_t size_t count
Definition true_bpe.h:209