Mercurial > pygar
view modules/bluespec/Pygar/core/Mixer.bsv @ 49:61f6267cb3db pygar svn.50
[svn r50] removed problematic stats stuff
author | rlm |
---|---|
date | Wed, 05 May 2010 14:40:48 -0400 |
parents | 9b0dfce52c29 |
children | 2991344775f8 |
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 `define MAX_VOICES 232 //AWB includes33 `include "asim/provides/low_level_platform_interface.bsh"34 `include "asim/provides/soft_connections.bsh"35 `include "asim/provides/common_services.bsh"37 // Local includes38 `include "asim/provides/audio_pipe_types.bsh"39 `include "asim/provides/path_types.bsh"41 interface PutMixerIn;42 method Action sendVoiceIn(AudioStream voiceInput);43 endinterface45 interface Mixer;46 interface PutMixerIn toMixer;47 interface Get#(AudioProcessorUnit) mixerOut;48 endinterface50 function Bool isAudioFini(Vector#(`MAX_VOICES, Reg#(Bool)) voiceStat);51 Bool result = True;52 for (Integer i = 0; i < `MAX_VOICES; i = i+1)53 begin54 result = voiceStat[i] && result;55 end56 return result;57 endfunction59 module [CONNECTED_MODULE] mkMixer#(Vector#(`MAX_VOICES, Volume) scalars) (Mixer);62 // Instantiate the modules63 Vector#(`MAX_VOICES, FIFO#(AudioPipeUnit)) voicesIn <- replicateM(mkFIFO());64 // <- newVector();65 Vector#(`MAX_VOICES, Reg#(Bool)) voiceFini <- replicateM(mkReg(False));67 FIFO#(AudioProcessorUnit) masterFifo <- mkFIFO();69 rule sendEnd(isAudioFini(voiceFini));70 masterFifo.enq(tagged EndOfFile);71 //prep for reset72 for (Integer i = 0; i < `MAX_VOICES; i = i+1)73 voiceFini[i] <= False;74 endrule76 rule processSample(!isAudioFini(voiceFini)); //implicit on all voiceFifos having data77 FixedPoint#(32,32) sum = 0; //this should allow 16 voices at 16 bits without messing up78 for (Integer i = 0; i < `MAX_VOICES; i = i+1)79 begin80 if (voicesIn[i].first() matches tagged Valid .data)81 begin82 case (data) matches83 tagged Sample .sample :84 sum = sum + ((fromInt(sample) * fromInt(scalars[i])) >> 8);85 //shifting right 8 to divide by 25686 tagged EndOfFile :87 voiceFini[i] <= True;88 endcase89 end90 else voiceFini[i] <= True;91 voicesIn[i].deq();92 end94 masterFifo.enq(tagged Sample truncate(fxptGetInt(sum >> `MAX_VOICES)));95 endrule97 // Internal connections99 interface PutMixerIn toMixer;100 method Action sendVoiceIn(AudioStream voiceInput);101 voicesIn[voiceInput.voice].enq(voiceInput.data);102 endmethod103 endinterface105 interface Get mixerOut = fifoToGet(masterFifo);107 endmodule