and quiet some warnings (of https://app.asana.com/0/32622044445063/37620738098871).
This commit is contained in:
Howard Stearns 2015-06-16 10:51:42 -07:00
parent ab73905832
commit 6d99d50f72
3 changed files with 11 additions and 5 deletions

View file

@ -51,7 +51,7 @@ void AudioInjector::setIsFinished(bool isFinished) {
emit finished();
if (_localBuffer) {
_localBuffer->stop();
// delete will stop (and nosily if we do so ourselves here first).
_localBuffer->deleteLater();
_localBuffer = NULL;
}
@ -60,7 +60,6 @@ void AudioInjector::setIsFinished(bool isFinished) {
if (_shouldDeleteAfterFinish) {
// we've been asked to delete after finishing, trigger a queued deleteLater here
qCDebug(audio) << "AudioInjector triggering delete from setIsFinished";
QMetaObject::invokeMethod(this, "deleteLater", Qt::QueuedConnection);
}
}

View file

@ -17,7 +17,8 @@ AudioInjectorLocalBuffer::AudioInjectorLocalBuffer(const QByteArray& rawAudioArr
_shouldLoop(false),
_isStopped(false),
_currentOffset(0),
_volume(1.0f)
_volume(1.0f),
_isFinished(false)
{
}
@ -51,6 +52,11 @@ 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;
@ -70,8 +76,8 @@ qint64 AudioInjectorLocalBuffer::readData(char* data, qint64 maxSize) {
}
if (!_shouldLoop && bytesRead == bytesToEnd) {
// we hit the end of the buffer, emit a signal
emit bufferEmpty();
// 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;
}

View file

@ -44,6 +44,7 @@ private:
int _currentOffset;
float _volume;
bool _isFinished;
};
#endif // hifi_AudioInjectorLocalBuffer_h