1
0
mirror of https://github.com/binary-kitchen/doorlockd synced 2024-12-22 02:14:26 +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:
Ralf Ramsauer 2015-10-11 19:33:19 +02:00
parent 811917b334
commit 5c8ca78c99
3 changed files with 37 additions and 13 deletions

View File

@ -3,6 +3,8 @@
#include <string>
#include <thread>
#include <ao/ao.h>
#include <boost/asio.hpp>
#include <boost/program_options.hpp>
@ -164,8 +166,17 @@ int main(int argc, char** argv)
app.setOrganizationName("Binary Kitchen");
app.setApplicationName("doorlock-client");
mainWindow = std::unique_ptr<MainWindow>(new MainWindow);
mainWindow->showFullScreen();
ao_initialize();
try {
mainWindow = std::unique_ptr<MainWindow>(new MainWindow);
mainWindow->showFullScreen();
}
catch(const std::exception &e)
{
l(LogLevel::error, e.what());
exit(-1);
}
// Start the TCP client as thread
std::thread clientThread = std::thread([&] () {
@ -199,6 +210,8 @@ int main(int argc, char** argv)
if (mainWindow)
mainWindow.reset();
ao_shutdown();
l(LogLevel::notice, "Stopping doorlock-client");
return 0;
}

View File

@ -3,15 +3,17 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"
#define PLAY(file) \
system("play -q " file " &")
MainWindow::MainWindow(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);
_LED(false);
}
@ -31,23 +33,23 @@ void MainWindow::setClientmessage(const Clientmessage &msg)
if (_oldMessage.isOpen() && !msg.isOpen()) {
// regular close
PLAY(SOUND_LOCK);
_soundLock.playAsync();
} else if (!_oldMessage.isOpen() && msg.isOpen()) {
// regular open
PLAY(SOUND_UNLOCK);
_soundUnlock.playAsync();
} else {
// no change
}
if (doormsg.isEmergencyUnlock) {
PLAY(SOUND_EMERGENCY_UNLOCK);
_soundEmergencyUnlock.playAsync();
} else if (doormsg.isLockButton) {
PLAY(SOUND_LOCK_BUTTON);
_soundLockButton.playAsync();
} else if (doormsg.isUnlockButton) {
if (msg.isOpen()) {
PLAY(SOUND_ZONK);
_soundZonk.playAsync();
} else {
PLAY(SOUND_UNLOCK_BUTTON);
_soundUnlockButton.playAsync();
}
}

View File

@ -2,7 +2,9 @@
#define MAINWINDOW_H
#include <QWidget>
#include "../lib/clientmessage.h"
#include "wave.h"
namespace Ui {
class MainWindow;
@ -27,6 +29,13 @@ private:
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);
};