Mercurial > pygar
view modules/bluespec/Pygar/core/revACS.cpp @ 69:5c963ab14143 pygar svn.70
[svn r70] added an attempt at multi-fileing
author | punk |
---|---|
date | Wed, 12 May 2010 00:07:40 -0400 |
parents | |
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/stats_device.h"7 //#include "asim/provides/SndfileWavUtil.h"9 #include "asim/rrr/client_stub_AUDIOCORERRR.h"11 using namespace std;13 #define NUM_VOICES 215 pthread_mutex_t CONNECTED_APPLICATION_CLASS::lock;16 pthread_cond_t CONNECTED_APPLICATION_CLASS::cond;17 sem_t CONNECTED_APPLICATION_CLASS::throttle;19 // constructor20 CONNECTED_APPLICATION_CLASS::CONNECTED_APPLICATION_CLASS(VIRTUAL_PLATFORM vp) :22 clientStub(new AUDIOCORERRR_CLIENT_STUB_CLASS(this))23 {24 }26 // destructor27 CONNECTED_APPLICATION_CLASS::~CONNECTED_APPLICATION_CLASS()28 {29 }31 // init32 void33 CONNECTED_APPLICATION_CLASS::Init()34 {36 pthread_mutex_init(&lock, NULL);37 pthread_cond_init(&cond, NULL);38 sem_init(&throttle, 0, 64);40 // enable stats41 STATS_DEVICE_SERVER_CLASS::GetInstance()->SetupStats();42 }44 void45 CONNECTED_APPLICATION_CLASS::UpdateSemaphore()46 {47 sem_post(&throttle);48 }50 void51 CONNECTED_APPLICATION_CLASS::EndSimulation()52 {53 printf("EndSimulation Called\n");54 fflush(stdout);55 pthread_mutex_lock(&lock);56 // Do something about the race occuring here57 pthread_cond_signal(&cond);58 pthread_mutex_unlock(&lock);59 printf("EndSimulation done\n");60 fflush(stdout);61 }63 // main64 void65 CONNECTED_APPLICATION_CLASS::Main()66 {67 //rlm: two files68 FILE* inputFiles[NUM_VOICES];69 // FILE *inputFile;70 // FILE *inputFile1;71 UINT16 sample;72 UINT16 sample1;74 //rlm: not sure if normal ints are ok here; using UINT16 because I know it works75 UINT16 channel0 = 0;76 UINT16 channel1 = 1;78 //init processor79 int sleepCount = 0;80 int result = 0;82 bool coreFin = false;84 fflush(stdout);86 // Convert input wav to pcm88 printf("word\n");90 for (int i = 0; i < NUM_VOICES; i++)91 {92 char* filename;93 sprintf(filename, "input%d", i);95 printf("Opening audio file %s", strcat(filename, ".wav"));96 generate_pcm(strcat(filename, ".wav"),strcat(filename, ".pcm"));97 // generate_pcm("input1.wav", "input1.pcm");99 inputFiles[i] = fopen(strcat(filename, ".pcm"), "r");101 assert(inputFiles[i]);102 }103 /*104 //rlm: for now we are going to going to just have 2 files with "common names"105 generate_pcm("input.wav","input.pcm");106 generate_pcm("input1.wav", "input1.pcm");107 //Send data to the machine here.108 //rlm: two files109 inputFile = fopen("input.pcm","r");110 inputFile1 = fopen("input1.pcm", "r");111 assert(inputFile1);112 assert(inputFile);113 */115 int count = 0;117 printf("main:PROCESSOR about to enter loop %d\n", count);119 //rlm: here we read both files. later refactor into a function.120 // also, this will terminate when the FIRST file reaches its end.121 while( (fread(&sample, 2, 1, inputFiles[0])) || (fread(&sample1, 2 , 1, inputFiles[1])))122 { /*123 printf("hi\n");124 if (!coreFin && (result = clientStub->ReadCPUToHost(0)) != 1)125 {126 sleepCount++;127 }128 else if (!coreFin && result == 1)129 {130 printf("\n***SOFT_CORE PASSED***\n");131 coreFin = true;132 }133 */135 if(count%1000 == 0)136 printf("main: %d\n", count);137 count++;138 sem_wait(&throttle);140 //rlm: two files.141 // clientStub->SendUnprocessedStream( Data,(UINT32)sample);142 clientStub->SendUnprocessedStream((UINT32)channel0 , Data,(UINT32)sample);143 clientStub->SendUnprocessedStream((UINT32)channel1 , Data,(UINT32)sample1);144 }146 printf("main: out of loop\n");148 // Need to put lock here to prevent potential race condition149 pthread_mutex_lock(&lock);151 //rlm: have to send end-files to both voices.152 // all of these operations wil eventually be moved into functions.153 //clientStub->SendUnprocessedStream(EndOfFile,0);154 clientStub->SendUnprocessedStream((UINT32)channel0, EndOfFile,0);155 clientStub->SendUnprocessedStream((UINT32)channel1, EndOfFile,0);157 printf("main: wait for end of file\n");159 pthread_cond_wait(&cond, &lock);160 pthread_mutex_unlock(&lock);162 printf("main: last data out\n");164 // Convert input wav to pcm165 // this part is ok because there is always only one input file.166 generate_wav("out_hw.pcm","input.wav","out_hw.wav");168 printf("generate wav done\n");170 // printf("If you missed it, core %s", coreFin ? "PASSED\n" : "FAILED\n");171 // Dump the stats file173 STATS_DEVICE_SERVER_CLASS::GetInstance()->DumpStats();174 STATS_DEVICE_SERVER_CLASS::GetInstance()->EmitFile();176 fflush(stdout);177 // exit(0);178 }