From 30b782dbca38fd9a0edb222c13b10ba5d372805e Mon Sep 17 00:00:00 2001 From: "(no author)" <(no author)@d8a302eb-03bc-478d-80e4-98257eca68ef> Date: Mon, 4 Aug 2014 19:42:52 +0000 Subject: [PATCH] correction git-svn-id: svn://elaine/murooma/trunk@140 d8a302eb-03bc-478d-80e4-98257eca68ef --- stream.cpp | 110 ++++++++++++++--------------------------------------- 1 file changed, 28 insertions(+), 82 deletions(-) diff --git a/stream.cpp b/stream.cpp index 8aa45785..fd9a641a 100644 --- a/stream.cpp +++ b/stream.cpp @@ -56,86 +56,37 @@ time_point_ms Stream::getNextPlayerChunk(short* outputBuffer, int correction) { Chunk* chunk = getNextChunk(); time_point_ms tp = chunk->timePoint(); -/* + int read = 0; + int toRead = PLAYER_CHUNK_SIZE + correction*PLAYER_CHUNK_MS_SIZE; + short* buffer; + + if (correction != 0) + buffer = (short*)malloc(toRead * sizeof(short)); + else + buffer = outputBuffer; + + while (read < toRead) + { + read += chunk->read(buffer + read, toRead - read); + if (chunk->isEndOfChunk()) + { + chunks.pop_front(); + delete chunk; + chunk = getNextChunk(); + } + } + if (correction != 0) { - float idx(chunk->idx); - float factor = 2*(1.f - (float)(correction) / (float)(PLAYER_CHUNK_MS)); - for (size_t n=0; npayload[index]; - *(outputBuffer + n+1) = chunk->payload[index + 1]; - idx += factor; - if (idx >= WIRE_CHUNK_SIZE) - { - chunks.pop_front(); - delete chunk; - chunk = getNextChunk(); - idx -= WIRE_CHUNK_SIZE; - } - } - chunk->idx = idx; -// if (correction != 0) -// std::cerr << "Diff: " << diff_ms(getTimeval(chunk), tv) << "\t" << chunk->idx / PLAYER_CHUNK_MS_SIZE << "\n"; - } - else -*/ { -/* int idx(chunk->idx); - for (size_t n=0; npayload[idx]; - *(outputBuffer + n+1) = chunk->payload[idx + 1]; - idx += 2; - if (++currentSample > everyN) - { - idx += 2; - currentSample = 0; - } - if (idx >= WIRE_CHUNK_SIZE) - { - chunks.pop_front(); - delete chunk; - chunk = getNextChunk(); - idx -= WIRE_CHUNK_SIZE; - } - } - chunk->idx = idx; -*/ - int read = 0; - 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(buffer + read, toRead - read); - if (chunk->isEndOfChunk()) - { - chunks.pop_front(); - delete chunk; - 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(); pShortBuffer->clear(); if (sleep < 0) { -// std::cerr << "Sleep: " << sleep << "\n"; + std::cerr << "Sleep: " << sleep << "\n"; sleep += PLAYER_CHUNK_MS; if (sleep > -PLAYER_CHUNK_MS/2) sleep = 0; @@ -199,7 +146,6 @@ void Stream::getChunk(short* outputBuffer, double outputBufferDacTime, unsigned } } -//correction = 2; int age = Chunk::getAge(getNextPlayerChunk(outputBuffer, correction)) - bufferMs;// + outputBufferDacTime*1000; if (outputBufferDacTime < 1) age += outputBufferDacTime*1000;