Mercurial > pygar
changeset 75:a15cc186e07d pygar svn.76
[svn r76] should be fully parameterized for however many cores we want (not fully tested)
author | punk |
---|---|
date | Wed, 12 May 2010 03:14:53 -0400 |
parents | 31fef269ae58 |
children | 8bd0e4d37ad2 |
files | modules/bluespec/Pygar/core/AudioCoreSystem.cpp modules/bluespec/Pygar/core/AudioCoreSystem.h |
diffstat | 2 files changed, 58 insertions(+), 54 deletions(-) [+] |
line wrap: on
line diff
1.1 --- a/modules/bluespec/Pygar/core/AudioCoreSystem.cpp Wed May 12 02:25:34 2010 -0400 1.2 +++ b/modules/bluespec/Pygar/core/AudioCoreSystem.cpp Wed May 12 03:14:53 2010 -0400 1.3 @@ -22,7 +22,7 @@ 1.4 1.5 clientStub(new AUDIOCORERRR_CLIENT_STUB_CLASS(this)) 1.6 { 1.7 - printf("SendSide Created\n"); 1.8 + printf("SendSide Constructed\n"); 1.9 } 1.10 1.11 // destructor 1.12 @@ -65,27 +65,60 @@ 1.13 fflush(stdout); 1.14 } 1.15 1.16 +bool CONNECTED_APPLICATION_CLASS::areAllFilesComplete(int numVoices, bool isFini[]) 1.17 +{ 1.18 + bool result = false; 1.19 + for (int n = 0; n < numVoices; n++) 1.20 + result |= isFini[n]; 1.21 + return result; 1.22 +} 1.23 + 1.24 // main 1.25 void 1.26 CONNECTED_APPLICATION_CLASS::Main() 1.27 { 1.28 + 1.29 //rlm: two files 1.30 - FILE *inputFile; 1.31 - FILE *inputFile1; 1.32 + FILE *inputFiles[NUM_VOICES]; 1.33 UINT16 sample; 1.34 - UINT16 sample1; 1.35 1.36 bool fileFini[NUM_VOICES]; 1.37 + UINT16 channel[NUM_VOICES]; 1.38 for (int n = 0; n < NUM_VOICES; n++) 1.39 - fileFini[n] = false; 1.40 + { 1.41 + fileFini[n] = false; 1.42 + channel[n] = n; 1.43 + } 1.44 1.45 - //rlm: not sure if normal ints are ok here; using UINT16 because I know it works 1.46 - UINT16 channel0 = 0; 1.47 - UINT16 channel1 = 1; 1.48 + fflush(stdout); 1.49 + 1.50 + // Convert input wav to pcm 1.51 + 1.52 + printf("word!\n"); 1.53 + 1.54 + for (int i = 0; i < NUM_VOICES; i++) 1.55 + { 1.56 + char filename[256]; 1.57 + sprintf(filename, "input%d", i); 1.58 + char wavname[256]; 1.59 + strcpy(wavname, filename); 1.60 + strcat(wavname, ".wav"); 1.61 + char pcmname[256]; 1.62 + strcpy(pcmname, filename); 1.63 + strcat(pcmname, ".pcm"); 1.64 + 1.65 + printf("Opening audio file %s and creating %s.\n", wavname, pcmname); 1.66 + inputFiles[i] = fopen(wavname, "r"); 1.67 + 1.68 + generate_pcm(wavname, pcmname); 1.69 + 1.70 + assert(inputFiles[i]); 1.71 + } 1.72 1.73 //init processor 1.74 int sleepCount = 0; 1.75 int result = 0; 1.76 + int count = 0; 1.77 1.78 int numCoreFini = 0; 1.79 1.80 @@ -94,30 +127,13 @@ 1.81 1.82 // Convert input wav to pcm 1.83 1.84 - //rlm: for now we are going to going to just have 2 files with "common names" 1.85 - 1.86 - generate_pcm("input.wav","input.pcm"); 1.87 - generate_pcm("input1.wav", "input1.pcm"); 1.88 - 1.89 - 1.90 - //Send data to the machine here. 1.91 - //rlm: two files 1.92 - inputFile = fopen("input.pcm","r"); 1.93 - inputFile1 = fopen("input1.pcm", "r"); 1.94 - 1.95 - assert(inputFile1); 1.96 - assert(inputFile); 1.97 - 1.98 - int count = 0; 1.99 - 1.100 - sleep(1); 1.101 + sleep(2); 1.102 printf("main:samples about to start sending %d\n", count); 1.103 1.104 //rlm: here we read both files. later refactor into a function. 1.105 // also, this will terminate when the FIRST file reaches its end. 1.106 - while( !feof(inputFile) || !feof(inputFile1)) 1.107 + while(!areAllFilesComplete(NUM_VOICES, fileFini)) 1.108 { 1.109 - 1.110 sem_wait(&throttle); 1.111 1.112 if(count%1000 == 0) 1.113 @@ -125,33 +141,20 @@ 1.114 count++; 1.115 1.116 //rlm: two files. 1.117 - 1.118 - if (!fileFini[0]) 1.119 + for (int i = 0; i < NUM_VOICES; i++) 1.120 { 1.121 - if (fread(&sample, 2, 1, inputFile)) 1.122 - clientStub->SendUnprocessedStream((UINT32)channel0 , Data,(UINT32)sample); 1.123 - else{ 1.124 - fileFini[0] = true; 1.125 - numCoreFini++; 1.126 - if (numCoreFini >= NUM_VOICES) // Need lock on last eof 1.127 - // Need to put lock here to prevent potential race condition 1.128 - pthread_mutex_lock(&lock); 1.129 - clientStub->SendUnprocessedStream((UINT32)channel0, EndOfFile,0); 1.130 - } 1.131 - } 1.132 - 1.133 - if (!fileFini[1]) 1.134 - { 1.135 - if (fread(&sample1, 2 , 1, inputFile1)) 1.136 - clientStub->SendUnprocessedStream((UINT32)channel1 , Data,(UINT32)sample1); 1.137 - else 1.138 + if (!fileFini[i]) 1.139 { 1.140 - fileFini[1] = true; 1.141 - numCoreFini++; 1.142 - if (numCoreFini >= NUM_VOICES) // Need lock on last eof 1.143 - // Need to put lock here to prevent potential race condition 1.144 - pthread_mutex_lock(&lock); 1.145 - clientStub->SendUnprocessedStream((UINT32)channel1, EndOfFile,0); 1.146 + if (fread(&sample, 2, 1, inputFiles[i])) 1.147 + clientStub->SendUnprocessedStream((UINT32)channel[i] , Data,(UINT32)sample); 1.148 + else{ 1.149 + fileFini[i] = true; 1.150 + numCoreFini++; 1.151 + if (numCoreFini >= NUM_VOICES) // Need lock on last eof 1.152 + // Need to put lock here to prevent potential race condition 1.153 + pthread_mutex_lock(&lock); 1.154 + clientStub->SendUnprocessedStream((UINT32)channel[i], EndOfFile,0); 1.155 + } 1.156 } 1.157 } 1.158 } 1.159 @@ -166,7 +169,7 @@ 1.160 1.161 // Convert input wav to pcm 1.162 // this part is ok because there is always only one input file. 1.163 - generate_wav("out_hw.pcm","input.wav","out_hw.wav"); 1.164 + generate_wav("out_hw.pcm","input0.wav","out_hw.wav"); 1.165 1.166 printf("generate wav done\n"); 1.167
2.1 --- a/modules/bluespec/Pygar/core/AudioCoreSystem.h Wed May 12 02:25:34 2010 -0400 2.2 +++ b/modules/bluespec/Pygar/core/AudioCoreSystem.h Wed May 12 03:14:53 2010 -0400 2.3 @@ -39,7 +39,8 @@ 2.4 static sem_t throttle; 2.5 static pthread_mutex_t lock; 2.6 static pthread_cond_t cond; 2.7 - 2.8 + static bool areAllFilesComplete(int numVoices, bool isFini[]); 2.9 + 2.10 public: 2.11 CONNECTED_APPLICATION_CLASS(VIRTUAL_PLATFORM vp); 2.12 ~CONNECTED_APPLICATION_CLASS();