From 2d7c3971387f857678358981cf1affd35ea4c41c Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 31 May 2013 15:47:54 -0700 Subject: [PATCH] create a FreeVerb object for each other agent per agent --- audio-mixer/src/main.cpp | 38 ++++++++++++++++++--------- injector/CMakeLists.txt | 8 +++++- interface/CMakeLists.txt | 6 +++++ interface/src/Application.cpp | 2 +- interface/src/Avatar.cpp | 4 +-- interface/src/Head.cpp | 4 +-- interface/src/Transmitter.cpp | 2 ++ interface/src/Util.cpp | 8 +++--- interface/src/world.h | 1 - libraries/audio/CMakeLists.txt | 8 +++++- libraries/audio/src/AudioRingBuffer.h | 6 +++++ libraries/shared/src/AgentList.cpp | 2 +- 12 files changed, 63 insertions(+), 26 deletions(-) diff --git a/audio-mixer/src/main.cpp b/audio-mixer/src/main.cpp index 47389a51ce..66bc196ef2 100644 --- a/audio-mixer/src/main.cpp +++ b/audio-mixer/src/main.cpp @@ -162,11 +162,10 @@ int main(int argc, const char* argv[]) { int numSamplesDelay = 0; float weakChannelAmplitudeRatio = 1.f; - // setup the FreeVerb object for this client and source - stk::FreeVerb freeVerb; - freeVerb.setEffectMix(0.0f); + stk::FreeVerb* otherAgentFreeVerb = NULL; if (otherAgent != agent) { + glm::vec3 agentPosition = agentRingBuffer->getPosition(); glm::vec3 otherAgentPosition = otherAgentBuffer->getPosition(); @@ -243,19 +242,28 @@ int main(int argc, const char* argv[]) { * otherAgentBuffer->getAttenuationRatio() * offAxisCoefficient; - // setup the freeVerb effect for this source for this client - freeVerb.setDamping(DISTANCE_REVERB_DAMPING); - freeVerb.setRoomSize(DISTANCE_REVERB_ROOM_SIZE); - freeVerb.setWidth(DISTANCE_REVERB_WIDTH); - - printf("EM set to %f\n", audioFactors[lowAgentIndex][highAgentIndex].effectMix); - freeVerb.setEffectMix(audioFactors[lowAgentIndex][highAgentIndex].effectMix); - bearingRelativeAngleToSource *= (M_PI / 180); float sinRatio = fabsf(sinf(bearingRelativeAngleToSource)); numSamplesDelay = PHASE_DELAY_AT_90 * sinRatio; weakChannelAmplitudeRatio = 1 - (PHASE_AMPLITUDE_RATIO_AT_90 * sinRatio); + + std::map& agentFreeVerbs = agentRingBuffer->getFreeVerbs(); + + if (agentFreeVerbs.count(otherAgent->getAgentID()) == 0) { + // setup the freeVerb effect for this source for this client + + otherAgentFreeVerb = agentFreeVerbs[otherAgent->getAgentID()] = new stk::FreeVerb; + + otherAgentFreeVerb->setDamping(DISTANCE_REVERB_DAMPING); + otherAgentFreeVerb->setRoomSize(DISTANCE_REVERB_ROOM_SIZE); + otherAgentFreeVerb->setWidth(DISTANCE_REVERB_WIDTH); + + } else { + otherAgentFreeVerb = agentFreeVerbs[otherAgent->getAgentID()]; + } + + otherAgentFreeVerb->setEffectMix(audioFactors[lowAgentIndex][highAgentIndex].effectMix); } int16_t* goodChannel = bearingRelativeAngleToSource > 0.0f @@ -278,7 +286,9 @@ int main(int argc, const char* argv[]) { * weakChannelAmplitudeRatio; // apply the STK FreeVerb effect - earlierSample = freeVerb.tick(earlierSample); + if (otherAgentFreeVerb) { + earlierSample = otherAgentFreeVerb->tick(earlierSample); + } plateauAdditionOfSamples(delayedChannel[s], earlierSample); } @@ -286,7 +296,9 @@ int main(int argc, const char* argv[]) { int16_t currentSample = (otherAgentBuffer->getNextOutput()[s] * attenuationCoefficient); // apply the STK FreeVerb effect - currentSample = freeVerb.tick(currentSample); + if (otherAgentFreeVerb) { + currentSample = otherAgentFreeVerb->tick(currentSample); + } plateauAdditionOfSamples(goodChannel[s], currentSample); diff --git a/injector/CMakeLists.txt b/injector/CMakeLists.txt index 2c022b0e92..83a650c62e 100644 --- a/injector/CMakeLists.txt +++ b/injector/CMakeLists.txt @@ -19,4 +19,10 @@ include_glm(${TARGET_NAME} ${ROOT_DIR}) include(${MACRO_DIR}/LinkHifiLibrary.cmake) link_hifi_library(shared ${TARGET_NAME} ${ROOT_DIR}) link_hifi_library(audio ${TARGET_NAME} ${ROOT_DIR}) -link_hifi_library(avatars ${TARGET_NAME} ${ROOT_DIR}) \ No newline at end of file +link_hifi_library(avatars ${TARGET_NAME} ${ROOT_DIR}) + +# link the stk library +set(STK_ROOT_DIR ${ROOT_DIR}/externals/stk) +find_package(STK REQUIRED) +target_link_libraries(${TARGET_NAME} ${STK_LIBRARIES}) +include_directories(${STK_INCLUDE_DIRS}) \ No newline at end of file diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index d5da2073fb..adda538ff2 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -146,6 +146,12 @@ else (WIN32) include_directories(${PORTAUDIO_INCLUDE_DIRS}) target_link_libraries(${TARGET_NAME} ${PORTAUDIO_LIBRARIES}) + # link the stk library + set(STK_ROOT_DIR ${ROOT_DIR}/externals/stk) + find_package(STK REQUIRED) + target_link_libraries(${TARGET_NAME} ${STK_LIBRARIES}) + include_directories(${STK_INCLUDE_DIRS}) + # link required libraries on UNIX if (UNIX AND NOT APPLE) find_package(Threads REQUIRED) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index bf68798d62..83522fcc74 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -380,7 +380,7 @@ void Application::resizeGL(int width, int height) { if (OculusManager::isConnected()) { // more magic numbers; see Oculus SDK docs, p. 32 camera.setAspectRatio(aspectRatio *= 0.5); - camera.setFieldOfView(fov = 2 * atan((0.0468 * _oculusDistortionScale) / 0.041) * (180 / PI)); + camera.setFieldOfView(fov = 2 * atan((0.0468 * _oculusDistortionScale) / 0.041) * (180 / PIf)); // resize the render texture if (_oculusTextureID != 0) { diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 68fd9b1c8e..ff23b3247e 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -792,7 +792,7 @@ void Avatar::render(bool lookingInMirror, glm::vec3 cameraPosition) { glTranslatef(_joint[AVATAR_JOINT_HEAD_BASE].springyPosition.x, _joint[AVATAR_JOINT_HEAD_BASE].springyPosition.y + chatMessageHeight, _joint[AVATAR_JOINT_HEAD_BASE].springyPosition.z); - glRotatef(atan2(-modelview[2], -modelview[10]) * 180 / PI, 0, 1, 0); + glRotatef(atan2(-modelview[2], -modelview[10]) * 180 / PIf, 0, 1, 0); glColor3f(0, 0.8, 0); glRotatef(180, 0, 0, 1); @@ -1274,7 +1274,7 @@ void Avatar::renderJointConnectingCone(glm::vec3 position1, glm::vec3 position2, // the rectangles that comprise the sides of the cone section are // referenced by "a" and "b" in one dimension, and "1", and "2" in the other dimension. anglea = angleb; - angleb = ((float)(i+1) / (float)NUM_BODY_CONE_SIDES) * PI * 2.0f; + angleb = ((float)(i+1) / (float)NUM_BODY_CONE_SIDES) * PIf * 2.0f; float sa = sinf(anglea); float sb = sinf(angleb); diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index 65d6c71860..baf9c5e468 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -250,9 +250,9 @@ void Head::createMohawk() { for (int i = 1; i < MOHAWK_TRIANGLES; i++) { _mohawkTriangleFan[i] = glm::vec3((randFloat() - 0.5f) * variance, - height * cosf(i * RAD_PER_TRIANGLE - PI / 2.f) + height * cosf(i * RAD_PER_TRIANGLE - PIf / 2.f) + (randFloat() - 0.5f) * variance, - height * sinf(i * RAD_PER_TRIANGLE - PI / 2.f) + height * sinf(i * RAD_PER_TRIANGLE - PIf / 2.f) + (randFloat() - 0.5f) * variance); _mohawkColors[i] = randFloat() * basicColor; diff --git a/interface/src/Transmitter.cpp b/interface/src/Transmitter.cpp index 5f6def92f7..15fe7ac9c4 100644 --- a/interface/src/Transmitter.cpp +++ b/interface/src/Transmitter.cpp @@ -51,6 +51,8 @@ void Transmitter::processIncomingData(unsigned char* packetData, int numBytes) { // Update estimated absolute position from rotation rates _estimatedRotation += _lastRotationRate * DELTA_TIME; + + printf("The accel %f, %f, %f\n", _lastAcceleration.x, _lastAcceleration.y, _lastAcceleration.z); // Sensor Fusion! Slowly adjust estimated rotation to be relative to gravity (average acceleration) const float GRAVITY_FOLLOW_RATE = 1.f; diff --git a/interface/src/Util.cpp b/interface/src/Util.cpp index 2df1196a86..e38eadc5d3 100644 --- a/interface/src/Util.cpp +++ b/interface/src/Util.cpp @@ -68,7 +68,7 @@ float angle_to(glm::vec3 head_pos, glm::vec3 source_pos, float render_yaw, float // Helper function returns the positive angle in degrees between two 3D vectors float angleBetween(const glm::vec3& v1, const glm::vec3& v2) { - return acos((glm::dot(v1, v2)) / (glm::length(v1) * glm::length(v2))) * 180.f / PI; + return acos((glm::dot(v1, v2)) / (glm::length(v1) * glm::length(v2))) * 180.f / PIf; } // Draw a 3D vector floating in space @@ -275,7 +275,7 @@ void renderDiskShadow(glm::vec3 position, glm::vec3 upDirection, float radius, f for (int i=1; i +#include #include +#include +#include #include "AgentData.h" @@ -32,6 +35,8 @@ public: int16_t* getBuffer() const { return _buffer; } + std::map& getFreeVerbs() { return _freeVerbs; } + bool isStarted() const { return _started; } void setStarted(bool started) { _started = started; } @@ -62,6 +67,7 @@ private: bool _shouldBeAddedToMix; bool _shouldLoopbackForAgent; unsigned char _streamIdentifier[STREAM_IDENTIFIER_NUM_BYTES]; + std::map _freeVerbs; }; #endif /* defined(__interface__AudioRingBuffer__) */ diff --git a/libraries/shared/src/AgentList.cpp b/libraries/shared/src/AgentList.cpp index 2b28ac620d..6c4d2d9a71 100644 --- a/libraries/shared/src/AgentList.cpp +++ b/libraries/shared/src/AgentList.cpp @@ -30,7 +30,7 @@ const char SOLO_AGENT_TYPES[3] = { }; char DOMAIN_HOSTNAME[] = "highfidelity.below92.com"; -char DOMAIN_IP[100] = ""; // IP Address will be re-set by lookup on startup +char DOMAIN_IP[100] = "192.168.1.47"; // IP Address will be re-set by lookup on startup const int DOMAINSERVER_PORT = 40102; bool silentAgentThreadStopFlag = false;