From 1884bfc17e9268d2d2dca3d22babaa2f61646b9b Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 26 Apr 2013 10:58:01 -0700 Subject: [PATCH 1/3] some spacing cleanup in Audio class --- interface/src/Audio.cpp | 78 +++++++---------------------------------- 1 file changed, 12 insertions(+), 66 deletions(-) diff --git a/interface/src/Audio.cpp b/interface/src/Audio.cpp index 1959b5ae33..f4fc3c35f1 100644 --- a/interface/src/Audio.cpp +++ b/interface/src/Audio.cpp @@ -114,15 +114,12 @@ int audioCallback (const void *inputBuffer, AudioData *data = (AudioData *) userData; int16_t *inputLeft = ((int16_t **) inputBuffer)[0]; -// int16_t *inputRight = ((int16_t **) inputBuffer)[1]; - //printLog("Audio callback at %6.0f\n", usecTimestampNow()/1000); + // printLog("Audio callback at %6.0f\n", usecTimestampNow()/1000); if (inputLeft != NULL) { - // // Measure the loudness of the signal from the microphone and store in audio object - // float loudness = 0; for (int i = 0; i < BUFFER_LENGTH_SAMPLES; i++) { loudness += abs(inputLeft[i]); @@ -130,10 +127,8 @@ int audioCallback (const void *inputBuffer, loudness /= BUFFER_LENGTH_SAMPLES; data->lastInputLoudness = loudness; - - // + // If scope is turned on, copy input buffer to scope - // if (scope->getState()) { for (int i = 0; i < BUFFER_LENGTH_SAMPLES; i++) { scope->addData((float)inputLeft[i]/32767.0, 1, i); @@ -174,42 +169,13 @@ int audioCallback (const void *inputBuffer, } if (data->mixerLoopbackFlag) { - correctedYaw = correctedYaw > 0 ? correctedYaw + AGENT_LOOPBACK_MODIFIER : correctedYaw - AGENT_LOOPBACK_MODIFIER; + correctedYaw = correctedYaw > 0 + ? correctedYaw + AGENT_LOOPBACK_MODIFIER + : correctedYaw - AGENT_LOOPBACK_MODIFIER; } memcpy(currentPacketPtr, &correctedYaw, sizeof(float)); - currentPacketPtr += sizeof(float); - -// if (samplesLeftForWalk == 0) { -// sampleWalkPointer = walkingSoundArray; -// } -// -// if (data->playWalkSound) { -// // if this boolean is true and we aren't currently playing the walk sound -// // set the number of samples left for walk -// samplesLeftForWalk = walkingSoundSamples; -// data->playWalkSound = false; -// } -// -// if (samplesLeftForWalk > 0) { -// // we need to play part of the walking sound -// // so add it in -// int affectedSamples = std::min(samplesLeftForWalk, BUFFER_LENGTH_SAMPLES); -// for (int i = 0; i < affectedSamples; i++) { -// inputLeft[i] += *sampleWalkPointer; -// inputLeft[i] = std::max(inputLeft[i], std::numeric_limits::min()); -// inputLeft[i] = std::min(inputLeft[i], std::numeric_limits::max()); -// -// sampleWalkPointer++; -// samplesLeftForWalk--; -// -// if (sampleWalkPointer - walkingSoundArray > walkingSoundSamples) { -// sampleWalkPointer = walkingSoundArray; -// }; -// } -// } -// - + currentPacketPtr += sizeof(float); // copy the audio data to the last BUFFER_LENGTH_BYTES bytes of the data packet memcpy(currentPacketPtr, inputLeft, BUFFER_LENGTH_BYTES); @@ -239,26 +205,21 @@ int audioCallback (const void *inputBuffer, starve_counter++; packetsReceivedThisPlayback = 0; - //printLog("Starved #%d\n", starve_counter); + // printLog("Starved #%d\n", starve_counter); data->wasStarved = 10; // Frames to render the indication that the system was starved. } else { if (!ringBuffer->isStarted()) { ringBuffer->setStarted(true); - //printLog("starting playback %3.1f msecs delayed \n", (usecTimestampNow() - usecTimestamp(&firstPlaybackTimer))/1000.0); + // printLog("starting playback %3.1f msecs delayed \n", (usecTimestampNow() - usecTimestamp(&firstPlaybackTimer))/1000.0); } else { - //printLog("pushing buffer\n"); + // printLog("pushing buffer\n"); } // play whatever we have in the audio buffer - // - // if we haven't fired off the flange effect, check if we should - // - // - // NOTE: PER - LastMeasuredHeadYaw is now relative to body position, represents the local - // rotation of the head relative to body, this may effect flange effect! - // - // + // if we haven't fired off the flange effect, check if we should + // TODO: lastMeasuredHeadYaw is now relative to body - check if this still works. + int lastYawMeasured = fabsf(data->linkedAvatar->getLastMeasuredHeadYaw()); if (!samplesLeftForFlange && lastYawMeasured > MIN_FLANGE_EFFECT_THRESHOLD) { @@ -277,21 +238,6 @@ int audioCallback (const void *inputBuffer, } } - // check if we have more than we need to play out -// int thresholdFrames = ceilf((PACKET_LENGTH_SAMPLES + JITTER_BUFFER_SAMPLES) / (float)PACKET_LENGTH_SAMPLES); -// int thresholdSamples = thresholdFrames * PACKET_LENGTH_SAMPLES; -// -// if (ringBuffer->diffLastWriteNextOutput() > thresholdSamples) { -// // we need to push the next output forwards -// int samplesToPush = ringBuffer->diffLastWriteNextOutput() - thresholdSamples; -// -// if (ringBuffer->getNextOutput() + samplesToPush > ringBuffer->getBuffer()) { -// ringBuffer->setNextOutput(ringBuffer->getBuffer() + (samplesToPush - (ringBuffer->getBuffer() + RING_BUFFER_SAMPLES - ringBuffer->getNextOutput()))); -// } else { -// ringBuffer->setNextOutput(ringBuffer->getNextOutput() + samplesToPush); -// } -// } - for (int s = 0; s < PACKET_LENGTH_SAMPLES_PER_CHANNEL; s++) { int leftSample = ringBuffer->getNextOutput()[s]; From fbdcd57529c5442bcc22b10b034ad8f848521522 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 26 Apr 2013 11:21:34 -0700 Subject: [PATCH 2/3] correct yaw sent to audio-mixer in Audio --- interface/src/Audio.cpp | 2 +- interface/src/Avatar.cpp | 5 ++++- interface/src/Avatar.h | 9 ++++++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/interface/src/Audio.cpp b/interface/src/Audio.cpp index f4fc3c35f1..cecfc9456a 100644 --- a/interface/src/Audio.cpp +++ b/interface/src/Audio.cpp @@ -160,7 +160,7 @@ int audioCallback (const void *inputBuffer, *(currentPacketPtr++) = 255; // memcpy the corrected render yaw - float correctedYaw = fmodf(data->linkedAvatar->getRenderYaw(), 360); + float correctedYaw = fmodf(data->linkedAvatar->getAbsoluteHeadYaw(), 360); if (correctedYaw > 180) { correctedYaw -= 360; diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index d5f778c70c..afe9632b45 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -275,13 +275,16 @@ void Avatar::UpdateGyros(float frametime, SerialInterface * serialInterface, glm addLean(-measured_lateral_accel * frametime * HEAD_LEAN_SCALE, -measured_fwd_accel*frametime * HEAD_LEAN_SCALE); } +float Avatar::getAbsoluteHeadYaw() { + return _bodyYaw + _headYaw; +} + void Avatar::addLean(float x, float z) { // Add Body lean as impulse _head.leanSideways += x; _head.leanForward += z; } - void Avatar::setLeanForward(float dist){ _head.leanForward = dist; } diff --git a/interface/src/Avatar.h b/interface/src/Avatar.h index f568f80313..b931574ee8 100644 --- a/interface/src/Avatar.h +++ b/interface/src/Avatar.h @@ -167,18 +167,21 @@ public: void reset(); void UpdateGyros(float frametime, SerialInterface * serialInterface, glm::vec3 * gravity); + void setNoise (float mag) { _head.noise = mag; } void setScale(float s) {_head.scale = s; }; void setRenderYaw(float y) {_renderYaw = y;} void setRenderPitch(float p) {_renderPitch = p;} float getRenderYaw() {return _renderYaw;} float getRenderPitch() {return _renderPitch;} - void setLeanForward(float dist); - void setLeanSideways(float dist); - void addLean(float x, float z); float getLastMeasuredHeadYaw() const {return _head.yawRate;} float getBodyYaw() {return _bodyYaw;}; void addBodyYaw(float y) {_bodyYaw += y;}; + + float getAbsoluteHeadYaw(); + void setLeanForward(float dist); + void setLeanSideways(float dist); + void addLean(float x, float z); const glm::vec3& getHeadLookatDirection() const { return _orientation.getFront(); }; const glm::vec3& getHeadLookatDirectionUp() const { return _orientation.getUp(); }; From 7c855464e1ec916d3f138cdfdef8c60c8e402f3c Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 26 Apr 2013 11:22:42 -0700 Subject: [PATCH 3/3] make the absolute head yaw getter const --- interface/src/Avatar.cpp | 2 +- interface/src/Avatar.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index afe9632b45..da5ac35893 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -275,7 +275,7 @@ void Avatar::UpdateGyros(float frametime, SerialInterface * serialInterface, glm addLean(-measured_lateral_accel * frametime * HEAD_LEAN_SCALE, -measured_fwd_accel*frametime * HEAD_LEAN_SCALE); } -float Avatar::getAbsoluteHeadYaw() { +float Avatar::getAbsoluteHeadYaw() const { return _bodyYaw + _headYaw; } diff --git a/interface/src/Avatar.h b/interface/src/Avatar.h index b931574ee8..c03734b156 100644 --- a/interface/src/Avatar.h +++ b/interface/src/Avatar.h @@ -178,7 +178,7 @@ public: float getBodyYaw() {return _bodyYaw;}; void addBodyYaw(float y) {_bodyYaw += y;}; - float getAbsoluteHeadYaw(); + float getAbsoluteHeadYaw() const; void setLeanForward(float dist); void setLeanSideways(float dist); void addLean(float x, float z);