From e1645b11584d56369373d0d416a55440c81dfbe4 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Tue, 7 May 2013 12:48:35 -0700 Subject: [PATCH 1/3] Testing audio noise generation at client --- interface/src/Audio.cpp | 6 +++++- voxel-edit/src/main.cpp | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/interface/src/Audio.cpp b/interface/src/Audio.cpp index 7474f434b7..6a287a84f1 100644 --- a/interface/src/Audio.cpp +++ b/interface/src/Audio.cpp @@ -111,7 +111,11 @@ int audioCallback (const void *inputBuffer, int16_t *inputLeft = ((int16_t **) inputBuffer)[0]; - // printLog("Audio callback at %6.0f\n", usecTimestampNow()/1000); + // Add some noise to the audio we got from the callback + + for (int i = 0; i < BUFFER_LENGTH_SAMPLES; i++) { + inputLeft[i] = (int16_t) (rand() % 65536); + } if (inputLeft != NULL) { diff --git a/voxel-edit/src/main.cpp b/voxel-edit/src/main.cpp index 5a474f15ee..d93effc7fd 100644 --- a/voxel-edit/src/main.cpp +++ b/voxel-edit/src/main.cpp @@ -19,6 +19,10 @@ bool countVoxelsOperation(VoxelNode* node, void* extraData) { return true; // keep going } +void addLandscape(VoxelTree * tree) { + printf("Adding Landscape...\n"); +} + void addScene(VoxelTree * tree) { printf("adding scene...\n"); From baf64c07dcc10b3a8a8e45f609a490bde3d0939f Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Wed, 8 May 2013 09:04:38 -0700 Subject: [PATCH 2/3] Added Procedural audio noise when moving, scaled to velocity --- interface/src/Audio.cpp | 7 ++----- interface/src/Audio.h | 3 +++ interface/src/AudioData.cpp | 16 ++++++++++++++++ interface/src/AudioData.h | 11 +++++++++++ interface/src/Avatar.h | 1 + interface/src/main.cpp | 7 ++++++- 6 files changed, 39 insertions(+), 6 deletions(-) diff --git a/interface/src/Audio.cpp b/interface/src/Audio.cpp index 6a287a84f1..916783bc32 100644 --- a/interface/src/Audio.cpp +++ b/interface/src/Audio.cpp @@ -111,11 +111,8 @@ int audioCallback (const void *inputBuffer, int16_t *inputLeft = ((int16_t **) inputBuffer)[0]; - // Add some noise to the audio we got from the callback - - for (int i = 0; i < BUFFER_LENGTH_SAMPLES; i++) { - inputLeft[i] = (int16_t) (rand() % 65536); - } + // Add Procedural effects to input samples + data->addProceduralSounds(inputLeft, BUFFER_LENGTH_SAMPLES); if (inputLeft != NULL) { diff --git a/interface/src/Audio.h b/interface/src/Audio.h index 73ff7f32d1..8f562e1fe6 100644 --- a/interface/src/Audio.h +++ b/interface/src/Audio.h @@ -30,6 +30,9 @@ public: void setWalkingState(bool newWalkState); + void setLastAcceleration(glm::vec3 a) { audioData->setLastAcceleration(a); }; + void setLastVelocity(glm::vec3 v) { audioData->setLastVelocity(v); }; + // terminates audio I/O bool terminate(); private: diff --git a/interface/src/AudioData.cpp b/interface/src/AudioData.cpp index 600cfa8d4d..f86af9a06e 100644 --- a/interface/src/AudioData.cpp +++ b/interface/src/AudioData.cpp @@ -28,4 +28,20 @@ AudioData::~AudioData() { delete audioSocket; } +// Take a pointer to the acquired microphone input samples and add procedural sounds +void AudioData::addProceduralSounds(int16_t* inputBuffer, int numSamples) { + const float MAX_AUDIBLE_VELOCITY = 3.0; + const float MIN_AUDIBLE_VELOCITY = 0.1; + const float VOLUME = 200; + float speed = glm::length(_lastVelocity); + if ((speed > MIN_AUDIBLE_VELOCITY) && (speed < MAX_AUDIBLE_VELOCITY)) { + for (int i = 0; i < numSamples; i++) { + inputBuffer[i] += (int16_t) ((randFloat() - 0.5f) * VOLUME * speed) ; + } + } + + return; +} + + #endif diff --git a/interface/src/AudioData.h b/interface/src/AudioData.h index 520291e3e6..bc545031d9 100644 --- a/interface/src/AudioData.h +++ b/interface/src/AudioData.h @@ -39,6 +39,17 @@ class AudioData { bool mixerLoopbackFlag; bool playWalkSound; + + // Added avatar acceleration and velocity for procedural effects sounds from client + void setLastVelocity(glm::vec3 v) { _lastVelocity = v; }; + void setLastAcceleration(glm::vec3 a) { _lastAcceleration = a; }; + void addProceduralSounds(int16_t* inputBuffer, int numSamples); + + private: + glm::vec3 _lastVelocity; + glm::vec3 _lastAcceleration; + + }; #endif /* defined(__interface__AudioData__) */ diff --git a/interface/src/Avatar.h b/interface/src/Avatar.h index 29896556a5..8f5c603b96 100644 --- a/interface/src/Avatar.h +++ b/interface/src/Avatar.h @@ -105,6 +105,7 @@ public: const glm::vec3& getJointPosition(AvatarJointID j) const { return _joint[j].position; }; const glm::vec3& getBodyUpDirection() const { return _orientation.getUp(); }; float getSpeed() const { return _speed; }; + const glm::vec3& getVelocity() const { return _velocity; }; float getGirth(); float getHeight(); diff --git a/interface/src/main.cpp b/interface/src/main.cpp index bfcb6c9dc8..bf1b859336 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -1671,6 +1671,7 @@ void idle(void) { handControl.stop(); } + // Read serial port interface devices if (serialPort.active && USING_INVENSENSE_MPU9150) { serialPort.readData(); } @@ -1696,7 +1697,11 @@ void idle(void) { myAvatar.setGravity(getGravity(myAvatar.getPosition())); myAvatar.simulate(deltaTime); - + + // Update audio stats for procedural sounds + audio.setLastAcceleration(myAvatar.getThrust()); + audio.setLastVelocity(myAvatar.getVelocity()); + glutPostRedisplay(); lastTimeIdle = check; } From 5052f4af5e7ec405b3bcb39a93305dab680b5d4c Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Wed, 8 May 2013 17:26:44 -0700 Subject: [PATCH 3/3] Added render option for avatars, code cleanup. --- interface/src/main.cpp | 79 +++++++++++++++++++++++------------------- 1 file changed, 44 insertions(+), 35 deletions(-) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index abbb67cdbc..47f9004f2b 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -120,8 +120,6 @@ char starFile[] = "https://s3-us-west-1.amazonaws.com/highfidelity/stars.txt"; char starCacheFile[] = "cachedStars.txt"; Stars stars; -bool showingVoxels = true; - glm::vec3 box(WORLD_SIZE,WORLD_SIZE,WORLD_SIZE); VoxelSystem voxels; @@ -136,16 +134,18 @@ Audio audio(&audioScope, &myAvatar); #endif #define IDLE_SIMULATE_MSECS 16 // How often should call simulate and other stuff - // in the idle loop? + // in the idle loop? (60 FPS is default) -// Where one's own agent begins in the world (needs to become a dynamic thing passed to the program) -glm::vec3 start_location(6.1f, 0, 1.4f); + +glm::vec3 start_location(6.1f, 0, 1.4f); // Where one's own agent begins in the world + // (will be overwritten if avatar data file is found) bool renderWarningsOn = false; // Whether to show render pipeline warnings - -bool statsOn = false; // Whether to show onscreen text overlay with stats -bool starsOn = false; // Whether to display the stars -bool atmosphereOn = true; // Whether to display the atmosphere +bool renderStatsOn = false; // Whether to show onscreen text overlay with stats +bool renderVoxels = true; // Whether to render voxels +bool renderStarsOn = true; // Whether to display the stars +bool renderAtmosphereOn = true; // Whether to display the atmosphere +bool renderAvatarsOn = true; // Whether to render avatars bool paintOn = false; // Whether to paint voxels as you fly around VoxelDetail paintingVoxel; // The voxel we're painting if we're painting unsigned char dominantColor = 0; // The dominant color of the voxel we're painting @@ -683,12 +683,12 @@ void renderViewFrustum(ViewFrustum& viewFrustum) { void displaySide(Camera& whichCamera) { glPushMatrix(); - if (::starsOn) { + if (::renderStarsOn) { // should be the first rendering pass - w/o depth buffer / lighting // compute starfield alpha based on distance from atmosphere float alpha = 1.0f; - if (::atmosphereOn) { + if (::renderAtmosphereOn) { float height = glm::distance(whichCamera.getPosition(), environment.getAtmosphereCenter()); if (height < environment.getAtmosphereInnerRadius()) { alpha = 0.0f; @@ -704,7 +704,7 @@ void displaySide(Camera& whichCamera) { } // draw the sky dome - if (::atmosphereOn) { + if (::renderAtmosphereOn) { environment.renderAtmosphere(whichCamera); } @@ -722,29 +722,31 @@ void displaySide(Camera& whichCamera) { drawGroundPlaneGrid(10.f); // Draw voxels - if (showingVoxels) { + if (renderVoxels) { voxels.render(); } - // Render avatars of other agents - AgentList* agentList = AgentList::getInstance(); - agentList->lock(); - for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { - if (agent->getLinkedData() != NULL && agent->getType() == AGENT_TYPE_AVATAR) { - Avatar *avatar = (Avatar *)agent->getLinkedData(); - avatar->render(0, ::myCamera.getPosition()); + if (::renderAvatarsOn) { + // Render avatars of other agents + AgentList* agentList = AgentList::getInstance(); + agentList->lock(); + for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { + if (agent->getLinkedData() != NULL && agent->getType() == AGENT_TYPE_AVATAR) { + Avatar *avatar = (Avatar *)agent->getLinkedData(); + avatar->render(0, ::myCamera.getPosition()); + } } + agentList->unlock(); + + // Render my own Avatar + myAvatar.render(::lookingInMirror, ::myCamera.getPosition()); } - agentList->unlock(); // Render the world box - if (!::lookingInMirror && ::statsOn) { render_world_box(); } + if (!::lookingInMirror && ::renderStatsOn) { render_world_box(); } // brad's frustum for debugging if (::frustumOn) renderViewFrustum(::viewFrustum); - - //Render my own avatar - myAvatar.render(::lookingInMirror, ::myCamera.getPosition()); glPopMatrix(); } @@ -915,7 +917,7 @@ void displayOverlay() { //noiseTest(WIDTH, HEIGHT); - if (displayHeadMouse && !::lookingInMirror && statsOn) { + if (displayHeadMouse && !::lookingInMirror && renderStatsOn) { // Display small target box at center or head mouse target that can also be used to measure LOD glColor3f(1.0, 1.0, 1.0); glDisable(GL_LINE_SMOOTH); @@ -937,7 +939,7 @@ void displayOverlay() { glLineWidth(1.0f); glPointSize(1.0f); - if (::statsOn) { displayStats(); } + if (::renderStatsOn) { displayStats(); } if (::logOn) { logger.render(WIDTH, HEIGHT); } // Show menu @@ -1222,17 +1224,23 @@ int setFullscreen(int state) { } int setVoxels(int state) { - return setValue(state, &::showingVoxels); + return setValue(state, &::renderVoxels); } int setStars(int state) { - return setValue(state, &::starsOn); + return setValue(state, &::renderStarsOn); } int setAtmosphere(int state) { - return setValue(state, &::atmosphereOn); + return setValue(state, &::renderAtmosphereOn); } +int setRenderAvatars(int state) { + return setValue(state, &::renderAvatarsOn); +} + + + int setOculus(int state) { bool wasOn = ::oculusOn; int value = setValue(state, &::oculusOn); @@ -1243,7 +1251,7 @@ int setOculus(int state) { } int setStats(int state) { - return setValue(state, &::statsOn); + return setValue(state, &::renderStatsOn); } int setMenu(int state) { @@ -1379,6 +1387,7 @@ void initMenu() { menuColumnRender->addRow("Voxels (V)", setVoxels); menuColumnRender->addRow("Stars (*)", setStars); menuColumnRender->addRow("Atmosphere (A)", setAtmosphere); + menuColumnRender->addRow("Avatars", setRenderAvatars); menuColumnRender->addRow("Oculus (o)", setOculus); // Tools @@ -1541,10 +1550,10 @@ void key(unsigned char k, int x, int y) { // Process keypresses if (k == 'q' || k == 'Q') ::terminate(); - if (k == '/') ::statsOn = !::statsOn; // toggle stats - if (k == '*') ::starsOn = !::starsOn; // toggle stars - if (k == 'V' || k == 'v') ::showingVoxels = !::showingVoxels; // toggle voxels - if (k == 'A') ::atmosphereOn = !::atmosphereOn; + if (k == '/') ::renderStatsOn = !::renderStatsOn; // toggle stats + if (k == '*') ::renderStarsOn = !::renderStarsOn; // toggle stars + if (k == 'V' || k == 'v') ::renderVoxels = !::renderVoxels; // toggle voxels + if (k == 'A') ::renderAtmosphereOn = !::renderAtmosphereOn; if (k == 'F') ::frustumOn = !::frustumOn; // toggle view frustum debugging if (k == 'C') ::cameraFrustum = !::cameraFrustum; // toggle which frustum to look at if (k == 'O' || k == 'G') setFrustumOffset(MENU_ROW_PICKED); // toggle view frustum offset debugging