mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-12 23:35:33 +08:00
Replace QAudioDeviceInfo with CAudioDeviceInfo where possible
QAudioDeviceInfo is a low level technical class, which shouldn't be used in higher level code. Remove it from all APIs where possible and just create it in order to interface with QAudio
This commit is contained in:
committed by
Mat Sutcliffe
parent
8656131eb1
commit
a2e3700739
@@ -15,6 +15,7 @@
|
||||
#include <QtGlobal>
|
||||
#include <QStringBuilder>
|
||||
#include <QDebug>
|
||||
#include <QAudioDeviceInfo>
|
||||
#include <cmath>
|
||||
|
||||
using namespace BlackMisc;
|
||||
@@ -90,21 +91,40 @@ namespace BlackCore
|
||||
m_encoder.setBitRate(16 * 1024);
|
||||
}
|
||||
|
||||
void CInput::start(const QAudioDeviceInfo &inputDevice)
|
||||
void CInput::start(const BlackMisc::Audio::CAudioDeviceInfo &inputDevice)
|
||||
{
|
||||
if (m_started) { return; }
|
||||
|
||||
m_device = inputDevice;
|
||||
QAudioDeviceInfo selectedDevice;
|
||||
if (inputDevice.isDefault())
|
||||
{
|
||||
selectedDevice = QAudioDeviceInfo::defaultInputDevice();
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: Add smart algorithm to find the device with lowest latency
|
||||
const QList<QAudioDeviceInfo> inputDevices = QAudioDeviceInfo::availableDevices(QAudio::AudioInput);
|
||||
for (const QAudioDeviceInfo &d : inputDevices)
|
||||
{
|
||||
if (d.deviceName() == inputDevice.getName())
|
||||
{
|
||||
selectedDevice = d;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_inputFormat.setSampleRate(m_sampleRate);
|
||||
m_inputFormat.setChannelCount(1);
|
||||
m_inputFormat.setSampleSize(16);
|
||||
m_inputFormat.setSampleType(QAudioFormat::SignedInt);
|
||||
m_inputFormat.setByteOrder(QAudioFormat::LittleEndian);
|
||||
m_inputFormat.setCodec("audio/pcm");
|
||||
if (!inputDevice.isFormatSupported(m_inputFormat))
|
||||
if (!selectedDevice.isFormatSupported(m_inputFormat))
|
||||
{
|
||||
m_inputFormat = inputDevice.nearestFormat(m_inputFormat);
|
||||
m_inputFormat = selectedDevice.nearestFormat(m_inputFormat);
|
||||
const QString w =
|
||||
inputDevice.deviceName() %
|
||||
selectedDevice.deviceName() %
|
||||
": Default INPUT format not supported - trying to use nearest" %
|
||||
" Sample rate: " % QString::number(m_inputFormat.sampleRate()) %
|
||||
" Sample size: " % QString::number(m_inputFormat.sampleSize()) %
|
||||
@@ -115,7 +135,7 @@ namespace BlackCore
|
||||
CLogMessage(this).warning(w);
|
||||
}
|
||||
|
||||
m_audioInput.reset(new QAudioInput(inputDevice, m_inputFormat));
|
||||
m_audioInput.reset(new QAudioInput(selectedDevice, m_inputFormat));
|
||||
m_audioInputBuffer.start();
|
||||
|
||||
m_audioInput->start(&m_audioInputBuffer);
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
|
||||
#include "blacksound/sampleprovider/bufferedwaveprovider.h"
|
||||
#include "blacksound/codecs/opusencoder.h"
|
||||
#include "blackmisc/audio/audiodeviceinfo.h"
|
||||
|
||||
#include <QAudioDeviceInfo>
|
||||
#include <QAudioInput>
|
||||
#include <QString>
|
||||
#include <QDateTime>
|
||||
@@ -70,7 +70,6 @@ namespace BlackCore
|
||||
|
||||
struct InputVolumeStreamArgs
|
||||
{
|
||||
QAudioDeviceInfo DeviceNumber;
|
||||
double PeakRaw = 0.0;
|
||||
double PeakDB = -1.0 * std::numeric_limits<double>::infinity();
|
||||
double PeakVU = 0.0;
|
||||
@@ -101,13 +100,13 @@ namespace BlackCore
|
||||
bool started() const { return m_started; }
|
||||
|
||||
//! Start
|
||||
void start(const QAudioDeviceInfo &inputDevice);
|
||||
void start(const BlackMisc::Audio::CAudioDeviceInfo &inputDevice);
|
||||
|
||||
//! Stop
|
||||
void stop();
|
||||
|
||||
//! Corresponding device
|
||||
const QAudioDeviceInfo &device() const { return m_device; }
|
||||
const BlackMisc::Audio::CAudioDeviceInfo &device() const { return m_device; }
|
||||
|
||||
signals:
|
||||
//! Volume stream data
|
||||
@@ -124,7 +123,7 @@ namespace BlackCore
|
||||
|
||||
BlackSound::Codecs::COpusEncoder m_encoder;
|
||||
QScopedPointer<QAudioInput> m_audioInput;
|
||||
QAudioDeviceInfo m_device;
|
||||
BlackMisc::Audio::CAudioDeviceInfo m_device;
|
||||
QAudioFormat m_inputFormat;
|
||||
|
||||
bool m_started = false;
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include <cmath>
|
||||
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::Audio;
|
||||
using namespace BlackSound;
|
||||
using namespace BlackSound::SampleProvider;
|
||||
|
||||
@@ -81,11 +82,32 @@ namespace BlackCore
|
||||
Output::Output(QObject *parent) : QObject(parent)
|
||||
{ }
|
||||
|
||||
void Output::start(const QAudioDeviceInfo &outputDevice, ISampleProvider *sampleProvider)
|
||||
void Output::start(const CAudioDeviceInfo &outputDevice, ISampleProvider *sampleProvider)
|
||||
{
|
||||
if (m_started) { return; }
|
||||
|
||||
m_audioOutputBuffer = new CAudioOutputBuffer(sampleProvider, this);
|
||||
connect(m_audioOutputBuffer, &CAudioOutputBuffer::outputVolumeStream, this, &Output::outputVolumeStream);
|
||||
|
||||
m_device = outputDevice;
|
||||
QAudioDeviceInfo selectedDevice;
|
||||
if (outputDevice.isDefault())
|
||||
{
|
||||
selectedDevice = QAudioDeviceInfo::defaultOutputDevice();
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: Add smart algorithm to find the device with lowest latency
|
||||
const QList<QAudioDeviceInfo> outputDevices = QAudioDeviceInfo::availableDevices(QAudio::AudioOutput);
|
||||
for (const QAudioDeviceInfo &d : outputDevices)
|
||||
{
|
||||
if (d.deviceName() == outputDevice.getName())
|
||||
{
|
||||
selectedDevice = d;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QAudioFormat outputFormat;
|
||||
outputFormat.setSampleRate(48000);
|
||||
outputFormat.setChannelCount(1);
|
||||
@@ -94,11 +116,11 @@ namespace BlackCore
|
||||
outputFormat.setByteOrder(QAudioFormat::LittleEndian);
|
||||
outputFormat.setCodec("audio/pcm");
|
||||
|
||||
if (!outputDevice.isFormatSupported(outputFormat))
|
||||
if (!selectedDevice.isFormatSupported(outputFormat))
|
||||
{
|
||||
outputFormat = outputDevice.nearestFormat(outputFormat);
|
||||
outputFormat = selectedDevice.nearestFormat(outputFormat);
|
||||
const QString w =
|
||||
outputDevice.deviceName() %
|
||||
selectedDevice.deviceName() %
|
||||
": Default OUTPUT format not supported - trying to use nearest" %
|
||||
" Sample rate: " % QString::number(outputFormat.sampleRate()) %
|
||||
" Sample size: " % QString::number(outputFormat.sampleSize()) %
|
||||
@@ -109,7 +131,7 @@ namespace BlackCore
|
||||
CLogMessage(this).warning(w);
|
||||
}
|
||||
|
||||
m_audioOutputCom.reset(new QAudioOutput(outputDevice, outputFormat));
|
||||
m_audioOutputCom.reset(new QAudioOutput(selectedDevice, outputFormat));
|
||||
// m_audioOutput->setBufferSize(bufferSize);
|
||||
m_audioOutputBuffer->open(QIODevice::ReadWrite | QIODevice::Unbuffered);
|
||||
m_audioOutputBuffer->setAudioFormat(outputFormat);
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
#define BLACKCORE_AFV_AUDIO_OUTPUT_H
|
||||
|
||||
#include "blacksound/sampleprovider/sampleprovider.h"
|
||||
#include "blackmisc/audio/audiodeviceinfo.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QAudioDeviceInfo>
|
||||
#include <QAudioOutput>
|
||||
|
||||
namespace BlackCore
|
||||
@@ -26,7 +26,6 @@ namespace BlackCore
|
||||
//! Stream args
|
||||
struct OutputVolumeStreamArgs
|
||||
{
|
||||
QAudioDeviceInfo DeviceNumber;
|
||||
double PeakRaw = 0.0;
|
||||
double PeakDB = -1 * std::numeric_limits<double>::infinity();
|
||||
double PeakVU = 0.0;
|
||||
@@ -82,13 +81,13 @@ namespace BlackCore
|
||||
}
|
||||
|
||||
//! Start output
|
||||
void start(const QAudioDeviceInfo &outputDevice, BlackSound::SampleProvider::ISampleProvider *sampleProvider);
|
||||
void start(const BlackMisc::Audio::CAudioDeviceInfo &outputDevice, BlackSound::SampleProvider::ISampleProvider *sampleProvider);
|
||||
|
||||
//! Stop output
|
||||
void stop();
|
||||
|
||||
//! Corresponding device
|
||||
const QAudioDeviceInfo &device() const { return m_device; }
|
||||
const BlackMisc::Audio::CAudioDeviceInfo &device() const { return m_device; }
|
||||
|
||||
signals:
|
||||
//! Streaming data
|
||||
@@ -97,7 +96,7 @@ namespace BlackCore
|
||||
private:
|
||||
bool m_started = false;
|
||||
|
||||
QAudioDeviceInfo m_device;
|
||||
BlackMisc::Audio::CAudioDeviceInfo m_device;
|
||||
QScopedPointer<QAudioOutput> m_audioOutputCom;
|
||||
CAudioOutputBuffer *m_audioOutputBuffer = nullptr;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user