pass timeval to diffclock function, change base SDK

This commit is contained in:
Stephen Birarda 2013-02-04 19:09:42 -08:00
parent 08d0283586
commit d0081e8ec1
6 changed files with 16 additions and 14 deletions

View file

@ -232,7 +232,7 @@ void *receiveAudioViaUDP(void *args) {
if (LOG_SAMPLE_DELAY) { if (LOG_SAMPLE_DELAY) {
if (!firstSample) { if (!firstSample) {
// write time difference (in microseconds) between packet receipts to file // write time difference (in microseconds) between packet receipts to file
double timeDiff = diffclock(previousReceiveTime, currentReceiveTime); double timeDiff = diffclock(&previousReceiveTime, &currentReceiveTime);
logFile << timeDiff << std::endl; logFile << timeDiff << std::endl;
} }
} }
@ -241,7 +241,7 @@ void *receiveAudioViaUDP(void *args) {
if (firstSample) { if (firstSample) {
stdev.reset(); stdev.reset();
} else { } else {
stdev.addValue(diffclock(previousReceiveTime, currentReceiveTime)); stdev.addValue(diffclock(&previousReceiveTime, &currentReceiveTime));
if (stdev.getSamples() > 500) { if (stdev.getSamples() > 500) {
printf("Avg: %4.2f, Stdev: %4.2f\n", stdev.getAverage(), stdev.getStDev()); printf("Avg: %4.2f, Stdev: %4.2f\n", stdev.getAverage(), stdev.getStDev());
stdev.reset(); stdev.reset();
@ -422,7 +422,7 @@ void Audio::render(int screenWidth, int screenHeight)
float remainingBuffer = 0; float remainingBuffer = 0;
timeval currentTime; timeval currentTime;
gettimeofday(&currentTime, NULL); gettimeofday(&currentTime, NULL);
float timeLeftInCurrentBuffer = diffclock(data->lastCallback, currentTime)/(1000.0*(float)BUFFER_LENGTH_SAMPLES/(float)SAMPLE_RATE) * frameWidth; float timeLeftInCurrentBuffer = diffclock(&data->lastCallback, &currentTime)/(1000.0*(float)BUFFER_LENGTH_SAMPLES/(float)SAMPLE_RATE) * frameWidth;
//float timeLeftInCurrentBuffer = diffclock(currentTime, data->lastCallback)/23.22 * frameWidth; //float timeLeftInCurrentBuffer = diffclock(currentTime, data->lastCallback)/23.22 * frameWidth;
remainingBuffer = data->ringBuffer->diffLastWriteNextOutput() / BUFFER_LENGTH_SAMPLES * frameWidth; remainingBuffer = data->ringBuffer->diffLastWriteNextOutput() / BUFFER_LENGTH_SAMPLES * frameWidth;

View file

@ -138,7 +138,7 @@ int network_receive(int handle, in_addr * from_addr, char * packet_data, int del
} }
// Then check if next to be sent is past due, send if so // Then check if next to be sent is past due, send if so
if ((next_to_receive != next_to_send) && if ((next_to_receive != next_to_send) &&
(diffclock(delay_time_received[next_to_send], check) > delay)) { (diffclock(&delay_time_received[next_to_send], &check) > delay)) {
int returned_bytes = delay_size_received[next_to_send]; int returned_bytes = delay_size_received[next_to_send];
memcpy(packet_data, memcpy(packet_data,
&delay_buffer[next_to_send*MAX_PACKET_SIZE], &delay_buffer[next_to_send*MAX_PACKET_SIZE],

View file

@ -137,10 +137,10 @@ void outstring(char * string, int length) {
std::cout << out << "\n"; std::cout << out << "\n";
} }
double diffclock(timeval clock1,timeval clock2) double diffclock(timeval *clock1,timeval *clock2)
{ {
double diffms = (clock2.tv_sec - clock1.tv_sec) * 1000.0; double diffms = (clock2->tv_sec - clock1->tv_sec) * 1000.0;
diffms += (clock2.tv_usec - clock1.tv_usec) / 1000.0; // us to ms diffms += (clock2->tv_usec - clock1->tv_usec) / 1000.0; // us to ms
return diffms; return diffms;
} }

View file

@ -22,7 +22,7 @@ void drawtext(int x, int y, float scale, float rotate, float thick, int mono, ch
float r=1.0, float g=1.0, float b=1.0); float r=1.0, float g=1.0, float b=1.0);
void drawvec3(int x, int y, float scale, float rotate, float thick, int mono, glm::vec3 vec, void drawvec3(int x, int y, float scale, float rotate, float thick, int mono, glm::vec3 vec,
float r=1.0, float g=1.0, float b=1.0); float r=1.0, float g=1.0, float b=1.0);
double diffclock(timeval clock1,timeval clock2); double diffclock(timeval *clock1,timeval *clock2);
class StDev { class StDev {
public: public:

View file

@ -217,9 +217,9 @@ float pointer_attenuation_quadratic[] = { 1.0f, 0.0f, 0.0f }; // for 2D view
void Timer(int extra) void Timer(int extra)
{ {
gettimeofday(&timer_end, NULL); gettimeofday(&timer_end, NULL);
FPS = (float)framecount / ((float)diffclock(timer_start,timer_end) / 1000.f); FPS = (float)framecount / ((float)diffclock(&timer_start, &timer_end) / 1000.f);
packets_per_second = (float)packetcount / ((float)diffclock(timer_start,timer_end) / 1000.f); packets_per_second = (float)packetcount / ((float)diffclock(&timer_start, &timer_end) / 1000.f);
bytes_per_second = (float)bytescount / ((float)diffclock(timer_start,timer_end) / 1000.f); bytes_per_second = (float)bytescount / ((float)diffclock(&timer_start, &timer_end) / 1000.f);
framecount = 0; framecount = 0;
packetcount = 0; packetcount = 0;
bytescount = 0; bytescount = 0;
@ -312,7 +312,7 @@ void init(void)
{ {
serialPort.readData(); serialPort.readData();
gettimeofday(&timer_end, NULL); gettimeofday(&timer_end, NULL);
if (diffclock(timer_start,timer_end) > 1000) done = 1; if (diffclock(&timer_start, &timer_end) > 1000) done = 1;
} }
gravity.x = serialPort.getValue(ACCEL_X); gravity.x = serialPort.getValue(ACCEL_X);
gravity.y = serialPort.getValue(ACCEL_Y); gravity.y = serialPort.getValue(ACCEL_Y);
@ -759,7 +759,7 @@ void read_network()
// //
timeval check; timeval check;
gettimeofday(&check, NULL); gettimeofday(&check, NULL);
ping_msecs = (float)diffclock(ping_start, check); ping_msecs = (float)diffclock(&ping_start, &check);
} else if (incoming_packet[0] == 'S') { } else if (incoming_packet[0] == 'S') {
// //
// Message from Spaceserver // Message from Spaceserver
@ -780,7 +780,7 @@ void idle(void)
gettimeofday(&check, NULL); gettimeofday(&check, NULL);
// Check and render display frame // Check and render display frame
if (diffclock(last_frame,check) > RENDER_FRAME_MSECS) if (diffclock(&last_frame, &check) > RENDER_FRAME_MSECS)
{ {
steps_per_frame++; steps_per_frame++;
// Simulation // Simulation

View file

@ -957,6 +957,7 @@
GCC_OPTIMIZATION_LEVEL = 0; GCC_OPTIMIZATION_LEVEL = 0;
GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES; GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.7;
ONLY_ACTIVE_ARCH = YES; ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx10.7; SDKROOT = macosx10.7;
}; };
@ -969,6 +970,7 @@
GCC_C_LANGUAGE_STANDARD = gnu99; GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES; GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.7;
SDKROOT = macosx10.7; SDKROOT = macosx10.7;
}; };
name = Release; name = Release;