punk@13: #include punk@13: #include punk@13: #include punk@13: punk@13: #include "asim/provides/connected_application.h" punk@13: #include "asim/provides/stats_device.h" punk@13: //#include "asim/provides/SndfileWavUtil.h" punk@13: punk@13: #include "asim/rrr/client_stub_AUDIOCORERRR.h" punk@13: punk@13: using namespace std; punk@13: punk@13: pthread_mutex_t CONNECTED_APPLICATION_CLASS::lock; punk@13: pthread_cond_t CONNECTED_APPLICATION_CLASS::cond; punk@13: sem_t CONNECTED_APPLICATION_CLASS::throttle; punk@13: punk@13: // constructor punk@13: CONNECTED_APPLICATION_CLASS::CONNECTED_APPLICATION_CLASS(VIRTUAL_PLATFORM vp) : rlm@23: rlm@23: clientStub(new AUDIOCORERRR_CLIENT_STUB_CLASS(this)) punk@13: { punk@13: } punk@13: punk@13: // destructor punk@13: CONNECTED_APPLICATION_CLASS::~CONNECTED_APPLICATION_CLASS() punk@13: { punk@13: } punk@13: punk@13: // init punk@13: void punk@13: CONNECTED_APPLICATION_CLASS::Init() punk@13: { punk@13: punk@13: pthread_mutex_init(&lock, NULL); punk@13: pthread_cond_init(&cond, NULL); punk@13: sem_init(&throttle, 0, 64); punk@13: punk@13: // enable stats punk@57: // STATS_DEVICE_SERVER_CLASS::GetInstance()->SetupStats(); punk@13: } punk@13: punk@57: //This isn't called. punk@13: void punk@13: CONNECTED_APPLICATION_CLASS::UpdateSemaphore() punk@13: { punk@13: sem_post(&throttle); punk@13: } punk@13: punk@13: void punk@13: CONNECTED_APPLICATION_CLASS::EndSimulation() punk@13: { punk@13: printf("EndSimulation Called\n"); punk@13: fflush(stdout); punk@13: pthread_mutex_lock(&lock); punk@13: // Do something about the race occuring here punk@13: pthread_cond_signal(&cond); punk@13: pthread_mutex_unlock(&lock); punk@13: printf("EndSimulation done\n"); punk@13: fflush(stdout); punk@13: } punk@13: punk@13: // main punk@13: void punk@13: CONNECTED_APPLICATION_CLASS::Main() punk@13: { rlm@34: //rlm: two files punk@13: FILE *inputFile; punk@52: FILE *inputFile1; punk@13: UINT16 sample; punk@52: UINT16 sample1; rlm@34: rlm@34: //rlm: not sure if normal ints are ok here; using UINT16 because I know it works punk@52: UINT16 channel0 = 0; punk@52: UINT16 channel1 = 1; punk@31: punk@31: //init processor punk@31: int sleepCount = 0; punk@31: int result = 0; punk@31: punk@31: bool coreFin = false; punk@31: punk@31: fflush(stdout); punk@31: punk@13: // Convert input wav to pcm rlm@34: rlm@34: //rlm: for now we are going to going to just have 2 files with "common names" rlm@34: punk@13: generate_pcm("input.wav","input.pcm"); punk@52: generate_pcm("input1.wav", "input1.pcm"); rlm@34: punk@13: punk@13: //Send data to the machine here. rlm@34: //rlm: two files punk@13: inputFile = fopen("input.pcm","r"); punk@53: inputFile1 = fopen("input1.pcm", "r"); rlm@34: punk@52: assert(inputFile1); punk@13: assert(inputFile); punk@13: punk@13: int count = 0; punk@13: punk@57: printf("main:samples about to start sending %d\n", count); punk@13: rlm@34: //rlm: here we read both files. later refactor into a function. rlm@34: // also, this will terminate when the FIRST file reaches its end. punk@52: while( (fread(&sample, 2, 1, inputFile)) || (fread(&sample1, 2 , 1, inputFile1))) punk@39: { /* punk@37: printf("hi\n"); punk@37: if (!coreFin && (result = clientStub->ReadCPUToHost(0)) != 1) punk@37: { punk@37: sleepCount++; punk@37: } punk@37: else if (!coreFin && result == 1) punk@37: { punk@37: printf("\n***SOFT_CORE PASSED***\n"); punk@37: coreFin = true; punk@37: } punk@39: */ punk@31: punk@37: if(count%1000 == 0) punk@37: printf("main: %d\n", count); punk@37: count++; punk@37: rlm@34: //rlm: two files. rlm@41: // clientStub->SendUnprocessedStream( Data,(UINT32)sample); punk@52: clientStub->SendUnprocessedStream((UINT32)channel0 , Data,(UINT32)sample); punk@52: clientStub->SendUnprocessedStream((UINT32)channel1 , Data,(UINT32)sample1); punk@13: } punk@13: punk@13: printf("main: out of loop\n"); punk@13: punk@13: // Need to put lock here to prevent potential race condition punk@13: pthread_mutex_lock(&lock); rlm@34: rlm@34: //rlm: have to send end-files to both voices. rlm@34: // all of these operations wil eventually be moved into functions. rlm@41: //clientStub->SendUnprocessedStream(EndOfFile,0); rlm@41: clientStub->SendUnprocessedStream((UINT32)channel0, EndOfFile,0); punk@52: clientStub->SendUnprocessedStream((UINT32)channel1, EndOfFile,0); punk@13: punk@13: printf("main: wait for end of file\n"); punk@13: punk@13: pthread_cond_wait(&cond, &lock); punk@13: pthread_mutex_unlock(&lock); punk@13: rlm@23: printf("main: last data out\n"); punk@13: punk@13: // Convert input wav to pcm rlm@34: // this part is ok because there is always only one input file. punk@13: generate_wav("out_hw.pcm","input.wav","out_hw.wav"); punk@13: punk@13: printf("generate wav done\n"); punk@13: punk@50: // printf("If you missed it, core %s", coreFin ? "PASSED\n" : "FAILED\n"); punk@13: // Dump the stats file punk@13: punk@13: STATS_DEVICE_SERVER_CLASS::GetInstance()->DumpStats(); punk@13: STATS_DEVICE_SERVER_CLASS::GetInstance()->EmitFile(); punk@13: punk@31: fflush(stdout); punk@53: // exit(0); punk@31: }