init
This commit is contained in:
49
lib_audio_dsp/test/signal_chain/src/adder.c
Normal file
49
lib_audio_dsp/test/signal_chain/src/adder.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 * in1 = _fopen("../sig1_48k.bin", "rb");
|
||||
FILE * out = _fopen("sig_out.bin", "wb");
|
||||
|
||||
fseek(in, 0, SEEK_END);
|
||||
int in_len = ftell(in) / sizeof(int32_t);
|
||||
fseek(in, 0, SEEK_SET);
|
||||
|
||||
|
||||
for (unsigned i = 0; i < in_len; i++)
|
||||
{
|
||||
int32_t samp = 0, samp1 = 0, samp_out = 0;
|
||||
int64_t acc = 0;
|
||||
fread(&samp, sizeof(int32_t), 1, in);
|
||||
fread(&samp1, sizeof(int32_t), 1, in1);
|
||||
//printf("%ld ", samp);
|
||||
acc += samp;
|
||||
acc += samp1;
|
||||
samp_out = adsp_saturate_32b(acc);
|
||||
//printf("%ld ", samp_out);
|
||||
fwrite(&samp_out, sizeof(int32_t), 1, out);
|
||||
}
|
||||
|
||||
fclose(in);
|
||||
fclose(in1);
|
||||
fclose(out);
|
||||
|
||||
return 0;
|
||||
}
|
||||
61
lib_audio_dsp/test/signal_chain/src/crossfader.c
Normal file
61
lib_audio_dsp/test/signal_chain/src/crossfader.c
Normal file
@@ -0,0 +1,61 @@
|
||||
// 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 gains[4] = {0};
|
||||
int32_t slew = 0;
|
||||
|
||||
FILE * in = _fopen("../sig_48k.bin", "rb");
|
||||
FILE * in1 = _fopen("../sig1_48k.bin", "rb");
|
||||
FILE * out = _fopen("sig_out.bin", "wb");
|
||||
FILE * gain = _fopen("gain.bin", "rb");
|
||||
|
||||
|
||||
fseek(in, 0, SEEK_END);
|
||||
int in_len = ftell(in) / sizeof(int32_t);
|
||||
fseek(in, 0, SEEK_SET);
|
||||
|
||||
fread(&slew, sizeof(int32_t), 1, gain);
|
||||
fread(gains, sizeof(int32_t), 4, gain);
|
||||
fclose(gain);
|
||||
|
||||
printf("gains: %ld %ld\n", gains[0], gains[1]);
|
||||
|
||||
crossfader_slew_t cfs = {.gain_1.gain=gains[0], .gain_1.target_gain=gains[2], .gain_1.slew_shift=slew,
|
||||
.gain_2.gain=gains[1], .gain_2.target_gain=gains[3], .gain_2.slew_shift=slew,
|
||||
.mix=0};
|
||||
|
||||
for (unsigned i = 0; i < in_len; i++)
|
||||
{
|
||||
int32_t samp = 0, samp1 = 0, samp_out = 0;
|
||||
fread(&samp, sizeof(int32_t), 1, in);
|
||||
fread(&samp1, sizeof(int32_t), 1, in1);
|
||||
//printf("%ld ", samp);
|
||||
samp_out = adsp_crossfader_slew(&cfs, samp, samp1);
|
||||
//printf("%ld ", samp_out);
|
||||
fwrite(&samp_out, sizeof(int32_t), 1, out);
|
||||
}
|
||||
|
||||
|
||||
fclose(in);
|
||||
fclose(in1);
|
||||
fclose(out);
|
||||
|
||||
return 0;
|
||||
}
|
||||
58
lib_audio_dsp/test/signal_chain/src/delay.c
Normal file
58
lib_audio_dsp/test/signal_chain/src/delay.c
Normal file
@@ -0,0 +1,58 @@
|
||||
// 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("delay.bin", "rb");
|
||||
|
||||
fseek(in, 0, SEEK_END);
|
||||
int in_len = ftell(in) / sizeof(int32_t);
|
||||
fseek(in, 0, SEEK_SET);
|
||||
|
||||
uint32_t start_delay, max_delay;
|
||||
fread(&max_delay, sizeof(uint32_t), 1, info);
|
||||
fread(&start_delay, sizeof(uint32_t), 1, info);
|
||||
fclose(info);
|
||||
|
||||
int32_t * buffer = (int32_t *) malloc(DELAY_DSP_REQUIRED_MEMORY_SAMPLES(max_delay));
|
||||
if (buffer == NULL)
|
||||
{
|
||||
printf("Error allocating memory\n");
|
||||
exit(2);
|
||||
}
|
||||
memset(buffer, 0, DELAY_DSP_REQUIRED_MEMORY_SAMPLES(max_delay));
|
||||
|
||||
delay_t delay = (delay_t) {0, start_delay, max_delay, 0, buffer};
|
||||
|
||||
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_delay(&delay, samp);
|
||||
//printf("%ld ", samp_out);
|
||||
fwrite(&samp_out, sizeof(int32_t), 1, out);
|
||||
}
|
||||
|
||||
fclose(in);
|
||||
fclose(out);
|
||||
|
||||
return 0;
|
||||
}
|
||||
48
lib_audio_dsp/test/signal_chain/src/fixed_gain.c
Normal file
48
lib_audio_dsp/test/signal_chain/src/fixed_gain.c
Normal file
@@ -0,0 +1,48 @@
|
||||
// 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 fixed_gain = 0;
|
||||
|
||||
FILE * in = _fopen("../sig_48k.bin", "rb");
|
||||
FILE * out = _fopen("sig_out.bin", "wb");
|
||||
FILE * gain = _fopen("gain.bin", "rb");
|
||||
|
||||
fseek(in, 0, SEEK_END);
|
||||
int in_len = ftell(in) / sizeof(int32_t);
|
||||
fseek(in, 0, SEEK_SET);
|
||||
|
||||
fread(&fixed_gain, sizeof(int32_t), 1, gain);
|
||||
fclose(gain);
|
||||
|
||||
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_fixed_gain(samp, fixed_gain);
|
||||
//printf("%ld ", samp_out);
|
||||
fwrite(&samp_out, sizeof(int32_t), 1, out);
|
||||
}
|
||||
|
||||
fclose(in);
|
||||
fclose(out);
|
||||
|
||||
return 0;
|
||||
}
|
||||
54
lib_audio_dsp/test/signal_chain/src/mixer.c
Normal file
54
lib_audio_dsp/test/signal_chain/src/mixer.c
Normal file
@@ -0,0 +1,54 @@
|
||||
// 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 fixed_gain = 0;
|
||||
|
||||
FILE * in = _fopen("../sig_48k.bin", "rb");
|
||||
FILE * in1 = _fopen("../sig1_48k.bin", "rb");
|
||||
FILE * out = _fopen("sig_out.bin", "wb");
|
||||
FILE * gain = _fopen("gain.bin", "rb");
|
||||
|
||||
fseek(in, 0, SEEK_END);
|
||||
int in_len = ftell(in) / sizeof(int32_t);
|
||||
fseek(in, 0, SEEK_SET);
|
||||
|
||||
fread(&fixed_gain, sizeof(int32_t), 1, gain);
|
||||
fclose(gain);
|
||||
|
||||
for (unsigned i = 0; i < in_len; i++)
|
||||
{
|
||||
int32_t samp = 0, samp1 = 0, samp_out = 0;
|
||||
int64_t acc = 0;
|
||||
fread(&samp, sizeof(int32_t), 1, in);
|
||||
fread(&samp1, sizeof(int32_t), 1, in1);
|
||||
//printf("%ld ", samp);
|
||||
acc += adsp_fixed_gain(samp, fixed_gain);
|
||||
acc += adsp_fixed_gain(samp1, fixed_gain);
|
||||
samp_out = adsp_saturate_32b(acc);
|
||||
//printf("%ld ", samp_out);
|
||||
fwrite(&samp_out, sizeof(int32_t), 1, out);
|
||||
}
|
||||
|
||||
fclose(in);
|
||||
fclose(in1);
|
||||
fclose(out);
|
||||
|
||||
return 0;
|
||||
}
|
||||
46
lib_audio_dsp/test/signal_chain/src/subtractor.c
Normal file
46
lib_audio_dsp/test/signal_chain/src/subtractor.c
Normal file
@@ -0,0 +1,46 @@
|
||||
// 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 * in1 = _fopen("../sig1_48k.bin", "rb");
|
||||
FILE * out = _fopen("sig_out.bin", "wb");
|
||||
|
||||
fseek(in, 0, SEEK_END);
|
||||
int in_len = ftell(in) / sizeof(int32_t);
|
||||
fseek(in, 0, SEEK_SET);
|
||||
|
||||
|
||||
for (unsigned i = 0; i < in_len; i++)
|
||||
{
|
||||
int32_t samp = 0, samp1 = 0, samp_out = 0;
|
||||
fread(&samp, sizeof(int32_t), 1, in);
|
||||
fread(&samp1, sizeof(int32_t), 1, in1);
|
||||
//printf("%ld ", samp);
|
||||
samp_out = adsp_subtractor(samp, samp1);
|
||||
//printf("%ld ", samp_out);
|
||||
fwrite(&samp_out, sizeof(int32_t), 1, out);
|
||||
}
|
||||
|
||||
fclose(in);
|
||||
fclose(in1);
|
||||
fclose(out);
|
||||
|
||||
return 0;
|
||||
}
|
||||
65
lib_audio_dsp/test/signal_chain/src/switch_slew.c
Normal file
65
lib_audio_dsp/test/signal_chain/src/switch_slew.c
Normal file
@@ -0,0 +1,65 @@
|
||||
// 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 * in1 = _fopen("../sig1_48k.bin", "rb");
|
||||
FILE * out = _fopen("sig_out.bin", "wb");
|
||||
|
||||
fseek(in, 0, SEEK_END);
|
||||
int in_len = ftell(in) / sizeof(int32_t);
|
||||
fseek(in, 0, SEEK_SET);
|
||||
|
||||
switch_slew_t switch_state = adsp_switch_slew_init(48000, 0);
|
||||
|
||||
for (unsigned i = 0; i < in_len/2; i++)
|
||||
{
|
||||
int32_t samples[2];
|
||||
int32_t samp_out = 0;
|
||||
fread(&samples[0], sizeof(int32_t), 1, in);
|
||||
fread(&samples[1], sizeof(int32_t), 1, in1);
|
||||
//printf("%ld ", samp);
|
||||
samp_out = adsp_switch_slew(&switch_state,
|
||||
samples);
|
||||
//printf("%ld ", samp_out);
|
||||
fwrite(&samp_out, sizeof(int32_t), 1, out);
|
||||
}
|
||||
|
||||
adsp_switch_slew_move(&switch_state, 1);
|
||||
|
||||
for (unsigned i = in_len/2; i < in_len; i++)
|
||||
{
|
||||
int32_t samples[2];
|
||||
int32_t samp_out = 0;
|
||||
fread(&samples[0], sizeof(int32_t), 1, in);
|
||||
fread(&samples[1], sizeof(int32_t), 1, in1);
|
||||
//printf("%ld ", samp);
|
||||
samp_out = adsp_switch_slew(&switch_state,
|
||||
samples);
|
||||
//printf("%ld ", samp_out);
|
||||
fwrite(&samp_out, sizeof(int32_t), 1, out);
|
||||
}
|
||||
|
||||
fclose(in);
|
||||
fclose(in1);
|
||||
fclose(out);
|
||||
|
||||
return 0;
|
||||
}
|
||||
74
lib_audio_dsp/test/signal_chain/src/volume_control.c
Normal file
74
lib_audio_dsp/test/signal_chain/src/volume_control.c
Normal file
@@ -0,0 +1,74 @@
|
||||
// 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;
|
||||
}
|
||||
|
||||
static inline void run_interval(FILE * in, FILE * out, unsigned bgn, unsigned end, volume_control_t * vol_ctl) {
|
||||
for (unsigned i = bgn; i < end; i++)
|
||||
{
|
||||
int32_t samp = 0, samp_out = 0;
|
||||
fread(&samp, sizeof(int32_t), 1, in);
|
||||
//printf("%ld ", samp);
|
||||
samp_out = adsp_volume_control(vol_ctl, samp);
|
||||
//printf("%ld ", samp_out);
|
||||
fwrite(&samp_out, sizeof(int32_t), 1, out);
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int32_t mute_test = 0;
|
||||
int32_t slew_shift = 0;
|
||||
int32_t gains[3] = {0};
|
||||
unsigned intervals[4] = {0};
|
||||
|
||||
FILE * in = _fopen("../sig_48k.bin", "rb");
|
||||
FILE * out = _fopen("sig_out.bin", "wb");
|
||||
FILE * conf = _fopen("gain.bin", "rb");
|
||||
|
||||
fseek(in, 0, SEEK_END);
|
||||
int in_len = ftell(in) / sizeof(int32_t);
|
||||
fseek(in, 0, SEEK_SET);
|
||||
intervals[1] = in_len / 3;
|
||||
intervals[2] = intervals[1] * 2;
|
||||
intervals[3] = in_len;
|
||||
|
||||
fread(&mute_test, sizeof(int32_t), 1, conf);
|
||||
fread(&slew_shift, sizeof(int32_t), 1, conf);
|
||||
fread(gains, sizeof(int32_t), 3, conf);
|
||||
fclose(conf);
|
||||
|
||||
//printf("ls %ld %ld %ld %ld\n", slew_shift, gains[0], gains[1], gains[2]);
|
||||
|
||||
volume_control_t vol_ctl = (volume_control_t){gains[0], gains[0], slew_shift};
|
||||
|
||||
run_interval(in, out, intervals[0], intervals[1], &vol_ctl);
|
||||
|
||||
adsp_volume_control_set_gain(&vol_ctl, gains[1]);
|
||||
if (mute_test) {adsp_volume_control_mute(&vol_ctl);}
|
||||
|
||||
run_interval(in, out, intervals[1], intervals[2], &vol_ctl);
|
||||
|
||||
adsp_volume_control_set_gain(&vol_ctl, gains[2]);
|
||||
if (mute_test) {adsp_volume_control_unmute(&vol_ctl);}
|
||||
|
||||
run_interval(in, out, intervals[2], intervals[3], &vol_ctl);
|
||||
|
||||
fclose(in);
|
||||
fclose(out);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user