Mercurial > pygar
view modules/bluespec/Pygar/common/AudioProcessor.cpp @ 37:0475235d1513 pygar svn.38
[svn r38] fixed audiocorepipe
author | punk |
---|---|
date | Tue, 04 May 2010 19:25:30 -0400 |
parents | 74716e9a81cc |
children |
line wrap: on
line source
1 #include <stdio.h>2 #include <pthread.h>3 #include <semaphore.h>5 #include "asim/provides/connected_application.h"6 //#include "asim/provides/SndfileWavUtil.h"8 #include "asim/rrr/client_stub_AUDIOPROCESSORRRR.h"10 using namespace std;12 pthread_mutex_t CONNECTED_APPLICATION_CLASS::lock;13 pthread_cond_t CONNECTED_APPLICATION_CLASS::cond;14 sem_t CONNECTED_APPLICATION_CLASS::throttle;16 // constructor17 CONNECTED_APPLICATION_CLASS::CONNECTED_APPLICATION_CLASS(VIRTUAL_PLATFORM vp) :18 clientStub(new AUDIOPROCESSORRRR_CLIENT_STUB_CLASS(this))19 {20 }22 // destructor23 CONNECTED_APPLICATION_CLASS::~CONNECTED_APPLICATION_CLASS()24 {25 }27 // init28 void29 CONNECTED_APPLICATION_CLASS::Init()30 {32 pthread_mutex_init(&lock, NULL);33 pthread_cond_init(&cond, NULL);34 sem_init(&throttle, 0, 64);36 }38 void39 CONNECTED_APPLICATION_CLASS::UpdateSemaphore()40 {41 sem_post(&throttle);42 }44 void45 CONNECTED_APPLICATION_CLASS::EndSimulation()46 {47 printf("EndSimulation Called\n");48 fflush(stdout);49 pthread_mutex_lock(&lock);50 // Do something about the race occuring here51 pthread_cond_signal(&cond);52 pthread_mutex_unlock(&lock);53 printf("EndSimulation done\n");54 fflush(stdout);55 }57 // main58 void59 CONNECTED_APPLICATION_CLASS::Main()60 {61 FILE *inputFile;62 UINT16 sample;64 // Convert input wav to pcm65 generate_pcm("input.wav","input.pcm");67 //Send data to the machine here.68 inputFile = fopen("input.pcm","r");69 assert(inputFile);72 int count = 0;74 printf("main: about to enter loop %d\n", count);76 while(fread(&sample, 2, 1, inputFile)) {77 if(count%1000 == 0)78 printf("main: %d\n", count);79 count++;80 sem_wait(&throttle);81 clientStub->SendUnprocessedStream(Data,(UINT32)sample);82 }84 printf("main: out of loop\n");86 // Need to put lock here to prevent potential race condition87 pthread_mutex_lock(&lock);88 clientStub->SendUnprocessedStream(EndOfFile,0);90 printf("main: wait for end of file\n");92 pthread_cond_wait(&cond, &lock);93 pthread_mutex_unlock(&lock);95 printf("main: lastt data out\n");97 // Convert input wav to pcm98 generate_wav("out_hw.pcm","input.wav","out_hw.wav");100 printf("generate wav done\n");102 fflush(stdout);103 exit(0);104 }