comparison modules/bluespec/Pygar/core/AudioCoreSystem.cpp @ 72:34fc182a1daa pygar svn.73

[svn r73] fixed bad code
author punk
date Wed, 12 May 2010 00:40:01 -0400
parents 44cc00df1168
children a15cc186e07d
comparison
equal deleted inserted replaced
71:86360c5ae9f2 72:34fc182a1daa
73 FILE *inputFile; 73 FILE *inputFile;
74 FILE *inputFile1; 74 FILE *inputFile1;
75 UINT16 sample; 75 UINT16 sample;
76 UINT16 sample1; 76 UINT16 sample1;
77 77
78 Bool fileFini[NUM_VOICES] = {false, false}; 78 bool fileFini[NUM_VOICES];
79 for (int n = 0; n < NUM_VOICES; n++)
80 fileFini[n] = false;
81
79 //rlm: not sure if normal ints are ok here; using UINT16 because I know it works 82 //rlm: not sure if normal ints are ok here; using UINT16 because I know it works
80 UINT16 channel0 = 0; 83 UINT16 channel0 = 0;
81 UINT16 channel1 = 1; 84 UINT16 channel1 = 1;
82 85
83 //init processor 86 //init processor
84 int sleepCount = 0; 87 int sleepCount = 0;
85 int result = 0; 88 int result = 0;
86 89
87 int numcCoreFin = 0; 90 int numCoreFini = 0;
88 91
89 printf("SendSide Main\n"); 92 printf("SendSide Main\n");
90 fflush(stdout); 93 fflush(stdout);
91 94
92 // Convert input wav to pcm 95 // Convert input wav to pcm
111 printf("main:samples about to start sending %d\n", count); 114 printf("main:samples about to start sending %d\n", count);
112 115
113 //rlm: here we read both files. later refactor into a function. 116 //rlm: here we read both files. later refactor into a function.
114 // also, this will terminate when the FIRST file reaches its end. 117 // also, this will terminate when the FIRST file reaches its end.
115 while( !feof(inputFile) || !feof(inputFile1)) 118 while( !feof(inputFile) || !feof(inputFile1))
116 { 119 {
117 120
118 sem_wait(&throttle); 121 sem_wait(&throttle);
119 122
120 if(count%1000 == 0) 123 if(count%1000 == 0)
121 printf("main: %d\n", count); 124 printf("main: %d\n", count);
122 count++; 125 count++;
134 // Need to put lock here to prevent potential race condition 137 // Need to put lock here to prevent potential race condition
135 pthread_mutex_lock(&lock); 138 pthread_mutex_lock(&lock);
136 clientStub->SendUnprocessedStream((UINT32)channel0, EndOfFile,0); 139 clientStub->SendUnprocessedStream((UINT32)channel0, EndOfFile,0);
137 } 140 }
138 } 141 }
139 if !fileFini[1]) 142
143 if (!fileFini[1])
140 { 144 {
141 if (fread(&sample1, 2 , 1, inputFile1)) 145 if (fread(&sample1, 2 , 1, inputFile1))
142 clientStub->SendUnprocessedStream((UINT32)channel1 , Data,(UINT32)sample1); 146 clientStub->SendUnprocessedStream((UINT32)channel1 , Data,(UINT32)sample1);
143 else{ 147 else
148 {
144 fileFini[1] = true; 149 fileFini[1] = true;
145 numCoreFini++; 150 numCoreFini++;
146 if (numCoreFini >= NUM_VOICES) // Need lock on last eof 151 if (numCoreFini >= NUM_VOICES) // Need lock on last eof
147 // Need to put lock here to prevent potential race condition 152 // Need to put lock here to prevent potential race condition
148 pthread_mutex_lock(&lock); 153 pthread_mutex_lock(&lock);
149 clientStub->SendUnprocessedStream((UINT32)channel1, EndOfFile,0); 154 clientStub->SendUnprocessedStream((UINT32)channel1, EndOfFile,0);
150 } 155 }
151 } 156 }
152 } 157 }
153 158
154 printf("main: out of loop\n"); 159 printf("main: out of loop\n");
155 printf("main: wait for end of file\n"); 160 printf("main: wait for end of file\n");
156 161
157 pthread_cond_wait(&cond, &lock); 162 pthread_cond_wait(&cond, &lock);