# HG changeset patch # User punk # Date 1273077018 14400 # Node ID 9b0dfce52c29291a09b50c322ec3a7bf891373ce # Parent 4d87fa55a776f7f9c0166297bf97f075a9880fc1 [svn r45] adding mixer diff -r 4d87fa55a776 -r 9b0dfce52c29 modules/bluespec/Pygar/core/Mixer.bsv --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/modules/bluespec/Pygar/core/Mixer.bsv Wed May 05 12:30:18 2010 -0400 @@ -0,0 +1,107 @@ +// The MIT License + +// Copyright (c) 2009 Massachusetts Institute of Technology + +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: + +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. + +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +import Connectable::*; +import GetPut::*; +import ClientServer::*; +import Vector::*; +import FIFO::*; +import FixedPoint::*; + +`define MAX_VOICES 2 + +//AWB includes +`include "asim/provides/low_level_platform_interface.bsh" +`include "asim/provides/soft_connections.bsh" +`include "asim/provides/common_services.bsh" + +// Local includes +`include "asim/provides/audio_pipe_types.bsh" +`include "asim/provides/path_types.bsh" + +interface PutMixerIn; + method Action sendVoiceIn(AudioStream voiceInput); +endinterface + +interface Mixer; + interface PutMixerIn toMixer; + interface Get#(AudioProcessorUnit) mixerOut; +endinterface + +function Bool isAudioFini(Vector#(`MAX_VOICES, Reg#(Bool)) voiceStat); + Bool result = True; + for (Integer i = 0; i < `MAX_VOICES; i = i+1) + begin + result = voiceStat[i] && result; + end + return result; +endfunction + +module [CONNECTED_MODULE] mkMixer#(Vector#(`MAX_VOICES, Volume) scalars) (Mixer); + + + // Instantiate the modules + Vector#(`MAX_VOICES, FIFO#(AudioPipeUnit)) voicesIn <- replicateM(mkFIFO()); +// <- newVector(); + Vector#(`MAX_VOICES, Reg#(Bool)) voiceFini <- replicateM(mkReg(False)); + + FIFO#(AudioProcessorUnit) masterFifo <- mkFIFO(); + + rule sendEnd(isAudioFini(voiceFini)); + masterFifo.enq(tagged EndOfFile); + //prep for reset + for (Integer i = 0; i < `MAX_VOICES; i = i+1) + voiceFini[i] <= False; + endrule + + rule processSample(!isAudioFini(voiceFini)); //implicit on all voiceFifos having data + FixedPoint#(32,32) sum = 0; //this should allow 16 voices at 16 bits without messing up + for (Integer i = 0; i < `MAX_VOICES; i = i+1) + begin + if (voicesIn[i].first() matches tagged Valid .data) + begin + case (data) matches + tagged Sample .sample : + sum = sum + ((fromInt(sample) * fromInt(scalars[i])) >> 8); + //shifting right 8 to divide by 256 + tagged EndOfFile : + voiceFini[i] <= True; + endcase + end + else voiceFini[i] <= True; + voicesIn[i].deq(); + end + + masterFifo.enq(tagged Sample truncate(fxptGetInt(sum >> `MAX_VOICES))); + endrule + + // Internal connections + + interface PutMixerIn toMixer; + method Action sendVoiceIn(AudioStream voiceInput); + voicesIn[voiceInput.voice].enq(voiceInput.data); + endmethod + endinterface + + interface Get mixerOut = fifoToGet(masterFifo); + +endmodule diff -r 4d87fa55a776 -r 9b0dfce52c29 modules/bluespec/Pygar/core/mixer.awb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/modules/bluespec/Pygar/core/mixer.awb Wed May 05 12:30:18 2010 -0400 @@ -0,0 +1,10 @@ +%name Mixer +%desc Provides mixer + +%provides mixer + +%attributes PYGAR + +%public Mixer.bsv + +