annotate modules/bluespec/Pygar/core/AudioCoreSystem.cpp~ @ 13:6d461680c6d9 pygar svn.14

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