Rename functions and structure of biquad lowpass filter
This commit is contained in:
parent
d447be5e26
commit
713b1ab118
|
@ -48,7 +48,7 @@ void scrambler_init(void)
|
|||
|
||||
void scrambler_setup(scrambler_t *scrambler, int samplerate)
|
||||
{
|
||||
biquad_init(&scrambler->bq, CARRIER_HZ - FILTER_BELOW, samplerate);
|
||||
filter_lowpass_init(&scrambler->lp, CARRIER_HZ - FILTER_BELOW, samplerate);
|
||||
scrambler->carrier_phaseshift256 = 256.0 / ((double)samplerate / CARRIER_HZ);
|
||||
}
|
||||
|
||||
|
@ -77,7 +77,7 @@ void scrambler(scrambler_t *scrambler, int16_t *samples, int length)
|
|||
scrambler->carrier_phase256 = phase;
|
||||
|
||||
/* cut off carrier frequency and modulation above carrier frequency */
|
||||
biquad_process(&scrambler->bq, spl, length, FILTER_TURNS);
|
||||
filter_lowpass_process(&scrambler->lp, spl, length, FILTER_TURNS);
|
||||
|
||||
for (i = 0; i < length; i++) {
|
||||
/* store result */
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
typedef struct scrambler {
|
||||
double carrier_phaseshift256; /* carrier phase shift per sample */
|
||||
double carrier_phase256; /* current phase of carrier frequency */
|
||||
biquad_low_pass_t bq; /* filter to remove carrier frequency */
|
||||
filter_lowpass_t lp; /* filter to remove carrier frequency */
|
||||
} scrambler_t;
|
||||
|
||||
void scrambler_init(void);
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
|
||||
//#define CASCADE
|
||||
|
||||
void biquad_init(biquad_low_pass_t *bq, double frequency, int samplerate)
|
||||
void filter_lowpass_init(filter_lowpass_t *bq, double frequency, int samplerate)
|
||||
{
|
||||
double Fc, Q, K, norm;
|
||||
|
||||
|
@ -44,7 +44,7 @@ void biquad_init(biquad_low_pass_t *bq, double frequency, int samplerate)
|
|||
bq->b2 = (1 - K / Q + K * K) * norm;
|
||||
}
|
||||
|
||||
void biquad_process(biquad_low_pass_t *bq, double *samples, int length, int iterations)
|
||||
void filter_lowpass_process(filter_lowpass_t *bq, double *samples, int length, int iterations)
|
||||
{
|
||||
double a0, a1, a2, b1, b2;
|
||||
double *z1, *z2;
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
#ifndef _FILTER_H
|
||||
#define _FILTER_H
|
||||
|
||||
typedef struct biquad_low_pass {
|
||||
typedef struct filter_lowpass {
|
||||
double a0, a1, a2, b1, b2;
|
||||
double z1[10], z2[10];
|
||||
} biquad_low_pass_t;
|
||||
} filter_lowpass_t;
|
||||
|
||||
void biquad_init(biquad_low_pass_t *bq, double frequency, int samplerate);
|
||||
void biquad_process(biquad_low_pass_t *bq, double *samples, int length, int iterations);
|
||||
void filter_lowpass_init(filter_lowpass_t *bq, double frequency, int samplerate);
|
||||
void filter_lowpass_process(filter_lowpass_t *bq, double *samples, int length, int iterations);
|
||||
|
||||
#endif /* _FILTER_H */
|
||||
|
|
|
@ -37,8 +37,8 @@ int init_samplerate(samplerate_t *state, double samplerate)
|
|||
memset(state, 0, sizeof(*state));
|
||||
state->factor = samplerate / 8000.0;
|
||||
|
||||
biquad_init(&state->up.bq, 4000.0, samplerate);
|
||||
biquad_init(&state->down.bq, 4000.0, samplerate);
|
||||
filter_lowpass_init(&state->up.lp, 4000.0, samplerate);
|
||||
filter_lowpass_init(&state->down.lp, 4000.0, samplerate);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ int samplerate_downsample(samplerate_t *state, int16_t *input, int input_num, in
|
|||
spl[i] = *input++ / 32768.0;
|
||||
|
||||
/* filter down */
|
||||
biquad_process(&state->down.bq, spl, input_num, 1);
|
||||
filter_lowpass_process(&state->down.lp, spl, input_num, 1);
|
||||
|
||||
/* resample filtered result */
|
||||
in_index = state->down.in_index;
|
||||
|
@ -125,7 +125,7 @@ int samplerate_upsample(samplerate_t *state, int16_t *input, int input_num, int1
|
|||
state->up.in_index = in_index;
|
||||
|
||||
/* filter up */
|
||||
biquad_process(&state->up.bq, spl, output_num, 1);
|
||||
filter_lowpass_process(&state->up.lp, spl, output_num, 1);
|
||||
|
||||
/* convert double to samples */
|
||||
for (i = 0; i < output_num; i++) {
|
||||
|
|
|
@ -3,11 +3,11 @@
|
|||
typedef struct samplerate {
|
||||
double factor;
|
||||
struct {
|
||||
biquad_low_pass_t bq;
|
||||
filter_lowpass_t lp;
|
||||
double in_index;
|
||||
} down;
|
||||
struct {
|
||||
biquad_low_pass_t bq;
|
||||
filter_lowpass_t lp;
|
||||
double in_index;
|
||||
} up;
|
||||
} samplerate_t;
|
||||
|
|
Loading…
Reference in New Issue