init
This commit is contained in:
120
lib_audio_dsp/test/biquad/src/coeffs_alltests.c
Normal file
120
lib_audio_dsp/test/biquad/src/coeffs_alltests.c
Normal file
@@ -0,0 +1,120 @@
|
||||
// Copyright 2024-2025 XMOS LIMITED.
|
||||
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "control/biquad.h"
|
||||
|
||||
FILE * _fopen(char * fname, char* mode) {
|
||||
FILE * fp = fopen(fname, mode);
|
||||
if (fp == NULL)
|
||||
{
|
||||
printf("Error opening a file\n");
|
||||
exit(1);
|
||||
}
|
||||
return fp;
|
||||
}
|
||||
|
||||
int read_int();
|
||||
float read_float();
|
||||
|
||||
enum bq_type {allpass, bandpass, bandstop, bypass, constq, gain, high_shelf,
|
||||
highpass, linkwitz, low_shelf, lowpass, mute, notch, peaking};
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
enum bq_type this_bq = atoi(argv[1]);
|
||||
|
||||
int n_inputs = 0;
|
||||
if (this_bq == allpass || this_bq == bandpass || this_bq == bandstop || this_bq == highpass ||
|
||||
this_bq == lowpass || this_bq == notch){
|
||||
n_inputs = 3;
|
||||
}
|
||||
else if (this_bq == constq || this_bq == high_shelf || this_bq == low_shelf || this_bq == peaking)
|
||||
{
|
||||
n_inputs = 4;
|
||||
}
|
||||
else if (this_bq == bypass || this_bq == gain || this_bq == mute)
|
||||
{
|
||||
n_inputs = 1;
|
||||
}
|
||||
else if (this_bq == linkwitz){
|
||||
n_inputs = 5;
|
||||
}
|
||||
else {
|
||||
printf("Unknown biquad type\n");
|
||||
exit(1);
|
||||
}
|
||||
FILE * in = _fopen("test_vector.bin", "rb");
|
||||
FILE * out = _fopen("out_vector.bin", "wb");
|
||||
|
||||
fseek(in, 0, SEEK_END);
|
||||
int in_len = ftell(in) / (n_inputs*sizeof(float));
|
||||
printf("inlen %d", in_len);
|
||||
fseek(in, 0, SEEK_SET);
|
||||
|
||||
for (unsigned i = 0; i < in_len; i++)
|
||||
{
|
||||
float samp[5] = {0}; // never more than 4 inputs
|
||||
fread(&samp, sizeof(float), n_inputs, in);
|
||||
|
||||
q2_30 coeffs[5] = {0};
|
||||
left_shift_t bsh;
|
||||
if (this_bq == allpass){
|
||||
bsh = adsp_design_biquad_allpass(coeffs, samp[0], samp[1], samp[2]);
|
||||
}
|
||||
else if (this_bq == bandpass){
|
||||
bsh = adsp_design_biquad_bandpass(coeffs, samp[0], samp[1], samp[2]);
|
||||
}
|
||||
else if (this_bq == bandstop){
|
||||
bsh = adsp_design_biquad_bandstop(coeffs, samp[0], samp[1], samp[2]);
|
||||
}
|
||||
else if (this_bq == bypass){
|
||||
bsh = adsp_design_biquad_bypass(coeffs);
|
||||
}
|
||||
else if (this_bq == constq){
|
||||
bsh = adsp_design_biquad_const_q(coeffs, samp[0], samp[1], samp[2], samp[3]);
|
||||
}
|
||||
else if (this_bq == gain){
|
||||
bsh = adsp_design_biquad_gain(coeffs, samp[0]);
|
||||
}
|
||||
else if (this_bq == high_shelf){
|
||||
bsh = adsp_design_biquad_highshelf(coeffs, samp[0], samp[1], samp[2], samp[3]);
|
||||
}
|
||||
else if (this_bq == highpass){
|
||||
bsh = adsp_design_biquad_highpass(coeffs, samp[0], samp[1], samp[2]);
|
||||
}
|
||||
else if (this_bq == linkwitz){
|
||||
bsh = adsp_design_biquad_linkwitz(coeffs, samp[0], samp[1], samp[2], samp[3], samp[4]);
|
||||
}
|
||||
else if (this_bq == lowpass){
|
||||
bsh = adsp_design_biquad_lowpass(coeffs, samp[0], samp[1], samp[2]);
|
||||
}
|
||||
else if (this_bq == low_shelf){
|
||||
bsh = adsp_design_biquad_lowshelf(coeffs, samp[0], samp[1], samp[2], samp[3]);
|
||||
}
|
||||
else if (this_bq == mute){
|
||||
bsh = adsp_design_biquad_mute(coeffs);
|
||||
}
|
||||
else if (this_bq == notch){
|
||||
bsh = adsp_design_biquad_notch(coeffs, samp[0], samp[1], samp[2]);
|
||||
}
|
||||
else if (this_bq == peaking){
|
||||
bsh = adsp_design_biquad_peaking(coeffs, samp[0], samp[1], samp[2], samp[3]);
|
||||
}
|
||||
else {
|
||||
printf("Unknown biquad type\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
fwrite(&coeffs, sizeof(int32_t), 5, out);
|
||||
fwrite(&bsh, sizeof(int32_t), 1, out);
|
||||
|
||||
}
|
||||
|
||||
fclose(in);
|
||||
fclose(out);
|
||||
|
||||
return 0;
|
||||
}
|
||||
52
lib_audio_dsp/test/biquad/src/main.c
Normal file
52
lib_audio_dsp/test/biquad/src/main.c
Normal file
@@ -0,0 +1,52 @@
|
||||
// Copyright 2024-2025 XMOS LIMITED.
|
||||
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "dsp/adsp.h"
|
||||
|
||||
FILE * _fopen(char * fname, char* mode) {
|
||||
FILE * fp = fopen(fname, mode);
|
||||
if (fp == NULL)
|
||||
{
|
||||
printf("Error opening a file\n");
|
||||
exit(1);
|
||||
}
|
||||
return fp;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int32_t DWORD_ALIGNED taps_buf[5] = {0};
|
||||
int32_t state[8] = {0};
|
||||
left_shift_t lsh = 0;
|
||||
|
||||
FILE * in = _fopen("../sig_48k.bin", "rb");
|
||||
FILE * out = _fopen("sig_out.bin", "wb");
|
||||
FILE * coeffs = _fopen("coeffs.bin", "rb");
|
||||
|
||||
fseek(in, 0, SEEK_END);
|
||||
int in_len = ftell(in) / sizeof(int32_t);
|
||||
fseek(in, 0, SEEK_SET);
|
||||
|
||||
fread(taps_buf, sizeof(int32_t), 5, coeffs);
|
||||
fread(&lsh, sizeof(int32_t), 1, coeffs);
|
||||
//printf("%ld %ld %ld %ld %ld %d\n", taps_buf[0], taps_buf[1], taps_buf[2], taps_buf[3], taps_buf[4], lsh);
|
||||
fclose(coeffs);
|
||||
|
||||
for (unsigned i = 0; i < in_len; i++)
|
||||
{
|
||||
int32_t samp = 0, samp_out = 0;
|
||||
fread(&samp, sizeof(int32_t), 1, in);
|
||||
//printf("%ld ", samp);
|
||||
samp_out = adsp_biquad(samp, taps_buf, state, lsh);
|
||||
//printf("%ld ", samp_out);
|
||||
fwrite(&samp_out, sizeof(int32_t), 1, out);
|
||||
}
|
||||
|
||||
fclose(in);
|
||||
fclose(out);
|
||||
|
||||
return 0;
|
||||
}
|
||||
79
lib_audio_dsp/test/biquad/src/main_slew.c
Normal file
79
lib_audio_dsp/test/biquad/src/main_slew.c
Normal file
@@ -0,0 +1,79 @@
|
||||
// Copyright 2024-2025 XMOS LIMITED.
|
||||
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "dsp/adsp.h"
|
||||
#include "control/biquad.h"
|
||||
|
||||
FILE * _fopen(char * fname, char* mode) {
|
||||
FILE * fp = fopen(fname, mode);
|
||||
if (fp == NULL)
|
||||
{
|
||||
printf("Error opening a file\n");
|
||||
exit(1);
|
||||
}
|
||||
return fp;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int32_t DWORD_ALIGNED taps_buf[8] = {0};
|
||||
int32_t DWORD_ALIGNED taps_buf_2[8] = {0};
|
||||
int32_t DWORD_ALIGNED state[8] = {0};
|
||||
left_shift_t lsh = 0;
|
||||
left_shift_t lsh_2 = 0;
|
||||
int32_t shift = 0;
|
||||
|
||||
FILE * in = _fopen("../slew_sig_48k.bin", "rb");
|
||||
FILE * out = _fopen("sig_out.bin", "wb");
|
||||
FILE * coeffs = _fopen("coeffs.bin", "rb");
|
||||
FILE * coeffs_2 = _fopen("coeffs_2.bin", "rb");
|
||||
|
||||
fseek(in, 0, SEEK_END);
|
||||
int in_len = ftell(in) / sizeof(int32_t);
|
||||
fseek(in, 0, SEEK_SET);
|
||||
|
||||
fread(taps_buf, sizeof(int32_t), 5, coeffs);
|
||||
fread(&lsh, sizeof(int32_t), 1, coeffs);
|
||||
fread(&shift, sizeof(int32_t), 1, coeffs);
|
||||
fclose(coeffs);
|
||||
|
||||
fread(taps_buf_2, sizeof(int32_t), 5, coeffs_2);
|
||||
fread(&lsh_2, sizeof(int32_t), 1, coeffs_2);
|
||||
fclose(coeffs_2);
|
||||
|
||||
biquad_slew_t slew_state = adsp_biquad_slew_init(taps_buf, lsh, shift);
|
||||
|
||||
int32_t * states[1] = {&state[0]};
|
||||
|
||||
for (unsigned i = 0; i < in_len/2; i++)
|
||||
{
|
||||
adsp_biquad_slew_coeffs(&slew_state, states, 1);
|
||||
int32_t samp = 0, samp_out = 0;
|
||||
fread(&samp, sizeof(int32_t), 1, in);
|
||||
//printf("%ld ", samp);
|
||||
samp_out = adsp_biquad(samp, slew_state.active_coeffs, state, slew_state.lsh);
|
||||
// printf("%ld ", samp_out);
|
||||
fwrite(&samp_out, sizeof(int32_t), 1, out);
|
||||
}
|
||||
|
||||
adsp_biquad_slew_update_coeffs(&slew_state, states, 1, taps_buf_2, lsh_2);
|
||||
|
||||
for (unsigned i = in_len/2; i < in_len; i++)
|
||||
{
|
||||
adsp_biquad_slew_coeffs(&slew_state, states, 1);
|
||||
int32_t samp = 0, samp_out = 0;
|
||||
fread(&samp, sizeof(int32_t), 1, in);
|
||||
//printf("%ld ", samp);
|
||||
samp_out = adsp_biquad(samp, slew_state.active_coeffs, state, slew_state.lsh);
|
||||
// printf("%ld ", samp_out);
|
||||
fwrite(&samp_out, sizeof(int32_t), 1, out);
|
||||
}
|
||||
|
||||
fclose(in);
|
||||
fclose(out);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user