├── .gitignore ├── LICENSE ├── README.md ├── athena_signal ├── __init__.py ├── dios_signal.c ├── dios_signal.h ├── dios_signal.i ├── dios_signal.py ├── dios_signal_wrap.c ├── dios_ssp_api.py └── kernels │ ├── dios_ssp_aec │ ├── dios_ssp_aec_api.c │ ├── dios_ssp_aec_api.h │ ├── dios_ssp_aec_common.c │ ├── dios_ssp_aec_common.h │ ├── dios_ssp_aec_doubletalk.c │ ├── dios_ssp_aec_doubletalk.h │ ├── dios_ssp_aec_erl_est.c │ ├── dios_ssp_aec_erl_est.h │ ├── dios_ssp_aec_firfilter.c │ ├── dios_ssp_aec_firfilter.h │ ├── dios_ssp_aec_macros.h │ ├── dios_ssp_aec_res.c │ ├── dios_ssp_aec_res.h │ └── dios_ssp_aec_tde │ │ ├── dios_ssp_aec_tde.c │ │ ├── dios_ssp_aec_tde.h │ │ ├── dios_ssp_aec_tde_delay_estimator.c │ │ ├── dios_ssp_aec_tde_delay_estimator.h │ │ ├── dios_ssp_aec_tde_delay_estimator_wrapper.c │ │ ├── dios_ssp_aec_tde_delay_estimator_wrapper.h │ │ ├── dios_ssp_aec_tde_ring_buffer.c │ │ └── dios_ssp_aec_tde_ring_buffer.h │ ├── dios_ssp_agc │ ├── dios_ssp_agc_api.c │ └── dios_ssp_agc_api.h │ ├── dios_ssp_api.c │ ├── dios_ssp_api.h │ ├── dios_ssp_doa │ ├── dios_ssp_doa_api.c │ ├── dios_ssp_doa_api.h │ ├── dios_ssp_doa_macros.h │ ├── dios_ssp_doa_win.c │ └── dios_ssp_doa_win.h │ ├── dios_ssp_gsc │ ├── dios_ssp_gsc_abm.c │ ├── dios_ssp_gsc_abm.h │ ├── dios_ssp_gsc_adaptctrl.c │ ├── dios_ssp_gsc_adaptctrl.h │ ├── dios_ssp_gsc_aic.c │ ├── dios_ssp_gsc_aic.h │ ├── dios_ssp_gsc_api.c │ ├── dios_ssp_gsc_api.h │ ├── dios_ssp_gsc_beamformer.c │ ├── dios_ssp_gsc_beamformer.h │ ├── dios_ssp_gsc_beamsteering.c │ ├── dios_ssp_gsc_beamsteering.h │ ├── dios_ssp_gsc_dsptools.c │ ├── dios_ssp_gsc_dsptools.h │ ├── dios_ssp_gsc_filtsumbeamformer.c │ ├── dios_ssp_gsc_filtsumbeamformer.h │ ├── dios_ssp_gsc_firfilterdesign.c │ ├── dios_ssp_gsc_firfilterdesign.h │ ├── dios_ssp_gsc_globaldefs.h │ ├── dios_ssp_gsc_micarray.c │ ├── dios_ssp_gsc_micarray.h │ ├── dios_ssp_gsc_multigscbeamformer.c │ ├── dios_ssp_gsc_multigscbeamformer.h │ ├── dios_ssp_gsc_rmNPsdOsMs.c │ └── dios_ssp_gsc_rmNPsdOsMs.h │ ├── dios_ssp_hpf │ ├── dios_ssp_hpf_api.c │ └── dios_ssp_hpf_api.h │ ├── dios_ssp_mvdr │ ├── dios_ssp_mvdr_api.c │ ├── dios_ssp_mvdr_api.h │ ├── dios_ssp_mvdr_cinv.c │ ├── dios_ssp_mvdr_cinv.h │ ├── dios_ssp_mvdr_header.c │ ├── dios_ssp_mvdr_header.h │ ├── dios_ssp_mvdr_macros.h │ ├── dios_ssp_mvdr_win.c │ └── dios_ssp_mvdr_win.h │ ├── dios_ssp_ns │ ├── dios_ssp_ns_api.c │ ├── dios_ssp_ns_api.h │ └── dios_ssp_ns_macros.h │ ├── dios_ssp_return_defs.h │ ├── dios_ssp_share │ ├── dios_ssp_share_cinv.c │ ├── dios_ssp_share_cinv.h │ ├── dios_ssp_share_complex_defs.c │ ├── dios_ssp_share_complex_defs.h │ ├── dios_ssp_share_noiselevel.c │ ├── dios_ssp_share_noiselevel.h │ ├── dios_ssp_share_rfft.c │ ├── dios_ssp_share_rfft.h │ ├── dios_ssp_share_subband.c │ ├── dios_ssp_share_subband.h │ └── dios_ssp_share_typedefs.h │ └── dios_ssp_vad │ ├── dios_ssp_vad_api.c │ ├── dios_ssp_vad_api.h │ ├── dios_ssp_vad_counter.c │ ├── dios_ssp_vad_counter.h │ ├── dios_ssp_vad_energy.c │ ├── dios_ssp_vad_energy.h │ └── dios_ssp_vad_macros.h ├── athena_signal_deep_learning ├── README.md ├── config │ ├── __init__.py │ ├── option.py │ └── train_rnn.yml ├── data_loader │ ├── __init__.py │ └── wham_dataset.py ├── logger │ ├── __init__.py │ └── set_logger.py ├── model │ ├── __init__.py │ ├── dprnn_net.py │ ├── en_decoder.py │ ├── loss.py │ ├── model_function.py │ └── norm.py ├── pre_process │ ├── prepare_speaker_labels.py │ └── preprocess_wham.py ├── test.py ├── train.py └── trainer.py ├── examples ├── 0841-0875_env7_sit1_male_in.pcm ├── 0841-0875_env7_sit1_male_ref.pcm ├── athena_signal_test.py ├── m0f60_5cm_1_mix.pcm ├── m0f60_5cm_2_mix.pcm ├── m0f60_5cm_3_mix.pcm ├── m0f60_5cm_4_mix.pcm ├── m0f60_5cm_5_mix.pcm └── m0f60_5cm_6_mix.pcm ├── pack.bat ├── pack.sh └── setup.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Object files 5 | *.o 6 | *.ko 7 | *.obj 8 | *.elf 9 | 10 | # Linker output 11 | *.ilk 12 | *.map 13 | *.exp 14 | 15 | # Precompiled Headers 16 | *.gch 17 | *.pch 18 | 19 | # Libraries 20 | *.lib 21 | *.a 22 | *.la 23 | *.lo 24 | 25 | # Shared objects (inc. Windows DLLs) 26 | *.dll 27 | *.so 28 | *.so.* 29 | *.dylib 30 | 31 | # Executables 32 | *.exe 33 | *.out 34 | *.app 35 | *.i*86 36 | *.x86_64 37 | *.hex 38 | 39 | # Debug files 40 | *.dSYM/ 41 | *.su 42 | *.idb 43 | *.pdb 44 | 45 | # Kernel Module Compile Results 46 | *.mod* 47 | *.cmd 48 | .tmp_versions/ 49 | modules.order 50 | Module.symvers 51 | Mkfile.old 52 | dkms.conf 53 | 54 | # Logs and databases 55 | *.log 56 | *.sql 57 | *.sqlite 58 | 59 | # OS generated files 60 | .DS_Store 61 | .DS_Store? 62 | 63 | .vscode 64 | .data 65 | .log 66 | *swp 67 | __pycache__ 68 | *pyc 69 | .idea 70 | -------------------------------------------------------------------------------- /athena_signal/__init__.py: -------------------------------------------------------------------------------- 1 | # /* Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | # All rights reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ==============================================================================*/ 16 | """Init model.""" 17 | 18 | from athena_signal import dios_ssp_api 19 | -------------------------------------------------------------------------------- /athena_signal/dios_signal.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | ==============================================================================*/ 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include "kernels/dios_ssp_api.h" 23 | 24 | int dios_ssp_v1(int argc, char **argv, int *fe_switch, size_t m, float *mic_coord, size_t n, int mic_num, int ref_num, float loc_phi); -------------------------------------------------------------------------------- /athena_signal/dios_signal.py: -------------------------------------------------------------------------------- 1 | # This file was automatically generated by SWIG (http://www.swig.org). 2 | # Version 4.0.1 3 | # 4 | # Do not make changes to this file unless you know what you are doing--modify 5 | # the SWIG interface file instead. 6 | 7 | from sys import version_info as _swig_python_version_info 8 | if _swig_python_version_info < (2, 7, 0): 9 | raise RuntimeError("Python 2.7 or later required") 10 | 11 | # Import the low-level C/C++ module 12 | if __package__ or "." in __name__: 13 | from . import _dios_signal 14 | else: 15 | import _dios_signal 16 | 17 | try: 18 | import builtins as __builtin__ 19 | except ImportError: 20 | import __builtin__ 21 | 22 | def _swig_repr(self): 23 | try: 24 | strthis = "proxy of " + self.this.__repr__() 25 | except __builtin__.Exception: 26 | strthis = "" 27 | return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,) 28 | 29 | 30 | def _swig_setattr_nondynamic_instance_variable(set): 31 | def set_instance_attr(self, name, value): 32 | if name == "thisown": 33 | self.this.own(value) 34 | elif name == "this": 35 | set(self, name, value) 36 | elif hasattr(self, name) and isinstance(getattr(type(self), name), property): 37 | set(self, name, value) 38 | else: 39 | raise AttributeError("You cannot add instance attributes to %s" % self) 40 | return set_instance_attr 41 | 42 | 43 | def _swig_setattr_nondynamic_class_variable(set): 44 | def set_class_attr(cls, name, value): 45 | if hasattr(cls, name) and not isinstance(getattr(cls, name), property): 46 | set(cls, name, value) 47 | else: 48 | raise AttributeError("You cannot add class attributes to %s" % cls) 49 | return set_class_attr 50 | 51 | 52 | def _swig_add_metaclass(metaclass): 53 | """Class decorator for adding a metaclass to a SWIG wrapped class - a slimmed down version of six.add_metaclass""" 54 | def wrapper(cls): 55 | return metaclass(cls.__name__, cls.__bases__, cls.__dict__.copy()) 56 | return wrapper 57 | 58 | 59 | class _SwigNonDynamicMeta(type): 60 | """Meta class to enforce nondynamic attributes (no new attributes) for a class""" 61 | __setattr__ = _swig_setattr_nondynamic_class_variable(type.__setattr__) 62 | 63 | 64 | 65 | def dios_ssp_v1(argc, fe_switch, mic_coord, mic_num, ref_num, loc_phi): 66 | return _dios_signal.dios_ssp_v1(argc, fe_switch, mic_coord, mic_num, ref_num, loc_phi) 67 | 68 | 69 | -------------------------------------------------------------------------------- /athena_signal/dios_ssp_api.py: -------------------------------------------------------------------------------- 1 | # /* Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | # All rights reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ==============================================================================*/ 16 | """This model implements the upper-level encapsulation of dios_signal for 17 | easy invocation.""" 18 | 19 | from athena_signal.dios_signal import dios_ssp_v1 20 | import numpy as np 21 | 22 | class AthenaSignal: 23 | """ 24 | This model does AEC/NS/AGC/HPF/MVDR on input wav. 25 | """ 26 | def __init__(self, feature_switch=[1, 1, 0, 0, 0, 0], mic_num=1, ref_num=1, loc_phi=90.0): 27 | self.feature_switch=feature_switch 28 | self.mic_num=mic_num 29 | self.ref_num=ref_num 30 | self.loc_phi=loc_phi 31 | 32 | def set_params(self, config=None, mic_coord=None): 33 | """ 34 | Set params. 35 | :param config: Contains seven optional parametres: 36 | --add_AEC : If 1, do AEC on signal. 37 | (int, default = 1) 38 | --add_NS : If 1, do NS on signal. 39 | (int, default = 1) 40 | --add_AGC : If 1, do AGC on signal. 41 | (int, default = 0) 42 | --add_HPF : If 1, do HPF on signal. 43 | (int, default = 0) 44 | --add_BF : If 1, do MVDR on signal. 45 | If 2, do GSC on signal. 46 | (int, default = 0) 47 | --add_DOA : If 1, do DOA on signal. 48 | (int, default = 0) 49 | --mic_num : Number of microphones. 50 | (int, default = 1) 51 | --ref_num : Number of reference channel. 52 | (int, default = 1) 53 | :param mic_coord: The coordinates of each microphone of the microphone array 54 | using in MVDR. (A float array/list of size [mic_num, 3] containing 55 | three-dimensional coordinates of every microphone.) 56 | :return: None 57 | """ 58 | if 'add_AEC' in config: 59 | self.feature_switch[0] = config['add_AEC'] 60 | if 'add_NS' in config: 61 | self.feature_switch[1] = config['add_NS'] 62 | if 'add_AGC' in config: 63 | self.feature_switch[2] = config['add_AGC'] 64 | if 'add_HPF' in config: 65 | self.feature_switch[3] = config['add_HPF'] 66 | if 'add_BF' in config: 67 | self.feature_switch[4] = config['add_BF'] 68 | if 'add_DOA' in config: 69 | self.feature_switch[5] = config['add_DOA'] 70 | if 'mic_num' in config: 71 | self.mic_num = config['mic_num'] 72 | if 'ref_num' in config: 73 | self.ref_num = config['ref_num'] 74 | if 'loc_phi' in config: 75 | self.loc_phi = config['loc_phi'] 76 | 77 | 78 | print('#################################################') 79 | print('The configurations are: add_AEC: {}, add_NS: {}, add_AGC: {}, add_HPF: {},' 80 | ' add_BF: {}, add_DOA: {}'.format(self.feature_switch[0], self.feature_switch[1], 81 | self.feature_switch[2], self.feature_switch[3], self.feature_switch[4], 82 | self.feature_switch[5])) 83 | print('The number of microphones is: ', self.mic_num) 84 | print('The number of reference channels is: ', self.ref_num) 85 | print("The source location azimuth is: ", self.loc_phi) 86 | 87 | self.mic_coord = np.zeros(3 * self.mic_num, dtype=float) 88 | if self.feature_switch[4] >= 1 and mic_coord is not None: 89 | for i in range(self.mic_num): 90 | self.mic_coord[i * 3] = mic_coord[i][0] 91 | self.mic_coord[i * 3 + 1] = mic_coord[i][1] 92 | self.mic_coord[i * 3 + 2] = mic_coord[i][2] 93 | print('The coordinates are: ', mic_coord) 94 | print('#################################################') 95 | 96 | def process(self, input_file, out_file, ref_file=None): 97 | argc = [] 98 | if input_file: 99 | argc.append('-i'.encode()) 100 | for file in input_file: 101 | argc.append(file.encode()) 102 | if ref_file: 103 | argc.append('-r'.encode()) 104 | for file in ref_file: 105 | argc.append(file.encode()) 106 | if out_file: 107 | argc.append('-o'.encode()) 108 | for file in out_file: 109 | argc.append(file.encode()) 110 | dios_ssp_v1(argc, self.feature_switch, list(self.mic_coord), self.mic_num, self.ref_num, self.loc_phi) 111 | 112 | def athena_signal_process(input_file, out_file, ref_file=None, config=None, mic_coord=None): 113 | """ 114 | Do signal processing. 115 | :param input_file: List of input wav files. 116 | :param out_file: List of output wav files. 117 | :param ref_file: List of reference wav files. 118 | :param config: Parameters for signal processing. 119 | :return: None 120 | """ 121 | athena_siganl_test = AthenaSignal() 122 | athena_siganl_test.set_params(config, mic_coord) 123 | athena_siganl_test.process(input_file, out_file, ref_file) 124 | -------------------------------------------------------------------------------- /athena_signal/kernels/dios_ssp_aec/dios_ssp_aec_api.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | ==============================================================================*/ 16 | 17 | #ifndef _DIOS_SSP_AEC_API_H_ 18 | #define _DIOS_SSP_AEC_API_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | #include "dios_ssp_aec_common.h" 24 | #include "dios_ssp_aec_firfilter.h" 25 | #include "dios_ssp_aec_doubletalk.h" 26 | #include "dios_ssp_aec_erl_est.h" 27 | #include "dios_ssp_aec_res.h" 28 | #include "./dios_ssp_aec_tde/dios_ssp_aec_tde.h" 29 | #include "../dios_ssp_share/dios_ssp_share_subband.h" 30 | #include "../dios_ssp_share/dios_ssp_share_complex_defs.h" 31 | 32 | /********************************************************************************** 33 | Function: // dios_ssp_aec_init_api 34 | Description: // load configure file and allocate memory 35 | Input: // mic_num: microphone number 36 | ref_num: reference number 37 | frm_len: frame length 38 | Output: // none 39 | Return: // success: return dios speech signal process aec pointer 40 | failure: return NULL 41 | **********************************************************************************/ 42 | void* dios_ssp_aec_init_api(int mic_num, int ref_num, int frm_len); 43 | 44 | /********************************************************************************** 45 | Function: // dios_ssp_aec_config_api 46 | Description: // config dios speech signal process aec module 47 | Input: // ptr: dios speech signal process aec pointer 48 | mode: aec mode 49 | Output: // none 50 | Return: // success: return 0, failure: return ERR_AEC 51 | **********************************************************************************/ 52 | int dios_ssp_aec_config_api(void* ptr, int mode); 53 | 54 | /********************************************************************************** 55 | Function: // dios_ssp_aec_reset_api 56 | Description: // reset dios speech signal process aec module 57 | Input: // ptr: dios speech signal process aec pointer 58 | Output: // none 59 | Return: // success: return 0, failure: return ERR_AEC 60 | **********************************************************************************/ 61 | int dios_ssp_aec_reset_api(void* ptr); 62 | 63 | /********************************************************************************** 64 | Function: // dios_ssp_aec_process_api 65 | Description: // run dios speech signal process aec module by frames 66 | Input: // ptr: dios speech signal process aec pointer 67 | io_buf: microphone array data input/output buffer, data type is float 68 | size is[M][N], M = mic number * data_len 69 | ref_buf: reference data buffer, data type is float 70 | size is[M][N], M = reference number * data_len 71 | dt_st: double talk status 72 | Output: // io_buf 73 | Return: // success: return 0, failure: return ERR_AEC 74 | **********************************************************************************/ 75 | int dios_ssp_aec_process_api(void* ptr, float* io_buf, float* ref_buf, int* dt_st); 76 | 77 | /********************************************************************************** 78 | Function: // dios_ssp_aec_uninit_api 79 | Description: // free dios speech signal process aec module 80 | Input: // ptr: dios speech signal process aec pointer 81 | Output: // none 82 | Return: // success: return 0, failure: return ERR_AEC 83 | **********************************************************************************/ 84 | int dios_ssp_aec_uninit_api(void* ptr); 85 | 86 | #endif /* _DIOS_SSP_AEC_API_H_ */ 87 | 88 | -------------------------------------------------------------------------------- /athena_signal/kernels/dios_ssp_aec/dios_ssp_aec_common.c: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | Description: The file contains one function, the main function of which is to 17 | calculate the average of the data. 18 | ==============================================================================*/ 19 | 20 | #include "dios_ssp_aec_common.h" 21 | 22 | int dios_ssp_aec_average_track(float *input_time, int frm_len, float *ret_avg) 23 | { 24 | int i; 25 | float avg_abs = 0.0f; 26 | 27 | if (NULL == input_time) 28 | { 29 | return ERR_AEC; 30 | } 31 | 32 | for (i = 0; i < frm_len; i++) 33 | { 34 | avg_abs += xabs(input_time[i]); 35 | } 36 | 37 | *ret_avg = avg_abs / frm_len; 38 | 39 | return 0; 40 | } 41 | 42 | -------------------------------------------------------------------------------- /athena_signal/kernels/dios_ssp_aec/dios_ssp_aec_common.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | ==============================================================================*/ 16 | 17 | #ifndef _DIOS_SSP_AEC_COMMON_H_ 18 | #define _DIOS_SSP_AEC_COMMON_H_ 19 | 20 | #include 21 | #include 22 | #include "dios_ssp_aec_macros.h" 23 | #include "../dios_ssp_share/dios_ssp_share_complex_defs.h" 24 | 25 | /********************************************************************************** 26 | Function: // dios_ssp_aec_average_track 27 | Description: // calculate current frame average value 28 | Input: // input_time: the pointer of input signal in time domain 29 | frm_len: frame length 30 | Output: // ret_avg: the pointer of the input_time average value 31 | Return: // Success: return 0, Failure : return ERR_AEC 32 | **********************************************************************************/ 33 | int dios_ssp_aec_average_track(float *input_time, int frm_len, float *ret_avg); 34 | 35 | #endif /* _DIOS_SSP_AEC_COMMON_H_ */ 36 | 37 | -------------------------------------------------------------------------------- /athena_signal/kernels/dios_ssp_aec/dios_ssp_aec_doubletalk.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | ==============================================================================*/ 16 | 17 | #ifndef _DIOS_SSP_AEC_DOUBLETALK_H_ 18 | #define _DIOS_SSP_AEC_DOUBLETALK_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | #include "dios_ssp_aec_macros.h" 24 | #include "../dios_ssp_share/dios_ssp_share_complex_defs.h" 25 | #include "../dios_ssp_share/dios_ssp_share_noiselevel.h" 26 | 27 | typedef struct { 28 | xcomplex** sig_spk_ref; 29 | xcomplex* sig_mic_rec; 30 | int ref_num; 31 | float* res1_psd; 32 | float* res1_sum; 33 | float res1_eng_avg; 34 | float* res1_eng_avg_buf; 35 | float* res1_min_avg_buf; 36 | float* mic_noiselevel_sum; 37 | float** erl_ratio; 38 | int dt_num_hangover; 39 | int dt_cnt; 40 | int dt_frame_cnt; 41 | int dt_num_bands; 42 | int** doubletalk_band_table; 43 | int far_end_talk_holdtime; 44 | int dt_st; 45 | float dt_thr_factor; 46 | float dt_min_thr; 47 | objNoiseLevel** mic_noise_bin; // subband 48 | }objDoubleTalk; 49 | 50 | /********************************************************************************** 51 | Function: // dios_ssp_aec_doubletalk_init 52 | Description: // load configure file and allocate memory 53 | Input: // ref_num: reference number 54 | Output: // none 55 | Return: // success: return dios speech signal process aec doubletalk pointer 56 | failure: return NULL 57 | **********************************************************************************/ 58 | objDoubleTalk* dios_ssp_aec_doubletalk_init(int ref_num); 59 | 60 | /********************************************************************************** 61 | Function: // dios_ssp_aec_doubletalk_reset 62 | Description: // reset dios speech signal process aec doubletalk module 63 | Input: // srv: dios speech signal process aec doubletalk pointer 64 | Output: // none 65 | Return: // success: return 0, failure: return ERR_AEC 66 | **********************************************************************************/ 67 | int dios_ssp_aec_doubletalk_reset(objDoubleTalk* srv); 68 | 69 | /********************************************************************************** 70 | Function: // dios_ssp_aec_doubletalk_process 71 | Description: // run dios speech signal process aec doubletalk module by frames 72 | Input: // srv: dios speech signal process aec doubletalk pointer 73 | Output: // dt_st: doubletalk status 74 | Return: // success: return 0, failure: return ERR_AEC 75 | **********************************************************************************/ 76 | int dios_ssp_aec_doubletalk_process(objDoubleTalk* srv, int* dt_st); 77 | 78 | /********************************************************************************** 79 | Function: // dios_ssp_aec_doubletalk_uninit 80 | Description: // free dios speech signal process aec doubletalk module 81 | Input: // srv: dios speech signal process aec doubletalk pointer 82 | Output: // none 83 | Return: // success: return 0, failure: return ERR_AEC 84 | **********************************************************************************/ 85 | int dios_ssp_aec_doubletalk_uninit(objDoubleTalk* srv); 86 | 87 | #endif /* _DIOS_SSP_AEC_DOUBLETALK_H_ */ 88 | 89 | -------------------------------------------------------------------------------- /athena_signal/kernels/dios_ssp_aec/dios_ssp_aec_erl_est.c: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | Description: the file contains echo return loss estimation related functions, 17 | the output value of which is the ratio of the estimated echo energy to the 18 | reference signal energy. 19 | ==============================================================================*/ 20 | 21 | /* include file */ 22 | #include "dios_ssp_aec_erl_est.h" 23 | 24 | int dios_ssp_aec_erl_est_process(objFirFilter* srv) 25 | { 26 | int ch; 27 | int i_spk; 28 | int i; 29 | float erl_dyn_bound_high; 30 | float erl_dyn_bound_low; 31 | 32 | if (NULL == srv) 33 | { 34 | return ERR_AEC; 35 | } 36 | 37 | for (ch = AEC_LOW_CHAN; ch < AEC_HIGH_CHAN; ch++) 38 | { 39 | /* get psd */ 40 | srv->mic_rec_psd[ch] = complex_abs2(srv->sig_mic_rec[ch]);/* mic record signal */ 41 | 42 | for (i_spk = 0; i_spk < srv->ref_num; i_spk++) 43 | { 44 | srv->ref_psd[i_spk][ch] = complex_abs2(srv->sig_spk_ref[i_spk][ch]); /* reference signal */ 45 | srv->power_echo_rtn_fir[i_spk][ch] = complex_abs2(srv->est_ref_fir[i_spk][ch]); 46 | srv->power_echo_rtn_adpt[i_spk][ch] = complex_abs2(srv->est_ref_adf[i_spk][ch]); 47 | } 48 | } 49 | for (ch = AEC_LOW_CHAN; ch < AEC_HIGH_CHAN; ch++) 50 | { 51 | if (srv->energy_err_fir[ch] < srv->energy_err_adf[ch]) 52 | { 53 | srv->power_mic_send_smooth[ch] = srv->energy_err_fir[ch]; 54 | for (i_spk = 0; i_spk < srv->ref_num; i_spk++) 55 | { 56 | srv->power_echo_rtn_smooth[i_spk][ch] = srv->power_echo_rtn_fir[i_spk][ch]; 57 | } 58 | } 59 | else 60 | { 61 | srv->power_mic_send_smooth[ch] = srv->energy_err_adf[ch]; 62 | for (i_spk = 0; i_spk < srv->ref_num; i_spk++) 63 | { 64 | srv->power_echo_rtn_smooth[i_spk][ch] = srv->power_echo_rtn_adpt[i_spk][ch]; 65 | } 66 | } 67 | } 68 | 69 | for (i = 0; i < ERL_BAND_NUM; i++) 70 | { 71 | srv->mic_rec_part_band_energy[i] = 0.0f; 72 | srv->mic_send_part_band_energy[i] = 0.0f; 73 | for (ch = srv->band_table[i][0]; ch <= srv->band_table[i][1]; ch++) 74 | { 75 | srv->mic_rec_part_band_energy[i] += srv->mic_rec_psd[ch]; 76 | srv->mic_send_part_band_energy[i] += srv->power_mic_send_smooth[ch]; 77 | } 78 | } 79 | 80 | for (i_spk = 0; i_spk < srv->ref_num; i_spk++) 81 | { 82 | for (i = 0; i < ERL_BAND_NUM; i++) 83 | { 84 | srv->echo_return_band_energy[i] = 0.0f; 85 | for (ch = srv->band_table[i][0]; ch <= srv->band_table[i][1]; ch++) 86 | { 87 | srv->echo_return_band_energy[i] += srv->power_echo_rtn_smooth[i_spk][ch]; 88 | } 89 | /* Mic peak value tracking */ 90 | float temp = srv->echo_return_band_energy[i]; 91 | if (temp > srv->mic_peak[i_spk][i]) 92 | { 93 | srv->mic_peak[i_spk][i] = temp; 94 | } 95 | else 96 | { 97 | srv->mic_peak[i_spk][i] = AEC_PEAK_ALPHA * srv->mic_peak[i_spk][i] + (1 - AEC_PEAK_ALPHA) * temp; 98 | } 99 | 100 | if ((srv->spk_part_band_energy[i] > 10.0f * srv->noise_est_spk_part[i_spk][i]->noise_level_first) 101 | && (srv->mic_rec_part_band_energy[i] > 4.0f * srv->mic_send_part_band_energy[i])) 102 | { 103 | float erl_inst = srv->mic_peak[i_spk][i] / (srv->spk_peak[i_spk][i] + 1e-006f); 104 | if (erl_inst > ERL_BOUND_H) 105 | erl_inst = ERL_BOUND_H; 106 | else if (erl_inst < ERL_BOUND_L) 107 | erl_inst = ERL_BOUND_L; 108 | 109 | srv->erl_ratio[i_spk][i] = AEC_ERL_ALPHA * srv->erl_ratio[i_spk][i] + (1 - AEC_ERL_ALPHA) * erl_inst; 110 | } 111 | } 112 | 113 | erl_dyn_bound_high = 8.0f * srv->erl_ratio[i_spk][1]; 114 | erl_dyn_bound_low = srv->erl_ratio[i_spk][1] / 8.0f; 115 | for (i = 0; i < ERL_BAND_NUM; i++) 116 | { 117 | if (i == 1) 118 | continue; 119 | 120 | if (srv->erl_ratio[i_spk][i] > erl_dyn_bound_high) 121 | srv->erl_ratio[i_spk][i] = erl_dyn_bound_high; 122 | else if (srv->erl_ratio[i_spk][i] < erl_dyn_bound_low) 123 | srv->erl_ratio[i_spk][i] = erl_dyn_bound_low; 124 | } 125 | } 126 | return 0; 127 | } 128 | 129 | -------------------------------------------------------------------------------- /athena_signal/kernels/dios_ssp_aec/dios_ssp_aec_erl_est.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | ==============================================================================*/ 16 | 17 | #ifndef _DIOS_SSP_AEC_ERL_EST_H_ 18 | #define _DIOS_SSP_AEC_ERL_EST_H_ 19 | 20 | #include 21 | #include "dios_ssp_aec_firfilter.h" 22 | 23 | /********************************************************************************** 24 | Function: // dios_ssp_aec_erl_est_process 25 | Description: // run dios speech signal process aec erl estimation module by frames 26 | Input: // srv: dios speech signal process aec firfilter pointer 27 | Output: // none 28 | Return: // success: return 0, failure: return ERR_AEC 29 | **********************************************************************************/ 30 | int dios_ssp_aec_erl_est_process(objFirFilter* srv); 31 | 32 | #endif /* _DIOS_SSP_AEC_ERL_EST_H_ */ 33 | 34 | -------------------------------------------------------------------------------- /athena_signal/kernels/dios_ssp_aec/dios_ssp_aec_firfilter.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | ==============================================================================*/ 16 | 17 | #ifndef _DIOS_SSP_AEC_FIRFILTER_H_ 18 | #define _DIOS_SSP_AEC_FIRFILTER_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | #include "dios_ssp_aec_macros.h" 24 | #include "../dios_ssp_share/dios_ssp_share_complex_defs.h" 25 | #include "../dios_ssp_share/dios_ssp_share_noiselevel.h" 26 | 27 | /* fir filter struct define */ 28 | typedef struct { 29 | int ref_num; 30 | int far_end_talk_holdtime; 31 | float myu; 32 | float beta; 33 | xcomplex** sig_spk_ref; 34 | xcomplex* sig_mic_rec; // data input for filter x, y 35 | float* err_out; // filter result error output 36 | int* num_main_subband_adf; 37 | float* lambda; 38 | float* weight; 39 | xcomplex*** fir_coef; 40 | xcomplex*** adf_coef; 41 | xcomplex*** stack_sigIn_adf; 42 | xcomplex* err_adf; 43 | xcomplex* err_fir; 44 | xcomplex** est_ref_adf; 45 | xcomplex** est_ref_fir; 46 | float* mse_main; //err_fir mse 47 | float* mse_adpt; //err_adf mse 48 | float* mse_mic_in; // mse of mic input singal 49 | float** power_in_ntaps_smooth; 50 | float* mic_rec_psd; 51 | float *energy_err_fir; 52 | float *energy_err_adf; 53 | float* power_mic_send_smooth; 54 | float** power_echo_rtn_smooth; 55 | float** ref_psd; 56 | float** power_echo_rtn_fir; 57 | float** power_echo_rtn_adpt; 58 | // ERL estimate 59 | int** band_table; 60 | float* spk_part_band_energy; 61 | float* echo_return_band_energy; 62 | float* mic_rec_part_band_energy; 63 | float* mic_send_part_band_energy; 64 | float** spk_peak; 65 | float** mic_peak; 66 | float** erl_ratio; 67 | // noise level estimate 68 | objNoiseLevel** noise_est_spk_t; // noise level for reference signal in time domain 69 | objNoiseLevel*** noise_est_spk_part; // partial group band 70 | objNoiseLevel** noise_est_mic_chan; // subband 71 | int adjust_flag; 72 | // double talk detection 73 | int* dt_status; 74 | }objFirFilter; 75 | 76 | /********************************************************************************** 77 | Function: // dios_ssp_aec_firfilter_init 78 | Description: // load configure file and allocate memory 79 | Input: // ref_num: reference number 80 | Output: // none 81 | Return: // success: return dios speech signal process aec firfilter pointer 82 | failure: return NULL 83 | **********************************************************************************/ 84 | objFirFilter* dios_ssp_aec_firfilter_init(int ref_num); 85 | 86 | /********************************************************************************** 87 | Function: // dios_ssp_aec_firfilter_reset 88 | Description: // reset dios speech signal process aec firfilter module 89 | Input: // ptr: dios speech signal process aec firfilter pointer 90 | Output: // none 91 | Return: // success: return 0, failure: return ERR_AEC 92 | **********************************************************************************/ 93 | int dios_ssp_aec_firfilter_reset(objFirFilter* ptr); 94 | 95 | /********************************************************************************** 96 | Function: // dios_ssp_aec_firfilter_process 97 | Description: // run dios speech signal process aec firfilter module by frames 98 | Input: // ptr: dios speech signal process aec firfilter pointer 99 | Output: // output_buf: error signal output 100 | est_echo: estimated echo signal output 101 | Return: // success: return 0, failure: return ERR_AEC 102 | **********************************************************************************/ 103 | int dios_ssp_aec_firfilter_process(objFirFilter* ptr, xcomplex* output_buf, xcomplex* est_echo); 104 | 105 | /********************************************************************************** 106 | Function: // dios_ssp_aec_firfilter_uninit 107 | Description: // free dios speech signal process aec firfilter module 108 | Input: // srv: dios speech signal process aec firfilter pointer 109 | Output: // none 110 | Return: // success: return 0, failure: return ERR_AEC 111 | **********************************************************************************/ 112 | int dios_ssp_aec_firfilter_uninit(objFirFilter* ptr); 113 | 114 | #endif /* _DIOS_SSP_AEC_FIRFILTER_H_ */ 115 | 116 | -------------------------------------------------------------------------------- /athena_signal/kernels/dios_ssp_aec/dios_ssp_aec_res.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | ==============================================================================*/ 16 | 17 | #ifndef _DIOS_SSP_AEC_RES_H_ 18 | #define _DIOS_SSP_AEC_RES_H_ 19 | 20 | #include 21 | #include "dios_ssp_aec_macros.h" 22 | #include "../dios_ssp_share/dios_ssp_share_complex_defs.h" 23 | 24 | typedef struct 25 | { 26 | xcomplex *Xf_res_echo; 27 | xcomplex *Xf_echo; 28 | int ccsize; // number of frequency bins 29 | int nb_adapt; // Number of frames used for adaptation 30 | float *echoPsd; 31 | float *res1_old_ps; 32 | float *res2_old_ps; 33 | float *Eh; //Error avg 34 | float *Yh; //Echo avg 35 | float *res1_echo_noise; 36 | float *res2_echo_noise; 37 | float *res1_zeta; 38 | float *res2_zeta; 39 | float spec_average; 40 | float beta0; 41 | float beta_max; 42 | float Pey_avg; 43 | float Pyy_avg; 44 | float res1_echo_noise_factor; 45 | float res2_echo_noise_factor; 46 | float res1_echo_suppress_default; 47 | float res2_st_echo_suppress_default; 48 | float res2_dt_echo_suppress_default; 49 | float res1_echo_suppress_active_default; 50 | float res2_st_echo_suppress_active_default; 51 | float res2_dt_echo_suppress_active_default; 52 | float res1_suppress_factor; 53 | float res2_st_suppress_factor; 54 | float res2_dt_suppress_factor; 55 | 56 | float *res_echo_noise; 57 | float *res_zeta; 58 | float res_echo_noise_factor; 59 | float *res_echo_psd; 60 | float *res_old_ps; 61 | }objRES; 62 | 63 | /********************************************************************************** 64 | Function: // dios_ssp_aec_res_get_residual_echo 65 | Description: // compute spectrum of estimated residual echo for use in an echo post-filter 66 | Input: // srv: dios speech signal process aec res pointer 67 | dt_st: double-talk detection result 68 | stage: the stage of residual echo suppression 69 | Output: // residual_echo: residual echo output 70 | Return: // success: return 0, failure: return ERR_AEC 71 | **********************************************************************************/ 72 | int dios_ssp_aec_res_get_residual_echo(objRES* srv, float* residual_echo, int dt_st, int stage); 73 | 74 | /********************************************************************************** 75 | Function: // dios_ssp_aec_res_init 76 | Description: // load configure file and allocate memory 77 | Input: // none 78 | Output: // none 79 | Return: // success: return dios speech signal process aec res pointer 80 | failure: return NULL 81 | **********************************************************************************/ 82 | objRES* dios_ssp_aec_res_init(void); 83 | 84 | /********************************************************************************** 85 | Function: // dios_ssp_aec_res_reset 86 | Description: // reset dios speech signal process aec res module 87 | Input: // srv: dios speech signal process aec res pointer 88 | Output: // none 89 | Return: // success: return 0, failure: return ERR_AEC 90 | **********************************************************************************/ 91 | int dios_ssp_aec_res_reset(objRES *srv); 92 | 93 | /********************************************************************************** 94 | Function: // dios_ssp_aec_res_process 95 | Description: // run dios speech signal process aec res module by frames 96 | Input: // srv: dios speech signal process aec res pointer 97 | dt_st: double-talk detection result 98 | stage: the stage of residual echo suppression 99 | Output: // none 100 | Return: // success: return 0, failure: return ERR_AEC 101 | **********************************************************************************/ 102 | int dios_ssp_aec_res_process(objRES *srv, int dt_st, int stage); 103 | 104 | /********************************************************************************** 105 | Function: // dios_ssp_aec_res_uninit 106 | Description: // free dios speech signal process aec res module 107 | Input: // srv: dios speech signal process aec res pointer 108 | Output: // none 109 | Return: // success: return 0, failure: return ERR_AEC 110 | **********************************************************************************/ 111 | int dios_ssp_aec_res_unit(objRES *srv); 112 | 113 | #endif /* _DIOS_SSP_AEC_RES_H_ */ 114 | -------------------------------------------------------------------------------- /athena_signal/kernels/dios_ssp_aec/dios_ssp_aec_tde/dios_ssp_aec_tde.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | ==============================================================================*/ 16 | 17 | #ifndef _DIOS_SSP_AEC_TDE_H_ 18 | #define _DIOS_SSP_AEC_TDE_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | #include "dios_ssp_aec_tde_delay_estimator_wrapper.h" 24 | #include "../dios_ssp_aec_macros.h" 25 | #include "../../dios_ssp_share/dios_ssp_share_complex_defs.h" 26 | 27 | typedef struct 28 | { 29 | /* TDE */ 30 | AecmCore_t *tde_short; 31 | AecmCore_t *tde_long; 32 | 33 | int flag_delayfind; 34 | 35 | /* Realign flag */ 36 | unsigned short CalibrateEnable; 37 | int CalibrateCounter; 38 | 39 | int mic_num; 40 | int ref_num; 41 | int frm_len; 42 | 43 | /* buffer, loop number and data length definition */ 44 | float *tdeBuf_ref; 45 | float *tdeBuf_mic; 46 | float **audioBuf_mic; 47 | float **audioBuf_ref; 48 | int pt_buf_push; 49 | int pt_output; 50 | double delay_fixed_sec; 51 | double delay_varied_sec; 52 | int tde_long_shift_smpl; 53 | int tde_short_shift_smpl; 54 | int act_delay_smpl; 55 | int act_delay_smpl_old; 56 | int frame_cnt_nSecond; 57 | int vadflag_mic; 58 | int vadflag_ref; 59 | }objTDE; 60 | 61 | /********************************************************************************** 62 | Function: // dios_ssp_aec_tde_init 63 | Description: // load configure file and allocate memory 64 | Input: // mic_num: microphone number 65 | ref_num: reference number 66 | frm_len: frame length 67 | Output: // none 68 | Return: // success: return dios speech signal process aec time delay estimation(tde) pointer 69 | failure: return NULL 70 | **********************************************************************************/ 71 | objTDE* dios_ssp_aec_tde_init(int mic_num, int ref_num, int frm_len); 72 | 73 | /********************************************************************************** 74 | Function: // dios_ssp_aec_tde_reset 75 | Description: // reset dios speech signal process aec tde module 76 | Input: // srv: dios speech signal process aec tde pointer 77 | Output: // none 78 | Return: // success: return 0, failure: return ERR_AEC 79 | **********************************************************************************/ 80 | int dios_ssp_aec_tde_reset(objTDE* srv); 81 | 82 | /********************************************************************************** 83 | Function: // dios_ssp_aec_tde_process 84 | Description: // run dios speech signal process aec tde module 85 | Input: // srv: dios speech signal process aec tde pointer 86 | refbuf: reference data buffer 87 | micbuf: microphone array data buffer 88 | Output: // none 89 | Return: // success: return 0, failure: return ERR_AEC 90 | **********************************************************************************/ 91 | int dios_ssp_aec_tde_process(objTDE* srv, float* refbuf, float* micbuf); 92 | 93 | /********************************************************************************** 94 | Function: // dios_ssp_aec_tde_uninit 95 | Description: // free dios speech signal process aec tde module 96 | Input: // srv: dios speech signal process aec tde pointer 97 | Output: // none 98 | Return: // success: return 0, failure: return ERR_AEC 99 | **********************************************************************************/ 100 | int dios_ssp_aec_tde_uninit(objTDE* srv); 101 | 102 | #endif /* _DIOS_SSP_AEC_TDE_H_ */ 103 | 104 | -------------------------------------------------------------------------------- /athena_signal/kernels/dios_ssp_aec/dios_ssp_aec_tde/dios_ssp_aec_tde_ring_buffer.c: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | Description: some codes of this file refers to Webrtc (https://webrtc.org/) 17 | which is an open source. this file aims to make a a ring buffer to hold 18 | arbitrary data. Provides no thread safety. Unless otherwise specified, 19 | functions return 0 on success and -1 on error. 20 | ==============================================================================*/ 21 | 22 | /* include file */ 23 | #include "dios_ssp_aec_tde_ring_buffer.h" 24 | 25 | enum Wrap 26 | { 27 | SAME_WRAP 28 | }; 29 | 30 | struct RingBuffer 31 | { 32 | size_t read_pos; 33 | size_t write_pos; 34 | size_t element_count; 35 | size_t element_size; 36 | enum Wrap rw_wrap; 37 | char* data; 38 | }; 39 | 40 | RingBuffer* dios_ssp_aec_tde_creatbuffer(size_t element_count, size_t element_size) 41 | { 42 | RingBuffer* self = NULL; 43 | if (element_count == 0 || element_size == 0) 44 | { 45 | return NULL; 46 | } 47 | 48 | self = (RingBuffer*)calloc(1, sizeof(RingBuffer)); 49 | if (!self) 50 | { 51 | return NULL; 52 | } 53 | 54 | self->data = (char*)calloc(element_count * element_size, sizeof(char)); 55 | if (!self->data) 56 | { 57 | free(self); 58 | self = NULL; 59 | return NULL; 60 | } 61 | 62 | self->element_count = element_count; 63 | self->element_size = element_size; 64 | 65 | return self; 66 | } 67 | 68 | int dios_ssp_aec_tde_initbuffer(RingBuffer* self) 69 | { 70 | if (!self) 71 | { 72 | return -1; 73 | } 74 | 75 | self->read_pos = 0; 76 | self->write_pos = 0; 77 | self->rw_wrap = SAME_WRAP; 78 | 79 | // Initialize buffer to zeros 80 | memset(self->data, 0, self->element_count * self->element_size); 81 | 82 | return 0; 83 | } 84 | 85 | void dios_ssp_aec_tde_freebuffer(void* handle) 86 | { 87 | RingBuffer* self = (RingBuffer*)handle; 88 | if (!self) 89 | { 90 | return; 91 | } 92 | 93 | free(self->data); 94 | free(self); 95 | } 96 | -------------------------------------------------------------------------------- /athena_signal/kernels/dios_ssp_aec/dios_ssp_aec_tde/dios_ssp_aec_tde_ring_buffer.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | ==============================================================================*/ 16 | 17 | #ifndef _DIOS_SSP_AEC_TDE_RING_BUFFER_H_ 18 | #define _DIOS_SSP_AEC_TDE_RING_BUFFER_H_ 19 | 20 | #include // size_t 21 | #include 22 | #include 23 | 24 | typedef struct RingBuffer RingBuffer; 25 | 26 | // Returns NULL on failure. 27 | RingBuffer* dios_ssp_aec_tde_creatbuffer(size_t element_count, size_t element_size); 28 | int dios_ssp_aec_tde_initbuffer(RingBuffer* handle); 29 | void dios_ssp_aec_tde_freebuffer(void* handle); 30 | 31 | #endif /* _DIOS_SSP_AEC_TDE_RING_BUFFER_H_ */ 32 | -------------------------------------------------------------------------------- /athena_signal/kernels/dios_ssp_agc/dios_ssp_agc_api.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | ==============================================================================*/ 16 | 17 | #ifndef _DIOS_SSP_AGC_API_H_ 18 | #define _DIOS_SSP_AGC_API_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | #include "../dios_ssp_return_defs.h" 24 | #include "../dios_ssp_share/dios_ssp_share_complex_defs.h" 25 | 26 | /********************************************************************************** 27 | Function: // dios_ssp_agc_init_api 28 | Description: // init agc module 29 | Input: // frame_len: frame length 30 | peak_val: agc peak value 31 | mode_type: agc mode type 32 | Output: // none 33 | Return: // success: return agc module pointer 34 | failure: return NULL 35 | **********************************************************************************/ 36 | void* dios_ssp_agc_init_api(int frame_len, float peak_val, int mode_type); 37 | 38 | /********************************************************************************** 39 | Function: // dios_ssp_agc_reset_api 40 | Description: // reset agc module 41 | Input: // ptr: agc module pointer 42 | Output: // none 43 | Return: // success: return 0, failure: return ERROR_AGC 44 | **********************************************************************************/ 45 | int dios_ssp_agc_reset_api(void* ptr); 46 | 47 | /********************************************************************************** 48 | Function: // dios_ssp_agc_process_api 49 | Description: // agc process 50 | Input: // ptr: agc module pointer 51 | io_buf: input and output buffer 52 | vad_sig: 53 | vad_dir: 54 | dt_st: doubletalk state, if any 55 | Output: // none 56 | Return: // success: return 0, failure: return ERROR_AGC 57 | **********************************************************************************/ 58 | int dios_ssp_agc_process_api(void* ptr, float* io_buf, 59 | int vad_sig, int vad_dir, int dt_st); 60 | 61 | /********************************************************************************** 62 | Function: // dios_ssp_agc_uninit_api 63 | Description: // free agc module 64 | Input: // ptr: agc module pointer 65 | Output: // none 66 | Return: // success: return 0, failure: return ERROR_AGC 67 | **********************************************************************************/ 68 | int dios_ssp_agc_uninit_api(void* ptr); 69 | 70 | #endif /* _DIOS_SSP_AGC_API_H_ */ 71 | 72 | -------------------------------------------------------------------------------- /athena_signal/kernels/dios_ssp_api.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | ==============================================================================*/ 16 | 17 | #ifndef _DIOS_SSP_API_H_ 18 | #define _DIOS_SSP_API_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | #include "./dios_ssp_hpf/dios_ssp_hpf_api.h" 24 | #include "./dios_ssp_vad/dios_ssp_vad_api.h" 25 | #include "./dios_ssp_aec/dios_ssp_aec_api.h" 26 | #include "./dios_ssp_ns/dios_ssp_ns_api.h" 27 | #include "./dios_ssp_agc/dios_ssp_agc_api.h" 28 | #include "./dios_ssp_mvdr/dios_ssp_mvdr_api.h" 29 | #include "./dios_ssp_doa/dios_ssp_doa_api.h" 30 | #include "./dios_ssp_gsc/dios_ssp_gsc_api.h" 31 | 32 | typedef struct 33 | { 34 | short AEC_KEY; 35 | short NS_KEY; 36 | short AGC_KEY; 37 | short HPF_KEY; 38 | short BF_KEY; 39 | short DOA_KEY; 40 | 41 | int mic_num; 42 | int ref_num; 43 | PlaneCoord mic_coord[16]; 44 | float loc_phi; 45 | } objSSP_Param; 46 | 47 | /********************************************************************************** 48 | Function: // dios_ssp_init_api 49 | Description: // init with SSP_PARAM and allocate memory 50 | Input: // SSP_PARAM: object of SSP with necessary parameters 51 | Output: // none 52 | Return: // success: return dios speech signal process pointer 53 | failure: return NULL 54 | **********************************************************************************/ 55 | void* dios_ssp_init_api(objSSP_Param *SSP_PARAM); 56 | 57 | /********************************************************************************** 58 | Function: // dios_ssp_reset_api 59 | Description: // reset dios speech signal process module 60 | Input: // ptr: dios speech signal process pointer 61 | SSP_PARAM: 62 | Output: // none 63 | Return: // success: return OK_AUDIO_PROCESS, failure: return others 64 | **********************************************************************************/ 65 | int dios_ssp_reset_api(void* ptr, objSSP_Param *SSP_PARAM); 66 | 67 | /********************************************************************************** 68 | Function: // dios_ssp_process_api 69 | Description: // run dios speech signal process module by frames 70 | Input: // ptr: dios speech signal process pointer 71 | mic_buf: microphone array data buffer 72 | ref_buf: reference data buffer 73 | for mono-channel, the length of ref_buf is 128 74 | for stereo-channel, the length of ref_buf is 128 * 2, 75 | [0 ~ 127] is from left channel 76 | [128 ~ 255] is from right channel 77 | SSP_PARAM: 78 | Output: // out_buf: processed data 79 | Return: // success: return OK_AUDIO_PROCESS, failure: return others 80 | **********************************************************************************/ 81 | int dios_ssp_process_api(void* ptr, short* mic_buf, short* ref_buf, 82 | short* out_buf, objSSP_Param *SSP_PARAM); 83 | 84 | /********************************************************************************** 85 | Function: // dios_ssp_uninit_api 86 | Description: // free dios speech signal process module 87 | Input: // ptr: dios speech signal process pointer 88 | SSP_PARAM: 89 | Output: // none 90 | Return: // success: return OK_AUDIO_PROCESS, failure: return others 91 | **********************************************************************************/ 92 | int dios_ssp_uninit_api(void* ptr, objSSP_Param *SSP_PARAM); 93 | 94 | #endif /* _DIOS_SSP_API_H_ */ 95 | 96 | -------------------------------------------------------------------------------- /athena_signal/kernels/dios_ssp_doa/dios_ssp_doa_api.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | ==============================================================================*/ 16 | 17 | #ifndef _DIOS_SSP_DOA_API_H_ 18 | #define _DIOS_SSP_DOA_API_H_ 19 | 20 | #include 21 | #include "../dios_ssp_return_defs.h" 22 | #include "dios_ssp_doa_macros.h" 23 | #include "dios_ssp_doa_win.h" 24 | #include "../dios_ssp_share/dios_ssp_share_typedefs.h" 25 | #include "../dios_ssp_share/dios_ssp_share_rfft.h" 26 | #include "../dios_ssp_share/dios_ssp_share_cinv.h" 27 | 28 | typedef struct 29 | { 30 | int m_fs; 31 | float m_eps; 32 | int m_channels; 33 | int m_delta_angle; 34 | float m_deta_fs; 35 | int m_fft_size; 36 | int m_sp_size; 37 | int m_shift_size; 38 | int m_angle_num; 39 | float m_angle_smooth; 40 | int m_frq_bin_num; 41 | float m_low_frq; 42 | float m_high_frq; 43 | int m_frq_sp; 44 | float *m_capon_spectrum; 45 | int *m_doa_fid; 46 | int m_low_fid; 47 | float *m_irxx_re; 48 | float *m_irxx_im; 49 | float *m_vec_re; 50 | float *m_vec_im; 51 | float *m_gstv_re; 52 | float *m_gstv_im; 53 | int m_frq_bin_width; 54 | // rxx 55 | int m_rxx_size; 56 | float *m_rxx_in; 57 | float *m_irxx_out; 58 | float *m_rxx_re; 59 | float *m_rxx_im; 60 | float *m_re; 61 | float *m_im; 62 | float *m_win_data; 63 | float *fft_out; 64 | short m_first_frame_flag; 65 | float m_beta_rxx; 66 | float m_alpha_rxx; 67 | int m_gstv_dim; 68 | PlaneCoord *cood; 69 | void *doainv; 70 | objDOACwin *doawin; 71 | void *doa_fft; 72 | float **m_mch_buffer; 73 | }objDOA; 74 | 75 | /********************************************************************************** 76 | Function: // dios_ssp_doa_init_api 77 | Description: // doa init 78 | Input: // sensor_num: microphone number 79 | cood: micphone coordinate 80 | Output: // none 81 | Return: // success: return doa object pointer (void*)ptr_doa 82 | failure: return NULL 83 | **********************************************************************************/ 84 | void* dios_ssp_doa_init_api(int mic_num, PlaneCoord* mic_coord); 85 | 86 | /********************************************************************************** 87 | Function: // dios_ssp_doa_reset_api 88 | Description: // doa reset 89 | Input: // ptr 90 | Output: // none 91 | Return: // success: return 0 92 | **********************************************************************************/ 93 | int dios_ssp_doa_reset_api(void *ptr); 94 | 95 | /********************************************************************************** 96 | Function: // dios_ssp_doa_process_api 97 | Description: // doa process 98 | Input: // ptr 99 | // in: microphone data 100 | // vad_result: vad result 101 | // dt_st: double talk result 102 | Output: // none 103 | Return: // success: return doa result 104 | **********************************************************************************/ 105 | float dios_ssp_doa_process_api(void* ptr, float* in, int vad_result, int dt_st); 106 | 107 | /********************************************************************************** 108 | Function: // dios_ssp_doa_uninit_api 109 | Description: // doa free 110 | Input: // ptr 111 | Output: // none 112 | Return: // success: return 0 113 | **********************************************************************************/ 114 | int dios_ssp_doa_uninit_api(void *ptr); 115 | 116 | #endif /* _DIOS_SSP_DOA_API_H_ */ 117 | -------------------------------------------------------------------------------- /athena_signal/kernels/dios_ssp_doa/dios_ssp_doa_macros.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | ==============================================================================*/ 16 | 17 | #ifndef _DIOS_SSP_DOA_MACROS_H_ 18 | #define _DIOS_SSP_DOA_MACROS_H_ 19 | 20 | #define VELOCITY (340.0f) 21 | #define PI (3.141592653589793f) 22 | #define DEFAULT_DOA_SAMPLING_FRQ 16000 23 | #define DEFAULT_DOA_WIN_SIZE 512 24 | #define DEFAULT_DOA_SHIFT_SIZE 128 25 | #define DEFAULT_DOA_DELTA_ANGLE 5 26 | #define DEFAULT_DOA_LOW_FRQ 2000 27 | #define DEFAULT_DOA_HIGH_FRQ 6000 28 | #define DEFAULT_DOA_FRQ_SP 200 29 | #define DEFAULT_DOA_EPS 1073 30 | #define DEFAULT_DOA_ALPHA_RXX (0.9f) 31 | 32 | #endif /* _DIOS_SSP_DOA_MACROS_H_ */ 33 | 34 | -------------------------------------------------------------------------------- /athena_signal/kernels/dios_ssp_doa/dios_ssp_doa_win.c: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | Description: Analysis window and synthesis window of DOA 17 | ==============================================================================*/ 18 | 19 | #include "dios_ssp_doa_win.h" 20 | 21 | void dios_ssp_doa_win_init(objDOACwin *doawin,int fft_size, int shift_size) 22 | { 23 | int i, j; 24 | int tmp; 25 | int log_fft_size = 0; 26 | float temp; 27 | tmp = 1; 28 | 29 | doawin->m_fft_size = fft_size; 30 | doawin->m_shift_size = shift_size; 31 | 32 | if ( doawin->m_shift_size >= doawin->m_fft_size ) 33 | { 34 | printf( "shift_size[%d] >= fft_size[%d].\n", doawin->m_shift_size, doawin->m_fft_size ); 35 | } 36 | 37 | while ( tmp < doawin->m_fft_size ) 38 | { 39 | log_fft_size += 1; 40 | tmp *= 2; 41 | } 42 | if ( tmp > doawin->m_fft_size ) 43 | { 44 | printf( "FFT Size[%d] should be power of 2.\n", doawin->m_fft_size ); 45 | } 46 | tmp = 1; 47 | while ( tmp < doawin->m_shift_size ) 48 | { 49 | tmp *= 2; 50 | } 51 | if ( tmp > doawin->m_shift_size ) 52 | { 53 | printf( "Shift Size[%d] should be power of 2.\n", doawin->m_shift_size ); 54 | } 55 | 56 | doawin->m_block_num = doawin->m_fft_size / doawin->m_shift_size; 57 | doawin->m_ana_win = (float*)calloc(doawin->m_fft_size, sizeof(float)); 58 | doawin->m_norm_win = (float*)calloc(doawin->m_fft_size, sizeof(float)); 59 | 60 | for (i = 0; i < doawin->m_fft_size; ++i ) 61 | { 62 | doawin->m_ana_win[i] = (float)(0.54 - 0.46*cos((2*i)*PI/(doawin->m_fft_size-1))); 63 | } 64 | for (i = 0; i < doawin->m_fft_size; ++i ) 65 | { 66 | doawin->m_norm_win[i] = doawin->m_ana_win[i] * doawin->m_ana_win[i]; 67 | } 68 | for (i = 0; i < doawin->m_shift_size; ++i ) 69 | { 70 | temp = 0; 71 | for (j = 0; j < doawin->m_block_num; ++j ) 72 | { 73 | temp += doawin->m_norm_win[i+j*doawin->m_shift_size]; 74 | } 75 | doawin->m_norm_win[i] = 1.0f / temp; 76 | } 77 | for (i = 0; i < doawin->m_shift_size; ++i ) 78 | { 79 | for (j = 1; j < doawin->m_block_num; ++j ) 80 | { 81 | doawin->m_norm_win[i+j*doawin->m_shift_size] = doawin->m_norm_win[i]; 82 | } 83 | } 84 | } 85 | 86 | int dios_ssp_doa_win_add_ana_win(objDOACwin *doawin, const float *x, float *x_win) 87 | { 88 | int i; 89 | for (i = 0; i < doawin->m_fft_size; ++i ) 90 | { 91 | x_win[i] = x[i] * doawin->m_ana_win[i]; 92 | } 93 | 94 | return 0; 95 | } 96 | 97 | int dios_ssp_doa_win_delete(objDOACwin *doawin) 98 | { 99 | free(doawin->m_ana_win); 100 | free(doawin->m_norm_win); 101 | 102 | return 0; 103 | } 104 | 105 | -------------------------------------------------------------------------------- /athena_signal/kernels/dios_ssp_doa/dios_ssp_doa_win.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | ==============================================================================*/ 16 | 17 | #ifndef _DIOS_SSP_DOA_WIN_H_ 18 | #define _DIOS_SSP_DOA_WIN_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include "dios_ssp_doa_macros.h" 25 | 26 | typedef struct 27 | { 28 | int m_fft_size; 29 | int m_shift_size; 30 | int m_block_num; 31 | 32 | float *m_ana_win; 33 | float *m_norm_win; 34 | }objDOACwin; 35 | 36 | /********************************************************************************** 37 | Function: // dios_ssp_doa_win_init 38 | Description: // doa win init 39 | Input: // doawin 40 | fft_size 41 | shift_size 42 | Output: // none 43 | Return: // success: return doa win object pointer (void*)doawin 44 | failure: return NULL 45 | **********************************************************************************/ 46 | void dios_ssp_doa_win_init(objDOACwin *doawin,int fft_size, int shift_size); 47 | 48 | /********************************************************************************** 49 | Function: // dios_ssp_doa_win_add_ana_win 50 | Description: // doa win ana 51 | Input: // doawin: doa win object pointer 52 | x: enter data 53 | Output: // x_win 54 | Return: // success: return 0 55 | **********************************************************************************/ 56 | int dios_ssp_doa_win_add_ana_win(objDOACwin *doawin, const float *x, float *x_win); 57 | 58 | /********************************************************************************** 59 | Function: // dios_ssp_doa_win_delete 60 | Description: // doa win syn 61 | Input: // doawin: doa win object pointer 62 | Output: // none 63 | Return: // success: return 0 64 | **********************************************************************************/ 65 | int dios_ssp_doa_win_delete(objDOACwin *doawin); 66 | 67 | #endif /* _DIOS_SSP_DOA_WIN_H_ */ 68 | 69 | -------------------------------------------------------------------------------- /athena_signal/kernels/dios_ssp_gsc/dios_ssp_gsc_api.c: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | Description: This is a Generalized Sidelobe Canceller beamformer. 17 | When the DOA module is disabled, you can set the steering vector(loc_phi) by 18 | yourself, which indicates the distortionless response direction. 19 | When the DOA module is enabled, the steering vector will be estimated by DOA 20 | estimation. You can set the steering vector by your own DOA estimation method. 21 | Microphone array could be any shape as long as you set the coordinates of each 22 | microphones(mic_coord) beforehand. 23 | ==============================================================================*/ 24 | 25 | #include "dios_ssp_gsc_api.h" 26 | 27 | void* dios_ssp_gsc_init_api(int mic_num, void* mic_coord) 28 | { 29 | void* st = NULL; 30 | st = (void*)calloc(1, sizeof(objGSCProcess)); 31 | objGSCProcess* ptr = (objGSCProcess*)st; 32 | 33 | PlaneCoord* mic_coord_1 = NULL; 34 | mic_coord_1 = (PlaneCoord*)mic_coord; 35 | dios_ssp_gsc_init(ptr, mic_num, mic_coord_1); 36 | 37 | return st; 38 | } 39 | 40 | int dios_ssp_gsc_reset_api(void* ptr) 41 | { 42 | if(ptr == NULL) 43 | { 44 | printf("gsc handle not init!\n"); 45 | return ERROR_GSC; 46 | } 47 | 48 | objGSCProcess* ptr_gsc; 49 | ptr_gsc = (objGSCProcess*)ptr; 50 | dios_ssp_gsc_reset(ptr_gsc); 51 | 52 | return 0; 53 | } 54 | 55 | int dios_ssp_gsc_process_api(void* ptr, float* mic_data, float* out_data, float loc_phi) 56 | { 57 | if(ptr == NULL) 58 | { 59 | printf("gsc handle not init!\n"); 60 | return ERROR_GSC; 61 | } 62 | objGSCProcess *ptr_gsc; 63 | ptr_gsc= (objGSCProcess*)ptr; 64 | 65 | for (int i = 0; i < ptr_gsc->mic_num; i++) 66 | { 67 | memcpy(ptr_gsc->ptr_input_data_float[i], mic_data + i * ptr_gsc->frame_len, sizeof(float) * ptr_gsc->frame_len); 68 | } 69 | ptr_gsc->source_location.phi = loc_phi * PI / 180.0f; 70 | doProcess(ptr_gsc); 71 | memcpy(out_data, ptr_gsc->ptr_output_data_float, sizeof(float) * ptr_gsc->frame_len); 72 | 73 | return 0; 74 | } 75 | 76 | int dios_ssp_gsc_uninit_api(void* ptr) 77 | { 78 | if(ptr == NULL) 79 | { 80 | printf("gsc handle not init!\n"); 81 | return ERROR_GSC; 82 | } 83 | objGSCProcess *ptr_gsc; 84 | ptr_gsc= (objGSCProcess*)ptr; 85 | dios_ssp_gsc_delete(ptr_gsc); 86 | return 0; 87 | } 88 | -------------------------------------------------------------------------------- /athena_signal/kernels/dios_ssp_gsc/dios_ssp_gsc_api.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | ==============================================================================*/ 16 | 17 | #ifndef _DIOS_SSP_GSC_API_H_ 18 | #define _DIOS_SSP_GSC_API_H_ 19 | 20 | #include 21 | #include 22 | #include "dios_ssp_gsc_micarray.h" 23 | #include "../dios_ssp_return_defs.h" 24 | 25 | 26 | /********************************************************************************** 27 | Function: // dios_ssp_gsc_init_api 28 | Description: // gsc init 29 | Input: // mic_num: microphone number 30 | mic_coord: each microphone coordinate (PlaneCoord*)mic_coord 31 | Output: // none 32 | Return: // success: return gsc object pointer (void*)ptr_gsc 33 | failure: return NULL 34 | Others: // none 35 | **********************************************************************************/ 36 | void* dios_ssp_gsc_init_api(int mic_num, void* mic_coord); 37 | 38 | /********************************************************************************** 39 | Function: // dios_ssp_gsc_reset_api 40 | Description: // gsc reset 41 | Input: // ptr: gsc object pointer 42 | Output: // none 43 | Return: // success: return 0, failure: return ERROR_GSC 44 | Others: // none 45 | **********************************************************************************/ 46 | int dios_ssp_gsc_reset_api(void* ptr); 47 | 48 | /********************************************************************************** 49 | Function: // dios_ssp_gsc_process_api 50 | Description: // gsc process 51 | Input: // ptr: gsc object pointer 52 | mic_data: gsc input data, data type is float 53 | loc_phi: direction of wakeup 54 | Output: // out_data: gsc output signal 55 | Return: // success: return 0, failure: return ERROR_GSC 56 | Others: // none 57 | **********************************************************************************/ 58 | int dios_ssp_gsc_process_api(void* ptr, float* mic_data, float* out_data, float loc_phi); 59 | 60 | /********************************************************************************** 61 | Function: // dios_ssp_gsc_uninit_api 62 | Description: // gsc delete 63 | Input: // ptr: gsc object pointer 64 | Output: // none 65 | Return: // success: return 0, failure: return ERROR_GSC 66 | Others: // none 67 | **********************************************************************************/ 68 | int dios_ssp_gsc_uninit_api(void* ptr); 69 | 70 | #endif /* _DIOS_SSP_GSC_API_H_ */ 71 | 72 | -------------------------------------------------------------------------------- /athena_signal/kernels/dios_ssp_gsc/dios_ssp_gsc_beamformer.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | ==============================================================================*/ 16 | 17 | #ifndef _DIOS_SSP_GSC_BEAMFORMER_H_ 18 | #define _DIOS_SSP_GSC_BEAMFORMER_H_ 19 | 20 | #include "dios_ssp_gsc_dsptools.h" 21 | #include "dios_ssp_gsc_globaldefs.h" 22 | #include "dios_ssp_gsc_beamsteering.h" 23 | #include "dios_ssp_gsc_filtsumbeamformer.h" 24 | #include "dios_ssp_gsc_abm.h" 25 | #include "dios_ssp_gsc_aic.h" 26 | #include "dios_ssp_gsc_adaptctrl.h" 27 | #include "../dios_ssp_share/dios_ssp_share_typedefs.h" 28 | 29 | typedef struct 30 | { 31 | float **m_input; 32 | float **m_outSteering; 33 | float *m_outFBF; 34 | float *m_ctrlABM; 35 | float *m_ctrlAIC; 36 | float **m_outABM; 37 | float *m_outAIC; 38 | float *m_output; 39 | 40 | int m_nMic; 41 | int m_nIOBlockSize; 42 | DWORD m_dwSampRate; 43 | float m_time; 44 | int m_nInputChannels; 45 | int m_nGSCUpdateSize; 46 | int m_nCCSSize; 47 | 48 | PlaneCoord *m_locMic; 49 | float *m_tdoa; 50 | float m_current_phi; 51 | float m_phi_thr; 52 | float m_current_abm_phi; 53 | float m_abm_phi_thr; 54 | 55 | float m_soft_vol; 56 | float m_alpha_mute; 57 | float m_alpha_active; 58 | 59 | GSCFDAF m_paramGSC; /* parameters for gsc frequency-domain adaptive filters */ 60 | ADAPTCTRL m_paramAC; /* parameters for adaptation control */ 61 | ABMPARAMETERS m_paramABM; /* parameters for adaptive blocking matrix */ 62 | AICPARAMETERS m_paramAIC; /* parameters for adaptive interference canceller */ 63 | SYNCDELAYS m_paramSync; /* parameters for synchronization delays */ 64 | 65 | objCGSCbeamsteer *gscbeamsteer; /* declaration of beamsteering */ 66 | objFGSCfiltsumbeamformer *gscfiltsumbeamformer; /* declaration of fixed beamformer */ 67 | objFGSCabm *gscabm; /* declaration of adaptive blocking matrix */ 68 | objFGSCaic *gscaic; /* declaration of adaptive interference canceller */ 69 | objFGSCadaptctrl *gscadaptctrl; /* declaration of gsc adaptation control */ 70 | 71 | }objCGSCbeamformer; 72 | 73 | /********************************************************************************** 74 | Function: // dios_ssp_gsc_gscbeamformer_init 75 | Description: // beamformer init 76 | Input: // gscbeamformer: gscbeamformer object pointer 77 | nMic: microphone number 78 | coord: each microphone coordinate (PlaneCoord*)mic_coord 79 | Output: // none 80 | Return: // success: return gscbeamformer object pointer 81 | Others: // none 82 | **********************************************************************************/ 83 | void dios_ssp_gsc_gscbeamformer_init(objCGSCbeamformer* gscbeamformer, DWORD nMic, DWORD dwSampRate, DWORD dwBlockSize, General_ArrayGeometric type, void *coord); 84 | 85 | /********************************************************************************** 86 | Function: // dios_ssp_gsc_gscbeamformer_reset 87 | Description: // beamformer reset 88 | Input: // gscbeamformer: gscbeamformer object pointer 89 | Output: // none 90 | Return: // success: return 0 91 | Others: // none 92 | **********************************************************************************/ 93 | int dios_ssp_gsc_gscbeamformer_reset(objCGSCbeamformer* gscbeamformer); 94 | 95 | /********************************************************************************** 96 | Function: // dios_ssp_gsc_gscbeamformer_arraysteer 97 | Description: // beamformer steering 98 | Input: // prototype: pSrcLoc, polar coordinates of source locations 99 | Output: // none 100 | Return: // success: return 0 101 | Others: // none 102 | **********************************************************************************/ 103 | int dios_ssp_gsc_gscbeamformer_arraysteer(objCGSCbeamformer* gscbeamformer, PolarCoord loc); 104 | 105 | /********************************************************************************** 106 | Function: // dios_ssp_gsc_gscbeamformer_process 107 | Description: // process data of one block 108 | Input: // prototype: pInput, float data, multi-channel, continuous memory 109 | Output: // none 110 | Return: // success: return 0 111 | Others: // none 112 | **********************************************************************************/ 113 | int dios_ssp_gsc_gscbeamformer_process(objCGSCbeamformer* gscbeamformer, float** ppInput); 114 | 115 | /********************************************************************************** 116 | Function: // dios_ssp_gsc_gscbeamformer_delete 117 | Description: // beamformer delete 118 | Input: // gscbeamformer: gscbeamformer object pointer 119 | Output: // none 120 | Return: // success: return 0 121 | Others: // none 122 | **********************************************************************************/ 123 | int dios_ssp_gsc_gscbeamformer_delete(objCGSCbeamformer* gscbeamformer); 124 | 125 | #endif /* _DIOS_SSP_GSC_BEAMFORMER_H_ */ 126 | -------------------------------------------------------------------------------- /athena_signal/kernels/dios_ssp_gsc/dios_ssp_gsc_beamsteering.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | ==============================================================================*/ 16 | 17 | #ifndef _DIOS_SSP_GSC_BEAMSTEERING_H_ 18 | #define _DIOS_SSP_GSC_BEAMSTEERING_H_ 19 | 20 | #include "dios_ssp_gsc_firfilterdesign.h" 21 | #include "dios_ssp_gsc_dsptools.h" 22 | 23 | typedef struct 24 | { 25 | int m_nMic; /* number of microphones */ 26 | DWORD m_dwKernelRate; /* sampling rate */ 27 | int m_nTaps; /* number of taps to use */ 28 | int m_nBlockSize; /* size of one block in samples */ 29 | float *m_delays; /* vector with intersensor delays */ 30 | float **m_pDlyLine; 31 | float **m_pTaps; 32 | int *m_nDlyLineIndex; 33 | 34 | objCGeneralFIRDesigner *generalfirdesign; 35 | 36 | }objCGSCbeamsteer; 37 | 38 | /********************************************************************************** 39 | Function: // dios_ssp_gsc_gscbeamsteer_init 40 | Description: // beamsteering process init 41 | Input: // gscbeamsteer: gscbeamsteer object pointer 42 | nMic: number of microphones 43 | nBlockSize: size of one block in samples 44 | dwKernelRate: sampling rate 45 | nTaps: number of taps to use 46 | Return: // success: return gscbeamsteer object pointer 47 | Others: // none 48 | **********************************************************************************/ 49 | void dios_ssp_gsc_gscbeamsteer_init(objCGSCbeamsteer* gscbeamsteer, int nMic, int nBlockSize, DWORD dwKernelRate, int nTaps); 50 | 51 | /********************************************************************************** 52 | Function: // dios_ssp_gsc_gscbeamsteer_reset 53 | Description: // beamsteering process reset 54 | Input: // gscbeamsteer: gscbeamsteer object pointer 55 | Return: // success: return 0 56 | Others: // none 57 | **********************************************************************************/ 58 | int dios_ssp_gsc_gscbeamsteer_reset(objCGSCbeamsteer* gscbeamsteer); 59 | 60 | /********************************************************************************** 61 | Function: // dios_ssp_gsc_gscbeamsteering 62 | Description: // prepare delay filter according to TDOA, stored in m_pTaps 63 | Input: // gscbeamsteer: gscbeamsteer object pointer 64 | delay_sample: TDOA 65 | dwInputRate: sampling rate of input signal 66 | Return: // success: return 0 67 | Others: // none 68 | **********************************************************************************/ 69 | int dios_ssp_gsc_gscbeamsteering(objCGSCbeamsteer* gscbeamsteer, float *delay_sample, DWORD dwInputRate); 70 | 71 | /********************************************************************************** 72 | Function: // dios_ssp_gsc_gscbeamsteer_process 73 | Description: // do delay-filtering processing 74 | Input: // X: input signals 75 | Output: // Y: output delayed signals 76 | Return: // success: return 0 77 | Others: // none 78 | **********************************************************************************/ 79 | int dios_ssp_gsc_gscbeamsteer_process(objCGSCbeamsteer* gscbeamsteer, float **X, float **Y); 80 | 81 | /********************************************************************************** 82 | Function: // dios_ssp_gsc_gscbeamsteer_delete 83 | Description: // free the memory of doProcessing 84 | Input: // gscbeamsteer: gscbeamsteer object pointer 85 | Return: // success: return 0 86 | Others: // none 87 | **********************************************************************************/ 88 | int dios_ssp_gsc_gscbeamsteer_delete(objCGSCbeamsteer* gscbeamsteer); 89 | 90 | #endif /* _DIOS_SSP_GSC_BEAMSTEERING_H_ */ 91 | -------------------------------------------------------------------------------- /athena_signal/kernels/dios_ssp_gsc/dios_ssp_gsc_dsptools.c: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | Description: delay line in the time domain 17 | ==============================================================================*/ 18 | 19 | #include "dios_ssp_gsc_dsptools.h" 20 | 21 | void delayline(float *x, float *xdline, int dly, int line_size) 22 | { 23 | if (dly != 0) 24 | { 25 | memmove(xdline, &xdline[line_size - dly], dly * sizeof(float)); 26 | } 27 | memcpy(&xdline[dly], x, (line_size - dly) * sizeof(float)); 28 | } 29 | 30 | -------------------------------------------------------------------------------- /athena_signal/kernels/dios_ssp_gsc/dios_ssp_gsc_dsptools.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | ==============================================================================*/ 16 | 17 | #ifndef _DIOS_SSP_GSC_DSPTOOLS_H_ 18 | #define _DIOS_SSP_GSC_DSPTOOLS_H_ 19 | 20 | #include 21 | #include 22 | #include "../dios_ssp_share/dios_ssp_share_complex_defs.h" 23 | 24 | /********************************************************************************** 25 | Function: // delayline 26 | Description: // delay line in the time domain 27 | Input: // x: input signal 28 | dly: delay the input signal x by dly samples 29 | line_size: the length of the vector xdline 30 | Output: // xdline: the delayed output signal is stored in the vector xdline 31 | from xdline[0] to xdline[line_size - dly - 1] 32 | Return: // none 33 | Others: // none 34 | **********************************************************************************/ 35 | void delayline(float *x, float *xdline, int dly, int line_size); 36 | 37 | #endif /* _DIOS_SSP_GSC_DSPTOOLS_H_ */ 38 | 39 | -------------------------------------------------------------------------------- /athena_signal/kernels/dios_ssp_gsc/dios_ssp_gsc_filtsumbeamformer.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | ==============================================================================*/ 16 | 17 | #ifndef _DIOS_SSP_GSC_FILTSUMBEAMFORMER_H_ 18 | #define _DIOS_SSP_GSC_FILTSUMBEAMFORMER_H_ 19 | 20 | #include "dios_ssp_gsc_dsptools.h" 21 | #include "../dios_ssp_share/dios_ssp_share_complex_defs.h" 22 | #include "../dios_ssp_share/dios_ssp_share_rfft.h" 23 | 24 | typedef struct 25 | { 26 | int nmic; /* number of microphones */ 27 | int fftlength; /* FFT size */ 28 | int fftoverlap; /* overlap factor of FFT */ 29 | int filtord; /* filter order */ 30 | float **Xdline; /* delayline for FBF inputs in time domain */ 31 | xcomplex *xftmp; /* temporary buffer in frequency domain */ 32 | float *ytmp; /* temporary buffer in time domain */ 33 | xcomplex *yftmp; /* temporary buffer in frequency domain */ 34 | 35 | void *filt_FFT; 36 | float *fft_out; 37 | float *fft_in; 38 | 39 | }objFGSCfiltsumbeamformer; 40 | 41 | /********************************************************************************** 42 | Function: // dios_ssp_gsc_gscfiltsumbeamformer_init 43 | Description: // fixed beamformer init 44 | Input: // gscfiltsumbeamformer: fixed beamformer object pointer 45 | Output: // none 46 | Return: // success: return gscfiltsumbeamformer 47 | Others: // none 48 | **********************************************************************************/ 49 | void dios_ssp_gsc_gscfiltsumbeamformer_init(objFGSCfiltsumbeamformer* gscfiltsumbeamformer, int num_mic, int fft_size, int fft_overlap); 50 | 51 | /********************************************************************************** 52 | Function: // dios_ssp_gsc_gscfiltsumbeamformer_reset 53 | Description: // fixed beamformer reset 54 | Input: // gscfiltsumbeamformer: fixed beamformer object pointer 55 | Output: // none 56 | Return: // success: return 0 57 | Others: // none 58 | **********************************************************************************/ 59 | int dios_ssp_gsc_gscfiltsumbeamformer_reset(objFGSCfiltsumbeamformer* gscfiltsumbeamformer); 60 | 61 | /********************************************************************************** 62 | Function: // dios_ssp_gsc_gscfiltsumbeamformer_process 63 | Description: // do filter-and-sum processing 64 | Input: // X: matrix of time-domain filter input signals 65 | columns: num_mic 66 | rows: fftlength / (2 * fftoverlap) 67 | y: vector of time-domain output signal 68 | index: row index of input signal 69 | Output: // none 70 | Return: // success: return 0 71 | Others: // none 72 | **********************************************************************************/ 73 | int dios_ssp_gsc_gscfiltsumbeamformer_process(objFGSCfiltsumbeamformer* gscfiltsumbeamformer, float **X, float *y, int index); 74 | 75 | /********************************************************************************** 76 | Function: // dios_ssp_gsc_gscfiltsumbeamformer_delete 77 | Description: // fixed beamformer delete 78 | Input: // gscfiltsumbeamformer: fixed beamformer object pointer 79 | Output: // none 80 | Return: // success: return 0 81 | Others: // none 82 | **********************************************************************************/ 83 | int dios_ssp_gsc_gscfiltsumbeamformer_delete(objFGSCfiltsumbeamformer* gscfiltsumbeamformer); 84 | 85 | #endif /* _DIOS_SSP_GSC_FILTSUMBEAMFORMER_H_ */ 86 | 87 | -------------------------------------------------------------------------------- /athena_signal/kernels/dios_ssp_gsc/dios_ssp_gsc_firfilterdesign.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | ==============================================================================*/ 16 | 17 | #ifndef _DIOS_SSP_GSC_FIRFILTERDESIGN_H_ 18 | #define _DIOS_SSP_GSC_FIRFILTERDESIGN_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | #include "dios_ssp_gsc_globaldefs.h" 24 | #include "../dios_ssp_share/dios_ssp_share_complex_defs.h" 25 | #include "../dios_ssp_share/dios_ssp_share_rfft.h" 26 | 27 | typedef struct 28 | { 29 | int m_nFIRLen; 30 | int m_nFFTLen; 31 | int m_nFFTOrder; 32 | int m_nCSize; 33 | 34 | float *m_pTapsBuf; 35 | xcomplex *m_pTapsFreq; 36 | float *m_mag; 37 | float *m_phase; 38 | float *m_win; 39 | 40 | void *gengralfir_FFT; 41 | float *fft_out; 42 | float *fft_in; 43 | 44 | }objCGeneralFIRDesigner; 45 | 46 | /********************************************************************************** 47 | Function: // dios_ssp_gscfirfilterdesign_init 48 | Description: // fir filter design init 49 | Input: // generalfirdesign: generalfirdesign object pointer 50 | Output: // none 51 | Return: // success: return generalfirdesign object pointer 52 | Others: // none 53 | **********************************************************************************/ 54 | void dios_ssp_gscfirfilterdesign_init(objCGeneralFIRDesigner *generalfirdesign, int len, General_WindowType winType); 55 | 56 | /********************************************************************************** 57 | Function: // dios_ssp_gscfirfilterdesign_fractionaldelay 58 | Description: // do FIR filtering directly, not using FIRState struct 59 | Input: // pIn: input signal 60 | dwBaseSize: length of input signal 61 | FIRTaps: FIR filter 62 | dwFIRTaps: length of FIR filter 63 | pDlyLine: signal data buffer including old and new samples 64 | DlyLineIndex: the beginning or endding position 65 | Output: // pOut: filtered output signal 66 | Return: // success: return 0 67 | Others: // none 68 | **********************************************************************************/ 69 | int dios_ssp_gscfirfilterdesign_fractionaldelay(objCGeneralFIRDesigner *generalfirdesign, float fcLow, float fcHigh, float delay, float *pTaps); 70 | 71 | /********************************************************************************** 72 | Function: // dios_ssp_gscfirfilterdesign_delete 73 | Description: // fir filter design delete 74 | Input: // generalfirdesign: generalfirdesign object pointer 75 | Output: // none 76 | Return: // success: return 0 77 | Others: // none 78 | **********************************************************************************/ 79 | int dios_ssp_gscfirfilterdesign_delete(objCGeneralFIRDesigner *generalfirdesign); 80 | 81 | #endif /* _DIOS_SSP_GSC_FIRFILTERDESIGN_H_ */ 82 | -------------------------------------------------------------------------------- /athena_signal/kernels/dios_ssp_gsc/dios_ssp_gsc_globaldefs.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | ==============================================================================*/ 16 | 17 | #ifndef _DIOS_SSP_GSC_GLOBALDEFS_H_ 18 | #define _DIOS_SSP_GSC_GLOBALDEFS_H_ 19 | 20 | #include 21 | 22 | #define S_OK ((long)0L) 23 | #define S_FALSE ((long)1L) 24 | #define FALSE false 25 | #define TRUE true 26 | #define ABS(TMP) (((TMP) < 0) ? -(TMP) : (TMP)) 27 | #define SIGN(TMP) (((TMP) < 0) ? -1 : 1) 28 | #define SQUARE(TMP) ((TMP)*(TMP)) 29 | 30 | #define DECLARE_HANDLE(name) struct name##__{int unused;}; typedef struct name##__ *name 31 | 32 | #ifndef EPSILON 33 | #define EPSILON 1e-5 34 | #endif 35 | 36 | typedef unsigned short WORD; 37 | typedef unsigned long DWORD; 38 | 39 | typedef enum 40 | { 41 | General_ArrayEquiSpacingLine, /* Equi-spacing line */ 42 | General_ArraySymmetricLine, /* Symmetric line */ 43 | General_ArrayLShape, /* L shape */ 44 | General_ArrayArbitrary, /* Arbitrary shape*/ 45 | } General_ArrayGeometric; 46 | 47 | /* struct GSCFDAF: structure with parameters for the gsc frequency-domain adaptive filters */ 48 | typedef struct GSCFDAF 49 | { 50 | int fftlength; /* Length of the FFT */ 51 | int fftoverlap; /* Overlap of input signal segments 52 | = max(ABMPARAMETERS.overlap, AICPARAMETERS.overlap) */ 53 | float delta_con; /* Threshold for static regularization */ 54 | float delta_dyn; /* Threshold for dynamic regularization */ 55 | float s0_dyn; /* 'Lobe' parameter of the dynamic regularization */ 56 | int regularize_dyn; /* Use dynamic regularization */ 57 | } GSCFDAF; 58 | 59 | /* struct ADAPTCTRL: structure with parameters for the adaptation control */ 60 | typedef struct ADAPTCTRL 61 | { 62 | int fmin; /* Minimum frequency for averaging the SNR estimate */ 63 | int fmax; /* Maximum frequency for averaging the SNR estimate */ 64 | int fc; /* Transition frequency for adaptation control in discrete frequency bins and averaged */ 65 | float ctabm; /* Correction factor for the vector of frequency-dependent abm thresholds */ 66 | float ctaic; /* Correction factor for the vector of frequency-dependent aic thresholds */ 67 | int U; /* number_sub_windows_for_minimum_statistics 8 */ 68 | int V; /* size_sub_windows_for_minimum_statistics 18 */ 69 | float lambda_max; /* upper_limit_forgetting_factor_minimum_statistics 0.96 */ 70 | float lambda_min; /* lower_limit_forgetting_factor_minimum_statistics 0.25 */ 71 | float corr_bias; /* correction_bias_for_minimum_statistics 2.12 */ 72 | } ADAPTCTRL; 73 | 74 | /* struct ABMPARAMETERS: structure with parameters for the adaptive blocking matrix */ 75 | typedef struct ABMPARAMETERS 76 | { 77 | float mu; /* Stepsize for the adaptation algorithm */ 78 | int ntaps; /* Number of filter taps for each adaptive filter */ 79 | int fftoverlap; /* Overlap factor of the FFT */ 80 | float lambda; /* Forgetting factor for recursive power estimation */ 81 | float tconstfreeze; /* Time constant which prevents freezing of adaptive filters (in seconds) */ 82 | } ABMPARAMETERS; 83 | 84 | /* struct AICPARAMETERS: structure with parameters for the adaptive interference canceller */ 85 | typedef struct AICPARAMETERS 86 | { 87 | float mu; /* Stepsize for the adaptation algorithm */ 88 | int ntaps; /* Number of filter taps for each adaptive filter */ 89 | int fftoverlap; /* Overlap factor of the FFT */ 90 | float lambda; /* Forgetting factor for recursive power estimation */ 91 | float maxnorm; /* Maximally allowed filter norm, against desired signal cancellation */ 92 | float tconstfreeze; /* Time constant which prevents freezing of adaptive filters (in seconds) */ 93 | } AICPARAMETERS; 94 | 95 | /* struct SYNCDELAYS: structure with delays for synchronization of the FGSC modules */ 96 | typedef struct SYNCDELAYS 97 | { 98 | int nDelayAIC; /* Sync delay for aic filter inputs */ 99 | int nDelayABM; /* Sync delay for abm filter input */ 100 | int nDelayAcRef; /* Sync delay for ac reference microphone */ 101 | int nDelayAEC; /* Sync delay for saec filter inputs */ 102 | } SYNCDELAYS; 103 | 104 | typedef enum 105 | { 106 | General_WinRect, /* no smoothing (rectangular window) */ 107 | General_WinBlackman, /* smoothing by optimal Blackman window */ 108 | General_WinHamming, /* smoothing by Hamming window */ 109 | General_WinHanning, /* smoothing by Hanning window */ 110 | } General_WindowType; 111 | 112 | #endif /* _DIOS_SSP_GSC_GLOBALDEFS_H_ */ 113 | -------------------------------------------------------------------------------- /athena_signal/kernels/dios_ssp_gsc/dios_ssp_gsc_micarray.c: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | Description: GSC beamforming includes two functions, steering vector and 17 | processing function. 18 | ==============================================================================*/ 19 | 20 | #include "dios_ssp_gsc_micarray.h" 21 | 22 | static const int gsc_sampling_rate = 16000; /* sampling rate */ 23 | static const int gsc_block_len = 128; /* frame len */ 24 | 25 | void dios_ssp_gsc_init(objGSCProcess *ptr_gsc, int mic_num, PlaneCoord* mic_coord) 26 | { 27 | /* parameter initialization */ 28 | ptr_gsc->nfs = gsc_sampling_rate; 29 | ptr_gsc->frame_len = gsc_block_len; 30 | ptr_gsc->mic_num = mic_num; 31 | ptr_gsc->outbeam_num = 1; 32 | ptr_gsc->loca_use_flag = 1; 33 | ptr_gsc->type = General_ArrayArbitrary; 34 | ptr_gsc->source_location.rho = 4.0f; 35 | ptr_gsc->source_location.theta = 0.0f; 36 | ptr_gsc->source_location.phi = 0.0f; 37 | ptr_gsc->ptr_input_data_float = (float**)calloc(ptr_gsc->mic_num, sizeof(float*)); 38 | for (int i_mic = 0; i_mic < ptr_gsc->mic_num; i_mic++) 39 | { 40 | ptr_gsc->ptr_input_data_float[i_mic] = (float*)calloc(ptr_gsc->frame_len, sizeof(float)); 41 | } 42 | 43 | /* input parameter and signal buffer init */ 44 | ptr_gsc->ptr_mic_coord = (PlaneCoord*)calloc(mic_num, sizeof(PlaneCoord)); 45 | for (int i = 0; i < mic_num; i++) 46 | { 47 | ptr_gsc->ptr_mic_coord[i].x = mic_coord[i].x; 48 | ptr_gsc->ptr_mic_coord[i].y = mic_coord[i].y; 49 | ptr_gsc->ptr_mic_coord[i].z = mic_coord[i].z; 50 | } 51 | 52 | /* output signal buffer init */ 53 | ptr_gsc->ptr_output_data_float = (float*)calloc(ptr_gsc->frame_len, sizeof(float)); 54 | ptr_gsc->ptr_output_data_short = (short*)calloc(ptr_gsc->frame_len, sizeof(short)); 55 | 56 | ptr_gsc->multigscbeamformer = (objCMultiGSCbeamformer*)calloc(1, sizeof(objCMultiGSCbeamformer)); 57 | dios_ssp_gsc_multibeamformer_init(ptr_gsc->multigscbeamformer, ptr_gsc->mic_num, ptr_gsc->outbeam_num, ptr_gsc->nfs, ptr_gsc->frame_len, ptr_gsc->type, ptr_gsc->ptr_mic_coord); 58 | 59 | } 60 | 61 | void dios_ssp_gsc_reset(objGSCProcess *ptr_gsc) 62 | { 63 | dios_ssp_gsc_multibeamformer_reset(ptr_gsc->multigscbeamformer); 64 | } 65 | 66 | void doProcess(objGSCProcess *ptr_gsc) 67 | { 68 | dios_ssp_gsc_multibeamformer_arraysteer(ptr_gsc->multigscbeamformer, &(ptr_gsc->source_location)); 69 | dios_ssp_gsc_multibeamformer_process(ptr_gsc->multigscbeamformer, ptr_gsc->ptr_input_data_float); 70 | float** gsc_bfout = ptr_gsc->multigscbeamformer->m_pOutput; 71 | memcpy(ptr_gsc->ptr_output_data_float, gsc_bfout[0], ptr_gsc->frame_len * sizeof(float)); 72 | } 73 | 74 | void dios_ssp_gsc_delete(objGSCProcess *ptr_gsc) 75 | { 76 | free((void*)ptr_gsc->ptr_mic_coord); 77 | free((void*)ptr_gsc->ptr_output_data_short); 78 | free((void*)ptr_gsc->ptr_output_data_float); 79 | for (int i_mic = 0; i_mic < ptr_gsc->mic_num; i_mic++) 80 | { 81 | free(ptr_gsc->ptr_input_data_float[i_mic]); 82 | } 83 | free(ptr_gsc->ptr_input_data_float); 84 | 85 | if(ptr_gsc->multigscbeamformer != NULL) 86 | { 87 | dios_ssp_gsc_multibeamformer_delete(ptr_gsc->multigscbeamformer); 88 | } 89 | free(ptr_gsc->multigscbeamformer); 90 | 91 | } 92 | -------------------------------------------------------------------------------- /athena_signal/kernels/dios_ssp_gsc/dios_ssp_gsc_micarray.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | ==============================================================================*/ 16 | 17 | #ifndef _DIOS_SSP_GSC_MICARRAY_H_ 18 | #define _DIOS_SSP_GSC_MICARRAY_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include "dios_ssp_gsc_beamformer.h" 25 | #include "dios_ssp_gsc_globaldefs.h" 26 | #include "dios_ssp_gsc_multigscbeamformer.h" 27 | 28 | typedef struct 29 | { 30 | int nfs; 31 | int frame_len; 32 | int mic_num; 33 | int outbeam_num; 34 | int loca_use_flag; 35 | float wakeup_loca; 36 | PlaneCoord* ptr_mic_coord; 37 | 38 | /* input parameter and signal */ 39 | PolarCoord source_location; 40 | float** ptr_input_data_float; 41 | 42 | /* output signal */ 43 | short* ptr_output_data_short; 44 | float* ptr_output_data_float; 45 | 46 | General_ArrayGeometric type; 47 | objCMultiGSCbeamformer *multigscbeamformer; 48 | 49 | }objGSCProcess; 50 | 51 | /********************************************************************************** 52 | Function: // dios_ssp_gsc_init 53 | Description: // gsc init 54 | Input: // mic_num: microphone number 55 | mic_coord: each microphone coordinate (PlaneCoord*)mic_coord 56 | Output: // none 57 | Return: // success: return gsc object pointer (void*)ptr_gsc 58 | failure: return NULL 59 | Others: // none 60 | **********************************************************************************/ 61 | void dios_ssp_gsc_init(objGSCProcess *ptr_gsc, int mic_num, PlaneCoord* mic_coord); 62 | 63 | /********************************************************************************** 64 | Function: // dios_ssp_gsc_reset 65 | Description: // gsc reset 66 | Input: // ptr: gsc object pointer 67 | Output: // none 68 | Return: // success: return gsc object pointer (void*)ptr_gsc 69 | Others: // none 70 | **********************************************************************************/ 71 | void dios_ssp_gsc_reset(objGSCProcess *ptr_gsc); 72 | 73 | /********************************************************************************** 74 | Function: // doProcess 75 | Description: // gsc process 76 | Input: // ptr: gsc object pointer 77 | Return: // success: return gsc object pointer (void*)ptr_gsc 78 | Others: // none 79 | **********************************************************************************/ 80 | void doProcess(objGSCProcess *ptr_gsc); 81 | 82 | /********************************************************************************** 83 | Function: // dios_ssp_gsc_delete 84 | Description: // gsc delete 85 | Input: // ptr: gsc object pointer 86 | Output: // none 87 | Return: // success: return gsc object pointer (void*)ptr_gsc 88 | Others: // none 89 | **********************************************************************************/ 90 | void dios_ssp_gsc_delete(objGSCProcess *ptr_gsc); 91 | 92 | #endif /* _DIOS_SSP_GSC_MICARRAY_H_ */ 93 | -------------------------------------------------------------------------------- /athena_signal/kernels/dios_ssp_gsc/dios_ssp_gsc_multigscbeamformer.c: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | Description: GSC beamforming includes two functions, steering vector and 17 | processing function. 18 | ==============================================================================*/ 19 | 20 | #include "dios_ssp_gsc_multigscbeamformer.h" 21 | 22 | void dios_ssp_gsc_multibeamformer_init(objCMultiGSCbeamformer* multigscbeamformer, DWORD nMic, DWORD nBeam, DWORD dwSampRate, DWORD dwBlockSize, General_ArrayGeometric type, void *coord) 23 | { 24 | multigscbeamformer->gscbeamformer = (objCGSCbeamformer*)calloc(1, sizeof(objCGSCbeamformer)); 25 | dios_ssp_gsc_gscbeamformer_init(multigscbeamformer->gscbeamformer, nMic, dwSampRate, dwBlockSize, type, coord); 26 | 27 | multigscbeamformer->m_pOutput = NULL; 28 | multigscbeamformer->m_nBeam = nBeam; 29 | multigscbeamformer->m_pOutput = (float**)calloc(multigscbeamformer->m_nBeam, sizeof(float*)); 30 | } 31 | 32 | int dios_ssp_gsc_multibeamformer_reset(objCMultiGSCbeamformer* multigscbeamformer) 33 | { 34 | dios_ssp_gsc_gscbeamformer_reset(multigscbeamformer->gscbeamformer); 35 | for(DWORD bch = 0; bch < multigscbeamformer->m_nBeam; bch++) 36 | { 37 | multigscbeamformer->m_pOutput[bch] = multigscbeamformer->gscbeamformer->m_output; 38 | } 39 | 40 | return 0; 41 | } 42 | 43 | int dios_ssp_gsc_multibeamformer_arraysteer(objCMultiGSCbeamformer* multigscbeamformer, PolarCoord *pSrcLoc) 44 | { 45 | for (DWORD bch = 0; bch < multigscbeamformer->m_nBeam; bch++) 46 | { 47 | dios_ssp_gsc_gscbeamformer_arraysteer(multigscbeamformer->gscbeamformer, pSrcLoc[bch]); 48 | } 49 | return 0; 50 | } 51 | 52 | int dios_ssp_gsc_multibeamformer_process(objCMultiGSCbeamformer* multigscbeamformer, float** ppInput) 53 | { 54 | for (DWORD bch = 0; bch < multigscbeamformer->m_nBeam; bch++) 55 | { 56 | dios_ssp_gsc_gscbeamformer_process(multigscbeamformer->gscbeamformer, ppInput); 57 | } 58 | return 0; 59 | } 60 | 61 | int dios_ssp_gsc_multibeamformer_delete(objCMultiGSCbeamformer* multigscbeamformer) 62 | { 63 | dios_ssp_gsc_gscbeamformer_delete(multigscbeamformer->gscbeamformer); 64 | free(multigscbeamformer->gscbeamformer); 65 | free(multigscbeamformer->m_pOutput); 66 | 67 | return 0; 68 | } 69 | -------------------------------------------------------------------------------- /athena_signal/kernels/dios_ssp_gsc/dios_ssp_gsc_multigscbeamformer.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | ==============================================================================*/ 16 | 17 | #ifndef _DIOS_SSP_GSC_MULTIGSCBEAMFORMER_H_ 18 | #define _DIOS_SSP_GSC_MULTIGSCBEAMFORMER_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | #include "dios_ssp_gsc_globaldefs.h" 24 | #include "dios_ssp_gsc_beamformer.h" 25 | #include "dios_ssp_gsc_dsptools.h" 26 | #include "dios_ssp_gsc_beamsteering.h" 27 | #include "dios_ssp_gsc_filtsumbeamformer.h" 28 | #include "dios_ssp_gsc_abm.h" 29 | #include "dios_ssp_gsc_aic.h" 30 | #include "dios_ssp_gsc_adaptctrl.h" 31 | #include "../dios_ssp_share/dios_ssp_share_typedefs.h" 32 | 33 | typedef struct 34 | { 35 | DWORD m_nBeam; 36 | float **m_pOutput; 37 | objCGSCbeamformer *gscbeamformer; 38 | 39 | }objCMultiGSCbeamformer; 40 | 41 | /********************************************************************************** 42 | Function: // dios_ssp_gsc_multibeamformer_init 43 | Description: // multibeamformer init 44 | Input: // multigscbeamformer: multigscbeamformer object pointer 45 | nMic: microphone number 46 | mic_coord: each microphone coordinate (PlaneCoord*)mic_coord 47 | Output: // none 48 | Return: // success: return multigscbeamformer object pointer 49 | Others: // none 50 | **********************************************************************************/ 51 | void dios_ssp_gsc_multibeamformer_init(objCMultiGSCbeamformer* multigscbeamformer, DWORD nMic, DWORD nBeam, DWORD dwSampRate, DWORD dwBlockSize, General_ArrayGeometric type, void *coord); 52 | 53 | /********************************************************************************** 54 | Function: // dios_ssp_gsc_multibeamformer_reset 55 | Description: // multibeamformer reset 56 | Input: // multigscbeamformer: multigscbeamformer object pointer 57 | Output: // none 58 | Return: // success: return 0 59 | Others: // none 60 | **********************************************************************************/ 61 | int dios_ssp_gsc_multibeamformer_reset(objCMultiGSCbeamformer* multigscbeamformer); 62 | 63 | /********************************************************************************** 64 | Function: // dios_ssp_gsc_multibeamformer_arraysteer 65 | Description: // multibeamformer steering 66 | Input: // prototype: pSrcLoc, polar coordinates of source locations 67 | Output: // none 68 | Return: // success: return 0 69 | Others: // none 70 | **********************************************************************************/ 71 | int dios_ssp_gsc_multibeamformer_arraysteer(objCMultiGSCbeamformer* multigscbeamformer, PolarCoord *pSrcLoc); 72 | 73 | /********************************************************************************** 74 | Function: // dios_ssp_gsc_multibeamformer_process 75 | Description: // process data of one block 76 | Input: // prototype: pInput, float data, multi-channel, continuous memory 77 | Output: // none 78 | Return: // success: return 0 79 | Others: // none 80 | **********************************************************************************/ 81 | int dios_ssp_gsc_multibeamformer_process(objCMultiGSCbeamformer* multigscbeamformer, float** ppInput); 82 | 83 | /********************************************************************************** 84 | Function: // dios_ssp_gsc_multibeamformer_delete 85 | Description: // multibeamformer delete 86 | Input: // multigscbeamformer: multigscbeamformer object pointer 87 | Output: // none 88 | Return: // success: return 0 89 | Others: // none 90 | **********************************************************************************/ 91 | int dios_ssp_gsc_multibeamformer_delete(objCMultiGSCbeamformer* multigscbeamformer); 92 | 93 | #endif /* _DIOS_SSP_GSC_MULTIGSCBEAMFORMER_H_ */ 94 | -------------------------------------------------------------------------------- /athena_signal/kernels/dios_ssp_hpf/dios_ssp_hpf_api.c: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | Description: High-pass filtering is implemented using cascaded-iir-filter. 17 | The cut-off frequency is 200Hz in this program. You can rewrite the iir filter 18 | coefficients and gains, with the help of filter design toolbox in MATLAB, 19 | to generate high-pass filter with cut-off frequency you set. 20 | ==============================================================================*/ 21 | 22 | #include "dios_ssp_hpf_api.h" 23 | 24 | #define SECTION_NUM 2 25 | 26 | // struct of filter coefficients 27 | typedef struct 28 | { 29 | // register 30 | float reg_x1[SECTION_NUM]; 31 | float reg_x2[SECTION_NUM]; 32 | float reg_y1[SECTION_NUM]; 33 | float reg_y2[SECTION_NUM]; 34 | // filter coefficients 35 | float num_0[SECTION_NUM]; 36 | float num_1[SECTION_NUM]; 37 | float num_2[SECTION_NUM]; // numerator 38 | float den_0[SECTION_NUM]; 39 | float den_1[SECTION_NUM]; 40 | float den_2[SECTION_NUM]; // denominator 41 | // gain 42 | float hpf_gain[SECTION_NUM]; 43 | } objHPF; 44 | 45 | // High-pass filtering real implementation 46 | float hpf_calc(objHPF *srv, float x) 47 | { 48 | float y = 0; 49 | float center_tap = 0; 50 | int section; 51 | 52 | for(section = 0; section < SECTION_NUM; section++) 53 | { 54 | center_tap = x * srv->num_0[section] + srv->num_1[section] * srv->reg_x1[section] 55 | + srv->num_2[section] * srv->reg_x2[section]; 56 | y = srv->den_0[section] * center_tap - srv->den_1[section] * srv->reg_y1[section] 57 | - srv->den_2[section] * srv->reg_y2[section]; 58 | 59 | srv->reg_x2[section] = srv->reg_x1[section]; 60 | srv->reg_x1[section] = x; 61 | srv->reg_y2[section] = srv->reg_y1[section]; 62 | srv->reg_y1[section] = y; 63 | 64 | y *= srv->hpf_gain[section]; 65 | x = y; 66 | 67 | } 68 | return y; 69 | } 70 | 71 | void* dios_ssp_hpf_init_api(void) 72 | { 73 | void* ptr = NULL; 74 | objHPF *srv; 75 | ptr = (void*)calloc(1, sizeof(objHPF)); 76 | srv = (objHPF *)ptr; 77 | int i; 78 | 79 | for(i = 0; i < SECTION_NUM; i++) 80 | { 81 | srv->reg_x1[i] = 0.0; 82 | srv->reg_x2[i] = 0.0; 83 | srv->reg_y1[i] = 0.0; 84 | srv->reg_y2[i] = 0.0; 85 | } 86 | 87 | srv->num_0[0] = 1.0f; 88 | srv->num_1[0] = -2.0f; 89 | srv->num_2[0] = 1.0f; 90 | srv->den_0[0] = 1.0f; 91 | srv->den_1[0] = -1.9467f; 92 | srv->den_2[0] = 0.9509f; 93 | srv->hpf_gain[0] = 0.9744f; 94 | srv->num_0[1] = 1.0f; 95 | srv->num_1[1] = -2.0f; 96 | srv->num_2[1] = 1.0f; 97 | srv->den_0[1] = 1.0f; 98 | srv->den_1[1] = -1.8814f; 99 | srv->den_2[1] = 0.8855f; 100 | srv->hpf_gain[1] = 0.9417f; 101 | 102 | return ptr; 103 | } 104 | 105 | int dios_ssp_hpf_reset_api(void* ptr) 106 | { 107 | if (NULL == ptr) 108 | { 109 | return -1; 110 | } 111 | objHPF *srv; 112 | srv = (objHPF *) ptr; 113 | int i; 114 | 115 | for(i = 0; i < SECTION_NUM; i++) 116 | { 117 | srv->reg_x1[i] = 0.0; 118 | srv->reg_x2[i] = 0.0; 119 | srv->reg_y1[i] = 0.0; 120 | srv->reg_y2[i] = 0.0; 121 | } 122 | 123 | return 0; 124 | } 125 | 126 | int dios_ssp_hpf_process_api(void* ptr, float* io_buf, int siglen) 127 | { 128 | if (NULL == ptr) 129 | { 130 | return -1; 131 | } 132 | objHPF *srv; 133 | int j = 0; 134 | 135 | srv = (objHPF *)ptr; 136 | for (j = 0; j < siglen; j++) 137 | { 138 | io_buf[j] = hpf_calc(srv, io_buf[j]); 139 | } 140 | return 0; 141 | } 142 | 143 | int dios_ssp_hpf_uninit_api(void* ptr) 144 | { 145 | if (NULL == ptr) 146 | { 147 | return -1; 148 | } 149 | objHPF *srv; 150 | srv = (objHPF *) ptr; 151 | free(srv); 152 | return 0; 153 | } 154 | 155 | -------------------------------------------------------------------------------- /athena_signal/kernels/dios_ssp_hpf/dios_ssp_hpf_api.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | ==============================================================================*/ 16 | 17 | #ifndef _DIOS_SSP_HPF_API_H_ 18 | #define _DIOS_SSP_HPF_API_H_ 19 | 20 | #include 21 | 22 | /********************************************************************************** 23 | Function: // dios_ssp_hpf_init_api 24 | Description: // init hpf module 25 | Input: // none 26 | Output: // none 27 | Return: // success: return hpf module pointer 28 | failure: return NULL 29 | **********************************************************************************/ 30 | void* dios_ssp_hpf_init_api(void); 31 | 32 | /********************************************************************************** 33 | Function: // dios_ssp_hpf_reset_api 34 | Description: // reset hpf module 35 | Input: // ptr: hpf module pointer 36 | Output: // none 37 | Return: // success: return 0, failure: return ERROR_HPF 38 | **********************************************************************************/ 39 | int dios_ssp_hpf_reset_api(void* ptr); 40 | 41 | /********************************************************************************** 42 | Function: // dios_ssp_hpf_process_api 43 | Description: // hpf process 44 | Input: // ptr: hpf module pointer 45 | io_buf: input and output buffer 46 | siglen: input signal length 47 | Output: // none 48 | Return: // success: return 0, failure: return ERROR_HPF 49 | **********************************************************************************/ 50 | int dios_ssp_hpf_process_api(void* ptr, float* io_buf, int siglen); 51 | 52 | /********************************************************************************** 53 | Function: // dios_ssp_hpf_uninit_api 54 | Description: // free hpf module 55 | Input: // ptr: hpf module pointer 56 | Output: // none 57 | Return: // success: return 0, failure: return ERROR_HPF 58 | **********************************************************************************/ 59 | int dios_ssp_hpf_uninit_api(void* ptr); 60 | 61 | #endif /* _DIOS_SSP_HPF_API_H_ */ 62 | 63 | -------------------------------------------------------------------------------- /athena_signal/kernels/dios_ssp_mvdr/dios_ssp_mvdr_api.c: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | Description: This is a Minimum Variance Distortionless Response beamformer. 17 | When the DOA module is disabled, you can set the steering vector(loc_phi) by 18 | yourself, which indicates the distortionless response direction. 19 | When the DOA module is enabled, the steering vector will be estimated by DOA 20 | estimation. You can set the steering vector by your own DOA estimation method. 21 | Rnn matrix is estimated using MCRA noise estimation method. 22 | Microphone array could be any shape as long as you set the coordinates of each 23 | microphones(mic_coord) beforehand. 24 | ==============================================================================*/ 25 | 26 | #include "dios_ssp_mvdr_api.h" 27 | 28 | void* dios_ssp_mvdr_init_api(int mic_num, void* mic_coord) 29 | { 30 | void* st = NULL; 31 | st = (void*)calloc(1, sizeof(objMVDR)); 32 | objMVDR* ptr = (objMVDR*)st; 33 | dios_ssp_mvdr_init(ptr, mic_num, (PlaneCoord*)mic_coord); 34 | 35 | return st; 36 | } 37 | 38 | int dios_ssp_mvdr_reset_api(void *ptr) 39 | { 40 | if(ptr == NULL) 41 | { 42 | printf("mvdr handle not init!\n"); 43 | return ERROR_MVDR; 44 | } 45 | 46 | objMVDR* ptr_mvdr; 47 | ptr_mvdr = (objMVDR*)ptr; 48 | dios_ssp_mvdr_reset(ptr_mvdr); 49 | 50 | return 0; 51 | } 52 | 53 | int dios_ssp_mvdr_process_api(void* ptr, float* mic_data, float* out_data, float loc_phi) 54 | { 55 | int angle; 56 | angle = (int)(loc_phi + 0.5); 57 | objMVDR *ptr_mvdr; 58 | ptr_mvdr= (objMVDR*)ptr; 59 | dios_ssp_mvdr_process(ptr_mvdr, mic_data, out_data, angle); 60 | 61 | return 0; 62 | } 63 | 64 | int dios_ssp_mvdr_uninit_api(void *ptr) 65 | { 66 | objMVDR *ptr_mvdr; 67 | ptr_mvdr= (objMVDR*)ptr; 68 | dios_ssp_mvdr_delete(ptr_mvdr); 69 | 70 | return 0; 71 | } 72 | -------------------------------------------------------------------------------- /athena_signal/kernels/dios_ssp_mvdr/dios_ssp_mvdr_api.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | ==============================================================================*/ 16 | 17 | #ifndef _DIOS_SSP_MVDR_API_H_ 18 | #define _DIOS_SSP_MVDR_API_H_ 19 | 20 | #include "../dios_ssp_return_defs.h" 21 | #include "dios_ssp_mvdr_header.h" 22 | 23 | /********************************************************************************** 24 | Function: // dios_ssp_mvdr_init_api 25 | Description: // mvdr init 26 | Input: // mic_num: microphone number 27 | mic_coord: each microphone coordinate (PlaneCoord*)mic_coord 28 | Output: // none 29 | Return: // success: return mvdr object pointer (void*)ptr_mvdr 30 | failure: return NULL 31 | **********************************************************************************/ 32 | void* dios_ssp_mvdr_init_api(int mic_num, void* mic_coord); 33 | 34 | /********************************************************************************** 35 | Function: // dios_ssp_mvdr_reset_api 36 | Description: // mvdr reset 37 | Input: // ptr: mvdr object pointer 38 | Output: // none 39 | Return: // success: return 0, failure: return ERROR_MVDR 40 | **********************************************************************************/ 41 | int dios_ssp_mvdr_reset_api(void *ptr); 42 | 43 | /********************************************************************************** 44 | Function: // dios_ssp_mvdr_process_api 45 | Description: // mvdr process 46 | Input: // ptr: mvdr object pointer 47 | mic_data: mvdr input data, data type is float 48 | loc_phi: direction of wakeup 49 | Output: // out_data: mvdr output signal 50 | Return: // success: return 0, failure: return ERROR_MVDR 51 | **********************************************************************************/ 52 | int dios_ssp_mvdr_process_api(void* ptr, float* mic_data, float* out_data, float loc_phi); 53 | 54 | /********************************************************************************** 55 | Function: // dios_ssp_mvdr_uninit_api 56 | Description: // mvdr delete 57 | Input: // ptr: mvdr object pointer 58 | Output: // none 59 | Return: // success: return 0, failure: return ERROR_MVDR 60 | **********************************************************************************/ 61 | int dios_ssp_mvdr_uninit_api(void *ptr); 62 | 63 | #endif /* _DIOS_SSP_MVDR_API_H_ */ 64 | 65 | 66 | -------------------------------------------------------------------------------- /athena_signal/kernels/dios_ssp_mvdr/dios_ssp_mvdr_cinv.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | ==============================================================================*/ 16 | 17 | #ifndef _DIOS_SSP_MVDR_CINV_H_ 18 | #define _DIOS_SSP_MVDR_CINV_H_ 19 | 20 | #include 21 | #include 22 | 23 | typedef struct 24 | { 25 | int dim; 26 | float **ar; 27 | float **ai; 28 | float **mat_temp; 29 | float **mat_temp2; 30 | }objMVDRCinv; 31 | 32 | void dios_ssp_mvdr_inv_init(objMVDRCinv *mvdrinv, int Rdim); 33 | int dios_ssp_mvdr_inv_process(objMVDRCinv *mvdrinv, float *R, float *Rinv); 34 | int dios_ssp_mvdr_inv_delete(objMVDRCinv *mvdrinv); 35 | 36 | #endif /* _DIOS_SSP_MVDR_CINV_H_ */ 37 | 38 | -------------------------------------------------------------------------------- /athena_signal/kernels/dios_ssp_mvdr/dios_ssp_mvdr_macros.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | ==============================================================================*/ 16 | 17 | #ifndef _DIOS_SSP_MVDR_MACROS_H_ 18 | #define _DIOS_SSP_MVDR_MACROS_H_ 19 | 20 | #define VELOCITY (340.0f) 21 | #define PI (3.141592653589793f) 22 | #define DEFAULT_MVDR_SAMPLING_FRQ 16000 23 | #define DEFAULT_MVDR_WIN_SIZE 512 24 | #define DEFAULT_MVDR_SHIFT_SIZE 128 25 | #define DEFAULT_MVDR_DELTA_ANGLE 5 26 | #define DEFAULT_MVDR_SD_FACTOR (0.01f) 27 | #define DEFAULT_MVDR_SD_EPS (0.000001f) 28 | #define DEFAULT_MVDR_RNN_EPS 100 29 | #define DEFAULT_MVDR_ALPHA_RNN (0.99f) 30 | #define DEFAULT_MVDR_ALPHA_S (0.8f) 31 | #define DEFAULT_MVDR_ALPHA_P (0.2f) 32 | #define DEFAULT_MVDR_ALPHA_D (0.95f) 33 | #define DEFAULT_MVDR_L 50 34 | #define DEFAULT_MVDR_DELTA_THRES 1.5 35 | 36 | #endif /* _DIOS_SSP_MVDR_MACROS_H_ */ 37 | 38 | -------------------------------------------------------------------------------- /athena_signal/kernels/dios_ssp_mvdr/dios_ssp_mvdr_win.c: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | Description: Analysis window and synthesis window of MVDR 17 | ==============================================================================*/ 18 | 19 | #include "dios_ssp_mvdr_win.h" 20 | 21 | void dios_ssp_mvdr_win_init(objMVDRCwin *mvdrwin,int fft_size, int shift_size) 22 | { 23 | int i, j; 24 | int tmp; 25 | int log_fft_size = 0; 26 | float temp; 27 | tmp = 1; 28 | 29 | mvdrwin->m_fft_size = fft_size; 30 | mvdrwin->m_shift_size = shift_size; 31 | 32 | if ( mvdrwin->m_shift_size >= mvdrwin->m_fft_size ) 33 | { 34 | printf( "shift_size[%d] >= fft_size[%d].\n", mvdrwin->m_shift_size, mvdrwin->m_fft_size ); 35 | } 36 | 37 | while ( tmp < mvdrwin->m_fft_size ) 38 | { 39 | log_fft_size += 1; 40 | tmp *= 2; 41 | } 42 | if ( tmp > mvdrwin->m_fft_size ) 43 | { 44 | printf( "FFT Size[%d] should be power of 2.\n", mvdrwin->m_fft_size ); 45 | } 46 | tmp = 1; 47 | while ( tmp < mvdrwin->m_shift_size ) 48 | { 49 | tmp *= 2; 50 | } 51 | if ( tmp > mvdrwin->m_shift_size ) 52 | { 53 | printf( "Shift Size[%d] should be power of 2.\n", mvdrwin->m_shift_size ); 54 | } 55 | 56 | mvdrwin->m_block_num = mvdrwin->m_fft_size / mvdrwin->m_shift_size; 57 | mvdrwin->m_ana_win = (float*)calloc(mvdrwin->m_fft_size, sizeof(float)); 58 | mvdrwin->m_syn_win = (float*)calloc(mvdrwin->m_fft_size, sizeof(float)); 59 | mvdrwin->m_norm_win = (float*)calloc(mvdrwin->m_fft_size, sizeof(float)); 60 | 61 | for (i = 0; i < mvdrwin->m_fft_size; ++i ) 62 | { 63 | mvdrwin->m_ana_win[i] = (float)(0.54 - 0.46*cos((2*i)*PI/(mvdrwin->m_fft_size-1))); 64 | } 65 | for (i = 0; i < mvdrwin->m_fft_size; ++i ) 66 | { 67 | mvdrwin->m_norm_win[i] = mvdrwin->m_ana_win[i] * mvdrwin->m_ana_win[i]; 68 | } 69 | for (i = 0; i < mvdrwin->m_shift_size; ++i ) 70 | { 71 | temp = 0; 72 | for (j = 0; j < mvdrwin->m_block_num; ++j ) 73 | { 74 | temp += mvdrwin->m_norm_win[i+j*mvdrwin->m_shift_size]; 75 | } 76 | mvdrwin->m_norm_win[i] = 1.0f / temp; 77 | } 78 | for (i = 0; i < mvdrwin->m_shift_size; ++i ) 79 | { 80 | for (j = 1; j < mvdrwin->m_block_num; ++j ) 81 | { 82 | mvdrwin->m_norm_win[i+j*mvdrwin->m_shift_size] = mvdrwin->m_norm_win[i]; 83 | } 84 | } 85 | for (i = 0; i < mvdrwin->m_fft_size; ++i ) 86 | { 87 | mvdrwin->m_syn_win[i] = mvdrwin->m_norm_win[i] * mvdrwin->m_ana_win[i]; 88 | } 89 | } 90 | 91 | int dios_ssp_mvdr_win_add_ana_win(objMVDRCwin *mvdrwin, const float *x, float *x_win) 92 | { 93 | int i; 94 | for (i = 0; i < mvdrwin->m_fft_size; ++i ) 95 | { 96 | x_win[i] = x[i] * mvdrwin->m_ana_win[i]; 97 | } 98 | 99 | return 0; 100 | } 101 | 102 | int dios_ssp_mvdr_win_add_syn_win(objMVDRCwin *mvdrwin, const float *x, float *x_win) 103 | { 104 | int i; 105 | for (i = 0; i < mvdrwin->m_fft_size; ++i ) 106 | { 107 | x_win[i] = x[i] * mvdrwin->m_syn_win[i]; 108 | } 109 | 110 | return 0; 111 | } 112 | 113 | int dios_ssp_mvdr_win_delete(objMVDRCwin *mvdrwin) 114 | { 115 | free(mvdrwin->m_ana_win); 116 | free(mvdrwin->m_syn_win); 117 | free(mvdrwin->m_norm_win); 118 | 119 | return 0; 120 | } 121 | 122 | -------------------------------------------------------------------------------- /athena_signal/kernels/dios_ssp_mvdr/dios_ssp_mvdr_win.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | ==============================================================================*/ 16 | 17 | #ifndef _DIOS_SSP_MVDR_WIN_H_ 18 | #define _DIOS_SSP_MVDR_WIN_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include "dios_ssp_mvdr_macros.h" 25 | 26 | typedef struct 27 | { 28 | int m_fft_size; 29 | int m_shift_size; 30 | int m_block_num; 31 | 32 | float *m_ana_win; 33 | float *m_norm_win; 34 | float *m_syn_win; 35 | }objMVDRCwin; 36 | 37 | /********************************************************************************** 38 | Function: // dios_ssp_mvdr_win_init 39 | Description: // mvdr win init 40 | Input: // mvdrwin 41 | fft_size 42 | shift_size 43 | Output: // none 44 | Return: // success: return mvdr win object pointer (void*)mvdrwin 45 | failure: return NULL 46 | **********************************************************************************/ 47 | void dios_ssp_mvdr_win_init(objMVDRCwin *mvdrwin,int fft_size, int shift_size); 48 | 49 | /********************************************************************************** 50 | Function: // dios_ssp_mvdr_win_add_ana_win 51 | Description: // mvdr win ana 52 | Input: // mvdrwin: mvdr win object pointer 53 | x: enter data 54 | Output: // x_win 55 | Return: // success: return 0 56 | **********************************************************************************/ 57 | int dios_ssp_mvdr_win_add_ana_win(objMVDRCwin *mvdrwin, const float *x, float *x_win); 58 | 59 | /********************************************************************************** 60 | Function: // dios_ssp_mvdr_win_add_syn_win 61 | Description: // mvdr win syn 62 | Input: // mvdrwin: mvdr win object pointer 63 | x: fft out data 64 | Output: // x_win 65 | Return: // success: return 0 66 | **********************************************************************************/ 67 | int dios_ssp_mvdr_win_add_syn_win(objMVDRCwin *mvdrwin, const float *x, float *x_win); 68 | 69 | /********************************************************************************** 70 | Function: // dios_ssp_mvdr_win_delete 71 | Description: // mvdr win syn 72 | Input: // mvdrwin: mvdr win object pointer 73 | Output: // none 74 | Return: // success: return 0 75 | **********************************************************************************/ 76 | int dios_ssp_mvdr_win_delete(objMVDRCwin *mvdrwin); 77 | 78 | #endif /* _DIOS_SSP_MVDR_WIN_H_ */ 79 | 80 | -------------------------------------------------------------------------------- /athena_signal/kernels/dios_ssp_ns/dios_ssp_ns_api.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | ==============================================================================*/ 16 | 17 | #ifndef _DIOS_SSP_NS_API_H_ 18 | #define _DIOS_SSP_NS_API_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include "../dios_ssp_share/dios_ssp_share_rfft.h" 25 | #include "dios_ssp_ns_macros.h" 26 | 27 | /********************************************************************************** 28 | Function: // dios_ssp_ns_init_api 29 | Description: // init ns module 30 | Input: // frame_len: frame length 31 | Output: // none 32 | Return: // success: return ns module pointer 33 | failure: return NULL 34 | **********************************************************************************/ 35 | void* dios_ssp_ns_init_api(int frame_len); 36 | 37 | /********************************************************************************** 38 | Function: // dios_ssp_ns_reset_api 39 | Description: // reset ns module 40 | Input: // ptr: ns module pointer 41 | Output: // none 42 | Return: // success: return 0, failure: return ERROR_NS 43 | **********************************************************************************/ 44 | int dios_ssp_ns_reset_api(void* ptr); 45 | 46 | /********************************************************************************** 47 | Function: // dios_ssp_ns_process 48 | Description: // ns process using MCRA 49 | Input: // ptr: ns module pointer 50 | in_data: input and output data 51 | Output: // 52 | Return: // success: return 0, failure: return ERROR_NS 53 | **********************************************************************************/ 54 | int dios_ssp_ns_process(void *ptr, float *in_data); 55 | 56 | /********************************************************************************** 57 | Function: // dios_ssp_ns_uninit_api 58 | Description: // free ns module 59 | Input: // ptr: ns module pointer 60 | Output: // none 61 | Return: // success: return 0, failure: return ERROR_NS 62 | **********************************************************************************/ 63 | int dios_ssp_ns_uninit_api(void* ptr); 64 | 65 | #endif /* _DIOS_SSP_NS_API_H_ */ 66 | 67 | -------------------------------------------------------------------------------- /athena_signal/kernels/dios_ssp_ns/dios_ssp_ns_macros.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | ==============================================================================*/ 16 | 17 | #ifndef _DIOS_SSP_NS_MACROS_H_ 18 | #define _DIOS_SSP_NS_MACROS_H_ 19 | 20 | #define NS_SAMPLE_RATE (16000) 21 | #define NS_FFT_LEN (256) 22 | #define NS_SUBBAND_NUM (NS_FFT_LEN/2+1) 23 | 24 | #endif /* _DIOS_SSP_NS_MACROS_H_ */ 25 | 26 | -------------------------------------------------------------------------------- /athena_signal/kernels/dios_ssp_return_defs.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | ==============================================================================*/ 16 | 17 | #ifndef _DIOS_SSP_RETURN_DEFS_H_ 18 | #define _DIOS_SSP_RETURN_DEFS_H_ 19 | 20 | typedef enum 21 | { 22 | OK_AUDIO_PROCESS, 23 | ERROR_AUDIO_PROCESS, 24 | ERROR_AEC, 25 | ERROR_VAD, 26 | ERROR_MVDR, 27 | ERROR_GSC, 28 | ERROR_DOA, 29 | ERROR_HPF, 30 | ERROR_NS, 31 | ERROR_AGC 32 | } FUN_RETURN; 33 | 34 | #endif /* _DIOS_SSP_RETURN_DEFS_H_ */ 35 | 36 | -------------------------------------------------------------------------------- /athena_signal/kernels/dios_ssp_share/dios_ssp_share_cinv.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | ==============================================================================*/ 16 | 17 | #ifndef _DIOS_SSP_SHARE_CINV_H_ 18 | #define _DIOS_SSP_SHARE_CINV_H_ 19 | 20 | #include 21 | #include 22 | 23 | typedef struct 24 | { 25 | int dim; 26 | float **ar; 27 | float **ai; 28 | float **mat_temp; 29 | float **mat_temp2; 30 | }objMATRIXinv; 31 | 32 | void *dios_ssp_matrix_inv_init(int Rdim); 33 | int dios_ssp_matrix_inv_process(void *matrix_inv, float *R, float *Rinv); 34 | int dios_ssp_matrix_inv_delete(void *matrix_inv); 35 | 36 | #endif /* _DIOS_SSP_SHARE_CINV_H_ */ 37 | 38 | -------------------------------------------------------------------------------- /athena_signal/kernels/dios_ssp_share/dios_ssp_share_complex_defs.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | ==============================================================================*/ 16 | 17 | #ifndef _DIOS_SSP_SHARE_COMPLEX_DEFS_H_ 18 | #define _DIOS_SSP_SHARE_COMPLEX_DEFS_H_ 19 | 20 | #include 21 | 22 | // define complex declare type 23 | typedef struct FCOMPLEX { float r, i; } fcomplex; 24 | 25 | // define fcomplex, float type 26 | typedef fcomplex xcomplex; 27 | 28 | // Macros specific for the fixed point implementation 29 | #define DIOS_SSP_WORD16_MAX 32767 30 | #define DIOS_SSP_WORD16_MIN -32768 31 | 32 | float xsqrt(float x); 33 | float xmax(float x, float y); 34 | float xmin(float x, float y); 35 | float xabs(float x); 36 | float xsmooth_proc(float y, float rate, float x); 37 | 38 | float xsmooth_factor(float st); 39 | 40 | // complex generation 41 | xcomplex complex_gen(float re, float im); 42 | 43 | // complex conjugation 44 | xcomplex complex_conjg(xcomplex z); 45 | 46 | // complex abs 47 | float complex_abs(xcomplex z); 48 | 49 | // complex number absolute value square 50 | float complex_abs2(xcomplex cp); 51 | 52 | // complex sqrt 53 | xcomplex complex_sqrt(xcomplex z); 54 | 55 | // complex addition 56 | xcomplex complex_add(xcomplex a, xcomplex b); 57 | 58 | // complex subtraction 59 | xcomplex complex_sub(xcomplex a, xcomplex b); 60 | 61 | // complex multiplication 62 | xcomplex complex_mul(xcomplex a, xcomplex b); 63 | 64 | // real and complex mutiplication 65 | xcomplex complex_real_complex_mul(float x, xcomplex a); 66 | 67 | // complex division 68 | xcomplex complex_div(xcomplex a, xcomplex b); 69 | 70 | // complex division 2 71 | xcomplex complex_div2(xcomplex a, xcomplex b); 72 | 73 | // complex number div real number 74 | xcomplex complex_div_real(xcomplex cp, float r); 75 | 76 | // complex number averaging 77 | xcomplex complex_avg_vec(xcomplex *cpVec, int cpVecLen); 78 | 79 | 80 | 81 | /* function implementations */ 82 | /*--------------------------------------------------- 83 | complex FIR filtering of 2nd dimension data 84 | len : Tap length : in : int 85 | hat : impulse response : in : xcomplex[][] 86 | buf : input buffer : in : xcomplex[][] 87 | xout: output data : out : xcomplex[] 88 | ---------------------------------------------------*/ 89 | xcomplex complex_conv(int len, xcomplex *hat, xcomplex *buf); 90 | 91 | /*--------------------------------------------------- 92 | CmplxDataPush 93 | : push complex data into 2nd dimension bufer 94 | in len bufer length 95 | xin input data 96 | renewal buf bufer 97 | ---------------------------------------------------*/ 98 | void complex_data_push(int len, xcomplex xin, xcomplex *buf); 99 | 100 | // delay function application 101 | int NormW16(short a); 102 | 103 | // Shifting with negative numbers not allowed 104 | // We cannot do casting here due to signed/unsigned problem 105 | #define DIOS_SSP_RSHIFT_W32(x, c) ((x) >> (c)) 106 | 107 | #endif /* _DIOS_SSP_SHARE__FUNC_DEFS_H_ */ 108 | 109 | -------------------------------------------------------------------------------- /athena_signal/kernels/dios_ssp_share/dios_ssp_share_noiselevel.c: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | Description: To estimate the background noise level the following step are 17 | applied: 18 | 1. Clipping the input energy into [max_noise_energy, min_noise_energy] 19 | 2. Running minimum (an approximation of the minimum over a shifting window of 20 | min_win_len values) 21 | 3. A linear smoothing as the output of the running min is staircase shaped 22 | ==============================================================================*/ 23 | 24 | #include "dios_ssp_share_noiselevel.h" 25 | 26 | int dios_ssp_share_noiselevel_init(objNoiseLevel* srv, float max_noise_energy, float min_noise_energy, int min_win_len) 27 | { 28 | float smooth_factor = 0.2f; 29 | if (NULL == srv) 30 | { 31 | return -1; 32 | } 33 | 34 | srv->smoothfactor_fisrt = smooth_factor; 35 | srv->min_noise_energy = min_noise_energy; 36 | srv->max_noise_energy = max_noise_energy; 37 | srv->min_energy = max_noise_energy; 38 | srv->temp_min = max_noise_energy; 39 | srv->min_win_len = min_win_len * 2; 40 | srv->min_hold_frame = 0; 41 | srv->noise_level_first = min_noise_energy; 42 | 43 | srv->smoothfactor_second = smooth_factor; 44 | srv->min_noise_energy_second = min_noise_energy; 45 | srv->max_noise_energy_second = max_noise_energy; 46 | srv->min_energy_second = max_noise_energy; 47 | srv->temp_min_second = max_noise_energy; 48 | srv->min_win_len_second = min_win_len; 49 | srv->min_hold_frame_second = 0; 50 | srv->noise_level_second = min_noise_energy; 51 | 52 | srv->min_energy_delay = max_noise_energy; 53 | srv->noise_change_frame = 0; 54 | srv->noise_change_flag = 0; 55 | srv->noise_change_counter = 0; 56 | srv->noise_change_update_flag = 0; 57 | 58 | return 0; 59 | } 60 | 61 | int dios_ssp_share_noiselevel_process(objNoiseLevel* srv, float in_energy) 62 | { 63 | int vad = 0; 64 | 65 | if (in_energy < srv->min_energy_second) 66 | { 67 | srv->min_energy_delay = srv->min_energy_second; 68 | srv->min_energy_second = in_energy; 69 | srv->min_hold_frame_second = 0; 70 | srv->temp_min_second = srv->max_noise_energy_second; 71 | } 72 | else 73 | { 74 | srv->min_hold_frame_second++; 75 | } 76 | 77 | if (srv->min_hold_frame_second > (srv->min_win_len_second >> 1) && in_energy < srv->temp_min_second) 78 | { 79 | srv->temp_min_second = in_energy; 80 | } 81 | 82 | if (srv->min_hold_frame_second > ((3 * srv->min_win_len_second) >> 1)) 83 | { 84 | srv->min_energy_delay = srv->min_energy_second; 85 | srv->min_energy_second = srv->temp_min_second; 86 | srv->temp_min_second = srv->max_noise_energy_second; 87 | srv->min_hold_frame_second = (srv->min_win_len_second >> 1); 88 | } 89 | 90 | srv->noise_level_second += srv->smoothfactor_second * (srv->min_energy_second - srv->noise_level_second); 91 | 92 | if ((srv->min_energy_second > 2 * srv->min_energy_delay || srv->min_energy_delay > 2 * srv->min_energy_second) 93 | && srv->noise_change_flag == 0) 94 | { 95 | srv->noise_change_flag = 1; 96 | srv->noise_change_frame = 0; 97 | } 98 | if (srv->noise_change_flag == 1 && in_energy < 10 * srv->min_energy_second) 99 | { 100 | srv->noise_change_counter++; 101 | srv->noise_change_update_flag = 1; 102 | } 103 | else 104 | { 105 | srv->noise_change_update_flag = 0; 106 | } 107 | if (srv->noise_change_counter >= 9) 108 | { 109 | srv->noise_change_update_flag = 0; 110 | } 111 | srv->noise_change_frame++; 112 | if (srv->noise_change_frame > srv->min_win_len_second) 113 | { 114 | srv->noise_change_counter = 0; 115 | srv->noise_change_flag = 0; 116 | srv->noise_change_frame = 0; 117 | srv->noise_change_update_flag = 0; 118 | } 119 | if (in_energy < 10.F * srv->noise_level_second) /* If low enough energy,update second noise estimator */ 120 | { 121 | if (in_energy < srv->min_noise_energy_second) 122 | { 123 | in_energy = srv->min_noise_energy; 124 | } 125 | 126 | if (in_energy < srv->min_energy) 127 | { 128 | srv->min_energy = in_energy; 129 | srv->min_hold_frame = 0; 130 | srv->temp_min = srv->max_noise_energy; 131 | } 132 | else 133 | { 134 | srv->min_hold_frame++; 135 | } 136 | 137 | if (srv->min_hold_frame > (srv->min_win_len >> 1) && in_energy < srv->temp_min) 138 | { 139 | srv->temp_min = in_energy; 140 | } 141 | 142 | if (srv->min_hold_frame > ((3 * srv->min_win_len) >> 1)) 143 | { 144 | srv->min_energy = srv->temp_min; 145 | srv->temp_min = srv->max_noise_energy; 146 | srv->min_hold_frame = (srv->min_win_len >> 1); 147 | } 148 | 149 | srv->noise_level_first += srv->smoothfactor_fisrt * (srv->min_energy - srv->noise_level_first); 150 | } 151 | if ((in_energy > 20.0f * srv->noise_level_second) && in_energy > 20.0f * srv->noise_level_first) 152 | { 153 | vad = 1; 154 | } 155 | else 156 | { 157 | vad = 0; 158 | } 159 | return(vad); 160 | } 161 | 162 | -------------------------------------------------------------------------------- /athena_signal/kernels/dios_ssp_share/dios_ssp_share_noiselevel.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | ==============================================================================*/ 16 | 17 | #ifndef _DIOS_SSP_SHARE_NOISELEVEL_H_ 18 | #define _DIOS_SSP_SHARE_NOISELEVEL_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | typedef struct { 27 | 28 | // aec_ns_first noise estimator variables 29 | float smoothfactor_fisrt; // final noise smooth rate 30 | float min_noise_energy; // Min Noise in_energy 31 | float max_noise_energy; // Max Noise in_energy 32 | float min_energy; // Running minimun along a shifting window 33 | float temp_min; // Temporary minimum 34 | int min_win_len; // Running minimun window length 35 | int min_hold_frame; // min age counter used to schedule min update 36 | float noise_level_first; // Noise Level (return value) 37 | 38 | // second noise estimator variables 39 | float smoothfactor_second; // final noise smooth rate 40 | float min_noise_energy_second; // Min Noise in_energy 41 | float max_noise_energy_second; // Max Noise in_energy 42 | float min_energy_second; // Running minimun along a shifting window 43 | float temp_min_second; // Temporary minimum 44 | int min_win_len_second; // Running minimun window length 45 | int min_hold_frame_second; // min age counter used to schedule min update 46 | float noise_level_second; // Noise Level (return value) 47 | 48 | float min_energy_delay; 49 | int noise_change_frame; 50 | int noise_change_flag; /* the frame jump flag*/ 51 | int noise_change_counter; /* count the jump frame number*/ 52 | int noise_change_update_flag; 53 | } objNoiseLevel; 54 | 55 | /********************************************************************************** 56 | Function: // dios_ssp_share_noiselevel_init 57 | Description: // load configure file and allocate memory 58 | Input: // srv: dios speech signal process noise level pointer 59 | max_noise_energy: max value of noise energy 60 | min_noise_energy: min value of noise energy 61 | min_win_len:min window length for noise level 62 | Output: // none 63 | Return: // success: return 0, failure: return -1 64 | **********************************************************************************/ 65 | int dios_ssp_share_noiselevel_init(objNoiseLevel* srv, float max_noise_energy, float min_noise_energy, int min_win_len); 66 | 67 | /********************************************************************************** 68 | Function: // dios_ssp_share_noiselevel_process 69 | Description: // run dios speech signal process noise level module 70 | Input: // srv: dios speech signal process noise level pointer 71 | input_energy: input signal energy 72 | Output: // none 73 | Return: // vad result 74 | **********************************************************************************/ 75 | int dios_ssp_share_noiselevel_process(objNoiseLevel* srv, float input_energy); 76 | 77 | #endif /* _DIOS_SSP_SHARE_NOISELEVEL_H_ */ 78 | 79 | -------------------------------------------------------------------------------- /athena_signal/kernels/dios_ssp_share/dios_ssp_share_rfft.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | ==============================================================================*/ 16 | 17 | #ifndef _DIOS_SSP_SHARE_RFFT_H_ 18 | #define _DIOS_SSP_SHARE_RFFT_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | #include "../dios_ssp_aec/dios_ssp_aec_macros.h" 24 | #include "./dios_ssp_share_complex_defs.h" 25 | 26 | /********************************************************************************** 27 | Function: // dios_ssp_share_rfft_init 28 | Description: // rfft init 29 | Input: // fft_len: fft length 30 | Output: // none 31 | Return: // success: return dios speech signal process rfft pointer 32 | failure: return NULL 33 | **********************************************************************************/ 34 | void *dios_ssp_share_rfft_init(int fft_len); 35 | 36 | /********************************************************************************** 37 | Function: // dios_ssp_share_rfft_process 38 | Description: // run dios speech signal process rfft module by frames 39 | Input: // rfft_handle: dios speech signal process rfft pointer 40 | inbuffer: input data in time domain, data type is float 41 | Output: // outbuffer: output data in frequency domain, data type is float 42 | Return: // success: return 0, failure: return -1 43 | **********************************************************************************/ 44 | int dios_ssp_share_rfft_process(void *rfft_handle, float *inbuffer, float *outbuffer); 45 | 46 | /********************************************************************************** 47 | Function: // dios_ssp_share_irfft_process 48 | Description: // run dios speech signal process irfft module by frames 49 | Input: // rfft_handle: dios speech signal process rfft pointer 50 | inbuffer: input data in frequency domain, data type is float 51 | Output: // outbuffer: output data in time domain, data type is float 52 | Return: // success: return 0, failure: return -1 53 | **********************************************************************************/ 54 | int dios_ssp_share_irfft_process(void *rfft_handle, float *inbuffer, float *outbuffer); 55 | 56 | /********************************************************************************** 57 | Function: // dios_ssp_share_rfft_uninit 58 | Description: // free dios speech signal process rfft module 59 | Input: // rfft_handle: dios speech signal process rfft pointer 60 | Output: // none 61 | Return: // success: return 0, failure: return -1 62 | **********************************************************************************/ 63 | int dios_ssp_share_rfft_uninit(void *rfft_handle); 64 | 65 | #endif /* _DIOS_SSP_SHARE_RFFT_H_ */ 66 | 67 | -------------------------------------------------------------------------------- /athena_signal/kernels/dios_ssp_share/dios_ssp_share_subband.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | ==============================================================================*/ 16 | 17 | #ifndef _DIOS_SSP_SHARE_SUBBAND_H_ 18 | #define _DIOS_SSP_SHARE_SUBBAND_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | #include "dios_ssp_share_rfft.h" 24 | 25 | typedef struct { 26 | int frm_len; 27 | int Ppf_tap; // WIN_LEN/FFT_LEN 28 | int Ppf_decm; 29 | int *p_in; 30 | int *p_h0; 31 | float scale; 32 | float *ana_xin; // time domain data input for analyze 33 | xcomplex *ana_cxout; // frequency domain complex output for analyze 34 | float *ana_xout; // time domain output for analyze 35 | 36 | float *comp_in; // time domain data input for compose 37 | float *comp_out; // data output for compose 38 | float* lpf_coef; 39 | void *rfft_param; 40 | float *fftout_buffer; 41 | float *fftin_buffer; 42 | }objSubBand; 43 | 44 | /********************************************************************************** 45 | Function: // dios_ssp_share_subband_init 46 | Description: // subband init 47 | Input: // frm_len: frame length 48 | Output: // none 49 | Return: // success: return dios speech signal process subband pointer 50 | failure: return NULL 51 | **********************************************************************************/ 52 | objSubBand* dios_ssp_share_subband_init(int frm_len); 53 | 54 | /********************************************************************************** 55 | Function: // dios_ssp_share_subband_reset 56 | Description: // reset dios speech signal process subband module 57 | Input: // ptr: dios speech signal process subband pointer 58 | Output: // none 59 | Return: // success: return 0, failure: return -1 60 | **********************************************************************************/ 61 | int dios_ssp_share_subband_reset(objSubBand* ptr); 62 | 63 | /********************************************************************************** 64 | Function: // dios_ssp_share_subband_analyse 65 | Description: // run dios speech signal process subband analyse module by frames 66 | Input: // ptr: dios speech signal process subband pointer 67 | in_buf: input data in time domain, data type is float 68 | Output: // out_buf: output data in frequency domain, data type is complex 69 | Return: // success: return 0, failure: return -1 70 | **********************************************************************************/ 71 | int dios_ssp_share_subband_analyse(objSubBand* ptr, float* in_buf, xcomplex* out_buf); 72 | 73 | /********************************************************************************** 74 | Function: // dios_ssp_share_subband_compose 75 | Description: // run dios speech signal process subband compose module by frames 76 | Input: // ptr: dios speech signal process subband pointer 77 | in_buf: input data in frequency domain, data type is complex 78 | Output: // out_buf: output data in time domain, data type is float 79 | Return: // success: return 0, failure: return -1 80 | **********************************************************************************/ 81 | int dios_ssp_share_subband_compose(objSubBand* ptr, xcomplex* in_buf, float* out_buf); 82 | 83 | /********************************************************************************** 84 | Function: // dios_ssp_share_subband_uninit 85 | Description: // free dios speech signal process subband module 86 | Input: // srv: dios speech signal process subband pointer 87 | Output: // none 88 | Return: // success: return 0, failure: return -1 89 | **********************************************************************************/ 90 | int dios_ssp_share_subband_uninit(objSubBand* ptr); 91 | 92 | #endif /* _DIOS_SSP_SHARE_SUBBAND_H_ */ 93 | 94 | -------------------------------------------------------------------------------- /athena_signal/kernels/dios_ssp_share/dios_ssp_share_typedefs.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | ==============================================================================*/ 16 | 17 | #ifndef _DIOS_SSP_SHARE_TYPEDEFS_H_ 18 | #define _DIOS_SSP_SHARE_TYPEDEFS_H_ 19 | 20 | #define CharacterNumMax 16 21 | 22 | struct objTimeSynchInfo 23 | { 24 | int timer_tick; 25 | int character_num; 26 | int character_begin_time[CharacterNumMax]; 27 | int character_end_time[CharacterNumMax]; 28 | }; 29 | 30 | typedef struct 31 | { 32 | float x; // left to right 33 | float y; // near to far 34 | float z; // low to high 35 | } PlaneCoord; 36 | 37 | typedef struct { 38 | float rho; ///< distance (metre) 39 | float phi; ///< horizontal angle (Radian), value range from 0 to 2*PI (PI is 3.1415926535) 40 | float theta; ///< vertical angle (Radian), value range from 0 to PI 41 | } PolarCoord; 42 | 43 | typedef struct 44 | { 45 | int nIndexR; // the index of the right microphone (when speak faces to array) 46 | int nIndexL; // the index of the left microphone (should be larger than nIndexR) 47 | } PairList; 48 | 49 | #endif /* _DIOS_SSP_SHARE_TYPEDEFS_H_ */ 50 | 51 | -------------------------------------------------------------------------------- /athena_signal/kernels/dios_ssp_vad/dios_ssp_vad_api.c: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | Description: Voice Activity Detection(VAD) function outputs the current frame 17 | speech state based on the result of the double-talk detection. 18 | 1. Set initial parameters based on double-talk results 19 | 2. Calculate input signal energy 20 | 3. Calculate the number of speech frames based on double-talk result and energy 21 | 4. Smooth VAD results with hangpover 22 | ==============================================================================*/ 23 | 24 | #include "dios_ssp_vad_api.h" 25 | 26 | typedef struct { 27 | void* energy_vad_ptr; 28 | void* vad_counter_ptr; 29 | void* vad_counter_stric_ptr; 30 | int voice_state; 31 | int vad_temp_result; 32 | int vad_result; 33 | int voice_stric_state; 34 | int vad_temp_stric_result; 35 | int vad_stric_result; 36 | } objVadProcess; 37 | 38 | void* dios_ssp_vad_init_api(void) 39 | { 40 | void* ptr_vad = NULL; 41 | objVadProcess *srv; 42 | ptr_vad = (void*)calloc(1, sizeof(objVadProcess)); 43 | srv = (objVadProcess *)ptr_vad; 44 | 45 | srv->energy_vad_ptr = dios_ssp_energy_vad_init(0); 46 | if(srv->energy_vad_ptr == NULL) 47 | { 48 | return NULL; 49 | } 50 | srv->vad_counter_ptr = dios_ssp_vad_counter_init(); 51 | if(srv->vad_counter_ptr == NULL) 52 | { 53 | return NULL; 54 | } 55 | srv->vad_counter_stric_ptr = dios_ssp_vad_counter_init(); 56 | if(srv->vad_counter_stric_ptr == NULL) 57 | { 58 | return NULL; 59 | } 60 | 61 | srv->voice_state = 0; 62 | srv->vad_temp_result = 0; 63 | srv->vad_result = 0; 64 | srv->voice_stric_state = 0; 65 | srv->vad_temp_stric_result = 0; 66 | srv->vad_stric_result = 0; 67 | 68 | return ptr_vad; 69 | } 70 | 71 | int dios_ssp_vad_reset_api(void* ptr_vad) 72 | { 73 | if (ptr_vad == NULL) 74 | { 75 | return ERROR_VAD; 76 | } 77 | objVadProcess *srv; 78 | srv = (objVadProcess *)ptr_vad; 79 | 80 | dios_ssp_energy_vad_reset(srv->energy_vad_ptr); 81 | dios_ssp_vad_counter_reset(srv->vad_counter_ptr); 82 | dios_ssp_vad_counter_reset(srv->vad_counter_stric_ptr); 83 | srv->voice_state = 0; 84 | srv->vad_temp_result = 0; 85 | srv->vad_result = 0; 86 | srv->voice_stric_state = 0; 87 | srv->vad_temp_stric_result = 0; 88 | srv->vad_stric_result = 0; 89 | 90 | return 0; 91 | } 92 | 93 | int dios_ssp_vad_process_api(void* ptr_vad, float* vad_data, int dt_st) 94 | { 95 | if (ptr_vad == NULL || vad_data == NULL) 96 | { 97 | return ERROR_VAD; 98 | } 99 | objVadProcess *srv; 100 | srv = (objVadProcess *)ptr_vad; 101 | 102 | // different param according to doubletalk status 103 | if(dt_st == 0) 104 | { 105 | dios_ssp_energy_vad_para_set(srv->energy_vad_ptr, singletalk_state, srv->voice_state); 106 | } 107 | else if(dt_st == 1) 108 | { 109 | dios_ssp_energy_vad_para_set(srv->energy_vad_ptr, nearend_state, srv->voice_state); 110 | } 111 | else 112 | { 113 | dios_ssp_energy_vad_para_set(srv->energy_vad_ptr, doubletalk_state, srv->voice_state); 114 | } 115 | 116 | // energy vad processing 117 | int energy_vad_result = 0; 118 | int energy_vad_stric_result = 0; 119 | energy_vad_result = dios_ssp_energy_vad_process(srv->energy_vad_ptr, vad_data); 120 | energy_vad_stric_result = dios_ssp_energy_vad_stric_result_get(srv->energy_vad_ptr); 121 | float signal_dev_value; 122 | float noiselevel_second; 123 | float noiselevel_first; 124 | float vmmean; 125 | dios_ssp_energy_vad_para_get(srv->energy_vad_ptr, &signal_dev_value, &noiselevel_second, &noiselevel_first, &vmmean); 126 | 127 | // mix vad processing 128 | dios_ssp_vad_mix_process(energy_vad_result, dt_st, srv->vad_counter_ptr, signal_dev_value, &srv->vad_temp_result, srv->voice_state); 129 | dios_ssp_vad_mix_stric_process(energy_vad_stric_result, dt_st, srv->vad_counter_stric_ptr, signal_dev_value, &srv->vad_temp_stric_result, srv->voice_stric_state); 130 | 131 | // smooth the vad result 132 | srv->vad_result = srv->vad_temp_result; 133 | dios_ssp_vad_smooth(&srv->vad_result, srv->vad_counter_ptr, &srv->voice_state); 134 | srv->vad_stric_result = srv->vad_temp_stric_result; 135 | dios_ssp_vad_smooth(&srv->vad_stric_result, srv->vad_counter_stric_ptr, &srv->voice_stric_state); 136 | 137 | return 0; 138 | } 139 | 140 | int dios_ssp_vad_result_get(void* ptr_vad) 141 | { 142 | if (ptr_vad == NULL) 143 | { 144 | return ERROR_VAD; 145 | } 146 | objVadProcess *srv; 147 | srv = (objVadProcess *)ptr_vad; 148 | 149 | return srv->vad_result; 150 | } 151 | 152 | int dios_ssp_vad_uninit_api(void* ptr_vad) 153 | { 154 | if (ptr_vad == NULL) 155 | { 156 | return ERROR_VAD; 157 | } 158 | objVadProcess *srv; 159 | srv = (objVadProcess *)ptr_vad; 160 | 161 | dios_ssp_energy_vad_uninit(srv->energy_vad_ptr); 162 | dios_ssp_vad_counter_uinit(srv->vad_counter_ptr); 163 | dios_ssp_vad_counter_uinit(srv->vad_counter_stric_ptr); 164 | free(srv); 165 | 166 | return 0; 167 | } 168 | 169 | -------------------------------------------------------------------------------- /athena_signal/kernels/dios_ssp_vad/dios_ssp_vad_api.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | ==============================================================================*/ 16 | 17 | #ifndef _DIOS_SSP_VAD_API_H_ 18 | #define _DIOS_SSP_VAD_API_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | #include "dios_ssp_vad_energy.h" 24 | #include "dios_ssp_vad_counter.h" 25 | #include "../dios_ssp_return_defs.h" 26 | 27 | /********************************************************************************** 28 | Function: // dios_ssp_vad_init_api 29 | Description: // init vad module 30 | Input: // none 31 | Output: // none 32 | Return: // success: return vad module pointer 33 | failure: return NULL 34 | **********************************************************************************/ 35 | void* dios_ssp_vad_init_api(void); 36 | 37 | /********************************************************************************** 38 | Function: // dios_ssp_vad_reset_api 39 | Description: // reset vad module 40 | Input: // ptr: vad module pointer 41 | Output: // none 42 | Return: // success: return 0, failure: return ERROR_VAD 43 | **********************************************************************************/ 44 | int dios_ssp_vad_reset_api(void* ptr); 45 | 46 | /********************************************************************************** 47 | Function: // dios_ssp_vad_process_api 48 | Description: // vad process 49 | Input: // ptr: vad module pointer 50 | vad_data: vad input data 51 | dt_st: doubletalk status, if any 52 | Output: // none 53 | Return: // success: return 0, failure: return ERROR_VAD 54 | **********************************************************************************/ 55 | int dios_ssp_vad_process_api(void* ptr, float* vad_data, int dt_st); 56 | 57 | /********************************************************************************** 58 | Function: // dios_ssp_vad_uninit_api 59 | Description: // free vad module 60 | Input: // ptr: vad module pointer 61 | Output: // none 62 | Return: // success: return 0, failure: return ERROR_VAD 63 | **********************************************************************************/ 64 | int dios_ssp_vad_uninit_api(void* ptr); 65 | 66 | /********************************************************************************** 67 | Function: // dios_ssp_vad_result_get 68 | Description: // get vad result 69 | Input: // ptr: vad module pointer 70 | Output: // none 71 | Return: // success: return vad result, failure: return ERROR_VAD 72 | **********************************************************************************/ 73 | int dios_ssp_vad_result_get(void* ptr); 74 | 75 | #endif /* _DIOS_SSP_VAD_API_H_ */ 76 | 77 | -------------------------------------------------------------------------------- /athena_signal/kernels/dios_ssp_vad/dios_ssp_vad_counter.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | ==============================================================================*/ 16 | 17 | #ifndef _DIOS_SSP_VAD_COUNTER_H_ 18 | #define _DIOS_SSP_VAD_COUNTER_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | /********************************************************************************** 26 | Function: // dios_ssp_vad_counter_init 27 | Description: // init vad counter module 28 | Input: // none 29 | Output: // none 30 | Return: // success: return vad counter module pointer 31 | failure: return NULL 32 | **********************************************************************************/ 33 | void* dios_ssp_vad_counter_init(void); 34 | 35 | /********************************************************************************** 36 | Function: // dios_ssp_vad_counter_reset 37 | Description: // reset vad counter module 38 | Input: // ptr: vad_counter_handle 39 | Output: // none 40 | Return: // success: return 0, failure: return -1 41 | **********************************************************************************/ 42 | int dios_ssp_vad_counter_reset(void* vad_counter_handle); 43 | 44 | /********************************************************************************** 45 | Function: // dios_ssp_vad_mix_process 46 | Description: // vad mix process 47 | Input: // ptr: apm_flag 48 | dt_flag 49 | vad_counter_handle 50 | signaldev 51 | vad_flag 52 | state 53 | Output: // none 54 | Return: // success: return 0 55 | failure: return NULL 56 | **********************************************************************************/ 57 | int dios_ssp_vad_mix_process(int apm_flag, int dt_flag, void* vad_counter_handle, float signaldev, int* vad_flag, int state); 58 | 59 | /********************************************************************************** 60 | Function: // dios_ssp_vad_mix_stric_process 61 | Description: // vad mix stric process 62 | Input: // ptr: apm_flag 63 | dt_flag 64 | vad_counter_handle 65 | signaldev 66 | vad_flag 67 | state 68 | Output: // none 69 | Return: // success: return 0 70 | failure: return NULL 71 | **********************************************************************************/ 72 | int dios_ssp_vad_mix_stric_process(int apm_flag, int dt_flag, void* vad_counter_handle, float signaldev, int* vad_flag, int state); 73 | 74 | /********************************************************************************** 75 | Function: // dios_ssp_vad_smooth 76 | Description: // vad smooth 77 | Input: // ptr: vad_flag 78 | vad_counter_handle 79 | vad_state 80 | Output: // none 81 | Return: // success: return NULL 82 | failure: return NULL 83 | **********************************************************************************/ 84 | void dios_ssp_vad_smooth(int* vad_flag, void* vad_counter_handle, int* vad_state); 85 | 86 | /********************************************************************************** 87 | Function: // dios_ssp_vad_para_get_debug 88 | Description: // vad param get 89 | Input: // ptr: vad_counter_handle 90 | vad_cnt 91 | false_cnt 92 | Output: // none 93 | Return: // success: return NULL 94 | failure: return NULL 95 | **********************************************************************************/ 96 | void dios_ssp_vad_para_get_debug(void* vad_counter_handle, float *vad_cnt, float *false_cnt); 97 | 98 | /********************************************************************************** 99 | Function: // dios_ssp_vad_counter_uinit 100 | Description: // free vad counter 101 | Input: // ptr: vad_counter_handle 102 | Output: // none 103 | Return: // success: return NULL 104 | failure: return NULL 105 | **********************************************************************************/ 106 | void dios_ssp_vad_counter_uinit(void* vad_counter_handle); 107 | 108 | #endif 109 | 110 | -------------------------------------------------------------------------------- /athena_signal/kernels/dios_ssp_vad/dios_ssp_vad_energy.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | ==============================================================================*/ 16 | 17 | #ifndef _DIOS_SSP_VAD_ENERGY_H_ 18 | #define _DIOS_SSP_VAD_ENERGY_H_ 19 | 20 | enum TALK_STATE 21 | { 22 | doubletalk_state, 23 | singletalk_state, 24 | nearend_state 25 | }; 26 | 27 | /********************************************************************************** 28 | Function: // dios_ssp_energy_vad_init 29 | Description: // init energy vad module 30 | Input: // ptr: vad_type 31 | Output: // none 32 | Return: // success: return energy vad module pointer 33 | failure: return NULL 34 | **********************************************************************************/ 35 | void* dios_ssp_energy_vad_init(int vad_type); 36 | 37 | /********************************************************************************** 38 | Function: // dios_ssp_energy_vad_reset 39 | Description: // reset energy vad module 40 | Input: // ptr: vad_handle 41 | Output: // none 42 | Return: // success: return energy vad module pointer 43 | failure: return NULL 44 | **********************************************************************************/ 45 | void dios_ssp_energy_vad_reset(void* vad_handle); 46 | 47 | /********************************************************************************** 48 | Function: // dios_ssp_energy_vad_para_set 49 | Description: // set energy vad param 50 | Input: // ptr: vad_handle 51 | talk_state 52 | state 53 | Output: // none 54 | Return: // success: return energy vad module pointer 55 | failure: return NULL 56 | **********************************************************************************/ 57 | void dios_ssp_energy_vad_para_set(void* vad_handle, enum TALK_STATE talk_state, int state); 58 | 59 | /********************************************************************************** 60 | Function: // dios_ssp_energy_vad_process 61 | Description: // energy vad process 62 | Input: // ptr: vad_handle 63 | inbuf 64 | Output: // none 65 | Return: // success: return energy vad flag 66 | failure: return NULL 67 | **********************************************************************************/ 68 | int dios_ssp_energy_vad_process(void* vad_handle, float *inbuf); 69 | 70 | /********************************************************************************** 71 | Function: // dios_ssp_energy_vad_stric_result_get 72 | Description: // stric energy vad result 73 | Input: // ptr: energyvad_ptr 74 | Output: // none 75 | Return: // success: return stric energy vad result 76 | failure: return NULL 77 | **********************************************************************************/ 78 | int dios_ssp_energy_vad_stric_result_get(void* energyvad_ptr); 79 | 80 | /********************************************************************************** 81 | Function: // dios_ssp_energy_vad_para_get 82 | Description: // stric energy vad result 83 | Input: // ptr: energyvad_ptr 84 | noisedev 85 | noiselevel_second 86 | noiselevel_first 87 | vmean 88 | Output: // none 89 | Return: // success: return NULL 90 | failure: return NULL 91 | **********************************************************************************/ 92 | void dios_ssp_energy_vad_para_get(void* energyvad_ptr, float *noisedev, float *noiselevel_second, float *noiselevel_first, float *vmean); 93 | 94 | /********************************************************************************** 95 | Function: // dios_ssp_energy_vad_uninit 96 | Description: // free energy vad module 97 | Input: // ptr: vad_handle 98 | Output: // none 99 | Return: // success: return NULL 100 | failure: return NULL 101 | **********************************************************************************/ 102 | void dios_ssp_energy_vad_uninit(void* vad_handle); 103 | 104 | #endif 105 | 106 | -------------------------------------------------------------------------------- /athena_signal/kernels/dios_ssp_vad/dios_ssp_vad_macros.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | ==============================================================================*/ 16 | 17 | #ifndef _DIOS_SSP_VAD_MACROS_H_ 18 | #define _DIOS_SSP_VAD_MACROS_H_ 19 | 20 | #define VAD_FFT_LEN (256) 21 | #define VAD_SUBBAND_NUM (VAD_FFT_LEN/2+1) 22 | 23 | #endif /* _DIOS_SSP_VAD_MACROS_H_ */ 24 | 25 | -------------------------------------------------------------------------------- /athena_signal_deep_learning/README.md: -------------------------------------------------------------------------------- 1 | # Athena-signal deep learning open source library 2 | 3 | ## What is Athena-signal deep learning? 4 | 5 | Athena-signal deep learning is an open-source implementation of speech signal processing algorithms, including speech separation, speaker extraction and speaker suppression. 6 | It aims to help reserchers and engineers who want to use deep learning speech signal processing algorithms in their own projects. 7 | Athena-signal deep learning is mainly implemented using python based on pytorch. 8 | 9 | ## Introduction of athena-signal modules 10 | 11 | Currently athena_signal deep learning is composed of such module as speech separation, speaker extraction and speaker suppression. 12 | 13 | ### Detailed description of each module 14 | 15 | - Speech Separation: The current speech separation model mainly separates the mixed sources of two people, and the outpit results includes s1 and s2 respectively, and the PIT criterion is used to determine the output order of the smallest loss to reduce redundancy. 16 | - Speaker Extraction: The speaker extraction model can extract the voice of a specfic speaker. During the model training, the specific speaker voice must be provided to the model as an auxiliary signal, output the target speaker speech, and provide the speaker label when calculating the loss, and calculate the cross entropy. Croos entropy can improve the performance of speaker extraction model. 17 | - Speaker Suppression: The speaker suppression model is mainly used to suppress the speech of a specific speaker. The current model mainly supports the suppression of the speech of one speaker. The experiment of suppressing the speech of multiple speakers is under further study. The training process of the speaker suppression model also needs to provide the speech of the suppression target as an auxiliary signal. And the output of the model is the speech of the non-suppression target. In the training process of the speaker suppression model, the speaker label can also be provided to calculate the cross entropy. Verifying cross entropy can also improve the performance of the speaker suppression model. 18 | 19 | Each modules has a separate switch that controls the operating status of the module. 20 | 21 | ## Athena-signal deep learning operating instructions 22 | 23 | 1. You need to set the name of the running model. The model name is set in the configuration file. Three different model names, DPRNN_Speech_Separation, DPRNN_Speaker_Extraction, DPRNN_Speaker_Suppression represent speech separation, speaker extraction and speaker suppression. 24 | 2. You can set various parameters in the configuration file, such as sample rate. At present, the setting of each parameter are the default seeting in the scenarior of sampling rate 8000. 25 | 3. The data loading function will select the corresponding module according to different model states. Speech separation does not need auxiliary signals and speaker labels, so the configurationfiles dataroot_aux and dataroot_labels are set to [], and [opt[data_dir]['train']['dataroot_aux'][0]] and [opt[data_dir]['train']['dataroot_labels'][0]] in the wham_datset.py file is changed to [opt[data_dir]['train']['dataroot_aux']] and [opt[data_dir]['train']['dataroot_labels']]. The current speaker extraction and speaker suppression models do not need to output speaker labels, and the configuration files dataroot_labels is set to []. 26 | 4. Speaker extraction and speaker suppression model parameters are basically the same. The main difference in speech separation model parameters is reflected in the parameter sp_channels. In speaker extraction and speaker suppression, sp_channels=128, and in speech separation sp_channels=0. 27 | 28 | ## Requirements 29 | 30 | + Python3.x 31 | + torch 32 | + numpy 33 | + pypesq 34 | + pystoi 35 | + librosa 36 | + time 37 | + datetime 38 | 39 | ## Execution of example 40 | 41 | python train.py --opt config/train_rnn.yml 42 | 43 | ## Contributing 44 | 45 | The open source code draws on the related programs of other open source workers. We would like to express our deep gratitude to other open source workers and welcome everyone to point out the problems. 46 | 47 | Any contribution is welcome. All issues and pull requests are highly appreciated. 48 | If you have any questions when using athena-signal, or any ideas to make it better, 49 | please feel free to contact us. -------------------------------------------------------------------------------- /athena_signal_deep_learning/config/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | # All rights reserved. 3 | 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ============================================================================== 16 | 17 | from .option import * -------------------------------------------------------------------------------- /athena_signal_deep_learning/config/option.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | # All rights reserved. 3 | 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ============================================================================== 16 | 17 | import yaml 18 | 19 | def parse(opt_path): 20 | with open(opt_path, mode='r') as f: 21 | opt = yaml.load(f,Loader=yaml.FullLoader) 22 | 23 | opt['logger']['path'] = opt['logger']['path'] 24 | return opt 25 | 26 | 27 | if __name__ == "__main__": 28 | parse('train.yml') -------------------------------------------------------------------------------- /athena_signal_deep_learning/config/train_rnn.yml: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | # All rights reserved. 3 | 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ============================================================================== 16 | 17 | #### general settings 18 | name: Dual_Path_RNN 19 | use_tb_logger: true 20 | num_spks: 2 21 | 22 | #### datasets 23 | datasets: 24 | train: 25 | dataroot_mix: [/nfs/volume-225-15/dengchengyun/dengchengyun/trainData/wsj0_mix/2speakers/wav8k/min/tr/mix.json] 26 | dataroot_aux: [] 27 | dataroot_labels: [] 28 | dataroot_targets: [/nfs/volume-225-15/dengchengyun/dengchengyun/trainData/wsj0_mix/2speakers/wav8k/min/tr/s1.json, 29 | /nfs/volume-225-15/dengchengyun/dengchengyun/trainData/wsj0_mix/2speakers/wav8k/min/tr/s2.json] 30 | val: 31 | dataroot_mix: [/nfs/volume-225-15/dengchengyun/dengchengyun/trainData/wsj0_mix/2speakers/wav8k/min/cv/mix.json] 32 | dataroot_aux: [] 33 | dataroot_labels: [] 34 | dataroot_targets: [/nfs/volume-225-15/dengchengyun/dengchengyun/trainData/wsj0_mix/2speakers/wav8k/min/cv/s1.json, 35 | /nfs/volume-225-15/dengchengyun/dengchengyun/trainData/wsj0_mix/2speakers/wav8k/min/cv/s2.json] 36 | 37 | dataloader_setting: 38 | shuffle: true 39 | num_workers: 2 # per GPU 40 | batch_size: 32 41 | 42 | audio_setting: 43 | sample_rate: 8000 44 | chunk_size: 32000 45 | least_size: 16000 46 | 47 | Dual_Path_Aux_Speaker: 48 | in_channels: 256 49 | out_channels: 64 50 | hidden_channels: 128 51 | sp_channels: 0 # extraction and suppression sp_channels=128, separation sp_channels=0 52 | S_R: 3 53 | num_speakers: 101 54 | P: 3 55 | kernel_size: 16 56 | rnn_type: LSTM 57 | norm: ln 58 | dropout: 0 59 | bidirectional: true 60 | num_layers: 6 61 | K: 100 62 | num_spks: 2 63 | 64 | #### training settings: learning rate scheme, loss 65 | train: 66 | epoch: 200 67 | early_stop: 10 68 | path: ./data/checkpoint 69 | gpuid: [3, 4, 5, 7] 70 | 71 | #### Optimizer settings 72 | optim: 73 | name: Adam ### Adam, RMSprop, SGD 74 | lr: !!float 5e-4 75 | momentum: 0 76 | weight_decay: 0 77 | clip_norm: 5 78 | 79 | #### scheduler settings 80 | scheduler: 81 | min_lr: !!float 1e-8 82 | patience: 2 83 | factor: 0.5 84 | 85 | #### Resume training settings 86 | resume: 87 | state: false 88 | epoch: 10 89 | path: ./data/checkpoint 90 | 91 | 92 | #### logger 93 | logger: 94 | name: DPCL 95 | path: ./data/log 96 | screen: true 97 | tofile: true 98 | print_freq: 100 99 | 100 | #### different model 101 | model: 102 | # MODEL: DPRNN_Speaker_Suppression 103 | # MODEL: DPRNN_Speaker_Extraction 104 | MODEL: DPRNN_Speech_Separation 105 | -------------------------------------------------------------------------------- /athena_signal_deep_learning/data_loader/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | # All rights reserved. 3 | 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ============================================================================== 16 | 17 | from .wham_dataset import * -------------------------------------------------------------------------------- /athena_signal_deep_learning/logger/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | # All rights reserved. 3 | 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ============================================================================== 16 | 17 | from .set_logger import * -------------------------------------------------------------------------------- /athena_signal_deep_learning/logger/set_logger.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | # All rights reserved. 3 | 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ============================================================================== 16 | 17 | import logging 18 | from datetime import datetime 19 | import os 20 | 21 | def get_timestamp(): 22 | return datetime.now().strftime('%y%m%d-%H%M%S') 23 | 24 | 25 | def setup_logger(logger_name, root, level=logging.INFO, screen=False, tofile=False): 26 | '''set up logger''' 27 | lg = logging.getLogger(logger_name) 28 | formatter = logging.Formatter('%(asctime)s [%(pathname)s:%(lineno)s - %(levelname)s ] %(message)s', 29 | datefmt='%y-%m-%d %H:%M:%S') 30 | lg.setLevel(level) 31 | os.makedirs(root, exist_ok=True) 32 | if tofile: 33 | log_file = os.path.join(root, '_{}.log'.format(get_timestamp())) 34 | fh = logging.FileHandler(log_file, mode='w') 35 | fh.setFormatter(formatter) 36 | lg.addHandler(fh) 37 | if screen: 38 | sh = logging.StreamHandler() 39 | sh.setFormatter(formatter) 40 | lg.addHandler(sh) 41 | 42 | 43 | if __name__ == "__main__": 44 | setup_logger('base','root',level=logging.INFO,screen=True, tofile=False) 45 | logger = logging.getLogger('base') 46 | logger.info('hello') 47 | -------------------------------------------------------------------------------- /athena_signal_deep_learning/model/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | # All rights reserved. 3 | 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ============================================================================== 16 | 17 | from .loss import * 18 | from .model_function import * 19 | from .norm import * 20 | from .en_decoder import * 21 | from .dprnn_net import * -------------------------------------------------------------------------------- /athena_signal_deep_learning/model/en_decoder.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | # All rights reserved. 3 | 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ============================================================================== 16 | 17 | from torch import nn 18 | import torch 19 | import torch.nn.functional as F 20 | 21 | class Encoder(nn.Module): 22 | ''' 23 | Conv-Tasnet Encoder part 24 | kernel_size: the length of filters 25 | out_channels: the number of filters 26 | ''' 27 | 28 | def __init__(self, kernel_size=2, out_channels=64): 29 | super(Encoder, self).__init__() 30 | self.conv1d = nn.Conv1d(in_channels=1, out_channels=out_channels, kernel_size=kernel_size, stride=kernel_size // 2, groups=1, bias=False) 31 | 32 | def forward(self, x): 33 | """ 34 | Input: 35 | x: [B, T], B is batch size, T is times 36 | Returns: 37 | x: [B, C, T_out] 38 | T_out is the number of time steps 39 | """ 40 | # B x T -> B x 1 x T 41 | x = torch.unsqueeze(x, dim=1) 42 | # B x 1 x T -> B x C x T_out 43 | x = self.conv1d(x) 44 | x = F.relu(x) 45 | return x 46 | 47 | class Decoder(nn.ConvTranspose1d): 48 | ''' 49 | Decoder of the TasNet 50 | This module can be seen as the gradient of Conv1d with respect to its input. 51 | It is also known as a fractionally-strided convolution 52 | or a deconvolution (although it is not an actual deconvolution operation). 53 | ''' 54 | 55 | def __init__(self, *args, **kwargs): 56 | super(Decoder, self).__init__(*args, **kwargs) 57 | 58 | def forward(self, x): 59 | """ 60 | x: [B, N, L] 61 | """ 62 | if x.dim() not in [2, 3]: 63 | raise RuntimeError("{} accept 3/4D tensor as input".format( 64 | self.__name__)) 65 | x = super().forward(x if x.dim() == 3 else torch.unsqueeze(x, 1)) 66 | 67 | if torch.squeeze(x).dim() == 1: 68 | x = torch.squeeze(x, dim=1) 69 | else: 70 | x = torch.squeeze(x) 71 | return x -------------------------------------------------------------------------------- /athena_signal_deep_learning/model/loss.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | # All rights reserved. 3 | 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ============================================================================== 16 | 17 | import torch 18 | from itertools import permutations 19 | import numpy as np 20 | 21 | def Loss_SI_SDR(ests, egs): 22 | # n x S 23 | 24 | snr_new = sisnr(ests, egs) 25 | N = egs.size(0) 26 | 27 | return -torch.sum(snr_new) / N 28 | 29 | def sisnr(x, s, eps=1e-8): 30 | """ 31 | calculate training loss 32 | input: 33 | x: separated signal, N x S tensor 34 | s: reference signal, N x S tensor 35 | Return: 36 | sisnr: N tensor 37 | """ 38 | 39 | def l2norm(mat, keepdim=False): 40 | return torch.norm(mat, dim=-1, keepdim=keepdim) 41 | 42 | if x.shape != s.shape: 43 | raise RuntimeError( 44 | "Dimention mismatch when calculate si-snr, {} vs {}".format( 45 | x.shape, s.shape)) 46 | x_zm = x - torch.mean(x, dim=-1, keepdim=True) 47 | s_zm = s - torch.mean(s, dim=-1, keepdim=True) 48 | t = torch.sum(x_zm * s_zm, dim=-1, keepdim=True) * s_zm / (l2norm(s_zm, keepdim=True)**2 + eps) 49 | return 20 * torch.log10(eps + l2norm(t) / (l2norm(x_zm - t) + eps)) 50 | 51 | def accuracy_speaker(probs, labels): 52 | est_labels = probs.argmax(dim=1) 53 | corrects = (est_labels == labels) 54 | accuracy = corrects.sum().float() / float(labels.size(0)) 55 | 56 | return accuracy 57 | 58 | def Loss(ests, egs): 59 | # spks x n x S 60 | refs = egs 61 | num_spks = len(refs) 62 | 63 | def sisnr_loss(permute): 64 | # for one permute 65 | return sum( 66 | [sisnr(ests[s], refs[t]) 67 | for s, t in enumerate(permute)]) / len(permute) 68 | # average the value 69 | 70 | # P x N 71 | N = egs[0].size(0) 72 | sisnr_mat = torch.stack( 73 | [sisnr_loss(p) for p in permutations(range(num_spks))]) 74 | max_perutt, _ = torch.max(sisnr_mat, dim=0) 75 | # si-snr 76 | return -torch.sum(max_perutt) / N 77 | -------------------------------------------------------------------------------- /athena_signal_deep_learning/model/norm.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | # All rights reserved. 3 | 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ============================================================================== 16 | 17 | from torch import nn 18 | 19 | def select_norm(norm, dim, shape): 20 | if norm == 'gln': 21 | return GlobalLayerNorm(dim, shape, elementwise_affine=True) 22 | if norm == 'cln': 23 | return CumulativeLayerNorm(dim, elementwise_affine=True) 24 | if norm == 'ln': 25 | return nn.GroupNorm(1, dim, eps=1e-8) 26 | else: 27 | return nn.BatchNorm1d(dim) 28 | 29 | class GlobalLayerNorm(nn.Module): 30 | ''' 31 | Calculate Global Layer Normalization 32 | dim: (int or list or torch.Size) – 33 | input shape from an expected input of size 34 | eps: a value added to the denominator for numerical stability. 35 | elementwise_affine: a boolean value that when set to True, 36 | this module has learnable per-element affine parameters 37 | initialized to ones (for weights) and zeros (for biases). 38 | ''' 39 | 40 | def __init__(self, dim, shape, eps=1e-8, elementwise_affine=True): 41 | super(GlobalLayerNorm, self).__init__() 42 | self.dim = dim 43 | self.eps = eps 44 | self.elementwise_affine = elementwise_affine 45 | 46 | if self.elementwise_affine: 47 | if shape == 3: 48 | self.weight = nn.Parameter(torch.ones(self.dim, 1)) 49 | self.bias = nn.Parameter(torch.zeros(self.dim, 1)) 50 | if shape == 4: 51 | self.weight = nn.Parameter(torch.ones(self.dim, 1, 1)) 52 | self.bias = nn.Parameter(torch.zeros(self.dim, 1, 1)) 53 | else: 54 | self.register_parameter('weight', None) 55 | self.register_parameter('bias', None) 56 | 57 | def forward(self, x): 58 | # x = N x C x K x S or N x C x L 59 | # N x 1 x 1 60 | # cln: mean,var N x 1 x K x S 61 | # gln: mean,var N x 1 x 1 62 | if x.dim() == 4: 63 | mean = torch.mean(x, (1, 2, 3), keepdim=True) 64 | var = torch.mean((x - mean) ** 2, (1, 2, 3), keepdim=True) 65 | if self.elementwise_affine: 66 | x = self.weight * (x - mean) / torch.sqrt(var + self.eps) + self.bias 67 | else: 68 | x = (x - mean) / torch.sqrt(var + self.eps) 69 | if x.dim() == 3: 70 | mean = torch.mean(x, (1, 2), keepdim=True) 71 | var = torch.mean((x - mean) ** 2, (1, 2), keepdim=True) 72 | if self.elementwise_affine: 73 | x = self.weight * (x - mean) / torch.sqrt(var + self.eps) + self.bias 74 | else: 75 | x = (x - mean) / torch.sqrt(var + self.eps) 76 | return x 77 | 78 | 79 | class CumulativeLayerNorm(nn.LayerNorm): 80 | ''' 81 | Calculate Cumulative Layer Normalization 82 | dim: you want to norm dim 83 | elementwise_affine: learnable per-element affine parameters 84 | ''' 85 | 86 | def __init__(self, dim, elementwise_affine=True): 87 | super(CumulativeLayerNorm, self).__init__(dim, elementwise_affine=elementwise_affine, eps=1e-8) 88 | 89 | def forward(self, x): 90 | # x: N x C x K x S or N x C x L 91 | # N x K x S x C 92 | if x.dim() == 4: 93 | x = x.permute(0, 2, 3, 1).contiguous() 94 | # N x K x S x C == only channel norm 95 | x = super().forward(x) 96 | # N x C x K x S 97 | x = x.permute(0, 3, 1, 2).contiguous() 98 | if x.dim() == 3: 99 | x = torch.transpose(x, 1, 2) 100 | # N x L x C == only channel norm 101 | x = super().forward(x) 102 | # N x C x L 103 | x = torch.transpose(x, 1, 2) 104 | return x 105 | -------------------------------------------------------------------------------- /athena_signal_deep_learning/pre_process/prepare_speaker_labels.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | # All rights reserved. 3 | 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ============================================================================== 16 | 17 | import numpy as np 18 | import os 19 | import pickle 20 | import torch 21 | import json 22 | 23 | def handle_json(json_path): 24 | with open(json_path, 'r') as f: 25 | aux_infos = json.load(f) 26 | speakers = {} 27 | for aux in aux_infos: 28 | speaker_id = aux[0].split('/')[-1][0:3] 29 | if speaker_id not in speakers: 30 | speakers[speaker_id] = 1 31 | else: 32 | speakers[speaker_id] += 1 33 | speakers_new = sorted(speakers.keys()) 34 | num_class = len(speakers_new) 35 | speakers_labels = {} 36 | for i in range(len(speakers_new)): 37 | label = np.zeros(num_class) 38 | label[i] = 1 39 | speakers_labels[speakers_new[i]] = label.astype(np.float32) 40 | export_name = os.path.join('/nfs/cold_project/dengchengyun/AEC_Separation/IRA/dprnn_extraction_original/data/tt', 'tt_speaker') 41 | with open(export_name, 'wb') as fid: 42 | pickle.dump(speakers_labels, fid) 43 | 44 | if __name__ == "__main__": 45 | 46 | handle_json('/nfs/cold_project/dengchengyun/AEC_Separation/IRA/dprnn_extraction_original/data/tt/aux.json') 47 | 48 | with open('/nfs/cold_project/dengchengyun/AEC_Separation/IRA/dprnn_extraction_original/data/tt/tt_speaker', 'rb') as fid: 49 | data = pickle.load(fid) 50 | for d in data: 51 | max_index = int(np.argmax(data[d])) 52 | print(data[d], max_index, type(max_index), torch.tensor(max_index).long()) -------------------------------------------------------------------------------- /athena_signal_deep_learning/pre_process/preprocess_wham.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | # All rights reserved. 3 | 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ============================================================================== 16 | 17 | import argparse 18 | import json 19 | import os 20 | import soundfile as sf 21 | from tqdm import tqdm 22 | 23 | 24 | def preprocess_one_dir(in_dir, out_dir, out_filename): 25 | """ Create .json file for one condition.""" 26 | file_infos = [] 27 | in_dir = os.path.abspath(in_dir) 28 | wav_list = os.listdir(in_dir) 29 | wav_list.sort() 30 | for wav_file in tqdm(wav_list): 31 | if not wav_file.endswith('.wav'): 32 | continue 33 | wav_path = os.path.join(in_dir, wav_file) 34 | samples = sf.SoundFile(wav_path) 35 | file_infos.append((wav_path, len(samples))) 36 | if not os.path.exists(out_dir): 37 | os.makedirs(out_dir) 38 | with open(os.path.join(out_dir, out_filename + '.json'), 'w') as f: 39 | json.dump(file_infos, f, indent=4) 40 | 41 | 42 | def preprocess(inp_args): 43 | """ Create .json files for all conditions.""" 44 | speaker_list = ['tts_16k_10s'] 45 | # for data_type in ['tr', 'cv']: 46 | # for spk in speaker_list: 47 | # preprocess_one_dir(os.path.join(inp_args.in_dir, data_type, spk), 48 | # os.path.join(inp_args.out_dir, data_type), 49 | # spk) 50 | 51 | for spk in speaker_list: 52 | preprocess_one_dir(os.path.join(inp_args.in_dir, spk), 53 | os.path.join(inp_args.out_dir), 54 | spk) 55 | 56 | 57 | if __name__ == "__main__": 58 | parser = argparse.ArgumentParser("WHAM data preprocessing") 59 | parser.add_argument('--in_dir', type=str, default=None, 60 | help='Directory path of wham including tr, cv and tt') 61 | parser.add_argument('--out_dir', type=str, default=None, 62 | help='Directory path to put output files') 63 | args = parser.parse_args() 64 | print(args) 65 | preprocess(args) 66 | -------------------------------------------------------------------------------- /athena_signal_deep_learning/trainer.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | # All rights reserved. 3 | 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ============================================================================== 16 | 17 | import torch 18 | import torch.nn as nn 19 | import math 20 | import os 21 | 22 | def check_parameters(net): 23 | ''' 24 | Returns module parameters. Mb 25 | ''' 26 | parameters = sum(param.numel() for param in net.parameters()) 27 | return parameters / 10**6 28 | 29 | def save_checkpoint(epoch, checkpoint_path, mymodel, optimizer, day_time): 30 | ''' 31 | save model 32 | best: the best model 33 | ''' 34 | os.makedirs(checkpoint_path, exist_ok=True) 35 | file_path = os.path.join(checkpoint_path, '{}_epoch{}.pth.tar'.format(day_time, epoch)) 36 | 37 | torch.save({ 38 | 'epoch': epoch, 39 | 'model_state_dict': mymodel.state_dict(), 40 | 'optim_state_dict': optimizer.state_dict() 41 | }, 42 | file_path) 43 | print('Saving checkpoint model to %s' % file_path) 44 | 45 | def make_optimizer(params, opt): 46 | optimizer = getattr(torch.optim, opt['optim']['name']) 47 | if opt['optim']['name'] == 'Adam': 48 | optimizer = optimizer(params, lr=opt['optim']['lr'], weight_decay=opt['optim']['weight_decay']) 49 | else: 50 | optimizer = optimizer(params, lr=opt['optim']['lr'], weight_decay=opt['optim'] 51 | ['weight_decay'], momentum=opt['optim']['momentum']) 52 | 53 | return optimizer 54 | -------------------------------------------------------------------------------- /examples/0841-0875_env7_sit1_male_in.pcm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/athena-team/athena-signal/fdf89deaa507c819378a1837053f529b9c35145e/examples/0841-0875_env7_sit1_male_in.pcm -------------------------------------------------------------------------------- /examples/0841-0875_env7_sit1_male_ref.pcm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/athena-team/athena-signal/fdf89deaa507c819378a1837053f529b9c35145e/examples/0841-0875_env7_sit1_male_ref.pcm -------------------------------------------------------------------------------- /examples/athena_signal_test.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | # All rights reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ============================================================================== 16 | """This model tests API of athena_signal.""" 17 | 18 | 19 | from athena_signal.dios_ssp_api import athena_signal_process 20 | 21 | if __name__ == "__main__": 22 | 23 | # Test AEC 24 | input_file = ["examples/0841-0875_env7_sit1_male_in.pcm"] 25 | ref_file = ["examples/0841-0875_env7_sit1_male_ref.pcm"] 26 | out_file = ["examples/0841-0875_env7_sit1_male_out.pcm"] 27 | config = {'add_AEC': 1, 'add_BF': 0} 28 | athena_signal_process(input_file, out_file, ref_file, config) 29 | 30 | # Test BF 31 | input_file = ["examples/m0f60_5cm_1_mix.pcm", 32 | "examples/m0f60_5cm_2_mix.pcm", 33 | "examples/m0f60_5cm_3_mix.pcm", 34 | "examples/m0f60_5cm_4_mix.pcm", 35 | "examples/m0f60_5cm_5_mix.pcm", 36 | "examples/m0f60_5cm_6_mix.pcm"] 37 | out_file = ["examples/m0f60_5cm_bf_out.pcm"] 38 | config = {'add_AEC': 0, 'add_BF': 2, 'add_DOA': 0, 'mic_num': 6, 'ref_num': 0} 39 | mic_coord = [[0.05, 0.0, 0.0], 40 | [0.025, 0.0433, 0.0], 41 | [-0.025, 0.0433, 0.0], 42 | [-0.05, 0.0, 0.0], 43 | [-0.025, -0.0433, 0.0], 44 | [0.025, -0.0433, 0.0]] 45 | athena_signal_process(input_file, out_file, config=config, mic_coord=mic_coord) 46 | -------------------------------------------------------------------------------- /examples/m0f60_5cm_1_mix.pcm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/athena-team/athena-signal/fdf89deaa507c819378a1837053f529b9c35145e/examples/m0f60_5cm_1_mix.pcm -------------------------------------------------------------------------------- /examples/m0f60_5cm_2_mix.pcm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/athena-team/athena-signal/fdf89deaa507c819378a1837053f529b9c35145e/examples/m0f60_5cm_2_mix.pcm -------------------------------------------------------------------------------- /examples/m0f60_5cm_3_mix.pcm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/athena-team/athena-signal/fdf89deaa507c819378a1837053f529b9c35145e/examples/m0f60_5cm_3_mix.pcm -------------------------------------------------------------------------------- /examples/m0f60_5cm_4_mix.pcm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/athena-team/athena-signal/fdf89deaa507c819378a1837053f529b9c35145e/examples/m0f60_5cm_4_mix.pcm -------------------------------------------------------------------------------- /examples/m0f60_5cm_5_mix.pcm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/athena-team/athena-signal/fdf89deaa507c819378a1837053f529b9c35145e/examples/m0f60_5cm_5_mix.pcm -------------------------------------------------------------------------------- /examples/m0f60_5cm_6_mix.pcm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/athena-team/athena-signal/fdf89deaa507c819378a1837053f529b9c35145e/examples/m0f60_5cm_6_mix.pcm -------------------------------------------------------------------------------- /pack.bat: -------------------------------------------------------------------------------- 1 | ::1. Uninstall athena-signal. 2 | echo "Uninstall athena-signal if exist ..." 3 | pip uninstall -y athena_signal 4 | 5 | ::2. Generate the wheel file. 6 | echo "pack ..." 7 | del/s/q build athena_signal.egg-info dist 8 | swig -python athena_signal/dios_signal.i 9 | python setup.py bdist_wheel sdist 10 | 11 | ::3. Pip install the athena-siganl. 12 | for /r dist %%i in (athena_signal-*.whl) do pip install --ignore-installed %%i 13 | 14 | ::4. Test the athena_signal model. [Optional] 15 | python examples/athena_signal_test.py 16 | -------------------------------------------------------------------------------- /pack.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #1. Uninstall athena-signal. 3 | echo "Uninstall athena-signal if exist ..." 4 | pip uninstall -y athena_signal 5 | 6 | #2. Generate the wheel file. 7 | echo "pack ..." 8 | rm -rf build/ athena_signal.egg-info/ dist/ 9 | swig -python athena_signal/dios_signal.i 10 | python setup.py bdist_wheel sdist 11 | 12 | #3. Pip install the athena-siganl. 13 | pip install --ignore-installed dist/athena_signal-*.whl 14 | 15 | #4. Test the athena_signal model. [Optional] 16 | python examples/athena_signal_test.py 17 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | # /* Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. 2 | # All rights reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ==============================================================================*/ 16 | """Compile and package the project into a wheel for easy installation.""" 17 | 18 | import setuptools 19 | from glob import glob 20 | import shutil 21 | 22 | directories = [ 23 | "athena_signal", 24 | "athena_signal/kernels", 25 | "athena_signal/kernels/dios_ssp_share", 26 | "athena_signal/kernels/dios_ssp_aec", 27 | "athena_signal/kernels/dios_ssp_mvdr", 28 | "athena_signal/kernels/dios_ssp_ns", 29 | "athena_signal/kernels/dios_ssp_hpf", 30 | "athena_signal/kernels/dios_ssp_vad", 31 | "athena_signal/kernels/dios_ssp_agc", 32 | "athena_signal/kernels/dios_ssp_aec/dios_ssp_aec_tde", 33 | "athena_signal/kernels/dios_ssp_doa", 34 | "athena_signal/kernels/dios_ssp_gsc"] 35 | 36 | source_list = [] 37 | depends_list = [] 38 | for dir in directories: 39 | depends_list += glob(dir + '/*.h') 40 | source_list += glob(dir + '/*.c*') 41 | 42 | speech_enhancement_module = setuptools.Extension('athena_signal._dios_signal', 43 | sources=source_list, 44 | depends=depends_list) 45 | 46 | setuptools.setup(name='athena_signal', 47 | version='0.1.0', 48 | author="DIDI AI LAB SPEECH SIGNAL", 49 | author_email="didi@didi.com", 50 | description="""athena_signal""", 51 | url="https://github.com/athena-team/athena-signal", 52 | packages=setuptools.find_packages(), 53 | package_data={"": ["_athena_signal.so"]}, 54 | ext_modules=[speech_enhancement_module], 55 | python_requires='>=3') 56 | 57 | # path = glob('build/lib.*/athena_signal/*.so') 58 | # shutil.copy(path[0], 'athena_signal/_dios_signal.so') 59 | 60 | --------------------------------------------------------------------------------