From 251e38cc16d408ecdff36e0f9fde81392bf8f599 Mon Sep 17 00:00:00 2001 From: matsukaze Date: Sun, 2 Mar 2014 14:28:44 -0500 Subject: [PATCH 1/7] Removed TODO --- interface/src/VoxelSystem.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/interface/src/VoxelSystem.cpp b/interface/src/VoxelSystem.cpp index 99f6171b7a..7513774a07 100644 --- a/interface/src/VoxelSystem.cpp +++ b/interface/src/VoxelSystem.cpp @@ -1751,11 +1751,12 @@ bool VoxelSystem::inspectForExteriorOcclusionsOperation(OctreeElement* element, //qDebug("Completely occupied voxel at %f %f %f size: %f", v.x, v.y, v.z, s); - // TODO: All of the exterior faces of this voxel element are - // occluders, which means that this element is completely - // occupied. Hence, the subtree from this node could be - // pruned and replaced by a leaf voxel, if the visible - // properties of the children are the same + // All of the exterior faces of this voxel element are + // occluders, which means that this element is completely + // occupied. Hence, the subtree from this node could be + // pruned and replaced by a leaf voxel, if the visible + // properties of the children are the same + } else if (exteriorOcclusions != OctreeElement::HalfSpace::None) { //const glm::vec3& v = voxel->getCorner(); //float s = voxel->getScale(); From ddb7fb9271ed9536cb68a5a98f334a81c605c5e4 Mon Sep 17 00:00:00 2001 From: matsukaze Date: Sun, 2 Mar 2014 14:29:25 -0500 Subject: [PATCH 2/7] Additional documentation --- interface/src/PrimitiveRenderer.h | 112 +++++++++++++++++------------- 1 file changed, 62 insertions(+), 50 deletions(-) diff --git a/interface/src/PrimitiveRenderer.h b/interface/src/PrimitiveRenderer.h index 51d96e0840..55f24cdf7a 100644 --- a/interface/src/PrimitiveRenderer.h +++ b/interface/src/PrimitiveRenderer.h @@ -103,7 +103,7 @@ private: /// Copy constructor prohibited. /// Primitive( - const Primitive& prim + const Primitive& copy ); // SPI methods are defined here @@ -150,14 +150,14 @@ public: /// Configuration dependency injection constructor. /// Cube( - float x, - float y, - float z, - float s, - unsigned char r, - unsigned char g, - unsigned char b, - unsigned char faces + float x, ///< Cube location on X-axis + float y, ///< Cube location on Y-axis + float z, ///< Cube location on Z-axis + float s, ///< Cube size + unsigned char r, ///< Cube red color component + unsigned char g, ///< Cube green color component + unsigned char b, ///< Cube blue color component + unsigned char faces ///< Bitmask of faces of cube excluded from construction ); ~Cube(); @@ -169,36 +169,48 @@ private: const Cube& cube ); + /// Cube initialization + /// void init( - float x, - float y, - float z, - float s, - unsigned char r, - unsigned char g, - unsigned char b, - unsigned char faceExclusions + float x, ///< Cube location on X-axis + float y, ///< Cube location on Y-axis + float z, ///< Cube location on Z-axis + float s, ///< Cube size + unsigned char r, ///< Cube red color component + unsigned char g, ///< Cube green color component + unsigned char b, ///< Cube blue color component + unsigned char faceExclusions ///< Bitmask of faces of cube excluded from construction ); + /// Cube termination + /// void terminate(); + /// Initialize cube's vertex list + /// void initializeVertices( - float x, - float y, - float z, - float s, - unsigned char r, - unsigned char g, - unsigned char b, - unsigned char faceExclusions + float x, ///< Cube location on X-axis + float y, ///< Cube location on Y-axis + float z, ///< Cube location on Z-axis + float s, ///< Cube size + unsigned char r, ///< Cube red color component + unsigned char g, ///< Cube green color component + unsigned char b, ///< Cube blue color component + unsigned char faceExclusions ///< Bitmask of faces of cube excluded from construction ); + /// Terminate cube's vertex list + /// void terminateVertices(); + /// Initialize cube's triangle list + /// void initializeTris( unsigned char faceExclusions ); + /// Terminate cube's triangle list + /// void terminateTris(); // SPI virtual override methods go here @@ -216,11 +228,11 @@ private: unsigned long _cpuMemoryUsage; ///< Memory allocation of object - static const int _sNumFacesPerCube = 6; - static const int _sNumVerticesPerCube = 24; - static unsigned char _sFaceIndexToHalfSpaceMask[6]; - static float _sVertexIndexToConstructionVector[24][3]; - static float _sVertexIndexToNormalVector[6][3]; + static const int _sNumFacesPerCube = 6; ///< Number of faces per cube + static const int _sNumVerticesPerCube = 24; ///< Number of vertices per cube + static unsigned char _sFaceIndexToHalfSpaceMask[6]; ///< index to bitmask map + static float _sVertexIndexToConstructionVector[24][3]; ///< Vertex index to construction vector map + static float _sVertexIndexToNormalVector[6][3]; ///< Vertex index to normal vector map }; @@ -239,13 +251,13 @@ public: /// Add primitive to renderer database. /// int add( - Primitive* primitive ///< Pointer to primitive + Primitive* primitive ///< Primitive instance to be added ); /// Remove primitive from renderer database. /// void remove( - int id ///< Primitive id + int id ///< Primitive id to be removed ); /// Clear all primitives from renderer database @@ -275,7 +287,7 @@ private: /// Copy constructor prohibited. /// Renderer( - const Renderer& primitive + const Renderer& copy ); // SPI methods are defined here @@ -283,10 +295,10 @@ private: /// Add primitive to renderer database. /// Service implementer to provide private override for this method /// in derived class - /// @return primitive id + /// @return Primitive id /// virtual int vAdd( - Primitive* primitive ///< Pointer to primitive + Primitive* primitive ///< Primitive instance to be added ) = 0; /// Remove primitive from renderer database. @@ -294,7 +306,7 @@ private: /// in derived class /// virtual void vRemove( - int id ///< Primitive id + int id ///< Primitive id ) = 0; /// Clear all primitives from renderer database @@ -329,7 +341,7 @@ public: /// Configuration dependency injection constructor. /// PrimitiveRenderer( - int maxCount + int maxCount ///< Max count ); ~PrimitiveRenderer(); @@ -362,39 +374,39 @@ private: /// Construct the elements of the faces of the primitive. /// void constructElements( - Primitive* primitive + Primitive* primitive ///< Primitive instance ); /// Deconstruct the elements of the faces of the primitive. /// void deconstructElements( - Primitive* primitive + Primitive* primitive ///< Primitive instance ); /// Deconstruct the triangle element from the GL buffer. /// void deconstructTriElement( - int idx + int idx ///< Triangle element index ); /// Deconstruct the vertex element from the GL buffer. /// void deconstructVertexElement( - int idx + int idx ///< Vertex element index ); /// Transfer the vertex element to the GL buffer. /// void transferVertexElement( - int idx, - VertexElement *vertex + int idx, ///< Vertex element index + VertexElement *vertex ///< Vertex element instance ); /// Transfer the triangle element to the GL buffer. /// void transferTriElement( - int idx, - int tri[3] + int idx, ///< Triangle element index + int tri[3] ///< Triangle element data ); /// Get available primitive index. @@ -421,13 +433,13 @@ private: /// Add primitive to renderer database. /// int vAdd( - Primitive* primitive + Primitive* primitive ///< Primitive instance to be added ); /// Remove primitive from renderer database. /// void vRemove( - int id + int id ///< Primitive id to be removed ); /// Clear all primitives from renderer database @@ -448,7 +460,7 @@ private: private: - int _maxCount; + int _maxCount; ///< Maximum count of tris // GL related parameters @@ -476,8 +488,8 @@ private: // Statistics parameters, not necessary for proper operation - unsigned long _gpuMemoryUsage; - unsigned long _cpuMemoryUsage; + unsigned long _gpuMemoryUsage; ///< GPU memory used by this instance + unsigned long _cpuMemoryUsage; ///< CPU memory used by this instance static const int _sIndicesPerTri = 3; From ff7a1bd60fb615c68744cf93c8ee47037a2e4e08 Mon Sep 17 00:00:00 2001 From: matsukaze Date: Tue, 22 Apr 2014 06:53:59 -0400 Subject: [PATCH 3/7] Job #19574. Add audio oscilloscope.' --- interface/src/Application.cpp | 2 + interface/src/Audio.cpp | 174 +++++++++++++++++++++++++++++++++- interface/src/Audio.h | 26 +++++ interface/src/Menu.cpp | 8 ++ interface/src/Menu.h | 3 +- interface/src/ui/InfoView.cpp | 4 +- 6 files changed, 213 insertions(+), 4 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index cd07f21300..a9f4c8eed7 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2648,6 +2648,8 @@ void Application::displayOverlay() { audioMeterY, Menu::getInstance()->isOptionChecked(MenuOption::Mirror)); + _audio.renderScope(_glWidget->width(), _glWidget->height()); + glBegin(GL_QUADS); if (isClipping) { glColor3f(1, 0, 0); diff --git a/interface/src/Audio.cpp b/interface/src/Audio.cpp index 698a8db725..1e85e77883 100644 --- a/interface/src/Audio.cpp +++ b/interface/src/Audio.cpp @@ -92,7 +92,14 @@ Audio::Audio(int16_t initialJitterBufferSamples, QObject* parent) : _processSpatialAudio(false), _spatialAudioStart(0), _spatialAudioFinish(0), - _spatialAudioRingBuffer(NETWORK_BUFFER_LENGTH_BYTES_PER_CHANNEL, true) // random access mode + _spatialAudioRingBuffer(NETWORK_BUFFER_LENGTH_BYTES_PER_CHANNEL, true), // random access mode + _scopeEnabled(false), + _scopeEnabledPause(false), + _scopeInputOffset(0), + _scopeOutputOffset(0), + _scopeInput(SAMPLES_PER_SCOPE_H * sizeof(int16_t), 0), + _scopeOutputLeft(SAMPLES_PER_SCOPE_H * sizeof(int16_t), 0), + _scopeOutputRight(SAMPLES_PER_SCOPE_H * sizeof(int16_t), 0) { // clear the array of locally injected samples memset(_localProceduralSamples, 0, NETWORK_BUFFER_LENGTH_BYTES_PER_CHANNEL); @@ -575,6 +582,14 @@ void Audio::handleAudioInput() { processProceduralAudio(monoAudioSamples, NETWORK_BUFFER_LENGTH_SAMPLES_PER_CHANNEL); } + if (_scopeEnabled && !_scopeEnabledPause) { + unsigned int numMonoAudioChannels = 1; + unsigned int monoAudioChannel = 0; + addBufferToScope(_scopeInput, _scopeInputOffset, monoAudioSamples, monoAudioChannel, numMonoAudioChannels); + _scopeInputOffset += NETWORK_SAMPLES_PER_FRAME; + _scopeInputOffset %= SAMPLES_PER_SCOPE_H; + } + NodeList* nodeList = NodeList::getInstance(); SharedNodePointer audioMixer = nodeList->soloNodeOfType(NodeType::AudioMixer); @@ -813,6 +828,30 @@ void Audio::processReceivedAudio(const QByteArray& audioByteArray) { if (_outputDevice) { _outputDevice->write(outputBuffer); } + + if (_scopeEnabled && !_scopeEnabledPause) { + unsigned int numAudioChannels = _desiredOutputFormat.channelCount(); + int16_t* samples = ringBufferSamples; + for (int numSamples = numNetworkOutputSamples / numAudioChannels; numSamples > 0; numSamples -= NETWORK_SAMPLES_PER_FRAME) { + + unsigned int audioChannel = 0; + addBufferToScope( + _scopeOutputLeft, + _scopeOutputOffset, + samples, audioChannel, numAudioChannels); + + audioChannel = 1; + addBufferToScope( + _scopeOutputRight, + _scopeOutputOffset, + samples, audioChannel, numAudioChannels); + + _scopeOutputOffset += NETWORK_SAMPLES_PER_FRAME; + _scopeOutputOffset %= SAMPLES_PER_SCOPE_H; + samples += NETWORK_SAMPLES_PER_FRAME * numAudioChannels; + } + } + delete[] ringBufferSamples; } } @@ -1019,6 +1058,139 @@ void Audio::renderToolBox(int x, int y, bool boxed) { glDisable(GL_TEXTURE_2D); } +void Audio::toggleScopePause() { + _scopeEnabledPause = !_scopeEnabledPause; +} + +void Audio::toggleScope() { + _scopeEnabled = !_scopeEnabled; + if (_scopeEnabled) { + static const int width = SAMPLES_PER_SCOPE_H; + _scopeInputOffset = 0; + _scopeOutputOffset = 0; + memset(_scopeInput.data(), 0, width * sizeof(int16_t)); + memset(_scopeOutputLeft.data(), 0, width * sizeof(int16_t)); + memset(_scopeOutputRight.data(), 0, width * sizeof(int16_t)); + } +} + +void Audio::addBufferToScope( + QByteArray& byteArray, unsigned int frameOffset, const int16_t* src, unsigned int srcChannel, unsigned int srcNumChannels) { + + int16_t* tgt = (int16_t*)byteArray.data() + frameOffset; + src += srcChannel; + + for (int i = NETWORK_SAMPLES_PER_FRAME; --i >= 0; src += srcNumChannels) { + float sample = (float)*src; + float multiplier = (float)MULTIPLIER_SCOPE_V / logf(2.0f); + int16_t value; + + if (sample > 0) { + value = (int16_t)(multiplier * logf(sample)); + } else if (sample < 0) { + value = (int16_t)(-multiplier * logf(-sample)); + } else { + value = 0; + } + + *tgt++ = value; + //*tgt++ = sample / 0x7fff * (SAMPLES_PER_SCOPE_V / 2); + } +} + +void Audio::renderScope(int width, int height) { + + if (!_scopeEnabled) + return; + + static const unsigned int backgroundColor = 0x33333399; + static const unsigned int gridColor = 0x44444499; + static const unsigned int inputColor = 0x44aa4499; + static const unsigned int outputLeftColor = 0xaa444499; + static const unsigned int outputRightColor = 0x4444aa99; + static const int gridRows = 2; + static const int gridCols = 5; + + int x = (width - SAMPLES_PER_SCOPE_H) / 2; + int y = (height - SAMPLES_PER_SCOPE_V) / 2; + int w = SAMPLES_PER_SCOPE_H; + int h = SAMPLES_PER_SCOPE_V; + + renderBackground(backgroundColor, x, y, w, h); + renderGrid(gridColor, x, y, w, h, gridRows, gridCols); + renderLineStrip(inputColor, x, y, w, _scopeInputOffset, _scopeInput); + renderLineStrip(outputLeftColor, x, y, w, _scopeOutputOffset, _scopeOutputLeft); + renderLineStrip(outputRightColor, x, y, w, _scopeOutputOffset, _scopeOutputRight); +} + +void Audio::renderBackground(unsigned int rgba, int x, int y, int width, int height) { + glBegin(GL_QUADS); + glColor4f(((rgba >> 24) & 0xff) / 255.0f, + ((rgba >> 16) & 0xff) / 255.0f, + ((rgba >> 8) & 0xff) / 255.0f, + (rgba & 0xff) / 255.0f); + glVertex2i(x, y); + glVertex2i(x + width, y); + glVertex2i(x + width, y + height); + glVertex2i(x , y + height); + glEnd(); + glColor4f(1, 1, 1, 1); +} + +void Audio::renderGrid(unsigned int rgba, int x, int y, int width, int height, int rows, int cols) { + glBegin(GL_LINES); + glColor4f(((rgba >> 24) & 0xff) / 255.0f, + ((rgba >> 16) & 0xff) / 255.0f, + ((rgba >> 8) & 0xff) / 255.0f, + (rgba & 0xff) / 255.0f); + + int dx = width / cols; + int dy = height / rows; + int tx = x; + int ty = y; + + // Draw horizontal grid lines + for (int i = rows + 1; --i >= 0; ) { + glVertex2i(x, ty); + glVertex2i(x + width, ty); + ty += dy; + } + // Draw vertical grid lines + for (int i = cols + 1; --i >= 0; ) { + glVertex2i(tx, y); + glVertex2i(tx, y + height); + tx += dx; + } + glEnd(); + glColor4f(1, 1, 1, 1); +} + +void Audio::renderLineStrip(unsigned int rgba, int x, int y, int n, int offset, const QByteArray& byteArray) { + + glColor4f(((rgba >> 24) & 0xff) / 255.0f, + ((rgba >> 16) & 0xff) / 255.0f, + ((rgba >> 8) & 0xff) / 255.0f, + (rgba & 0xff) / 255.0f); + + glBegin(GL_LINE_STRIP); + + int16_t sample; + int16_t* samples = ((int16_t*) byteArray.data()) + offset; + y += SAMPLES_PER_SCOPE_V / 2; + for (int i = n - offset; --i >= 0; ) { + sample = *samples++; + glVertex2i(x++, y - sample); + } + samples = (int16_t*) byteArray.data(); + for (int i = offset; --i >= 0; ) { + sample = *samples++; + glVertex2i(x++, y - sample); + } + glEnd(); + glColor4f(1, 1, 1, 1); +} + + bool Audio::switchInputToAudioDevice(const QAudioDeviceInfo& inputDeviceInfo) { bool supportedFormat = false; diff --git a/interface/src/Audio.h b/interface/src/Audio.h index 96def43dd2..4d4501c93d 100644 --- a/interface/src/Audio.h +++ b/interface/src/Audio.h @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -67,6 +68,7 @@ public: bool mousePressEvent(int x, int y); void renderToolBox(int x, int y, bool boxed); + void renderScope(int width, int height); int getNetworkSampleRate() { return SAMPLE_RATE; } int getNetworkBufferLengthSamplesPerChannel() { return NETWORK_BUFFER_LENGTH_SAMPLES_PER_CHANNEL; } @@ -83,6 +85,8 @@ public slots: void toggleMute(); void toggleAudioNoiseReduction(); void toggleToneInjection(); + void toggleScope(); + void toggleScopePause(); void toggleAudioSpatialProcessing(); virtual void handleAudioByteArray(const QByteArray& audioByteArray); @@ -196,6 +200,28 @@ private: int calculateNumberOfFrameSamples(int numBytes); float calculateDeviceToNetworkInputRatio(int numBytes); + // Audio scope methods for data acquisition + void addBufferToScope(QByteArray& byteArray, unsigned int frameOffset, const int16_t* src, unsigned int srcChannel, unsigned int srcNumChannels); + + // Audio scope methods for rendering + void renderBackground(unsigned int rgba, int x, int y, int width, int height); + void renderGrid(unsigned int rgba, int x, int y, int width, int height, int rows, int cols); + void renderLineStrip(unsigned int rgba, int x, int y, int n, int offset, const QByteArray& byteArray); + + // Audio scope data + static const unsigned int NETWORK_SAMPLES_PER_FRAME = NETWORK_BUFFER_LENGTH_SAMPLES_PER_CHANNEL; + static const unsigned int FRAMES_PER_SCOPE = 5; + static const unsigned int SAMPLES_PER_SCOPE_H = FRAMES_PER_SCOPE * NETWORK_SAMPLES_PER_FRAME; + static const unsigned int MULTIPLIER_SCOPE_V = 20; + static const unsigned int SAMPLES_PER_SCOPE_V = 2 * 15 * MULTIPLIER_SCOPE_V; + bool _scopeEnabled; + bool _scopeEnabledPause; + int _scopeInputOffset; + int _scopeOutputOffset; + QByteArray _scopeInput; + QByteArray _scopeOutputLeft; + QByteArray _scopeOutputRight; + }; diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 7cdd72afd5..2e4abaa17d 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -259,6 +259,9 @@ Menu::Menu() : addCheckableActionToQMenuAndActionHash(viewMenu, MenuOption::Bandwidth, 0, true); addActionToQMenuAndActionHash(viewMenu, MenuOption::BandwidthDetails, 0, this, SLOT(bandwidthDetails())); addActionToQMenuAndActionHash(viewMenu, MenuOption::OctreeStats, 0, this, SLOT(octreeStatsDetails())); + addCheckableActionToQMenuAndActionHash(viewMenu, MenuOption::AudioScope, 0, false, + appInstance->getAudio(), + SLOT(toggleScope())); QMenu* developerMenu = addMenu("Developer"); @@ -385,6 +388,11 @@ Menu::Menu() : false, appInstance->getAudio(), SLOT(toggleToneInjection())); + addCheckableActionToQMenuAndActionHash(audioDebugMenu, MenuOption::AudioScopePause, + Qt::CTRL | Qt::Key_P, + false, + appInstance->getAudio(), + SLOT(toggleScopePause())); QMenu* spatialAudioMenu = audioDebugMenu->addMenu("Spatial Audio"); diff --git a/interface/src/Menu.h b/interface/src/Menu.h index 597ae4a74b..ddcd0571f8 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -256,8 +256,9 @@ namespace MenuOption { const QString AmbientOcclusion = "Ambient Occlusion"; const QString Atmosphere = "Atmosphere"; const QString AudioNoiseReduction = "Audio Noise Reduction"; + const QString AudioScope = "Audio Scope"; + const QString AudioScopePause = "Pause Audio Scope"; const QString AudioToneInjection = "Inject Test Tone"; - const QString AudioSpatialProcessing = "Audio Spatial Processing"; const QString AudioSpatialProcessingHeadOriented = "Head Oriented"; const QString AudioSpatialProcessingIncludeOriginal = "Includes Network Original"; diff --git a/interface/src/ui/InfoView.cpp b/interface/src/ui/InfoView.cpp index 06de3fdf2e..99a4f8cb06 100644 --- a/interface/src/ui/InfoView.cpp +++ b/interface/src/ui/InfoView.cpp @@ -28,8 +28,8 @@ InfoView::InfoView(bool forced) : QString absPath = QFileInfo(Application::resourcesPath() + "html/interface-welcome-allsvg.html").absoluteFilePath(); QUrl url = QUrl::fromLocalFile(absPath); - load(url); - connect(this, SIGNAL(loadFinished(bool)), this, SLOT(loaded(bool))); +// load(url); +// connect(this, SIGNAL(loadFinished(bool)), this, SLOT(loaded(bool))); } void InfoView::showFirstTime() { From 99cb1da5ec16eaeeda12a9b1a131594859aa6cae Mon Sep 17 00:00:00 2001 From: matsukaze Date: Tue, 22 Apr 2014 07:40:31 -0400 Subject: [PATCH 4/7] Reverting inadvertently committed local changes. --- interface/src/ui/InfoView.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/interface/src/ui/InfoView.cpp b/interface/src/ui/InfoView.cpp index 99a4f8cb06..06de3fdf2e 100644 --- a/interface/src/ui/InfoView.cpp +++ b/interface/src/ui/InfoView.cpp @@ -28,8 +28,8 @@ InfoView::InfoView(bool forced) : QString absPath = QFileInfo(Application::resourcesPath() + "html/interface-welcome-allsvg.html").absoluteFilePath(); QUrl url = QUrl::fromLocalFile(absPath); -// load(url); -// connect(this, SIGNAL(loadFinished(bool)), this, SLOT(loaded(bool))); + load(url); + connect(this, SIGNAL(loadFinished(bool)), this, SLOT(loaded(bool))); } void InfoView::showFirstTime() { From 015cbce32217b94801f5ac08ee12e746a7fb2c06 Mon Sep 17 00:00:00 2001 From: matsukaze Date: Tue, 22 Apr 2014 18:57:22 -0400 Subject: [PATCH 5/7] Changed constant names for improved readability. --- interface/src/Audio.cpp | 45 ++++++++++++++++++++++++----------------- interface/src/Audio.h | 6 +++--- 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/interface/src/Audio.cpp b/interface/src/Audio.cpp index 1e85e77883..5e9d343df6 100644 --- a/interface/src/Audio.cpp +++ b/interface/src/Audio.cpp @@ -97,9 +97,9 @@ Audio::Audio(int16_t initialJitterBufferSamples, QObject* parent) : _scopeEnabledPause(false), _scopeInputOffset(0), _scopeOutputOffset(0), - _scopeInput(SAMPLES_PER_SCOPE_H * sizeof(int16_t), 0), - _scopeOutputLeft(SAMPLES_PER_SCOPE_H * sizeof(int16_t), 0), - _scopeOutputRight(SAMPLES_PER_SCOPE_H * sizeof(int16_t), 0) + _scopeInput(SAMPLES_PER_SCOPE_WIDTH * sizeof(int16_t), 0), + _scopeOutputLeft(SAMPLES_PER_SCOPE_WIDTH * sizeof(int16_t), 0), + _scopeOutputRight(SAMPLES_PER_SCOPE_WIDTH * sizeof(int16_t), 0) { // clear the array of locally injected samples memset(_localProceduralSamples, 0, NETWORK_BUFFER_LENGTH_BYTES_PER_CHANNEL); @@ -587,7 +587,7 @@ void Audio::handleAudioInput() { unsigned int monoAudioChannel = 0; addBufferToScope(_scopeInput, _scopeInputOffset, monoAudioSamples, monoAudioChannel, numMonoAudioChannels); _scopeInputOffset += NETWORK_SAMPLES_PER_FRAME; - _scopeInputOffset %= SAMPLES_PER_SCOPE_H; + _scopeInputOffset %= SAMPLES_PER_SCOPE_WIDTH; } NodeList* nodeList = NodeList::getInstance(); @@ -847,7 +847,7 @@ void Audio::processReceivedAudio(const QByteArray& audioByteArray) { samples, audioChannel, numAudioChannels); _scopeOutputOffset += NETWORK_SAMPLES_PER_FRAME; - _scopeOutputOffset %= SAMPLES_PER_SCOPE_H; + _scopeOutputOffset %= SAMPLES_PER_SCOPE_WIDTH; samples += NETWORK_SAMPLES_PER_FRAME * numAudioChannels; } } @@ -1065,7 +1065,7 @@ void Audio::toggleScopePause() { void Audio::toggleScope() { _scopeEnabled = !_scopeEnabled; if (_scopeEnabled) { - static const int width = SAMPLES_PER_SCOPE_H; + static const int width = SAMPLES_PER_SCOPE_WIDTH; _scopeInputOffset = 0; _scopeOutputOffset = 0; memset(_scopeInput.data(), 0, width * sizeof(int16_t)); @@ -1077,13 +1077,21 @@ void Audio::toggleScope() { void Audio::addBufferToScope( QByteArray& byteArray, unsigned int frameOffset, const int16_t* src, unsigned int srcChannel, unsigned int srcNumChannels) { - int16_t* tgt = (int16_t*)byteArray.data() + frameOffset; - src += srcChannel; + // Constant multiplier to map sample value to vertical size of scope + float multiplier = (float)MULTIPLIER_SCOPE_HEIGHT / logf(2.0f); - for (int i = NETWORK_SAMPLES_PER_FRAME; --i >= 0; src += srcNumChannels) { - float sample = (float)*src; - float multiplier = (float)MULTIPLIER_SCOPE_V / logf(2.0f); - int16_t value; + // Temporary variable receives sample value + float sample; + + // Temporary variable receives mapping of sample value + int16_t value; + + // Short int pointer to mapped samples in byte array + int16_t* tgt = (int16_t*) byteArray.data(); + + for (int i = 0; i < NETWORK_SAMPLES_PER_FRAME; i++) { + + sample = (float)src[i * srcNumChannels + srcChannel]; if (sample > 0) { value = (int16_t)(multiplier * logf(sample)); @@ -1093,8 +1101,7 @@ void Audio::addBufferToScope( value = 0; } - *tgt++ = value; - //*tgt++ = sample / 0x7fff * (SAMPLES_PER_SCOPE_V / 2); + tgt[i + frameOffset] = value; } } @@ -1111,10 +1118,10 @@ void Audio::renderScope(int width, int height) { static const int gridRows = 2; static const int gridCols = 5; - int x = (width - SAMPLES_PER_SCOPE_H) / 2; - int y = (height - SAMPLES_PER_SCOPE_V) / 2; - int w = SAMPLES_PER_SCOPE_H; - int h = SAMPLES_PER_SCOPE_V; + int x = (width - SAMPLES_PER_SCOPE_WIDTH) / 2; + int y = (height - SAMPLES_PER_SCOPE_HEIGHT) / 2; + int w = SAMPLES_PER_SCOPE_WIDTH; + int h = SAMPLES_PER_SCOPE_HEIGHT; renderBackground(backgroundColor, x, y, w, h); renderGrid(gridColor, x, y, w, h, gridRows, gridCols); @@ -1176,7 +1183,7 @@ void Audio::renderLineStrip(unsigned int rgba, int x, int y, int n, int offset, int16_t sample; int16_t* samples = ((int16_t*) byteArray.data()) + offset; - y += SAMPLES_PER_SCOPE_V / 2; + y += SAMPLES_PER_SCOPE_HEIGHT / 2; for (int i = n - offset; --i >= 0; ) { sample = *samples++; glVertex2i(x++, y - sample); diff --git a/interface/src/Audio.h b/interface/src/Audio.h index 4d4501c93d..71030e39e3 100644 --- a/interface/src/Audio.h +++ b/interface/src/Audio.h @@ -211,9 +211,9 @@ private: // Audio scope data static const unsigned int NETWORK_SAMPLES_PER_FRAME = NETWORK_BUFFER_LENGTH_SAMPLES_PER_CHANNEL; static const unsigned int FRAMES_PER_SCOPE = 5; - static const unsigned int SAMPLES_PER_SCOPE_H = FRAMES_PER_SCOPE * NETWORK_SAMPLES_PER_FRAME; - static const unsigned int MULTIPLIER_SCOPE_V = 20; - static const unsigned int SAMPLES_PER_SCOPE_V = 2 * 15 * MULTIPLIER_SCOPE_V; + static const unsigned int SAMPLES_PER_SCOPE_WIDTH = FRAMES_PER_SCOPE * NETWORK_SAMPLES_PER_FRAME; + static const unsigned int MULTIPLIER_SCOPE_HEIGHT = 20; + static const unsigned int SAMPLES_PER_SCOPE_HEIGHT = 2 * 15 * MULTIPLIER_SCOPE_HEIGHT; bool _scopeEnabled; bool _scopeEnabledPause; int _scopeInputOffset; From 1ff3b83644e5eeaeb67ba168f08b78d8b8345af6 Mon Sep 17 00:00:00 2001 From: matsukaze Date: Tue, 22 Apr 2014 19:42:51 -0400 Subject: [PATCH 6/7] Changed const color data and method signatures. Changed constant color data and method signatures from unsigned int to array of float. Changed glColor4f to glColor4fv. --- interface/src/Audio.cpp | 36 +++++++++++++++--------------------- interface/src/Audio.h | 6 +++--- 2 files changed, 18 insertions(+), 24 deletions(-) diff --git a/interface/src/Audio.cpp b/interface/src/Audio.cpp index 5e9d343df6..29aaa3b34b 100644 --- a/interface/src/Audio.cpp +++ b/interface/src/Audio.cpp @@ -1110,11 +1110,11 @@ void Audio::renderScope(int width, int height) { if (!_scopeEnabled) return; - static const unsigned int backgroundColor = 0x33333399; - static const unsigned int gridColor = 0x44444499; - static const unsigned int inputColor = 0x44aa4499; - static const unsigned int outputLeftColor = 0xaa444499; - static const unsigned int outputRightColor = 0x4444aa99; + static const float backgroundColor[4] = { 0.2f, 0.2f, 0.2f, 0.6f }; + static const float gridColor[4] = { 0.3f, 0.3f, 0.3f, 0.6f }; + static const float inputColor[4] = { 0.3f, .7f, 0.3f, 0.6f }; + static const float outputLeftColor[4] = { 0.7f, .3f, 0.3f, 0.6f }; + static const float outputRightColor[4] = { 0.3f, .3f, 0.7f, 0.6f }; static const int gridRows = 2; static const int gridCols = 5; @@ -1130,26 +1130,24 @@ void Audio::renderScope(int width, int height) { renderLineStrip(outputRightColor, x, y, w, _scopeOutputOffset, _scopeOutputRight); } -void Audio::renderBackground(unsigned int rgba, int x, int y, int width, int height) { +void Audio::renderBackground(const float* color, int x, int y, int width, int height) { + + glColor4fv(color); glBegin(GL_QUADS); - glColor4f(((rgba >> 24) & 0xff) / 255.0f, - ((rgba >> 16) & 0xff) / 255.0f, - ((rgba >> 8) & 0xff) / 255.0f, - (rgba & 0xff) / 255.0f); + glVertex2i(x, y); glVertex2i(x + width, y); glVertex2i(x + width, y + height); glVertex2i(x , y + height); + glEnd(); glColor4f(1, 1, 1, 1); } -void Audio::renderGrid(unsigned int rgba, int x, int y, int width, int height, int rows, int cols) { +void Audio::renderGrid(const float* color, int x, int y, int width, int height, int rows, int cols) { + + glColor4fv(color); glBegin(GL_LINES); - glColor4f(((rgba >> 24) & 0xff) / 255.0f, - ((rgba >> 16) & 0xff) / 255.0f, - ((rgba >> 8) & 0xff) / 255.0f, - (rgba & 0xff) / 255.0f); int dx = width / cols; int dy = height / rows; @@ -1172,13 +1170,9 @@ void Audio::renderGrid(unsigned int rgba, int x, int y, int width, int height, i glColor4f(1, 1, 1, 1); } -void Audio::renderLineStrip(unsigned int rgba, int x, int y, int n, int offset, const QByteArray& byteArray) { - - glColor4f(((rgba >> 24) & 0xff) / 255.0f, - ((rgba >> 16) & 0xff) / 255.0f, - ((rgba >> 8) & 0xff) / 255.0f, - (rgba & 0xff) / 255.0f); +void Audio::renderLineStrip(const float* color, int x, int y, int n, int offset, const QByteArray& byteArray) { + glColor4fv(color); glBegin(GL_LINE_STRIP); int16_t sample; diff --git a/interface/src/Audio.h b/interface/src/Audio.h index 71030e39e3..c42b442a81 100644 --- a/interface/src/Audio.h +++ b/interface/src/Audio.h @@ -204,9 +204,9 @@ private: void addBufferToScope(QByteArray& byteArray, unsigned int frameOffset, const int16_t* src, unsigned int srcChannel, unsigned int srcNumChannels); // Audio scope methods for rendering - void renderBackground(unsigned int rgba, int x, int y, int width, int height); - void renderGrid(unsigned int rgba, int x, int y, int width, int height, int rows, int cols); - void renderLineStrip(unsigned int rgba, int x, int y, int n, int offset, const QByteArray& byteArray); + 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); + void renderLineStrip(const float* color, int x, int y, int n, int offset, const QByteArray& byteArray); // Audio scope data static const unsigned int NETWORK_SAMPLES_PER_FRAME = NETWORK_BUFFER_LENGTH_SAMPLES_PER_CHANNEL; From d6e4f217f5adeb7ee26e6e3a05cba405e1a31d43 Mon Sep 17 00:00:00 2001 From: matsukaze Date: Tue, 22 Apr 2014 21:57:41 -0400 Subject: [PATCH 7/7] Expanded variable names. --- interface/src/Audio.cpp | 8 ++++---- interface/src/Audio.h | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/interface/src/Audio.cpp b/interface/src/Audio.cpp index 29aaa3b34b..eb4a751356 100644 --- a/interface/src/Audio.cpp +++ b/interface/src/Audio.cpp @@ -1075,7 +1075,7 @@ void Audio::toggleScope() { } void Audio::addBufferToScope( - QByteArray& byteArray, unsigned int frameOffset, const int16_t* src, unsigned int srcChannel, unsigned int srcNumChannels) { + QByteArray& byteArray, unsigned int frameOffset, const int16_t* source, unsigned int sourceChannel, unsigned int sourceNumberOfChannels) { // Constant multiplier to map sample value to vertical size of scope float multiplier = (float)MULTIPLIER_SCOPE_HEIGHT / logf(2.0f); @@ -1087,11 +1087,11 @@ void Audio::addBufferToScope( int16_t value; // Short int pointer to mapped samples in byte array - int16_t* tgt = (int16_t*) byteArray.data(); + int16_t* destination = (int16_t*) byteArray.data(); for (int i = 0; i < NETWORK_SAMPLES_PER_FRAME; i++) { - sample = (float)src[i * srcNumChannels + srcChannel]; + sample = (float)source[i * sourceNumberOfChannels + sourceChannel]; if (sample > 0) { value = (int16_t)(multiplier * logf(sample)); @@ -1101,7 +1101,7 @@ void Audio::addBufferToScope( value = 0; } - tgt[i + frameOffset] = value; + destination[i + frameOffset] = value; } } diff --git a/interface/src/Audio.h b/interface/src/Audio.h index c42b442a81..ebd7f8612a 100644 --- a/interface/src/Audio.h +++ b/interface/src/Audio.h @@ -201,7 +201,8 @@ private: float calculateDeviceToNetworkInputRatio(int numBytes); // Audio scope methods for data acquisition - void addBufferToScope(QByteArray& byteArray, unsigned int frameOffset, const int16_t* src, unsigned int srcChannel, unsigned int srcNumChannels); + void addBufferToScope( + QByteArray& byteArray, unsigned int frameOffset, const int16_t* source, unsigned int sourceChannel, unsigned int sourceNumberOfChannels); // Audio scope methods for rendering void renderBackground(const float* color, int x, int y, int width, int height);