File size: 6,219 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 |
//
// 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 __BIQUAD_H__
#define __BIQUAD_H__
#include <stdio.h>
#define AGORA_UAP_BIQUAD_MAX_SECTION (20)
// the max. number of sections supported by this Biquad module
#define AGORA_UAP_BIQUAD_MAX_INPUT_LEN (3840)
// max. number of samples each time can be fed in
#define AGORA_UAP_BIQUAD_ALIGN8(o) (((o) + 7) & (~7))
#define _BIQUAD_FLOAT2SHORT(x) \
((x) < -32767.5f ? -32768 : ((x) > 32766.5f ? 32767 : (short)floor(.5 + (x))))
#define _BIQUAD_DC_REMOVAL_NSECT (2)
const float _BIQUAD_DC_REMOVAL_B[_BIQUAD_DC_REMOVAL_NSECT][3] = {
{1.0f, -2.0f, 1.0f}, {1.0f, -1.0f, 0.0f}};
const float _BIQUAD_DC_REMOVAL_A[_BIQUAD_DC_REMOVAL_NSECT][3] = {
{1.0f, -1.93944294f, 0.94281253f}, {1.0f, -0.94276431f, 0.0f}};
// const float _BIQUAD_DC_REMOVAL_G[_BIQUAD_DC_REMOVAL_NSECT] = {0.97056387f,
// 0.97138215f};
const float _BIQUAD_DC_REMOVAL_G[_BIQUAD_DC_REMOVAL_NSECT] = {0.97056387f,
0.8655014957f};
// Configuration Parameters, which impacts dynamic memory occupation, can only
// be set during allocation
typedef struct Biquad_StaticCfg_ {
size_t maxNSample; // max. number of samples each time can be fed in
// (0, AGORA_UAP_BIQUAD_MAX_INPUT_LEN]
int nsect; // the number of sections to be processed by this Biquad module
// (-inf, AGORA_UAP_BIQUAD_MAX_SECTION]
// if <= 0, use internal default filter coefficients
const float* B[AGORA_UAP_BIQUAD_MAX_SECTION];
const float* A[AGORA_UAP_BIQUAD_MAX_SECTION];
// always assume A[...][0] = 1.0f
const float* G;
} Biquad_StaticCfg;
typedef struct Biquad_InputData_ {
const void*
samplesPtr; // externally provided buffer containing input time samples
// either in short or float type
short sampleType; // = 0: samplesPtr = short*; o.w. samplesPtr = float*
size_t nsamples; // number of samples fed in this time
} Biquad_InputData;
typedef struct Biquad_OutputData_ {
void* outputBuff; // externally provided output buffer,
// assumed to be of enough size nsamples *
// sizeof(short)/sizeof(short) output data type is the same
// as input
} Biquad_OutputData;
#ifdef __cplusplus
extern "C" {
#endif
/****************************************************************************
* AUP_Biquad_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_Biquad_create(void** stPtr);
/****************************************************************************
* AUP_Biquad_destroy(...)
*
* destroy biquad 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_Biquad_destroy(void** stPtr);
/****************************************************************************
* AUP_Biquad_memAllocate(...)
*
* This function sets Static Config params and does memory allocation
* operation
*
* Input:
* - stPtr : State Handler which was returned by _create
* - pCfg : static configuration parameters
*
* Output:
*
* Return value : 0 - Ok
* -1 - Error
*/
int AUP_Biquad_memAllocate(void* stPtr, const Biquad_StaticCfg* pCfg);
/****************************************************************************
* AUP_Biquad_init(...)
*
* This function resets (initialize) the biquad 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_Biquad_init(void* stPtr);
/****************************************************************************
* AUP_Biquad_getStaticCfg(...)
*
* This function get static configuration status from Biquad module
*
* Input:
* - stPtr : State Handler which has gone through create and
* memAllocate
*
* Output:
* - pCfg : configuration content
*
* Return value : 0 - Ok
* -1 - Error
*/
int AUP_Biquad_getStaticCfg(const void* stPtr, Biquad_StaticCfg* pCfg);
/****************************************************************************
* AUP_Biquad_getAlgDelay(...)
*
* This function get algorithm delay from biquad module
*
* Input:
* - stPtr : State Handler which has gone through create and
* memAllocate
*
* Output:
* - delayInSamples : algorithm delay in terms of samples
*
* Return value : 0 - Ok
* -1 - Error
*/
int AUP_Biquad_getAlgDelay(const void* stPtr, int* delayInSamples);
/****************************************************************************
* AUP_Biquad_proc(...)
*
* process a single frame
*
* Input:
* - stPtr : State Handler which has gone through create and
* memAllocate
* - 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_Biquad_proc(void* stPtr, const Biquad_InputData* pIn,
Biquad_OutputData* pOut);
#ifdef __cplusplus
}
#endif
#endif // __BIQUAD_H__
|