2015-10-11 19:06:05 +02:00
|
|
|
#include <cstring>
|
|
|
|
#include <stdexcept>
|
2015-10-11 19:15:50 +02:00
|
|
|
#include <thread>
|
2015-10-11 19:06:05 +02:00
|
|
|
|
|
|
|
#include "wave.h"
|
|
|
|
|
2016-04-24 22:02:49 +02:00
|
|
|
std::mutex Wave::_playMutex = {};
|
2015-10-11 19:06:05 +02:00
|
|
|
|
2016-04-24 22:02:49 +02:00
|
|
|
Wave::Wave(const std::string &filename):
|
|
|
|
_filename(filename),
|
|
|
|
_command("aplay " + _filename)
|
|
|
|
{
|
2015-10-11 19:06:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Wave::~Wave()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Wave::play() const
|
|
|
|
{
|
2015-10-11 19:15:50 +02:00
|
|
|
std::lock_guard<std::mutex> l(_playMutex);
|
2016-04-24 22:02:49 +02:00
|
|
|
system(_command.c_str());
|
2015-10-11 19:06:05 +02:00
|
|
|
}
|
2015-10-11 19:15:50 +02:00
|
|
|
|
|
|
|
void Wave::playAsync() const
|
|
|
|
{
|
|
|
|
std::thread([this] () {
|
|
|
|
play();
|
|
|
|
}).detach();
|
|
|
|
}
|