Mercurial > pygar
comparison modules/bluespec/Pygar/core/#AudioCoreSystem.cpp# @ 13:6d461680c6d9 pygar svn.14
[svn r14] more stuff
author | punk |
---|---|
date | Tue, 27 Apr 2010 09:03:28 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
12:394aa40fd812 | 13:6d461680c6d9 |
---|---|
1 #include <stdio.h> | |
2 #include <pthread.h> | |
3 #include <semaphore.h> | |
4 | |
5 #include "asim/provides/connected_application.h" | |
6 #include "asim/provides/stats_device.h" | |
7 //#include "asim/provides/SndfileWavUtil.h" | |
8 | |
9 //#include "asim/rrr/client_stub_AUDIOCORERRR.h" | |
10 | |
11 using namespace std; | |
12 | |
13 pthread_mutex_t CONNECTED_APPLICATION_CLASS::lock; | |
14 pthread_cond_t CONNECTED_APPLICATION_CLASS::cond; | |
15 sem_t CONNECTED_APPLICATION_CLASS::throttle; | |
16 | |
17 // constructor | |
18 CONNECTED_APPLICATION_CLASS::CONNECTED_APPLICATION_CLASS(VIRTUAL_PLATFORM vp) : | |
19 clientStub(new AUDIOCORERRR_CLIENT_STUB_CLASS(this)) | |
20 { | |
21 } | |
22 | |
23 // destructor | |
24 CONNECTED_APPLICATION_CLASS::~CONNECTED_APPLICATION_CLASS() | |
25 { | |
26 } | |
27 | |
28 // init | |
29 void | |
30 CONNECTED_APPLICATION_CLASS::Init() | |
31 { | |
32 | |
33 pthread_mutex_init(&lock, NULL); | |
34 pthread_cond_init(&cond, NULL); | |
35 sem_init(&throttle, 0, 64); | |
36 | |
37 // enable stats | |
38 STATS_DEVICE_SERVER_CLASS::GetInstance()->SetupStats(); | |
39 } | |
40 | |
41 void | |
42 CONNECTED_APPLICATION_CLASS::UpdateSemaphore() | |
43 { | |
44 sem_post(&throttle); | |
45 } | |
46 | |
47 void | |
48 CONNECTED_APPLICATION_CLASS::EndSimulation() | |
49 { | |
50 printf("EndSimulation Called\n"); | |
51 fflush(stdout); | |
52 pthread_mutex_lock(&lock); | |
53 // Do something about the race occuring here | |
54 pthread_cond_signal(&cond); | |
55 pthread_mutex_unlock(&lock); | |
56 printf("EndSimulation done\n"); | |
57 fflush(stdout); | |
58 } | |
59 | |
60 // main | |
61 void | |
62 CONNECTED_APPLICATION_CLASS::Main() | |
63 { | |
64 FILE *inputFile; | |
65 UINT16 sample; | |
66 | |
67 // Convert input wav to pcm | |
68 generate_pcm("input.wav","input.pcm"); | |
69 | |
70 //Send data to the machine here. | |
71 inputFile = fopen("input.pcm","r"); | |
72 assert(inputFile); | |
73 | |
74 | |
75 int count = 0; | |
76 | |
77 printf("main: about to enter loop %d\n", count); | |
78 | |
79 while(fread(&sample, 2, 1, inputFile)) { | |
80 if(count%1000 == 0) | |
81 printf("main: %d\n", count); | |
82 count++; | |
83 sem_wait(&throttle); | |
84 clientStub->SendUnprocessedStream(Data,(UINT32)sample); | |
85 } | |
86 | |
87 printf("main: out of loop\n"); | |
88 | |
89 // Need to put lock here to prevent potential race condition | |
90 pthread_mutex_lock(&lock); | |
91 clientStub->SendUnprocessedStream(EndOfFile,0); | |
92 | |
93 printf("main: wait for end of file\n"); | |
94 | |
95 pthread_cond_wait(&cond, &lock); | |
96 pthread_mutex_unlock(&lock); | |
97 | |
98 printf("main: lastt data out\n"); | |
99 | |
100 // Convert input wav to pcm | |
101 generate_wav("out_hw.pcm","input.wav","out_hw.wav"); | |
102 | |
103 printf("generate wav done\n"); | |
104 | |
105 fflush(stdout); | |
106 exit(0); | |
107 } | |
108 | |
109 /* THIS IS THE CODE HANDLING FROM THE REGULAR SOFT-CORE | |
110 TO BE INCORPORATED | |
111 // main | |
112 void | |
113 CONNECTED_APPLICATION_CLASS::Main() | |
114 { | |
115 int sleepCount = 0; | |
116 int result = 0; | |
117 | |
118 fflush(stdout); | |
119 | |
120 while ((result = clientStub->ReadCPUToHost(0)) != 1) { | |
121 sleep(1); | |
122 //printf("System controller sleeps with result: %d\n", result); | |
123 sleepCount++; | |
124 if(sleepCount == 100) { | |
125 printf("Failed to get response from hardware, bailing\n\n"); | |
126 printf("This means that either your hardware is hanging\n"); | |
127 printf("or that the software hasn't given it enough time\n"); | |
128 printf("to complete. If you think it needs more time, then\n"); | |
129 printf("edit CONNECTED_APPLICATION_CLASS::Main() in ProcessorSystem.cpp\n"); | |
130 printf("(connected_application)\n"); | |
131 exit(0); | |
132 } | |
133 } | |
134 | |
135 if(result == 1) { | |
136 printf("\n***PASSED***\n"); | |
137 } | |
138 | |
139 // Dump the stats file | |
140 | |
141 STATS_DEVICE_SERVER_CLASS::GetInstance()->DumpStats(); | |
142 STATS_DEVICE_SERVER_CLASS::GetInstance()->EmitFile(); | |
143 | |
144 fflush(stdout); | |
145 exit(0); | |
146 }*/ |