Mercurial > pygar
diff 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 diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/modules/bluespec/Pygar/core/revACS.cpp Wed May 12 00:07:40 2010 -0400 1.3 @@ -0,0 +1,178 @@ 1.4 +#include <stdio.h> 1.5 +#include <pthread.h> 1.6 +#include <semaphore.h> 1.7 + 1.8 +#include "asim/provides/connected_application.h" 1.9 +#include "asim/provides/stats_device.h" 1.10 +//#include "asim/provides/SndfileWavUtil.h" 1.11 + 1.12 +#include "asim/rrr/client_stub_AUDIOCORERRR.h" 1.13 + 1.14 +using namespace std; 1.15 + 1.16 +#define NUM_VOICES 2 1.17 + 1.18 +pthread_mutex_t CONNECTED_APPLICATION_CLASS::lock; 1.19 +pthread_cond_t CONNECTED_APPLICATION_CLASS::cond; 1.20 +sem_t CONNECTED_APPLICATION_CLASS::throttle; 1.21 + 1.22 +// constructor 1.23 +CONNECTED_APPLICATION_CLASS::CONNECTED_APPLICATION_CLASS(VIRTUAL_PLATFORM vp) : 1.24 + 1.25 + clientStub(new AUDIOCORERRR_CLIENT_STUB_CLASS(this)) 1.26 +{ 1.27 +} 1.28 + 1.29 +// destructor 1.30 +CONNECTED_APPLICATION_CLASS::~CONNECTED_APPLICATION_CLASS() 1.31 +{ 1.32 +} 1.33 + 1.34 +// init 1.35 +void 1.36 +CONNECTED_APPLICATION_CLASS::Init() 1.37 +{ 1.38 + 1.39 + pthread_mutex_init(&lock, NULL); 1.40 + pthread_cond_init(&cond, NULL); 1.41 + sem_init(&throttle, 0, 64); 1.42 + 1.43 + // enable stats 1.44 + STATS_DEVICE_SERVER_CLASS::GetInstance()->SetupStats(); 1.45 +} 1.46 + 1.47 +void 1.48 +CONNECTED_APPLICATION_CLASS::UpdateSemaphore() 1.49 +{ 1.50 + sem_post(&throttle); 1.51 +} 1.52 + 1.53 +void 1.54 +CONNECTED_APPLICATION_CLASS::EndSimulation() 1.55 +{ 1.56 + printf("EndSimulation Called\n"); 1.57 + fflush(stdout); 1.58 + pthread_mutex_lock(&lock); 1.59 + // Do something about the race occuring here 1.60 + pthread_cond_signal(&cond); 1.61 + pthread_mutex_unlock(&lock); 1.62 + printf("EndSimulation done\n"); 1.63 + fflush(stdout); 1.64 +} 1.65 + 1.66 +// main 1.67 +void 1.68 +CONNECTED_APPLICATION_CLASS::Main() 1.69 +{ 1.70 + //rlm: two files 1.71 + FILE* inputFiles[NUM_VOICES]; 1.72 +// FILE *inputFile; 1.73 +// FILE *inputFile1; 1.74 + UINT16 sample; 1.75 + UINT16 sample1; 1.76 + 1.77 + //rlm: not sure if normal ints are ok here; using UINT16 because I know it works 1.78 + UINT16 channel0 = 0; 1.79 + UINT16 channel1 = 1; 1.80 + 1.81 + //init processor 1.82 + int sleepCount = 0; 1.83 + int result = 0; 1.84 + 1.85 + bool coreFin = false; 1.86 + 1.87 + fflush(stdout); 1.88 + 1.89 + // Convert input wav to pcm 1.90 + 1.91 + printf("word\n"); 1.92 + 1.93 + for (int i = 0; i < NUM_VOICES; i++) 1.94 + { 1.95 + char* filename; 1.96 + sprintf(filename, "input%d", i); 1.97 + 1.98 + printf("Opening audio file %s", strcat(filename, ".wav")); 1.99 + generate_pcm(strcat(filename, ".wav"),strcat(filename, ".pcm")); 1.100 + // generate_pcm("input1.wav", "input1.pcm"); 1.101 + 1.102 + inputFiles[i] = fopen(strcat(filename, ".pcm"), "r"); 1.103 + 1.104 + assert(inputFiles[i]); 1.105 + } 1.106 +/* 1.107 + //rlm: for now we are going to going to just have 2 files with "common names" 1.108 + generate_pcm("input.wav","input.pcm"); 1.109 + generate_pcm("input1.wav", "input1.pcm"); 1.110 + //Send data to the machine here. 1.111 + //rlm: two files 1.112 + inputFile = fopen("input.pcm","r"); 1.113 + inputFile1 = fopen("input1.pcm", "r"); 1.114 + assert(inputFile1); 1.115 + assert(inputFile); 1.116 +*/ 1.117 + 1.118 + int count = 0; 1.119 + 1.120 + printf("main:PROCESSOR about to enter loop %d\n", count); 1.121 + 1.122 + //rlm: here we read both files. later refactor into a function. 1.123 + // also, this will terminate when the FIRST file reaches its end. 1.124 + while( (fread(&sample, 2, 1, inputFiles[0])) || (fread(&sample1, 2 , 1, inputFiles[1]))) 1.125 + { /* 1.126 + printf("hi\n"); 1.127 + if (!coreFin && (result = clientStub->ReadCPUToHost(0)) != 1) 1.128 + { 1.129 + sleepCount++; 1.130 + } 1.131 + else if (!coreFin && result == 1) 1.132 + { 1.133 + printf("\n***SOFT_CORE PASSED***\n"); 1.134 + coreFin = true; 1.135 + } 1.136 + */ 1.137 + 1.138 + if(count%1000 == 0) 1.139 + printf("main: %d\n", count); 1.140 + count++; 1.141 + sem_wait(&throttle); 1.142 + 1.143 + //rlm: two files. 1.144 + // clientStub->SendUnprocessedStream( Data,(UINT32)sample); 1.145 + clientStub->SendUnprocessedStream((UINT32)channel0 , Data,(UINT32)sample); 1.146 + clientStub->SendUnprocessedStream((UINT32)channel1 , Data,(UINT32)sample1); 1.147 + } 1.148 + 1.149 + printf("main: out of loop\n"); 1.150 + 1.151 + // Need to put lock here to prevent potential race condition 1.152 + pthread_mutex_lock(&lock); 1.153 + 1.154 + //rlm: have to send end-files to both voices. 1.155 + // all of these operations wil eventually be moved into functions. 1.156 + //clientStub->SendUnprocessedStream(EndOfFile,0); 1.157 + clientStub->SendUnprocessedStream((UINT32)channel0, EndOfFile,0); 1.158 + clientStub->SendUnprocessedStream((UINT32)channel1, EndOfFile,0); 1.159 + 1.160 + printf("main: wait for end of file\n"); 1.161 + 1.162 + pthread_cond_wait(&cond, &lock); 1.163 + pthread_mutex_unlock(&lock); 1.164 + 1.165 + printf("main: last data out\n"); 1.166 + 1.167 + // Convert input wav to pcm 1.168 + // this part is ok because there is always only one input file. 1.169 + generate_wav("out_hw.pcm","input.wav","out_hw.wav"); 1.170 + 1.171 + printf("generate wav done\n"); 1.172 + 1.173 + // printf("If you missed it, core %s", coreFin ? "PASSED\n" : "FAILED\n"); 1.174 + // Dump the stats file 1.175 + 1.176 + STATS_DEVICE_SERVER_CLASS::GetInstance()->DumpStats(); 1.177 + STATS_DEVICE_SERVER_CLASS::GetInstance()->EmitFile(); 1.178 + 1.179 + fflush(stdout); 1.180 + // exit(0); 1.181 +}