# HG changeset patch # User punk # Date 1272423290 14400 # Node ID 7e1510b4733687e0166bfcb881f374ecfad3944d # Parent a1833d9f6e3d18f3cbaca90ba9d071e7afe905d0 [svn r17] added rest of items for core diff -r a1833d9f6e3d -r 7e1510b47336 #AudioProcessor.cpp# --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/#AudioProcessor.cpp# Tue Apr 27 22:54:50 2010 -0400 @@ -0,0 +1,104 @@ +#include +#include +#include + +#include "asim/provides/connected_application.h" +//#include "asim/provides/SndfileWavUtil.h" + +#include "asim/rrr/client_stub_AUDIOPROCESSORRRR.h" + +using namespace std; + +pthread_mutex_t CONNECTED_APPLICATION_CLASS::lock; +pthread_cond_t CONNECTED_APPLICATION_CLASS::cond; +sem_t CONNECTED_APPLICATION_CLASS::throttle; + +// constructor +CONNECTED_APPLICATION_CLASS::CONNECTED_APPLICATION_CLASS(VIRTUAL_PLATFORM vp) : + clientStub(new AUDIOPROCESSORRRR_CLIENT_STUB_CLASS(this)) +{ +œôøº} +œôøºœôøºœôøº +// destructor +CONNECTED_APPLICATION_CLASS::~CONNECTED_APPLICATION_CLASS() +{ +} + +// init +void +CONNECTED_APPLICATION_CLASS::Init() +{ + + pthread_mutex_init(&lock, NULL); + pthread_cond_init(&cond, NULL); + sem_init(&throttle, 0, 64); + +} + +void +CONNECTED_APPLICATION_CLASS::UpdateSemaphore() +{ + sem_post(&throttle); +} + +void +CONNECTED_APPLICATION_CLASS::EndSimulation() +{ + printf("EndSimulation Called\n"); + fflush(stdout); + pthread_mutex_lock(&lock); + // Do something about the race occuring here + pthread_cond_signal(&cond); + pthread_mutex_unlock(&lock); + printf("EndSimulation done\n"); + fflush(stdout); +} + +// main +void +CONNECTED_APPLICATION_CLASS::Main() +{ + FILE *inputFile; + UINT16 sample; + + // Convert input wav to pcm + generate_pcm("input.wav","input.pcm"); + + //Send data to the machine here. + inputFile = fopen("input.pcm","r"); + assert(inputFile); + + + int count = 0; + + printf("main: about to enter loop %d\n", count); + + while(fread(&sample, 2, 1, inputFile)) { + if(count%1000 == 0) + printf("main: %d\n", count); + count++; + sem_wait(&throttle); + clientStub->SendUnprocessedStream(Data,(UINT32)sample); + } + + printf("main: out of loop\n"); + + // Need to put lock here to prevent potential race condition + pthread_mutex_lock(&lock); + clientStub->SendUnprocessedStream(EndOfFile,0); + + printf("main: wait for end of file\n"); + + pthread_cond_wait(&cond, &lock); + pthread_mutex_unlock(&lock); + + printf("main: lastt data out\n"); + + // Convert input wav to pcm + generate_wav("out_hw.pcm","input.wav","out_hw.wav"); + + printf("generate wav done\n"); + + fflush(stdout); + exit(0); +} diff -r a1833d9f6e3d -r 7e1510b47336 #AudioProcessorRRR.rrr# --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/#AudioProcessorRRR.rrr# Tue Apr 27 22:54:50 2010 -0400 @@ -0,0 +1,14 @@ +service AUDIOPROCESSORRRR +{ + server sw (cpp, method) <- hw (bsv, connection) + { + method SendProcessedStream (in UINT32[32] ctrl, in UINT32[32] sample); + }; + + server hw (bsv, connection) <- sw (cpp, method) + { + method SendUnprocessedStream (in UINT32[32] ctrl, in UINT32[32] sample); + }; + + + }; diff -r a1833d9f6e3d -r 7e1510b47336 #AudioProcessorTypes.bsv# --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/#AudioProcessorTypes.bsv# Tue Apr 27 22:54:50 2010 -0400 @@ -0,0 +1,52 @@ + +// The MIT License + +// Copyright (c) 2009 Massachusetts Institute of Technology + +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: + +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. + +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +// Author: Kermin Fleming kfleming@mit.edu + +import Connectable::*; +import GetPut::*; +import ClientServer::*; + +typedef Int#(16) Sample; + +typedef enum { + EndOfFile = 0, + Data = 1 +} AudioProcessorControl deriving (Bits,Eq); + + +typedef struct { + Sample left; + Sample right; +} StereoSample deriving (Bits,Eq); + +typedef union tagged{ + Sample Sample; + void EndOfFile; +} AudioProcessorUnit deriving (Bits,Eq); + +interface AudioPipeline; + interface Put#(AudioProcessorUnit) sampleInput; + interface Get#(AudioProcessorUnit) sampleOutput; +endinterface + diff -r a1833d9f6e3d -r 7e1510b47336 AudioPipelineDefault.bsv --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/AudioPipelineDefault.bsv Tue Apr 27 22:54:50 2010 -0400 @@ -0,0 +1,38 @@ +// The MIT License + +// Copyright (c) 2009 Massachusetts Institute of Technology + +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: + +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. + +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +// Author: Kermin Fleming kfleming@mit.edu + +import Connectable::*; +import GetPut::*; +import ClientServer::*; +import FIFO::*; + +`include "asim/provides/audio_processor_types.bsh" + +module mkAudioPipeline (AudioPipeline); + FIFO#(AudioProcessorUnit) fifo <- mkFIFO; + + interface sampleInput = fifoToPut(fifo); + interface sampleOutput = fifoToGet(fifo); + +endmodule diff -r a1833d9f6e3d -r 7e1510b47336 AudioProcessor.bsv --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/AudioProcessor.bsv Tue Apr 27 22:54:50 2010 -0400 @@ -0,0 +1,77 @@ +// The MIT License + +// Copyright (c) 2009 Massachusetts Institute of Technology + +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: + +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. + +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +import Connectable::*; +import GetPut::*; +import ClientServer::*; + +//AWB includes +`include "asim/provides/low_level_platform_interface.bsh" +`include "asim/provides/soft_connections.bsh" +`include "asim/provides/common_services.bsh" + +// Local includes +`include "asim/provides/audio_processor_types.bsh" +`include "asim/provides/audio_pipeline.bsh" + +`include "asim/rrr/remote_client_stub_AUDIOPROCESSORRRR.bsh" +`include "asim/rrr/remote_server_stub_AUDIOPROCESSORRRR.bsh" + + +module [CONNECTED_MODULE] mkConnectedApplication (); + + // Instantiate the rrr stubs + ClientStub_AUDIOPROCESSORRRR client_stub <- mkClientStub_AUDIOPROCESSORRRR(); + ServerStub_AUDIOPROCESSORRRR server_stub <- mkServerStub_AUDIOPROCESSORRRR(); + + // Instantiate the audio pipeline + AudioPipeline pipeline <- mkAudioPipeline(); + + rule feedInput; + let command <- server_stub.acceptRequest_SendUnprocessedStream(); + AudioProcessorControl ctrl = unpack(truncate(command.ctrl)); + + if(ctrl == EndOfFile) + begin + pipeline.sampleInput.put(tagged EndOfFile); + end + else + begin + pipeline.sampleInput.put(tagged Sample unpack(truncate(command.sample))); + end + endrule + + rule feedOutput; + let pipelineData <- pipeline.sampleOutput.get(); + AudioProcessorControl endOfFileTag = EndOfFile; + AudioProcessorControl sampleTag = Data; + + case (pipelineData) matches + tagged EndOfFile: client_stub.makeRequest_SendProcessedStream(zeroExtend(pack(endOfFileTag)),?); + tagged Sample .sample:client_stub.makeRequest_SendProcessedStream(zeroExtend(pack(sampleTag)), + zeroExtend(pack(sample))); + endcase + endrule + +endmodule + + diff -r a1833d9f6e3d -r 7e1510b47336 AudioProcessor.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/AudioProcessor.cpp Tue Apr 27 22:54:50 2010 -0400 @@ -0,0 +1,104 @@ +#include +#include +#include + +#include "asim/provides/connected_application.h" +//#include "asim/provides/SndfileWavUtil.h" + +#include "asim/rrr/client_stub_AUDIOPROCESSORRRR.h" + +using namespace std; + +pthread_mutex_t CONNECTED_APPLICATION_CLASS::lock; +pthread_cond_t CONNECTED_APPLICATION_CLASS::cond; +sem_t CONNECTED_APPLICATION_CLASS::throttle; + +// constructor +CONNECTED_APPLICATION_CLASS::CONNECTED_APPLICATION_CLASS(VIRTUAL_PLATFORM vp) : + clientStub(new AUDIOPROCESSORRRR_CLIENT_STUB_CLASS(this)) +{ +} + +// destructor +CONNECTED_APPLICATION_CLASS::~CONNECTED_APPLICATION_CLASS() +{ +} + +// init +void +CONNECTED_APPLICATION_CLASS::Init() +{ + + pthread_mutex_init(&lock, NULL); + pthread_cond_init(&cond, NULL); + sem_init(&throttle, 0, 64); + +} + +void +CONNECTED_APPLICATION_CLASS::UpdateSemaphore() +{ + sem_post(&throttle); +} + +void +CONNECTED_APPLICATION_CLASS::EndSimulation() +{ + printf("EndSimulation Called\n"); + fflush(stdout); + pthread_mutex_lock(&lock); + // Do something about the race occuring here + pthread_cond_signal(&cond); + pthread_mutex_unlock(&lock); + printf("EndSimulation done\n"); + fflush(stdout); +} + +// main +void +CONNECTED_APPLICATION_CLASS::Main() +{ + FILE *inputFile; + UINT16 sample; + + // Convert input wav to pcm + generate_pcm("input.wav","input.pcm"); + + //Send data to the machine here. + inputFile = fopen("input.pcm","r"); + assert(inputFile); + + + int count = 0; + + printf("main: about to enter loop %d\n", count); + + while(fread(&sample, 2, 1, inputFile)) { + if(count%1000 == 0) + printf("main: %d\n", count); + count++; + sem_wait(&throttle); + clientStub->SendUnprocessedStream(Data,(UINT32)sample); + } + + printf("main: out of loop\n"); + + // Need to put lock here to prevent potential race condition + pthread_mutex_lock(&lock); + clientStub->SendUnprocessedStream(EndOfFile,0); + + printf("main: wait for end of file\n"); + + pthread_cond_wait(&cond, &lock); + pthread_mutex_unlock(&lock); + + printf("main: lastt data out\n"); + + // Convert input wav to pcm + generate_wav("out_hw.pcm","input.wav","out_hw.wav"); + + printf("generate wav done\n"); + + fflush(stdout); + exit(0); +} diff -r a1833d9f6e3d -r 7e1510b47336 AudioProcessor.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/AudioProcessor.h Tue Apr 27 22:54:50 2010 -0400 @@ -0,0 +1,56 @@ +// +// INTEL CONFIDENTIAL +// Copyright (c) 2008 Intel Corp. Recipient is granted a non-sublicensable +// copyright license under Intel copyrights to copy and distribute this code +// internally only. This code is provided "AS IS" with no support and with no +// warranties of any kind, including warranties of MERCHANTABILITY, +// FITNESS FOR ANY PARTICULAR PURPOSE or INTELLECTUAL PROPERTY INFRINGEMENT. +// By making any use of this code, Recipient agrees that no other licenses +// to any Intel patents, trade secrets, copyrights or other intellectual +// property rights are granted herein, and no other licenses shall arise by +// estoppel, implication or by operation of law. Recipient accepts all risks +// of use. +// + +// possibly use include paths to hide existing modules? + +#ifndef __AUDIO_PROCESSOR_CONNECTED_APPLICATION__ +#define __AUDIO_PROCESSOR_CONNECTED_APPLICATION__ + +#include +#include +#include + +#include "asim/provides/virtual_platform.h" + +#include "asim/rrr/client_stub_AUDIOPROCESSORRRR.h" + +typedef enum { + EndOfFile = 0, + Data = 1 +} AudioProcessorControl; + + +typedef class CONNECTED_APPLICATION_CLASS* CONNECTED_APPLICATION; +class CONNECTED_APPLICATION_CLASS : public PLATFORMS_MODULE_CLASS +{ + private: + AUDIOPROCESSORRRR_CLIENT_STUB clientStub; + static sem_t throttle; + static pthread_mutex_t lock; + static pthread_cond_t cond; + + public: + CONNECTED_APPLICATION_CLASS(VIRTUAL_PLATFORM vp); + ~CONNECTED_APPLICATION_CLASS(); + static void EndSimulation(); + static void UpdateSemaphore(); + + // init + void Init(); + + // main + void Main(); +}; + +#endif diff -r a1833d9f6e3d -r 7e1510b47336 AudioProcessorRRR.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/AudioProcessorRRR.cpp Tue Apr 27 22:54:50 2010 -0400 @@ -0,0 +1,93 @@ +#include +#include +#include +#include +#include +#include + +#include "asim/rrr/service_ids.h" + +#include "asim/provides/connected_application.h" + + + +using namespace std; + +// ===== service instantiation ===== +AUDIOPROCESSORRRR_SERVER_CLASS AUDIOPROCESSORRRR_SERVER_CLASS::instance; + +// constructor +AUDIOPROCESSORRRR_SERVER_CLASS::AUDIOPROCESSORRRR_SERVER_CLASS() : + serverStub(new AUDIOPROCESSORRRR_SERVER_STUB_CLASS(this)) +{ + // instantiate stub + printf("AUDIOPROCESSORRR init called\n"); + outputFile = NULL; +} + +// destructor +AUDIOPROCESSORRRR_SERVER_CLASS::~AUDIOPROCESSORRRR_SERVER_CLASS() +{ + Cleanup(); +} + +// init +void +AUDIOPROCESSORRRR_SERVER_CLASS::Init(PLATFORMS_MODULE p) +{ + parent = p; +} + +// uninit +void +AUDIOPROCESSORRRR_SERVER_CLASS::Uninit() +{ + Cleanup(); +} + +// cleanup +void +AUDIOPROCESSORRRR_SERVER_CLASS::Cleanup() +{ + delete serverStub; +} + + +// +// RRR service methods +// + +void +AUDIOPROCESSORRRR_SERVER_CLASS::SendProcessedStream(UINT16 control, UINT16 data) +{ + + AudioProcessorControl audioProcessorControl = (AudioProcessorControl) control; + switch(control) { + case EndOfFile: + if(outputFile != NULL) { + fflush(outputFile); + fclose(outputFile); + outputFile = NULL; + } else { + outputFile = fopen("out_hw.pcm","w"); + assert(outputFile); + fflush(outputFile); + fclose(outputFile); + } + + CONNECTED_APPLICATION_CLASS::EndSimulation(); + break; + + case Data: + if(outputFile == NULL) { + outputFile = fopen("out_hw.pcm","w"); + assert(outputFile); + } + + CONNECTED_APPLICATION_CLASS::UpdateSemaphore(); + fwrite(&data, 2,1 , outputFile); + break; + } + +} + diff -r a1833d9f6e3d -r 7e1510b47336 AudioProcessorRRR.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/AudioProcessorRRR.h Tue Apr 27 22:54:50 2010 -0400 @@ -0,0 +1,50 @@ + +#ifndef _AUDIOPROCESSORRRR_ +#define _AUDIOPROCESSORRRR_ + +#include +#include + +#include "asim/provides/low_level_platform_interface.h" + +#include "asim/provides/rrr.h" + + + +typedef class AUDIOPROCESSORRRR_SERVER_CLASS* AUDIOPROCESSORRRR_SERVER; +class AUDIOPROCESSORRRR_SERVER_CLASS: public RRR_SERVER_CLASS, public PLATFORMS_MODULE_CLASS +{ + private: + // self-instantiation + static AUDIOPROCESSORRRR_SERVER_CLASS instance; + FILE *outputFile; + + // server stub + RRR_SERVER_STUB serverStub; + + int count; + + public: + AUDIOPROCESSORRRR_SERVER_CLASS(); + ~AUDIOPROCESSORRRR_SERVER_CLASS(); + + // static methods + static AUDIOPROCESSORRRR_SERVER GetInstance() { return &instance; } + + // required RRR methods + void Init(PLATFORMS_MODULE); + void Uninit(); + void Cleanup(); + + // + // RRR service methods + // + void SendProcessedStream(UINT16 control, UINT16 data0); +}; + + + +// include server stub +#include "asim/rrr/server_stub_AUDIOPROCESSORRRR.h" + +#endif diff -r a1833d9f6e3d -r 7e1510b47336 AudioProcessorRRR.rrr --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/AudioProcessorRRR.rrr Tue Apr 27 22:54:50 2010 -0400 @@ -0,0 +1,14 @@ +service AUDIOPROCESSORRRR +{ + server sw (cpp, method) <- hw (bsv, connection) + { + method SendProcessedStream (in UINT32[32] ctrl, in UINT32[32] sample); + }; + + server hw (bsv, connection) <- sw (cpp, method) + { + method SendUnprocessedStream (in UINT32[32] ctrl, in UINT32[32] sample); + }; + + + }; diff -r a1833d9f6e3d -r 7e1510b47336 AudioProcessorTypes.bsv --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/AudioProcessorTypes.bsv Tue Apr 27 22:54:50 2010 -0400 @@ -0,0 +1,52 @@ + +// The MIT License + +// Copyright (c) 2009 Massachusetts Institute of Technology + +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: + +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. + +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +// Author: Kermin Fleming kfleming@mit.edu + +import Connectable::*; +import GetPut::*; +import ClientServer::*; + +typedef Int#(16) Sample; + +typedef enum { + EndOfFile = 0, + Data = 1 +} AudioProcessorControl deriving (Bits,Eq); + + +typedef struct { + Sample left; + Sample right; +} StereoSample deriving (Bits,Eq); + +typedef union tagged{ + Sample Sample; + void EndOfFile; +} AudioProcessorUnit deriving (Bits,Eq); + +interface AudioPipeline; + interface Put#(AudioProcessorUnit) sampleInput; + interface Get#(AudioProcessorUnit) sampleOutput; +endinterface + diff -r a1833d9f6e3d -r 7e1510b47336 DFT.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DFT.cpp Tue Apr 27 22:54:50 2010 -0400 @@ -0,0 +1,46 @@ +#include +#include +#include + + +int DFT(int dir,int m,double *x1,double *y1) +{ + long i,k; + double arg; + double cosarg,sinarg; + double *x2=NULL,*y2=NULL; + + x2 = (double *)(malloc(m*sizeof(double))); + y2 = (double *)(malloc(m*sizeof(double))); + if (x2 == NULL || y2 == NULL) + return 0; + + for (i=0;i +#include +#include +#include +#include +#include "SndfileWavUtil.h" + +void +generate_wav(const char * pcmfilename, const char * samplewavfilename, const char * outputwavfilename) +{ + char outfilename[2048]; + SNDFILE * outfile ; + SNDFILE * wavfile ; + SNDFILE * pcmfile ; + SF_INFO wavinfo ; + SF_INFO pcminfo ; + int buff; + SF_INSTRUMENT inst ; + + memset (&wavinfo, 0, sizeof (wavinfo)) ; + + + wavfile = sf_open(samplewavfilename, SFM_READ, &wavinfo); + + if (wavfile == NULL){ + printf ("\nERROR : Not able to open wav file named '%s' : %s/\n", samplewavfilename, sf_strerror (NULL)) ; + exit (1) ; + } ; + + printf("WAV format: %x\n", wavinfo.format); + + if (!((wavinfo.format & SF_FORMAT_PCM_16) && (wavinfo.channels == 1) && + (wavinfo.format & SF_FORMAT_WAV))){ + printf("\nERROR : .wav file must be SF_FORMAT_PCM_16 in mono\n"); + } + + pcminfo.format = SF_FORMAT_RAW | SF_FORMAT_PCM_16; + pcminfo.samplerate = wavinfo.samplerate; + pcminfo.channels = wavinfo.channels; + + pcmfile = sf_open(pcmfilename, SFM_READ, &pcminfo); + + if (pcmfile == NULL){ + printf ("\nERROR : Not able to open pcm file named '%s' : %s/\n", pcmfilename, sf_strerror (NULL)) ; + exit (1) ; + } ; + + + + outfile = sf_open(outputwavfilename, SFM_WRITE, &wavinfo); + + memset (&inst, 0, sizeof (inst)) ; + + for(int i = SF_STR_FIRST; i <= SF_STR_LAST; i = i + 1) { + const char * str = sf_get_string(wavfile,i); + if(str != NULL) { + sf_set_string(outfile,i,str); + } + } + + if (outfile == NULL){ + printf ("\nERROR : Not able to create wav file named '%s' : %s/\n", outfilename, sf_strerror (NULL)) ; + exit (1) ; + } ; + + while(sf_read_int(pcmfile, &buff, 1) == 1){ + if(sf_write_int(outfile, &buff, 1) != 1){ + printf("\nERROR : unable to write to '%s' : %s/\n", outfilename, sf_strerror(NULL)); + } + } + + sf_close (wavfile) ; + sf_close (outfile) ; + sf_close (pcmfile) ; + +} + + +void +generate_pcm (const char * wavfilename, const char * pcmfilename) +{ + SNDFILE * wavfile ; + SNDFILE * pcmfile ; + SF_INFO wavinfo ; + SF_INFO pcminfo ; + int buff; + + memset (&wavinfo, 0, sizeof (wavinfo)) ; + memset (&pcminfo, 0, sizeof (pcminfo)) ; + + wavfile = sf_open (wavfilename, SFM_READ, &wavinfo) ; + + if (wavfile == NULL){ + printf ("\nERROR : Not able to open wav file named '%s' : %s/\n", wavfilename, sf_strerror (NULL)) ; + exit (1) ; + } ; + + pcminfo.format = SF_FORMAT_RAW | SF_FORMAT_PCM_16; + pcminfo.samplerate = wavinfo.samplerate; + pcminfo.channels = wavinfo.channels; + + if ((!wavinfo.format & SF_FORMAT_PCM_16) || (!wavinfo.channels == 1)){ + printf("\nERROR : .wav file must be SF_FORMAT_PCM_16 and mono\n"); + } + + pcmfile = sf_open (pcmfilename, SFM_WRITE, &pcminfo) ; + + if (pcmfile == NULL){ + printf ("\nERROR : Not able to create pcm file named '%s' : %s/\n", pcmfilename, sf_strerror (NULL)) ; + exit (1) ; + } ; + + while(sf_read_int(wavfile, &buff, 1) == 1){ + if(sf_write_int(pcmfile, &buff, 1) != 1){ + printf("\nERROR : unable to write to '%s' : %s/\n", pcmfilename, sf_strerror(NULL)); + } + } + + sf_close (wavfile) ; + sf_close (pcmfile) ; +} + + + + diff -r a1833d9f6e3d -r 7e1510b47336 SndfileWavUtil.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SndfileWavUtil.h Tue Apr 27 22:54:50 2010 -0400 @@ -0,0 +1,9 @@ +#ifndef _SNDFILE_WAV_UTIL_ +#define _SNDFILE_WAV_UTIL_ + +int guess_direction (const char * filename1, const char * filename2) ; +int guess_major_format (const char * filename) ; +void generate_pcm(const char * wavfilename, const char * pcmfilename); +void generate_wav(const char * pcmfilename, const char * samplewavfilename, const char * outputwavfilename); + +#endif diff -r a1833d9f6e3d -r 7e1510b47336 audio_pipeline_default.awb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/audio_pipeline_default.awb Tue Apr 27 22:54:50 2010 -0400 @@ -0,0 +1,10 @@ +%name Default Audio Pipeline +%desc A basic copy-though audio pipeline + +%provides audio_pipeline + +%attributes 6_375 + +%public AudioPipelineDefault.bsv + + diff -r a1833d9f6e3d -r 7e1510b47336 audio_processor_hardware_system.awb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/audio_processor_hardware_system.awb Tue Apr 27 22:54:50 2010 -0400 @@ -0,0 +1,19 @@ +%name Audio Processor Application +%desc Top level audio processor. This module wraps an Audio Pipeline, providing communications between host and audio processor + +%provides connected_application + +%requires audio_processor_types +%requires audio_pipeline + +%attributes 6_375 + +%sources -t H -v PUBLIC AudioProcessor.h +%sources -t H -v PUBLIC AudioProcessorRRR.h +%sources -t H -v PUBLIC SndfileWavUtil.h +%sources -t BSV -v PUBLIC AudioProcessor.bsv +%sources -t CPP -v PRIVATE AudioProcessor.cpp +%sources -t CPP -v PRIVATE AudioProcessorRRR.cpp +%sources -t CPP -v PRIVATE SndfileWavUtil.cpp +%sources -t RRR -v PUBLIC AudioProcessorRRR.rrr +%library /usr/lib/libsndfile.so diff -r a1833d9f6e3d -r 7e1510b47336 audio_processor_software_system.awb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/audio_processor_software_system.awb Tue Apr 27 22:54:50 2010 -0400 @@ -0,0 +1,16 @@ +******************************************************************** +* Awb module specification +******************************************************************** + +%AWB_START + +%name Audio Processor Software +%desc Audio Processor Software +%provides software_system + +%attributes 6_375 + +%public AudioProcessor.cpp +%public AudioProcessor.h + +%AWB_END diff -r a1833d9f6e3d -r 7e1510b47336 audio_processor_types.awb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/audio_processor_types.awb Tue Apr 27 22:54:50 2010 -0400 @@ -0,0 +1,9 @@ +%name Audio Processor Types +%desc Audio Processing Pipeline Types + +%provides audio_processor_types + +%attributes 6_375 + +%public AudioProcessorTypes.bsv + diff -r a1833d9f6e3d -r 7e1510b47336 common/PathTypes.bsv --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/common/PathTypes.bsv Tue Apr 27 22:54:50 2010 -0400 @@ -0,0 +1,31 @@ +import Trace::*; +import Vector::*; + +`define MAX_VOICES 4 +`define MAX_CORES 16 +`define MAX_PATH_IDS 18 +`define MAX_PATH_LENGTH 8 + +// The path is hardwired and so should never be stored in a register. Therefore int type rather than Bit type + +typedef Bit#(32) MemAddr; +typedef Int#(TLog#(`MAX_PATH_IDS)) PathId; +typedef Int#(24) Sample; +typedef Int#(TLog#(`MAX_VOICES)) VoiceId; + + +//The mixer is identified as PathId 0, path end is max +PathId mixerId = 0; +PathId endId = `MAX_CORES+1; + +// Path is array of path ids +typedef Vector#(`MAX_PATH_LENGTH, PathId) CorePath; +CorePath emptyCore = replicate(endId); + +typedef struct +{ + VoiceId voice; + MemAddr startAddr; + CorePath route; +} FullPath deriving (Bits, Eq); + diff -r a1833d9f6e3d -r 7e1510b47336 common/RoutingTable.bsv --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/common/RoutingTable.bsv Tue Apr 27 22:54:50 2010 -0400 @@ -0,0 +1,52 @@ +import Trace::*; +import Vector::*; +import PathTypes::*; + +function FullPath genEmptyPaths (Integer a) ; + FullPath empt = FullPath {voice: fromInteger(a), startAddr: 0, route: emptyCore}; + return (empt); +endfunction + +interface RoutingTable; + method FullPath getPath(Integer voiceNo); +endinterface + +module mkRoutingTable(RoutingTable); + Vector#(`MAX_VOICES, FullPath) routeTable = genWith(genEmptyPaths); + + function CorePath updateVoice0(Integer len, Vector#(len, PathId) cores, CorePath inPath); + CorePath outPath = inPath; + for(Integer i = 0; i < len; i = i+1) + inPath[i] = cores[i]; + return outPath; + endfunction + + //demonstrate two ways of building the routeTable + routeTable[0].startAddr = 0; //where is this really going to come from? + routeTable[0].route[0] = 3; + routeTable[0].route[1] = mixerId; + //rest are already initialized toinvalid + + // or if you just want to update a straight list, this longer emplate works. + function CorePath createVoice1Route(); + CorePath outPath = emptyCore; + + Integer len = 3; + PathId route[len] = {1, 2, mixerId}; //route to update + + for(Integer i = 0; i < len; i = i+1) + outPath[i] = route[i]; + + return outPath; + endfunction + routeTable[1].route = createVoice1Route; + routeTable[1].startAddr = 0; + + //remaining voices are all initialized to empty. + + method FullPath getPath(Integer a); + return routeTable[a]; + endmethod + +endmodule + diff -r a1833d9f6e3d -r 7e1510b47336 config/pm/Pygar/fullSystem/audio_core_exe.apm --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/config/pm/Pygar/fullSystem/audio_core_exe.apm Tue Apr 27 22:54:50 2010 -0400 @@ -0,0 +1,110 @@ + +[Global] +SaveParameters=0 +Description= +File=audio_core_exe +Version=2.1 +Name=Audio Processor +DefaultBenchmark=config/bm/bluespec/demos.cfx/benchmarks/null.cfg +Type=HAsim +Class=Asim::Model +DefaultRunOpts= + +[Model] +DefaultAttributes=hybrid simulation +model=HW/SW Hybrid Project Foundation + +[FPGA Environment] +File=config/pm/hasim/submodels/fpgaenv/fpgaenv-hybrid-exe.apm +Packagehint=platforms + +[Soft Connections Hybrid Application Environment/Requires] +platform_services=Platform Services +soft_connections_lib=Soft Connections Library +connected_application=audio pipeline with soft core + +[Hybrid Project Common Utilities] +File=config/pm/hasim/submodels/common/project-common-default.apm +Packagehint=hasim + +[Soft Connections Library] +File=config/pm/hasim/submodels/common/soft-connections-lib.apm +Packagehint=hasim + +[Platform Services] +File=config/pm/hasim/submodels/platform-services/standard-platform-services.apm +Packagehint=hasim + +[HW/SW Hybrid Project Foundation] +File=modules/project/project-hybrid.awb +Packagehint=platforms + +[Soft Connections Hybrid Application Environment] +File=modules/application-env/hybrid/soft-connections/application-env-hybrid-soft-conn.awb +Packagehint=platforms + +[HW/SW Hybrid Project Foundation/Requires] +project_common=Hybrid Project Common Utilities +fpgaenv=FPGA Environment +application_env=Soft Connections Hybrid Application Environment + +[HW/SW Hybrid Project Foundation/Params] +WAIT_FOR_HARDWARE=0 + +[VMH hybrid memory] +File=modules/hasim/functional-partition/memory-state/memory/hybrid/vmh/vmh-memory.awb +Packagehint=hasim + +[Functional Partition Base Types] +File=modules/hasim/functional-partition/base-types/funcp-base-types.awb +Packagehint=hasim + +[3-Stage Audio Processor] +File=modules/bluespec/mit-6.375/core/processor.awb +Packagehint=mit-6.375 + +[Blocking Data Cache] +File=modules/bluespec/mit-6.375/lab4/data_cache.awb +Packagehint=mit-6.375 + +[Blocking Instruction Cache] +File=modules/bluespec/mit-6.375/lab4/instruction_cache.awb +Packagehint=mit-6.375 + +[Default HAsim Common Library] +File=config/pm/hasim/submodels/common/hasim_common.apm +Packagehint=hasim + +[Simple Audio Processor Core] +File=modules/bluespec/mit-6.375/core/audio_pipe_types.awb +Packagehint=mit-6.375 + +[Round-robin memory arbiter] +File=modules/bluespec/mit-6.375/lab4/mem_arb.awb +Packagehint=mit-6.375 + +[Processor Library] +File=modules/bluespec/mit-6.375/lab4/processor_library.awb +Packagehint=mit-6.375 + +[audio pipeline with soft core] +File=modules/bluespec/mit-6.375/core/audio_core_pipe.awb +Packagehint=mit-6.375 + +[Audio Processor Core] +File=modules/bluespec/mit-6.375/core/audio_core.awb +Packagehint=mit-6.375 + +[audio pipeline with soft core/Requires] +hasim_common=Default HAsim Common Library +funcp_simulated_memory=VMH hybrid memory +core=Audio Processor Core +funcp_base_types=Functional Partition Base Types +audio_pipe_types=Simple Audio Processor Core + +[Audio Processor Core/Requires] +processor_library=Processor Library +processor=3-Stage Audio Processor +data_cache=Blocking Data Cache +instruction_cache=Blocking Instruction Cache +mem_arb=Round-robin memory arbiter diff -r a1833d9f6e3d -r 7e1510b47336 modules/bluespec/Pygar/core/audioPipeTypes.bsv --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/modules/bluespec/Pygar/core/audioPipeTypes.bsv Tue Apr 27 22:54:50 2010 -0400 @@ -0,0 +1,50 @@ + +// The MIT License + +// Copyright (c) 2009 Massachusetts Institute of Technology + +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: + +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. + +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +// Author: Ker +// min Fleming kfleming@mit.edu + +import Connectable::*; +import GetPut::*; +import ClientServer::*; + +typedef Int#(16) Sample; + +typedef enum { + EndOfFile = 0, + Data = 1 +} AudioProcessorControl deriving (Bits,Eq); + + +typedef struct { + Sample left; + Sample right; +} StereoSample deriving (Bits,Eq); + +typedef union tagged{ + Sample Sample; + void EndOfFile; +} AudioProcessorUnit deriving (Bits,Eq); + + +