mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 06:44:06 +02:00
Added yellow line for average msecs latency
This commit is contained in:
parent
8b4fa7c009
commit
4864931d84
6 changed files with 83 additions and 10 deletions
|
@ -28,7 +28,7 @@ const float AMPLITUDE_RATIO_AT_90 = 0.5;
|
|||
const short RING_BUFFER_FRAMES = 10;
|
||||
const short RING_BUFFER_SIZE_SAMPLES = RING_BUFFER_FRAMES * BUFFER_LENGTH_SAMPLES;
|
||||
|
||||
const short JITTER_BUFFER_LENGTH_MSECS = 50;
|
||||
const short JITTER_BUFFER_LENGTH_MSECS = 40;
|
||||
const int SAMPLE_RATE = 22050;
|
||||
|
||||
const short NUM_AUDIO_SOURCES = 2;
|
||||
|
@ -43,7 +43,7 @@ int starve_counter = 0;
|
|||
|
||||
StDev stdev;
|
||||
|
||||
#define LOG_SAMPLE_DELAY 1
|
||||
#define LOG_SAMPLE_DELAY 0
|
||||
|
||||
bool Audio::initialized;
|
||||
PaError Audio::err;
|
||||
|
@ -127,6 +127,7 @@ int audioCallback (const void *inputBuffer,
|
|||
if (ringBuffer->diffLastWriteNextOutput() < BUFFER_LENGTH_SAMPLES) {
|
||||
starve_counter++;
|
||||
printf("Starved #%d\n", starve_counter);
|
||||
data->wasStarved = 10; // Frames to render the indication that the system was starved.
|
||||
ringBuffer->endOfLastWrite = NULL;
|
||||
}
|
||||
}
|
||||
|
@ -263,6 +264,7 @@ void *receiveAudioViaUDP(void *args) {
|
|||
// we'll need a jitter buffer
|
||||
// reset the ring buffer and write
|
||||
copyToPointer = ringBuffer->buffer;
|
||||
std::cout << "Writing jitter buffer\n";
|
||||
} else {
|
||||
copyToPointer = ringBuffer->endOfLastWrite;
|
||||
|
||||
|
@ -422,19 +424,41 @@ void Audio::render(int screenWidth, int screenHeight)
|
|||
float remainingBuffer = 0;
|
||||
timeval currentTime;
|
||||
gettimeofday(¤tTime, NULL);
|
||||
float timeLeftInCurrentBuffer = diffclock(currentTime, data->lastCallback)/(1000.0*(float)BUFFER_LENGTH_SAMPLES/(float)SAMPLE_RATE) * frameWidth;
|
||||
//float timeLeftInCurrentBuffer = diffclock(currentTime, data->lastCallback)/23.22 * frameWidth;
|
||||
float timeLeftInCurrentBuffer = 0;
|
||||
if (data->lastCallback.tv_usec > 0) timeLeftInCurrentBuffer = diffclock(data->lastCallback, currentTime)/(1000.0*(float)BUFFER_LENGTH_SAMPLES/(float)SAMPLE_RATE) * frameWidth;
|
||||
|
||||
remainingBuffer = data->ringBuffer->diffLastWriteNextOutput() / BUFFER_LENGTH_SAMPLES * frameWidth;
|
||||
if (data->ringBuffer->endOfLastWrite != NULL)
|
||||
remainingBuffer = data->ringBuffer->diffLastWriteNextOutput() / BUFFER_LENGTH_SAMPLES * frameWidth;
|
||||
|
||||
if (data->wasStarved == 0) glColor3f(0, 1, 0);
|
||||
else {
|
||||
glColor3f(0.5 + (float)data->wasStarved/20.0, 0, 0);
|
||||
data->wasStarved--;
|
||||
}
|
||||
|
||||
glColor3f(1, 0, 0);
|
||||
glBegin(GL_QUADS);
|
||||
glVertex2f(startX, topY);
|
||||
glVertex2f(startX + remainingBuffer + timeLeftInCurrentBuffer, topY);
|
||||
glVertex2f(startX + remainingBuffer + timeLeftInCurrentBuffer, bottomY);
|
||||
glVertex2f(startX, bottomY);
|
||||
glVertex2f(startX, topY + 5);
|
||||
glVertex2f(startX + remainingBuffer + timeLeftInCurrentBuffer, topY + 5);
|
||||
glVertex2f(startX + remainingBuffer + timeLeftInCurrentBuffer, bottomY - 5);
|
||||
glVertex2f(startX, bottomY - 5);
|
||||
glEnd();
|
||||
|
||||
if (data->averagedLatency == 0.0) data->averagedLatency = remainingBuffer + timeLeftInCurrentBuffer;
|
||||
else data->averagedLatency = 0.99*data->averagedLatency + 0.01*((float)remainingBuffer + (float)timeLeftInCurrentBuffer);
|
||||
|
||||
glColor3f(1,1,0);
|
||||
glBegin(GL_QUADS);
|
||||
glLineWidth(4.0);
|
||||
glVertex2f(startX + data->averagedLatency - 2, topY - 2);
|
||||
glVertex2f(startX + data->averagedLatency + 2, topY - 2);
|
||||
glVertex2f(startX + data->averagedLatency + 2, bottomY + 2);
|
||||
glVertex2f(startX + data->averagedLatency - 2, bottomY + 2);
|
||||
glEnd();
|
||||
|
||||
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);
|
||||
|
||||
//glVertex2f(nextOutputX, topY);
|
||||
//glVertex2f(nextOutputX, bottomY);
|
||||
|
||||
|
|
|
@ -25,6 +25,8 @@ AudioData::AudioData(int numberOfSources, int bufferLength) {
|
|||
|
||||
samplesToQueue = new int16_t[bufferLength / sizeof(int16_t)];
|
||||
averagedLatency = 0.0;
|
||||
lastCallback.tv_usec = 0;
|
||||
wasStarved = 0;
|
||||
}
|
||||
|
||||
AudioData::~AudioData() {
|
||||
|
|
|
@ -28,6 +28,7 @@ class AudioData {
|
|||
|
||||
timeval lastCallback;
|
||||
float averagedLatency;
|
||||
int wasStarved;
|
||||
|
||||
AudioData(int bufferLength);
|
||||
AudioData(int numberOfSources, int bufferLength);
|
||||
|
|
26
Source/octal.cpp
Normal file
26
Source/octal.cpp
Normal file
|
@ -0,0 +1,26 @@
|
|||
//
|
||||
// octal.cpp
|
||||
// interface
|
||||
//
|
||||
// Created by Philip on 2/4/13.
|
||||
// Copyright (c) 2013 HighFidelity, Inc. All rights reserved.
|
||||
//
|
||||
// Various subroutines for converting between X,Y,Z coords and octree coordinates.
|
||||
//
|
||||
|
||||
const int X = 0;
|
||||
const int Y = 1;
|
||||
const int Z = 2;
|
||||
|
||||
#include "util.h"
|
||||
#include "octal.h"
|
||||
|
||||
// Given a position vector between zero and one (but less than one), and a voxel scale 1/2^scale,
|
||||
// returns the smallest voxel at that scale which encloses the given point.
|
||||
void getVoxel(float * pos, int scale, float * vpos) {
|
||||
float vscale = powf(2, scale);
|
||||
vpos[X] = floor(pos[X]*vscale)/vscale;
|
||||
vpos[Y] = floor(pos[Y]*vscale)/vscale;
|
||||
vpos[Z] = floor(pos[Z]*vscale)/vscale;
|
||||
}
|
||||
|
14
Source/octal.h
Normal file
14
Source/octal.h
Normal file
|
@ -0,0 +1,14 @@
|
|||
//
|
||||
// octal.h
|
||||
// interface
|
||||
//
|
||||
// Created by Philip on 2/4/13.
|
||||
// Copyright (c) 2013 HighFidelity, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef __interface__octal__
|
||||
#define __interface__octal__
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#endif /* defined(__interface__octal__) */
|
|
@ -46,6 +46,7 @@
|
|||
B6BDADE415F44AC7002A07DF /* AudioUnit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B6BDADDC15F444D3002A07DF /* AudioUnit.framework */; };
|
||||
D40BDFD513404BA300B0BE1F /* GLUT.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D40BDFD413404BA300B0BE1F /* GLUT.framework */; };
|
||||
D40BDFD713404BB300B0BE1F /* OpenGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D40BDFD613404BB300B0BE1F /* OpenGL.framework */; };
|
||||
D4200F7816C0DBA3000F8D6D /* octal.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D4200F7616C0DBA3000F8D6D /* octal.cpp */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXCopyFilesBuildPhase section */
|
||||
|
@ -357,6 +358,8 @@
|
|||
B6BDADDE15F444DB002A07DF /* CoreServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreServices.framework; path = System/Library/Frameworks/CoreServices.framework; sourceTree = SDKROOT; };
|
||||
D40BDFD413404BA300B0BE1F /* GLUT.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GLUT.framework; path = /System/Library/Frameworks/GLUT.framework; sourceTree = "<absolute>"; };
|
||||
D40BDFD613404BB300B0BE1F /* OpenGL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGL.framework; path = /System/Library/Frameworks/OpenGL.framework; sourceTree = "<absolute>"; };
|
||||
D4200F7616C0DBA3000F8D6D /* octal.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = octal.cpp; sourceTree = "<group>"; };
|
||||
D4200F7716C0DBA3000F8D6D /* octal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = octal.h; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
|
@ -441,6 +444,8 @@
|
|||
53CF370516B9C039001FCB05 /* main.cpp */,
|
||||
53CF370A16B9C039001FCB05 /* Network.cpp */,
|
||||
53CF370B16B9C039001FCB05 /* Network.h */,
|
||||
D4200F7616C0DBA3000F8D6D /* octal.cpp */,
|
||||
D4200F7716C0DBA3000F8D6D /* octal.h */,
|
||||
53ACC39616B9C59500ABD227 /* Oscilloscope.cpp */,
|
||||
53ACC39716B9C59500ABD227 /* Oscilloscope.h */,
|
||||
53CF370C16B9C039001FCB05 /* Particle.cpp */,
|
||||
|
@ -874,6 +879,7 @@
|
|||
53CF372A16B9C039001FCB05 /* Util.cpp in Sources */,
|
||||
53ACC39816B9C59500ABD227 /* Oscilloscope.cpp in Sources */,
|
||||
53A4EAB216BC770A00F07F4C /* AudioRingBuffer.cpp in Sources */,
|
||||
D4200F7816C0DBA3000F8D6D /* octal.cpp in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue