46
46
47
47
48
48
class DFRobot_vocalgorithmParams :
49
- """Class for voc index algorithm
50
- """
49
+ """Class for voc index algorithm"""
51
50
52
51
# pylint: disable=all
53
52
# Complex math conversion from C
@@ -127,8 +126,7 @@ def _fix16_mul(self, inarg0, inarg1):
127
126
return FIX16_OVERFLOW
128
127
product_lo_tmp = product_lo & 0xFFFFFFFF
129
128
product_lo = (product_lo - 0x8000 ) & 0xFFFFFFFF
130
- product_lo = (
131
- product_lo - ((product_hi & 0xFFFFFFFF ) >> 31 )) & 0xFFFFFFFF
129
+ product_lo = (product_lo - ((product_hi & 0xFFFFFFFF ) >> 31 )) & 0xFFFFFFFF
132
130
if product_lo > product_lo_tmp :
133
131
product_hi = product_hi - 1
134
132
result = (product_hi << 16 ) | (product_lo >> 16 )
@@ -237,16 +235,14 @@ def _fix16_exp(self, x):
237
235
return res
238
236
239
237
def vocalgorithm_init (self ):
240
- self .params .mvoc_index_offset = self ._f16 (
241
- VOCALGORITHM_VOC_INDEX_OFFSET_DEFAULT )
238
+ self .params .mvoc_index_offset = self ._f16 (VOCALGORITHM_VOC_INDEX_OFFSET_DEFAULT )
242
239
self .params .mtau_mean_variance_hours = self ._f16 (
243
240
VOCALGORITHM_TAU_MEAN_VARIANCE_HOURS
244
241
)
245
242
self .params .mgating_max_duration_minutes = self ._f16 (
246
243
VOCALGORITHM_GATING_MAX_DURATION_MINUTES
247
244
)
248
- self .params .msraw_std_initial = self ._f16 (
249
- VOCALGORITHM_SRAW_STD_INITIAL )
245
+ self .params .msraw_std_initial = self ._f16 (VOCALGORITHM_SRAW_STD_INITIAL )
250
246
self .params .muptime = self ._f16 (0.0 )
251
247
self .params .msraw = self ._f16 (0.0 )
252
248
self .params .mvoc_index = 0
@@ -278,8 +274,10 @@ def _vocalgorithm_get_states(self, state0, state1):
278
274
279
275
def _vocalgorithm_set_states (self , state0 , state1 ):
280
276
self ._vocalgorithm__mean_variance_estimator__set_states (
281
- self .params , state0 , state1 , self ._f16 (
282
- VOCALGORITHM_PERSISTENCE_UPTIME_GAMMA )
277
+ self .params ,
278
+ state0 ,
279
+ state1 ,
280
+ self ._f16 (VOCALGORITHM_PERSISTENCE_UPTIME_GAMMA ),
283
281
)
284
282
self .params .msraw = state0
285
283
@@ -291,8 +289,7 @@ def _vocalgorithm_set_tuning_parameters(
291
289
std_initial ,
292
290
):
293
291
self .params .mvoc_index_offset = self ._fix16_from_int (voc_index_offset )
294
- self .params .mtau_mean_variance_hours = self ._fix16_from_int (
295
- learning_time_hours )
292
+ self .params .mtau_mean_variance_hours = self ._fix16_from_int (learning_time_hours )
296
293
self .params .mgating_max_duration_minutes = self ._fix16_from_int (
297
294
gating_max_duration_minutes
298
295
)
@@ -330,8 +327,7 @@ def vocalgorithm_process(self, sraw):
330
327
self ._vocalgorithm__mean_variance_estimator__get_std (),
331
328
self ._vocalgorithm__mean_variance_estimator__get_mean (),
332
329
)
333
- voc_index = self ._fix16_cast_to_int (
334
- (self .params .mvoc_index + self ._f16 (0.5 )))
330
+ voc_index = self ._fix16_cast_to_int ((self .params .mvoc_index + self ._f16 (0.5 )))
335
331
return voc_index
336
332
337
333
def _vocalgorithm__mean_variance_estimator__init (self ):
@@ -387,8 +383,7 @@ def _vocalgorithm__mean_variance_estimator__set_parameters(
387
383
self .params .m_mean_variance_estimator__gamma_variance = self ._f16 (0.0 )
388
384
self .params .m_mean_variance_estimator_uptime_gamma = self ._f16 (0.0 )
389
385
self .params .m_mean_variance_estimator_uptime_gating = self ._f16 (0.0 )
390
- self .params .m_mean_variance_estimator_gating_duration_minutes = self ._f16 (
391
- 0.0 )
386
+ self .params .m_mean_variance_estimator_gating_duration_minutes = self ._f16 (0.0 )
392
387
393
388
def _vocalgorithm__mean_variance_estimator__set_states (
394
389
self , mean , std , uptime_gamma
@@ -536,8 +531,7 @@ def _vocalgorithm__mean_variance_estimator___calculate_gamma(
536
531
(
537
532
self ._fix16_mul (
538
533
(self ._f16 (1.0 ) - sigmoid_gating_mean ),
539
- self ._f16 (
540
- (1.0 + VOCALGORITHM_GATING_MAX_RATIO )),
534
+ self ._f16 ((1.0 + VOCALGORITHM_GATING_MAX_RATIO )),
541
535
)
542
536
)
543
537
- self ._f16 (VOCALGORITHM_GATING_MAX_RATIO )
@@ -557,8 +551,7 @@ def _vocalgorithm__mean_variance_estimator___calculate_gamma(
557
551
self .params .m_mean_variance_estimator_gating_duration_minutes
558
552
> self .params .m_mean_variance_estimator_gating_max_duration_minutes
559
553
):
560
- self .params .m_mean_variance_estimator_uptime_gating = self ._f16 (
561
- 0.0 )
554
+ self .params .m_mean_variance_estimator_uptime_gating = self ._f16 (0.0 )
562
555
563
556
def _vocalgorithm__mean_variance_estimator__process (
564
557
self , sraw , voc_index_from_prior
@@ -682,8 +675,7 @@ def _vocalgorithm__mean_variance_estimator___sigmoid__process(self, sample):
682
675
)
683
676
684
677
def _vocalgorithm__mox_model__init (self ):
685
- self ._vocalgorithm__mox_model__set_parameters (
686
- self ._f16 (1.0 ), self ._f16 (0.0 ))
678
+ self ._vocalgorithm__mox_model__set_parameters (self ._f16 (1.0 ), self ._f16 (0.0 ))
687
679
688
680
def _vocalgorithm__mox_model__set_parameters (self , SRAW_STD , SRAW_MEAN ):
689
681
self .params .m_mox_model_sraw_std = SRAW_STD
@@ -727,8 +719,7 @@ def _vocalgorithm__sigmoid_scaled__process(self, sample):
727
719
self ._f16 (VOCALGORITHM_SIGMOID_L )
728
720
- (
729
721
self ._fix16_mul (
730
- self ._f16 (
731
- 5.0 ), self .params .m_sigmoid_scaled_offset
722
+ self ._f16 (5.0 ), self .params .m_sigmoid_scaled_offset
732
723
)
733
724
)
734
725
),
@@ -805,16 +796,14 @@ def _vocalgorithm__adaptive_lowpass__process(self, sample):
805
796
)
806
797
tau_a = (
807
798
self ._fix16_mul (
808
- self ._f16 ((VOCALGORITHM_LP_TAU_SLOW -
809
- VOCALGORITHM_LP_TAU_FAST )), F1
799
+ self ._f16 ((VOCALGORITHM_LP_TAU_SLOW - VOCALGORITHM_LP_TAU_FAST )), F1
810
800
)
811
801
) + self ._f16 (VOCALGORITHM_LP_TAU_FAST )
812
802
a3 = self ._fix16_div (
813
803
self ._f16 (VOCALGORITHM_SAMPLING_INTERVAL ),
814
804
(self ._f16 (VOCALGORITHM_SAMPLING_INTERVAL ) + tau_a ),
815
805
)
816
806
self .params .m_adaptive_lowpass_x3 = (
817
- self ._fix16_mul ((self ._f16 (1.0 ) - a3 ),
818
- self .params .m_adaptive_lowpass_x3 )
807
+ self ._fix16_mul ((self ._f16 (1.0 ) - a3 ), self .params .m_adaptive_lowpass_x3 )
819
808
) + (self ._fix16_mul (a3 , sample ))
820
809
return self .params .m_adaptive_lowpass_x3
0 commit comments