soundd: fix long wav playback and mic feedback (#38155)

fix soundd long duration playback and mic feedback
This commit is contained in:
Daniel Koepping
2026-06-09 16:37:45 -07:00
committed by GitHub
parent 41390a95b8
commit 24d373062d
+6 -3
View File
@@ -110,6 +110,8 @@ class Soundd:
ret[written_frames:written_frames+frames_to_write] = sound_data[current_sound_frame:current_sound_frame+frames_to_write]
written_frames += frames_to_write
self.current_sound_frame += frames_to_write
current_sound_frame = self.current_sound_frame % len(sound_data)
loops = self.current_sound_frame // len(sound_data)
return ret * self.current_volume
@@ -119,7 +121,7 @@ class Soundd:
data_out[:frames, 0] = self.get_sound_data(frames)
def update_alert(self, new_alert):
current_alert_played_once = self.current_alert == AudibleAlert.none or self.current_sound_frame > len(self.loaded_sounds[self.current_alert])
current_alert_played_once = self.current_alert == AudibleAlert.none or self.current_sound_frame >= len(self.loaded_sounds[self.current_alert])
if self.current_alert != new_alert and (new_alert != AudibleAlert.none or current_alert_played_once):
if new_alert == AudibleAlert.warningImmediate:
self.ramp_start_volume = self.current_volume
@@ -162,10 +164,11 @@ class Soundd:
while True:
sm.update(0)
# Always update volume, even when alert is playing
# freeze volume during alerts to avoid mic feedback increasing volume
if sm.updated['soundPressure']:
self.spl_filter_weighted.update(sm["soundPressure"].soundPressureWeightedDb)
self.current_volume = self.calculate_volume(float(self.spl_filter_weighted.x))
if self.current_alert == AudibleAlert.none:
self.current_volume = self.calculate_volume(float(self.spl_filter_weighted.x))
self.get_audible_alert(sm)