NoiseReduction.c
833 字节
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <math.h>
#include "JZsdkLib.h"
// T_JZsdkReturnCode PcmNoiseReduction(unsigned char *data, int len, int threshold)
// {
// for (int i = 0; i < len; i++)
// {
// if (abs(data) >= 0xFF)
// {
// data[i] = 0;
// }
// }
// return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
// }
#define NOISE_THRESHOLD 0.003 // 降噪阈值
short PcmNoiseReduction(short data)
{
// 转换为浮点数并进行降噪
short re_data;
float float_buffer = data / 32768.0f;
if (fabs(float_buffer) < NOISE_THRESHOLD)
{
float_buffer = 0.0f; // 如果样本小于阈值,则将其置为零
}
re_data = (short)(float_buffer * 32767.0f); // 溢出处理
return re_data;
}