annotate 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
rev   line source
rlm@8 1 #include <stdio.h>
rlm@8 2 #include <pthread.h>
rlm@8 3 #include <semaphore.h>
rlm@8 4
rlm@8 5 #include "asim/provides/connected_application.h"
rlm@8 6 //#include "asim/provides/SndfileWavUtil.h"
rlm@8 7
rlm@8 8 #include "asim/rrr/client_stub_AUDIOPROCESSORRRR.h"
rlm@8 9
rlm@8 10 using namespace std;
rlm@8 11
rlm@8 12 pthread_mutex_t CONNECTED_APPLICATION_CLASS::lock;
rlm@8 13 pthread_cond_t CONNECTED_APPLICATION_CLASS::cond;
rlm@8 14 sem_t CONNECTED_APPLICATION_CLASS::throttle;
rlm@8 15
rlm@8 16 // constructor
rlm@8 17 CONNECTED_APPLICATION_CLASS::CONNECTED_APPLICATION_CLASS(VIRTUAL_PLATFORM vp) :
rlm@8 18 clientStub(new AUDIOPROCESSORRRR_CLIENT_STUB_CLASS(this))
rlm@8 19 {
rlm@8 20 }
rlm@8 21
rlm@8 22 // destructor
rlm@8 23 CONNECTED_APPLICATION_CLASS::~CONNECTED_APPLICATION_CLASS()
rlm@8 24 {
rlm@8 25 }
rlm@8 26
rlm@8 27 // init
rlm@8 28 void
rlm@8 29 CONNECTED_APPLICATION_CLASS::Init()
rlm@8 30 {
rlm@8 31
rlm@8 32 pthread_mutex_init(&lock, NULL);
rlm@8 33 pthread_cond_init(&cond, NULL);
rlm@8 34 sem_init(&throttle, 0, 64);
rlm@8 35
rlm@8 36 }
rlm@8 37
rlm@8 38 void
rlm@8 39 CONNECTED_APPLICATION_CLASS::UpdateSemaphore()
rlm@8 40 {
rlm@8 41 sem_post(&throttle);
rlm@8 42 }
rlm@8 43
rlm@8 44 void
rlm@8 45 CONNECTED_APPLICATION_CLASS::EndSimulation()
rlm@8 46 {
rlm@8 47 printf("EndSimulation Called\n");
rlm@8 48 fflush(stdout);
rlm@8 49 pthread_mutex_lock(&lock);
rlm@8 50 // Do something about the race occuring here
rlm@8 51 pthread_cond_signal(&cond);
rlm@8 52 pthread_mutex_unlock(&lock);
rlm@8 53 printf("EndSimulation done\n");
rlm@8 54 fflush(stdout);
rlm@8 55 }
rlm@8 56
rlm@8 57 // main
rlm@8 58 void
rlm@8 59 CONNECTED_APPLICATION_CLASS::Main()
rlm@8 60 {
rlm@8 61 FILE *inputFile;
rlm@8 62 UINT16 sample;
rlm@8 63
rlm@8 64 // Convert input wav to pcm
rlm@8 65 generate_pcm("input.wav","input.pcm");
rlm@8 66
rlm@8 67 //Send data to the machine here.
rlm@8 68 inputFile = fopen("input.pcm","r");
rlm@8 69 assert(inputFile);
rlm@8 70
rlm@8 71
rlm@8 72 int count = 0;
rlm@8 73
rlm@8 74 printf("main: about to enter loop %d\n", count);
rlm@8 75
rlm@8 76 while(fread(&sample, 2, 1, inputFile)) {
rlm@8 77 if(count%1000 == 0)
rlm@8 78 printf("main: %d\n", count);
rlm@8 79 count++;
rlm@8 80 sem_wait(&throttle);
rlm@8 81 clientStub->SendUnprocessedStream(Data,(UINT32)sample);
rlm@8 82 }
rlm@8 83
rlm@8 84 printf("main: out of loop\n");
rlm@8 85
rlm@8 86 // Need to put lock here to prevent potential race condition
rlm@8 87 pthread_mutex_lock(&lock);
rlm@8 88 clientStub->SendUnprocessedStream(EndOfFile,0);
rlm@8 89
rlm@8 90 printf("main: wait for end of file\n");
rlm@8 91
rlm@8 92 pthread_cond_wait(&cond, &lock);
rlm@8 93 pthread_mutex_unlock(&lock);
rlm@8 94
rlm@8 95 printf("main: lastt data out\n");
rlm@8 96
rlm@8 97 // Convert input wav to pcm
rlm@8 98 generate_wav("out_hw.pcm","input.wav","out_hw.wav");
rlm@8 99
rlm@8 100 printf("generate wav done\n");
rlm@8 101
rlm@8 102 fflush(stdout);
rlm@8 103 exit(0);
rlm@8 104 }