comparison modules/bluespec/Pygar/core/AudioCoreSystem.cpp @ 34:1a21b4cd85ee pygar svn.35

[svn r35] fixed the perl scripts and c files to handle multiple voices
author rlm
date Tue, 04 May 2010 12:08:19 -0400
parents 0c775e733b81
children 99519a031813
comparison
equal deleted inserted replaced
33:2c8166d205d5 34:1a21b4cd85ee
60 60
61 // main 61 // main
62 void 62 void
63 CONNECTED_APPLICATION_CLASS::Main() 63 CONNECTED_APPLICATION_CLASS::Main()
64 { 64 {
65 //rlm: two files
65 FILE *inputFile; 66 FILE *inputFile;
67 FILE *inputFile1;
66 UINT16 sample; 68 UINT16 sample;
69 UINT16 sample1;
70
71 //rlm: not sure if normal ints are ok here; using UINT16 because I know it works
72 UINT16 channel0 = 0;
73 UINT16 channel1 = 1;
67 74
68 //init processor 75 //init processor
69 int sleepCount = 0; 76 int sleepCount = 0;
70 int result = 0; 77 int result = 0;
71 78
72 bool coreFin = false; 79 bool coreFin = false;
73 80
81
82
74 fflush(stdout); 83 fflush(stdout);
75 84
76 // Convert input wav to pcm 85 // Convert input wav to pcm
86
87
88 //rlm: for now we are going to going to just have 2 files with "common names"
89
77 generate_pcm("input.wav","input.pcm"); 90 generate_pcm("input.wav","input.pcm");
91 generate_pcm("input1.wav", "input1.pcm");
92
93
78 94
79 //Send data to the machine here. 95 //Send data to the machine here.
96 //rlm: two files
80 inputFile = fopen("input.pcm","r"); 97 inputFile = fopen("input.pcm","r");
98 inputFile = fopen("input1.pcm", "r");
99
100 assert(inputFile1);
81 assert(inputFile); 101 assert(inputFile);
82 102
83 int count = 0; 103 int count = 0;
84 104
85 printf("main:PROCESSOR about to enter loop %d\n", count); 105 printf("main:PROCESSOR about to enter loop %d\n", count);
86 106
87 while(fread(&sample, 2, 1, inputFile)) { 107 //rlm: here we read both files. later refactor into a function.
108 // also, this will terminate when the FIRST file reaches its end.
109 while( (fread(&sample, 2, 1, inputFile)) && (fread(&sample1, 2 , 1, inputFile1))) {
88 if (!coreFin && (result = clientStub->ReadCPUToHost(0)) != 1) 110 if (!coreFin && (result = clientStub->ReadCPUToHost(0)) != 1)
89 { 111 {
90 sleepCount++; 112 sleepCount++;
91 if(sleepCount == 200) { 113 if(sleepCount == 200) {
92 printf("Failed to get response from hardware, bailing\n\n"); 114 printf("Failed to get response from hardware, bailing\n\n");
105 127
106 if(count%1000 == 0) 128 if(count%1000 == 0)
107 printf("main: %d\n", count); 129 printf("main: %d\n", count);
108 count++; 130 count++;
109 sem_wait(&throttle); 131 sem_wait(&throttle);
110 // printf("rlm:sending data to processor (%d)\n", count); 132
111 clientStub->SendUnprocessedStream(Data,(UINT32)sample); 133 //rlm: two files.
134 clientStub->SendUnprocessedStream(channel0 , Data,(UINT32)sample);
135 clientStub->SendUnprocessedStream(channel1 , Data,(UINT32)sample1);
112 136
113 } 137 }
114 138
115 printf("main: out of loop\n"); 139 printf("main: out of loop\n");
116 140
117 // Need to put lock here to prevent potential race condition 141 // Need to put lock here to prevent potential race condition
118 pthread_mutex_lock(&lock); 142 pthread_mutex_lock(&lock);
119 clientStub->SendUnprocessedStream(EndOfFile,0); 143
144 //rlm: have to send end-files to both voices.
145 // all of these operations wil eventually be moved into functions.
146 clientStub->SendUnprocessedStream(channel0, EndOfFile,0);
147 clientStub->SendUnprocessedStream(channel1, EndOfFile,0);
120 148
121 printf("main: wait for end of file\n"); 149 printf("main: wait for end of file\n");
122 150
123 pthread_cond_wait(&cond, &lock); 151 pthread_cond_wait(&cond, &lock);
124 pthread_mutex_unlock(&lock); 152 pthread_mutex_unlock(&lock);
125 153
126 printf("main: last data out\n"); 154 printf("main: last data out\n");
127 155
128 // Convert input wav to pcm 156 // Convert input wav to pcm
157 // this part is ok because there is always only one input file.
129 generate_wav("out_hw.pcm","input.wav","out_hw.wav"); 158 generate_wav("out_hw.pcm","input.wav","out_hw.wav");
130 159
131 printf("generate wav done\n"); 160 printf("generate wav done\n");
132 161
133 printf("If you missed it, core %s", coreFin ? "PASSED\n" : "FAILED\n"); 162 printf("If you missed it, core %s", coreFin ? "PASSED\n" : "FAILED\n");