Verified Commit 441a5632 authored by Phobos D'thorga's avatar Phobos D'thorga 🐲
Browse files

* Changes made to how the audio devices are handled throughout the playback and recording sections.

parent f84305c3
Pipeline #1023 passed with stages
in 30 minutes and 55 seconds
......@@ -203,6 +203,8 @@ namespace GekkoFyre {
#define AUDIO_PLAYBACK_CODEC_FLAC_IDX (2)
#define AUDIO_RECORDING_DEF_BITRATE (192)
#define AUDIO_RECORDING_SOURCE_INPUT_IDX (0)
#define AUDIO_RECORDING_SOURCE_OUTPUT_IDX (1)
//
// Mostly regarding FFTW functions
......
......@@ -227,7 +227,7 @@ void GkAudioEncoding::startCaller(const QFileInfo &media_path, const Database::S
m_frameSize = frame_size;
if (audio_dev_info.default_input_dev) {
if (audio_dev_info.audio_src == GkAudioSource::Input) {
//
// Input device
m_channels = gkAudioInput->format().channelCount();
......@@ -257,7 +257,7 @@ void GkAudioEncoding::startCaller(const QFileInfo &media_path, const Database::S
//
// Ogg Opus
//
if (audio_dev_info.default_input_dev) {
if (audio_dev_info.audio_src == GkAudioSource::Input) {
//
// Input device
if (m_audioInEncodeThread.joinable()) {
......@@ -268,7 +268,7 @@ void GkAudioEncoding::startCaller(const QFileInfo &media_path, const Database::S
std::ref(bitrate), std::ref(audio_dev_info.chosen_sample_rate),
std::ref(frame_size));
m_audioInEncodeThread.detach();
} else if (audio_dev_info.default_output_dev) {
} else if (audio_dev_info.audio_src == GkAudioSource::Output) {
//
// Output device
if (m_audioOutEncodeThread.joinable()) {
......@@ -288,7 +288,7 @@ void GkAudioEncoding::startCaller(const QFileInfo &media_path, const Database::S
//
// Ogg Vorbis
//
if (audio_dev_info.default_input_dev) {
if (audio_dev_info.audio_src == GkAudioSource::Input) {
//
// Input device
if (m_audioInEncodeThread.joinable()) {
......@@ -299,7 +299,7 @@ void GkAudioEncoding::startCaller(const QFileInfo &media_path, const Database::S
std::ref(bitrate), std::ref(audio_dev_info.chosen_sample_rate),
std::ref(frame_size));
m_audioInEncodeThread.detach();
} else if (audio_dev_info.default_output_dev) {
} else if (audio_dev_info.audio_src == GkAudioSource::Output) {
//
// Output device
if (m_audioOutEncodeThread.joinable()) {
......@@ -319,7 +319,7 @@ void GkAudioEncoding::startCaller(const QFileInfo &media_path, const Database::S
//
// FLAC
//
if (audio_dev_info.default_input_dev) {
if (audio_dev_info.audio_src == GkAudioSource::Input) {
//
// Input device
if (m_audioInEncodeThread.joinable()) {
......@@ -330,7 +330,7 @@ void GkAudioEncoding::startCaller(const QFileInfo &media_path, const Database::S
std::ref(bitrate), std::ref(audio_dev_info.chosen_sample_rate),
std::ref(frame_size));
m_audioInEncodeThread.detach();
} else if (audio_dev_info.default_output_dev) {
} else if (audio_dev_info.audio_src == GkAudioSource::Output) {
//
// Output device
if (m_audioOutEncodeThread.joinable()) {
......
......@@ -61,16 +61,16 @@ using namespace Security;
/**
* @author Phobos A. D'thorga <phobos.gekko@gekkofyre.io>
*/
GkPaAudioPlayer::GkPaAudioPlayer(QPointer<GekkoFyre::GkLevelDb> database, const GkDevice &output_device, const GkDevice &input_device,
QPointer<QAudioOutput> audioOutput, QPointer<QAudioInput> audioInput,
QPointer<GekkoFyre::GkAudioEncoding> audioEncoding, const QPointer<GekkoFyre::GkEventLogger> &eventLogger,
GkPaAudioPlayer::GkPaAudioPlayer(QPointer<GekkoFyre::GkLevelDb> database, QPointer<QAudioOutput> audioOutput,
QPointer<QAudioInput> audioInput, QPointer<GekkoFyre::GkAudioEncoding> audioEncoding,
const QPointer<GekkoFyre::GkEventLogger> &eventLogger,
std::shared_ptr<AudioFile<double>> audioFileLib, QObject *parent)
{
gkAudioInput = std::move(audioInput);
gkAudioOutput = std::move(audioOutput);
gkAudioEncoding = std::move(audioEncoding);
gkAudioFile = std::move(audioFileLib);
streamHandler = new GkPaStreamHandler(std::move(database), output_device, input_device, gkAudioOutput, gkAudioInput, gkAudioEncoding, eventLogger, gkAudioFile, parent);;
streamHandler = new GkPaStreamHandler(std::move(database), gkAudioOutput, gkAudioInput, gkAudioEncoding, eventLogger, gkAudioFile, parent);;
return;
}
......@@ -83,10 +83,11 @@ GkPaAudioPlayer::~GkPaAudioPlayer()
* @author Phobos A. D'thorga <phobos.gekko@gekkofyre.io>
* @param audio_file
*/
void GkPaAudioPlayer::play(const GkAudioFramework::CodecSupport &supported_codec, const QFileInfo &audio_file)
void GkPaAudioPlayer::play(const GkAudioFramework::CodecSupport &supported_codec, const QFileInfo &audio_file,
const GkDevice &audio_device)
{
try {
streamHandler->processEvent(GkAudioFramework::AudioEventType::start, audio_file, supported_codec, false);
streamHandler->processEvent(GkAudioFramework::AudioEventType::start, audio_device, audio_file, supported_codec, false);
} catch (const std::exception &e) {
std::throw_with_nested(std::runtime_error(tr("A stream processing error has occurred with regards to the multimedia library handling functions. Error:\n\n%1")
.arg(QString::fromStdString(e.what())).toStdString()));
......@@ -100,10 +101,10 @@ void GkPaAudioPlayer::play(const GkAudioFramework::CodecSupport &supported_codec
* @author Phobos A. D'thorga <phobos.gekko@gekkofyre.io>
* @param supported_codec
*/
void GkPaAudioPlayer::play(const GkAudioFramework::CodecSupport &supported_codec)
void GkPaAudioPlayer::play(const GkAudioFramework::CodecSupport &supported_codec, const GkDevice &audio_device)
{
try {
streamHandler->processEvent(GkAudioFramework::AudioEventType::start, QFileInfo(), supported_codec, false);
streamHandler->processEvent(GkAudioFramework::AudioEventType::start, audio_device, QFileInfo(), supported_codec, false);
} catch (const std::exception &e) {
std::throw_with_nested(std::runtime_error(tr("A stream processing error has occurred with regards to the multimedia library handling functions. Error:\n\n%1")
.arg(QString::fromStdString(e.what())).toStdString()));
......@@ -118,11 +119,14 @@ void GkPaAudioPlayer::play(const GkAudioFramework::CodecSupport &supported_codec
* @author Phobos A. D'thorga <phobos.gekko@gekkofyre.io>
* @param supported_codec The codec to use when creating the recording, whether it be Opus, PCM, FLAC, etc.
* @param record_dir The directory to which recordings are to be saved towards.
* @param audio_device The audio device to record from, which is either the input or output, or even a mix of the
* aforementioned two.
*/
void GkPaAudioPlayer::record(const CodecSupport &supported_codec, const QDir &record_dir)
void GkPaAudioPlayer::record(const CodecSupport &supported_codec, const QDir &record_dir, const GkDevice &audio_device)
{
try {
streamHandler->processEvent(GkAudioFramework::AudioEventType::record, record_dir, supported_codec, false);
streamHandler->processEvent(GkAudioFramework::AudioEventType::record, audio_device, record_dir,
supported_codec, false);
} catch (const std::exception &e) {
std::throw_with_nested(std::runtime_error(tr("A stream processing error has occurred with regards to the multimedia library handling functions. Error:\n\n%1")
.arg(QString::fromStdString(e.what())).toStdString()));
......@@ -136,10 +140,11 @@ void GkPaAudioPlayer::record(const CodecSupport &supported_codec, const QDir &re
* @author Phobos A. D'thorga <phobos.gekko@gekkofyre.io>
* @param audio_file
*/
void GkPaAudioPlayer::loop(const GkAudioFramework::CodecSupport &supported_codec, const QFileInfo &audio_file)
void GkPaAudioPlayer::loop(const GkAudioFramework::CodecSupport &supported_codec, const QFileInfo &audio_file,
const GkDevice &audio_device)
{
try {
streamHandler->processEvent(GkAudioFramework::AudioEventType::start, audio_file, supported_codec, true);
streamHandler->processEvent(GkAudioFramework::AudioEventType::start, audio_device, audio_file, supported_codec, true);
} catch (const std::exception &e) {
std::throw_with_nested(std::runtime_error(tr("A stream processing error has occurred with regards to the multimedia library handling functions. Error:\n\n%1")
.arg(QString::fromStdString(e.what())).toStdString()));
......@@ -153,10 +158,10 @@ void GkPaAudioPlayer::loop(const GkAudioFramework::CodecSupport &supported_codec
* @author Phobos A. D'thorga <phobos.gekko@gekkofyre.io>
* @param audio_file
*/
void GkPaAudioPlayer::stop(const QFileInfo &audio_file)
void GkPaAudioPlayer::stop(const QFileInfo &audio_file, const GkDevice &audio_device)
{
try {
streamHandler->processEvent(GkAudioFramework::AudioEventType::stop, audio_file);
streamHandler->processEvent(GkAudioFramework::AudioEventType::stop, audio_device, audio_file);
} catch (const std::exception &e) {
std::throw_with_nested(std::runtime_error(tr("A stream processing error has occurred with regards to the multimedia library handling functions. Error:\n\n%1")
.arg(QString::fromStdString(e.what())).toStdString()));
......@@ -172,7 +177,7 @@ void GkPaAudioPlayer::stop(const QFileInfo &audio_file)
void GkPaAudioPlayer::loopback()
{
try {
streamHandler->processEvent(GkAudioFramework::AudioEventType::loopback, QFileInfo());
streamHandler->processEvent(GkAudioFramework::AudioEventType::loopback, GkDevice(), QFileInfo());
} catch (const std::exception &e) {
std::throw_with_nested(std::runtime_error(tr("A stream processing error has occurred with regards to the multimedia library handling functions. Error:\n\n%1")
.arg(QString::fromStdString(e.what())).toStdString()));
......
......@@ -62,19 +62,21 @@ class GkPaAudioPlayer : public QObject {
Q_OBJECT
public:
explicit GkPaAudioPlayer(QPointer<GekkoFyre::GkLevelDb> database, const GekkoFyre::Database::Settings::Audio::GkDevice &output_device,
const GekkoFyre::Database::Settings::Audio::GkDevice &input_device,
QPointer<QAudioOutput> audioOutput, QPointer<QAudioInput> audioInput,
QPointer<GekkoFyre::GkAudioEncoding> audioEncoding,
explicit GkPaAudioPlayer(QPointer<GekkoFyre::GkLevelDb> database, QPointer<QAudioOutput> audioOutput,
QPointer<QAudioInput> audioInput, QPointer<GekkoFyre::GkAudioEncoding> audioEncoding,
const QPointer<GekkoFyre::GkEventLogger> &eventLogger,
std::shared_ptr<AudioFile<double>> audioFileLib, QObject *parent = nullptr);
virtual ~GkPaAudioPlayer();
void play(const GekkoFyre::GkAudioFramework::CodecSupport &supported_codec, const QFileInfo &audio_file);
void play(const GekkoFyre::GkAudioFramework::CodecSupport &supported_codec);
void record(const GekkoFyre::GkAudioFramework::CodecSupport &supported_codec, const QDir &record_dir);
void loop(const GekkoFyre::GkAudioFramework::CodecSupport &supported_codec, const QFileInfo &audio_file);
void stop(const QFileInfo &audio_file);
void play(const GekkoFyre::GkAudioFramework::CodecSupport &supported_codec, const QFileInfo &audio_file,
const GekkoFyre::Database::Settings::Audio::GkDevice &audio_device);
void play(const GekkoFyre::GkAudioFramework::CodecSupport &supported_codec,
const GekkoFyre::Database::Settings::Audio::GkDevice &audio_device);
void record(const GekkoFyre::GkAudioFramework::CodecSupport &supported_codec, const QDir &record_dir,
const GekkoFyre::Database::Settings::Audio::GkDevice &audio_device);
void loop(const GekkoFyre::GkAudioFramework::CodecSupport &supported_codec, const QFileInfo &audio_file,
const GekkoFyre::Database::Settings::Audio::GkDevice &audio_device);
void stop(const QFileInfo &audio_file, const GekkoFyre::Database::Settings::Audio::GkDevice &audio_device);
void loopback();
private:
......
......@@ -67,8 +67,7 @@ using namespace Security;
* @author Phobos A. D'thorga <phobos.gekko@gekkofyre.io>
* @note <https://qtsource.wordpress.com/2011/09/12/multithreaded-audio-using-qaudiooutput/>.
*/
GkPaStreamHandler::GkPaStreamHandler(QPointer<GekkoFyre::GkLevelDb> database, const GkDevice &output_device,
const GkDevice &input_device, QPointer<QAudioOutput> audioOutput,
GkPaStreamHandler::GkPaStreamHandler(QPointer<GekkoFyre::GkLevelDb> database, QPointer<QAudioOutput> audioOutput,
QPointer<QAudioInput> audioInput, QPointer<GekkoFyre::GkAudioEncoding> audioEncoding,
QPointer<GekkoFyre::GkEventLogger> eventLogger, std::shared_ptr<AudioFile<double>> audioFileLib,
QObject *parent) : QObject(parent)
......@@ -85,8 +84,6 @@ GkPaStreamHandler::GkPaStreamHandler(QPointer<GekkoFyre::GkLevelDb> database, co
//
// Initialize variables
//
pref_output_device = output_device;
pref_input_device = input_device;
gkPcmFileStream = std::make_unique<GkPcmFileStream>(this);
QObject::connect(gkAudioOutput, SIGNAL(stateChanged(QAudio::State)), this, SLOT(playbackHandleStateChanged(QAudio::State)));
......@@ -94,10 +91,10 @@ GkPaStreamHandler::GkPaStreamHandler(QPointer<GekkoFyre::GkLevelDb> database, co
//
// Playing of multimedia files
QObject::connect(this, SIGNAL(playMedia(const QFileInfo &, const GekkoFyre::GkAudioFramework::CodecSupport &)),
this, SLOT(playMediaFile(const QFileInfo &, const GekkoFyre::GkAudioFramework::CodecSupport &)));
QObject::connect(this, SIGNAL(playMedia(const QDir &, const GekkoFyre::GkAudioFramework::CodecSupport &)),
this, SLOT(playMediaFile(const QDir &, const GekkoFyre::GkAudioFramework::CodecSupport &)));
QObject::connect(this, SIGNAL(playMedia(const QFileInfo &, const GekkoFyre::GkAudioFramework::CodecSupport &, const GekkoFyre::Database::Settings::Audio::GkDevice &)),
this, SLOT(playMediaFile(const QFileInfo &, const GekkoFyre::GkAudioFramework::CodecSupport &, const GekkoFyre::Database::Settings::Audio::GkDevice &)));
QObject::connect(this, SIGNAL(playMedia(const QDir &, const GekkoFyre::GkAudioFramework::CodecSupport &, const GekkoFyre::Database::Settings::Audio::GkDevice &)),
this, SLOT(playMediaFile(const QDir &, const GekkoFyre::GkAudioFramework::CodecSupport &, const GekkoFyre::Database::Settings::Audio::GkDevice &)));
//
// Stopping of either playing or recording of multimedia files
......@@ -106,10 +103,10 @@ GkPaStreamHandler::GkPaStreamHandler(QPointer<GekkoFyre::GkLevelDb> database, co
//
// Recording of multimedia files
QObject::connect(this, SIGNAL(recordMedia(const QFileInfo &, const GekkoFyre::GkAudioFramework::CodecSupport &, qint32)),
this, SLOT(recordMediaFile(const QFileInfo &, const GekkoFyre::GkAudioFramework::CodecSupport &, qint32)));
QObject::connect(this, SIGNAL(recordMedia(const QDir &, const GekkoFyre::GkAudioFramework::CodecSupport &, qint32)),
this, SLOT(recordMediaFile(const QDir &, const GekkoFyre::GkAudioFramework::CodecSupport &, qint32)));
QObject::connect(this, SIGNAL(recordMedia(const QFileInfo &, const GekkoFyre::GkAudioFramework::CodecSupport &, qint32, const GekkoFyre::Database::Settings::Audio::GkDevice &)),
this, SLOT(recordMediaFile(const QFileInfo &, const GekkoFyre::GkAudioFramework::CodecSupport &, qint32, const GekkoFyre::Database::Settings::Audio::GkDevice &)));
QObject::connect(this, SIGNAL(recordMedia(const QDir &, const GekkoFyre::GkAudioFramework::CodecSupport &, qint32, const GekkoFyre::Database::Settings::Audio::GkDevice &)),
this, SLOT(recordMediaFile(const QDir &, const GekkoFyre::GkAudioFramework::CodecSupport &, qint32, const GekkoFyre::Database::Settings::Audio::GkDevice &)));
//
// Changing the playback state of multimedia files (i.e. for recording, playing, etc.)
......@@ -140,14 +137,17 @@ GkPaStreamHandler::~GkPaStreamHandler()
* @brief GkPaStreamHandler::processEvent
* @author Phobos A. D'thorga <phobos.gekko@gekkofyre.io>
* @param audioEventType
* @param audio_device The audio device to record from, which is either the input or output, or even a mix of the
* aforementioned two.
* @param mediaFilePath
* @param supported_codec
* @param loop_media
* @param encode_bitrate The bitrate to use when encoding/recording an audio signal, with a format like Opus or Ogg
* Vorbis, for example. This is only used for recording purposes at the moment.
*/
void GkPaStreamHandler::processEvent(GkAudioFramework::AudioEventType audioEventType, const QFileInfo &mediaFilePath,
const CodecSupport &supported_codec, bool loop_media, qint32 encode_bitrate)
void GkPaStreamHandler::processEvent(GkAudioFramework::AudioEventType audioEventType, const GkDevice &audio_device,
const QFileInfo &mediaFilePath, const CodecSupport &supported_codec,
bool loop_media, qint32 encode_bitrate)
{
Q_UNUSED(loop_media);
try {
......@@ -156,14 +156,14 @@ void GkPaStreamHandler::processEvent(GkAudioFramework::AudioEventType audioEvent
{
if (mediaFilePath.isReadable()) {
gkSounds.insert(mediaFilePath.path(), *gkAudioFile);
emit playMedia(mediaFilePath, supported_codec);
emit playMedia(mediaFilePath, supported_codec, audio_device);
}
}
break;
case GkAudioFramework::AudioEventType::record:
if (mediaFilePath.isReadable()) {
emit recordMedia(mediaFilePath, supported_codec, encode_bitrate);
emit recordMedia(mediaFilePath, supported_codec, encode_bitrate, audio_device);
}
break;
......@@ -190,14 +190,17 @@ void GkPaStreamHandler::processEvent(GkAudioFramework::AudioEventType audioEvent
* @brief GkPaStreamHandler::processEvent
* @author Phobos A. D'thorga <phobos.gekko@gekkofyre.io>
* @param audioEventType
* @param audio_device The audio device to record from, which is either the input or output, or even a mix of the
* aforementioned two.
* @param mediaFilePath
* @param supported_codec
* @param loop_media
* @param encode_bitrate The bitrate to use when encoding/recording an audio signal, with a format like Opus or Ogg
* Vorbis, for example. This is only used for recording purposes at the moment.
*/
void GkPaStreamHandler::processEvent(GkAudioFramework::AudioEventType audioEventType, const QDir &mediaFilePath,
const CodecSupport &supported_codec, bool loop_media, qint32 encode_bitrate)
void GkPaStreamHandler::processEvent(GkAudioFramework::AudioEventType audioEventType, const GkDevice &audio_device,
const QDir &mediaFilePath, const CodecSupport &supported_codec, bool loop_media,
qint32 encode_bitrate)
{
Q_UNUSED(loop_media);
try {
......@@ -206,14 +209,14 @@ void GkPaStreamHandler::processEvent(GkAudioFramework::AudioEventType audioEvent
{
if (mediaFilePath.isReadable()) {
gkSounds.insert(mediaFilePath.path(), *gkAudioFile);
emit playMedia(mediaFilePath, supported_codec);
emit playMedia(mediaFilePath, supported_codec, audio_device);
}
}
break;
case GkAudioFramework::AudioEventType::record:
if (mediaFilePath.isReadable()) {
emit recordMedia(mediaFilePath, supported_codec, encode_bitrate);
emit recordMedia(mediaFilePath, supported_codec, encode_bitrate, audio_device);
}
break;
......@@ -242,9 +245,10 @@ void GkPaStreamHandler::processEvent(GkAudioFramework::AudioEventType audioEvent
* @param media_path
* @param supported_codec
*/
void GkPaStreamHandler::playMediaFile(const QFileInfo &media_path, const GkAudioFramework::CodecSupport &supported_codec)
void GkPaStreamHandler::playMediaFile(const QFileInfo &media_path, const GkAudioFramework::CodecSupport &supported_codec,
const GkDevice &audio_device)
{
playMediaFileHelper(media_path, supported_codec);
playMediaFileHelper(media_path, supported_codec, audio_device);
return;
}
......@@ -254,10 +258,10 @@ void GkPaStreamHandler::playMediaFile(const QFileInfo &media_path, const GkAudio
* @param media_path
* @param supported_codec
*/
void GkPaStreamHandler::playMediaFile(const QDir &media_path, const CodecSupport &supported_codec)
void GkPaStreamHandler::playMediaFile(const QDir &media_path, const CodecSupport &supported_codec, const GkDevice &audio_device)
{
const QFileInfo file_info_tmp(media_path.path());
playMediaFileHelper(file_info_tmp, supported_codec);
playMediaFileHelper(file_info_tmp, supported_codec, audio_device);
return;
}
......@@ -270,9 +274,9 @@ void GkPaStreamHandler::playMediaFile(const QDir &media_path, const CodecSupport
* @param encoding_bitrate The bitrate at which to encode with (i.e. 192 kbit/sec).
*/
void GkPaStreamHandler::recordMediaFile(const QFileInfo &media_path, const GkAudioFramework::CodecSupport &supported_codec,
qint32 encoding_bitrate)
qint32 encoding_bitrate, const GkDevice &audio_device)
{
recordMediaFileHelper(media_path, supported_codec, encoding_bitrate);
recordMediaFileHelper(media_path, supported_codec, encoding_bitrate, audio_device);
return;
}
......@@ -284,10 +288,10 @@ void GkPaStreamHandler::recordMediaFile(const QFileInfo &media_path, const GkAud
* @param encoding_bitrate The bitrate at which to encode with (i.e. 192 kbit/sec).
*/
void GkPaStreamHandler::recordMediaFile(const QDir &media_path, const CodecSupport &supported_codec,
qint32 encoding_bitrate)
qint32 encoding_bitrate, const GkDevice &audio_device)
{
const QFileInfo file_info_tmp(media_path.path());
recordMediaFileHelper(file_info_tmp, supported_codec, encoding_bitrate);
recordMediaFileHelper(file_info_tmp, supported_codec, encoding_bitrate, audio_device);
return;
}
......@@ -448,7 +452,8 @@ QFileInfo GkPaStreamHandler::createRecordMediaFile(const QDir &media_path, const
* @param media_path
* @param supported_codec
*/
void GkPaStreamHandler::playMediaFileHelper(const QFileInfo &media_path, const CodecSupport &supported_codec)
void GkPaStreamHandler::playMediaFileHelper(const QFileInfo &media_path, const CodecSupport &supported_codec,
const GkDevice &audio_device)
{
try {
if (gkAudioOutput.isNull()) {
......@@ -458,7 +463,7 @@ void GkPaStreamHandler::playMediaFileHelper(const QFileInfo &media_path, const C
for (auto media = gkSounds.begin(); media != gkSounds.end(); ++media) {
if (media.key() == media_path.path()) {
if (!gkPcmFileStream->init(pref_output_device.audio_device_info.preferredFormat())) {
if (!gkPcmFileStream->init(audio_device.audio_device_info.preferredFormat())) {
throw std::runtime_error(tr("Error whilst initializing output audio stream!").toStdString());
}
}
......@@ -507,11 +512,11 @@ void GkPaStreamHandler::playMediaFileHelper(const QFileInfo &media_path, const C
* @param encoding_bitrate The bitrate at which to encode with (i.e. 192 kbit/sec).
*/
void GkPaStreamHandler::recordMediaFileHelper(const QFileInfo &media_path, const CodecSupport &supported_codec,
qint32 encoding_bitrate)
qint32 encoding_bitrate, const GkDevice &audio_device)
{
try {
if (encoding_bitrate >= 8) {
if (pref_input_device.is_enabled) {
if (audio_device.is_enabled) {
//
// Make use of the Input Audio Device!
if (supported_codec == CodecSupport::Opus) {
......@@ -521,7 +526,7 @@ void GkPaStreamHandler::recordMediaFileHelper(const QFileInfo &media_path, const
//
// Use a differing FRAME SIZE for Opus!
emit initEncode(m_mediaFile, pref_input_device, encoding_bitrate, supported_codec, AUDIO_OPUS_MAX_FRAME_SIZE);
emit initEncode(m_mediaFile, audio_device, encoding_bitrate, supported_codec, AUDIO_OPUS_MAX_FRAME_SIZE);
} else {
//
// Create a media file with a randomized name within the given path, for recording purposes!
......@@ -529,7 +534,7 @@ void GkPaStreamHandler::recordMediaFileHelper(const QFileInfo &media_path, const
//
// PCM, Ogg Vorbis, etc.
emit initEncode(m_mediaFile, pref_input_device, encoding_bitrate, supported_codec, AUDIO_FRAMES_PER_BUFFER);
emit initEncode(m_mediaFile, audio_device, encoding_bitrate, supported_codec, AUDIO_FRAMES_PER_BUFFER);
}
procMediaEventLoop = new QEventLoop(this);
......@@ -537,7 +542,7 @@ void GkPaStreamHandler::recordMediaFileHelper(const QFileInfo &media_path, const
procMediaEventLoop->exec(QEventLoop::WaitForMoreEvents);
} while (gkAudioInput->state() == QAudio::ActiveState);
delete procMediaEventLoop;
} else if (pref_output_device.is_enabled) {
} else if (audio_device.is_enabled) {
//
// Make use of the Output Audio Device!
if (supported_codec == CodecSupport::Opus) {
......@@ -547,7 +552,7 @@ void GkPaStreamHandler::recordMediaFileHelper(const QFileInfo &media_path, const
//
// Use a differing FRAME SIZE for Opus!
emit initEncode(m_mediaFile, pref_output_device, encoding_bitrate, supported_codec, AUDIO_OPUS_MAX_FRAME_SIZE);
emit initEncode(m_mediaFile, audio_device, encoding_bitrate, supported_codec, AUDIO_OPUS_MAX_FRAME_SIZE);
} else {
//
// Create a media file with a randomized name within the given path, for recording purposes!
......@@ -555,7 +560,7 @@ void GkPaStreamHandler::recordMediaFileHelper(const QFileInfo &media_path, const
//
// PCM, Ogg Vorbis, etc.
emit initEncode(m_mediaFile, pref_output_device, encoding_bitrate, supported_codec, AUDIO_FRAMES_PER_BUFFER);
emit initEncode(m_mediaFile, audio_device, encoding_bitrate, supported_codec, AUDIO_FRAMES_PER_BUFFER);
}
procMediaEventLoop = new QEventLoop(this);
......
......@@ -70,30 +70,31 @@ class GkPaStreamHandler : public QObject {
Q_OBJECT
public:
explicit GkPaStreamHandler(QPointer<GekkoFyre::GkLevelDb> database, const GekkoFyre::Database::Settings::Audio::GkDevice &output_device,
const GekkoFyre::Database::Settings::Audio::GkDevice &input_device, QPointer<QAudioOutput> audioOutput,
explicit GkPaStreamHandler(QPointer<GekkoFyre::GkLevelDb> database, QPointer<QAudioOutput> audioOutput,
QPointer<QAudioInput> audioInput, QPointer<GekkoFyre::GkAudioEncoding> audioEncoding,
QPointer<GekkoFyre::GkEventLogger> eventLogger, std::shared_ptr<AudioFile<double>> audioFileLib,
QObject *parent = nullptr);
~GkPaStreamHandler() override;
void processEvent(GkAudioFramework::AudioEventType audioEventType, const QFileInfo &mediaFilePath = QFileInfo(),
const GekkoFyre::GkAudioFramework::CodecSupport &supported_codec = GekkoFyre::GkAudioFramework::CodecSupport::Unknown,
void processEvent(GkAudioFramework::AudioEventType audioEventType, const GekkoFyre::Database::Settings::Audio::GkDevice &audio_device,
const QFileInfo &mediaFilePath = QFileInfo(), const GekkoFyre::GkAudioFramework::CodecSupport &supported_codec = GekkoFyre::GkAudioFramework::CodecSupport::Unknown,
bool loop_media = false, qint32 encode_bitrate = 8);
void processEvent(GkAudioFramework::AudioEventType audioEventType, const QDir &mediaFilePath = QDir(),
const GekkoFyre::GkAudioFramework::CodecSupport &supported_codec = GekkoFyre::GkAudioFramework::CodecSupport::Unknown,
void processEvent(GkAudioFramework::AudioEventType audioEventType, const GekkoFyre::Database::Settings::Audio::GkDevice &audio_device,
const QDir &mediaFilePath = QDir(), const GekkoFyre::GkAudioFramework::CodecSupport &supported_codec = GekkoFyre::GkAudioFramework::CodecSupport::Unknown,
bool loop_media = false, qint32 encode_bitrate = 8);
QFileInfo createRecordMediaFile(const QFileInfo &media_path, const GkAudioFramework::CodecSupport &supported_codec);
QFileInfo createRecordMediaFile(const QDir &media_path, const GkAudioFramework::CodecSupport &supported_codec);
private slots:
void playMediaFile(const QFileInfo &media_path, const GekkoFyre::GkAudioFramework::CodecSupport &supported_codec);
void playMediaFile(const QDir &media_path, const GekkoFyre::GkAudioFramework::CodecSupport &supported_codec);
void playMediaFile(const QFileInfo &media_path, const GekkoFyre::GkAudioFramework::CodecSupport &supported_codec,
const GekkoFyre::Database::Settings::Audio::GkDevice &audio_device);
void playMediaFile(const QDir &media_path, const GekkoFyre::GkAudioFramework::CodecSupport &supported_codec,
const GekkoFyre::Database::Settings::Audio::GkDevice &audio_device);
void recordMediaFile(const QFileInfo &media_path, const GekkoFyre::GkAudioFramework::CodecSupport &supported_codec,
qint32 encoding_bitrate);
qint32 encoding_bitrate, const GekkoFyre::Database::Settings::Audio::GkDevice &audio_device);
void recordMediaFile(const QDir &media_path, const GekkoFyre::GkAudioFramework::CodecSupport &supported_codec,
qint32 encoding_bitrate);
qint32 encoding_bitrate, const GekkoFyre::Database::Settings::Audio::GkDevice &audio_device);
void stopMediaFile(const QFileInfo &media_path);
void startMediaLoopback();
void playbackHandleStateChanged(QAudio::State changed_state);
......@@ -102,13 +103,17 @@ private slots:
signals:
//
// Playing of multimedia files
void playMedia(const QFileInfo &media_path, const GekkoFyre::GkAudioFramework::CodecSupport &supported_codec);
void playMedia(const QDir &media_path, const GekkoFyre::GkAudioFramework::CodecSupport &supported_codec);
void playMedia(const QFileInfo &media_path, const GekkoFyre::GkAudioFramework::CodecSupport &supported_codec,
const GekkoFyre::Database::Settings::Audio::GkDevice &audio_device);
void playMedia(const QDir &media_path, const GekkoFyre::GkAudioFramework::CodecSupport &supported_codec,
const GekkoFyre::Database::Settings::Audio::GkDevice &audio_device);
//
// Recording of multimedia files
void recordMedia(const QFileInfo &media_path, const GekkoFyre::GkAudioFramework::CodecSupport &supported_codec, qint32 encoding_bitrate);
void recordMedia(const QDir &media_path, const GekkoFyre::GkAudioFramework::CodecSupport &supported_codec, qint32 encoding_bitrate);
void recordMedia(const QFileInfo &media_path, const GekkoFyre::GkAudioFramework::CodecSupport &supported_codec, qint32 encoding_bitrate,
const GekkoFyre::Database::Settings::Audio::GkDevice &audio_device);
void recordMedia(const QDir &media_path, const GekkoFyre::GkAudioFramework::CodecSupport &supported_codec, qint32 encoding_bitrate,
const GekkoFyre::Database::Settings::Audio::GkDevice &audio_device);
//
// Stopping of either playing or recording of multimedia files
......@@ -150,13 +155,12 @@ private:
QPointer<QEventLoop> procMediaEventLoop;
QPointer<QAudioInput> gkAudioInput;
QPointer<QAudioOutput> gkAudioOutput;
GekkoFyre::Database::Settings::Audio::GkDevice pref_output_device;
GekkoFyre::Database::Settings::Audio::GkDevice pref_input_device;
QMap<QString, AudioFile<double>> gkSounds;
void playMediaFileHelper(const QFileInfo &media_path, const GekkoFyre::GkAudioFramework::CodecSupport &supported_codec);
void playMediaFileHelper(const QFileInfo &media_path, const GekkoFyre::GkAudioFramework::CodecSupport &supported_codec,
const GekkoFyre::Database::Settings::Audio::GkDevice &audio_device);
void recordMediaFileHelper(const QFileInfo &media_path, const GekkoFyre::GkAudioFramework::CodecSupport &supported_codec,
qint32 encoding_bitrate);
qint32 encoding_bitrate, const GekkoFyre::Database::Settings::Audio::GkDevice &audio_device);
};
};
......@@ -92,7 +92,7 @@ GkAudioPlayDialog::GkAudioPlayDialog(QPointer<GkLevelDb> database,
m_rec_codec_chosen = CodecSupport::PCM;
m_encode_bitrate_chosen = 8;
gkAudioFile = std::make_shared<AudioFile<double>>();
gkPaAudioPlayer = new GkPaAudioPlayer(gkDb, pref_output_device, pref_input_device, gkAudioOutput, gkAudioInput, gkAudioEncoding, gkEventLogger, gkAudioFile, this);
gkPaAudioPlayer = new GkPaAudioPlayer(gkDb, gkAudioOutput, gkAudioInput, gkAudioEncoding, gkEventLogger, gkAudioFile, this);
//
// QPushButtons, etc.
......@@ -103,18 +103,22 @@ GkAudioPlayDialog::GkAudioPlayDialog(QPointer<GkLevelDb> database,
audio_out_skip_fwd = false;
audio_out_skip_bck = false;
pref_input_device.audio_src = GkAudioSource::Input;
pref_output_device.audio_src = GkAudioSource::Output;
prefillCodecComboBoxes(GkAudioFramework::CodecSupport::OggVorbis);
prefillCodecComboBoxes(GkAudioFramework::CodecSupport::FLAC);
prefillCodecComboBoxes(GkAudioFramework::CodecSupport::Opus);
prefillCodecComboBoxes(GkAudioFramework::CodecSupport::PCM);
prefillCodecComboBoxes(GkAudioFramework::CodecSupport::Loopback);
prefillAudioSourceComboBoxes();
}
GkAudioPlayDialog::~GkAudioPlayDialog()
{
emit recStatus(GkAudioRecordStatus::Defunct);
if (audio_out_play) {
gkPaAudioPlayer->stop(gkAudioFileInfo.audio_file_path);
gkPaAudioPlayer->stop(gkAudioFileInfo.audio_file_path, GkDevice());
gkEventLogger->publishEvent(tr("Stopped playing audio file, \"%1\"").arg(gkAudioFileInfo.audio_file_path.fileName()), GkSeverity::Info, "", true, true, true, false);
}
......@@ -188,7 +192,7 @@ void GkAudioPlayDialog::on_pushButton_playback_stop_clicked()
{
if (!audio_out_stop) {
gkStringFuncs->changePushButtonColor(ui->pushButton_playback_stop, false);
gkPaAudioPlayer->stop(gkAudioFileInfo.audio_file_path);
gkPaAudioPlayer->stop(gkAudioFileInfo.audio_file_path, GkDevice());
gkEventLogger->publishEvent(tr("Stopped playing audio file, \"%1\"").arg(gkAudioFileInfo.audio_file_path.fileName()), GkSeverity::Info, "", true, true, true, false);
audio_out_stop = true;
......@@ -262,13 +266,13 @@ void GkAudioPlayDialog::on_pushButton_playback_play_clicked()
GkAudioFramework::CodecSupport codec_used = gkDb->convCodecSupportFromIdxToEnum(ui->comboBox_playback_rec_codec->currentData().toInt());
if (gkAudioFileInfo.audio_file_path.exists() && codec_used != GkAudioFramework::CodecSupport::Loopback) {
gkPaAudioPlayer->play(codec_used, gkAudioFileInfo.audio_file_path.filePath());
audioPlaybackHelper(codec_used, gkAudioFileInfo.audio_file_path.filePath());
gkEventLogger->publishEvent(
tr("Started playing audio file, \"%1\"").arg(gkAudioFileInfo.audio_file_path.filePath()),
GkSeverity::Info, "", true, true, true, false);
ui->progressBar_playback->setFormat(tr("%p%")); // Modify the QProgressBar to display the correct text!