Mercurial > pygar
view modules/bluespec/Pygar/core/Mixer.bsv @ 66:6bd9397cd591 pygar svn.67
[svn r67] added a couple sound files
author | punk |
---|---|
date | Tue, 11 May 2010 21:02:59 -0400 |
parents | 2991344775f8 |
children | 44cc00df1168 |
line wrap: on
line source
1 // The MIT License3 // Copyright (c) 2009 Massachusetts Institute of Technology5 // Permission is hereby granted, free of charge, to any person obtaining a copy6 // of this software and associated documentation files (the "Software"), to deal7 // in the Software without restriction, including without limitation the rights8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell9 // copies of the Software, and to permit persons to whom the Software is10 // furnished to do so, subject to the following conditions:12 // The above copyright notice and this permission notice shall be included in13 // all copies or substantial portions of the Software.15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER19 // 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 IN21 // THE SOFTWARE.23 import Connectable::*;24 import GetPut::*;25 import ClientServer::*;26 import Vector::*;27 import FIFO::*;28 import FixedPoint::*;30 //AWB includes31 `include "asim/provides/low_level_platform_interface.bsh"32 `include "asim/provides/soft_connections.bsh"33 `include "asim/provides/common_services.bsh"35 // Local includes36 `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 endinterface44 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 begin50 result = voiceStat[i] && result;51 end52 return result;53 endfunction56 // Instantiate the modules57 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 reset66 for (Integer i = 0; i < numVoices; i = i+1)67 voiceFini[i] <= False;68 endrule70 rule processSample(!isAudioFini(voiceFini)); //implicit on all voiceFifos having data71 FixedPoint#(32,32) sum = 0; //this should allow 16 voices at 16 bits without messing up72 for (Integer i = 0; i < numVoices; i = i+1)73 begin74 if (voicesIn[i].first() matches tagged Valid .data)75 begin76 case (data) matches77 tagged Sample .sample :78 sum = sum + ((fromInt(sample) * fromInt(scalars[i])) >> 8);79 //shifting right 8 to divide by 25680 tagged EndOfFile :81 voiceFini[i] <= True;82 endcase83 end84 else voiceFini[i] <= True;85 voicesIn[i].deq();86 end88 masterFifo.enq(tagged Sample truncate(fxptGetInt(sum >> numVoices)));89 endrule91 // Internal connections93 // method Action loadMixerFifos(AudioStream voiceInput);94 // voicesIn[voiceInput.voice].enq(voiceInput.data);95 // endmethod97 method Action toMixer(AudioStream streamIn);98 voicesIn[streamIn.voice].enq(streamIn.data);99 endmethod101 interface Get mainOut = fifoToGet(masterFifo);103 endmodule