chunks have shorts

git-svn-id: svn://elaine/murooma/trunk@53 d8a302eb-03bc-478d-80e4-98257eca68ef
This commit is contained in:
(no author) 2014-07-03 18:46:52 +00:00
parent f444f63d25
commit 4d798b701c
3 changed files with 29 additions and 11 deletions

10
chunk.h
View file

@ -2,16 +2,16 @@
#define CHUNK_H #define CHUNK_H
#define SAMPLE_RATE (48000) #define SAMPLE_RATE (48000)
#define SAMPLE_BIT (16) //#define SAMPLE_BIT (16)
#define CHANNELS (2) #define CHANNELS (2)
#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*WIRE_CHUNK_MS/1000)
#define PLAYER_CHUNK_MS (10) #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*PLAYER_CHUNK_MS/1000)
#define FRAMES_PER_BUFFER (PLAYER_CHUNK_SIZE/(CHANNELS*SAMPLE_BIT/8)) #define FRAMES_PER_BUFFER (PLAYER_CHUNK_SIZE/CHANNELS)
int bufferMs; int bufferMs;
@ -20,7 +20,7 @@ struct ChunkT
{ {
int32_t tv_sec; int32_t tv_sec;
int32_t tv_usec; int32_t tv_usec;
char payload[T]; short payload[T];
}; };

View file

@ -152,7 +152,7 @@ static int patestCallback( const void *inputBuffer, void *outputBuffer,
cv.wait(lck); cv.wait(lck);
mutex.lock(); mutex.lock();
chunk = chunks->front(); chunk = chunks->front();
// std::cerr << "Chunks: " << chunks->size() << "\n"; int chunkCount = chunks->size();
mutex.unlock(); mutex.unlock();
age = getAge(*chunk) + timeInfo->outputBufferDacTime*1000 - bufferMs; age = getAge(*chunk) + timeInfo->outputBufferDacTime*1000 - bufferMs;
buffer.add(age); buffer.add(age);
@ -166,6 +166,7 @@ static int patestCallback( const void *inputBuffer, void *outputBuffer,
lastUpdate = now; lastUpdate = now;
median = buffer.median(); median = buffer.median();
shortMedian = shortBuffer.median(); shortMedian = shortBuffer.median();
std::cerr << "age: " << getAge(*chunk) << "\t" << age << "\t" << shortMedian << "\t" << median << "\t" << buffer.size() << "\t" << chunkCount << "\t" << timeInfo->outputBufferDacTime*1000 << "\n";
} }
if ((age > 500) || (age < -500)) if ((age > 500) || (age < -500))
skip = age / PLAYER_CHUNK_MS; skip = age / PLAYER_CHUNK_MS;
@ -240,8 +241,24 @@ int initAudio()
err = Pa_Initialize(); err = Pa_Initialize();
if( err != paNoError ) goto error; if( err != paNoError ) goto error;
int numDevices;
numDevices = Pa_GetDeviceCount();
if( numDevices < 0 )
{
printf( "ERROR: Pa_CountDevices returned 0x%x\n", numDevices );
err = numDevices;
goto error;
}
const PaDeviceInfo *deviceInfo;
for(int i=0; i<numDevices; i++)
{
deviceInfo = Pa_GetDeviceInfo(i);
std::cerr << "Device " << i << ": " << deviceInfo->name << "\n";
}
outputParameters.device = Pa_GetDefaultOutputDevice(); /* default output device */ outputParameters.device = Pa_GetDefaultOutputDevice(); /* default output device */
if (outputParameters.device == paNoDevice) { if (outputParameters.device == paNoDevice)
{
fprintf(stderr,"Error: No default output device.\n"); fprintf(stderr,"Error: No default output device.\n");
goto error; goto error;
} }

View file

@ -30,7 +30,7 @@ int main () {
// Initialize random number generator // Initialize random number generator
size_t idx(0); size_t idx(0);
char c;//[2]; char c[2];
Chunk chunk; Chunk chunk;
timeval ts; timeval ts;
ts.tv_sec = 0; ts.tv_sec = 0;
@ -38,10 +38,11 @@ int main () {
timeval last; timeval last;
gettimeofday(&last, NULL); gettimeofday(&last, NULL);
last.tv_sec -= 1000; last.tv_sec -= 1000;
while (!cin.get(c).eof()) while (true)
{ {
// read(fd, &msg[0], size); c[0] = cin.get();
chunk.payload[idx++] = c; c[1] = cin.get();
chunk.payload[idx++] = c[0] + (c[1] << 8);
if (idx == WIRE_CHUNK_SIZE) if (idx == WIRE_CHUNK_SIZE)
{ {
timeval now; timeval now;