MI AED API
1. Overview¶
1.1. Module Description¶
AED (short for Acoustic event detection) is used to detect specific sound events in the audio stream. Currently supports baby crying and Loud Sound Detection (LSD).
1.2. Keyword¶
-
Sensitivity
Sensitivity of baby cry detection. The lower the sensitivity, the longer it takes for a continuous baby cry to be reported. On the contrary, the higher the sensitivity, the easier it is to be detected. The parameter range is listed according to AedSensitivity.
-
Operating Point
Baby crying detection operation point. Increasing the operating point will reduce the false alarm rate, and reducing the operating point will reduce the false alarm rate. This parameter needs to be in the range of [-10,10].
-
Vad Threshold
Voice Activity Detection dBFS threshold value. Must be higher than this setting value before entering baby cry detection.
-
LSD Threshold
Loud Sound Detection dBFS threshold. Above this set value, it is detected as loud sound.
1.3. Note¶
In order to facilitate debugging and confirm the effect of the algorithm, the user application needs to implement replacement algorithm parameter and grab audio data.
2. API REFERENCE¶
2.1. API List¶
API name | Features |
---|---|
IaaAed_GetBufferSize | Get the memory size required for Aed algorithm running |
IaaAed_Init | Initialize the memory required for the Aed algorithm |
IaaAed_Config | Configure Aed algorithm |
IaaAed_Run | baby cry detection |
IaaAed_GetResult | Get the result of baby cry detection |
IaaAed_SetSensitivity | Set the sensitivity of baby cry detection |
IaaAed_SetSampleRate | Set the data sampling rate for baby cry detection |
IaaAed_SetOperatingPoint | Set the operation point for baby cry detection |
IaaAed_SetVadThreshold | Set the Vad dBFS threshold of baby cry detection |
IaaAed_SetLsdThreshold | Set the dBFS threshold for LSD |
IaaAed_RunLsd | LSD algorithm processing |
IaaAed_GetLsdResult | Get the results of LSD |
IaaAed_Release | Quit Aed and release memory |
2.2. IaaAed_GetBufferSize¶
-
Features
Get the memory size required for Aed algorithm running.
-
Syntax
unsigned int IaaAed_GetBufferSize(void);
-
Return value
Return value is the memory size required for the operation of the Aed algorithm.
-
Dependency
-
Header: AudioAedProcess.h
-
Library: libAED_LINUX.so/ libAED_LINUX.a
-
-
Note
Only the required memory size is returned. The application and release of memory need to be processed by the application.
-
Example
Please refer to IaaAed_Run example.
2.3. IaaAed_Init¶
-
Features
Initialize the memory required for the Aed algorithm
-
Syntax
AedHandle IaaAed_Init(char *working_buf_ptr, AedProcessStruct *aed_struct);
-
Parameters
Parameter name Description Input/output working_buf_ptr Aed algorithm initialization parameter Input aed_struct Aed initialization algorithm structure Input -
Return value
Return value Result Not NULL Successful NULL Failed -
Dependency
-
Header: AudioAedProcess.h
-
Library: libAED_LINUX.so/ libAED_LINUX.a
-
-
Note
- Whether using a baby cry detection or LSD function needs to call MI_AED_Init to initialize Aed algorithm to get the Aed algorithm handle.
-
Example
Please refer to IaaAed_Run example.
2.4. IaaAed_Config¶
-
Features
Configure Aed algorithm.
-
Syntax
ALGO_AED_RET IaaAed_Config(AedHandle handle);
-
Parameters
Parameter name Description Input/output handle Aed algorithm handle Input -
Return value
Return value Result 0 Successful Non-zero Failed -
Dependency
-
Header: AudioAedProcess.h
-
Library: libAED_LINUX.so/ libAED_LINUX.a
-
-
Example
Please refer to IaaAed_Run example.
2.5. IaaAed_Run¶
-
Features
Aed algorithm baby cry detection processing
-
Syntax
ALGO_AED_RET IaaAed_Run(AedHandle handle,short *audio_io);
-
Parameters
Parameter name Description Input/output handle Aed algorithm handle Input audio_io Baby cry detection data pointer Input -
Return value
Return value Result 0 Successful Non-zero Failed, refer to error code -
Dependency
-
Header: AudioAedProcess.h
-
Library: libAED_LINUX.so/ libAED_LINUX.a
-
-
Note
- The data length of audio_input must correspond to the point_number(the number of sampling points processed by the Aed algorithm at a time) set by AedProcessStruct.
-
Example
#include <stdio.h> #include <string.h> #include <stdlib.h> #include "AudioAedProcess.h" /* 0:Fixed input file 1:User input file */ #define IN_PARAMETER 1 int main(int argc, char *argv[]) { AedHandle AED_HANDLE; AedProcessStruct aed_params; unsigned int aedBuffSize; char *working_buf_ptr = NULL; /************************User change section start**************************/ int vad_threshold_db = -40; int lsd_threshold_db = -15; int operating_point = -10; AedSensitivity sensitivity = AED_SEN_HIGH; AedSampleRate sample_rate = AED_SRATE_8K; aed_params.channel = 1; /************************User change section end***************************/ short input[1024]; char src_file[128] = {0}; FILE * fpIn; ALGO_AED_RET ret = ALGO_AED_RET_SUCCESS; int bcd_result; int lsd_result; int frm_cnt = 0; int lsd_db = 0; //useless param. #if IN_PARAMETER if(argc < 2) { printf("Please enter the correct parameters!\n"); return -1; } sscanf(argv[1], "%s", src_file); #else sprintf(src_file, "%s", "./AFE_8K.wav"); #endif switch (sample_rate) { case AED_SRATE_8K: aed_params.point_number = 256; break; case AED_SRATE_16K: aed_params.point_number = 512; break; case AED_SRATE_32K: aed_params.point_number = 1024; break; case AED_SRATE_48K: aed_params.point_number = 1535; break; default: printf("Unsupported current sample rate !\n"); return -1; } aedBuffSize = IaaAed_GetBufferSize(); working_buf_ptr = (char *)malloc(aedBuffSize); if(NULL == working_buf_ptr) { printf("malloc workingBuffer failed !\n"); return -1; } printf("malloc workingBuffer succeed !\n"); AED_HANDLE = IaaAed_Init(working_buf_ptr, &aed_params); if(NULL == AED_HANDLE) { printf("IaaAed_Init faild !\n"); return -1; } printf("IaaAed_Init succeed !\n"); ret = IaaAed_Config(AED_HANDLE); if(ALGO_AED_RET_SUCCESS != ret) { printf("IaaAed_Config failed !, ret = %d\n", ret); return -1; } ret = IaaAed_SetSensitivity(AED_HANDLE, sensitivity); if(ALGO_AED_RET_SUCCESS != ret) { printf("IaaAed_SetSensitivity failed !, ret = %d\n", ret); return -1; } ret = IaaAed_SetSampleRate(AED_HANDLE, sample_rate); if(ALGO_AED_RET_SUCCESS != ret) { printf("IaaAed_SetSampleRate failed !, ret = %d\n", ret); return -1; } ret = IaaAed_SetOperatingPoint(AED_HANDLE, operating_point); if(ALGO_AED_RET_SUCCESS != ret) { printf("IaaAed_SetOperatingPoint failed !, ret = %d\n", ret); return -1; } ret = IaaAed_SetLsdThreshold(AED_HANDLE, lsd_threshold_db); if(ALGO_AED_RET_SUCCESS != ret) { printf("IaaAed_SetLsdThreshold failed !, ret = %d\n", ret); return -1; } ret = IaaAed_SetVadThreshold(AED_HANDLE, vad_threshold_db); if(ALGO_AED_RET_SUCCESS != ret) { printf("IaaAed_SetVadThreshold failed !, ret = %d\n", ret); return -1; } fpIn = fopen(src_file, "rb"); if(NULL == fpIn) { printf("fopen in_file failed !\n"); return -1; } printf("fopen in_file success !\n"); memset(input, 0, sizeof(short) * 1024); #if 1 /*Consider whether the input file has a header*/ fread(input, sizeof(char), 44, fpIn); // Remove the 44 bytes header #endif while(fread(input, sizeof(short), aed_params.point_number * aed_params.channel, fpIn)) { frm_cnt++; /* Run LSD process */ ret = IaaAed_RunLsd(AED_HANDLE, input, &lsd_db); if (ALGO_AED_RET_SUCCESS != ret) { printf("MI_AED_RunLsd failed !, ret = %d\n", ret); break; } ret = IaaAed_GetLsdResult(AED_HANDLE, &lsd_result); if(ALGO_AED_RET_SUCCESS != ret) { printf("IaaAed_GetLsdResult failed !, ret = %d\n", ret); } if (lsd_result) { printf("current time = %f, loud sound detected!\n", \ frm_cnt * ((float)aed_params.point_number / sample_rate)); } /* Run AED process */ ret = IaaAed_Run(AED_HANDLE, input); if(ALGO_AED_RET_SUCCESS != ret) { printf("MI_AED_Run failed !,ret = %d\n", ret); break; } ret = IaaAed_GetResult(AED_HANDLE, &bcd_result); if(ALGO_AED_RET_SUCCESS != ret) { printf("IaaAed_GetResult failed !, ret = %d\n", ret); } if(bcd_result) { printf("Baby cried at %.3f.\n", \ frm_cnt * ((float)aed_params.point_number / sample_rate)); } } printf("AED end !\n"); ret = IaaAed_Release(AED_HANDLE); if(ALGO_AED_RET_SUCCESS != ret) { printf("IaaAed_Release failed !, ret = %d\n", ret); } fclose(fpIn); return 0; }
2.6. IaaAed_GetResult¶
-
Features
Get the result of baby cry detection
-
Syntax
ALGO_AED_RET IaaAed_GetResult(AedHandle handle, int *aed_result);
-
Parameters
Parameter name Description Input/output handle Aed algorithm handle Input aed_result Baby cry detection result Output -
Return value
Return value Result 0 Successful Non-zero Failed, refer to error code -
Dependency
-
Header: AudioAedProcess.h
-
Library: libAED_LINUX.so/ libAED_LINUX.a
-
-
Example
Please refer to IaaAed_Run example.
2.7. IaaAed_SetSensitivity¶
-
Features
Set the sensitivity of baby cry detection
-
Syntax
ALGO_AED_RET IaaAed_SetSensitivity(AedHandle handle,AedSensitivity sensitivity);
-
Parameters
Parameter name Description Input/output handle Aed algorithm handle Input sensitivity Baby cry detection sensitivity Input -
Return value
Return value Result 0 Successful Non-zero Failed, refer to error code -
Dependency
-
Header: AudioAedProcess.h
-
Library: libAED_LINUX.so/ libAED_LINUX.a
-
-
Example
Please refer to IaaAed_Run example.
2.8. IaaAed_SetSampleRate¶
-
Features
Set the data sampling rate for baby cry detection
-
Syntax
ALGO_AED_RET IaaAed_SetSampleRate(AedHandle handle,AedSampleRate srate);
-
Parameters
Parameter name Description Input/output handle Aed algorithm handle Input srate Sampling rate of baby cry detection data Input -
Return value
Return value Result 0 Successful Non-zero Failed, refer to error code -
Dependency
-
Header: AudioAedProcess.h
-
Library: libAED_LINUX.so/ libAED_LINUX.a
-
-
Example
Please refer to IaaAed_Run example.
2.9. IaaAed_SetOperatingPoint¶
-
Features
Set the operation point for baby cry detection
-
Syntax
ALGO_AED_RET IaaAed_SetOperatingPoint(AedHandle handle,int operating_point);
-
Parameters
Parameter name Description Input/output handle Aed algorithm handle Input operating_point Baby crying detection operation point Input -
Return value
Return value Result 0 Successful Non-zero Failed, refer to error code -
Dependency
-
Header: AudioAedProcess.h
-
Library: libAED_LINUX.so/ libAED_LINUX.a
-
-
Example
Please refer to IaaAed_Run example.
2.10. IaaAed_SetVadThreshold¶
-
Features
Set the Vad dBFS threshold of baby cry detection, enter baby cry detection when it is higher than this threshold.
-
Syntax
ALGO_AED_RET IaaAed_SetVadThreshold(AedHandle handle,int threshold_db);
-
Parameters
Parameter name Description Input/output handle Aed algorithm handle Input threshold_db Vad dBFS threshold for baby crying detection Input -
Return value
Return value Result 0 Successful Non-zero Failed, refer to error code -
Dependency
-
Header: AudioAedProcess.h
-
Library: libAED_LINUX.so/ libAED_LINUX.a
-
-
Example
Please refer to IaaAed_Run example.
2.11. IaaAed_SetLsdThreshold¶
-
Features
Set the threshold of Aed algorithm loud sound detection
-
Syntax
ALGO_AED_RET IaaAed_SetLsdThreshold(AedHandle handle,int threshold_db);
-
Parameters
Parameter name Description Input/output handle Aed algorithm handle Input threshold_db LSD threshold, more than the specified dBFS it was considered loud sound. Input -
Return value
Return value Result 0 Successful Non-zero Failed, refer to error code -
Dependency
-
Header: AudioAedProcess.h
-
Library: libAED_LINUX.so/ libAED_LINUX.a
-
-
Example
Please refer to IaaAed_Run example.
2.12. IaaAed_RunLsd¶
-
Features
Aed algorithm LSD processing
-
Syntax
ALGO_AED_RET IaaAed_RunLsd(AedHandle handle,short *audio_input, int *lsd_db);
-
Parameters
Parameter name Description Input/output handle Aed algorithm handle Input audio_input LSD data pointer Input lsd_db Current data decibels Output -
Return value
Return value Result 0 Successful Non-zero Failed, refer to error code -
Dependency
-
Header: AudioAedProcess.h
-
Library: libAED_LINUX.so/ libAED_LINUX.a
-
-
Note
- The data length of audio_input must correspond to the point_number(the number of sampling points processed by the Aed algorithm at a time) set by AedProcessStruct.
-
Example
Please refer to IaaAed_Run example.
2.13. IaaAed_GetLsdResult¶
-
Features
Get the LSD results of Aed algorithm
-
Syntax
ALGO_AED_RET IaaAed_GetLsdResult(AedHandle handle, int* lsd_result);
-
Parameters
Parameter name Description Input/output handle Aed algorithm handle Input lsd_result LSD results Output -
Return value
Return value Result 0 Successful Non-zero Failed, refer to error code -
Dependency
-
Header: AudioAedProcess.h
-
Library: libAED_LINUX.so/ libAED_LINUX.a
-
-
Example
Please refer to IaaAed_Run example.
2.14. IaaAed_Release¶
-
Features
Release Aed algorithm resource
-
Syntax
ALGO_AED_RET IaaAed_Release(AedHandle handle);
-
Parameters
Parameter name Description Input/output handle Aed algorithm handle Input -
Return value
Return value Result 0 Successful Non-zero Failed, refer to error code -
Dependency
-
Header: AudioAedProcess.h
-
Library: libAED_LINUX.so/ libAED_LINUX.a
-
-
Example
Please refer to IaaAed_Run example.
3. AED data type¶
3.1. AED data type list¶
Data type | Definition |
---|---|
AedProcessStruct | Aed algorithm initialization parameter structure type |
AedHandle | Aed algorithm handle type |
AedSensitivity | Aed algorithm baby cry detection sensitivity type |
AedSampleRate | Aed algorithm baby cry detection data sampling rate |
3.2. AedProcessStruct¶
-
Description
Define Aed algorithm initialization parameter structure type
-
Definition
typedef struct { unsigned int point_number; unsigned int channel; } AedProcessStruct;
-
Member
Member name Description point_number Sampling points, give value according to sampling rate
Sampling rate: sampling points
8K:256, 16K:512, 32K:1024, 48K:1536channel Audio data channels -
Related data types and interfaces
3.3. AedHandle¶
-
Description
Define the Aed algorithm handle type
-
Definition
typedef void* AedHandle;
-
Related data types and interfaces
3.4. AedSensitivity¶
-
Description
Define the sensitivity type of baby cry detection for Aed algorithm.
-
Definition
typedef enum { AED_SEN_LOW, AED_SEN_MID, AED_SEN_HIGH } AedSensitivity;
-
Member
Member name Description AED_SEN_LOW Low sensitivity AED_SEN_MID Medium sensitivity AED_SEN_HIGH High sensitivity -
Related data types and interfaces
3.5. AedSampleRate¶
-
Description
Define the sampling rate type of baby cry detection for Aed algorithm
-
Definition
typedef enum { AED_SRATE_8K = 8000, AED_SRATE_16K = 16000, AED_SRATE_32K = 32000, AED_SRATE_48K = 48000 } AedSampleRate;
-
Member
Member name Description AED_SRATE_8K Sampling Rate 8000Hz AED_SRATE_16K Sampling Rate 16000Hz AED_SRATE_32K Sampling Rate 32000Hz AED_SRATE_48K Sampling Rate 48000Hz -
Related data types and interfaces
4. Error code¶
AED API error codes are shown as follow:
Error code | Definition | Description |
---|---|---|
0x00000000 | ALGO_AED_RET_SUCCESS | AED runs successfully |
0x10000201 | ALGO_AED_RET_INIT_ERROR | AED initialization error |
0x10000202 | ALGO_AED_RET_INVALID_CONFIG | AED Config is invalid |
0x10000203 | ALGO_AED_RET_INVALID_HANDLE | AED Handle is invalid |
0x10000204 | ALGO_AED_RET_INVALID_SAMPLERATE | AED sampling rate is invalid |
0x10000205 | ALGO_AED_RET_INVALID_POINTNUMBER | AED sampling points are invalid |
0x10000206 | ALGO_AED_RET_INVALID_CHANNEL | AED channel number is invalid |
0x10000207 | ALGO_AED_RET_INVALID_SENSITIVITY | AED detection sensitivity is invalid |
0x10000208 | ALGO_AED_RET_INVALID_CALLING | AED API call sequence error |
0x10000209 | ALGO_AED_RET_API_CONFLICT | Other APIs are running |