mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-02 23:25:53 +08:00
[Audio] Get/set audio device volume (this is the device's value, NOT the logical AFV value)
This commit is contained in:
committed by
Mat Sutcliffe
parent
fc9bb1277d
commit
091fa5f338
@@ -86,6 +86,20 @@ namespace BlackCore
|
||||
return true;
|
||||
}
|
||||
|
||||
double CInput::getDeviceInputVolume() const
|
||||
{
|
||||
if (m_audioInput) { return static_cast<double>(m_audioInput->volume()); }
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
bool CInput::setDeviceInputVolume(double volume)
|
||||
{
|
||||
if (!m_audioInput && m_started) { return false; }
|
||||
const qreal v = normalize0to100qr(volume);
|
||||
m_audioInput->setVolume(v);
|
||||
return true;
|
||||
}
|
||||
|
||||
void CInput::start(const CAudioDeviceInfo &inputDevice)
|
||||
{
|
||||
if (m_started) { return; }
|
||||
|
||||
@@ -64,8 +64,8 @@ namespace BlackCore
|
||||
//! Opus data arguments
|
||||
struct OpusDataAvailableArgs
|
||||
{
|
||||
uint sequenceCounter = 0; //!< sequence counter
|
||||
QByteArray audio; //!< audio data
|
||||
uint sequenceCounter = 0; //!< sequence counter
|
||||
QByteArray audio; //!< audio data
|
||||
};
|
||||
|
||||
//! Input volume stream arguments
|
||||
@@ -101,11 +101,16 @@ namespace BlackCore
|
||||
void setOpusBytesEncoded(int opusBytesEncoded) { m_opusBytesEncoded = opusBytesEncoded; }
|
||||
//! @}
|
||||
|
||||
//! Volume @{
|
||||
//! Volume 0..1 @{
|
||||
double volume() const { return m_volume; }
|
||||
bool setVolume(double volume);
|
||||
//! @}
|
||||
|
||||
//! The device's volume 0..1 @{
|
||||
double getDeviceInputVolume() const;
|
||||
bool setDeviceInputVolume(double volume);
|
||||
//! @}
|
||||
|
||||
//! Started?
|
||||
bool started() const { return m_started; }
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace BlackCore
|
||||
{
|
||||
const int sampleBytes = m_outputFormat.sampleSize() / 8;
|
||||
const int channelCount = m_outputFormat.channelCount();
|
||||
const qint64 count = maxlen / (sampleBytes * channelCount);
|
||||
const qint64 count = maxlen / (sampleBytes * channelCount);
|
||||
QVector<float> buffer;
|
||||
m_sampleProvider->readSamples(buffer, count);
|
||||
|
||||
@@ -70,8 +70,7 @@ namespace BlackCore
|
||||
buffer = convertFromMonoToStereo(buffer);
|
||||
}
|
||||
|
||||
memcpy(data, buffer.constData(), maxlen);
|
||||
|
||||
memcpy(data, buffer.constData(), static_cast<size_t>(maxlen));
|
||||
return maxlen;
|
||||
}
|
||||
|
||||
@@ -111,10 +110,10 @@ namespace BlackCore
|
||||
const QAudioDeviceInfo selectedDevice = getLowestLatencyDevice(outputDevice, outputFormat);
|
||||
CLogMessage(this).info(u"Starting: '%1' with: %2") << selectedDevice.deviceName() << format;
|
||||
|
||||
m_audioOutputCom.reset(new QAudioOutput(selectedDevice, outputFormat));
|
||||
m_audioOutput.reset(new QAudioOutput(selectedDevice, outputFormat));
|
||||
m_audioOutputBuffer->open(QIODevice::ReadWrite | QIODevice::Unbuffered);
|
||||
m_audioOutputBuffer->setAudioFormat(outputFormat);
|
||||
m_audioOutputCom->start(m_audioOutputBuffer);
|
||||
m_audioOutput->start(m_audioOutputBuffer);
|
||||
|
||||
m_started = true;
|
||||
}
|
||||
@@ -123,14 +122,29 @@ namespace BlackCore
|
||||
{
|
||||
if (!m_started) { return; }
|
||||
m_started = false;
|
||||
m_audioOutputCom->stop();
|
||||
m_audioOutputCom.reset();
|
||||
m_audioOutput->stop();
|
||||
m_audioOutput.reset();
|
||||
if (m_audioOutputBuffer)
|
||||
{
|
||||
m_audioOutputBuffer->deleteLater();
|
||||
m_audioOutputBuffer = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
double COutput::getDeviceOutputVolume() const
|
||||
{
|
||||
if (m_audioOutput && m_started) { return static_cast<double>(m_audioOutput->volume()); }
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
bool COutput::setDeviceOutputVolume(double volume)
|
||||
{
|
||||
if (!m_audioOutput) { return false; }
|
||||
const qreal v = normalize0to100qr(volume);
|
||||
m_audioOutput->setVolume(v);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // ns
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
@@ -89,6 +89,11 @@ namespace BlackCore
|
||||
//! Corresponding device
|
||||
const BlackMisc::Audio::CAudioDeviceInfo &device() const { return m_device; }
|
||||
|
||||
//! The device's volume 0..1 @{
|
||||
double getDeviceOutputVolume() const;
|
||||
bool setDeviceOutputVolume(double volume);
|
||||
//! @}
|
||||
|
||||
signals:
|
||||
//! Streaming data
|
||||
void outputVolumeStream(const OutputVolumeStreamArgs &args);
|
||||
@@ -96,7 +101,7 @@ namespace BlackCore
|
||||
private:
|
||||
bool m_started = false;
|
||||
BlackMisc::Audio::CAudioDeviceInfo m_device;
|
||||
QScopedPointer<QAudioOutput> m_audioOutputCom;
|
||||
QScopedPointer<QAudioOutput> m_audioOutput;
|
||||
CAudioOutputBuffer *m_audioOutputBuffer = nullptr;
|
||||
};
|
||||
} // ns
|
||||
|
||||
@@ -357,6 +357,30 @@ namespace BlackCore
|
||||
emit this->stoppedAudio();
|
||||
}
|
||||
|
||||
double CAfvClient::getDeviceInputVolume() const
|
||||
{
|
||||
if (m_input) { return m_input->getDeviceInputVolume(); }
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool CAfvClient::setDeviceInputVolume(double volume)
|
||||
{
|
||||
if (m_input) { return m_input->setDeviceInputVolume(volume); }
|
||||
return false;
|
||||
}
|
||||
|
||||
double CAfvClient::getDeviceOutputVolume() const
|
||||
{
|
||||
if (m_output) { return m_output->getDeviceOutputVolume(); }
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool CAfvClient::setDeviceOutputVolume(double volume)
|
||||
{
|
||||
if (m_output) { return m_output->setDeviceOutputVolume(volume); }
|
||||
return false;
|
||||
}
|
||||
|
||||
void CAfvClient::setReceiveAudio(bool receive)
|
||||
{
|
||||
QMutexLocker lock(&m_mutexConnection);
|
||||
|
||||
@@ -128,6 +128,13 @@ namespace BlackCore
|
||||
void stopAudio();
|
||||
//! @}
|
||||
|
||||
//! The device's volume 0..1 @{
|
||||
double getDeviceInputVolume() const;
|
||||
bool setDeviceInputVolume(double volume);
|
||||
double getDeviceOutputVolume() const;
|
||||
bool setDeviceOutputVolume(double volume);
|
||||
//! @}
|
||||
|
||||
//! Receive audio
|
||||
//! \threadsafe
|
||||
void setReceiveAudio(bool receive);
|
||||
|
||||
Reference in New Issue
Block a user