← Back to C-Kernel-Engine Docs Doxygen Source Documentation
 
Loading...
Searching...
No Matches
ckernel_audio.h
Go to the documentation of this file.
1#ifndef CKERNEL_AUDIO_H
2#define CKERNEL_AUDIO_H
3
4#include <stdint.h>
5#include <stddef.h>
6
7#ifdef __cplusplus
8extern "C" {
9#endif
10
11#define CK_AUDIO_WHISPER_SAMPLE_RATE 16000
12#define CK_AUDIO_WHISPER_N_FFT 400
13#define CK_AUDIO_WHISPER_HOP_LENGTH 160
14#define CK_AUDIO_WHISPER_POWER_BINS 201
15
25
27 const uint8_t *bytes,
28 size_t byte_count,
29 CKAudioWavInfo *info);
30
32 const uint8_t *bytes,
33 size_t byte_count,
34 const CKAudioWavInfo *info,
35 float *mono,
36 int mono_capacity);
37
39 const uint8_t *bytes,
40 size_t byte_count,
41 float *mono,
42 int mono_capacity,
43 CKAudioWavInfo *info);
44
46 const uint8_t *bytes,
47 size_t byte_count,
48 int start_frame,
49 float *mono,
50 int mono_capacity,
51 CKAudioWavInfo *info);
52
54 const int16_t *interleaved,
55 int n_frames,
56 int n_channels,
57 float *mono);
58
60 int input_frames,
61 int input_rate,
62 int output_rate);
63
65 const float *input,
66 int input_frames,
67 int input_rate,
68 float *output,
69 int output_frames,
70 int output_rate);
71
73 const float *input,
74 int input_frames,
75 int input_rate,
76 float *output,
77 int output_frames,
78 int output_rate,
79 int radius);
80
82 const float *input,
83 int input_frames,
84 float *output,
85 int output_frames);
86
88 float *output,
89 int frames,
90 int periodic);
91
93 const float *input,
94 float *output,
95 int frames,
96 float coefficient);
97
99 const float *input,
100 float *output,
101 int channels,
102 int frames,
103 float epsilon);
104
106 float *output,
107 int frames,
108 int channels);
109
111 const float *input,
112 const float *running_mean,
113 const float *running_variance,
114 const float *weight,
115 const float *bias,
116 float *output,
117 int channels,
118 int frames,
119 float epsilon);
120
122 const float *input,
123 const float *weight_ih,
124 const float *weight_hh,
125 const float *bias_ih,
126 const float *bias_hh,
127 float *hidden_state,
128 float *cell_state,
129 float *output,
130 float *gates_scratch,
131 size_t gates_scratch_bytes,
132 int input_size,
133 int hidden_size);
134
135/* Packed direction-major weights: [2, 4*H, I] and [2, 4*H, H].
136 * H must be at most INT_MAX/4 because the IFGO step uses signed gate indices.
137 * Output rows are [forward H, reverse H]. State is reset at each call.
138 * Returns -1 for null pointers, -2 for invalid/overflowing geometry,
139 * and -3 for insufficient input, weight, output, state or scratch capacity.
140 */
142 const float *input, size_t input_elements,
143 const float *weight_ih, size_t weight_ih_elements,
144 const float *weight_hh, size_t weight_hh_elements,
145 const float *bias_ih, size_t bias_ih_elements,
146 const float *bias_hh, size_t bias_hh_elements,
147 float *output, size_t output_elements,
148 float *hidden_state, size_t hidden_state_elements,
149 float *cell_state, size_t cell_state_elements,
150 float *gates_scratch, size_t gates_scratch_bytes,
151 int tokens, int input_size, int hidden_size,
152 size_t input_stride, size_t output_stride);
153
154/* Token-major adaptive LayerNorm: gamma,beta = linear(style), then
155 * (1 + gamma) * layer_norm(input, epsilon) + beta on each token.
156 * Projection weights are [2*channels, style_dim], output-feature major.
157 * All capacities are explicit; scratch needs 2*channels floats.
158 * Returns -1 null, -2 invalid/overflowing geometry, -3 capacity,
159 * -4 nonfinite input or result. Output is unchanged on rejection.
160 */
162 const float *input, size_t input_elements,
163 const float *style, size_t style_elements,
164 const float *projection_weight, size_t projection_weight_elements,
165 const float *projection_bias, size_t projection_bias_elements,
166 float *output, size_t output_elements,
167 float *projection_scratch, size_t projection_scratch_bytes,
168 int tokens, int channels, int style_dim,
169 size_t input_stride, size_t output_stride, float epsilon);
170
171/* Channel-major InstanceNorm1d affine followed by style affine. Statistics
172 * use only valid frames, with biased variance. Style affine is [gamma, beta]
173 * of length 2*channels, ordinarily produced by a separate linear operation.
174 * Input/output strides are physical frame capacities. Returns -1 for invalid
175 * geometry, -2 for short buffers, -3 for nonfinite input or result. Output is
176 * unchanged on rejection; no hidden allocation or persistent state.
177 */
179 const float *input, size_t input_elements, size_t input_stride,
180 const float *norm_weight, size_t norm_weight_elements,
181 const float *norm_bias, size_t norm_bias_elements,
182 const float *style_affine, size_t style_affine_elements,
183 float *output, size_t output_elements, size_t output_stride,
184 size_t channels, size_t frames, float epsilon);
185
187 int n_fft,
188 float *window,
189 float *cos_table,
190 float *sin_table);
191
193 int sample_rate,
194 int n_fft,
195 int n_mels,
196 float *mel_filters);
197
199 const float *samples,
200 int n_samples,
201 const float *window,
202 const float *cos_table,
203 const float *sin_table,
204 int n_fft,
205 int hop_length,
206 float *power,
207 int n_frames);
208
210 const float *samples,
211 int n_samples,
212 const float *window,
213 int window_length,
214 const float *cos_table,
215 const float *sin_table,
216 int n_fft,
217 int hop_length,
218 int reflect_padding,
219 float *power,
220 int n_frames);
221
223 const float *power,
224 const float *mel_filters,
225 float *log_mel,
226 int frames,
227 int bins,
228 int channels,
229 float epsilon);
230
232 const float *samples,
233 int n_samples,
234 const float *window,
235 const float *cos_table,
236 const float *sin_table,
237 int hop_length,
238 float *power,
239 int n_frames,
240 float *fft_scratch);
241
243 const float *input,
244 const float *weight,
245 const float *bias,
246 float *output,
247 int input_channels,
248 int output_channels,
249 int input_frames,
250 int kernel_size,
251 int stride,
252 int padding,
253 int output_frames);
254
256 const float *input,
257 const float *weight,
258 const float *bias,
259 float *output,
260 int input_channels,
261 int output_channels,
262 int input_frames,
263 int kernel_size,
264 int stride,
265 int padding,
266 int groups,
267 int output_frames);
268
270 const float *input,
271 const float *weight,
272 const float *bias,
273 float *output,
274 int input_width,
275 int input_height,
276 int input_channels,
277 int output_channels,
278 int kernel_width,
279 int kernel_height,
280 int stride_width,
281 int stride_height,
282 int padding_width,
283 int padding_height,
284 int groups,
285 int output_width,
286 int output_height);
287
289 int feature_frames,
290 int feature_channels,
291 int conv_channels,
292 int kernel_size,
293 int stride);
294
296 const float *features,
297 const float *conv0_weight,
298 const float *conv0_bias,
299 const float *depthwise1_weight,
300 const float *depthwise1_bias,
301 const float *pointwise1_weight,
302 const float *pointwise1_bias,
303 const float *depthwise2_weight,
304 const float *depthwise2_bias,
305 const float *pointwise2_weight,
306 const float *pointwise2_bias,
307 const float *linear_weight,
308 const float *linear_bias,
309 float *output,
310 void *workspace,
311 size_t workspace_bytes,
312 int feature_frames,
313 int live_frames,
314 int feature_channels,
315 int conv_channels,
316 int hidden_size,
317 int kernel_size,
318 int stride,
319 int output_capacity_frames,
320 int *output_frames);
321
322/*
323 * Returns the recommended workspace for the configured CK thread pool. The
324 * block also accepts the compatible minimum allocation with one score row per
325 * attention head and caps attention workers to the supplied score capacity.
326 */
328 int frames,
329 int hidden_size,
330 int intermediate_size,
331 int heads);
332
334 const float *input,
335 const float *relative_positions,
336 const float *ff1_norm_weight,
337 const float *ff1_norm_bias,
338 const float *ff1_up_weight,
339 const float *ff1_up_bias,
340 const float *ff1_down_weight,
341 const float *ff1_down_bias,
342 const float *attn_norm_weight,
343 const float *attn_norm_bias,
344 const float *q_weight,
345 const float *q_bias,
346 const float *k_weight,
347 const float *k_bias,
348 const float *v_weight,
349 const float *v_bias,
350 const float *relative_weight,
351 const float *attn_bias_u,
352 const float *attn_bias_v,
353 const float *attn_out_weight,
354 const float *attn_out_bias,
355 const float *conv_norm_weight,
356 const float *conv_norm_bias,
357 const float *conv_pw1_weight,
358 const float *conv_pw1_bias,
359 const float *conv_dw_weight,
360 const float *conv_dw_bias,
361 const float *conv_bn_mean,
362 const float *conv_bn_variance,
363 const float *conv_bn_weight,
364 const float *conv_bn_bias,
365 const float *conv_pw2_weight,
366 const float *conv_pw2_bias,
367 const float *ff2_norm_weight,
368 const float *ff2_norm_bias,
369 const float *ff2_up_weight,
370 const float *ff2_up_bias,
371 const float *ff2_down_weight,
372 const float *ff2_down_bias,
373 const float *out_norm_weight,
374 const float *out_norm_bias,
375 float *output,
376 void *workspace,
377 size_t workspace_bytes,
378 int frames,
379 int hidden_size,
380 int intermediate_size,
381 int heads,
382 int head_dim,
383 int conv_kernel_size,
384 float layer_norm_epsilon,
385 float batch_norm_epsilon);
386
388 const float *input,
389 float *output,
390 int channels,
391 int frames);
392
394 const float *raw_scores,
395 float *scores,
396 int heads,
397 int query_frames);
398
400 const float *query,
401 const float *key,
402 const float *value,
403 const float *relative_key,
404 const float *bias_u,
405 const float *bias_v,
406 float *output,
407 int frames,
408 int heads,
409 int head_dim,
410 float scale,
411 float *scores_scratch,
412 size_t scores_scratch_bytes);
413
415 const float *input,
416 float *output,
417 int channels,
418 int frames);
419
421 const float *residual,
422 const float *branch,
423 float scale,
424 float *output,
425 size_t elements);
426
428 const float *values,
429 int elements,
430 int *selected);
431
433 const float *samples,
434 int n_samples,
435 float *power,
436 int n_frames);
437
439 const float *power,
440 const float *mel_filters,
441 int n_mels,
442 int n_frames,
443 float *log_mel);
444
446 const uint8_t *bytes,
447 size_t byte_count,
448 int start_frame,
449 int target_sample_rate,
450 const float *window,
451 const float *cos_table,
452 const float *sin_table,
453 const float *mel_filters,
454 int n_mels,
455 int output_frames,
456 float *log_mel);
457
459 const float *samples,
460 int n_samples,
461 const float *mel_filters,
462 int n_mels,
463 float *power_scratch,
464 float *log_mel,
465 int n_frames);
466
467#ifdef __cplusplus
468}
469#endif
470
471#endif
int audio_whisper_mel_filters_slaney_f32(int sample_rate, int n_fft, int n_mels, float *mel_filters)
int audio_lstm_step_f32(const float *input, const float *weight_ih, const float *weight_hh, const float *bias_ih, const float *bias_hh, float *hidden_state, float *cell_state, float *output, float *gates_scratch, size_t gates_scratch_bytes, int input_size, int hidden_size)
int audio_whisper_log_mel_reference_f32(const float *samples, int n_samples, const float *mel_filters, int n_mels, float *power_scratch, float *log_mel, int n_frames)
int audio_stft_power_precomputed_f32(const float *samples, int n_samples, const float *window, const float *cos_table, const float *sin_table, int n_fft, int hop_length, float *power, int n_frames)
int audio_resample_linear_f32(const float *input, int input_frames, int input_rate, float *output, int output_frames, int output_rate)
int audio_wav_parse_memory(const uint8_t *bytes, size_t byte_count, CKAudioWavInfo *info)
int audio_conv2d_whc_grouped_f32(const float *input, const float *weight, const float *bias, float *output, int input_width, int input_height, int input_channels, int output_channels, int kernel_width, int kernel_height, int stride_width, int stride_height, int padding_width, int padding_height, int groups, int output_width, int output_height)
int audio_lstm_bidirectional_scan_f32(const float *input, size_t input_elements, const float *weight_ih, size_t weight_ih_elements, const float *weight_hh, size_t weight_hh_elements, const float *bias_ih, size_t bias_ih_elements, const float *bias_hh, size_t bias_hh_elements, float *output, size_t output_elements, float *hidden_state, size_t hidden_state_elements, float *cell_state, size_t cell_state_elements, float *gates_scratch, size_t gates_scratch_bytes, int tokens, int input_size, int hidden_size, size_t input_stride, size_t output_stride)
int audio_log_mel_time_major_f32(const float *power, const float *mel_filters, float *log_mel, int frames, int bins, int channels, float epsilon)
int audio_conv1d_channel_major_grouped_f32(const float *input, const float *weight, const float *bias, float *output, int input_channels, int output_channels, int input_frames, int kernel_size, int stride, int padding, int groups, int output_frames)
int audio_wav_decode_pcm16_mono_f32(const uint8_t *bytes, size_t byte_count, const CKAudioWavInfo *info, float *mono, int mono_capacity)
int audio_whisper_log_mel_window_wav_pcm16_f32(const uint8_t *bytes, size_t byte_count, int start_frame, int target_sample_rate, const float *window, const float *cos_table, const float *sin_table, const float *mel_filters, int n_mels, int output_frames, float *log_mel)
int audio_batch_norm_inference_channel_major_f32(const float *input, const float *running_mean, const float *running_variance, const float *weight, const float *bias, float *output, int channels, int frames, float epsilon)
size_t audio_fastconformer_subsampling_workspace_bytes(int feature_frames, int feature_channels, int conv_channels, int kernel_size, int stride)
int audio_adaptive_layer_norm_f32(const float *input, size_t input_elements, const float *style, size_t style_elements, const float *projection_weight, size_t projection_weight_elements, const float *projection_bias, size_t projection_bias_elements, float *output, size_t output_elements, float *projection_scratch, size_t projection_scratch_bytes, int tokens, int channels, int style_dim, size_t input_stride, size_t output_stride, float epsilon)
int audio_adain_instance_norm_f32(const float *input, size_t input_elements, size_t input_stride, const float *norm_weight, size_t norm_weight_elements, const float *norm_bias, size_t norm_bias_elements, const float *style_affine, size_t style_affine_elements, float *output, size_t output_elements, size_t output_stride, size_t channels, size_t frames, float epsilon)
int audio_preemphasis_f32(const float *input, float *output, int frames, float coefficient)
int audio_scaled_residual_add_f32(const float *residual, const float *branch, float scale, float *output, size_t elements)
int audio_relative_shift_f32(const float *raw_scores, float *scores, int heads, int query_frames)
int audio_argmax_first_f32(const float *values, int elements, int *selected)
int audio_whisper_stft_power_reference_f32(const float *samples, int n_samples, float *power, int n_frames)
int audio_stft_power_centered_window_f32(const float *samples, int n_samples, const float *window, int window_length, const float *cos_table, const float *sin_table, int n_fft, int hop_length, int reflect_padding, float *power, int n_frames)
int audio_stft_precompute_tables_f32(int n_fft, float *window, float *cos_table, float *sin_table)
int audio_fastconformer_block_f32(const float *input, const float *relative_positions, const float *ff1_norm_weight, const float *ff1_norm_bias, const float *ff1_up_weight, const float *ff1_up_bias, const float *ff1_down_weight, const float *ff1_down_bias, const float *attn_norm_weight, const float *attn_norm_bias, const float *q_weight, const float *q_bias, const float *k_weight, const float *k_bias, const float *v_weight, const float *v_bias, const float *relative_weight, const float *attn_bias_u, const float *attn_bias_v, const float *attn_out_weight, const float *attn_out_bias, const float *conv_norm_weight, const float *conv_norm_bias, const float *conv_pw1_weight, const float *conv_pw1_bias, const float *conv_dw_weight, const float *conv_dw_bias, const float *conv_bn_mean, const float *conv_bn_variance, const float *conv_bn_weight, const float *conv_bn_bias, const float *conv_pw2_weight, const float *conv_pw2_bias, const float *ff2_norm_weight, const float *ff2_norm_bias, const float *ff2_up_weight, const float *ff2_up_bias, const float *ff2_down_weight, const float *ff2_down_bias, const float *out_norm_weight, const float *out_norm_bias, float *output, void *workspace, size_t workspace_bytes, int frames, int hidden_size, int intermediate_size, int heads, int head_dim, int conv_kernel_size, float layer_norm_epsilon, float batch_norm_epsilon)
int audio_glu_split_channel_major_f32(const float *input, float *output, int channels, int frames)
int audio_conformer_relative_attention_f32(const float *query, const float *key, const float *value, const float *relative_key, const float *bias_u, const float *bias_v, float *output, int frames, int heads, int head_dim, float scale, float *scores_scratch, size_t scores_scratch_bytes)
int audio_pcm_s16_to_mono_f32(const int16_t *interleaved, int n_frames, int n_channels, float *mono)
int audio_transpose_channel_to_token_f32(const float *input, float *output, int channels, int frames)
int audio_fastconformer_subsampling_f32(const float *features, const float *conv0_weight, const float *conv0_bias, const float *depthwise1_weight, const float *depthwise1_bias, const float *pointwise1_weight, const float *pointwise1_bias, const float *depthwise2_weight, const float *depthwise2_bias, const float *pointwise2_weight, const float *pointwise2_bias, const float *linear_weight, const float *linear_bias, float *output, void *workspace, size_t workspace_bytes, int feature_frames, int live_frames, int feature_channels, int conv_channels, int hidden_size, int kernel_size, int stride, int output_capacity_frames, int *output_frames)
int audio_whisper_log_mel_from_power_reference_f32(const float *power, const float *mel_filters, int n_mels, int n_frames, float *log_mel)
size_t audio_fastconformer_block_workspace_bytes(int frames, int hidden_size, int intermediate_size, int heads)
int audio_feature_normalize_per_feature_f32(const float *input, float *output, int channels, int frames, float epsilon)
int audio_pad_or_truncate_f32(const float *input, int input_frames, float *output, int output_frames)
int audio_conv1d_channel_major_f32(const float *input, const float *weight, const float *bias, float *output, int input_channels, int output_channels, int input_frames, int kernel_size, int stride, int padding, int output_frames)
int audio_resample_windowed_sinc_f32(const float *input, int input_frames, int input_rate, float *output, int output_frames, int output_rate, int radius)
int audio_relative_sinusoidal_position_f32(float *output, int frames, int channels)
int audio_hann_window_f32(float *output, int frames, int periodic)
int audio_wav_decode_memory_pcm16_mono_window_f32(const uint8_t *bytes, size_t byte_count, int start_frame, float *mono, int mono_capacity, CKAudioWavInfo *info)
int audio_stft_power_fft400_f32(const float *samples, int n_samples, const float *window, const float *cos_table, const float *sin_table, int hop_length, float *power, int n_frames, float *fft_scratch)
int audio_resampled_frame_count(int input_frames, int input_rate, int output_rate)
int audio_wav_decode_memory_pcm16_mono_f32(const uint8_t *bytes, size_t byte_count, float *mono, int mono_capacity, CKAudioWavInfo *info)
CKSpacePrefixStyle style
Definition tokenizer.h:288