rlm@2: import FIFOF::*;
rlm@2: import FIFO::*;
rlm@2: 
rlm@2: 
rlm@2: interface Mixer;
rlm@2:    method Action feed(Sample samp, VoiceId id); // feed in a sample to a specific FIFOF
rlm@2:    method Action stream(); // Outputs muxed data.
rlm@2: endinterface
rlm@2: 
rlm@2: 
rlm@2: method vectorFull?(Vector#(FIFOF#(Sample)) vect)
rlm@2: 
rlm@2:    (reduce .notEmpty vect)
rlm@2: 
rlm@2: endmethod
rlm@2: 
rlm@2: 
rlm@2: 
rlm@2: module mkMixer(Mixer);
rlm@2: 
rlm@2:    FIFO output = mkFIFO();
rlm@2: 
rlm@2: 
rlm@2:    // make vector of fifos, length = MAX_VOICES 
rlm@2:    fifo_vect Vector#(FIFOF#(Sample)) = mkVector(`MAX_VOICES);
rlm@2: 
rlm@2:    
rlm@2:    for $i(1 .. `MAX_VOICES)
rlm@2:       begin
rlm@2:          fifo_vect[$i] = mkFIFOF();
rlm@2:       end
rlm@2:         
rlm@2:    rule(vectorFull?(fifo_vect))
rlm@2: 
rlm@6:       Sample out = (/ (reduce + fifo_vector) (log `MAX_VOICES))
rlm@2:       output.enq(out);
rlm@2:       
rlm@2:    endrule
rlm@2: 
rlm@2:   
rlm@2: endmodule
rlm@2: