-
Notifications
You must be signed in to change notification settings - Fork 9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Soundd: move to python #30567
Soundd: move to python #30567
Conversation
jnewb1
commented
Dec 1, 2023
•
edited
Loading
edited
- match c++ impl
- same sound scale? audible test seems equivalent between c++ and python version
- test cpu usage
- cpu usage is higher (1.5% -> 5%), but still reasonable considering it's now in python
6685cb1
to
9c11563
Compare
Looks like this doesn't need it, but if we do need it, Hardware::set_volume needs to be updated to not use pulse. If this doesn't end up needing it, let's just remove it. openpilot/system/hardware/tici/hardware.h Line 75 in afd5877
|
yea we will just remove it and scale the sound within soundd |
|
Why is the CPU now 5%? Is that at idle or constantly playing a sound? 5% is fine on its own, but we should always understand why it increased and why it’s so high. |
at idle, but its constantly streaming zeros even while idle through sounddevice.OutputStream. I can look at switching to the non-streaming api, though looping and stopping at a specific time might be a bit more tricky |
Oh nice, does that make the CPU constant? |
|
||
def new_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]) | ||
if self.current_alert != new_alert and (new_alert != AudibleAlert.none or current_alert_played_once): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this the same as soundd? should consider alertType, alertSize, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should match the current soundd
- let current alert finish if its playing and the alert status goes to none
- newer (non-none) alert overrides old alert even if the old alert hasn't stopped playing
sm = messaging.SubMaster(['controlsState', 'microphone']) | ||
|
||
with sd.OutputStream(device="pulse", channels=1, samplerate=SAMPLE_RATE, callback=self.callback): | ||
while True: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is missing handling of a controlsState timeout
Needs to handle this: Line 78 in 33ee753
We also need to add a unit test for this. |
selfdrive/ui/soundd.py
Outdated
sm = messaging.SubMaster(['controlsState', 'microphone']) | ||
|
||
if PC: | ||
device = "pulse" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we use the default one on PC?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
selfdrive/ui/soundd.py
Outdated
else: | ||
self.update_alert(AudibleAlert.none) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you want to remove this branch. looks like if soundd was running at >100Hz for example, it would cut the sounds immediately after starting them
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is for stopping the timeout alert, I made a flag to make that more clear and also more robust if we are running >100hz
selfdrive/ui/soundd.py
Outdated
assert wavefile.getframerate() == SAMPLE_RATE | ||
|
||
length = wavefile.getnframes() | ||
self.loaded_sounds[sound] = np.frombuffer(wavefile.readframes(length), dtype=np.int16).astype(np.float32) / 32767 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's 32767?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2^16/2 for converting the int16 to float. I put that in
selfdrive/ui/soundd.py
Outdated
AudibleAlert.warningImmediate: ("warning_immediate.wav", None, MAX_VOLUME), | ||
} | ||
|
||
def check_controls_state(sm): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make this name more specific
666f0bb
to
2311290
Compare