mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-20 20:40:29 +08:00
Expanded voice sample to an interactive app
refs #36 - Based on the existing network sample, expanded the voice sample to an interactive app - Implmenented commands: mic test, squelch test refs #81
This commit is contained in:
committed by
Mathew Sutcliffe
parent
7292e265fb
commit
f91525b65b
102
samples/voiceclient/client.cpp
Normal file
102
samples/voiceclient/client.cpp
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
/* Copyright (C) 2013 VATSIM Community / authors
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
#include "client.h"
|
||||||
|
|
||||||
|
Client::Client(QObject *parent) :
|
||||||
|
QObject(parent),
|
||||||
|
m_voiceClient(&BlackMisc::IContext::getInstance().getObject<BlackCore::IVoiceClient>())
|
||||||
|
{
|
||||||
|
using namespace BlackCore;
|
||||||
|
connect(m_voiceClient, &IVoiceClient::squelchTestFinished, this, &Client::onSquelchTestFinished);
|
||||||
|
connect(m_voiceClient, &IVoiceClient::micTestFinished, this, &Client::onMicTestFinished);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
using namespace std::placeholders;
|
||||||
|
m_commands["help"] = std::bind(&Client::help, this, _1);
|
||||||
|
m_commands["echo"] = std::bind(&Client::echo, this, _1);
|
||||||
|
m_commands["exit"] = std::bind(&Client::exit, this, _1);
|
||||||
|
m_commands["runsquelchtest"] = std::bind(&Client::runSquelchTest, this, _1);
|
||||||
|
m_commands["runmictest"] = std::bind(&Client::runMicTest, this, _1);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Client::command(QString line)
|
||||||
|
{
|
||||||
|
QTextStream stream(&line, QIODevice::ReadOnly);
|
||||||
|
QString cmd;
|
||||||
|
stream >> cmd;
|
||||||
|
stream.skipWhiteSpace();
|
||||||
|
|
||||||
|
auto found = m_commands.find(cmd);
|
||||||
|
if (found == m_commands.end())
|
||||||
|
{
|
||||||
|
std::cout << "No such command" << std::endl;
|
||||||
|
printLinePrefix();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
(*found)(stream);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Client::printLinePrefix()
|
||||||
|
{
|
||||||
|
std::cout << "voice> ";
|
||||||
|
std::cout.flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************/
|
||||||
|
/************ Commands *************/
|
||||||
|
/****************************************************************************/
|
||||||
|
|
||||||
|
void Client::help(QTextStream &)
|
||||||
|
{
|
||||||
|
std::cout << "Commands:" << std::endl;
|
||||||
|
auto keys = m_commands.keys();
|
||||||
|
for (auto i = keys.begin(); i != keys.end(); ++i)
|
||||||
|
{
|
||||||
|
std::cout << " " << i->toStdString() << std::endl;
|
||||||
|
}
|
||||||
|
printLinePrefix();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Client::echo(QTextStream &line)
|
||||||
|
{
|
||||||
|
std::cout << "echo: " << line.readAll().toStdString() << std::endl;
|
||||||
|
printLinePrefix();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Client::exit(QTextStream &)
|
||||||
|
{
|
||||||
|
emit quit();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Client::runSquelchTest(QTextStream &args)
|
||||||
|
{
|
||||||
|
std::cout << "Running squelch test. Please be quiet for 5 seconds..." << std::endl;
|
||||||
|
printLinePrefix();
|
||||||
|
m_voiceClient->runSquelchTest();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Client::runMicTest(QTextStream &args)
|
||||||
|
{
|
||||||
|
std::cout << "Running mic test. Speak normally for 5 seconds..." << std::endl;
|
||||||
|
printLinePrefix();
|
||||||
|
m_voiceClient->runMicTest();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Client::onSquelchTestFinished()
|
||||||
|
{
|
||||||
|
std::cout << "Input squelch: " << m_voiceClient->inputSquelch() << std::endl;
|
||||||
|
printLinePrefix();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Client::onMicTestFinished()
|
||||||
|
{
|
||||||
|
std::cout << "Mic test result: " << (int)m_voiceClient->micTestResult() << std::endl;
|
||||||
|
printLinePrefix();
|
||||||
|
}
|
||||||
45
samples/voiceclient/client.h
Normal file
45
samples/voiceclient/client.h
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
/* Copyright (C) 2013 VATSIM Community / authors
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
#ifndef CLIENT_H
|
||||||
|
#define CLIENT_H
|
||||||
|
|
||||||
|
#include "blackcore/voiceclient.h"
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QMap>
|
||||||
|
|
||||||
|
class Client : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
Client(QObject *parent = 0);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void quit();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void command(QString line);
|
||||||
|
|
||||||
|
private: //commands
|
||||||
|
void help(QTextStream &args);
|
||||||
|
void echo(QTextStream &args);
|
||||||
|
void exit(QTextStream &args);
|
||||||
|
void runSquelchTest(QTextStream &args);
|
||||||
|
void runMicTest(QTextStream &args);
|
||||||
|
|
||||||
|
void printLinePrefix();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void onSquelchTestFinished();
|
||||||
|
void onMicTestFinished();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QMap<QString, std::function<void(QTextStream &)>> m_commands;
|
||||||
|
BlackCore::IVoiceClient *m_voiceClient;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // CLIENT_H
|
||||||
@@ -4,6 +4,10 @@
|
|||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
#include "blackcore/voiceclient_vatlib.h"
|
#include "blackcore/voiceclient_vatlib.h"
|
||||||
|
|
||||||
|
#include "client.h"
|
||||||
|
#include "reader.h"
|
||||||
|
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
@@ -15,15 +19,12 @@ int main(int argc, char *argv[])
|
|||||||
BlackMisc::IContext::getInstance().setObject(*new BlackMisc::CDebug());
|
BlackMisc::IContext::getInstance().setObject(*new BlackMisc::CDebug());
|
||||||
BlackMisc::IContext::getInstance().setObject<BlackCore::IVoiceClient>(*new BlackCore::CVoiceClientVatlib());
|
BlackMisc::IContext::getInstance().setObject<BlackCore::IVoiceClient>(*new BlackCore::CVoiceClientVatlib());
|
||||||
|
|
||||||
BlackCore::IVoiceClient *voiceClient = BlackMisc::IContext::getInstance().singleton<BlackCore::IVoiceClient>();
|
Client client;
|
||||||
QList<COutputAudioDevice> outputDevices = voiceClient->audioOutputDevices(0);
|
LineReader reader;
|
||||||
|
QObject::connect(&reader, SIGNAL(command(const QString&)), &client, SLOT(command(const QString&)));
|
||||||
qDebug() << "Found " << outputDevices.size() << " output devices:";
|
QObject::connect(&client, SIGNAL(quit()), &reader, SLOT(terminate()));
|
||||||
|
QObject::connect(&client, SIGNAL(quit()), &app, SLOT(quit()));
|
||||||
foreach (COutputAudioDevice device, outputDevices)
|
|
||||||
{
|
|
||||||
qDebug() << device.name();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
reader.start();
|
||||||
app.exec();
|
app.exec();
|
||||||
}
|
}
|
||||||
|
|||||||
24
samples/voiceclient/reader.cpp
Normal file
24
samples/voiceclient/reader.cpp
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
/* Copyright (C) 2013 VATSIM Community / authors
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
|
||||||
|
#include "reader.h"
|
||||||
|
#include <QFile>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
void LineReader::run()
|
||||||
|
{
|
||||||
|
QFile file;
|
||||||
|
file.open(stdin, QIODevice::ReadOnly | QIODevice::Text);
|
||||||
|
forever
|
||||||
|
{
|
||||||
|
std::cout << "voice> ";
|
||||||
|
QString line = file.readLine().trimmed();
|
||||||
|
if (! line.isEmpty())
|
||||||
|
{
|
||||||
|
emit command(line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
25
samples/voiceclient/reader.h
Normal file
25
samples/voiceclient/reader.h
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
/* Copyright (C) 2013 VATSIM Community / authors
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
#ifndef READER_H
|
||||||
|
#define READER_H
|
||||||
|
|
||||||
|
#include <QThread>
|
||||||
|
|
||||||
|
class LineReader : public QThread
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit LineReader() {}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void run();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void command(const QString& line);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // READER_H
|
||||||
@@ -13,7 +13,9 @@ DEPENDPATH += . ../../src
|
|||||||
INCLUDEPATH += . ../../src
|
INCLUDEPATH += . ../../src
|
||||||
|
|
||||||
SOURCES += *.cpp
|
SOURCES += *.cpp
|
||||||
HEADERS += *.h
|
HEADERS += *.h \
|
||||||
|
client.h \
|
||||||
|
reader.h
|
||||||
|
|
||||||
LIBS += -L../../lib -lblackcore -lblackmisc
|
LIBS += -L../../lib -lblackcore -lblackmisc
|
||||||
LIBS += -lvatlib
|
LIBS += -lvatlib
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ namespace BlackCore
|
|||||||
virtual void runMicTest() = 0;
|
virtual void runMicTest() = 0;
|
||||||
|
|
||||||
virtual float inputSquelch() const = 0;
|
virtual float inputSquelch() const = 0;
|
||||||
|
virtual Cvatlib_Voice_Simple::agc micTestResult() const = 0;
|
||||||
|
|
||||||
virtual const BlackMisc::Voice::CVoiceRoom &voiceRoom (const uint32_t comUnit) = 0;
|
virtual const BlackMisc::Voice::CVoiceRoom &voiceRoom (const uint32_t comUnit) = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -177,6 +177,11 @@ namespace BlackCore
|
|||||||
return m_inputSquelch;
|
return m_inputSquelch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Cvatlib_Voice_Simple::agc CVoiceClientVatlib::micTestResult() const
|
||||||
|
{
|
||||||
|
return m_micTestResult;
|
||||||
|
}
|
||||||
|
|
||||||
const BlackMisc::Voice::CVoiceRoom &CVoiceClientVatlib::voiceRoom(const uint32_t comUnit)
|
const BlackMisc::Voice::CVoiceRoom &CVoiceClientVatlib::voiceRoom(const uint32_t comUnit)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -202,7 +207,6 @@ namespace BlackCore
|
|||||||
|
|
||||||
//TODO: store captured squelch
|
//TODO: store captured squelch
|
||||||
m_inputSquelch = m_voice->GetInputSquelch();
|
m_inputSquelch = m_voice->GetInputSquelch();
|
||||||
qDebug() << m_inputSquelch;
|
|
||||||
emit squelchTestFinished();
|
emit squelchTestFinished();
|
||||||
}
|
}
|
||||||
catch (...) { this->exceptionDispatcher(Q_FUNC_INFO); }
|
catch (...) { this->exceptionDispatcher(Q_FUNC_INFO); }
|
||||||
@@ -214,8 +218,7 @@ namespace BlackCore
|
|||||||
{
|
{
|
||||||
Q_ASSERT_X (m_voice->IsValid() && m_voice->IsSetup(), "CVoiceClientVatlib", "Cvatlib_Voice_Simple invalid or not setup!");
|
Q_ASSERT_X (m_voice->IsValid() && m_voice->IsSetup(), "CVoiceClientVatlib", "Cvatlib_Voice_Simple invalid or not setup!");
|
||||||
|
|
||||||
Cvatlib_Voice_Simple::agc micTestResult = m_voice->EndMicTest();
|
m_micTestResult = m_voice->EndMicTest();
|
||||||
qDebug() << micTestResult;
|
|
||||||
emit micTestFinished();
|
emit micTestFinished();
|
||||||
}
|
}
|
||||||
catch (...) { this->exceptionDispatcher(Q_FUNC_INFO); }
|
catch (...) { this->exceptionDispatcher(Q_FUNC_INFO); }
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ namespace BlackCore
|
|||||||
virtual void runMicTest();
|
virtual void runMicTest();
|
||||||
|
|
||||||
virtual float inputSquelch() const;
|
virtual float inputSquelch() const;
|
||||||
|
virtual Cvatlib_Voice_Simple::agc micTestResult() const;
|
||||||
|
|
||||||
|
|
||||||
virtual const BlackMisc::Voice::CVoiceRoom &voiceRoom (const uint32_t comUnit);
|
virtual const BlackMisc::Voice::CVoiceRoom &voiceRoom (const uint32_t comUnit);
|
||||||
@@ -94,6 +95,7 @@ namespace BlackCore
|
|||||||
QList<BlackMisc::Voice::COutputAudioDevice> m_outputDevices;
|
QList<BlackMisc::Voice::COutputAudioDevice> m_outputDevices;
|
||||||
|
|
||||||
float m_inputSquelch;
|
float m_inputSquelch;
|
||||||
|
Cvatlib_Voice_Simple::agc m_micTestResult;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace BlackCore
|
} // namespace BlackCore
|
||||||
|
|||||||
Reference in New Issue
Block a user