git-svn-id: svn://elaine/murooma/trunk@160 d8a302eb-03bc-478d-80e4-98257eca68ef
This commit is contained in:
(no author) 2014-08-08 20:03:43 +00:00
parent 47137cc436
commit a0dc7f336f
2 changed files with 27 additions and 11 deletions

View file

@ -47,7 +47,12 @@ time_point_ms Stream::getNextPlayerChunk(short* outputBuffer, unsigned long fram
short* buffer;
if (correction != 0)
{
int msBuffer = floor(framesPerBuffer*2 / PLAYER_CHUNK_MS_SIZE);
if (abs(correction) > msBuffer / 2)
correction = copysign(msBuffer / 2, correction);
buffer = (short*)malloc(toRead * sizeof(short));
}
else
buffer = outputBuffer;
@ -93,7 +98,8 @@ void Stream::resetBuffers()
void Stream::getPlayerChunk(short* outputBuffer, double outputBufferDacTime, unsigned long framesPerBuffer)
{
//cout << "framesPerBuffer: " << framesPerBuffer << "\t";
//cout << "framesPerBuffer: " << framesPerBuffer << "\tms: " << framesPerBuffer*2 / PLAYER_CHUNK_MS_SIZE << "\t" << PLAYER_CHUNK_SIZE << "\n";
int msBuffer = floor(framesPerBuffer*2 / PLAYER_CHUNK_MS_SIZE);
if (sleep != 0)
{
resetBuffers();
@ -112,7 +118,7 @@ void Stream::getPlayerChunk(short* outputBuffer, double outputBufferDacTime, uns
while (true)// (int i=0; i<(int)(round((float)sleep / (float)PLAYER_CHUNK_MS)) + 1; ++i)
{
int age = Chunk::getAge(getNextPlayerChunk(outputBuffer, framesPerBuffer)) - bufferMs;
if (age < PLAYER_CHUNK_MS / 2)
if (age < msBuffer / 2)
break;
}
sleep = 0;
@ -121,13 +127,13 @@ void Stream::getPlayerChunk(short* outputBuffer, double outputBufferDacTime, uns
}
int correction(0);
if ((pBuffer->full() && (abs(median) <= PLAYER_CHUNK_MS) && (abs(median) > 1)) ||
(pShortBuffer->full() && (abs(shortMedian) <= PLAYER_CHUNK_MS) && (abs(shortMedian) > 10)))
if ((pBuffer->full() && (abs(median) <= msBuffer) && (abs(median) > 1)) ||
(pShortBuffer->full() && (abs(shortMedian) <= msBuffer) && (abs(shortMedian) > max(7, msBuffer))))
{
correction = shortMedian;
resetBuffers();
}
correction = 0;
//correction = 0;
//if (time(NULL) != lastUpdate)
// correction = 2;
@ -137,14 +143,14 @@ correction = 0;
age += outputBufferDacTime*1000;
// cout << age << "\t" << outputBufferDacTime*1000 << "\n";
if (pShortBuffer->full() && (abs(shortMedian) > PLAYER_CHUNK_MS))
if (pShortBuffer->full() && (abs(shortMedian) > max(15, msBuffer)))
{
sleep = shortMedian;
std::cerr << "Sleep: " << sleep << "\n";
}
else if (pMiniBuffer->full() && (abs(age) > 50) && (abs(pMiniBuffer->median()) > 50))
else if (pMiniBuffer->full() && (abs(age) > 50) && (abs(pMiniBuffer->mean()) > 50))
{
sleep = pMiniBuffer->median();
sleep = pMiniBuffer->mean();
std::cerr << "Sleep: " << sleep << "\n";
}
@ -155,9 +161,9 @@ correction = 0;
if (now != lastUpdate)
{
lastUpdate = now;
median = pBuffer->median();
shortMedian = pShortBuffer->median();
std::cerr << "Chunk: " << age << "\t" << pMiniBuffer->median() << "\t" << shortMedian << "\t" << median << "\t" << pBuffer->size() << "\t" << outputBufferDacTime*1000 << "\n";
median = pBuffer->mean();
shortMedian = pShortBuffer->mean();
std::cerr << "Chunk: " << age << "\t" << pMiniBuffer->mean() << "\t" << shortMedian << "\t" << median << "\t" << pBuffer->size() << "\t" << outputBufferDacTime*1000 << "\n";
}
}