当前位置:网站首页 > 技术博客 > 正文

音频降噪工具



#include <stdio.h> #include <stdlib.h> #include <stdint.h> #include <assert.h> #include <string.h> #include <speex/speex_preprocess.h> #include <speex/speex.h> #define HEADLEN 44 #define SAMPLE_RATE (48000) #define SAMPLES_PER_FRAME (1024) #define FRAME_SIZE (SAMPLES_PER_FRAME * 1000/ SAMPLE_RATE) #define FRAME_BYTES (SAMPLES_PER_FRAME) int main() { size_t n = 0; FILE *inFile, *outFile; fopen_s(&inFile, "https://www.cnblogs.com/riddick/p/audio/input01L.wav", "rb"); fopen_s(&outFile, "https://www.cnblogs.com/riddick/p/audio/output01L.wav", "wb"); char *headBuf = (char*)malloc(HEADLEN); char *dataBuf = (char*)malloc(FRAME_BYTES * 2 ); memset(headBuf, 0, HEADLEN); memset(dataBuf, 0, FRAME_BYTES); assert(headBuf != NULL); assert(dataBuf != NULL); SpeexPreprocessState *state = speex_preprocess_state_init(1024, SAMPLE_RATE); int denoise = 1; int noiseSuppress = -25; speex_preprocess_ctl(state, SPEEX_PREPROCESS_SET_DENOISE, &denoise); speex_preprocess_ctl(state, SPEEX_PREPROCESS_SET_NOISE_SUPPRESS, &noiseSuppress); int i; i = 0; speex_preprocess_ctl(state, SPEEX_PREPROCESS_SET_AGC, &i); i = 80000; speex_preprocess_ctl(state, SPEEX_PREPROCESS_SET_AGC_LEVEL, &i); i = 0; speex_preprocess_ctl(state, SPEEX_PREPROCESS_SET_DEREVERB, &i); float f = 0; speex_preprocess_ctl(state, SPEEX_PREPROCESS_SET_DEREVERB_DECAY, &f); f = 0; speex_preprocess_ctl(state, SPEEX_PREPROCESS_SET_DEREVERB_LEVEL, &f); //静音检测 /*int vad = 1; int vadProbStart = 80; int vadProbContinue = 65; speex_preprocess_ctl(state, SPEEX_PREPROCESS_SET_VAD, &vad); speex_preprocess_ctl(state, SPEEX_PREPROCESS_SET_PROB_START, &vadProbStart); speex_preprocess_ctl(state, SPEEX_PREPROCESS_SET_PROB_CONTINUE, &vadProbContinue);*/ bool flag = true; while (1) { if (flag == true) { flag = false; n = fread(headBuf, 1, HEADLEN, inFile); if (n == 0) break; fwrite(headBuf, 1, HEADLEN, outFile); } else { n = fread(dataBuf, 1, SAMPLES_PER_FRAME, inFile); if (n == 0) break; speex_preprocess_run(state, (spx_int16_t*)(dataBuf)); fwrite(dataBuf, 1, SAMPLES_PER_FRAME, outFile); } } free(headBuf); free(dataBuf); fclose(inFile); fclose(outFile); speex_preprocess_state_destroy(state); return 0; }

版权声明


相关文章:

  • css的选择器及其用法2024-12-02 20:30:02
  • 好用的网络调试助手2024-12-02 20:30:02
  • java单元测试步骤2024-12-02 20:30:02
  • c udp发送数据2024-12-02 20:30:02
  • expdp include=table2024-12-02 20:30:02
  • jstl包含用于编写和开发jsp2024-12-02 20:30:02
  • 霍夫曼树权值2024-12-02 20:30:02
  • time has value2024-12-02 20:30:02
  • 一句话木马图片2024-12-02 20:30:02
  • 同步fifo verilog2024-12-02 20:30:02