• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

stef1949 / LumiFur_Controller / 24297151496

12 Apr 2026 02:50AM UTC coverage: 37.075% (+4.7%) from 32.346%
24297151496

push

github

web-flow
Merge pull request #56 from stef1949/dev

Dev

73 of 94 new or added lines in 3 files covered. (77.66%)

360 of 971 relevant lines covered (37.08%)

125.35 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.37
/src/core/mic/mic_math.cpp
1
#include "core/mic/mic_math.h"
2

3
#include <cmath>
4

5
#ifndef I2S_NUM_1
6
#define I2S_NUM_1 1
7
#endif
8

9
#ifndef I2S_BITS_PER_SAMPLE_32BIT
10
#define I2S_BITS_PER_SAMPLE_32BIT 32
11
#endif
12

13
#ifndef I2S_CHANNEL_FMT_RIGHT_LEFT
14
#define I2S_CHANNEL_FMT_RIGHT_LEFT 0
15
#endif
16

17
#ifndef I2S_COMM_FORMAT_STAND_I2S
18
#define I2S_COMM_FORMAT_STAND_I2S 1
19
#endif
20

21
#include "core/mic/mic_config.h"
22

23
float micClamp(float value, float minValue, float maxValue)
27✔
24
{
25
  if (value < minValue)
27✔
26
  {
27
    return minValue;
2✔
28
  }
29
  if (value > maxValue)
25✔
30
  {
31
    return maxValue;
4✔
32
  }
33
  return value;
21✔
34
}
35

36
float micClamp01(float value)
17✔
37
{
38
  return micClamp(value, 0.0f, 1.0f);
17✔
39
}
40

41
float micApplyEma(float currentValue, float targetValue, float alpha)
9✔
42
{
43
  const float clampedAlpha = micClamp01(alpha);
9✔
44
  return currentValue + clampedAlpha * (targetValue - currentValue);
9✔
45
}
46

47
float micApplyAttackReleaseEma(float currentValue, float targetValue, float attackAlpha, float releaseAlpha)
6✔
48
{
49
  const float alpha = (targetValue > currentValue) ? attackAlpha : releaseAlpha;
6✔
50
  return micApplyEma(currentValue, targetValue, alpha);
6✔
51
}
52

53
float micUpdateNoiseFloor(float noiseFloor, float blockEnvelope)
3✔
54
{
55
  if (blockEnvelope > noiseFloor + MIC_NOISE_FLOOR_GATE_BAND)
3✔
56
  {
57
    return micClamp(noiseFloor, MIC_NOISE_FLOOR_MIN, MIC_NOISE_FLOOR_MAX);
1✔
58
  }
59

60
  const float alpha = (blockEnvelope >= noiseFloor) ? MIC_NOISE_FLOOR_RISE_ALPHA : MIC_NOISE_FLOOR_FALL_ALPHA;
2✔
61
  const float updated = micApplyEma(noiseFloor, blockEnvelope, alpha);
2✔
62
  return micClamp(updated, MIC_NOISE_FLOOR_MIN, MIC_NOISE_FLOOR_MAX);
2✔
63
}
64

65
float micComputeSpeechLevel(float blockEnvelope, float noiseFloor)
4✔
66
{
67
  const float speech = blockEnvelope - (noiseFloor + MIC_NOISE_GATE_MARGIN);
4✔
68
  return (speech > 0.0f) ? speech : 0.0f;
4✔
69
}
70

71
float micUpdatePeakReference(float peakReference, float speechLevel)
4✔
72
{
73
  const float target = (speechLevel > MIC_PEAK_REF_MIN) ? speechLevel : MIC_PEAK_REF_MIN;
4✔
74
  const float updated = micApplyAttackReleaseEma(
4✔
75
      peakReference,
76
      target,
77
      MIC_PEAK_REF_ATTACK_ALPHA,
78
      MIC_PEAK_REF_RELEASE_ALPHA);
79
  return micClamp(updated, MIC_PEAK_REF_MIN, MIC_PEAK_REF_MAX);
4✔
80
}
81

82
float micNormalizeSpeechLevel(float speechLevel, float peakReference)
2✔
83
{
84
  if (peakReference <= 0.0f)
2✔
85
  {
NEW
86
    return 0.0f;
×
87
  }
88
  return micClamp01(speechLevel / peakReference);
2✔
89
}
90

91
float micComputeBrightnessTarget(float normalizedEnvelope)
3✔
92
{
93
  const float shapedEnvelope = std::sqrt(micClamp01(normalizedEnvelope));
3✔
94
  return static_cast<float>(MIC_MIN_BRIGHTNESS) +
95
         (static_cast<float>(MIC_MAX_BRIGHTNESS - MIC_MIN_BRIGHTNESS) * shapedEnvelope);
3✔
96
}
97

98
bool micShouldOpenMouth(float normalizedEnvelope, bool mouthOpen)
6✔
99
{
100
  if (mouthOpen)
6✔
101
  {
102
    return normalizedEnvelope >= MIC_MOUTH_CLOSE_THRESHOLD;
3✔
103
  }
104
  return normalizedEnvelope >= MIC_MOUTH_OPEN_THRESHOLD;
3✔
105
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc