comparison modules/bluespec/Pygar/core/AudioCoreSystem.cpp @ 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 34fc182a1daa
children
comparison
equal deleted inserted replaced
74:31fef269ae58 75:a15cc186e07d
20 // constructor 20 // constructor
21 CONNECTED_APPLICATION_CLASS::CONNECTED_APPLICATION_CLASS(VIRTUAL_PLATFORM vp) : 21 CONNECTED_APPLICATION_CLASS::CONNECTED_APPLICATION_CLASS(VIRTUAL_PLATFORM vp) :
22 22
23 clientStub(new AUDIOCORERRR_CLIENT_STUB_CLASS(this)) 23 clientStub(new AUDIOCORERRR_CLIENT_STUB_CLASS(this))
24 { 24 {
25 printf("SendSide Created\n"); 25 printf("SendSide Constructed\n");
26 } 26 }
27 27
28 // destructor 28 // destructor
29 CONNECTED_APPLICATION_CLASS::~CONNECTED_APPLICATION_CLASS() 29 CONNECTED_APPLICATION_CLASS::~CONNECTED_APPLICATION_CLASS()
30 { 30 {
63 pthread_mutex_unlock(&lock); 63 pthread_mutex_unlock(&lock);
64 printf("EndSimulation done\n"); 64 printf("EndSimulation done\n");
65 fflush(stdout); 65 fflush(stdout);
66 } 66 }
67 67
68 bool CONNECTED_APPLICATION_CLASS::areAllFilesComplete(int numVoices, bool isFini[])
69 {
70 bool result = false;
71 for (int n = 0; n < numVoices; n++)
72 result |= isFini[n];
73 return result;
74 }
75
68 // main 76 // main
69 void 77 void
70 CONNECTED_APPLICATION_CLASS::Main() 78 CONNECTED_APPLICATION_CLASS::Main()
71 { 79 {
80
72 //rlm: two files 81 //rlm: two files
73 FILE *inputFile; 82 FILE *inputFiles[NUM_VOICES];
74 FILE *inputFile1;
75 UINT16 sample; 83 UINT16 sample;
76 UINT16 sample1;
77 84
78 bool fileFini[NUM_VOICES]; 85 bool fileFini[NUM_VOICES];
86 UINT16 channel[NUM_VOICES];
79 for (int n = 0; n < NUM_VOICES; n++) 87 for (int n = 0; n < NUM_VOICES; n++)
80 fileFini[n] = false; 88 {
89 fileFini[n] = false;
90 channel[n] = n;
91 }
81 92
82 //rlm: not sure if normal ints are ok here; using UINT16 because I know it works 93 fflush(stdout);
83 UINT16 channel0 = 0; 94
84 UINT16 channel1 = 1; 95 // Convert input wav to pcm
96
97 printf("word!\n");
98
99 for (int i = 0; i < NUM_VOICES; i++)
100 {
101 char filename[256];
102 sprintf(filename, "input%d", i);
103 char wavname[256];
104 strcpy(wavname, filename);
105 strcat(wavname, ".wav");
106 char pcmname[256];
107 strcpy(pcmname, filename);
108 strcat(pcmname, ".pcm");
109
110 printf("Opening audio file %s and creating %s.\n", wavname, pcmname);
111 inputFiles[i] = fopen(wavname, "r");
112
113 generate_pcm(wavname, pcmname);
114
115 assert(inputFiles[i]);
116 }
85 117
86 //init processor 118 //init processor
87 int sleepCount = 0; 119 int sleepCount = 0;
88 int result = 0; 120 int result = 0;
121 int count = 0;
89 122
90 int numCoreFini = 0; 123 int numCoreFini = 0;
91 124
92 printf("SendSide Main\n"); 125 printf("SendSide Main\n");
93 fflush(stdout); 126 fflush(stdout);
94 127
95 // Convert input wav to pcm 128 // Convert input wav to pcm
96 129
97 //rlm: for now we are going to going to just have 2 files with "common names" 130 sleep(2);
98
99 generate_pcm("input.wav","input.pcm");
100 generate_pcm("input1.wav", "input1.pcm");
101
102
103 //Send data to the machine here.
104 //rlm: two files
105 inputFile = fopen("input.pcm","r");
106 inputFile1 = fopen("input1.pcm", "r");
107
108 assert(inputFile1);
109 assert(inputFile);
110
111 int count = 0;
112
113 sleep(1);
114 printf("main:samples about to start sending %d\n", count); 131 printf("main:samples about to start sending %d\n", count);
115 132
116 //rlm: here we read both files. later refactor into a function. 133 //rlm: here we read both files. later refactor into a function.
117 // also, this will terminate when the FIRST file reaches its end. 134 // also, this will terminate when the FIRST file reaches its end.
118 while( !feof(inputFile) || !feof(inputFile1)) 135 while(!areAllFilesComplete(NUM_VOICES, fileFini))
119 { 136 {
120
121 sem_wait(&throttle); 137 sem_wait(&throttle);
122 138
123 if(count%1000 == 0) 139 if(count%1000 == 0)
124 printf("main: %d\n", count); 140 printf("main: %d\n", count);
125 count++; 141 count++;
126 142
127 //rlm: two files. 143 //rlm: two files.
128 144 for (int i = 0; i < NUM_VOICES; i++)
129 if (!fileFini[0])
130 { 145 {
131 if (fread(&sample, 2, 1, inputFile)) 146 if (!fileFini[i])
132 clientStub->SendUnprocessedStream((UINT32)channel0 , Data,(UINT32)sample);
133 else{
134 fileFini[0] = true;
135 numCoreFini++;
136 if (numCoreFini >= NUM_VOICES) // Need lock on last eof
137 // Need to put lock here to prevent potential race condition
138 pthread_mutex_lock(&lock);
139 clientStub->SendUnprocessedStream((UINT32)channel0, EndOfFile,0);
140 }
141 }
142
143 if (!fileFini[1])
144 {
145 if (fread(&sample1, 2 , 1, inputFile1))
146 clientStub->SendUnprocessedStream((UINT32)channel1 , Data,(UINT32)sample1);
147 else
148 { 147 {
149 fileFini[1] = true; 148 if (fread(&sample, 2, 1, inputFiles[i]))
150 numCoreFini++; 149 clientStub->SendUnprocessedStream((UINT32)channel[i] , Data,(UINT32)sample);
151 if (numCoreFini >= NUM_VOICES) // Need lock on last eof 150 else{
152 // Need to put lock here to prevent potential race condition 151 fileFini[i] = true;
153 pthread_mutex_lock(&lock); 152 numCoreFini++;
154 clientStub->SendUnprocessedStream((UINT32)channel1, EndOfFile,0); 153 if (numCoreFini >= NUM_VOICES) // Need lock on last eof
154 // Need to put lock here to prevent potential race condition
155 pthread_mutex_lock(&lock);
156 clientStub->SendUnprocessedStream((UINT32)channel[i], EndOfFile,0);
157 }
155 } 158 }
156 } 159 }
157 } 160 }
158 161
159 printf("main: out of loop\n"); 162 printf("main: out of loop\n");
164 167
165 printf("main: last data out\n"); 168 printf("main: last data out\n");
166 169
167 // Convert input wav to pcm 170 // Convert input wav to pcm
168 // this part is ok because there is always only one input file. 171 // this part is ok because there is always only one input file.
169 generate_wav("out_hw.pcm","input.wav","out_hw.wav"); 172 generate_wav("out_hw.pcm","input0.wav","out_hw.wav");
170 173
171 printf("generate wav done\n"); 174 printf("generate wav done\n");
172 175
173 // printf("If you missed it, core %s", coreFin ? "PASSED\n" : "FAILED\n"); 176 // printf("If you missed it, core %s", coreFin ? "PASSED\n" : "FAILED\n");
174 // Dump the stats file 177 // Dump the stats file