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 SAMPLE_RATE (48000)
#define SAMPLE_BIT (16)
//#define SAMPLE_BIT (16)
#define CHANNELS (2)
#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_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;
@ -20,7 +20,7 @@ struct ChunkT
{
int32_t tv_sec;
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);
mutex.lock();
chunk = chunks->front();
// std::cerr << "Chunks: " << chunks->size() << "\n";
int chunkCount = chunks->size();
mutex.unlock();
age = getAge(*chunk) + timeInfo->outputBufferDacTime*1000 - bufferMs;
buffer.add(age);
@ -166,6 +166,7 @@ static int patestCallback( const void *inputBuffer, void *outputBuffer,
lastUpdate = now;
median = buffer.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))
skip = age / PLAYER_CHUNK_MS;
@ -240,8 +241,24 @@ int initAudio()
err = Pa_Initialize();
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 */
if (outputParameters.device == paNoDevice) {
if (outputParameters.device == paNoDevice)
{
fprintf(stderr,"Error: No default output device.\n");
goto error;
}

View file

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