buffering

git-svn-id: svn://elaine/murooma/trunk@49 d8a302eb-03bc-478d-80e4-98257eca68ef
This commit is contained in:
(no author) 2014-06-30 16:26:41 +00:00
parent 36337a1c66
commit 17f7c993ff
2 changed files with 18 additions and 5 deletions

View file

@ -8,7 +8,7 @@
#define WIRE_CHUNK_MS (40) #define WIRE_CHUNK_MS (40)
#define WIRE_CHUNK_SIZE (SAMPLE_RATE*CHANNELS*SAMPLE_BIT/8*WIRE_CHUNK_MS/1000) #define WIRE_CHUNK_SIZE (SAMPLE_RATE*CHANNELS*SAMPLE_BIT/8*WIRE_CHUNK_MS/1000)
#define PLAYER_CHUNK_MS (20) #define PLAYER_CHUNK_MS (10)
#define PLAYER_CHUNK_SIZE (SAMPLE_RATE*CHANNELS*SAMPLE_BIT/8*PLAYER_CHUNK_MS/1000) #define PLAYER_CHUNK_SIZE (SAMPLE_RATE*CHANNELS*SAMPLE_BIT/8*PLAYER_CHUNK_MS/1000)
#define FRAMES_PER_BUFFER (PLAYER_CHUNK_SIZE/(CHANNELS*SAMPLE_BIT/8)) #define FRAMES_PER_BUFFER (PLAYER_CHUNK_SIZE/(CHANNELS*SAMPLE_BIT/8))

View file

@ -118,6 +118,9 @@ void sleepMs(int ms)
} }
int skip(0);
/* This routine will be called by the PortAudio engine when audio is needed. /* This routine will be called by the PortAudio engine when audio is needed.
** It may called at interrupt level on some machines so don't do anything ** It may called at interrupt level on some machines so don't do anything
** that could mess up the system like calling malloc() or free(). ** that could mess up the system like calling malloc() or free().
@ -155,10 +158,19 @@ static int patestCallback( const void *inputBuffer, void *outputBuffer,
int shortMedian = shortBuffer.median(); int shortMedian = shortBuffer.median();
std::cerr << "age: " << getAge(*chunk) << "\t" << age << "\t" << shortMedian << "\t" << median << "\t" << buffer.size() << "\t" << timeInfo->outputBufferDacTime*1000 << "\n"; std::cerr << "age: " << getAge(*chunk) << "\t" << age << "\t" << shortMedian << "\t" << median << "\t" << buffer.size() << "\t" << timeInfo->outputBufferDacTime*1000 << "\n";
bool skip = (age > 500) || (shortBuffer.full() && (shortMedian > 100)) || (buffer.full() && (median > 20)); if (skip == 0)
bool silence = (age < -500) || (shortBuffer.full() && (shortMedian < -100)) || (buffer.full() && (median < -20));
if (skip)
{ {
if ((age > 500) || (age < -500))
skip = age / PLAYER_CHUNK_MS;
else if (shortBuffer.full() && ((shortMedian > 100) || (shortMedian < -100)))
skip = shortMedian / PLAYER_CHUNK_MS;
else if (buffer.full() && ((median > 15) || (median < -15)))
skip = median / PLAYER_CHUNK_MS;
}
// bool silence = (age < -500) || (shortBuffer.full() && (shortMedian < -100)) || (buffer.full() && (median < -15));
if (skip > 0)
{
skip--;
chunks->pop_front(); chunks->pop_front();
delete chunk; delete chunk;
std::cerr << "packe too old, dropping\n"; std::cerr << "packe too old, dropping\n";
@ -166,8 +178,9 @@ static int patestCallback( const void *inputBuffer, void *outputBuffer,
shortBuffer.clear(); shortBuffer.clear();
usleep(100); usleep(100);
} }
else if (silence) else if (skip < 0)
{ {
skip++;
chunk = new PlayerChunk(); chunk = new PlayerChunk();
memset(&(chunk->payload[0]), 0, PLAYER_CHUNK_SIZE); memset(&(chunk->payload[0]), 0, PLAYER_CHUNK_SIZE);
// std::cerr << "age < bufferMs (" << age << " < " << bufferMs << "), playing silence\n"; // std::cerr << "age < bufferMs (" << age << " < " << bufferMs << "), playing silence\n";