From 6c1511ed41b4ed54a39a17c3fa697f6d9fba1bdf Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 4 Feb 2013 17:34:40 -0800 Subject: [PATCH] add a really dumb graph for ring buffer stats --- Source/Audio.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++++-- Source/Audio.h | 1 + Source/main.cpp | 1 + 3 files changed, 54 insertions(+), 2 deletions(-) diff --git a/Source/Audio.cpp b/Source/Audio.cpp index d88e887194..501a5ccc47 100644 --- a/Source/Audio.cpp +++ b/Source/Audio.cpp @@ -84,7 +84,7 @@ int audioCallback (const void *inputBuffer, // int16_t *inputRight = ((int16_t **) inputBuffer)[1]; if (inputLeft != NULL) { - data->audioSocket->send((char *) WORKCLUB_AUDIO_SERVER, 55443, (void *)inputLeft, BUFFER_LENGTH_BYTES); + data->audioSocket->send((char *) EC2_WEST_AUDIO_SERVER, 55443, (void *)inputLeft, BUFFER_LENGTH_BYTES); } int16_t *outputLeft = ((int16_t **) outputBuffer)[0]; @@ -376,7 +376,6 @@ error: void Audio::render() { if (initialized && !ECHO_SERVER_TEST) { - for (int s = 0; s < NUM_AUDIO_SOURCES; s++) { // render gl objects on screen for our sources glPushMatrix(); @@ -390,6 +389,57 @@ void Audio::render() } } +void Audio::render(int screenWidth, int screenHeight) +{ + if (initialized && ECHO_SERVER_TEST) { + glBegin(GL_LINES); + glColor3f(1,1,1); + + int startX = 50.0; + int currentX = startX; + int topY = screenHeight - 90; + int bottomY = screenHeight - 50; + float frameWidth = 50.0; + float halfY = topY + ((bottomY - topY) / 2.0); + + // draw the lines for the base of the ring buffer + + glVertex2f(currentX, topY); + glVertex2f(currentX, bottomY); + + for (int i = 0; i < RING_BUFFER_FRAMES; i++) { + glVertex2f(currentX, halfY); + glVertex2f(currentX + frameWidth, halfY); + currentX += frameWidth; + + glVertex2f(currentX, topY); + glVertex2f(currentX, bottomY); + } + + // show the next audio buffer and end of last write position + int scaleLength = currentX - startX; + + float nextOutputSampleOffset = data->ringBuffer->nextOutput - data->ringBuffer->buffer; + float nextOutputX = startX + (nextOutputSampleOffset / RING_BUFFER_SIZE_SAMPLES) * scaleLength; + glColor3f(1, 0, 0); + glVertex2f(nextOutputX, topY); + glVertex2f(nextOutputX, bottomY); + + float endLastWriteSampleOffset = data->ringBuffer->endOfLastWrite - data->ringBuffer->buffer; + + if (data->ringBuffer->endOfLastWrite == NULL) { + endLastWriteSampleOffset = 0; + } + + float endLastWriteX = startX + (endLastWriteSampleOffset / RING_BUFFER_SIZE_SAMPLES) * scaleLength; + glColor3f(0, 1, 0); + glVertex2f(endLastWriteX, topY); + glVertex2f(endLastWriteX, bottomY); + + glEnd(); + } +} + /** * Close the running audio stream, and deinitialize portaudio. * Should be called at the end of program execution. diff --git a/Source/Audio.h b/Source/Audio.h index 9889a0d783..f1c8ac1d8a 100644 --- a/Source/Audio.h +++ b/Source/Audio.h @@ -21,6 +21,7 @@ public: static bool init(Head* mainHead); static void render(); + static void render(int screenWidth, int screenHeight); // terminates audio I/O static bool terminate(); diff --git a/Source/main.cpp b/Source/main.cpp index 1dc89ffeee..60203ffd13 100644 --- a/Source/main.cpp +++ b/Source/main.cpp @@ -584,6 +584,7 @@ void display(void) glDisable(GL_LIGHTING); //lattice.render(WIDTH, HEIGHT); + Audio::render(WIDTH, HEIGHT); //drawvec3(100, 100, 0.15, 0, 1.0, 0, myHead.getPos(), 0, 1, 0); glPointParameterfvARB( GL_POINT_DISTANCE_ATTENUATION_ARB, pointer_attenuation_quadratic );