Added measured jitter indicator (stdev() of packet receipt times) to audio renderer. Also added head being rendered in world at 0,0 as dummy.

This commit is contained in:
Philip Rosedale 2013-02-05 19:43:15 -08:00
parent 269d2bb83e
commit 2589183f86
7 changed files with 54 additions and 21 deletions

View file

@ -43,7 +43,7 @@ int starve_counter = 0;
StDev stdev; StDev stdev;
#define LOG_SAMPLE_DELAY 0 #define LOG_SAMPLE_DELAY 1
bool Audio::initialized; bool Audio::initialized;
PaError Audio::err; PaError Audio::err;
@ -242,9 +242,12 @@ void *receiveAudioViaUDP(void *args) {
if (firstSample) { if (firstSample) {
stdev.reset(); stdev.reset();
} else { } else {
stdev.addValue(diffclock(&previousReceiveTime, &currentReceiveTime)); double tDiff = diffclock(&previousReceiveTime, &currentReceiveTime);
//printf(\n";
stdev.addValue(tDiff);
if (stdev.getSamples() > 500) { 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(); stdev.reset();
} }
} }
@ -458,21 +461,25 @@ void Audio::render(int screenWidth, int screenHeight)
char out[20]; char out[20];
sprintf(out, "%3.0f\n", data->averagedLatency/(float)frameWidth*(1000.0*(float)BUFFER_LENGTH_SAMPLES/(float)SAMPLE_RATE)); 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 // 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); glColor3f(0,1,1);
glBegin(GL_QUADS); glBegin(GL_QUADS);
glVertex2f(startX + jitter - 2, topY - 2); glVertex2f(startX + jitterPels - 2, topY - 2);
glVertex2f(startX + jitter + 2, topY - 2); glVertex2f(startX + jitterPels + 2, topY - 2);
glVertex2f(startX + jitter + 2, bottomY + 2); glVertex2f(startX + jitterPels + 2, bottomY + 2);
glVertex2f(startX + jitter - 2, bottomY + 2); glVertex2f(startX + jitterPels - 2, bottomY + 2);
glEnd(); 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, topY);
//glVertex2f(nextOutputX, bottomY); //glVertex2f(nextOutputX, bottomY);

View file

@ -27,6 +27,7 @@ AudioData::AudioData(int numberOfSources, int bufferLength) {
averagedLatency = 0.0; averagedLatency = 0.0;
lastCallback.tv_usec = 0; lastCallback.tv_usec = 0;
wasStarved = 0; wasStarved = 0;
jitter = 0;
} }
AudioData::~AudioData() { AudioData::~AudioData() {

View file

@ -28,6 +28,7 @@ class AudioData {
timeval lastCallback; timeval lastCallback;
float averagedLatency; float averagedLatency;
float jitter;
int wasStarved; int wasStarved;
AudioData(int bufferLength); AudioData(int bufferLength);

View file

@ -52,6 +52,7 @@ Head::Head()
leanSideways = 0.0; leanSideways = 0.0;
eyeContact = 1; eyeContact = 1;
eyeContactTarget = LEFT_EYE; eyeContactTarget = LEFT_EYE;
scale = 1.0;
setNoise(1); setNoise(1);
} }
@ -206,6 +207,9 @@ void Head::render()
int side = 0; int side = 0;
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
glPushMatrix();
glScalef(scale, scale, scale);
glTranslatef(leanSideways, 0.f, leanForward); glTranslatef(leanSideways, 0.f, leanForward);
glRotatef(Yaw/2.0, 0, 1, 0); glRotatef(Yaw/2.0, 0, 1, 0);
@ -306,6 +310,8 @@ void Head::render()
//glRotatef(90,0,1,0); //glRotatef(90,0,1,0);
glutSolidSphere(PupilSize, 15, 15); glutSolidSphere(PupilSize, 15, 15);
glPopMatrix(); glPopMatrix();
glPopMatrix();
} }

View file

@ -45,6 +45,7 @@ class Head {
float YawTarget; float YawTarget;
float NoiseEnvelope; float NoiseEnvelope;
float PupilConverge; float PupilConverge;
float scale;
glm::vec3 position; glm::vec3 position;
int eyeContact; int eyeContact;
eyeContactTargets eyeContactTarget; eyeContactTargets eyeContactTarget;
@ -59,6 +60,7 @@ public:
void setPitch(float p) {Pitch = p; } void setPitch(float p) {Pitch = p; }
void setYaw(float y) {Yaw = y; } void setYaw(float y) {Yaw = y; }
void setRoll(float r) {Roll = r; }; void setRoll(float r) {Roll = r; };
void setScale(float s) {scale = s; };
void setRenderYaw(float y) {renderYaw = y;} void setRenderYaw(float y) {renderYaw = y;}
void setLeanForward(float dist); void setLeanForward(float dist);
void setLeanSideways(float dist); void setLeanSideways(float dist);

View file

@ -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 // 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 // Excite the hovered cell a bit toward firing
//printf("X = %3.1f Y = %3.1f\n", x, y); //printf("X = %3.1f Y = %3.1f\n", x, y);
if ((width + height) > 0) {
int index = int(x*(float)width) + int(y*(float)height)*width; int index = int(x*(float)width) + int(y*(float)height)*width;
if (tiles[index].type > 0) tiles[index].excited += 0.05; if (tiles[index].type > 0) tiles[index].excited += 0.05;
//printf("excited = %3.1f, inhibited = %3.1f\n", tiles[index].excited, tiles[index].inhibited); //printf("excited = %3.1f, inhibited = %3.1f\n", tiles[index].excited, tiles[index].inhibited);
}
} }
void Lattice::simulate(float deltaTime) { void Lattice::simulate(float deltaTime) {

View file

@ -9,9 +9,9 @@
// Keyboard Commands: // Keyboard Commands:
// //
// / = toggle stats display // / = toggle stats display
// n = toggle noise in firing on/off // spacebar = reset gyros/head
// c = clear all cells and synapses to zero // h = render Head
// s = clear cells to zero but preserve synapse weights // l = show incoming gyro levels
// //
//#define MARKER_CAPTURE // yep. //#define MARKER_CAPTURE // yep.
@ -87,6 +87,9 @@ int fullscreen = 0;
#define HAND_RADIUS 0.25 // Radius of in-world 'hand' of you #define HAND_RADIUS 0.25 // Radius of in-world 'hand' of you
Head myHead; // The rendered head of oneself or others Head myHead; // The rendered head of oneself or others
Head dummyHead; // Test Head to render
int showDummyHead = 1;
Hand myHand(HAND_RADIUS, Hand myHand(HAND_RADIUS,
glm::vec3(0,1,1)); // My hand (used to manipulate things in world) glm::vec3(0,1,1)); // My hand (used to manipulate things in world)
@ -278,6 +281,13 @@ void init(void)
{ {
myHead.setRenderYaw(start_yaw); 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 (audio_on) {
if (serial_on) { if (serial_on) {
Audio::init(&myHead); Audio::init(&myHead);
@ -300,6 +310,7 @@ void init(void)
{ {
myHand.setNoise(noise); myHand.setNoise(noise);
myHead.setNoise(noise); myHead.setNoise(noise);
dummyHead.setNoise(noise);
} }
if (serial_on) 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()); 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! // Update all this stuff to any agents that are nearby and need to see it!
/*
const int MAX_BROADCAST_STRING = 200; const int MAX_BROADCAST_STRING = 200;
char broadcast_string[MAX_BROADCAST_STRING]; char broadcast_string[MAX_BROADCAST_STRING];
int broadcast_bytes = myHead.getBroadcastData(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); broadcast_to_agents(UDP_socket, broadcast_string, broadcast_bytes);
*/
} }
int render_test_spot = WIDTH/2; int render_test_spot = WIDTH/2;
@ -554,12 +566,14 @@ void display(void)
glPopMatrix(); glPopMatrix();
} }
// Render dummy head
if (showDummyHead) dummyHead.render();
// Render heads of other agents // Render heads of other agents
if (!display_head) render_agents(); if (!display_head) render_agents();
if (display_hand) myHand.render(); if (display_hand) myHand.render();
if (!display_head) balls.render(); if (!display_head) balls.render();
// Render the world box // Render the world box