Mercurial > pygar
comparison 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 |
comparison
equal
deleted
inserted
replaced
67:0ede0715dbd6 | 68:44cc00df1168 |
---|---|
8 | 8 |
9 #include "asim/rrr/client_stub_AUDIOCORERRR.h" | 9 #include "asim/rrr/client_stub_AUDIOCORERRR.h" |
10 | 10 |
11 using namespace std; | 11 using namespace std; |
12 | 12 |
13 #define NUM_VOICES 2 | |
14 | |
13 pthread_mutex_t CONNECTED_APPLICATION_CLASS::lock; | 15 pthread_mutex_t CONNECTED_APPLICATION_CLASS::lock; |
14 pthread_cond_t CONNECTED_APPLICATION_CLASS::cond; | 16 pthread_cond_t CONNECTED_APPLICATION_CLASS::cond; |
15 sem_t CONNECTED_APPLICATION_CLASS::throttle; | 17 sem_t CONNECTED_APPLICATION_CLASS::throttle; |
18 | |
16 | 19 |
17 // constructor | 20 // constructor |
18 CONNECTED_APPLICATION_CLASS::CONNECTED_APPLICATION_CLASS(VIRTUAL_PLATFORM vp) : | 21 CONNECTED_APPLICATION_CLASS::CONNECTED_APPLICATION_CLASS(VIRTUAL_PLATFORM vp) : |
19 | 22 |
20 clientStub(new AUDIOCORERRR_CLIENT_STUB_CLASS(this)) | 23 clientStub(new AUDIOCORERRR_CLIENT_STUB_CLASS(this)) |
70 FILE *inputFile; | 73 FILE *inputFile; |
71 FILE *inputFile1; | 74 FILE *inputFile1; |
72 UINT16 sample; | 75 UINT16 sample; |
73 UINT16 sample1; | 76 UINT16 sample1; |
74 | 77 |
78 Bool fileFini[NUM_VOICES] = {false, false}; | |
75 //rlm: not sure if normal ints are ok here; using UINT16 because I know it works | 79 //rlm: not sure if normal ints are ok here; using UINT16 because I know it works |
76 UINT16 channel0 = 0; | 80 UINT16 channel0 = 0; |
77 UINT16 channel1 = 1; | 81 UINT16 channel1 = 1; |
78 | 82 |
79 //init processor | 83 //init processor |
80 int sleepCount = 0; | 84 int sleepCount = 0; |
81 int result = 0; | 85 int result = 0; |
82 | 86 |
83 bool coreFin = false; | 87 int numcCoreFin = 0; |
84 | 88 |
85 printf("SendSide Main\n"); | 89 printf("SendSide Main\n"); |
86 fflush(stdout); | 90 fflush(stdout); |
87 | 91 |
88 // Convert input wav to pcm | 92 // Convert input wav to pcm |
106 sleep(1); | 110 sleep(1); |
107 printf("main:samples about to start sending %d\n", count); | 111 printf("main:samples about to start sending %d\n", count); |
108 | 112 |
109 //rlm: here we read both files. later refactor into a function. | 113 //rlm: here we read both files. later refactor into a function. |
110 // also, this will terminate when the FIRST file reaches its end. | 114 // also, this will terminate when the FIRST file reaches its end. |
111 while( (fread(&sample, 2, 1, inputFile)) || (fread(&sample1, 2 , 1, inputFile1))) | 115 while( !feof(inputFile) || !feof(inputFile1)) |
112 { /* | 116 { |
113 printf("hi\n"); | 117 |
114 if (!coreFin && (result = clientStub->ReadCPUToHost(0)) != 1) | |
115 { | |
116 sleepCount++; | |
117 } | |
118 else if (!coreFin && result == 1) | |
119 { | |
120 printf("\n***SOFT_CORE PASSED***\n"); | |
121 coreFin = true; | |
122 } | |
123 */ | |
124 sem_wait(&throttle); | 118 sem_wait(&throttle); |
125 | 119 |
126 if(count%1000 == 0) | 120 if(count%1000 == 0) |
127 printf("main: %d\n", count); | 121 printf("main: %d\n", count); |
128 count++; | 122 count++; |
129 | 123 |
130 //rlm: two files. | 124 //rlm: two files. |
131 // clientStub->SendUnprocessedStream( Data,(UINT32)sample); | 125 |
132 clientStub->SendUnprocessedStream((UINT32)channel0 , Data,(UINT32)sample); | 126 if (!fileFini[0]) |
133 clientStub->SendUnprocessedStream((UINT32)channel1 , Data,(UINT32)sample1); | 127 { |
134 } | 128 if (fread(&sample, 2, 1, inputFile)) |
129 clientStub->SendUnprocessedStream((UINT32)channel0 , Data,(UINT32)sample); | |
130 else{ | |
131 fileFini[0] = true; | |
132 numCoreFini++; | |
133 if (numCoreFini >= NUM_VOICES) // Need lock on last eof | |
134 // Need to put lock here to prevent potential race condition | |
135 pthread_mutex_lock(&lock); | |
136 clientStub->SendUnprocessedStream((UINT32)channel0, EndOfFile,0); | |
137 } | |
138 } | |
139 if !fileFini[1]) | |
140 { | |
141 if (fread(&sample1, 2 , 1, inputFile1)) | |
142 clientStub->SendUnprocessedStream((UINT32)channel1 , Data,(UINT32)sample1); | |
143 else{ | |
144 fileFini[1] = true; | |
145 numCoreFini++; | |
146 if (numCoreFini >= NUM_VOICES) // Need lock on last eof | |
147 // Need to put lock here to prevent potential race condition | |
148 pthread_mutex_lock(&lock); | |
149 clientStub->SendUnprocessedStream((UINT32)channel1, EndOfFile,0); | |
150 } | |
151 } | |
152 } | |
135 | 153 |
136 printf("main: out of loop\n"); | 154 printf("main: out of loop\n"); |
137 | |
138 // Need to put lock here to prevent potential race condition | |
139 pthread_mutex_lock(&lock); | |
140 | |
141 //rlm: have to send end-files to both voices. | |
142 // all of these operations wil eventually be moved into functions. | |
143 //clientStub->SendUnprocessedStream(EndOfFile,0); | |
144 clientStub->SendUnprocessedStream((UINT32)channel0, EndOfFile,0); | |
145 clientStub->SendUnprocessedStream((UINT32)channel1, EndOfFile,0); | |
146 | |
147 printf("main: wait for end of file\n"); | 155 printf("main: wait for end of file\n"); |
148 | 156 |
149 pthread_cond_wait(&cond, &lock); | 157 pthread_cond_wait(&cond, &lock); |
150 pthread_mutex_unlock(&lock); | 158 pthread_mutex_unlock(&lock); |
151 | 159 |