mirror of
https://github.com/lubosz/overte.git
synced 2025-08-08 04:08:13 +02:00
Incorporate ctrlaltdavid's changes.
This commit is contained in:
parent
6d99d50f72
commit
b4dfaba55e
5 changed files with 18 additions and 20 deletions
|
@ -1011,7 +1011,10 @@ bool AudioClient::outputLocalInjector(bool isStereo, AudioInjector* injector) {
|
||||||
localOutput->moveToThread(injector->getLocalBuffer()->thread());
|
localOutput->moveToThread(injector->getLocalBuffer()->thread());
|
||||||
|
|
||||||
// have it be stopped when that local buffer is about to close
|
// have it be stopped when that local buffer is about to close
|
||||||
connect(injector->getLocalBuffer(), &AudioInjectorLocalBuffer::bufferEmpty, localOutput, &QAudioOutput::stop);
|
connect(localOutput, &QAudioOutput::stateChanged, this, &AudioClient::audioStateChanged);
|
||||||
|
connect(this, &AudioClient::audioFinished, localOutput, &QAudioOutput::stop);
|
||||||
|
connect(this, &AudioClient::audioFinished, injector, &AudioInjector::stop);
|
||||||
|
|
||||||
connect(injector->getLocalBuffer(), &QIODevice::aboutToClose, localOutput, &QAudioOutput::stop);
|
connect(injector->getLocalBuffer(), &QIODevice::aboutToClose, localOutput, &QAudioOutput::stop);
|
||||||
|
|
||||||
qCDebug(audioclient) << "Starting QAudioOutput for local injector" << localOutput;
|
qCDebug(audioclient) << "Starting QAudioOutput for local injector" << localOutput;
|
||||||
|
@ -1329,3 +1332,9 @@ void AudioClient::saveSettings() {
|
||||||
windowSecondsForDesiredReduction.set(_receivedAudioStream.getWindowSecondsForDesiredReduction());
|
windowSecondsForDesiredReduction.set(_receivedAudioStream.getWindowSecondsForDesiredReduction());
|
||||||
repetitionWithFade.set(_receivedAudioStream.getRepetitionWithFade());
|
repetitionWithFade.set(_receivedAudioStream.getRepetitionWithFade());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AudioClient::audioStateChanged(QAudio::State state) {
|
||||||
|
if (state == QAudio::IdleState) {
|
||||||
|
emit audioFinished();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -188,6 +188,8 @@ signals:
|
||||||
void receivedFirstPacket();
|
void receivedFirstPacket();
|
||||||
void disconnected();
|
void disconnected();
|
||||||
|
|
||||||
|
void audioFinished();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
AudioClient();
|
AudioClient();
|
||||||
~AudioClient();
|
~AudioClient();
|
||||||
|
@ -196,6 +198,9 @@ protected:
|
||||||
deleteLater();
|
deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void audioStateChanged(QAudio::State state);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void outputFormatChanged();
|
void outputFormatChanged();
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ void AudioInjector::setIsFinished(bool isFinished) {
|
||||||
emit finished();
|
emit finished();
|
||||||
|
|
||||||
if (_localBuffer) {
|
if (_localBuffer) {
|
||||||
// delete will stop (and nosily if we do so ourselves here first).
|
_localBuffer->stop();
|
||||||
_localBuffer->deleteLater();
|
_localBuffer->deleteLater();
|
||||||
_localBuffer = NULL;
|
_localBuffer = NULL;
|
||||||
}
|
}
|
||||||
|
@ -121,9 +121,6 @@ void AudioInjector::injectLocally() {
|
||||||
|
|
||||||
success = _localAudioInterface->outputLocalInjector(_options.stereo, this);
|
success = _localAudioInterface->outputLocalInjector(_options.stereo, this);
|
||||||
|
|
||||||
// if we're not looping and the buffer tells us it is empty then emit finished
|
|
||||||
connect(_localBuffer, &AudioInjectorLocalBuffer::bufferEmpty, this, &AudioInjector::stop);
|
|
||||||
|
|
||||||
if (!success) {
|
if (!success) {
|
||||||
qCDebug(audio) << "AudioInjector::injectLocally could not output locally via _localAudioInterface";
|
qCDebug(audio) << "AudioInjector::injectLocally could not output locally via _localAudioInterface";
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,8 +17,7 @@ AudioInjectorLocalBuffer::AudioInjectorLocalBuffer(const QByteArray& rawAudioArr
|
||||||
_shouldLoop(false),
|
_shouldLoop(false),
|
||||||
_isStopped(false),
|
_isStopped(false),
|
||||||
_currentOffset(0),
|
_currentOffset(0),
|
||||||
_volume(1.0f),
|
_volume(1.0f)
|
||||||
_isFinished(false)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -52,11 +51,6 @@ void copy(char* to, char* from, int size, qreal factor) {
|
||||||
qint64 AudioInjectorLocalBuffer::readData(char* data, qint64 maxSize) {
|
qint64 AudioInjectorLocalBuffer::readData(char* data, qint64 maxSize) {
|
||||||
if (!_isStopped) {
|
if (!_isStopped) {
|
||||||
|
|
||||||
if (_isFinished) {
|
|
||||||
emit bufferEmpty();
|
|
||||||
return -1; // qt docs say -1 is appropriate when subsequent calls will not write data
|
|
||||||
}
|
|
||||||
|
|
||||||
// first copy to the end of the raw audio
|
// first copy to the end of the raw audio
|
||||||
int bytesToEnd = _rawAudioArray.size() - _currentOffset;
|
int bytesToEnd = _rawAudioArray.size() - _currentOffset;
|
||||||
|
|
||||||
|
@ -75,10 +69,7 @@ qint64 AudioInjectorLocalBuffer::readData(char* data, qint64 maxSize) {
|
||||||
_currentOffset += bytesRead;
|
_currentOffset += bytesRead;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_shouldLoop && bytesRead == bytesToEnd) {
|
if (_shouldLoop && _currentOffset == _rawAudioArray.size()) {
|
||||||
// If we emit bufferEmpty now, we'll clip the end of the sound. Wait until the next call.
|
|
||||||
_isFinished = true;
|
|
||||||
} else if (_shouldLoop && _currentOffset == _rawAudioArray.size()) {
|
|
||||||
_currentOffset = 0;
|
_currentOffset = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,9 +32,6 @@ public:
|
||||||
void setCurrentOffset(int currentOffset) { _currentOffset = currentOffset; }
|
void setCurrentOffset(int currentOffset) { _currentOffset = currentOffset; }
|
||||||
void setVolume(float volume) { _volume = glm::clamp(volume, 0.0f, 1.0f); }
|
void setVolume(float volume) { _volume = glm::clamp(volume, 0.0f, 1.0f); }
|
||||||
|
|
||||||
signals:
|
|
||||||
void bufferEmpty();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
qint64 recursiveReadFromFront(char* data, qint64 maxSize);
|
qint64 recursiveReadFromFront(char* data, qint64 maxSize);
|
||||||
|
|
||||||
|
@ -44,7 +41,6 @@ private:
|
||||||
|
|
||||||
int _currentOffset;
|
int _currentOffset;
|
||||||
float _volume;
|
float _volume;
|
||||||
bool _isFinished;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_AudioInjectorLocalBuffer_h
|
#endif // hifi_AudioInjectorLocalBuffer_h
|
Loading…
Reference in a new issue