punk@13
|
1 #include <stdio.h>
|
punk@13
|
2 #include <pthread.h>
|
punk@13
|
3 #include <semaphore.h>
|
punk@13
|
4
|
punk@13
|
5 #include "asim/provides/connected_application.h"
|
punk@13
|
6 #include "asim/provides/stats_device.h"
|
punk@13
|
7 //#include "asim/provides/SndfileWavUtil.h"
|
punk@13
|
8
|
punk@13
|
9 #include "asim/rrr/client_stub_AUDIOCORERRR.h"
|
punk@13
|
10
|
punk@13
|
11 using namespace std;
|
punk@13
|
12
|
punk@13
|
13 pthread_mutex_t CONNECTED_APPLICATION_CLASS::lock;
|
punk@13
|
14 pthread_cond_t CONNECTED_APPLICATION_CLASS::cond;
|
punk@13
|
15 sem_t CONNECTED_APPLICATION_CLASS::throttle;
|
punk@13
|
16
|
punk@13
|
17 // constructor
|
punk@13
|
18 CONNECTED_APPLICATION_CLASS::CONNECTED_APPLICATION_CLASS(VIRTUAL_PLATFORM vp) :
|
rlm@23
|
19
|
rlm@23
|
20 clientStub(new AUDIOCORERRR_CLIENT_STUB_CLASS(this))
|
punk@13
|
21 {
|
punk@64
|
22 printf("SendSide Created\n");
|
punk@13
|
23 }
|
punk@13
|
24
|
punk@13
|
25 // destructor
|
punk@13
|
26 CONNECTED_APPLICATION_CLASS::~CONNECTED_APPLICATION_CLASS()
|
punk@13
|
27 {
|
punk@13
|
28 }
|
punk@13
|
29
|
punk@13
|
30 // init
|
punk@13
|
31 void
|
punk@13
|
32 CONNECTED_APPLICATION_CLASS::Init()
|
punk@13
|
33 {
|
punk@13
|
34
|
punk@64
|
35 printf("InitSend Side\n");
|
punk@13
|
36 pthread_mutex_init(&lock, NULL);
|
punk@13
|
37 pthread_cond_init(&cond, NULL);
|
punk@65
|
38 sem_init(&throttle, 0, 256);
|
punk@13
|
39
|
punk@13
|
40 // enable stats
|
punk@64
|
41 //STATS_DEVICE_SERVER_CLASS::GetInstance()->SetupStats();
|
punk@13
|
42 }
|
punk@13
|
43
|
punk@57
|
44 //This isn't called.
|
punk@13
|
45 void
|
punk@13
|
46 CONNECTED_APPLICATION_CLASS::UpdateSemaphore()
|
punk@13
|
47 {
|
punk@64
|
48 printf("UpdateSemaphore\n");
|
punk@13
|
49 sem_post(&throttle);
|
punk@13
|
50 }
|
punk@13
|
51
|
punk@13
|
52 void
|
punk@13
|
53 CONNECTED_APPLICATION_CLASS::EndSimulation()
|
punk@13
|
54 {
|
punk@13
|
55 printf("EndSimulation Called\n");
|
punk@13
|
56 fflush(stdout);
|
punk@13
|
57 pthread_mutex_lock(&lock);
|
punk@13
|
58 // Do something about the race occuring here
|
punk@13
|
59 pthread_cond_signal(&cond);
|
punk@13
|
60 pthread_mutex_unlock(&lock);
|
punk@13
|
61 printf("EndSimulation done\n");
|
punk@13
|
62 fflush(stdout);
|
punk@13
|
63 }
|
punk@13
|
64
|
punk@13
|
65 // main
|
punk@13
|
66 void
|
punk@13
|
67 CONNECTED_APPLICATION_CLASS::Main()
|
punk@13
|
68 {
|
rlm@34
|
69 //rlm: two files
|
punk@13
|
70 FILE *inputFile;
|
punk@52
|
71 FILE *inputFile1;
|
punk@13
|
72 UINT16 sample;
|
punk@52
|
73 UINT16 sample1;
|
rlm@34
|
74
|
rlm@34
|
75 //rlm: not sure if normal ints are ok here; using UINT16 because I know it works
|
punk@52
|
76 UINT16 channel0 = 0;
|
punk@52
|
77 UINT16 channel1 = 1;
|
punk@31
|
78
|
punk@31
|
79 //init processor
|
punk@31
|
80 int sleepCount = 0;
|
punk@31
|
81 int result = 0;
|
punk@31
|
82
|
punk@31
|
83 bool coreFin = false;
|
punk@31
|
84
|
punk@64
|
85 printf("SendSide Main\n");
|
punk@31
|
86 fflush(stdout);
|
punk@31
|
87
|
punk@13
|
88 // Convert input wav to pcm
|
rlm@34
|
89
|
rlm@34
|
90 //rlm: for now we are going to going to just have 2 files with "common names"
|
rlm@34
|
91
|
punk@13
|
92 generate_pcm("input.wav","input.pcm");
|
punk@52
|
93 generate_pcm("input1.wav", "input1.pcm");
|
rlm@34
|
94
|
punk@13
|
95
|
punk@13
|
96 //Send data to the machine here.
|
rlm@34
|
97 //rlm: two files
|
punk@13
|
98 inputFile = fopen("input.pcm","r");
|
punk@53
|
99 inputFile1 = fopen("input1.pcm", "r");
|
rlm@34
|
100
|
punk@52
|
101 assert(inputFile1);
|
punk@13
|
102 assert(inputFile);
|
punk@13
|
103
|
punk@13
|
104 int count = 0;
|
punk@13
|
105
|
punk@65
|
106 sleep(1);
|
punk@57
|
107 printf("main:samples about to start sending %d\n", count);
|
punk@13
|
108
|
rlm@34
|
109 //rlm: here we read both files. later refactor into a function.
|
rlm@34
|
110 // also, this will terminate when the FIRST file reaches its end.
|
punk@52
|
111 while( (fread(&sample, 2, 1, inputFile)) || (fread(&sample1, 2 , 1, inputFile1)))
|
punk@39
|
112 { /*
|
punk@37
|
113 printf("hi\n");
|
punk@37
|
114 if (!coreFin && (result = clientStub->ReadCPUToHost(0)) != 1)
|
punk@37
|
115 {
|
punk@37
|
116 sleepCount++;
|
punk@37
|
117 }
|
punk@37
|
118 else if (!coreFin && result == 1)
|
punk@37
|
119 {
|
punk@37
|
120 printf("\n***SOFT_CORE PASSED***\n");
|
punk@37
|
121 coreFin = true;
|
punk@37
|
122 }
|
punk@39
|
123 */
|
punk@65
|
124 sem_wait(&throttle);
|
punk@65
|
125
|
punk@37
|
126 if(count%1000 == 0)
|
punk@37
|
127 printf("main: %d\n", count);
|
punk@37
|
128 count++;
|
punk@37
|
129
|
rlm@34
|
130 //rlm: two files.
|
rlm@41
|
131 // clientStub->SendUnprocessedStream( Data,(UINT32)sample);
|
punk@52
|
132 clientStub->SendUnprocessedStream((UINT32)channel0 , Data,(UINT32)sample);
|
punk@52
|
133 clientStub->SendUnprocessedStream((UINT32)channel1 , Data,(UINT32)sample1);
|
punk@13
|
134 }
|
punk@13
|
135
|
punk@13
|
136 printf("main: out of loop\n");
|
punk@13
|
137
|
punk@13
|
138 // Need to put lock here to prevent potential race condition
|
punk@13
|
139 pthread_mutex_lock(&lock);
|
rlm@34
|
140
|
rlm@34
|
141 //rlm: have to send end-files to both voices.
|
rlm@34
|
142 // all of these operations wil eventually be moved into functions.
|
rlm@41
|
143 //clientStub->SendUnprocessedStream(EndOfFile,0);
|
rlm@41
|
144 clientStub->SendUnprocessedStream((UINT32)channel0, EndOfFile,0);
|
punk@52
|
145 clientStub->SendUnprocessedStream((UINT32)channel1, EndOfFile,0);
|
punk@13
|
146
|
punk@13
|
147 printf("main: wait for end of file\n");
|
punk@13
|
148
|
punk@13
|
149 pthread_cond_wait(&cond, &lock);
|
punk@13
|
150 pthread_mutex_unlock(&lock);
|
punk@13
|
151
|
rlm@23
|
152 printf("main: last data out\n");
|
punk@13
|
153
|
punk@13
|
154 // Convert input wav to pcm
|
rlm@34
|
155 // this part is ok because there is always only one input file.
|
punk@13
|
156 generate_wav("out_hw.pcm","input.wav","out_hw.wav");
|
punk@13
|
157
|
punk@13
|
158 printf("generate wav done\n");
|
punk@13
|
159
|
punk@50
|
160 // printf("If you missed it, core %s", coreFin ? "PASSED\n" : "FAILED\n");
|
punk@13
|
161 // Dump the stats file
|
punk@13
|
162
|
punk@13
|
163 STATS_DEVICE_SERVER_CLASS::GetInstance()->DumpStats();
|
punk@13
|
164 STATS_DEVICE_SERVER_CLASS::GetInstance()->EmitFile();
|
punk@13
|
165
|
punk@31
|
166 fflush(stdout);
|
punk@53
|
167 // exit(0);
|
punk@31
|
168 }
|