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 57b7c1db04
commit 77f32b8211
7 changed files with 54 additions and 21 deletions

View file

@ -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, &currentReceiveTime));
double tDiff = diffclock(&previousReceiveTime, &currentReceiveTime);
//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);

View file

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

View file

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

View file

@ -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();
}

View file

@ -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);

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
// 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) {

View file

@ -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