W
weg22
Dear all,
I am trying to compile a Visual Studio 2005 C++ project using an
example file from some software I just bought. The code was created
in 1998 and I'm getting some errors. Most of the errors complain
about converting from void* to float* because of the last 5 parameters
in the "BiquadSections" structure. However, if I change these to
float*, the program compiles but I get a link errror. I would
appreciate any suggestions/help.
Thanks in advance,
-weg
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
typedef struct {
int nosect; /* number of sections */
int rMthd; /* realization method */
int quant; /* quantization switch */
int quantType; /* 0 Floating point */
int realType1; /* applies to cascaded sections only */
int realType2; /* applies to parallel sections only */
void *gain; /* pointer to initial gain - cascaded and parallel
sections */
void *pars; /* pointer to scaler for parallel form */
void *num; /* pointer to array of numerator values */
void *den; /* pointer to array of denominator values */
void *m1; /* pointer to intermediate storage */
void *m2; /* pointer to intermediate storage */
void (*filter) ();
/* void (*filter) (float *pInValues, float *pOutValues, int n,
BiquadSections *F); */
/* address of filter routine */
} BiquadSections; /* second order section structure name */
void init_biquad_float (BiquadSections *F);
void cas_blkfloat_fm1(float *pInValues, float *pOutValues, int
nValues, BiquadSections *Filt);
static float x[2], y[2];
int main(void)
{
int i;
int in_count = 2;
x[0] = -2.0;
x[1] = -1.0;
float test_num[6] =
{
6.347656250000e-003F, /* b[ 1, 0] */
1.269531250000e-002F, /* b[ 1, 1] */
6.347656250000e-003F, /* b[ 1, 2] */
8.392333984375e-003F, /* b[ 2, 0] */
1.678466796875e-002F, /* b[ 2, 1] */
8.392333984375e-003F /* b[ 2, 2] */
};
float test_den[6] =
{
5.000000000000e-001F, /* a[ 1, 0] */
-7.821044921875e-001F, /* a[ 1, 1] */
3.074951171875e-001F, /* a[ 1, 2] */
5.000000000000e-001F, /* a[ 2, 0] */
-8.193359375000e-001F, /* a[ 2, 1] */
3.529052734375e-001F /* a[ 2, 2] */
};
float test_m1[2];
float test_m2[2];
float test_gain = 1.000000000000e+000F; /* initial gain for cascade
realization */
/* also applies to parallel realization */
float test_pars = 1.000000000000e+000F; /* scale value for parallel
sections */
BiquadSections IIR_test =
{
2, /* number of sections */
0, /* realization method */
/* 0 Cascaded second order sections */
/* 1 Parallel second order sections */
1, /* quantization: 0 off, 1 on */
1, /* quantization type */
/* 0 Floating point */
/* 1 Fixed point fractional */
0, /* realization type for cascaded sections only */
/* 0 Fixed point - Transposed Canonic biquad sections */
/* 1 Fixed point - Canonic biquad sections */
/* 2 Floating point - 4 multiplies */
/* 3 Floating point - 5 multiplies */
0, /* realization type for parallel sections only */
/* 0 Fixed point - Transposed Canonic biquad sections */
/* 1 Floating point - Transposed Canonic biquad sections */
&test_gain, /* ptr to gain for cascade/parallel realizations */
&test_pars, /* ptr to scale value for parallel sections */
test_num, /* ptr to numerator coefficients */
test_den, /* ptr to denominator coefficients */
test_m1, /* ptr to delay line 1 */
test_m2, /* ptr to delay line 2 */
cas_blkfloat_fm1 /* ptr to filter routine */
};
init_biquad_float (&IIR_test);
for(i=0; i<in_count; i++)
{
IIR_test.filter(x, y, 1, &IIR_test);
printf("%d", y);
}
while(1);
return 0;
}
/**************************************************************
* initialize biquad sections
* clears delay lines to zero
* must be called prior to calling filter routine
**************************************************************/
void init_biquad_float(BiquadSections *Filt)
{
float *m1; /* pointer to delay line1 */
float *m2; /* pointer to delay line2 */
int i;
m1 = Filt->m1;
m2 = Filt->m2;
for (i = 0; i < Filt->nosect; i++)
{
m1 = (float) 0.0;
m2 = (float) 0.0;
}
}
/* filter routine for 5 multiplier block floating point
cascaded sections
This uses form I . This is the transpose of Form II
If code is used for coefficients from an flt file,
these signs must be changed to positive. All feedback
coefficients in flt files have complemented signs.
*/
void cas_blkfloat_fm1
(float *pInValues, /* pointer to input buffer */
float *pOutValues, /* pointer to output buffer */
int nValues, /* number of samples to process */
BiquadSections *Filt) /* pointer to filter structure */
{
float *pGain; /* pointer to gain value of filter */
float gain; /* gain value of filter */
int nosect; /* number of sections in the filter */
float *m1; /* pointer to delay line1 */
float *m2; /* pointer to delay line2 */
float *num; /* pointer to numerator coefficients */
float *den; /* pointer to denominator coefficients */
float x; /* gain * input sample */
float s; /* scratch variable */
int i; /* input sample counter */
int j; /* section counter */
/* runtime initialization for filter routine */
m1 = Filt->m1;
m2 = Filt->m2;
pGain = Filt->gain;
gain = *pGain;
nosect = Filt->nosect;
for (i = 0; i < nValues; i++)
{
num = Filt->num;
den = Filt->den;
x = pInValues * gain;
for (j = 0; j < nosect; j++)
{
s = (num[0] * x + m1[j]) / den[0];
m1[j] = num[1] * x - den[1] * s + m2[j];
m2[j] = num[2] * x - den[2] * s;
x = s;
num += 3;
den += 3;
}
pOutValues = s;
}
return;
}
I am trying to compile a Visual Studio 2005 C++ project using an
example file from some software I just bought. The code was created
in 1998 and I'm getting some errors. Most of the errors complain
about converting from void* to float* because of the last 5 parameters
in the "BiquadSections" structure. However, if I change these to
float*, the program compiles but I get a link errror. I would
appreciate any suggestions/help.
Thanks in advance,
-weg
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
typedef struct {
int nosect; /* number of sections */
int rMthd; /* realization method */
int quant; /* quantization switch */
int quantType; /* 0 Floating point */
int realType1; /* applies to cascaded sections only */
int realType2; /* applies to parallel sections only */
void *gain; /* pointer to initial gain - cascaded and parallel
sections */
void *pars; /* pointer to scaler for parallel form */
void *num; /* pointer to array of numerator values */
void *den; /* pointer to array of denominator values */
void *m1; /* pointer to intermediate storage */
void *m2; /* pointer to intermediate storage */
void (*filter) ();
/* void (*filter) (float *pInValues, float *pOutValues, int n,
BiquadSections *F); */
/* address of filter routine */
} BiquadSections; /* second order section structure name */
void init_biquad_float (BiquadSections *F);
void cas_blkfloat_fm1(float *pInValues, float *pOutValues, int
nValues, BiquadSections *Filt);
static float x[2], y[2];
int main(void)
{
int i;
int in_count = 2;
x[0] = -2.0;
x[1] = -1.0;
float test_num[6] =
{
6.347656250000e-003F, /* b[ 1, 0] */
1.269531250000e-002F, /* b[ 1, 1] */
6.347656250000e-003F, /* b[ 1, 2] */
8.392333984375e-003F, /* b[ 2, 0] */
1.678466796875e-002F, /* b[ 2, 1] */
8.392333984375e-003F /* b[ 2, 2] */
};
float test_den[6] =
{
5.000000000000e-001F, /* a[ 1, 0] */
-7.821044921875e-001F, /* a[ 1, 1] */
3.074951171875e-001F, /* a[ 1, 2] */
5.000000000000e-001F, /* a[ 2, 0] */
-8.193359375000e-001F, /* a[ 2, 1] */
3.529052734375e-001F /* a[ 2, 2] */
};
float test_m1[2];
float test_m2[2];
float test_gain = 1.000000000000e+000F; /* initial gain for cascade
realization */
/* also applies to parallel realization */
float test_pars = 1.000000000000e+000F; /* scale value for parallel
sections */
BiquadSections IIR_test =
{
2, /* number of sections */
0, /* realization method */
/* 0 Cascaded second order sections */
/* 1 Parallel second order sections */
1, /* quantization: 0 off, 1 on */
1, /* quantization type */
/* 0 Floating point */
/* 1 Fixed point fractional */
0, /* realization type for cascaded sections only */
/* 0 Fixed point - Transposed Canonic biquad sections */
/* 1 Fixed point - Canonic biquad sections */
/* 2 Floating point - 4 multiplies */
/* 3 Floating point - 5 multiplies */
0, /* realization type for parallel sections only */
/* 0 Fixed point - Transposed Canonic biquad sections */
/* 1 Floating point - Transposed Canonic biquad sections */
&test_gain, /* ptr to gain for cascade/parallel realizations */
&test_pars, /* ptr to scale value for parallel sections */
test_num, /* ptr to numerator coefficients */
test_den, /* ptr to denominator coefficients */
test_m1, /* ptr to delay line 1 */
test_m2, /* ptr to delay line 2 */
cas_blkfloat_fm1 /* ptr to filter routine */
};
init_biquad_float (&IIR_test);
for(i=0; i<in_count; i++)
{
IIR_test.filter(x, y, 1, &IIR_test);
printf("%d", y);
}
while(1);
return 0;
}
/**************************************************************
* initialize biquad sections
* clears delay lines to zero
* must be called prior to calling filter routine
**************************************************************/
void init_biquad_float(BiquadSections *Filt)
{
float *m1; /* pointer to delay line1 */
float *m2; /* pointer to delay line2 */
int i;
m1 = Filt->m1;
m2 = Filt->m2;
for (i = 0; i < Filt->nosect; i++)
{
m1 = (float) 0.0;
m2 = (float) 0.0;
}
}
/* filter routine for 5 multiplier block floating point
cascaded sections
This uses form I . This is the transpose of Form II
If code is used for coefficients from an flt file,
these signs must be changed to positive. All feedback
coefficients in flt files have complemented signs.
*/
void cas_blkfloat_fm1
(float *pInValues, /* pointer to input buffer */
float *pOutValues, /* pointer to output buffer */
int nValues, /* number of samples to process */
BiquadSections *Filt) /* pointer to filter structure */
{
float *pGain; /* pointer to gain value of filter */
float gain; /* gain value of filter */
int nosect; /* number of sections in the filter */
float *m1; /* pointer to delay line1 */
float *m2; /* pointer to delay line2 */
float *num; /* pointer to numerator coefficients */
float *den; /* pointer to denominator coefficients */
float x; /* gain * input sample */
float s; /* scratch variable */
int i; /* input sample counter */
int j; /* section counter */
/* runtime initialization for filter routine */
m1 = Filt->m1;
m2 = Filt->m2;
pGain = Filt->gain;
gain = *pGain;
nosect = Filt->nosect;
for (i = 0; i < nValues; i++)
{
num = Filt->num;
den = Filt->den;
x = pInValues * gain;
for (j = 0; j < nosect; j++)
{
s = (num[0] * x + m1[j]) / den[0];
m1[j] = num[1] * x - den[1] * s + m2[j];
m2[j] = num[2] * x - den[2] * s;
x = s;
num += 3;
den += 3;
}
pOutValues = s;
}
return;
}