SGS WNR ALGORITHM USER GUIDE¶
REVISION HISTORY¶
| Revision No. | Description |
Date |
|---|---|---|
| 1.0 | 07/19/2024 | |
| 1.01 | 04/25/2025 | |
| 1.02 | 05/14/2025 | |
| 1.03 | 05/21/2025 | |
| 1.1 | 11/03/2025 |
1. Overview¶
1.1. Algorithm Description¶
Wind Noise Reduction algorithm (WNR) is designed to suppress wind noise in the environment to improve speech quality. If the Library file contains deep learning mode (MODE1), dynamic library is not supported.
2. API Reference¶
| API Name | Function |
|---|---|
| IaaWnr_GetBufferSize | Get the memory size required to run the WNR algorithm |
| IaaWnr_Init | Initialize WNR algorithm |
| IaaWnr_Config | Set WNR algorithm parameters |
| IaaWnr_Run | Run WNR algorithm |
| IaaWnr_Free | Free WNR algorithm resources |
| IaaWnr_SetHandleId | Set WNR algorithm ID |
| IaaWnr_GetJsonFileSize | WNR get size of json file |
| IaaWnr_InitReadFromJson | Set json parameter into WNR init structure |
| IaaWnr_ConfigReadFromJson | Set json parameter into WNR config structure |
2.1. IaaWnr_GetBufferSize¶
-
Function
Get the memory size required to run the WNR algorithm
-
Syntax
unsigned int IaaWnr_GetBufferSize(void); -
Parameter
Parameter Name Description Input/Output N/A -
Return Value
The return value is the memory size required to run the WNR algorithm.
-
Dependency
-
Header file: AudioWnrProcess.h
-
Library file: libWNR_LINUX.so/ libWNR_LINUX.a
-
-
Note
This interface only returns the required memory size. To apply and release the memory, you need to use other APIs.
-
Example
Please refer to the example section of IaaWnr_Run.
2.2. IaaWnr_Init¶
-
Function
Initialize WNR algorithm
-
Syntax
WNR_HANDLE IaaWnr_Init(char* const working_buffer_address, AudioWnrInit *wnr_init); -
Parameter
Parameter name Description Input/Output working_buffer_address Memory address used by WNR algorithm Input wnr_init WNR algorithm initialization structure pointer Input -
Return Value
Return Value Result Non-NULL Successful NULL Failed -
Dependency
-
Header file: AudioWnrProcess.h
-
Library file: libWNR_LINUX.so/ libWNR_LINUX.a
-
-
Note
N/A
-
Example
Please refer to IaaWnr_Run example.
2.3. IaaWnr_Config¶
-
Function
Set WNR algorithm parameters.
-
Syntax
ALGO_WNR_RET IaaWnr_Config(WNR_HANDLE handle, AudioWnrConfig *wnr_config); -
Parameter
Parameter name Description Input/Output handle WNR algorithm handle Input wnr_config WNR algorithm parameter setting structure Input -
Return Value
Return Value Result 0 Successful Non-zero Failed, refer to Error code -
Dependency
-
Header file: AudioWnrProcess.h
-
Library file: libWNR_LINUX.so/ libWNR_LINUX.a
-
-
Note
N/A
-
Example
Please refer to IaaWnr_Run example
2.4. IaaWnr_Run¶
-
Function
Run WNR algorithm.
-
Syntax
ALGO_WNR_RET IaaWnr_Run(WNR_HANDLE handle, short* pss_audio_in); -
Parameter
Parameter name Description Input/Output handle Algorithm handle Input pss_audio_in Input data pointer Input -
Return Value
Return Value Result 0 Successful Non-zero Failed, refer to Error code -
Dependency
-
Header file: AudioWnrProcess.h
-
Library file: libWNR_LINUX.so/ libWNR_LINUX.a
-
-
Note
N/A
-
Example
#include <stdio.h> #include <string.h> #include <time.h> #include <stdlib.h> #ifndef OS_WINDOWS #include <sys/ioctl.h> #endif #include <sys/types.h> #include <sys/stat.h> #include <sys/time.h> #include "AudioWnrProcess.h" #define USE_MALLOC (1) unsigned int WorkingBuffer2[1] = {0}; typedef unsigned char uint8; typedef unsigned short uint16; typedef unsigned long uint32; float AVERAGE_RUN(int a) { static unsigned int num = 0; static float avg = 0; if(num == 0) avg = 0; num++; avg = avg + ((float)a - avg) / ((float)num); return avg; } unsigned int _OsCounterGetMs(void) { struct timeval t1; gettimeofday(&t1,NULL); unsigned int T = ( (1000000 * t1.tv_sec)+ t1.tv_usec ); return T; } int main(int argc, char *argv[]) { short input[1024]; char input_file[512]; char outfile_name[512]; unsigned int T0, T1; float avg = 0; int counter=0; #if USE_MALLOC char *working_buf_ptr = (char*)malloc(IaaWnr_GetBufferSize()); #else char working_buf_ptr[512*100*2]; #endif FILE * fin, *fout; int ret1; WNR_HANDLE handle; AudioWnrInit wnr_init; AudioWnrConfig wnr_config; char wnr_para_json_file[512]; sprintf(wnr_para_json_file,"%s","./../sample/data/WnrParamJson.json"); unsigned int wnr_para_buffersize = IaaWnr_GetJsonFileSize(wnr_para_json_file); char *wnr_para_json_buf_ptr = (char*)malloc(wnr_para_buffersize); memset(&wnr_init,0,sizeof(AudioWnrInit)); memset(&wnr_config,0,sizeof(AudioWnrConfig)); ret1 = IaaWnr_InitReadFromJson(&wnr_init, wnr_para_json_buf_ptr, wnr_para_json_file, wnr_para_buffersize); ret1 = IaaWnr_ConfigReadFromJson(&wnr_config, wnr_para_json_buf_ptr, wnr_para_json_file, wnr_para_buffersize); if(ret1 < 0) { printf("Error occured Read JSON file\n"); return -1; } handle = IaaWnr_Init((char *)working_buf_ptr, &wnr_init); if(handle==NULL) { printf("WNR init error\r\n"); return -1; } else { printf("WNR init succeed\r\n"); } if(IaaWnr_Config(handle, &wnr_config) == -1) { printf("Config Error!"); return -1; } sprintf(input_file,"%s","./../sample/data/m5dB_p228_217_mic1_test_gusts_07.wav"); sprintf(outfile_name,"%s","./../sample/data/m5dB_p228_217_mic1_test_gusts_07_sim.wav"); fin = fopen(input_file, "rb"); if(!fin) { printf("the input file %s could not be open\n",input_file); return -1; } fout = fopen(outfile_name, "wb"); if (!fout) { fprintf(stderr, "Error opening file: %s\n", outfile_name); return -1; } fread(input, sizeof(char), 44, fin); // read header 44 bytes fwrite(input, sizeof(char),44, fout); // write 44 bytes output while(fread(input, sizeof(short), wnr_init.point_number*wnr_init.channel, fin)) { counter++; T0 = (long)_OsCounterGetMs(); ret1 = IaaWnr_Run(handle, input); T1 = (long)_OsCounterGetMs(); avg += (T1 - T0); if(ret1 < 0) { printf("Error occured in WNR\n"); break; } fwrite(input, sizeof(short), wnr_init.point_number*wnr_init.channel, fout); } avg /= counter; printf("AVG is %.2f us\n",avg); IaaWnr_Free(handle); free(working_buf_ptr); fclose(fin); fclose(fout); printf("Done\n"); return 0;
2.5. IaaWnr_Free¶
-
Function
Free WNR algorithm resources.
-
Syntax
ALGO_WNR_RET IaaWnr_Free(WNR_HANDLE handle); -
Parameter
Parameter name Description Input/Output handle WNR algorithm handle Input -
Return Value
Return Value Result 0 Successful Non-zero Failed, refer to Error code -
Dependency
-
Header file: AudioWnrProcess.h
-
Library file: libWNR_LINUX.so/ libWNR_LINUX.a
-
-
Note
IaaWnr_Free must be called first before releasing the memory used by the WNR algorithm
-
Example
Please refer to IaaWnr_Run example.
2.6. IaaWnr_SetHandleId¶
-
Function
Set WNR algorithm ID
-
Syntax
ALGO_WNR_RET IaaWnr_SetHandleId(WNR_HANDLE handle, int id); -
Parameter
Parameter name Description Input/Output handle WNR algorithm handle Input id WNR algorithm handle id. Value range: [0,100] Input -
Return Value
Return Value Result 0 Successful Non-zero Failed, refer to Error code -
Dependency
-
Header file: AudioWnrProcess.h
-
Library file: libWNR_LINUX.so/ libWNR_LINUX.a
-
-
Note
N/A
2.7. IaaWnr_GetJsonFileSize¶
-
Function
WNR get size of json file
-
Syntax
unsigned int IaaWnr_GetJsonFileSize(char* jsonfile); -
Parameter
Parameter name Description Input/Output jsonfile name of json file Input -
Return Value
Return value is the memory size required for decoding json file.
-
Dependency
-
Header file: AudioWnrProcess.h
-
Library file: libWNR_LINUX.so/ libWNR_LINUX.a
-
-
Note
N/A
-
Example
Please refer to IaaWnr_Run example.
2.8. IaaWnr_InitReadFromJson¶
-
Function
Set json parameter into WNR init structure
-
Syntax
ALGO_WNR_RET IaaWnr_InitReadFromJson(AudioWnrInit* wnr_init, char* jsonBuffer, char* jsonfile, unsigned int buffSize); -
Parameter
Parameter name Description Input/Output wnr_init WNR algorithm Init Input jsonBuffer json buffer memory address Input jsonfile name of json file Input buffSize size of json file Input -
Return Value
Return Value Result 0 Successful Non-zero Failed, refer to Error code -
Dependency
-
Header file: AudioWnrProcess.h
-
Library file: libWNR_LINUX.so/ libWNR_LINUX.a
-
-
Note
N/A
-
Example
Please refer to IaaWnr_Run example.
2.9. IaaWnr_ConfigReadFromJson¶
-
Function
Set json parameter into WNR config structure
-
Syntax
ALGO_WNR_RET IaaWnr_ConfigReadFromJson(AudioWnrConfig* wnr_config, char* jsonBuffer, char* jsonfile, unsigned int buffSize); -
Parameter
Parameter name Description Input/Output wnr_config WNR algorithm Config Input jsonBuffer json buffer memory address Input jsonfile name of json file Input buffSize size of json file Input -
Return Value
Return Value Result 0 Successful Non-zero Failed, refer to Error code -
Dependency
-
Header file: AudioWnrProcess.h
-
Library file: libWNR_LINUX.so/ libWNR_LINUX.a
-
-
Note
N/A
-
Example
Please refer to IaaWnr_Run example.
3. WNR data type list¶
The relevant data types of the WNR module are defined as follows:
| Data Type | Definition |
|---|---|
| IAA_WNR_SAMPLE_RATE | Sampling rate type of WNR algorithm |
| WNR_CONVERGE_SPEED | Convergence speed of WNR algorithm |
| AudioWnrInit | Initialization data structure type of WNR algorithm |
| AudioWnrConfig | Parameter setting structure type of WNR algorithm |
| WNR_HANDLE | Define WNR algorithm handle type. |
3.1. IAA_WNR_SAMPLE_RATE¶
-
Description
Define the sampling rate type of the WNR algorithm.
-
Definition
typedef enum { IAA_WNR_SAMPLE_RATE_16000 = 16000 , }IAA_WNR_SAMPLE_RATE; -
Member
Member name Description IAA_WNR_SAMPLE_RATE_16000 Sampling rate 16000Hz -
Note
N/A
-
Related Data Type and Interface
3.2. WNR_CONVERGE_SPEED¶
-
Description
Define the convergence speed of the WNR algorithm.
-
Definition
typedef enum { WNR_SPEED_LOW, WNR_SPEED_MID, WNR_SPEED_HIGH } WNR_CONVERGE_SPEED; -
Member
Member name Description WNR_SPEED_LOW Low speed WNR_SPEED_MID Medium speed WNR_SPEED_HIGH High speed -
Note
N/A
-
Related Data Type and Interface
3.3. AudioWnrInit¶
-
Description
Define the initialization parameter type of the WNR algorithm.
-
Definition
typedef struct { unsigned int point_number; unsigned int channel; IAA_WNR_SAMPLE_RATE sample_rate; }AudioWnrInit; -
Member
Member name Description point_number The number of sampling points processed by the WNR algorithm once channel Channel number, support mono and stereo. sample_rate Sampling rate -
Note
- point_number, MODE1 can support the 128 point and the 256 point (determined at compile time). The point_number supported by library file can be obtained by entering the following command in the terminal
strings libWNR_LINUX.a | grep WNRSET - sample_rate, MODE1 only supports 16k.
- point_number, MODE1 can support the 128 point and the 256 point (determined at compile time). The point_number supported by library file can be obtained by entering the following command in the terminal
-
Related Data Type and Interface
3.4. AudioWnrConfig¶
-
Description
Define the configuration parameter structure type of the WNR algorithm.
-
Definition
typedef struct{ unsigned int wnr_enable; unsigned int wnr_mode; int wnr_intensity_band[WNR_BAND_NUM-1]; int wnr_intensity[WNR_BAND_NUM]; unsigned int wnr_smooth_level; WNR_CONVERGE_SPEED wnr_converge_speed; }AudioWnrConfig; -
Member
Member name Description wnr_enable Disable/Enable WNR algorithm wnr_mode WNR filter mode. Rang [0,1]. Step size: 1 wnr_intensity_band WNR frequency range.Range [1,point_number]. Step size: 1 wnr_intensity Supress instensity.The larger the value, the higher the wnr. But at the same time it will also bring about the loss/damage of details. The recommended value is 10. Range [0,30]. Step size: 1 wnr_smooth_level Frequency domain smoothness. Recommended value: 0 Range [0,10]. Step size: 1 wnr_converge_speed Wind noise convergence speed. Recommended value: high. Range [low;mid;high] -
Note
-
When wnr_enable is FALSE, the algorithm does not take action and other WNR parameters will not take effect.
-
wnr_mode specifies WNR algorithm 1 is the wind noise reduction algorithm using deep learning. The algorithm mode that can be used by library file can be found by entering the following command in the terminal
strings libWNR_LINUX.a | grep WNRTYPE -
wnr_intensity_band/wnr_intensity/wnr_smooth_level/wnr_converge_speed is the tuning parameter of wnr_mode 1.
-
WNR_BAND_NUM Definition can be viewed from header.
-
wnr_intensity_band, noise reduction frequency range, the next element must be greater than or equal to the previous element.
For example: wnr_intensity_band[0] = 10, then: wnr_intensity_band[1] must be greater than or equal to 10.
The highest frequency corresponding to the current sampling rate is evenly divided into point_number parts, and the frequency range is the corresponding number of parts that form a frequency band.
For example: the current point_number is 128, the sampling rate is 16K, the corresponding maximum frequency is 8K, and each part is 8000 / 128 ≈ 62.5 Hz. For example, under the settings of {4, 6, 36, 49, 50, 51}, the noise reduction frequency range is {0 ~ 4 * 62.5Hz, 4 ~ 6 * 62.5Hz, 6 ~ 36 * 62.5Hz, 36 ~ 49 * 62.5Hz, 49 ~ 50 * 62.5Hz, 50 ~ 51 * 62.5Hz, 51-127 * 62.5Hz} = {0 ~ 250Hz, 250 ~ 375Hz, 375 ~ 2250Hz, 2250 ~ 3062.5Hz, 3062.5 ~ 3125Hz, 3125 ~ 3187.5Hz, 3187.5Hz ~ 8000Hz}. wnr_intensity is the wind noise reduction intensity, which can be divided according to the frequency band of wnr_intensity_band, and different parameters can be set according to the noise situation of each frequency band.
-
wnr_smooth_level, WNR algorithm handles the smoothness in the frequency domain and smoothes the suppression on adjacent frequencies.
-
wnr_converge_speed, the convergence speed of the WNR algorithm, that is the speed of updating noise. The slower the setting, the slower the noise reduction convergence.
-
-
Related Data Type and Interface
3.5. WNR_HANDLE¶
-
Description
Define WNR algorithm handle type.
-
Definition
typedef void* WNR_HANDLE;
-
Member
Member name Description N/A -
Note
N/A
-
Related Data Type and Interface
4. Error code¶
WNR API error codes are shown as follow:
| error code | Definition | Description |
|---|---|---|
| 0x00000000 | ALGO_WNR_RET_SUCCESS | WNR execute Successful |
| 0x10000801 | ALGO_WNR_RET_INVALID_CONFIG | WNR Config setting is invalid |
| 0x10000802 | ALGO_WNR_RET_INVALID_HANDLE | WNR Handle is invalid |
| 0x10000803 | ALGO_WNR_RET_INVALID_SAMPLERATE | WNR Sample rate setting is invalid |
| 0x10000804 | ALGO_WNR_RET_INVALID_POINTNUMBER | WNR point number setting is invalid |
| 0x10000805 | ALGO_WNR_RET_INVALID_CHANNEL | WNR channel setting is invalid |
| 0x10000806 | ALGO_WNR_RET_INVALID_ENABLE | WNR enable setting is invalid |
| 0x10000807 | ALGO_WNR_RET_INVALID_MODE | WNR mode setting is invalid |
| 0x10000808 | ALGO_WNR_RET_INVALID_INTENSITY | WNR intensity setting is invalid |
| 0x10000809 | ALGO_WNR_RET_INVALID_SMOOTH_LEVEL | WNR smooth level setting is invalid |
| 0x10000810 | ALGO_WNR_RET_INVALID_CONVERGE_SPEED | WNR convergence speed setting is invalid |
| 0x10000811 | ALGO_WNR_RET_INVALID_JSONFILE | WNR json releated error |
| 0x10000812 | ALGO_WNR_RET_INVALID_DUMP | WNR Dump file related error |
| 0x10000813 | ALGO_WNR_RET_INVALID_CALLING | Incorrect order of calling WNR API |
| 0x10000814 | ALGO_WNR_RET_API_CONFLICT | Other WNR APIs are running |
| 0x10000815 | ALGO_WNR_RET_FAILED | WNR execute failed |