From b035f74f94afd10d808b94a5b1c8101a6bfea07a Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 19 Dec 2013 12:39:57 -0800 Subject: [PATCH] fix for build busters with changed AbstractAudioInterface --- interface/src/Audio.cpp | 20 +++++++++++++------- libraries/audio/src/AbstractAudioInterface.h | 4 ++++ libraries/audio/src/AudioInjector.h | 1 - 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/interface/src/Audio.cpp b/interface/src/Audio.cpp index 6d3e415e4f..429b0ec66a 100644 --- a/interface/src/Audio.cpp +++ b/interface/src/Audio.cpp @@ -42,7 +42,7 @@ static const int ICON_LEFT = 20; static const int BOTTOM_PADDING = 110; Audio::Audio(Oscilloscope* scope, int16_t initialJitterBufferSamples, QObject* parent) : - QObject(parent), + AbstractAudioInterface(parent), _audioInput(NULL), _desiredInputFormat(), _inputFormat(), @@ -469,17 +469,23 @@ void Audio::addReceivedAudioToBuffer(const QByteArray& audioByteArray) { int16_t* byteArraySamples = (int16_t*) audioByteArray.data(); - for (int i = 0; i < NETWORK_BUFFER_LENGTH_SAMPLES_PER_CHANNEL; i++) { + int samplesToRead = MIN(audioByteArray.size() / sizeof(int16_t), + NETWORK_BUFFER_LENGTH_SAMPLES_PER_CHANNEL); + + for (int i = 0; i < samplesToRead; i++) { _localInjectedSamples[i] = glm::clamp(_localInjectedSamples[i] + byteArraySamples[i], MIN_SAMPLE_VALUE, MAX_SAMPLE_VALUE); } - // pull out the bytes we just read for outputs - audioByteArray.remove(0, NETWORK_BUFFER_LENGTH_BYTES_PER_CHANNEL); - - if (audioByteArray.size() == 0) { - // if there isn't anything left to inject from this byte array, remove it from the vector + if (samplesToRead < NETWORK_BUFFER_LENGTH_SAMPLES_PER_CHANNEL) { + // there isn't anything left to inject from this byte array, remove it from the vector _localInjectionByteArrays.remove(b); + } else { + // pull out the bytes we just read for outputs + audioByteArray.remove(0, samplesToRead * sizeof(int16_t)); + + // still data left to read - replace the byte array in the QVector with the smaller one + _localInjectionByteArrays.replace(b, audioByteArray); } } diff --git a/libraries/audio/src/AbstractAudioInterface.h b/libraries/audio/src/AbstractAudioInterface.h index 26e2ebe997..d2cb0c3360 100644 --- a/libraries/audio/src/AbstractAudioInterface.h +++ b/libraries/audio/src/AbstractAudioInterface.h @@ -10,9 +10,13 @@ #ifndef __hifi__AbstractAudioInterface__ #define __hifi__AbstractAudioInterface__ +#include + class AbstractAudioInterface : public QObject { Q_OBJECT public: + AbstractAudioInterface(QObject* parent = 0) : QObject(parent) {}; + virtual void startCollisionSound(float magnitude, float frequency, float noise, float duration, bool flashScreen) = 0; virtual void startDrumSound(float volume, float frequency, float duration, float decay) = 0; public slots: diff --git a/libraries/audio/src/AudioInjector.h b/libraries/audio/src/AudioInjector.h index 2d8109289b..0a920077f1 100644 --- a/libraries/audio/src/AudioInjector.h +++ b/libraries/audio/src/AudioInjector.h @@ -18,7 +18,6 @@ class AudioInjector : public QObject { Q_OBJECT public: AudioInjector(const QUrl& sampleURL, QObject* parent = 0); - ~AudioInjector(); void injectViaThread(AbstractAudioInterface* localAudioInterface = NULL);