File size: 7,034 Bytes
b50f2a2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
//
// Copyright © 2025 Agora
// This file is part of TEN Framework, an open source project.
// Licensed under the Apache License, Version 2.0, with certain conditions.
//
// Refer to the "LICENSE" file in the root directory for more information.
//
#ifndef __PITCH_EST_H__
#define __PITCH_EST_H__
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#define AUP_PE_MAX_FFTSIZE (1024)
#define AUP_PE_MAX_NBINS ((AUP_PE_MAX_FFTSIZE >> 1) + 1)
#define AUP_PE_FS (16000)
// assumed sampling freq. of this module
// Configuration Parameters, which impacts dynamic memory occupation, can only
// be set during allocation
typedef struct PE_StaticCfg_ {
size_t fftSz; // fft-size, only support: 128, 256, 512, 1024
size_t anaWindowSz; // analysis fft-Window Size, will be used in LPC estimate
size_t hopSz; // fft-Hop Size, will be used to check
int useLPCPreFiltering;
// 0: use raw pcm to estimate pitch
// 1: use LPC prefiltering before pitch estimation
size_t procFs; // internal processing sampling rate
// 2000/4000/8000/16000
} PE_StaticCfg;
// Configuraiton parameters which can be modified/set every frames
typedef struct PE_DynamCfg_ {
float voicedThr; // threshold on frame correlation coeff to label if voice
// present
// suggested value: procFs == 2KHz, Yes: 0.45, No: 0.4
} PE_DynamCfg;
// Spectrum are assumed to be generated with time-domain samples in [-32768,
// 32767] WITH LEC blowup protection Note: the input timeSignal has to be in
// 16KHz sampling-rate
typedef struct PE_InputData_ {
const float*
timeSignal; // [hopSz] // this frame's input signal, in [-32768, 32767]
int hopSz; // should be equal to StaticCfg->hopSz
// if useLPCPreFiltering == 0, the following two input argument
// are not necessary
const float* inBinPow; // [nBins], bin-wise power
int nBins;
} PE_InputData;
typedef struct PE_OutputData_ {
float pitchFreq; // the current estimated pitch freq.
// <= 0: no voice
int voiced; // 0: no-voice, 1: voice-present
} PE_OutputData;
typedef struct PE_GetData_ {
float pitchFreq; // the current estimated pitch freq.
// <= 0: no voice
int voiced; // 0: no-voice, 1: voice-present
} PE_GetData;
#ifdef __cplusplus
extern "C" {
#endif
/****************************************************************************
* AUP_PE_create(...)
*
* This function creats a state handler from nothing, which is NOT ready for
* processing
*
* Input:
*
* Output:
* - stPtr : buffer to store the returned state handler
*
* Return value : 0 - Ok
* -1 - Error
*/
int AUP_PE_create(void** stPtr);
/****************************************************************************
* AUP_PE_destroy(...)
*
* destroy PE instance, and releasing all the dynamically allocated memory
*
* Input:
* - stPtr : buffer of State Handler, after this method, this
* handler won't be usable anymore
*
* Output:
*
* Return value : 0 - Ok
* -1 - Error
*/
int AUP_PE_destroy(void** stPtr);
/****************************************************************************
* AUP_PE_memAllocate(...)
*
* This function sets Static Config params and does memory allocation
* operation, will lose the dynamCfg values
*
* Input:
* - stPtr : State Handler which was returned by _create
* - pCfg : static configuration parameters
*
* Output:
*
* Return value : 0 - Ok
* -1 - Error
*/
int AUP_PE_memAllocate(void* stPtr, const PE_StaticCfg* pCfg);
/****************************************************************************
* AUP_PE_init(...)
*
* This function resets (initialize) the PE module and gets it prepared for
* processing
*
* Input:
* - stPtr : State Handler which has gone through create and
* memAllocate
*
* Output:
*
* Return value : 0 - Ok
* -1 - Error
*/
int AUP_PE_init(void* stPtr);
/****************************************************************************
* AUP_PE_setDynamCfg(...)
*
* This function set dynamic (per-frame variable) configuration
*
* Input:
* - stPtr : State Handler which has gone through create and
* memAllocate
* - pCfg : configuration content
*
* Output:
*
* Return value : 0 - Ok
* -1 - Error
*/
int AUP_PE_setDynamCfg(void* stPtr, const PE_DynamCfg* pCfg);
/****************************************************************************
* AUP_PE_getStaticCfg(...)
*
* This function get static configuration status from PE module
*
* Input:
* - stPtr : State Handler which has gone through create and
* memAllocate
*
* Output:
* - pCfg : configuration content
*
* Return value : 0 - Ok
* -1 - Error
*/
int AUP_PE_getStaticCfg(const void* stPtr, PE_StaticCfg* pCfg);
/****************************************************************************
* AUP_PE_getDynamCfg(...)
*
* This function get dynamic (per-frame variable) configuration status from
* PE module
*
* Input:
* - stPtr : State Handler which has gone through create and
* memAllocate
*
* Output:
* - pCfg : configuration content
*
* Return value : 0 - Ok
* -1 - Error
*/
int AUP_PE_getDynamCfg(const void* stPtr, PE_DynamCfg* pCfg);
/****************************************************************************
* AUP_PE_getAlgDelay(...)
*
* This function get algorithm delay from PE module
*
* Input:
* - stPtr : State Handler which has gone through create and
* memAllocate
*
* Output:
* - delayInFrms : algorithm delay in terms of frames
*
* Return value : 0 - Ok
* -1 - Error
*/
int AUP_PE_getAlgDelay(const void* stPtr, int* delayInFrms);
/****************************************************************************
* AUP_PE_proc(...)
*
* process a single frame
*
* Input:
* - stPtr : State Handler which has gone through create and
* memAllocate and reset
* - pCtrl : per-frame variable control parameters
* - pIn : input data stream
*
* Output:
* - pOut : output data (mask, highband time-domain gain etc.)
*
* Return value : 0 - Ok
* -1 - Error
*/
int AUP_PE_proc(void* stPtr, const PE_InputData* pIn, PE_OutputData* pOut);
#ifdef __cplusplus
}
#endif
#endif // __PITCH_EST_H__
|