mirror of
https://github.com/dragonpilot/dragonpilot.git
synced 2026-06-24 23:42:05 +08:00
sound cleanup (#20491)
* fix high CPU usage when playing repeated sounds * fix build * fix cpu usage * same behavior for now Co-authored-by: Comma Device <device@comma.ai>
This commit is contained in:
@@ -16,7 +16,7 @@ if arch == "Darwin":
|
||||
qt_env['FRAMEWORKS'] += ['OpenCL']
|
||||
|
||||
widgets_src = ["qt/widgets/input.cc", "qt/widgets/drive_stats.cc",
|
||||
"qt/widgets/ssh_keys.cc", "qt/widgets/toggle.cc", "qt/widgets/controls.cc", "qt/qt_sound.cc",
|
||||
"qt/widgets/ssh_keys.cc", "qt/widgets/toggle.cc", "qt/widgets/controls.cc", "qt/sound.cc",
|
||||
"qt/widgets/offroad_alerts.cc", "qt/widgets/setup.cc", "qt/widgets/keyboard.cc",
|
||||
"#phonelibs/qrcode/QrCode.cc"]
|
||||
if arch != 'aarch64':
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include <QTimer>
|
||||
#include <QWidget>
|
||||
|
||||
#include "qt_sound.hpp"
|
||||
#include "sound.hpp"
|
||||
#include "ui/ui.hpp"
|
||||
#include "widgets/offroad_alerts.hpp"
|
||||
|
||||
@@ -38,7 +38,7 @@ private:
|
||||
QTimer* timer;
|
||||
QTimer* backlight_timer;
|
||||
|
||||
QtSound sound;
|
||||
Sound sound;
|
||||
|
||||
bool onroad = true;
|
||||
double prev_draw_t = 0;
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <QSoundEffect>
|
||||
#include "sound.hpp"
|
||||
|
||||
class QtSound : public Sound {
|
||||
public:
|
||||
QtSound();
|
||||
bool play(AudibleAlert alert);
|
||||
void stop();
|
||||
void setVolume(int volume);
|
||||
float volume = 0;
|
||||
|
||||
private:
|
||||
std::map<AudibleAlert, QSoundEffect> sounds;
|
||||
};
|
||||
@@ -1,22 +1,21 @@
|
||||
#include <QUrl>
|
||||
#include "qt_sound.hpp"
|
||||
#include "sound.hpp"
|
||||
|
||||
QtSound::QtSound() {
|
||||
Sound::Sound() {
|
||||
for (auto &kv : sound_map) {
|
||||
auto path = QUrl::fromLocalFile(kv.second.first);
|
||||
sounds[kv.first].setSource(path);
|
||||
}
|
||||
}
|
||||
|
||||
bool QtSound::play(AudibleAlert alert) {
|
||||
void Sound::play(AudibleAlert alert) {
|
||||
int loops = sound_map[alert].second> - 1 ? sound_map[alert].second : QSoundEffect::Infinite;
|
||||
sounds[alert].setLoopCount(loops);
|
||||
sounds[alert].setVolume(volume);
|
||||
sounds[alert].play();
|
||||
return true;
|
||||
}
|
||||
|
||||
void QtSound::stop() {
|
||||
void Sound::stop() {
|
||||
for (auto &kv : sounds) {
|
||||
// Only stop repeating sounds
|
||||
if (sound_map[kv.first].second != 0) {
|
||||
@@ -24,7 +23,3 @@ void QtSound::stop() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void QtSound::setVolume(int volume) {
|
||||
// TODO: implement this
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <QSoundEffect>
|
||||
#include "cereal/gen/cpp/log.capnp.h"
|
||||
|
||||
typedef cereal::CarControl::HUDControl::AudibleAlert AudibleAlert;
|
||||
@@ -18,8 +20,11 @@ static std::map<AudibleAlert, std::pair<const char *, int>> sound_map {
|
||||
|
||||
class Sound {
|
||||
public:
|
||||
virtual ~Sound() {}
|
||||
virtual bool play(AudibleAlert alert) = 0;
|
||||
virtual void stop() = 0;
|
||||
virtual void setVolume(int volume) = 0;
|
||||
Sound();
|
||||
void play(AudibleAlert alert);
|
||||
void stop();
|
||||
float volume = 0;
|
||||
|
||||
private:
|
||||
std::map<AudibleAlert, QSoundEffect> sounds;
|
||||
};
|
||||
+1
-1
@@ -25,7 +25,7 @@
|
||||
#include "common/params.h"
|
||||
#include "common/glutil.h"
|
||||
#include "common/transformations/orientation.hpp"
|
||||
#include "sound.hpp"
|
||||
#include "qt/sound.hpp"
|
||||
#include "visionipc.h"
|
||||
#include "visionipc_client.h"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user