view modules/bluespec/Pygar/core/AudioCoreSystem.cpp @ 67:0ede0715dbd6 pygar svn.68

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