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 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 `define MAX_VOICES 2
32 //AWB includes
33 `include "asim/provides/low_level_platform_interface.bsh"
34 `include "asim/provides/soft_connections.bsh"
35 `include "asim/provides/common_services.bsh"
37 // Local includes
38 `include "asim/provides/audio_pipe_types.bsh"
39 `include "asim/provides/path_types.bsh"
41 interface PutMixerIn;
42 method Action sendVoiceIn(AudioStream voiceInput);
43 endinterface
45 interface Mixer;
46 interface PutMixerIn toMixer;
47 interface Get#(AudioProcessorUnit) mixerOut;
48 endinterface
50 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 begin
54 result = voiceStat[i] && result;
55 end
56 return result;
57 endfunction
59 module [CONNECTED_MODULE] mkMixer#(Vector#(`MAX_VOICES, Volume) scalars) (Mixer);
62 // Instantiate the modules
63 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 reset
72 for (Integer i = 0; i < `MAX_VOICES; i = i+1)
73 voiceFini[i] <= False;
74 endrule
76 rule processSample(!isAudioFini(voiceFini)); //implicit on all voiceFifos having data
77 FixedPoint#(32,32) sum = 0; //this should allow 16 voices at 16 bits without messing up
78 for (Integer i = 0; i < `MAX_VOICES; i = i+1)
79 begin
80 if (voicesIn[i].first() matches tagged Valid .data)
81 begin
82 case (data) matches
83 tagged Sample .sample :
84 sum = sum + ((fromInt(sample) * fromInt(scalars[i])) >> 8);
85 //shifting right 8 to divide by 256
86 tagged EndOfFile :
87 voiceFini[i] <= True;
88 endcase
89 end
90 else voiceFini[i] <= True;
91 voicesIn[i].deq();
92 end
94 masterFifo.enq(tagged Sample truncate(fxptGetInt(sum >> `MAX_VOICES)));
95 endrule
97 // Internal connections
99 interface PutMixerIn toMixer;
100 method Action sendVoiceIn(AudioStream voiceInput);
101 voicesIn[voiceInput.voice].enq(voiceInput.data);
102 endmethod
103 endinterface
105 interface Get mixerOut = fifoToGet(masterFifo);
107 endmodule