AM62D FreeRTOS SDK  11.02.00
calcratio.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2025 Texas Instruments Incorporated
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
11  * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the
14  * distribution.
15  *
16  * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
48 #ifndef CALCRATIO_H
49 #define CALCRATIO_H
50 
51 /* ========================================================================== */
52 /* Include Files */
53 /* ========================================================================== */
54 
56 
57 #ifdef __cplusplus
58 extern "C" {
59 #endif
60 
61 /* ========================================================================== */
62 /* Macros & Typedefs */
63 /* ========================================================================== */
64 
72  #define CALCRATIO_MA1_LENGTH (1024U)
73 
80  #define CALCRATIO_MA2_LENGTH (128U)
81 
82 /* ========================================================================== */
83 /* Structure Definitions */
84 /* ========================================================================== */
85 
111 typedef struct
112 {
114  float fsi;
116  float fso;
123  double target_ratio;
130  double actual_ratio;
140  double capture_history[CALCRATIO_MA1_LENGTH];
157  double capture2_history[CALCRATIO_MA2_LENGTH];
173  uint32_t movingAvg2Count;
181  uint16_t one_shot;
182 } CalcRatio_t;
183 
184 /* ========================================================================== */
185 /* API Function Declarations */
186 /* ========================================================================== */
187 
205  CalcRatio_t *calcRatioInstance,
206  float sampleRateIn,
207  float sampleRateOut
208 );
209 
210 
233 int32_t calcRatio_exec(CalcRatio_t *calcRatioInstance,double *Tx_Counter,double *Rx_Counter);
234 
235 
252 double calcRatio_getActualratio(CalcRatio_t *calcRatioInstance);
253 
254 
255 /* None */
256 
257 #ifdef __cplusplus
258 }
259 #endif
260 
261 #endif /* #ifndef CALCRATIO_H_ */
262 
calcRatio_init
int32_t calcRatio_init(CalcRatio_t *calcRatioInstance, float sampleRateIn, float sampleRateOut)
Initializes the ratio calculation module for ASRC (Asynchronous Sample Rate Converter) with input and...
CalcRatio_t
CALCRATIO Parameters.
Definition: calcratio.h:112
CalcRatio_t::target_ratio
double target_ratio
Target ratio produced by calcRatio_init.
Definition: calcratio.h:123
CalcRatio_t::one_shot
uint16_t one_shot
One-shot flag to discard the very first captured period.
Definition: calcratio.h:181
CalcRatio_t::actual_ratio
double actual_ratio
Actual ratio produced by calcRatio_exec on each call.
Definition: calcratio.h:130
CalcRatio_t::movingAvg2Count
uint32_t movingAvg2Count
Counter for the graduated (incremental) update of the second-stage average.
Definition: calcratio.h:173
CALCRATIO_MA2_LENGTH
#define CALCRATIO_MA2_LENGTH
Length of the second-stage moving average filter for refined smoothing.
Definition: calcratio.h:80
CalcRatio_t::P2_capture2_hist
double * P2_capture2_hist
Pointer into capture2_history for the next write location.
Definition: calcratio.h:163
CALCRATIO_MA1_LENGTH
#define CALCRATIO_MA1_LENGTH
Length of the first-stage moving average filter used in ratio smoothing.
Definition: calcratio.h:72
calcRatio_getActualratio
double calcRatio_getActualratio(CalcRatio_t *calcRatioInstance)
Safely retrieve the derived actual sample rate ratio.
CalcRatio_t::movingAvg1Sum
double movingAvg1Sum
Accumulator for the first-stage moving-average sum.
Definition: calcratio.h:132
CalcRatio_t::fsi
float fsi
Input sample rate set by the user (Hz).
Definition: calcratio.h:114
CalcRatio_t::movingAvg2Sum
double movingAvg2Sum
Accumulator for the second-stage moving-average sum.
Definition: calcratio.h:150
calcRatio_exec
int32_t calcRatio_exec(CalcRatio_t *calcRatioInstance, double *Tx_Counter, double *Rx_Counter)
Executes the CALCRATIO algorithm to derive and update the smoothed actual sample rate ratio.
AddrTranslateP.h
CalcRatio_t::fso
float fso
Output sample rate set by the user (Hz).
Definition: calcratio.h:116
CalcRatio_t::P2_capture_hist
double * P2_capture_hist
Pointer into capture_history indicating where the next period sample will be written.
Definition: calcratio.h:148