view modules/bluespec/Pygar/core/Mixer.bsv @ 59:92041177735c pygar svn.60

[svn r60] LUTRAMing
author punk
date Mon, 10 May 2010 13:50:40 -0400
parents 2991344775f8
children 44cc00df1168
line wrap: on
line source
1 // The MIT License
3 // Copyright (c) 2009 Massachusetts Institute of Technology
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // 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 IN
21 // THE SOFTWARE.
23 import Connectable::*;
24 import GetPut::*;
25 import ClientServer::*;
26 import Vector::*;
27 import FIFO::*;
28 import FixedPoint::*;
30 //AWB includes
31 `include "asim/provides/low_level_platform_interface.bsh"
32 `include "asim/provides/soft_connections.bsh"
33 `include "asim/provides/common_services.bsh"
35 // Local includes
36 `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 endinterface
44 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 begin
50 result = voiceStat[i] && result;
51 end
52 return result;
53 endfunction
56 // Instantiate the modules
57 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 reset
66 for (Integer i = 0; i < numVoices; i = i+1)
67 voiceFini[i] <= False;
68 endrule
70 rule processSample(!isAudioFini(voiceFini)); //implicit on all voiceFifos having data
71 FixedPoint#(32,32) sum = 0; //this should allow 16 voices at 16 bits without messing up
72 for (Integer i = 0; i < numVoices; i = i+1)
73 begin
74 if (voicesIn[i].first() matches tagged Valid .data)
75 begin
76 case (data) matches
77 tagged Sample .sample :
78 sum = sum + ((fromInt(sample) * fromInt(scalars[i])) >> 8);
79 //shifting right 8 to divide by 256
80 tagged EndOfFile :
81 voiceFini[i] <= True;
82 endcase
83 end
84 else voiceFini[i] <= True;
85 voicesIn[i].deq();
86 end
88 masterFifo.enq(tagged Sample truncate(fxptGetInt(sum >> numVoices)));
89 endrule
91 // Internal connections
93 // method Action loadMixerFifos(AudioStream voiceInput);
94 // voicesIn[voiceInput.voice].enq(voiceInput.data);
95 // endmethod
97 method Action toMixer(AudioStream streamIn);
98 voicesIn[streamIn.voice].enq(streamIn.data);
99 endmethod
101 interface Get mainOut = fifoToGet(masterFifo);
103 endmodule