fir-flat.c
来自「Reference Implementation of G.711 standa」· C语言 代码 · 共 733 行 · 第 1/2 页
C
733 行
/* v2.2 16.MAY.97 18H00 ============================================================================= U U GGG SSSS TTTTT U U G S T U U G GG SSSS T U U G G S T UUU GG SSS T ======================================== ITU-T - USER'S GROUP ON SOFTWARE TOOLS ======================================== ============================================================= COPYRIGHT NOTE: This source code, and all of its derivations, is subject to the "ITU-T General Public License". Please have it read in the distribution disk, or in the ITU-T Recommendation G.191 on "SOFTWARE TOOLS FOR SPEECH AND AUDIO CODING STANDARDS". =============================================================MODULE: FIRFLT, HIGH QUALITY FIR UP/DOWN-SAMPLING FILTER Sub-unit: Flat-weighting filters, LP and BPORIGINAL BY: Chris Tate <c.n.tate@bnr.co.uk> John Barnes <G.J.P.Barnes@bnr.co.uk> Rudolf Hofmann <hf@pkinbg.uucp> Simao Ferraz de Campos Neto <simao@ctd.comsat.com>DESCRIPTION: This file contains procedures for flat-weighting low-pass and high-pass filters, with rate factors of 2 and 3 for both up- and down-sampling.FUNCTIONS: Global (have prototype in firflt.h) = hq_down_2_to_1_init() : initialize down-sampling filter 2:1 = hq_down_3_to_1_init() : initialize down-sampling filter 3:1 = hq_up_1_to_2_init() : initialize up-sampling filter 1:2 = hq_up_1_to_3_init() : initialize up-sampling filter 1:3 = linear_phase_pb_2_to_1_init() = linear_phase_pb_1_to_2_init() = linear_phase_pb_1_to_1_init() Local (should be used only here -- prototypes only in this file) = fill_lp_2_to_1(...) : filling filter coefficients into array for flat low pass, factor 2:1 = fill_lp_3_to_1(...) : idem, for flat low pass, factor 3:1 = fill_flat_band_pass(...): idem, for linear-phase band-pass HISTORY: 16.Dec.91 v0.1 First beta-version <hf@pkinbg.uucp> 28.Feb.92 v1.0 Release of 1st version to UGST <hf@pkinbg.uucp> 20.Apr.94 v2.0 Added new filtering routines: modified IRS at 16kHz and 48kHz, Delta-SM, Linear-phase band-pass. <simao@cpqd.ansp.br> 30.Sep.94 v2.1 Updated to accomodate changes in the name of the name and slitting of module in several files, for ease of expansion. ** THIS FILE WAS SPLIT FROM THE ORIGINAL .C FILE ** 16.May.97 v2.2 Added function for HQ flat bandpass keeping the sampling rate (1:1 factor) =============================================================================*//* * ......... INCLUDES ......... */#include <stdio.h>#ifndef VMS#include <stdlib.h> /* General utility definitions */#endif#include "firflt.h" /* Global definitions for FIR-FIR filter *//* * ......... Local function prototypes ......... */void fill_lp_2_to_1 ARGS((float *h0[], long *lenh0));void fill_lp_3_to_1 ARGS((float **h0, long *lenh0));void fill_flat_band_pass ARGS((float **h0, long *lenh0));/* * ..... Private function prototypes defined in other sub-unit ..... */extern SCD_FIR *fir_initialization ARGS((long lenh0, float h0[], double gain, long idwnup, int hswitch));/* * ...................... BEGIN OF FUNCTIONS ......................... *//* ============================================================================ SCD_FIR *hq_down_2_to_1_init (void); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Description: ~~~~~~~~~~~~ Initialization routine for high quality FIR downsampling filter by factor of 2. Parameters: none. ~~~~~~~~~~~ Return value: ~~~~~~~~~~~~~ Returns a pointer to struct SCD_FIR; Author: <hf@pkinbg.uucp> ~~~~~~~ History: ~~~~~~~~ 28.Feb.92 v1.0 Release of 1st version <hf@pkinbg.uucp> ============================================================================*/SCD_FIR *hq_down_2_to_1_init(){ float *h0; /* pointer to array with FIR coeff. */ long lenh0; /* number of FIR coefficients */ /* allocate array for FIR coeff. and fill with coefficients */ fill_lp_2_to_1(&h0, &lenh0); return fir_initialization( /* Returns: pointer to SCD_FIR-struct */ lenh0, /* In: number of FIR-coefficients */ h0, /* In: pointer to array with FIR-cof. */ 1.0, /* In: gain factor for FIR-coeffic. */ 2l, /* In: Down-sampling factor */ 'D' /* In: switch to down-sampling kernel */ );}/* ..................... End of hq_down_2_to_1_init() ..................... *//* ============================================================================ SCD_FIR *hq_up_1_to_2_init (void); ~~~~~~~~~~~~~~~~~~~~~~~~~~ Description: ~~~~~~~~~~~~ Initialization routine for high quality upsampling FIR filter by factor of 2. Parameters: none. ~~~~~~~~~~~ Return value: ~~~~~~~~~~~~~ Returns a pointer to struct SCD_FIR; Author: <hf@pkinbg.uucp> ~~~~~~~ History: ~~~~~~~~ 28.Feb.92 v1.0 Release of 1st version <hf@pkinbg.uucp> ============================================================================*/SCD_FIR *hq_up_1_to_2_init(){ float *h0; /* pointer to array with FIR coeff. */ long lenh0; /* number of FIR coefficients */ /* allocate array for FIR coeff. and fill with coefficients */ fill_lp_2_to_1(&h0, &lenh0); return fir_initialization( /* Returns: pointer to SCD_FIR-struct */ lenh0, /* In: number of FIR-coefficients */ h0, /* In: pointer to array with FIR-cof. */ 2.0, /* In: gain factor for FIR-coeffic. */ 2l, /* In: Up-sampling factor */ 'U' /* In: Switch to upsampling procedure */ );}/* ..................... End of hq_up_1_to_2_init() ..................... *//* ============================================================================ SCD_FIR *hq_down_3_to_1_init (void); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Description: ~~~~~~~~~~~~ Initialization routine for high quality FIR downsampling filter by factor of 3. Parameters: none. ~~~~~~~~~~~ Return value: ~~~~~~~~~~~~~ Returns a pointer to struct SCD_FIR; Author: <hf@pkinbg.uucp> ~~~~~~~ History: ~~~~~~~~ 28.Feb.92 v1.0 Release of 1st version <hf@pkinbg.uucp> ============================================================================*/SCD_FIR *hq_down_3_to_1_init(){ float *h0; /* pointer to array with FIR coeff. */ long lenh0; /* number of FIR coefficients */ /* allocate array for FIR coeff. and fill with coefficients */ fill_lp_3_to_1(&h0, &lenh0); return fir_initialization( /* Returns: pointer to SCD_FIR-struct */ lenh0, /* In: number of FIR-coefficients */ h0, /* In: pointer to array with FIR-cof. */ 1.0, /* In: gain factor for FIR-coeffic. */ 3l, /* In: Down-sampling factor */ 'D' /* In: switch to down-sampling proc. */ );}/* .................... End of hq_down_3_to_1_init() ..................... *//* ============================================================================ SCD_FIR *hq_up_1_to_3_init (void); ~~~~~~~~~~~~~~~~~~~~~~~~~~ Description: ~~~~~~~~~~~~ Initialization routine for high quality FIR upsampling filter by factor of 3. Parameters: none. ~~~~~~~~~~~ Return value: ~~~~~~~~~~~~~ Returns a pointer to struct SCD_FIR; Author: <hf@pkinbg.uucp> ~~~~~~~ History: ~~~~~~~~ 28.Feb.92 v1.0 Release of 1st version <hf@pkinbg.uucp> ============================================================================*/SCD_FIR *hq_up_1_to_3_init(){ float *h0; /* pointer to array with FIR coeff. */ long lenh0; /* number of FIR coefficients */ /* allocate array for FIR coeff. and fill with coefficients */ fill_lp_3_to_1(&h0, &lenh0); return fir_initialization( /* Returns: pointer to SCD_FIR-struct */ lenh0, /* In: number of FIR-coefficients */ h0, /* In: pointer to array with FIR-cof. */ 3.0, /* In: gain factor for FIR-coeffic. */ 3l, /* In: Up-sampling factor */ 'U' /* In: switch to upsampling procedure */ );}/* ...................... End of hq_up_1_to_3_init() ...................... *//* ============================================================================ void fill_lp_2_to_1 (float **h0, long *lenh0); ~~~~~~~~~~~~~~~~~~~ Description: ~~~~~~~~~~~~ Initialize pointer to array with of FIR coefficients of a low pass filter for up/down sampling filter with factor 2:1 or 1:2 and 24-bit representation. Parameters: ~~~~~~~~~~~ h0: (Out) pointer to array with FIR coefficients lenh0: (Out) pointer to number of coefficients Return value: ~~~~~~~~~~~~~ None. Author: <hf@pkinbg.uucp> ~~~~~~~ History: ~~~~~~~~ 28.Feb.92 v1.0 Release of 1st version <hf@pkinbg.uucp> ============================================================================*/#define f24 (float)0x00800000#define lenh02 118void fill_lp_2_to_1(h0, lenh0) float *h0[]; long *lenh0;{ static float h02[lenh02] = { 1584. / f24, 805. / f24, -4192. / f24, -8985. / f24, -5987. / f24, 2583. / f24, 4657. / f24, -3035. / f24, -7004. / f24, 1542. / f24, 8969. / f24, 567. / f24, -10924. / f24, -3757. / f24, 12320. / f24, 7951. / f24, -12793. / f24, -13048. / f24, 11923. / f24, 18793. / f24, -9331. / f24, -24802. / f24, 4694. / f24, 30570. / f24, 2233. / f24, -35439. / f24, -11526. / f24, 38680. / f24, 23114. / f24, -39474. / f24, -36701. / f24, 36999. / f24, 51797. / f24, -30419. / f24, -67658. / f24, 18962. / f24, 83318. / f24, -1927. / f24, -97566. / f24, -21284. / f24, 108971. / f24, 51215. / f24, -115837. / f24, -88430. / f24, 116130. / f24, 133716. / f24, -107253. / f24, -188497. / f24, 85497. / f24, 255795. / f24, -44643. / f24, -342699. / f24, -28185. / f24, 468096. / f24, 167799. / f24, -696809. / f24, -519818. / f24, 1446093. / f24, 3562497. / f24, 3562497. / f24, 1446093. / f24, -519818. / f24, -696809. / f24, 167799. / f24, 468096. / f24, -28185. / f24, -342699. / f24, -44643. / f24, 255795. / f24, 85497. / f24, -188497. / f24, -107253. / f24, 133716. / f24, 116130. / f24, -88430. / f24, -115837. / f24, 51215. / f24, 108971. / f24, -21284. / f24, -97566. / f24, -1927. / f24, 83318. / f24, 18962. / f24, -67658. / f24, -30419. / f24, 51797. / f24, 36999. / f24, -36701. / f24, -39474. / f24, 23114. / f24, 38680. / f24, -11526. / f24, -35439. / f24, 2233. / f24, 30570. / f24, 4694. / f24, -24802. / f24, -9331. / f24, 18793. / f24, 11923. / f24, -13048. / f24, -12793. / f24, 7951. / f24, 12320. / f24, -3757. / f24, -10924. / f24, 567. / f24, 8969. / f24, 1542. / f24, -7004. / f24, -3035. / f24, 4657. / f24,
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?