QT UI: sounds (#2078)
* move android into own dir * fix name * maybe this works? qt ui doesn't work on mac * fix that * pc sound works * fix pc build * lowercase * that needs to be real_arch * split into classes * fix typo in lib * Fix cycle alerts * Add qt multimedia libs to install scripts * Add ui/android folder * Fix android build * Raise exception if sound init fails * add missing return Co-authored-by: Willem Melching <willem.melching@gmail.com> Co-authored-by: Comma Device <device@comma.ai>pull/2097/head
parent
9eca642c76
commit
acd1bde496
16 changed files with 178 additions and 100 deletions
@ -0,0 +1,26 @@ |
||||
#pragma once |
||||
#include <SLES/OpenSLES.h> |
||||
#include <SLES/OpenSLES_Android.h> |
||||
|
||||
#include "sound.hpp" |
||||
|
||||
|
||||
class SLSound : public Sound { |
||||
public: |
||||
SLSound(); |
||||
~SLSound(); |
||||
bool play(AudibleAlert alert); |
||||
void stop(); |
||||
void setVolume(int volume); |
||||
|
||||
private: |
||||
bool init(); |
||||
SLObjectItf engine_ = nullptr; |
||||
SLObjectItf outputMix_ = nullptr; |
||||
int last_volume_ = 0; |
||||
double last_set_volume_time_ = 0.; |
||||
AudibleAlert currentSound_ = AudibleAlert::NONE; |
||||
struct Player; |
||||
std::map<AudibleAlert, Player *> player_; |
||||
friend void SLAPIENTRY slplay_callback(SLPlayItf playItf, void *context, SLuint32 event); |
||||
}; |
@ -0,0 +1,29 @@ |
||||
#include <QUrl> |
||||
#include "qt/qt_sound.hpp" |
||||
|
||||
QtSound::QtSound() { |
||||
for (auto &kv : sound_map) { |
||||
auto path = QUrl::fromLocalFile(kv.second.first); |
||||
sounds[kv.first].setSource(path); |
||||
} |
||||
} |
||||
|
||||
bool QtSound::play(AudibleAlert alert) { |
||||
sounds[alert].setLoopCount(sound_map[alert].second); |
||||
sounds[alert].play(); |
||||
return true; |
||||
} |
||||
|
||||
void QtSound::stop() { |
||||
for (auto &kv : sounds) { |
||||
kv.second.stop(); |
||||
} |
||||
} |
||||
|
||||
void QtSound::setVolume(int volume) { |
||||
// TODO: implement this
|
||||
} |
||||
|
||||
QtSound::~QtSound() { |
||||
|
||||
} |
@ -0,0 +1,16 @@ |
||||
#pragma once |
||||
|
||||
#include <QSoundEffect> |
||||
#include "sound.hpp" |
||||
|
||||
class QtSound : public Sound { |
||||
public: |
||||
QtSound(); |
||||
~QtSound(); |
||||
bool play(AudibleAlert alert); |
||||
void stop(); |
||||
void setVolume(int volume); |
||||
|
||||
private: |
||||
std::map<AudibleAlert, QSoundEffect> sounds; |
||||
}; |
Loading…
Reference in new issue