annotate modules/bluespec/Pygar/core/Mixer.bsv @ 56:4449e17a2237 pygar svn.57

[svn r57] added useless stuff that should work but doesn't.
author rlm
date Sun, 09 May 2010 23:12:15 -0400
parents 2991344775f8
children 44cc00df1168
rev   line source
punk@44 1 // The MIT License
punk@44 2
punk@44 3 // Copyright (c) 2009 Massachusetts Institute of Technology
punk@44 4
punk@44 5 // Permission is hereby granted, free of charge, to any person obtaining a copy
punk@44 6 // of this software and associated documentation files (the "Software"), to deal
punk@44 7 // in the Software without restriction, including without limitation the rights
punk@44 8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
punk@44 9 // copies of the Software, and to permit persons to whom the Software is
punk@44 10 // furnished to do so, subject to the following conditions:
punk@44 11
punk@44 12 // The above copyright notice and this permission notice shall be included in
punk@44 13 // all copies or substantial portions of the Software.
punk@44 14
punk@44 15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
punk@44 16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
punk@44 17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
punk@44 18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
punk@44 19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
punk@44 20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
punk@44 21 // THE SOFTWARE.
punk@44 22
punk@44 23 import Connectable::*;
punk@44 24 import GetPut::*;
punk@44 25 import ClientServer::*;
punk@44 26 import Vector::*;
punk@44 27 import FIFO::*;
punk@44 28 import FixedPoint::*;
punk@44 29
punk@44 30 //AWB includes
punk@44 31 `include "asim/provides/low_level_platform_interface.bsh"
punk@44 32 `include "asim/provides/soft_connections.bsh"
punk@44 33 `include "asim/provides/common_services.bsh"
punk@44 34
punk@44 35 // Local includes
punk@44 36 `include "asim/provides/audio_pipe_types.bsh"
punk@44 37 `include "asim/provides/path_types.bsh"
punk@44 38
punk@44 39 interface Mixer;
punk@53 40 method Action toMixer(AudioStream streamIn);
punk@53 41 interface Get#(AudioProcessorUnit) mainOut;
punk@44 42 endinterface
punk@44 43
punk@53 44 module [CONNECTED_MODULE] mkMixer#(Integer numVoices, Vector#(numVoices, Volume) scalars) (Mixer);
punk@44 45
punk@53 46 function Bool isAudioFini(Vector#(numVoices, Reg#(Bool)) voiceStat);
punk@53 47 Bool result = True;
punk@53 48 for (Integer i = 0; i < numVoices; i = i+1)
punk@53 49 begin
punk@53 50 result = voiceStat[i] && result;
punk@53 51 end
punk@53 52 return result;
punk@53 53 endfunction
punk@44 54
punk@44 55
punk@44 56 // Instantiate the modules
punk@53 57 Vector#(numVoices, FIFO#(AudioPipeUnit)) voicesIn <- replicateM(mkFIFO());
punk@44 58 // <- newVector();
punk@53 59 Vector#(numVoices, Reg#(Bool)) voiceFini <- replicateM(mkReg(False));
punk@44 60
punk@44 61 FIFO#(AudioProcessorUnit) masterFifo <- mkFIFO();
punk@44 62
punk@44 63 rule sendEnd(isAudioFini(voiceFini));
punk@44 64 masterFifo.enq(tagged EndOfFile);
punk@44 65 //prep for reset
punk@53 66 for (Integer i = 0; i < numVoices; i = i+1)
punk@44 67 voiceFini[i] <= False;
punk@44 68 endrule
punk@44 69
punk@44 70 rule processSample(!isAudioFini(voiceFini)); //implicit on all voiceFifos having data
punk@44 71 FixedPoint#(32,32) sum = 0; //this should allow 16 voices at 16 bits without messing up
punk@53 72 for (Integer i = 0; i < numVoices; i = i+1)
punk@44 73 begin
punk@44 74 if (voicesIn[i].first() matches tagged Valid .data)
punk@44 75 begin
punk@44 76 case (data) matches
punk@44 77 tagged Sample .sample :
punk@44 78 sum = sum + ((fromInt(sample) * fromInt(scalars[i])) >> 8);
punk@44 79 //shifting right 8 to divide by 256
punk@44 80 tagged EndOfFile :
punk@44 81 voiceFini[i] <= True;
punk@44 82 endcase
punk@44 83 end
punk@44 84 else voiceFini[i] <= True;
punk@44 85 voicesIn[i].deq();
punk@44 86 end
punk@44 87
punk@53 88 masterFifo.enq(tagged Sample truncate(fxptGetInt(sum >> numVoices)));
punk@44 89 endrule
punk@44 90
punk@44 91 // Internal connections
punk@44 92
punk@53 93 // method Action loadMixerFifos(AudioStream voiceInput);
punk@53 94 // voicesIn[voiceInput.voice].enq(voiceInput.data);
punk@53 95 // endmethod
punk@53 96
punk@53 97 method Action toMixer(AudioStream streamIn);
punk@53 98 voicesIn[streamIn.voice].enq(streamIn.data);
punk@53 99 endmethod
punk@53 100
punk@53 101 interface Get mainOut = fifoToGet(masterFifo);
punk@44 102
punk@44 103 endmodule