mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 08:48:53 +02:00
Fix local injector modifying system volume
This commit is contained in:
parent
d7cc76e48b
commit
1dcc2f7988
6 changed files with 27 additions and 11 deletions
|
@ -981,7 +981,7 @@ void AudioClient::selectAudioSourceSine440() {
|
||||||
_noiseSourceEnabled = false;
|
_noiseSourceEnabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AudioClient::outputLocalInjector(bool isStereo, qreal volume, AudioInjector* injector) {
|
bool AudioClient::outputLocalInjector(bool isStereo, AudioInjector* injector) {
|
||||||
if (injector->getLocalBuffer()) {
|
if (injector->getLocalBuffer()) {
|
||||||
QAudioFormat localFormat = _desiredOutputFormat;
|
QAudioFormat localFormat = _desiredOutputFormat;
|
||||||
localFormat.setChannelCount(isStereo ? 2 : 1);
|
localFormat.setChannelCount(isStereo ? 2 : 1);
|
||||||
|
@ -990,8 +990,6 @@ bool AudioClient::outputLocalInjector(bool isStereo, qreal volume, AudioInjector
|
||||||
localFormat,
|
localFormat,
|
||||||
injector->getLocalBuffer());
|
injector->getLocalBuffer());
|
||||||
|
|
||||||
localOutput->setVolume(volume);
|
|
||||||
|
|
||||||
// move the localOutput to the same thread as the local injector buffer
|
// move the localOutput to the same thread as the local injector buffer
|
||||||
localOutput->moveToThread(injector->getLocalBuffer()->thread());
|
localOutput->moveToThread(injector->getLocalBuffer()->thread());
|
||||||
|
|
||||||
|
|
|
@ -157,7 +157,7 @@ public slots:
|
||||||
|
|
||||||
void setOutputBufferSize(int numFrames);
|
void setOutputBufferSize(int numFrames);
|
||||||
|
|
||||||
virtual bool outputLocalInjector(bool isStereo, qreal volume, AudioInjector* injector);
|
virtual bool outputLocalInjector(bool isStereo, AudioInjector* injector);
|
||||||
|
|
||||||
bool switchInputToAudioDevice(const QString& inputDeviceName);
|
bool switchInputToAudioDevice(const QString& inputDeviceName);
|
||||||
bool switchOutputToAudioDevice(const QString& outputDeviceName);
|
bool switchOutputToAudioDevice(const QString& outputDeviceName);
|
||||||
|
|
|
@ -26,7 +26,7 @@ public:
|
||||||
AbstractAudioInterface(QObject* parent = 0) : QObject(parent) {};
|
AbstractAudioInterface(QObject* parent = 0) : QObject(parent) {};
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
virtual bool outputLocalInjector(bool isStereo, qreal volume, AudioInjector* injector) = 0;
|
virtual bool outputLocalInjector(bool isStereo, AudioInjector* injector) = 0;
|
||||||
|
|
||||||
virtual void enableAudioSourceInject(bool enable) = 0;
|
virtual void enableAudioSourceInject(bool enable) = 0;
|
||||||
virtual void selectAudioSourcePinkNoise() = 0;
|
virtual void selectAudioSourcePinkNoise() = 0;
|
||||||
|
|
|
@ -105,11 +105,12 @@ void AudioInjector::injectLocally() {
|
||||||
|
|
||||||
_localBuffer->open(QIODevice::ReadOnly);
|
_localBuffer->open(QIODevice::ReadOnly);
|
||||||
_localBuffer->setShouldLoop(_options.loop);
|
_localBuffer->setShouldLoop(_options.loop);
|
||||||
|
_localBuffer->setVolume(_options.volume);
|
||||||
|
|
||||||
// give our current send position to the local buffer
|
// give our current send position to the local buffer
|
||||||
_localBuffer->setCurrentOffset(_currentSendPosition);
|
_localBuffer->setCurrentOffset(_currentSendPosition);
|
||||||
|
|
||||||
success = _localAudioInterface->outputLocalInjector(_options.stereo, _options.volume, this);
|
success = _localAudioInterface->outputLocalInjector(_options.stereo, this);
|
||||||
|
|
||||||
// if we're not looping and the buffer tells us it is empty then emit finished
|
// if we're not looping and the buffer tells us it is empty then emit finished
|
||||||
connect(_localBuffer, &AudioInjectorLocalBuffer::bufferEmpty, this, &AudioInjector::stop);
|
connect(_localBuffer, &AudioInjectorLocalBuffer::bufferEmpty, this, &AudioInjector::stop);
|
||||||
|
|
|
@ -16,7 +16,8 @@ AudioInjectorLocalBuffer::AudioInjectorLocalBuffer(const QByteArray& rawAudioArr
|
||||||
_rawAudioArray(rawAudioArray),
|
_rawAudioArray(rawAudioArray),
|
||||||
_shouldLoop(false),
|
_shouldLoop(false),
|
||||||
_isStopped(false),
|
_isStopped(false),
|
||||||
_currentOffset(0)
|
_currentOffset(0),
|
||||||
|
_volume(1.0f)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -35,6 +36,18 @@ bool AudioInjectorLocalBuffer::seek(qint64 pos) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void copy(char* to, char* from, int size, qreal factor) {
|
||||||
|
int16_t* toArray = (int16_t*) to;
|
||||||
|
int16_t* fromArray = (int16_t*) from;
|
||||||
|
int sampleSize = size / sizeof(int16_t);
|
||||||
|
|
||||||
|
for (int i = 0; i < sampleSize; i++) {
|
||||||
|
*toArray = factor * (*fromArray);
|
||||||
|
toArray++;
|
||||||
|
fromArray++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
qint64 AudioInjectorLocalBuffer::readData(char* data, qint64 maxSize) {
|
qint64 AudioInjectorLocalBuffer::readData(char* data, qint64 maxSize) {
|
||||||
if (!_isStopped) {
|
if (!_isStopped) {
|
||||||
|
|
||||||
|
@ -47,7 +60,7 @@ qint64 AudioInjectorLocalBuffer::readData(char* data, qint64 maxSize) {
|
||||||
bytesRead = bytesToEnd;
|
bytesRead = bytesToEnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(data, _rawAudioArray.data() + _currentOffset, bytesRead);
|
copy(data, _rawAudioArray.data() + _currentOffset, bytesRead, _volume);
|
||||||
|
|
||||||
// now check if we are supposed to loop and if we can copy more from the beginning
|
// now check if we are supposed to loop and if we can copy more from the beginning
|
||||||
if (_shouldLoop && maxSize != bytesRead) {
|
if (_shouldLoop && maxSize != bytesRead) {
|
||||||
|
@ -78,7 +91,7 @@ qint64 AudioInjectorLocalBuffer::recursiveReadFromFront(char* data, qint64 maxSi
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy that amount
|
// copy that amount
|
||||||
memcpy(data, _rawAudioArray.data(), bytesRead);
|
copy(data, _rawAudioArray.data(), bytesRead, _volume);
|
||||||
|
|
||||||
// check if we need to call ourselves again and pull from the front again
|
// check if we need to call ourselves again and pull from the front again
|
||||||
if (bytesRead < maxSize) {
|
if (bytesRead < maxSize) {
|
||||||
|
|
|
@ -14,6 +14,8 @@
|
||||||
|
|
||||||
#include <QtCore/qiodevice.h>
|
#include <QtCore/qiodevice.h>
|
||||||
|
|
||||||
|
#include <glm/detail/func_common.hpp>
|
||||||
|
|
||||||
class AudioInjectorLocalBuffer : public QIODevice {
|
class AudioInjectorLocalBuffer : public QIODevice {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
@ -27,12 +29,13 @@ public:
|
||||||
qint64 writeData(const char* data, qint64 maxSize) { return 0; }
|
qint64 writeData(const char* data, qint64 maxSize) { return 0; }
|
||||||
|
|
||||||
void setShouldLoop(bool shouldLoop) { _shouldLoop = shouldLoop; }
|
void setShouldLoop(bool shouldLoop) { _shouldLoop = shouldLoop; }
|
||||||
|
|
||||||
void setCurrentOffset(int currentOffset) { _currentOffset = currentOffset; }
|
void setCurrentOffset(int currentOffset) { _currentOffset = currentOffset; }
|
||||||
|
void setVolume(float volume) { _volume = glm::clamp(volume, 0.0f, 1.0f); }
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void bufferEmpty();
|
void bufferEmpty();
|
||||||
private:
|
|
||||||
|
|
||||||
|
private:
|
||||||
qint64 recursiveReadFromFront(char* data, qint64 maxSize);
|
qint64 recursiveReadFromFront(char* data, qint64 maxSize);
|
||||||
|
|
||||||
QByteArray _rawAudioArray;
|
QByteArray _rawAudioArray;
|
||||||
|
@ -40,6 +43,7 @@ private:
|
||||||
bool _isStopped;
|
bool _isStopped;
|
||||||
|
|
||||||
int _currentOffset;
|
int _currentOffset;
|
||||||
|
float _volume;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_AudioInjectorLocalBuffer_h
|
#endif // hifi_AudioInjectorLocalBuffer_h
|
Loading…
Reference in a new issue