rlm@8: #include rlm@8: #include rlm@8: #include rlm@8: rlm@8: #include "asim/provides/connected_application.h" rlm@8: //#include "asim/provides/SndfileWavUtil.h" rlm@8: rlm@8: #include "asim/rrr/client_stub_AUDIOPROCESSORRRR.h" rlm@8: rlm@8: using namespace std; rlm@8: rlm@8: pthread_mutex_t CONNECTED_APPLICATION_CLASS::lock; rlm@8: pthread_cond_t CONNECTED_APPLICATION_CLASS::cond; rlm@8: sem_t CONNECTED_APPLICATION_CLASS::throttle; rlm@8: rlm@8: // constructor rlm@8: CONNECTED_APPLICATION_CLASS::CONNECTED_APPLICATION_CLASS(VIRTUAL_PLATFORM vp) : rlm@8: clientStub(new AUDIOPROCESSORRRR_CLIENT_STUB_CLASS(this)) rlm@8: { rlm@8: } rlm@8: rlm@8: // destructor rlm@8: CONNECTED_APPLICATION_CLASS::~CONNECTED_APPLICATION_CLASS() rlm@8: { rlm@8: } rlm@8: rlm@8: // init rlm@8: void rlm@8: CONNECTED_APPLICATION_CLASS::Init() rlm@8: { rlm@8: rlm@8: pthread_mutex_init(&lock, NULL); rlm@8: pthread_cond_init(&cond, NULL); rlm@8: sem_init(&throttle, 0, 64); rlm@8: rlm@8: } rlm@8: rlm@8: void rlm@8: CONNECTED_APPLICATION_CLASS::UpdateSemaphore() rlm@8: { rlm@8: sem_post(&throttle); rlm@8: } rlm@8: rlm@8: void rlm@8: CONNECTED_APPLICATION_CLASS::EndSimulation() rlm@8: { rlm@8: printf("EndSimulation Called\n"); rlm@8: fflush(stdout); rlm@8: pthread_mutex_lock(&lock); rlm@8: // Do something about the race occuring here rlm@8: pthread_cond_signal(&cond); rlm@8: pthread_mutex_unlock(&lock); rlm@8: printf("EndSimulation done\n"); rlm@8: fflush(stdout); rlm@8: } rlm@8: rlm@8: // main rlm@8: void rlm@8: CONNECTED_APPLICATION_CLASS::Main() rlm@8: { rlm@8: FILE *inputFile; rlm@8: UINT16 sample; rlm@8: rlm@8: // Convert input wav to pcm rlm@8: generate_pcm("input.wav","input.pcm"); rlm@8: rlm@8: //Send data to the machine here. rlm@8: inputFile = fopen("input.pcm","r"); rlm@8: assert(inputFile); rlm@8: rlm@8: rlm@8: int count = 0; rlm@8: rlm@8: printf("main: about to enter loop %d\n", count); rlm@8: rlm@8: while(fread(&sample, 2, 1, inputFile)) { rlm@8: if(count%1000 == 0) rlm@8: printf("main: %d\n", count); rlm@8: count++; rlm@8: sem_wait(&throttle); rlm@8: clientStub->SendUnprocessedStream(Data,(UINT32)sample); rlm@8: } rlm@8: rlm@8: printf("main: out of loop\n"); rlm@8: rlm@8: // Need to put lock here to prevent potential race condition rlm@8: pthread_mutex_lock(&lock); rlm@8: clientStub->SendUnprocessedStream(EndOfFile,0); rlm@8: rlm@8: printf("main: wait for end of file\n"); rlm@8: rlm@8: pthread_cond_wait(&cond, &lock); rlm@8: pthread_mutex_unlock(&lock); rlm@8: rlm@8: printf("main: lastt data out\n"); rlm@8: rlm@8: // Convert input wav to pcm rlm@8: generate_wav("out_hw.pcm","input.wav","out_hw.wav"); rlm@8: rlm@8: printf("generate wav done\n"); rlm@8: rlm@8: fflush(stdout); rlm@8: exit(0); rlm@8: }