init
This commit is contained in:
50
lib_audio_dsp/test/drc/src/clipper.c
Normal file
50
lib_audio_dsp/test/drc/src/clipper.c
Normal file
@@ -0,0 +1,50 @@
|
||||
// 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()
|
||||
{
|
||||
FILE * in = _fopen("../sig_48k.bin", "rb");
|
||||
FILE * out = _fopen("sig_out.bin", "wb");
|
||||
FILE * info = _fopen("info.bin", "rb");
|
||||
|
||||
fseek(in, 0, SEEK_END);
|
||||
int in_len = ftell(in) / sizeof(int32_t);
|
||||
fseek(in, 0, SEEK_SET);
|
||||
|
||||
int32_t th;
|
||||
|
||||
fread(&th, sizeof(int32_t), 1, info);
|
||||
fclose(info);
|
||||
|
||||
clipper_t clip = th;
|
||||
|
||||
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_clipper(clip, samp);
|
||||
//printf("%ld ", samp_out);
|
||||
fwrite(&samp_out, sizeof(int32_t), 1, out);
|
||||
}
|
||||
|
||||
fclose(in);
|
||||
fclose(out);
|
||||
|
||||
return 0;
|
||||
}
|
||||
55
lib_audio_dsp/test/drc/src/compressor_rms.c
Normal file
55
lib_audio_dsp/test/drc/src/compressor_rms.c
Normal file
@@ -0,0 +1,55 @@
|
||||
// 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()
|
||||
{
|
||||
FILE * in = _fopen("../sig_48k.bin", "rb");
|
||||
FILE * out = _fopen("sig_out.bin", "wb");
|
||||
FILE * comp_info = _fopen("info.bin", "rb");
|
||||
|
||||
fseek(in, 0, SEEK_END);
|
||||
int in_len = ftell(in) / sizeof(int32_t);
|
||||
fseek(in, 0, SEEK_SET);
|
||||
|
||||
int32_t th, at_al, re_al;
|
||||
float sl;
|
||||
|
||||
fread(&th, sizeof(int32_t), 1, comp_info);
|
||||
fread(&at_al, sizeof(int32_t), 1, comp_info);
|
||||
fread(&re_al, sizeof(int32_t), 1, comp_info);
|
||||
fread(&sl, sizeof(float), 1, comp_info);
|
||||
fclose(comp_info);
|
||||
|
||||
compressor_t comp = (compressor_t){
|
||||
(env_detector_t){at_al, re_al, 0}, th, INT32_MAX, sl};
|
||||
|
||||
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_compressor_rms(&comp, samp);
|
||||
//printf("%ld ", samp_out);
|
||||
fwrite(&samp_out, sizeof(int32_t), 1, out);
|
||||
}
|
||||
|
||||
fclose(in);
|
||||
fclose(out);
|
||||
|
||||
return 0;
|
||||
}
|
||||
59
lib_audio_dsp/test/drc/src/compressor_rms_sidechain_mono.c
Normal file
59
lib_audio_dsp/test/drc/src/compressor_rms_sidechain_mono.c
Normal file
@@ -0,0 +1,59 @@
|
||||
// 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()
|
||||
{
|
||||
//FILE * in0 = _fopen("ch0.bin", "rb");
|
||||
//FILE * in1 = _fopen("ch1.bin", "rb");
|
||||
FILE * in = _fopen("../sig_2ch_48k.bin", "rb");
|
||||
FILE * out = _fopen("sig_out.bin", "wb");
|
||||
FILE * comp_info = _fopen("info.bin", "rb");
|
||||
|
||||
fseek(in, 0, SEEK_END);
|
||||
int in_len = ftell(in) / (sizeof(int32_t) * 2); // two channels
|
||||
fseek(in, 0, SEEK_SET);
|
||||
|
||||
int32_t th, at_al, re_al;
|
||||
float sl;
|
||||
|
||||
fread(&th, sizeof(int32_t), 1, comp_info);
|
||||
fread(&at_al, sizeof(int32_t), 1, comp_info);
|
||||
fread(&re_al, sizeof(int32_t), 1, comp_info);
|
||||
fread(&sl, sizeof(float), 1, comp_info);
|
||||
fclose(comp_info);
|
||||
|
||||
compressor_t comp = (compressor_t){
|
||||
(env_detector_t){at_al, re_al, 0}, th, INT32_MAX, sl};
|
||||
|
||||
for (unsigned i = 0; i < in_len; i++)
|
||||
{
|
||||
int32_t samp0 = 0, samp1 = 0, samp_out = 0;
|
||||
fread(&samp0, sizeof(int32_t), 1, in);
|
||||
fread(&samp1, sizeof(int32_t), 1, in);
|
||||
//printf("%ld ", samp);
|
||||
samp_out = adsp_compressor_rms_sidechain(&comp, samp0, samp1);
|
||||
//printf("%ld ", samp_out);
|
||||
fwrite(&samp_out, sizeof(int32_t), 1, out);
|
||||
}
|
||||
|
||||
fclose(in);
|
||||
//fclose(in1);
|
||||
fclose(out);
|
||||
|
||||
return 0;
|
||||
}
|
||||
63
lib_audio_dsp/test/drc/src/compressor_rms_sidechain_stereo.c
Normal file
63
lib_audio_dsp/test/drc/src/compressor_rms_sidechain_stereo.c
Normal file
@@ -0,0 +1,63 @@
|
||||
// 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()
|
||||
{
|
||||
//FILE * in0 = _fopen("ch0.bin", "rb");
|
||||
//FILE * in1 = _fopen("ch1.bin", "rb");
|
||||
FILE * in = _fopen("../sig_4ch_48k.bin", "rb");
|
||||
FILE * out = _fopen("sig_out.bin", "wb");
|
||||
FILE * comp_info = _fopen("info.bin", "rb");
|
||||
|
||||
fseek(in, 0, SEEK_END);
|
||||
int in_len = ftell(in) / (sizeof(int32_t) * 4); // two channels
|
||||
fseek(in, 0, SEEK_SET);
|
||||
|
||||
int32_t th, at_al, re_al;
|
||||
float sl;
|
||||
|
||||
fread(&th, sizeof(int32_t), 1, comp_info);
|
||||
fread(&at_al, sizeof(int32_t), 1, comp_info);
|
||||
fread(&re_al, sizeof(int32_t), 1, comp_info);
|
||||
fread(&sl, sizeof(float), 1, comp_info);
|
||||
fclose(comp_info);
|
||||
|
||||
compressor_stereo_t comp = (compressor_stereo_t){
|
||||
(env_detector_t){at_al, re_al, 0},
|
||||
(env_detector_t){at_al, re_al, 0}, th, INT32_MAX, sl};
|
||||
|
||||
for (unsigned i = 0; i < in_len; i++)
|
||||
{
|
||||
int32_t samp0 = 0, samp1 = 0, samp2 = 0, samp3 = 0, samp_out[2] = {0};
|
||||
fread(&samp0, sizeof(int32_t), 1, in);
|
||||
fread(&samp1, sizeof(int32_t), 1, in);
|
||||
fread(&samp2, sizeof(int32_t), 1, in);
|
||||
fread(&samp3, sizeof(int32_t), 1, in);
|
||||
|
||||
//printf("%ld ", samp);
|
||||
adsp_compressor_rms_sidechain_stereo(&comp, samp_out, samp0, samp1, samp2, samp3);
|
||||
//printf("%ld ", samp_out);
|
||||
fwrite(samp_out, sizeof(int32_t), 2, out);
|
||||
}
|
||||
|
||||
fclose(in);
|
||||
//fclose(in1);
|
||||
fclose(out);
|
||||
|
||||
return 0;
|
||||
}
|
||||
49
lib_audio_dsp/test/drc/src/envelope_detector_peak.c
Normal file
49
lib_audio_dsp/test/drc/src/envelope_detector_peak.c
Normal file
@@ -0,0 +1,49 @@
|
||||
// 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()
|
||||
{
|
||||
FILE * in = _fopen("../sig_48k.bin", "rb");
|
||||
FILE * out = _fopen("sig_out.bin", "wb");
|
||||
FILE * env_info = _fopen("env_info.bin", "rb");
|
||||
|
||||
fseek(in, 0, SEEK_END);
|
||||
int in_len = ftell(in) / sizeof(int32_t);
|
||||
fseek(in, 0, SEEK_SET);
|
||||
|
||||
int32_t at_al, re_al;
|
||||
|
||||
fread(&at_al, sizeof(int32_t), 1, env_info);
|
||||
fread(&re_al, sizeof(int32_t), 1, env_info);
|
||||
fclose(env_info);
|
||||
|
||||
env_detector_t env_det = (env_detector_t){at_al, re_al, 0};
|
||||
|
||||
for (unsigned i = 0; i < in_len; i++)
|
||||
{
|
||||
int32_t samp = 0;
|
||||
fread(&samp, sizeof(int32_t), 1, in);
|
||||
adsp_env_detector_peak(&env_det, samp);
|
||||
fwrite(&env_det.envelope, sizeof(int32_t), 1, out);
|
||||
}
|
||||
|
||||
fclose(in);
|
||||
fclose(out);
|
||||
|
||||
return 0;
|
||||
}
|
||||
49
lib_audio_dsp/test/drc/src/envelope_detector_rms.c
Normal file
49
lib_audio_dsp/test/drc/src/envelope_detector_rms.c
Normal file
@@ -0,0 +1,49 @@
|
||||
// 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()
|
||||
{
|
||||
FILE * in = _fopen("../sig_48k.bin", "rb");
|
||||
FILE * out = _fopen("sig_out.bin", "wb");
|
||||
FILE * env_info = _fopen("env_info.bin", "rb");
|
||||
|
||||
fseek(in, 0, SEEK_END);
|
||||
int in_len = ftell(in) / sizeof(int32_t);
|
||||
fseek(in, 0, SEEK_SET);
|
||||
|
||||
int32_t at_al, re_al;
|
||||
|
||||
fread(&at_al, sizeof(int32_t), 1, env_info);
|
||||
fread(&re_al, sizeof(int32_t), 1, env_info);
|
||||
fclose(env_info);
|
||||
|
||||
env_detector_t env_det = (env_detector_t){at_al, re_al, 0};
|
||||
|
||||
for (unsigned i = 0; i < in_len; i++)
|
||||
{
|
||||
int32_t samp = 0;
|
||||
fread(&samp, sizeof(int32_t), 1, in);
|
||||
adsp_env_detector_rms(&env_det, samp);
|
||||
fwrite(&env_det.envelope, sizeof(int32_t), 1, out);
|
||||
}
|
||||
|
||||
fclose(in);
|
||||
fclose(out);
|
||||
|
||||
return 0;
|
||||
}
|
||||
53
lib_audio_dsp/test/drc/src/hard_limiter_peak.c
Normal file
53
lib_audio_dsp/test/drc/src/hard_limiter_peak.c
Normal file
@@ -0,0 +1,53 @@
|
||||
// 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()
|
||||
{
|
||||
FILE * in = _fopen("../sig_48k.bin", "rb");
|
||||
FILE * out = _fopen("sig_out.bin", "wb");
|
||||
FILE * lim_info = _fopen("info.bin", "rb");
|
||||
|
||||
fseek(in, 0, SEEK_END);
|
||||
int in_len = ftell(in) / sizeof(int32_t);
|
||||
fseek(in, 0, SEEK_SET);
|
||||
|
||||
int32_t th, at_al, re_al;
|
||||
|
||||
fread(&th, sizeof(int32_t), 1, lim_info);
|
||||
fread(&at_al, sizeof(int32_t), 1, lim_info);
|
||||
fread(&re_al, sizeof(int32_t), 1, lim_info);
|
||||
fclose(lim_info);
|
||||
|
||||
limiter_t lim = (limiter_t){
|
||||
(env_detector_t){at_al, re_al, 0}, th, INT32_MAX};
|
||||
|
||||
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_hard_limiter_peak(&lim, samp);
|
||||
//printf("%ld ", samp_out);
|
||||
fwrite(&samp_out, sizeof(int32_t), 1, out);
|
||||
}
|
||||
|
||||
fclose(in);
|
||||
fclose(out);
|
||||
|
||||
return 0;
|
||||
}
|
||||
53
lib_audio_dsp/test/drc/src/limiter_peak.c
Normal file
53
lib_audio_dsp/test/drc/src/limiter_peak.c
Normal file
@@ -0,0 +1,53 @@
|
||||
// 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()
|
||||
{
|
||||
FILE * in = _fopen("../sig_48k.bin", "rb");
|
||||
FILE * out = _fopen("sig_out.bin", "wb");
|
||||
FILE * lim_info = _fopen("info.bin", "rb");
|
||||
|
||||
fseek(in, 0, SEEK_END);
|
||||
int in_len = ftell(in) / sizeof(int32_t);
|
||||
fseek(in, 0, SEEK_SET);
|
||||
|
||||
int32_t th, at_al, re_al;
|
||||
|
||||
fread(&th, sizeof(int32_t), 1, lim_info);
|
||||
fread(&at_al, sizeof(int32_t), 1, lim_info);
|
||||
fread(&re_al, sizeof(int32_t), 1, lim_info);
|
||||
fclose(lim_info);
|
||||
|
||||
limiter_t lim = (limiter_t){
|
||||
(env_detector_t){at_al, re_al, 0}, th, INT32_MAX};
|
||||
|
||||
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_limiter_peak(&lim, samp);
|
||||
//printf("%ld ", samp_out);
|
||||
fwrite(&samp_out, sizeof(int32_t), 1, out);
|
||||
}
|
||||
|
||||
fclose(in);
|
||||
fclose(out);
|
||||
|
||||
return 0;
|
||||
}
|
||||
53
lib_audio_dsp/test/drc/src/limiter_rms.c
Normal file
53
lib_audio_dsp/test/drc/src/limiter_rms.c
Normal file
@@ -0,0 +1,53 @@
|
||||
// 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()
|
||||
{
|
||||
FILE * in = _fopen("../sig_48k.bin", "rb");
|
||||
FILE * out = _fopen("sig_out.bin", "wb");
|
||||
FILE * lim_info = _fopen("info.bin", "rb");
|
||||
|
||||
fseek(in, 0, SEEK_END);
|
||||
int in_len = ftell(in) / sizeof(int32_t);
|
||||
fseek(in, 0, SEEK_SET);
|
||||
|
||||
int32_t th, at_al, re_al;
|
||||
|
||||
fread(&th, sizeof(int32_t), 1, lim_info);
|
||||
fread(&at_al, sizeof(int32_t), 1, lim_info);
|
||||
fread(&re_al, sizeof(int32_t), 1, lim_info);
|
||||
fclose(lim_info);
|
||||
|
||||
limiter_t lim = (limiter_t){
|
||||
(env_detector_t){at_al, re_al, 0}, th, INT32_MAX};
|
||||
|
||||
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_limiter_rms(&lim, samp);
|
||||
//printf("%ld ", samp_out);
|
||||
fwrite(&samp_out, sizeof(int32_t), 1, out);
|
||||
}
|
||||
|
||||
fclose(in);
|
||||
fclose(out);
|
||||
|
||||
return 0;
|
||||
}
|
||||
53
lib_audio_dsp/test/drc/src/noise_gate.c
Normal file
53
lib_audio_dsp/test/drc/src/noise_gate.c
Normal file
@@ -0,0 +1,53 @@
|
||||
// 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()
|
||||
{
|
||||
FILE * in = _fopen("../sig_48k.bin", "rb");
|
||||
FILE * out = _fopen("sig_out.bin", "wb");
|
||||
FILE * ng_info = _fopen("info.bin", "rb");
|
||||
|
||||
fseek(in, 0, SEEK_END);
|
||||
int in_len = ftell(in) / sizeof(int32_t);
|
||||
fseek(in, 0, SEEK_SET);
|
||||
|
||||
int32_t th, at_al, re_al;
|
||||
|
||||
fread(&th, sizeof(int32_t), 1, ng_info);
|
||||
fread(&at_al, sizeof(int32_t), 1, ng_info);
|
||||
fread(&re_al, sizeof(int32_t), 1, ng_info);
|
||||
fclose(ng_info);
|
||||
|
||||
noise_gate_t ng = (noise_gate_t){
|
||||
(env_detector_t){at_al, re_al, (1 << (-SIG_EXP)) - 1}, th, INT32_MAX};
|
||||
|
||||
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_noise_gate(&ng, samp);
|
||||
//printf("%ld ", samp_out);
|
||||
fwrite(&samp_out, sizeof(int32_t), 1, out);
|
||||
}
|
||||
|
||||
fclose(in);
|
||||
fclose(out);
|
||||
|
||||
return 0;
|
||||
}
|
||||
57
lib_audio_dsp/test/drc/src/noise_suppressor_expander.c
Normal file
57
lib_audio_dsp/test/drc/src/noise_suppressor_expander.c
Normal file
@@ -0,0 +1,57 @@
|
||||
// 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/adsp_control.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()
|
||||
{
|
||||
FILE * in = _fopen("../sig_48k.bin", "rb");
|
||||
FILE * out = _fopen("sig_out.bin", "wb");
|
||||
FILE * nse_info = _fopen("info.bin", "rb");
|
||||
|
||||
fseek(in, 0, SEEK_END);
|
||||
int in_len = ftell(in) / sizeof(int32_t);
|
||||
fseek(in, 0, SEEK_SET);
|
||||
|
||||
int32_t th, at_al, re_al;
|
||||
float slope;
|
||||
|
||||
fread(&th, sizeof(int32_t), 1, nse_info);
|
||||
fread(&at_al, sizeof(int32_t), 1, nse_info);
|
||||
fread(&re_al, sizeof(int32_t), 1, nse_info);
|
||||
fread(&slope, sizeof(float), 1, nse_info);
|
||||
|
||||
fclose(nse_info);
|
||||
if (!th) th = 1;
|
||||
noise_suppressor_expander_t nse = (noise_suppressor_expander_t){
|
||||
(env_detector_t){at_al, re_al, (1 << (Q_SIG)) - 1}, 0, 0, INT32_MAX, slope};
|
||||
adsp_noise_suppressor_expander_set_th(&nse, th);
|
||||
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_noise_suppressor_expander(&nse, samp);
|
||||
//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