From 60447e48cbe50395e765c97fe7d357a03c919168 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 16 Dec 2014 13:29:42 -0800 Subject: [PATCH] handle input from Audio class in AudioScope --- interface/src/Audio.cpp | 9 +++------ interface/src/Audio.h | 4 +--- interface/src/audio/AudioScope.cpp | 14 ++++++++++++++ interface/src/audio/AudioScope.h | 20 ++++++++++++-------- 4 files changed, 30 insertions(+), 17 deletions(-) diff --git a/interface/src/Audio.cpp b/interface/src/Audio.cpp index f8043fe7df..d26dbd708c 100644 --- a/interface/src/Audio.cpp +++ b/interface/src/Audio.cpp @@ -831,12 +831,9 @@ void Audio::handleAudioInput() { if (!_isStereoInput && _proceduralAudioOutput) { processProceduralAudio(networkAudioSamples, AudioConstants::NETWORK_FRAME_SAMPLES_PER_CHANNEL); } - -// if (!_isStereoInput && _scopeEnabled && !_scopeEnabledPause) { -// unsigned int numMonoAudioChannels = 1; -// unsigned int monoAudioChannel = 0; -// _scopeInputOffset = addBufferToScope(_scopeInput, _scopeInputOffset, networkAudioSamples, NETWORK_SAMPLES_PER_FRAME, monoAudioChannel, numMonoAudioChannels); -// } + + emit inputReceived(QByteArray(reinterpret_cast(networkAudioSamples), + AudioConstants::NETWORK_FRAME_SAMPLES_PER_CHANNEL)); NodeList* nodeList = NodeList::getInstance(); SharedNodePointer audioMixer = nodeList->soloNodeOfType(NodeType::AudioMixer); diff --git a/interface/src/Audio.h b/interface/src/Audio.h index 31a691dd6d..da52028e44 100644 --- a/interface/src/Audio.h +++ b/interface/src/Audio.h @@ -164,9 +164,7 @@ public slots: signals: bool muteToggled(); - void preProcessOriginalInboundAudio(unsigned int sampleTime, QByteArray& samples, const QAudioFormat& format); - void processInboundAudio(unsigned int sampleTime, const QByteArray& samples, const QAudioFormat& format); - void processLocalAudio(unsigned int sampleTime, const QByteArray& samples, const QAudioFormat& format); + void inputReceived(const QByteArray& inputSamples); protected: // setup for audio I/O diff --git a/interface/src/audio/AudioScope.cpp b/interface/src/audio/AudioScope.cpp index cd5960104a..b87a2c7a07 100644 --- a/interface/src/audio/AudioScope.cpp +++ b/interface/src/audio/AudioScope.cpp @@ -43,6 +43,7 @@ AudioScope::AudioScope() : this, &AudioScope::addLastFrameRepeatedWithFadeToScope); connect(&audioIO->getReceivedAudioStream(), &MixedProcessedAudioStream::addedStereoSamples, this, &AudioScope::addStereoSamplesToScope); + connect(audioIO, &Audio::inputReceived, this, &AudioScope::addInputToScope); } void AudioScope::toggle() { @@ -301,3 +302,16 @@ void AudioScope::addLastFrameRepeatedWithFadeToScope(int samplesPerChannel) { indexOfRepeat++; } while (samplesRemaining > 0); } + +void AudioScope::addInputToScope(const QByteArray& inputSamples) { + if (!_isEnabled || _isPaused) { + return; + } + + const int INPUT_AUDIO_CHANNEL = 0; + const int NUM_INPUT_CHANNELS = 1; + + _scopeInputOffset = addBufferToScope(_scopeInput, _scopeInputOffset, + reinterpret_cast(inputSamples.data()), + inputSamples.size() / sizeof(int16_t), INPUT_AUDIO_CHANNEL, NUM_INPUT_CHANNELS); +} diff --git a/interface/src/audio/AudioScope.h b/interface/src/audio/AudioScope.h index fc12b3089e..1bb485e6a3 100644 --- a/interface/src/audio/AudioScope.h +++ b/interface/src/audio/AudioScope.h @@ -20,11 +20,6 @@ class AudioScope : public QObject, public DependencyManager::Dependency { Q_OBJECT public: - // Audio scope methods for data acquisition - int addBufferToScope(QByteArray* byteArray, int frameOffset, const int16_t* source, int sourceSamples, - unsigned int sourceChannel, unsigned int sourceNumberOfChannels, float fade = 1.0f); - int addSilenceToScope(QByteArray* byteArray, int frameOffset, int silentSamples); - // Audio scope methods for rendering static void renderBackground(const float* color, int x, int y, int width, int height); void renderGrid(const float* color, int x, int y, int width, int height, int rows, int cols); @@ -45,13 +40,22 @@ public slots: void selectAudioScopeFiveFrames(); void selectAudioScopeTwentyFrames(); void selectAudioScopeFiftyFrames(); - void addStereoSilenceToScope(int silentSamplesPerChannel); - void addLastFrameRepeatedWithFadeToScope(int samplesPerChannel); - void addStereoSamplesToScope(const QByteArray& samples); protected: AudioScope(); + +private slots: + void addStereoSilenceToScope(int silentSamplesPerChannel); + void addLastFrameRepeatedWithFadeToScope(int samplesPerChannel); + void addStereoSamplesToScope(const QByteArray& samples); + void addInputToScope(const QByteArray& inputSamples); + private: + // Audio scope methods for data acquisition + int addBufferToScope(QByteArray* byteArray, int frameOffset, const int16_t* source, int sourceSamples, + unsigned int sourceChannel, unsigned int sourceNumberOfChannels, float fade = 1.0f); + int addSilenceToScope(QByteArray* byteArray, int frameOffset, int silentSamples); + bool _isEnabled; bool _isPaused; int _scopeInputOffset;