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/SndfileWavUtil.h" | |
7 | |
8 #include "asim/rrr/client_stub_AUDIOPROCESSORRRR.h" | |
9 | |
10 using namespace std; | |
11 | |
12 pthread_mutex_t CONNECTED_APPLICATION_CLASS::lock; | |
13 pthread_cond_t CONNECTED_APPLICATION_CLASS::cond; | |
14 sem_t CONNECTED_APPLICATION_CLASS::throttle; | |
15 | |
16 // constructor | |
17 CONNECTED_APPLICATION_CLASS::CONNECTED_APPLICATION_CLASS(VIRTUAL_PLATFORM vp) : | |
18 clientStub(new AUDIOPROCESSORRRR_CLIENT_STUB_CLASS(this)) | |
19 { | |
20 } | |
21 | |
22 // destructor | |
23 CONNECTED_APPLICATION_CLASS::~CONNECTED_APPLICATION_CLASS() | |
24 { | |
25 } | |
26 | |
27 // init | |
28 void | |
29 CONNECTED_APPLICATION_CLASS::Init() | |
30 { | |
31 | |
32 pthread_mutex_init(&lock, NULL); | |
33 pthread_cond_init(&cond, NULL); | |
34 sem_init(&throttle, 0, 64); | |
35 | |
36 } | |
37 | |
38 void | |
39 CONNECTED_APPLICATION_CLASS::UpdateSemaphore() | |
40 { | |
41 sem_post(&throttle); | |
42 } | |
43 | |
44 void | |
45 CONNECTED_APPLICATION_CLASS::EndSimulation() | |
46 { | |
47 printf("EndSimulation Called\n"); | |
48 fflush(stdout); | |
49 pthread_mutex_lock(&lock); | |
50 // Do something about the race occuring here | |
51 pthread_cond_signal(&cond); | |
52 pthread_mutex_unlock(&lock); | |
53 printf("EndSimulation done\n"); | |
54 fflush(stdout); | |
55 } | |
56 | |
57 // main | |
58 void | |
59 CONNECTED_APPLICATION_CLASS::Main() | |
60 { | |
61 FILE *inputFile; | |
62 UINT16 sample; | |
63 | |
64 // Convert input wav to pcm | |
65 generate_pcm("input.wav","input.pcm"); | |
66 | |
67 //Send data to the machine here. | |
68 inputFile = fopen("input.pcm","r"); | |
69 assert(inputFile); | |
70 | |
71 | |
72 int count = 0; | |
73 | |
74 printf("main: about to enter loop %d\n", count); | |
75 | |
76 while(fread(&sample, 2, 1, inputFile)) { | |
77 if(count%1000 == 0) | |
78 printf("main: %d\n", count); | |
79 count++; | |
80 sem_wait(&throttle); | |
81 clientStub->SendUnprocessedStream(Data,(UINT32)sample); | |
82 } | |
83 | |
84 printf("main: out of loop\n"); | |
85 | |
86 // Need to put lock here to prevent potential race condition | |
87 pthread_mutex_lock(&lock); | |
88 clientStub->SendUnprocessedStream(EndOfFile,0); | |
89 | |
90 printf("main: wait for end of file\n"); | |
91 | |
92 pthread_cond_wait(&cond, &lock); | |
93 pthread_mutex_unlock(&lock); | |
94 | |
95 printf("main: lastt data out\n"); | |
96 | |
97 // Convert input wav to pcm | |
98 generate_wav("out_hw.pcm","input.wav","out_hw.wav"); | |
99 | |
100 printf("generate wav done\n"); | |
101 | |
102 fflush(stdout); | |
103 exit(0); | |
104 } |