Mercurial > pygar
view modules/bluespec/Pygar/core/Mixer.bsv @ 69:5c963ab14143 pygar svn.70
[svn r70] added an attempt at multi-fileing
author | punk |
---|---|
date | Wed, 12 May 2010 00:07:40 -0400 |
parents | 44cc00df1168 |
children |
line wrap: on
line source
1 // The MIT License3 // Copyright (c) 2009 Massachusetts Institute of Technology5 // Permission is hereby granted, free of charge, to any person obtaining a copy6 // of this software and associated documentation files (the "Software"), to deal7 // in the Software without restriction, including without limitation the rights8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell9 // copies of the Software, and to permit persons to whom the Software is10 // furnished to do so, subject to the following conditions:12 // The above copyright notice and this permission notice shall be included in13 // all copies or substantial portions of the Software.15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN21 // THE SOFTWARE.23 import Connectable::*;24 import GetPut::*;25 import ClientServer::*;26 import Vector::*;27 import FIFO::*;28 import FixedPoint::*;30 //AWB includes31 `include "asim/provides/low_level_platform_interface.bsh"32 `include "asim/provides/soft_connections.bsh"33 `include "asim/provides/common_services.bsh"35 // Local includes36 `include "asim/provides/audio_pipe_types.bsh"37 `include "asim/provides/path_types.bsh"39 interface Mixer;40 method Action toMixer(AudioStream streamIn);41 interface Get#(AudioProcessorUnit) mainOut;42 endinterface44 module [CONNECTED_MODULE] mkMixer#(Integer numVoices, Vector#(numVoices, Volume) scalars) (Mixer);46 function Bool isAudioFini(Vector#(numVoices, Reg#(Bool)) voiceStat);47 Bool result = True;48 for (Integer i = 0; i < numVoices; i = i+1)49 begin50 result = voiceStat[i] && result;51 end52 return result;53 endfunction56 // Instantiate the modules57 Vector#(numVoices, FIFO#(AudioPipeUnit)) voicesIn <- replicateM(mkFIFO());58 // <- newVector();59 Vector#(numVoices, Reg#(Bool)) voiceFini <- replicateM(mkReg(False));61 FIFO#(AudioProcessorUnit) masterFifo <- mkFIFO();63 rule sendEnd(isAudioFini(voiceFini));64 masterFifo.enq(tagged EndOfFile);65 //prep for reset66 for (Integer i = 0; i < numVoices; i = i+1)67 voiceFini[i] <= False;68 endrule70 rule processSample(!isAudioFini(voiceFini)); //implicit on all voiceFifos having data71 FixedPoint#(32,32) sum = 0; //this should allow 16 voices at 16 bits without messing up72 Integer numValid = 0;73 for (Integer i = 0; i < numVoices; i = i+1)74 begin75 if (voicesIn[i].first() matches tagged Valid .data)76 begin77 case (data) matches78 tagged Sample .sample :79 begin //shifting right 8 to divide by 25680 sum = sum + ((fromInt(sample) * fromInt(scalars[i])) >> 8);81 numValid = numValid + 1;82 end83 tagged EndOfFile :84 voiceFini[i] <= True;85 endcase86 end87 else voiceFini[i] <= True;88 voicesIn[i].deq();89 end90 if (numValid > 0) // If nothing is valid, don't send anything91 masterFifo.enq(tagged Sample truncate(fxptGetInt(sum >> numVoices)));92 endrule94 // Internal connections96 method Action toMixer(AudioStream streamIn);97 voicesIn[streamIn.voice].enq(streamIn.data);98 endmethod100 interface Get mainOut = fifoToGet(masterFifo);102 endmodule