Files
99_7018_lmx/apps/common/audio/audio_ns.c

113 lines
3.6 KiB
C
Raw Normal View History

2025-10-29 13:10:02 +08:00
/*
******************************************************************
* Noise Suppress Module()
*Notes:
*(1)8k/16k
*(2)5k左右代码
*(3)
* int ns_mem_size = noise_suppress_mem_query(&ans->ns_para);
******************************************************************
*/
#include "audio_ns.h"
#ifdef CONFIG_MEDIA_NEW_ENABLE
/*
*********************************************************************
* NoiseSuppress Process
* Description:
* Arguments : ns
* in
* out
* len
* Return :
* Note(s) :
* 0
*********************************************************************
*/
int audio_ns_run(audio_ns_t *ns, short *in, short *out, u16 len)
{
if (ns == NULL) {
return len;
}
#if 0
int wlen = cbuf_write(&ns->cbuf, in, len);
if (wlen != len) {
printf("ns_cbuf full\n");
}
if (ns->cbuf.data_len >= NS_FRAME_SIZE) {
cbuf_read(&ns->cbuf, out, NS_FRAME_SIZE);
putchar('.');
noise_suppress_run(out, out, NS_FRAME_POINTS);
return NS_FRAME_SIZE;
} else {
return 0;
}
#else
//putchar('.');
int nOut = noise_suppress_run(in, out, (len / 2));
return (nOut << 1);
#endif
}
/*
*********************************************************************
* Noise Suppress Open
* Description:
* Arguments : sr
* mode (0,1,2:)
* NoiseLevel ()
* AggressFactor (:1~2)
* MinSuppress (:0~1)
* Return :
* Note(s) : (1)8k16k
* (2)wideband强制为0
* ans-ns_para.wideband = 0;
*********************************************************************
*/
audio_ns_t *audio_ns_open(u16 sr, u8 mode, float NoiseLevel, float AggressFactor, float MinSuppress)
{
audio_ns_t *ans = zalloc(sizeof(audio_ns_t));
//cbuf_init(&ans->cbuf, ans->in, sizeof(ans->in));
ans->ns_para.wideband = (sr == 16000) ? 1 : 0;
ans->ns_para.mode = mode;
ans->ns_para.NoiseLevel = NoiseLevel;
ans->ns_para.AggressFactor = AggressFactor;
ans->ns_para.MinSuppress = MinSuppress;
printf("ns wideband:%d\n", ans->ns_para.wideband);
//int ns_mem_size = noise_suppress_mem_query(&ans->ns_para);
//printf("ns mem_size:%d\n", ns_mem_size);
noise_suppress_open(&ans->ns_para);
float lowcut = -60.f;
noise_suppress_config(NS_CMD_LOWCUTTHR, 0, &lowcut);
float noise_floor = -60.f;
noise_suppress_config(NS_CMD_NOISE_FLOOR, 0, &noise_floor);
printf("audio_ns_open ok\n");
return ans;
}
/*
*********************************************************************
* Noise Suppress Close
* Description:
* Arguments : ns
* Return : 0
* Note(s) : None.
*********************************************************************
*/
int audio_ns_close(audio_ns_t *ns)
{
noise_suppress_close();
if (ns) {
free(ns);
ns = NULL;
}
printf("esco_ans_close ok\n");
return 0;
}
#endif /*CONFIG_MEDIA_NEW_ENABLE*/