diff --git a/server.cpp b/server.cpp index ffa03ef6..3eda4309 100644 --- a/server.cpp +++ b/server.cpp @@ -30,9 +30,8 @@ int main () { char c[2]; Chunk* chunk = new Chunk(); - timeval start; - timeval now; - gettimeofday(&start, NULL); + timeval tvChunk; + gettimeofday(&tvChunk, NULL); long nextTick = getTickCount(); while (cin.good()) { @@ -43,23 +42,25 @@ int main () { chunk->payload[n] = (int)c[0] + ((int)c[1] * 256); } - chunk->tv_sec = start.tv_sec; - chunk->tv_usec = start.tv_usec; + chunk->tv_sec = tvChunk.tv_sec; + chunk->tv_usec = tvChunk.tv_usec; chunk->idx = 0; zmq::message_t message(sizeof(Chunk)); memcpy(message.data(), chunk, sizeof(Chunk)); publisher.send(message); - addMs(start, WIRE_CHUNK_MS); + addMs(tvChunk, WIRE_CHUNK_MS); + nextTick += WIRE_CHUNK_MS; long currentTick = getTickCount(); if (nextTick - currentTick > 0) { usleep((nextTick - currentTick) * 1000); } else - gettimeofday(&start, NULL); - - nextTick += WIRE_CHUNK_MS; + { + gettimeofday(&tvChunk, NULL); + nextTick = getTickCount(); + } } delete chunk; return 0; diff --git a/stream.cpp b/stream.cpp index dc45d697..17f5cdec 100644 --- a/stream.cpp +++ b/stream.cpp @@ -153,6 +153,7 @@ void Stream::getChunk(short* outputBuffer, double outputBufferDacTime, unsigned { // std::cerr << "Sleep: " << sleep << "\n"; getNextPlayerChunk(outputBuffer); + usleep(10); } sleep = 0; } @@ -203,7 +204,11 @@ void Stream::getChunk(short* outputBuffer, double outputBufferDacTime, unsigned // sleep = median; //sleep = 0; if (sleep != 0) + { std::cerr << "Sleep: " << sleep << "\n"; + for (size_t i=0; isize() << "\t" << outputBufferDacTime*1000 << "\n"; }