mirror of
https://github.com/binary-kitchen/doorlockd
synced 2024-12-22 18:34:25 +01:00
Cached playback of audio files
doorlock_client now caches wave files in memory for faster playback. LibAO is used for audio playback and libsndfile for wave file header parsing.
This commit is contained in:
parent
811917b334
commit
5c8ca78c99
@ -3,6 +3,8 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
|
#include <ao/ao.h>
|
||||||
|
|
||||||
#include <boost/asio.hpp>
|
#include <boost/asio.hpp>
|
||||||
#include <boost/program_options.hpp>
|
#include <boost/program_options.hpp>
|
||||||
|
|
||||||
@ -164,8 +166,17 @@ int main(int argc, char** argv)
|
|||||||
app.setOrganizationName("Binary Kitchen");
|
app.setOrganizationName("Binary Kitchen");
|
||||||
app.setApplicationName("doorlock-client");
|
app.setApplicationName("doorlock-client");
|
||||||
|
|
||||||
|
ao_initialize();
|
||||||
|
|
||||||
|
try {
|
||||||
mainWindow = std::unique_ptr<MainWindow>(new MainWindow);
|
mainWindow = std::unique_ptr<MainWindow>(new MainWindow);
|
||||||
mainWindow->showFullScreen();
|
mainWindow->showFullScreen();
|
||||||
|
}
|
||||||
|
catch(const std::exception &e)
|
||||||
|
{
|
||||||
|
l(LogLevel::error, e.what());
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
// Start the TCP client as thread
|
// Start the TCP client as thread
|
||||||
std::thread clientThread = std::thread([&] () {
|
std::thread clientThread = std::thread([&] () {
|
||||||
@ -199,6 +210,8 @@ int main(int argc, char** argv)
|
|||||||
if (mainWindow)
|
if (mainWindow)
|
||||||
mainWindow.reset();
|
mainWindow.reset();
|
||||||
|
|
||||||
|
ao_shutdown();
|
||||||
|
|
||||||
l(LogLevel::notice, "Stopping doorlock-client");
|
l(LogLevel::notice, "Stopping doorlock-client");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -3,15 +3,17 @@
|
|||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "ui_mainwindow.h"
|
#include "ui_mainwindow.h"
|
||||||
|
|
||||||
#define PLAY(file) \
|
|
||||||
system("play -q " file " &")
|
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent) :
|
MainWindow::MainWindow(QWidget *parent) :
|
||||||
QWidget(parent),
|
QWidget(parent),
|
||||||
ui(new Ui::MainWindow)
|
ui(new Ui::MainWindow),
|
||||||
|
_soundLock(Wave::fromFile(SOUND_LOCK)),
|
||||||
|
_soundUnlock(Wave::fromFile(SOUND_UNLOCK)),
|
||||||
|
_soundEmergencyUnlock(Wave::fromFile(SOUND_EMERGENCY_UNLOCK)),
|
||||||
|
_soundZonk(Wave::fromFile(SOUND_ZONK)),
|
||||||
|
_soundLockButton(Wave::fromFile(SOUND_LOCK_BUTTON)),
|
||||||
|
_soundUnlockButton(Wave::fromFile(SOUND_UNLOCK_BUTTON))
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
_LED(false);
|
_LED(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,23 +33,23 @@ void MainWindow::setClientmessage(const Clientmessage &msg)
|
|||||||
|
|
||||||
if (_oldMessage.isOpen() && !msg.isOpen()) {
|
if (_oldMessage.isOpen() && !msg.isOpen()) {
|
||||||
// regular close
|
// regular close
|
||||||
PLAY(SOUND_LOCK);
|
_soundLock.playAsync();
|
||||||
} else if (!_oldMessage.isOpen() && msg.isOpen()) {
|
} else if (!_oldMessage.isOpen() && msg.isOpen()) {
|
||||||
// regular open
|
// regular open
|
||||||
PLAY(SOUND_UNLOCK);
|
_soundUnlock.playAsync();
|
||||||
} else {
|
} else {
|
||||||
// no change
|
// no change
|
||||||
}
|
}
|
||||||
|
|
||||||
if (doormsg.isEmergencyUnlock) {
|
if (doormsg.isEmergencyUnlock) {
|
||||||
PLAY(SOUND_EMERGENCY_UNLOCK);
|
_soundEmergencyUnlock.playAsync();
|
||||||
} else if (doormsg.isLockButton) {
|
} else if (doormsg.isLockButton) {
|
||||||
PLAY(SOUND_LOCK_BUTTON);
|
_soundLockButton.playAsync();
|
||||||
} else if (doormsg.isUnlockButton) {
|
} else if (doormsg.isUnlockButton) {
|
||||||
if (msg.isOpen()) {
|
if (msg.isOpen()) {
|
||||||
PLAY(SOUND_ZONK);
|
_soundZonk.playAsync();
|
||||||
} else {
|
} else {
|
||||||
PLAY(SOUND_UNLOCK_BUTTON);
|
_soundUnlockButton.playAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,9 @@
|
|||||||
#define MAINWINDOW_H
|
#define MAINWINDOW_H
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
#include "../lib/clientmessage.h"
|
#include "../lib/clientmessage.h"
|
||||||
|
#include "wave.h"
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class MainWindow;
|
class MainWindow;
|
||||||
@ -27,6 +29,13 @@ private:
|
|||||||
|
|
||||||
Clientmessage _oldMessage = { };
|
Clientmessage _oldMessage = { };
|
||||||
|
|
||||||
|
const Wave _soundLock;
|
||||||
|
const Wave _soundUnlock;
|
||||||
|
const Wave _soundEmergencyUnlock;
|
||||||
|
const Wave _soundZonk;
|
||||||
|
const Wave _soundLockButton;
|
||||||
|
const Wave _soundUnlockButton;
|
||||||
|
|
||||||
void _LED(const bool on);
|
void _LED(const bool on);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user