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@13: STATS_DEVICE_SERVER_CLASS::GetInstance()->SetupStats(); punk@13: } punk@13: 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; rlm@34: FILE *inputFile1; punk@13: UINT16 sample; rlm@34: UINT16 sample1; rlm@34: rlm@34: //rlm: not sure if normal ints are ok here; using UINT16 because I know it works rlm@34: UINT16 channel0 = 0; rlm@34: 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: rlm@34: rlm@34: punk@31: fflush(stdout); punk@31: punk@13: // Convert input wav to pcm rlm@34: 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"); rlm@34: generate_pcm("input1.wav", "input1.pcm"); rlm@34: rlm@34: punk@13: punk@13: //Send data to the machine here. rlm@34: //rlm: two files punk@13: inputFile = fopen("input.pcm","r"); rlm@34: inputFile = fopen("input1.pcm", "r"); rlm@34: rlm@34: assert(inputFile1); punk@13: assert(inputFile); punk@13: punk@13: int count = 0; punk@13: rlm@23: printf("main:PROCESSOR about to enter loop %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. rlm@34: while( (fread(&sample, 2, 1, inputFile)) && (fread(&sample1, 2 , 1, inputFile1))) { punk@31: if (!coreFin && (result = clientStub->ReadCPUToHost(0)) != 1) punk@31: { punk@31: sleepCount++; punk@31: if(sleepCount == 200) { punk@31: printf("Failed to get response from hardware, bailing\n\n"); punk@31: printf("This means that either your hardware is hanging\n"); punk@31: printf("or that the software hasn't given it enough time\n"); punk@31: printf("to complete. If you think it needs more time, then\n"); punk@31: printf("edit CONNECTED_APPLICATION_CLASS::Main() in ProcessorSystem.cpp\n"); punk@31: printf("(connected_application)\n"); punk@31: } punk@31: } punk@31: else if (!coreFin && result == 1) punk@31: { punk@31: printf("\n***SOFT_CORE PASSED***\n"); punk@31: coreFin = true; punk@31: } punk@31: punk@13: if(count%1000 == 0) punk@13: printf("main: %d\n", count); punk@13: count++; punk@13: sem_wait(&throttle); rlm@34: rlm@34: //rlm: two files. rlm@34: clientStub->SendUnprocessedStream(channel0 , Data,(UINT32)sample); rlm@34: clientStub->SendUnprocessedStream(channel1 , Data,(UINT32)sample1); punk@31: 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@34: clientStub->SendUnprocessedStream(channel0, EndOfFile,0); rlm@34: clientStub->SendUnprocessedStream(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@32: 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@13: exit(0); punk@31: }