diff --git a/stream.cpp b/stream.cpp index 0a4b6d14..8aa45785 100644 --- a/stream.cpp +++ b/stream.cpp @@ -103,9 +103,17 @@ time_point_ms Stream::getNextPlayerChunk(short* outputBuffer, int correction) chunk->idx = idx; */ int read = 0; - while (read < PLAYER_CHUNK_SIZE) + int toRead = PLAYER_CHUNK_SIZE + correction*PLAYER_CHUNK_MS_SIZE; +//std::cout << "toRead: " << toRead << ", correction: " << correction << "\n"; + short* buffer; + if (correction == 0) + buffer = outputBuffer; + else + buffer = (short*)malloc(toRead * sizeof(short)); + + while (read < toRead) { - read += chunk->read(outputBuffer + read, PLAYER_CHUNK_SIZE - read); + read += chunk->read(buffer + read, toRead - read); if (chunk->isEndOfChunk()) { chunks.pop_front(); @@ -113,6 +121,21 @@ time_point_ms Stream::getNextPlayerChunk(short* outputBuffer, int correction) chunk = getNextChunk(); } } + + if (correction != 0) + { + float factor = (float)toRead / (float)PLAYER_CHUNK_SIZE; +std::cout << "correction: " << correction << ", factor: " << factor << "\n"; + for (size_t n=0; nclear(); @@ -157,7 +184,7 @@ void Stream::getChunk(short* outputBuffer, double outputBufferDacTime, unsigned { if (abs(median) > 1) { - correction = -shortMedian; + correction = shortMedian; pBuffer->clear(); pShortBuffer->clear(); } @@ -166,18 +193,19 @@ void Stream::getChunk(short* outputBuffer, double outputBufferDacTime, unsigned { if (abs(shortMedian) > 3) { - correction = -shortMedian; + correction = shortMedian; pBuffer->clear(); pShortBuffer->clear(); } - } + } +//correction = 2; int age = Chunk::getAge(getNextPlayerChunk(outputBuffer, correction)) - bufferMs;// + outputBufferDacTime*1000; if (outputBufferDacTime < 1) age += outputBufferDacTime*1000; +// std::cerr << "Chunk: " << age << "\t" << outputBufferDacTime*1000 << "\n"; pBuffer->add(age); pShortBuffer->add(age); -// std::cerr << "Chunk: " << age << "\t" << outputBufferDacTime*1000 << "\n"; time_t now = time(NULL); if (now != lastUpdate)