From e1645b11584d56369373d0d416a55440c81dfbe4 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Tue, 7 May 2013 12:48:35 -0700 Subject: [PATCH 1/2] 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/2] 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; }