Mercurial > pygar
diff modules/bluespec/Pygar/core/AudioCoreSystem.cpp @ 68:44cc00df1168 pygar svn.69
[svn r69] runs separate eofs (I think)
author | punk |
---|---|
date | Wed, 12 May 2010 00:06:05 -0400 |
parents | cf8bb3038cbd |
children | 34fc182a1daa |
line wrap: on
line diff
1.1 --- a/modules/bluespec/Pygar/core/AudioCoreSystem.cpp Tue May 11 23:23:21 2010 -0400 1.2 +++ b/modules/bluespec/Pygar/core/AudioCoreSystem.cpp Wed May 12 00:06:05 2010 -0400 1.3 @@ -10,10 +10,13 @@ 1.4 1.5 using namespace std; 1.6 1.7 +#define NUM_VOICES 2 1.8 + 1.9 pthread_mutex_t CONNECTED_APPLICATION_CLASS::lock; 1.10 pthread_cond_t CONNECTED_APPLICATION_CLASS::cond; 1.11 sem_t CONNECTED_APPLICATION_CLASS::throttle; 1.12 1.13 + 1.14 // constructor 1.15 CONNECTED_APPLICATION_CLASS::CONNECTED_APPLICATION_CLASS(VIRTUAL_PLATFORM vp) : 1.16 1.17 @@ -72,6 +75,7 @@ 1.18 UINT16 sample; 1.19 UINT16 sample1; 1.20 1.21 + Bool fileFini[NUM_VOICES] = {false, false}; 1.22 //rlm: not sure if normal ints are ok here; using UINT16 because I know it works 1.23 UINT16 channel0 = 0; 1.24 UINT16 channel1 = 1; 1.25 @@ -80,7 +84,7 @@ 1.26 int sleepCount = 0; 1.27 int result = 0; 1.28 1.29 - bool coreFin = false; 1.30 + int numcCoreFin = 0; 1.31 1.32 printf("SendSide Main\n"); 1.33 fflush(stdout); 1.34 @@ -108,19 +112,9 @@ 1.35 1.36 //rlm: here we read both files. later refactor into a function. 1.37 // also, this will terminate when the FIRST file reaches its end. 1.38 - while( (fread(&sample, 2, 1, inputFile)) || (fread(&sample1, 2 , 1, inputFile1))) 1.39 - { /* 1.40 - printf("hi\n"); 1.41 - if (!coreFin && (result = clientStub->ReadCPUToHost(0)) != 1) 1.42 - { 1.43 - sleepCount++; 1.44 - } 1.45 - else if (!coreFin && result == 1) 1.46 - { 1.47 - printf("\n***SOFT_CORE PASSED***\n"); 1.48 - coreFin = true; 1.49 - } 1.50 - */ 1.51 + while( !feof(inputFile) || !feof(inputFile1)) 1.52 + { 1.53 + 1.54 sem_wait(&throttle); 1.55 1.56 if(count%1000 == 0) 1.57 @@ -128,22 +122,36 @@ 1.58 count++; 1.59 1.60 //rlm: two files. 1.61 - // clientStub->SendUnprocessedStream( Data,(UINT32)sample); 1.62 - clientStub->SendUnprocessedStream((UINT32)channel0 , Data,(UINT32)sample); 1.63 - clientStub->SendUnprocessedStream((UINT32)channel1 , Data,(UINT32)sample1); 1.64 - } 1.65 + 1.66 + if (!fileFini[0]) 1.67 + { 1.68 + if (fread(&sample, 2, 1, inputFile)) 1.69 + clientStub->SendUnprocessedStream((UINT32)channel0 , Data,(UINT32)sample); 1.70 + else{ 1.71 + fileFini[0] = true; 1.72 + numCoreFini++; 1.73 + if (numCoreFini >= NUM_VOICES) // Need lock on last eof 1.74 + // Need to put lock here to prevent potential race condition 1.75 + pthread_mutex_lock(&lock); 1.76 + clientStub->SendUnprocessedStream((UINT32)channel0, EndOfFile,0); 1.77 + } 1.78 + } 1.79 + if !fileFini[1]) 1.80 + { 1.81 + if (fread(&sample1, 2 , 1, inputFile1)) 1.82 + clientStub->SendUnprocessedStream((UINT32)channel1 , Data,(UINT32)sample1); 1.83 + else{ 1.84 + fileFini[1] = true; 1.85 + numCoreFini++; 1.86 + if (numCoreFini >= NUM_VOICES) // Need lock on last eof 1.87 + // Need to put lock here to prevent potential race condition 1.88 + pthread_mutex_lock(&lock); 1.89 + clientStub->SendUnprocessedStream((UINT32)channel1, EndOfFile,0); 1.90 + } 1.91 + } 1.92 + } 1.93 1.94 printf("main: out of loop\n"); 1.95 - 1.96 - // Need to put lock here to prevent potential race condition 1.97 - pthread_mutex_lock(&lock); 1.98 - 1.99 - //rlm: have to send end-files to both voices. 1.100 - // all of these operations wil eventually be moved into functions. 1.101 - //clientStub->SendUnprocessedStream(EndOfFile,0); 1.102 - clientStub->SendUnprocessedStream((UINT32)channel0, EndOfFile,0); 1.103 - clientStub->SendUnprocessedStream((UINT32)channel1, EndOfFile,0); 1.104 - 1.105 printf("main: wait for end of file\n"); 1.106 1.107 pthread_cond_wait(&cond, &lock);