mirror of
https://github.com/lubosz/overte.git
synced 2025-04-16 21:26:32 +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());
|
||||
|
||||
// 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);
|
||||
|
||||
qCDebug(audioclient) << "Starting QAudioOutput for local injector" << localOutput;
|
||||
|
@ -1329,3 +1332,9 @@ void AudioClient::saveSettings() {
|
|||
windowSecondsForDesiredReduction.set(_receivedAudioStream.getWindowSecondsForDesiredReduction());
|
||||
repetitionWithFade.set(_receivedAudioStream.getRepetitionWithFade());
|
||||
}
|
||||
|
||||
void AudioClient::audioStateChanged(QAudio::State state) {
|
||||
if (state == QAudio::IdleState) {
|
||||
emit audioFinished();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -188,6 +188,8 @@ signals:
|
|||
void receivedFirstPacket();
|
||||
void disconnected();
|
||||
|
||||
void audioFinished();
|
||||
|
||||
protected:
|
||||
AudioClient();
|
||||
~AudioClient();
|
||||
|
@ -196,6 +198,9 @@ protected:
|
|||
deleteLater();
|
||||
}
|
||||
|
||||
private slots:
|
||||
void audioStateChanged(QAudio::State state);
|
||||
|
||||
private:
|
||||
void outputFormatChanged();
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ void AudioInjector::setIsFinished(bool isFinished) {
|
|||
emit finished();
|
||||
|
||||
if (_localBuffer) {
|
||||
// delete will stop (and nosily if we do so ourselves here first).
|
||||
_localBuffer->stop();
|
||||
_localBuffer->deleteLater();
|
||||
_localBuffer = NULL;
|
||||
}
|
||||
|
@ -121,9 +121,6 @@ void AudioInjector::injectLocally() {
|
|||
|
||||
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) {
|
||||
qCDebug(audio) << "AudioInjector::injectLocally could not output locally via _localAudioInterface";
|
||||
}
|
||||
|
|
|
@ -17,8 +17,7 @@ AudioInjectorLocalBuffer::AudioInjectorLocalBuffer(const QByteArray& rawAudioArr
|
|||
_shouldLoop(false),
|
||||
_isStopped(false),
|
||||
_currentOffset(0),
|
||||
_volume(1.0f),
|
||||
_isFinished(false)
|
||||
_volume(1.0f)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -52,11 +51,6 @@ void copy(char* to, char* from, int size, qreal factor) {
|
|||
qint64 AudioInjectorLocalBuffer::readData(char* data, qint64 maxSize) {
|
||||
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
|
||||
int bytesToEnd = _rawAudioArray.size() - _currentOffset;
|
||||
|
||||
|
@ -75,10 +69,7 @@ qint64 AudioInjectorLocalBuffer::readData(char* data, qint64 maxSize) {
|
|||
_currentOffset += bytesRead;
|
||||
}
|
||||
|
||||
if (!_shouldLoop && bytesRead == bytesToEnd) {
|
||||
// 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()) {
|
||||
if (_shouldLoop && _currentOffset == _rawAudioArray.size()) {
|
||||
_currentOffset = 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -32,9 +32,6 @@ public:
|
|||
void setCurrentOffset(int currentOffset) { _currentOffset = currentOffset; }
|
||||
void setVolume(float volume) { _volume = glm::clamp(volume, 0.0f, 1.0f); }
|
||||
|
||||
signals:
|
||||
void bufferEmpty();
|
||||
|
||||
private:
|
||||
qint64 recursiveReadFromFront(char* data, qint64 maxSize);
|
||||
|
||||
|
@ -44,7 +41,6 @@ private:
|
|||
|
||||
int _currentOffset;
|
||||
float _volume;
|
||||
bool _isFinished;
|
||||
};
|
||||
|
||||
#endif // hifi_AudioInjectorLocalBuffer_h
|
Loading…
Reference in a new issue