From 8c31b6d7e8f1b1ba359f97a47b85a024bb5a3601 Mon Sep 17 00:00:00 2001 From: James Courtier-Dutton Date: Sun, 16 May 2004 15:13:34 +0000 Subject: Changes in white space only. e.g. changing // to /* */ CVS patchset: 6549 CVS date: 2004/05/16 15:13:34 --- src/post/audio/dsp.h | 16 +- src/post/audio/filter.c | 395 ++++++++++++++++++++++++------------------------ src/post/audio/filter.h | 52 +++---- src/post/audio/upmix.c | 6 +- src/post/audio/window.c | 208 ++++++++++++------------- src/post/audio/window.h | 26 ++-- 6 files changed, 351 insertions(+), 352 deletions(-) (limited to 'src') diff --git a/src/post/audio/dsp.h b/src/post/audio/dsp.h index 8f5d5eb51..237640283 100644 --- a/src/post/audio/dsp.h +++ b/src/post/audio/dsp.h @@ -1,12 +1,12 @@ /*============================================================================= -// -// This software has been released under the terms of the GNU Public -// license. See http://www.gnu.org/copyleft/gpl.html for details. -// -// Copyright 2002 Anders Johansson ajh@atri.curtin.edu.au -// -//============================================================================= -*/ + * + * This software has been released under the terms of the GNU Public + * license. See http://www.gnu.org/copyleft/gpl.html for details. + * + * Copyright 2002 Anders Johansson ajh@atri.curtin.edu.au + * + *============================================================================= + */ #ifndef _DSP_H #define _DSP_H 1 diff --git a/src/post/audio/filter.c b/src/post/audio/filter.c index 10f1c975d..cb0363633 100644 --- a/src/post/audio/filter.c +++ b/src/post/audio/filter.c @@ -1,33 +1,32 @@ /*============================================================================= -// -// This software has been released under the terms of the GNU Public -// license. See http://www.gnu.org/copyleft/gpl.html for details. -// -// Copyright 2001 Anders Johansson ajh@atri.curtin.edu.au -// -//============================================================================= -*/ + * + * This software has been released under the terms of the GNU Public + * license. See http://www.gnu.org/copyleft/gpl.html for details. + * + * Copyright 2001 Anders Johansson ajh@atri.curtin.edu.au + * + *============================================================================= + */ -/* Design and implementation of different types of digital filters +/* Design and implementation of different types of digital filters */ -*/ #include #include #include "dsp.h" /****************************************************************************** -* FIR filter implementations -******************************************************************************/ + * FIR filter implementations + ******************************************************************************/ /* C implementation of FIR filter y=w*x - - n number of filter taps, where mod(n,4)==0 - w filter taps - x input signal must be a circular buffer which is indexed backwards -*/ + * + * n number of filter taps, where mod(n,4)==0 + * w filter taps + * x input signal must be a circular buffer which is indexed backwards + */ inline _ftype_t fir(register unsigned int n, _ftype_t* w, _ftype_t* x) { - register _ftype_t y; // Output + register _ftype_t y; /* Output */ y = 0.0; do{ n--; @@ -37,15 +36,15 @@ inline _ftype_t fir(register unsigned int n, _ftype_t* w, _ftype_t* x) } /* C implementation of parallel FIR filter y(k)=w(k) * x(k) (where * denotes convolution) - - n number of filter taps, where mod(n,4)==0 - d number of filters - xi current index in xq - w filter taps k by n big - x input signal must be a circular buffers which are indexed backwards - y output buffer - s output buffer stride -*/ + * + * n number of filter taps, where mod(n,4)==0 + * d number of filters + * xi current index in xq + * w filter taps k by n big + * x input signal must be a circular buffers which are indexed backwards + * y output buffer + * s output buffer stride + */ inline _ftype_t* pfir(unsigned int n, unsigned int d, unsigned int xi, _ftype_t** w, _ftype_t** x, _ftype_t* y, unsigned int s) { register _ftype_t* xt = *x + xi; @@ -97,21 +96,21 @@ inline int updatepq(unsigned int n, unsigned int d, unsigned int xi, _ftype_t** */ int design_fir(unsigned int n, _ftype_t* w, _ftype_t* fc, unsigned int flags, _ftype_t opt) { - unsigned int o = n & 1; // Indicator for odd filter length - unsigned int end = ((n + 1) >> 1) - o; // Loop end - unsigned int i; // Loop index - - _ftype_t k1 = 2 * M_PI; // 2*pi*fc1 - _ftype_t k2 = 0.5 * (_ftype_t)(1 - o);// Constant used if the filter has even length - _ftype_t k3; // 2*pi*fc2 Constant used in BP and BS design - _ftype_t g = 0.0; // Gain - _ftype_t t1,t2,t3; // Temporary variables - _ftype_t fc1,fc2; // Cutoff frequencies - - // Sanity check + unsigned int o = n & 1; /* Indicator for odd filter length */ + unsigned int end = ((n + 1) >> 1) - o; /* Loop end */ + unsigned int i; /* Loop index */ + + _ftype_t k1 = 2 * M_PI; /* 2*pi*fc1 */ + _ftype_t k2 = 0.5 * (_ftype_t)(1 - o);/* Constant used if the filter has even length */ + _ftype_t k3; /* 2*pi*fc2 Constant used in BP and BS design */ + _ftype_t g = 0.0; /* Gain */ + _ftype_t t1,t2,t3; /* Temporary variables */ + _ftype_t fc1,fc2; /* Cutoff frequencies */ + + /* Sanity check */ if(!w || (n == 0)) return -1; - // Get window coefficients + /* Get window coefficients */ switch(flags & WINDOW_MASK){ case(BOXCAR): boxcar(n,w); break; @@ -133,39 +132,41 @@ int design_fir(unsigned int n, _ftype_t* w, _ftype_t* fc, unsigned int flags, _f if(flags & (LP | HP)){ fc1=*fc; - // Cutoff frequency must be < 0.5 where 0.5 <=> Fs/2 + /* Cutoff frequency must be < 0.5 where 0.5 <=> Fs/2 */ fc1 = ((fc1 <= 1.0) && (fc1 > 0.0)) ? fc1/2 : 0.25; k1 *= fc1; - if(flags & LP){ // Low pass filter + if(flags & LP){ /* Low pass filter */ - // If the filter length is odd, there is one point which is exactly - // in the middle. The value at this point is 2*fCutoff*sin(x)/x, - // where x is zero. To make sure nothing strange happens, we set this - // value separately. + /* + * If the filter length is odd, there is one point which is exactly + * in the middle. The value at this point is 2*fCutoff*sin(x)/x, + * where x is zero. To make sure nothing strange happens, we set this + * value separately. + */ if (o){ w[end] = fc1 * w[end] * 2.0; g=w[end]; } - // Create filter + /* Create filter */ for (i=0 ; i Fs/2 + /* Cutoff frequencies must be < 1.0 where 1.0 <=> Fs/2 */ fc1 = ((fc1 <= 1.0) && (fc1 > 0.0)) ? fc1/2 : 0.25; fc2 = ((fc2 <= 1.0) && (fc2 > 0.0)) ? fc2/2 : 0.25; - k3 = k1 * fc2; // 2*pi*fc2 - k1 *= fc1; // 2*pi*fc1 + k3 = k1 * fc2; /* 2*pi*fc2 */ + k1 *= fc1; /* 2*pi*fc1 */ - if(flags & BP){ // Band pass - // Calculate center tap + if(flags & BP){ /* Band pass */ + /* Calculate center tap */ if (o){ g=w[end]*(fc1+fc2); w[end] = (fc2 - fc1) * w[end] * 2.0; } - // Create filter + /* Create filter */ for (i=0 ; i HP filter - - returns 0 if OK, -1 if fail -*/ + * + * n length of prototype filter + * k number of polyphase components + * w prototype filter taps + * pw Parallel FIR filter + * g Filter gain + * flags FWD forward indexing + * REW reverse indexing + * ODD multiply every 2nd filter tap by -1 => HP filter + * + * returns 0 if OK, -1 if fail + */ int design_pfir(unsigned int n, unsigned int k, _ftype_t* w, _ftype_t** pw, _ftype_t g, unsigned int flags) { - int l = (int)n/k; // Length of individual FIR filters - int i; // Counters + int l = (int)n/k; /* Length of individual FIR filters */ + int i; /* Counters */ int j; - _ftype_t t; // g * w[i] + _ftype_t t; /* g * w[i] */ - // Sanity check + /* Sanity check */ if(l<1 || k<1 || !w || !pw) return -1; - // Do the stuff + /* Do the stuff */ if(flags&REW){ - for(j=l-1;j>-1;j--){//Columns - for(i=0;i<(int)k;i++){//Rows + for(j=l-1;j>-1;j--){ /* Columns */ + for(i=0;i<(int)k;i++){ /* Rows */ t=g * *w++; pw[i][j]=t * ((flags & ODD) ? ((j & 1) ? -1 : 1) : 1); } } } else{ - for(j=0;j directly; include instead" @@ -15,20 +15,18 @@ #ifndef _FILTER_H #define _FILTER_H 1 +/* Design and implementation of different types of digital filters */ -// Design and implementation of different types of digital filters +/* Flags used for filter design */ - -// Flags used for filter design - -// Filter characteristics -#define LP 0x00010000 // Low pass -#define HP 0x00020000 // High pass -#define BP 0x00040000 // Band pass -#define BS 0x00080000 // Band stop +/* Filter characteristics */ +#define LP 0x00010000 /* Low pass */ +#define HP 0x00020000 /* High pass */ +#define BP 0x00040000 /* Band pass */ +#define BS 0x00080000 /* Band stop */ #define TYPE_MASK 0x000F0000 -// Window types +/* Window types */ #define BOXCAR 0x00000001 #define TRIANG 0x00000002 #define HAMMING 0x00000004 @@ -38,12 +36,12 @@ #define KAISER 0x00000012 #define WINDOW_MASK 0x0000001F -// Parallel filter design -#define FWD 0x00000001 // Forward indexing of polyphase filter -#define REW 0x00000002 // Reverse indexing of polyphase filter -#define ODD 0x00000010 // Make filter HP +/* Parallel filter design */ +#define FWD 0x00000001 /* Forward indexing of polyphase filter */ +#define REW 0x00000002 /* Reverse indexing of polyphase filter */ +#define ODD 0x00000010 /* Make filter HP */ -// Exported functions +/* Exported functions */ extern _ftype_t fir(unsigned int n, _ftype_t* w, _ftype_t* x); extern _ftype_t* pfir(unsigned int n, unsigned int k, unsigned int xi, _ftype_t** w, _ftype_t** x, _ftype_t* y, unsigned int s); @@ -60,10 +58,10 @@ void bilinear(_ftype_t* a, _ftype_t* b, _ftype_t* k, _ftype_t fs, _ftype_t *coef extern int szxform(_ftype_t* a, _ftype_t* b, _ftype_t Q, _ftype_t fc, _ftype_t fs, _ftype_t *k, _ftype_t *coef); /* Add new data to circular queue designed to be used with a FIR - filter. xq is the circular queue, in pointing at the new sample, xi - current index for xq and n the length of the filter. xq must be n*2 - long. -*/ + * filter. xq is the circular queue, in pointing at the new sample, xi + * current index for xq and n the length of the filter. xq must be n*2 + * long. + */ #define updateq(n,xi,xq,in)\ xq[xi]=(xq)[(xi)+(n)]=*(in);\ xi=(++(xi))&((n)-1); diff --git a/src/post/audio/upmix.c b/src/post/audio/upmix.c index 168411fd3..ecaa5a273 100644 --- a/src/post/audio/upmix.c +++ b/src/post/audio/upmix.c @@ -23,7 +23,7 @@ * process. It simply paints the screen a solid color and rotates through * colors on each iteration. * - * $Id: upmix.c,v 1.4 2004/05/16 14:44:42 jcdutton Exp $ + * $Id: upmix.c,v 1.5 2004/05/16 15:13:34 jcdutton Exp $ * */ @@ -56,8 +56,8 @@ struct post_class_upmix_s { /* Analog domain biquad section */ typedef struct{ - float a[3]; // Numerator coefficients - float b[3]; // Denominator coefficients + float a[3]; /* Numerator coefficients */ + float b[3]; /* Denominator coefficients */ } biquad_t; /* S-parameters for designing 4th order Butterworth filter */ diff --git a/src/post/audio/window.c b/src/post/audio/window.c index 25b92bc31..3fe76a112 100644 --- a/src/post/audio/window.c +++ b/src/post/audio/window.c @@ -1,49 +1,49 @@ /*============================================================================= -// -// This software has been released under the terms of the GNU Public -// license. See http://www.gnu.org/copyleft/gpl.html for details. -// -// Copyright 2001 Anders Johansson ajh@atri.curtin.edu.au -// -//============================================================================= -*/ + * + * This software has been released under the terms of the GNU Public + * license. See http://www.gnu.org/copyleft/gpl.html for details. + * + * Copyright 2001 Anders Johansson ajh@atri.curtin.edu.au + * + *============================================================================= + */ /* Calculates a number of window functions. The following window - functions are currently implemented: Boxcar, Triang, Hanning, - Hamming, Blackman, Flattop and Kaiser. In the function call n is - the number of filter taps and w the buffer in which the filter - coefficients will be stored. -*/ + * functions are currently implemented: Boxcar, Triang, Hanning, + * Hamming, Blackman, Flattop and Kaiser. In the function call n is + * the number of filter taps and w the buffer in which the filter + * coefficients will be stored. + */ #include #include "dsp.h" /* -// Boxcar -// -// n window length -// w buffer for the window parameters -*/ + * Boxcar + * + * n window length + * w buffer for the window parameters + */ void boxcar(int n, _ftype_t* w) { int i; - // Calculate window coefficients + /* Calculate window coefficients */ for (i=0 ; i> 1; int i; - // Calculate window coefficients + /* Calculate window coefficients */ for (i=0 ; i= 1 -// -// Beta trades the rejection of the low pass filter against the -// transition width from passband to stop band. Larger Beta means a -// slower transition and greater stop band rejection. See Rabiner and -// Gold (Theory and Application of DSP) under Kaiser windows for more -// about Beta. The following table from Rabiner and Gold gives some -// feel for the effect of Beta: -// -// All ripples in dB, width of transition band = D*N where N = window -// length -// -// BETA D PB RIP SB RIP -// 2.120 1.50 +-0.27 -30 -// 3.384 2.23 0.0864 -40 -// 4.538 2.93 0.0274 -50 -// 5.658 3.62 0.00868 -60 -// 6.764 4.32 0.00275 -70 -// 7.865 5.0 0.000868 -80 -// 8.960 5.7 0.000275 -90 -// 10.056 6.4 0.000087 -100 -*/ + * Kaiser + * + * n window length + * w buffer for the window parameters + * b beta parameter of Kaiser window, Beta >= 1 + * + * Beta trades the rejection of the low pass filter against the + * transition width from passband to stop band. Larger Beta means a + * slower transition and greater stop band rejection. See Rabiner and + * Gold (Theory and Application of DSP) under Kaiser windows for more + * about Beta. The following table from Rabiner and Gold gives some + * feel for the effect of Beta: + * + * All ripples in dB, width of transition band = D*N where N = window + * length + * + * BETA D PB RIP SB RIP + * 2.120 1.50 +-0.27 -30 + * 3.384 2.23 0.0864 -40 + * 4.538 2.93 0.0274 -50 + * 5.658 3.62 0.00868 -60 + * 6.764 4.32 0.00275 -70 + * 7.865 5.0 0.000868 -80 + * 8.960 5.7 0.000275 -90 + * 10.056 6.4 0.000087 -100 + */ void kaiser(int n, _ftype_t* w, _ftype_t b) { _ftype_t tmp; @@ -194,7 +194,7 @@ void kaiser(int n, _ftype_t* w, _ftype_t b) int end = (n + 1) >> 1; int i; - // Calculate window coefficients + /* Calculate window coefficients */ for (i=0 ; i directly; include instead" -- cgit v1.2.3