Mercurial > pygar
view modules/bluespec/Pygar/core/AudioCoreSystem.cpp @ 64:bf08daea854e pygar svn.65
[svn r65] compiles but doesn't run
author | punk |
---|---|
date | Mon, 10 May 2010 23:16:14 -0400 |
parents | b5be746a0d74 |
children | cf8bb3038cbd |
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 // constructor18 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 // destructor26 CONNECTED_APPLICATION_CLASS::~CONNECTED_APPLICATION_CLASS()27 {28 }30 // init31 void32 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, 64);40 // enable stats41 //STATS_DEVICE_SERVER_CLASS::GetInstance()->SetupStats();42 }44 //This isn't called.45 void46 CONNECTED_APPLICATION_CLASS::UpdateSemaphore()47 {48 printf("UpdateSemaphore\n");49 sem_post(&throttle);50 }52 void53 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 here59 pthread_cond_signal(&cond);60 pthread_mutex_unlock(&lock);61 printf("EndSimulation done\n");62 fflush(stdout);63 }65 // main66 void67 CONNECTED_APPLICATION_CLASS::Main()68 {69 //rlm: two files70 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 works76 UINT16 channel0 = 0;77 UINT16 channel1 = 1;79 //init processor80 int sleepCount = 0;81 int result = 0;83 bool coreFin = false;85 printf("SendSide Main\n");86 fflush(stdout);88 // Convert input wav to pcm90 //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 files98 inputFile = fopen("input.pcm","r");99 inputFile1 = fopen("input1.pcm", "r");101 assert(inputFile1);102 assert(inputFile);104 int count = 0;106 printf("main:samples about to start sending %d\n", count);108 //rlm: here we read both files. later refactor into a function.109 // also, this will terminate when the FIRST file reaches its end.110 while( (fread(&sample, 2, 1, inputFile)) || (fread(&sample1, 2 , 1, inputFile1)))111 { /*112 printf("hi\n");113 if (!coreFin && (result = clientStub->ReadCPUToHost(0)) != 1)114 {115 sleepCount++;116 }117 else if (!coreFin && result == 1)118 {119 printf("\n***SOFT_CORE PASSED***\n");120 coreFin = true;121 }122 */124 if(count%1000 == 0)125 printf("main: %d\n", count);126 count++;128 //rlm: two files.129 // clientStub->SendUnprocessedStream( Data,(UINT32)sample);130 clientStub->SendUnprocessedStream((UINT32)channel0 , Data,(UINT32)sample);131 clientStub->SendUnprocessedStream((UINT32)channel1 , Data,(UINT32)sample1);132 }134 printf("main: out of loop\n");136 // Need to put lock here to prevent potential race condition137 pthread_mutex_lock(&lock);139 //rlm: have to send end-files to both voices.140 // all of these operations wil eventually be moved into functions.141 //clientStub->SendUnprocessedStream(EndOfFile,0);142 clientStub->SendUnprocessedStream((UINT32)channel0, EndOfFile,0);143 clientStub->SendUnprocessedStream((UINT32)channel1, EndOfFile,0);145 printf("main: wait for end of file\n");147 pthread_cond_wait(&cond, &lock);148 pthread_mutex_unlock(&lock);150 printf("main: last data out\n");152 // Convert input wav to pcm153 // this part is ok because there is always only one input file.154 generate_wav("out_hw.pcm","input.wav","out_hw.wav");156 printf("generate wav done\n");158 // printf("If you missed it, core %s", coreFin ? "PASSED\n" : "FAILED\n");159 // Dump the stats file161 STATS_DEVICE_SERVER_CLASS::GetInstance()->DumpStats();162 STATS_DEVICE_SERVER_CLASS::GetInstance()->EmitFile();164 fflush(stdout);165 // exit(0);166 }