# HG changeset patch # User punk # Date 1273637260 14400 # Node ID 5c963ab14143dbfc8ca5e132fcebaa2a1ee4a9c8 # Parent 44cc00df11687227342bc1a8d069620b7b6e7f5c [svn r70] added an attempt at multi-fileing diff -r 44cc00df1168 -r 5c963ab14143 modules/bluespec/Pygar/core/revACS.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/modules/bluespec/Pygar/core/revACS.cpp Wed May 12 00:07:40 2010 -0400 @@ -0,0 +1,178 @@ +#include +#include +#include + +#include "asim/provides/connected_application.h" +#include "asim/provides/stats_device.h" +//#include "asim/provides/SndfileWavUtil.h" + +#include "asim/rrr/client_stub_AUDIOCORERRR.h" + +using namespace std; + +#define NUM_VOICES 2 + +pthread_mutex_t CONNECTED_APPLICATION_CLASS::lock; +pthread_cond_t CONNECTED_APPLICATION_CLASS::cond; +sem_t CONNECTED_APPLICATION_CLASS::throttle; + +// constructor +CONNECTED_APPLICATION_CLASS::CONNECTED_APPLICATION_CLASS(VIRTUAL_PLATFORM vp) : + + clientStub(new AUDIOCORERRR_CLIENT_STUB_CLASS(this)) +{ +} + +// destructor +CONNECTED_APPLICATION_CLASS::~CONNECTED_APPLICATION_CLASS() +{ +} + +// init +void +CONNECTED_APPLICATION_CLASS::Init() +{ + + pthread_mutex_init(&lock, NULL); + pthread_cond_init(&cond, NULL); + sem_init(&throttle, 0, 64); + + // enable stats + STATS_DEVICE_SERVER_CLASS::GetInstance()->SetupStats(); +} + +void +CONNECTED_APPLICATION_CLASS::UpdateSemaphore() +{ + sem_post(&throttle); +} + +void +CONNECTED_APPLICATION_CLASS::EndSimulation() +{ + printf("EndSimulation Called\n"); + fflush(stdout); + pthread_mutex_lock(&lock); + // Do something about the race occuring here + pthread_cond_signal(&cond); + pthread_mutex_unlock(&lock); + printf("EndSimulation done\n"); + fflush(stdout); +} + +// main +void +CONNECTED_APPLICATION_CLASS::Main() +{ + //rlm: two files + FILE* inputFiles[NUM_VOICES]; +// FILE *inputFile; +// FILE *inputFile1; + UINT16 sample; + UINT16 sample1; + + //rlm: not sure if normal ints are ok here; using UINT16 because I know it works + UINT16 channel0 = 0; + UINT16 channel1 = 1; + + //init processor + int sleepCount = 0; + int result = 0; + + bool coreFin = false; + + fflush(stdout); + + // Convert input wav to pcm + + printf("word\n"); + + for (int i = 0; i < NUM_VOICES; i++) + { + char* filename; + sprintf(filename, "input%d", i); + + printf("Opening audio file %s", strcat(filename, ".wav")); + generate_pcm(strcat(filename, ".wav"),strcat(filename, ".pcm")); + // generate_pcm("input1.wav", "input1.pcm"); + + inputFiles[i] = fopen(strcat(filename, ".pcm"), "r"); + + assert(inputFiles[i]); + } +/* + //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; + + printf("main:PROCESSOR about to enter loop %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( (fread(&sample, 2, 1, inputFiles[0])) || (fread(&sample1, 2 , 1, inputFiles[1]))) + { /* + printf("hi\n"); + if (!coreFin && (result = clientStub->ReadCPUToHost(0)) != 1) + { + sleepCount++; + } + else if (!coreFin && result == 1) + { + printf("\n***SOFT_CORE PASSED***\n"); + coreFin = true; + } + */ + + if(count%1000 == 0) + printf("main: %d\n", count); + count++; + sem_wait(&throttle); + + //rlm: two files. + // clientStub->SendUnprocessedStream( Data,(UINT32)sample); + clientStub->SendUnprocessedStream((UINT32)channel0 , Data,(UINT32)sample); + clientStub->SendUnprocessedStream((UINT32)channel1 , Data,(UINT32)sample1); + } + + printf("main: out of loop\n"); + + // Need to put lock here to prevent potential race condition + pthread_mutex_lock(&lock); + + //rlm: have to send end-files to both voices. + // all of these operations wil eventually be moved into functions. + //clientStub->SendUnprocessedStream(EndOfFile,0); + clientStub->SendUnprocessedStream((UINT32)channel0, EndOfFile,0); + clientStub->SendUnprocessedStream((UINT32)channel1, EndOfFile,0); + + printf("main: wait for end of file\n"); + + pthread_cond_wait(&cond, &lock); + pthread_mutex_unlock(&lock); + + printf("main: last data out\n"); + + // 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"); + + printf("generate wav done\n"); + + // printf("If you missed it, core %s", coreFin ? "PASSED\n" : "FAILED\n"); + // Dump the stats file + + STATS_DEVICE_SERVER_CLASS::GetInstance()->DumpStats(); + STATS_DEVICE_SERVER_CLASS::GetInstance()->EmitFile(); + + fflush(stdout); + // exit(0); +}