diff --git a/components/st3m/st3m_audio.c b/components/st3m/st3m_audio.c
index 1ea7111aec8ce395f6806495e7130ae884c11068..2c296747c5325e20b6e334fa8cab94621c5e99e0 100644
--- a/components/st3m/st3m_audio.c
+++ b/components/st3m/st3m_audio.c
@@ -64,7 +64,6 @@ static float _output_set_volume(st3m_audio_output_t *out, float vol_dB) {
}
if (vol_dB < out->volume_min) {
vol_dB = SILLY_LOW_VOLUME_DB;
- out->mute = true;
}
out->volume = vol_dB;
_output_apply(out);
@@ -131,6 +130,7 @@ static float _output_get_volume_relative(st3m_audio_output_t *out) {
static void _audio_headphones_apply(st3m_audio_output_t *out) {
bool mute = out->mute;
float vol_dB = out->volume;
+ if (out->volume < (SILLY_LOW_VOLUME_DB + 1)) mute = true;
bool headphones = _headphones_connected();
if (!headphones) {
@@ -153,6 +153,7 @@ static void _audio_headphones_apply(st3m_audio_output_t *out) {
static void _audio_speaker_apply(st3m_audio_output_t *out) {
bool mute = out->mute;
float vol_dB = out->volume;
+ if (out->volume < (SILLY_LOW_VOLUME_DB + 1)) mute = true;
bool headphones = _headphones_connected();
if (headphones) {
diff --git a/python_payload/st3m/processors.py b/python_payload/st3m/processors.py
index 6f7e78b40f27e762274368f48d99005505b6fb08..9ff75199ca348e304d3d64be2f53ce4bec377ca5 100644
--- a/python_payload/st3m/processors.py
+++ b/python_payload/st3m/processors.py
@@ -30,32 +30,14 @@ class AudioProcessor(Processor):
def __init__(self) -> None:
super().__init__()
self.input = InputController()
+ self.volume_step = 1.5
def think(self, ins: InputState, delta_ms: int) -> None:
self.input.think(ins, delta_ms)
- # Whether the volume was adjusted. Used to do a second pass.
- adjusted = False
- # Whether the volume is so low that we should enable mute.
- should_mute = False
if self.input.buttons.os.left.pressed:
- started_at = audio.get_volume_dB()
- if started_at <= -20:
- should_mute = True
- audio.adjust_volume_dB(-5)
- adjusted = True
+ audio.adjust_volume_dB(-self.volume_step)
if self.input.buttons.os.right.pressed:
- if not audio.get_mute():
- audio.adjust_volume_dB(5)
- adjusted = True
- if adjusted:
- # Clamp lower level to -20dB.
- if audio.get_volume_dB() < -20:
- audio.set_volume_dB(-20)
- # Set audio mute
- if should_mute:
- audio.set_mute(True)
- else:
- audio.set_mute(False)
+ audio.adjust_volume_dB(self.volume_step)
class ProcessorMidldeware(Responder):
diff --git a/python_payload/st3m/run.py b/python_payload/st3m/run.py
index 1f22ab7f2fa157b48a72c3b0a20ac869721a893e..bde74b88c3442cca9678b00f9252159f4b346639 100644
--- a/python_payload/st3m/run.py
+++ b/python_payload/st3m/run.py
@@ -145,7 +145,11 @@ def run_main() -> None:
log.info(f"free memory: {gc.mem_free()}")
captouch.calibration_request()
- audio.set_volume_dB(-10) # slightly less loud startup volume
+ # defaults, maybe expose in a config file someday
+ audio.set_volume_dB(-10)
+ audio.headphones_set_minimum_volume_dB(-30)
+ audio.speaker_set_minimum_volume_dB(-30)
+
leds.set_rgb(0, 255, 0, 0)
leds.update()
bundles = BundleManager()
diff --git a/python_payload/st3m/ui/elements/overlays.py b/python_payload/st3m/ui/elements/overlays.py
index c3ae78c7d437469b84684520a8a6404c27822ff6..88b61784b364627f1a290e7c8393197e2347b182 100644
--- a/python_payload/st3m/ui/elements/overlays.py
+++ b/python_payload/st3m/ui/elements/overlays.py
@@ -302,17 +302,9 @@ class OverlayVolume(Overlay):
return False
def think(self, ins: InputState, delta_ms: int) -> None:
- self._volume = audio.get_volume_dB()
+ self._volume = audio.get_volume_relative()
self._headphones = audio.headphones_are_connected()
- self._muted = audio.get_mute()
- if self._headphones:
- # -20 ... +3dB
- self._volume += 20
- self._volume /= 20 + 3
- else:
- # -20 ... +14dB
- self._volume += 20
- self._volume /= 20 + 14
+ self._muted = (self._volume == 0) or audio.get_mute()
if self._started:
if self.changed():
@@ -380,10 +372,7 @@ class OverlayVolume(Overlay):
ctx.line_width = 2
ctx.stroke()
- v = self._volume
- v = min(max(v, 0), 1)
-
- width = 60 * v
+ width = 60 * self._volume
ctx.round_rectangle(-30, 20, width, 10, 3)
ctx.fill()
diff --git a/sim/fakes/audio.py b/sim/fakes/audio.py
index 1f4e885b9a5a938a5e552901e0c5e6bd8ba5f4f9..0633298f348d4ddd25be7c13e4e99d9e195d1613 100644
--- a/sim/fakes/audio.py
+++ b/sim/fakes/audio.py
@@ -12,6 +12,18 @@ def get_volume_dB() -> float:
return _volume
+def get_volume_relative() -> float:
+ return 0
+
+
+def headphones_set_minimum_volume_dB(v: float) -> None:
+ pass
+
+
+def speaker_set_minimum_volume_dB(v: float) -> None:
+ pass
+
+
def adjust_volume_dB(v) -> float:
global _volume
_volume += v