NoiseReduction.c 833 字节
#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;
}