/* * Copyright (C) 2024–2025 Amlogic, Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef PRE_POST_COMMON_H #define PRE_POST_COMMON_H #include "common.h" #include "whisper.h" #include #include #include #include #include #include #include #include struct whisper_mel { int n_len; int n_len_org; int n_mel; std::vector data; }; struct whisper_filters { int32_t n_mel = 80; int32_t n_fft = 201; std::vector data; }; struct whisper_state { int64_t t_sample_us = 0; int64_t t_encode_us = 0; int64_t t_decode_us = 0; int64_t t_batchd_us = 0; int64_t t_prompt_us = 0; int64_t t_mel_us = 0; int32_t n_sample = 0; // number of tokens sampled int32_t n_encode = 0; // number of encoder calls int32_t n_decode = 0; // number of decoder calls with n_tokens == 1 (text-generation) int32_t n_batchd = 0; // number of decoder calls with n_tokens < 16 (batch decoding) int32_t n_prompt = 0; // number of decoder calls with n_tokens > 1 (prompt encoding) int32_t n_fail_p = 0; // number of logprob threshold failures int32_t n_fail_h = 0; // number of entropy threshold failures whisper_mel mel; // decode output (2-dimensional array: [n_tokens][n_vocab]) std::vector logits; std::vector prompt_past; int lang_id = 0; // english by default std::string path_model; // populated by whisper_init_from_file_with_params() // [EXPERIMENTAL] token-level timestamps data int64_t t_beg = 0; int64_t t_last = 0; whisper_token tid_last; std::vector energy; // PCM signal energy // [EXPERIMENTAL] speed-up techniques int32_t exp_n_audio_ctx = 0; // 0 - use default }; struct whisper_model { whisper_filters filters; }; struct whisper_context { int64_t t_load_us = 0; int64_t t_start_us = 0; whisper_model model; whisper_vocab vocab; whisper_state * state = nullptr; }; template static void read_safe(whisper_model_loader * loader, T & dest) { loader->read(loader->context, &dest, sizeof(T)); } #endif // PRE_POST_COMMON_H