From 77f32b82117671982db1edec8e209171ce8d8c22 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Tue, 5 Feb 2013 19:43:15 -0800 Subject: [PATCH] Added measured jitter indicator (stdev() of packet receipt times) to audio renderer. Also added head being rendered in world at 0,0 as dummy. --- Source/Audio.cpp | 29 ++++++++++++++++++----------- Source/AudioData.cpp | 1 + Source/AudioData.h | 1 + Source/Head.cpp | 6 ++++++ Source/Head.h | 2 ++ Source/Lattice.cpp | 6 ++++-- Source/main.cpp | 30 ++++++++++++++++++++++-------- 7 files changed, 54 insertions(+), 21 deletions(-) diff --git a/Source/Audio.cpp b/Source/Audio.cpp index f5e633ce30..9bb1d30259 100644 --- a/Source/Audio.cpp +++ b/Source/Audio.cpp @@ -43,7 +43,7 @@ int starve_counter = 0; StDev stdev; -#define LOG_SAMPLE_DELAY 0 +#define LOG_SAMPLE_DELAY 1 bool Audio::initialized; PaError Audio::err; @@ -242,9 +242,12 @@ void *receiveAudioViaUDP(void *args) { if (firstSample) { stdev.reset(); } else { - stdev.addValue(diffclock(&previousReceiveTime, ¤tReceiveTime)); + double tDiff = diffclock(&previousReceiveTime, ¤tReceiveTime); + //printf(\n"; + stdev.addValue(tDiff); if (stdev.getSamples() > 500) { - printf("Avg: %4.2f, Stdev: %4.2f\n", stdev.getAverage(), stdev.getStDev()); + sharedAudioData->jitter = stdev.getStDev(); + printf("Avg: %4.2f, Stdev: %4.2f\n", stdev.getAverage(), sharedAudioData->jitter); stdev.reset(); } } @@ -458,21 +461,25 @@ void Audio::render(int screenWidth, int screenHeight) char out[20]; sprintf(out, "%3.0f\n", data->averagedLatency/(float)frameWidth*(1000.0*(float)BUFFER_LENGTH_SAMPLES/(float)SAMPLE_RATE)); - drawtext(startX + data->averagedLatency, topY-10, 0.1, 0, 1, 0, out); + drawtext(startX + data->averagedLatency - 10, topY-10, 0.08, 0, 1, 0, out, 1,1,0); // Show a Cyan bar with the most recently measured jitter stdev - /* - int jitter = (float)stdev.getStDev() / ((1000.0*(float)BUFFER_LENGTH_SAMPLES/(float)SAMPLE_RATE)) * (float)frameWidth; + + int jitterPels = (float) data->jitter/ ((1000.0*(float)BUFFER_LENGTH_SAMPLES/(float)SAMPLE_RATE)) * (float)frameWidth; glColor3f(0,1,1); glBegin(GL_QUADS); - glVertex2f(startX + jitter - 2, topY - 2); - glVertex2f(startX + jitter + 2, topY - 2); - glVertex2f(startX + jitter + 2, bottomY + 2); - glVertex2f(startX + jitter - 2, bottomY + 2); + glVertex2f(startX + jitterPels - 2, topY - 2); + glVertex2f(startX + jitterPels + 2, topY - 2); + glVertex2f(startX + jitterPels + 2, bottomY + 2); + glVertex2f(startX + jitterPels - 2, bottomY + 2); glEnd(); - */ + + sprintf(out,"%3.1f\n", data->jitter); + drawtext(startX + jitterPels - 5, topY-10, 0.08, 0, 1, 0, out, 0,1,1); + + //glVertex2f(nextOutputX, topY); //glVertex2f(nextOutputX, bottomY); diff --git a/Source/AudioData.cpp b/Source/AudioData.cpp index c86a3b6fdb..7497f31d96 100644 --- a/Source/AudioData.cpp +++ b/Source/AudioData.cpp @@ -27,6 +27,7 @@ AudioData::AudioData(int numberOfSources, int bufferLength) { averagedLatency = 0.0; lastCallback.tv_usec = 0; wasStarved = 0; + jitter = 0; } AudioData::~AudioData() { diff --git a/Source/AudioData.h b/Source/AudioData.h index 4a28b966f8..2b026b2fda 100644 --- a/Source/AudioData.h +++ b/Source/AudioData.h @@ -28,6 +28,7 @@ class AudioData { timeval lastCallback; float averagedLatency; + float jitter; int wasStarved; AudioData(int bufferLength); diff --git a/Source/Head.cpp b/Source/Head.cpp index 8a66d11128..b7c57d4896 100644 --- a/Source/Head.cpp +++ b/Source/Head.cpp @@ -52,6 +52,7 @@ Head::Head() leanSideways = 0.0; eyeContact = 1; eyeContactTarget = LEFT_EYE; + scale = 1.0; setNoise(1); } @@ -206,6 +207,9 @@ void Head::render() int side = 0; glEnable(GL_DEPTH_TEST); + glPushMatrix(); + + glScalef(scale, scale, scale); glTranslatef(leanSideways, 0.f, leanForward); glRotatef(Yaw/2.0, 0, 1, 0); @@ -306,6 +310,8 @@ void Head::render() //glRotatef(90,0,1,0); glutSolidSphere(PupilSize, 15, 15); glPopMatrix(); + + glPopMatrix(); } diff --git a/Source/Head.h b/Source/Head.h index 910e41463f..0c5ad0e692 100644 --- a/Source/Head.h +++ b/Source/Head.h @@ -45,6 +45,7 @@ class Head { float YawTarget; float NoiseEnvelope; float PupilConverge; + float scale; glm::vec3 position; int eyeContact; eyeContactTargets eyeContactTarget; @@ -59,6 +60,7 @@ public: void setPitch(float p) {Pitch = p; } void setYaw(float y) {Yaw = y; } void setRoll(float r) {Roll = r; }; + void setScale(float s) {scale = s; }; void setRenderYaw(float y) {renderYaw = y;} void setLeanForward(float dist); void setLeanSideways(float dist); diff --git a/Source/Lattice.cpp b/Source/Lattice.cpp index f35287e2b7..443d3fe51d 100644 --- a/Source/Lattice.cpp +++ b/Source/Lattice.cpp @@ -64,9 +64,11 @@ void Lattice::mouseOver(float x, float y) { // Update lattice based on mouse location, where x and y are floats between 0 and 1 corresponding to screen location clicked // Excite the hovered cell a bit toward firing //printf("X = %3.1f Y = %3.1f\n", x, y); - int index = int(x*(float)width) + int(y*(float)height)*width; - if (tiles[index].type > 0) tiles[index].excited += 0.05; + if ((width + height) > 0) { + int index = int(x*(float)width) + int(y*(float)height)*width; + if (tiles[index].type > 0) tiles[index].excited += 0.05; //printf("excited = %3.1f, inhibited = %3.1f\n", tiles[index].excited, tiles[index].inhibited); + } } void Lattice::simulate(float deltaTime) { diff --git a/Source/main.cpp b/Source/main.cpp index b61bfab762..2b5d95bdaf 100644 --- a/Source/main.cpp +++ b/Source/main.cpp @@ -9,9 +9,9 @@ // Keyboard Commands: // // / = toggle stats display -// n = toggle noise in firing on/off -// c = clear all cells and synapses to zero -// s = clear cells to zero but preserve synapse weights +// spacebar = reset gyros/head +// h = render Head +// l = show incoming gyro levels // //#define MARKER_CAPTURE // yep. @@ -85,8 +85,11 @@ int WIDTH = 1200; int HEIGHT = 800; int fullscreen = 0; -#define HAND_RADIUS 0.25 // Radius of in-world 'hand' of you -Head myHead; // The rendered head of oneself or others +#define HAND_RADIUS 0.25 // Radius of in-world 'hand' of you +Head myHead; // The rendered head of oneself or others +Head dummyHead; // Test Head to render +int showDummyHead = 1; + Hand myHand(HAND_RADIUS, glm::vec3(0,1,1)); // My hand (used to manipulate things in world) @@ -278,6 +281,13 @@ void init(void) { myHead.setRenderYaw(start_yaw); + dummyHead.setPitch(0); + dummyHead.setRoll(0); + dummyHead.setYaw(0); + dummyHead.setScale(0.25); + + dummyHead.setPos(glm::vec3(0,0,0)); + if (audio_on) { if (serial_on) { Audio::init(&myHead); @@ -300,6 +310,7 @@ void init(void) { myHand.setNoise(noise); myHead.setNoise(noise); + dummyHead.setNoise(noise); } if (serial_on) @@ -494,12 +505,13 @@ void update_pos(float frametime) balls.updateHand(myHead.getPos() + myHand.getPos(), glm::vec3(0,0,0), myHand.getRadius()); // Update all this stuff to any agents that are nearby and need to see it! - /* + const int MAX_BROADCAST_STRING = 200; char broadcast_string[MAX_BROADCAST_STRING]; int broadcast_bytes = myHead.getBroadcastData(broadcast_string); + //printf("head bytes: %d\n", broadcast_bytes); broadcast_to_agents(UDP_socket, broadcast_string, broadcast_bytes); - */ + } int render_test_spot = WIDTH/2; @@ -554,12 +566,14 @@ void display(void) glPopMatrix(); } + // Render dummy head + if (showDummyHead) dummyHead.render(); + // Render heads of other agents if (!display_head) render_agents(); if (display_hand) myHand.render(); - if (!display_head) balls.render(); // Render the world box