annotate #AudioProcessor.cpp# @ 16:7e1510b47336 pygar svn.17

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