# HG changeset patch # User punk # Date 1273648493 14400 # Node ID a15cc186e07d55489d9422daae8834cd8811bdb9 # Parent 31fef269ae58bbdb29a5746845e912f7ee88d272 [svn r76] should be fully parameterized for however many cores we want (not fully tested) diff -r 31fef269ae58 -r a15cc186e07d modules/bluespec/Pygar/core/AudioCoreSystem.cpp --- a/modules/bluespec/Pygar/core/AudioCoreSystem.cpp Wed May 12 02:25:34 2010 -0400 +++ b/modules/bluespec/Pygar/core/AudioCoreSystem.cpp Wed May 12 03:14:53 2010 -0400 @@ -22,7 +22,7 @@ clientStub(new AUDIOCORERRR_CLIENT_STUB_CLASS(this)) { - printf("SendSide Created\n"); + printf("SendSide Constructed\n"); } // destructor @@ -65,27 +65,60 @@ fflush(stdout); } +bool CONNECTED_APPLICATION_CLASS::areAllFilesComplete(int numVoices, bool isFini[]) +{ + bool result = false; + for (int n = 0; n < numVoices; n++) + result |= isFini[n]; + return result; +} + // main void CONNECTED_APPLICATION_CLASS::Main() { + //rlm: two files - FILE *inputFile; - FILE *inputFile1; + FILE *inputFiles[NUM_VOICES]; UINT16 sample; - UINT16 sample1; bool fileFini[NUM_VOICES]; + UINT16 channel[NUM_VOICES]; for (int n = 0; n < NUM_VOICES; n++) - fileFini[n] = false; + { + fileFini[n] = false; + channel[n] = n; + } - //rlm: not sure if normal ints are ok here; using UINT16 because I know it works - UINT16 channel0 = 0; - UINT16 channel1 = 1; + fflush(stdout); + + // Convert input wav to pcm + + printf("word!\n"); + + for (int i = 0; i < NUM_VOICES; i++) + { + char filename[256]; + sprintf(filename, "input%d", i); + char wavname[256]; + strcpy(wavname, filename); + strcat(wavname, ".wav"); + char pcmname[256]; + strcpy(pcmname, filename); + strcat(pcmname, ".pcm"); + + printf("Opening audio file %s and creating %s.\n", wavname, pcmname); + inputFiles[i] = fopen(wavname, "r"); + + generate_pcm(wavname, pcmname); + + assert(inputFiles[i]); + } //init processor int sleepCount = 0; int result = 0; + int count = 0; int numCoreFini = 0; @@ -94,30 +127,13 @@ // Convert input wav to pcm - //rlm: for now we are going to going to just have 2 files with "common names" - - generate_pcm("input.wav","input.pcm"); - generate_pcm("input1.wav", "input1.pcm"); - - - //Send data to the machine here. - //rlm: two files - inputFile = fopen("input.pcm","r"); - inputFile1 = fopen("input1.pcm", "r"); - - assert(inputFile1); - assert(inputFile); - - int count = 0; - - sleep(1); + sleep(2); printf("main:samples about to start sending %d\n", count); //rlm: here we read both files. later refactor into a function. // also, this will terminate when the FIRST file reaches its end. - while( !feof(inputFile) || !feof(inputFile1)) + while(!areAllFilesComplete(NUM_VOICES, fileFini)) { - sem_wait(&throttle); if(count%1000 == 0) @@ -125,33 +141,20 @@ count++; //rlm: two files. - - if (!fileFini[0]) + for (int i = 0; i < NUM_VOICES; i++) { - if (fread(&sample, 2, 1, inputFile)) - clientStub->SendUnprocessedStream((UINT32)channel0 , Data,(UINT32)sample); - else{ - fileFini[0] = true; - numCoreFini++; - if (numCoreFini >= NUM_VOICES) // Need lock on last eof - // Need to put lock here to prevent potential race condition - pthread_mutex_lock(&lock); - clientStub->SendUnprocessedStream((UINT32)channel0, EndOfFile,0); - } - } - - if (!fileFini[1]) - { - if (fread(&sample1, 2 , 1, inputFile1)) - clientStub->SendUnprocessedStream((UINT32)channel1 , Data,(UINT32)sample1); - else + if (!fileFini[i]) { - fileFini[1] = true; - numCoreFini++; - if (numCoreFini >= NUM_VOICES) // Need lock on last eof - // Need to put lock here to prevent potential race condition - pthread_mutex_lock(&lock); - clientStub->SendUnprocessedStream((UINT32)channel1, EndOfFile,0); + if (fread(&sample, 2, 1, inputFiles[i])) + clientStub->SendUnprocessedStream((UINT32)channel[i] , Data,(UINT32)sample); + else{ + fileFini[i] = true; + numCoreFini++; + if (numCoreFini >= NUM_VOICES) // Need lock on last eof + // Need to put lock here to prevent potential race condition + pthread_mutex_lock(&lock); + clientStub->SendUnprocessedStream((UINT32)channel[i], EndOfFile,0); + } } } } @@ -166,7 +169,7 @@ // Convert input wav to pcm // this part is ok because there is always only one input file. - generate_wav("out_hw.pcm","input.wav","out_hw.wav"); + generate_wav("out_hw.pcm","input0.wav","out_hw.wav"); printf("generate wav done\n"); diff -r 31fef269ae58 -r a15cc186e07d modules/bluespec/Pygar/core/AudioCoreSystem.h --- a/modules/bluespec/Pygar/core/AudioCoreSystem.h Wed May 12 02:25:34 2010 -0400 +++ b/modules/bluespec/Pygar/core/AudioCoreSystem.h Wed May 12 03:14:53 2010 -0400 @@ -39,7 +39,8 @@ static sem_t throttle; static pthread_mutex_t lock; static pthread_cond_t cond; - + static bool areAllFilesComplete(int numVoices, bool isFini[]); + public: CONNECTED_APPLICATION_CLASS(VIRTUAL_PLATFORM vp); ~CONNECTED_APPLICATION_CLASS();