comparison modules/bluespec/Pygar/core/Mixer.bsv @ 53:2991344775f8 pygar svn.54

[svn r54] mixer integrated
author punk
date Sun, 09 May 2010 10:58:40 -0400
parents 9b0dfce52c29
children 44cc00df1168
comparison
equal deleted inserted replaced
52:49049f97312c 53:2991344775f8
25 import ClientServer::*; 25 import ClientServer::*;
26 import Vector::*; 26 import Vector::*;
27 import FIFO::*; 27 import FIFO::*;
28 import FixedPoint::*; 28 import FixedPoint::*;
29 29
30 `define MAX_VOICES 2
31
32 //AWB includes 30 //AWB includes
33 `include "asim/provides/low_level_platform_interface.bsh" 31 `include "asim/provides/low_level_platform_interface.bsh"
34 `include "asim/provides/soft_connections.bsh" 32 `include "asim/provides/soft_connections.bsh"
35 `include "asim/provides/common_services.bsh" 33 `include "asim/provides/common_services.bsh"
36 34
37 // Local includes 35 // Local includes
38 `include "asim/provides/audio_pipe_types.bsh" 36 `include "asim/provides/audio_pipe_types.bsh"
39 `include "asim/provides/path_types.bsh" 37 `include "asim/provides/path_types.bsh"
40 38
41 interface PutMixerIn;
42 method Action sendVoiceIn(AudioStream voiceInput);
43 endinterface
44
45 interface Mixer; 39 interface Mixer;
46 interface PutMixerIn toMixer; 40 method Action toMixer(AudioStream streamIn);
47 interface Get#(AudioProcessorUnit) mixerOut; 41 interface Get#(AudioProcessorUnit) mainOut;
48 endinterface 42 endinterface
49 43
50 function Bool isAudioFini(Vector#(`MAX_VOICES, Reg#(Bool)) voiceStat); 44 module [CONNECTED_MODULE] mkMixer#(Integer numVoices, Vector#(numVoices, Volume) scalars) (Mixer);
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
58 45
59 module [CONNECTED_MODULE] mkMixer#(Vector#(`MAX_VOICES, 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
60 54
61 55
62 // Instantiate the modules 56 // Instantiate the modules
63 Vector#(`MAX_VOICES, FIFO#(AudioPipeUnit)) voicesIn <- replicateM(mkFIFO()); 57 Vector#(numVoices, FIFO#(AudioPipeUnit)) voicesIn <- replicateM(mkFIFO());
64 // <- newVector(); 58 // <- newVector();
65 Vector#(`MAX_VOICES, Reg#(Bool)) voiceFini <- replicateM(mkReg(False)); 59 Vector#(numVoices, Reg#(Bool)) voiceFini <- replicateM(mkReg(False));
66 60
67 FIFO#(AudioProcessorUnit) masterFifo <- mkFIFO(); 61 FIFO#(AudioProcessorUnit) masterFifo <- mkFIFO();
68 62
69 rule sendEnd(isAudioFini(voiceFini)); 63 rule sendEnd(isAudioFini(voiceFini));
70 masterFifo.enq(tagged EndOfFile); 64 masterFifo.enq(tagged EndOfFile);
71 //prep for reset 65 //prep for reset
72 for (Integer i = 0; i < `MAX_VOICES; i = i+1) 66 for (Integer i = 0; i < numVoices; i = i+1)
73 voiceFini[i] <= False; 67 voiceFini[i] <= False;
74 endrule 68 endrule
75 69
76 rule processSample(!isAudioFini(voiceFini)); //implicit on all voiceFifos having data 70 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 71 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) 72 for (Integer i = 0; i < numVoices; i = i+1)
79 begin 73 begin
80 if (voicesIn[i].first() matches tagged Valid .data) 74 if (voicesIn[i].first() matches tagged Valid .data)
81 begin 75 begin
82 case (data) matches 76 case (data) matches
83 tagged Sample .sample : 77 tagged Sample .sample :
89 end 83 end
90 else voiceFini[i] <= True; 84 else voiceFini[i] <= True;
91 voicesIn[i].deq(); 85 voicesIn[i].deq();
92 end 86 end
93 87
94 masterFifo.enq(tagged Sample truncate(fxptGetInt(sum >> `MAX_VOICES))); 88 masterFifo.enq(tagged Sample truncate(fxptGetInt(sum >> numVoices)));
95 endrule 89 endrule
96 90
97 // Internal connections 91 // Internal connections
98 92
99 interface PutMixerIn toMixer; 93 // method Action loadMixerFifos(AudioStream voiceInput);
100 method Action sendVoiceIn(AudioStream voiceInput); 94 // voicesIn[voiceInput.voice].enq(voiceInput.data);
101 voicesIn[voiceInput.voice].enq(voiceInput.data); 95 // endmethod
102 endmethod 96
103 endinterface 97 method Action toMixer(AudioStream streamIn);
104 98 voicesIn[streamIn.voice].enq(streamIn.data);
105 interface Get mixerOut = fifoToGet(masterFifo); 99 endmethod
100
101 interface Get mainOut = fifoToGet(masterFifo);
106 102
107 endmodule 103 endmodule