punk@13: // The MIT License punk@13: punk@13: // Copyright (c) 2009 Massachusetts Institute of Technology punk@13: punk@13: // Permission is hereby granted, free of charge, to any person obtaining a copy punk@13: // of this software and associated documentation files (the "Software"), to deal punk@13: // in the Software without restriction, including without limitation the rights punk@13: // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell punk@13: // copies of the Software, and to permit persons to whom the Software is punk@13: // furnished to do so, subject to the following conditions: punk@13: punk@13: // The above copyright notice and this permission notice shall be included in punk@13: // all copies or substantial portions of the Software. punk@13: punk@13: // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR punk@13: // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, punk@13: // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE punk@13: // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER punk@13: // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, punk@13: // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN punk@13: // THE SOFTWARE. punk@13: punk@13: // Author: Kermin Fleming kfleming@mit.edu punk@13: punk@13: import Connectable::*; punk@13: import GetPut::*; punk@13: import ClientServer::*; punk@13: import FIFO::*; punk@15: import SpecialFIFOs::*; punk@52: import Vector::*; punk@13: punk@13: //AWB includes punk@13: `include "asim/provides/low_level_platform_interface.bsh" punk@13: `include "asim/provides/soft_connections.bsh" punk@13: `include "asim/provides/common_services.bsh" punk@13: punk@13: //Local includes punk@13: `include "asim/provides/audio_pipe_types.bsh" //provides Audio Pipeline interface punk@33: `include "asim/provides/path_types.bsh" punk@13: `include "asim/provides/core.bsh" punk@43: `include "asim/provides/mixer.bsh" punk@15: `include "asim/provides/processor_library.bsh" punk@15: `include "asim/provides/fpga_components.bsh" punk@51: `include "asim/dict/VDEV_SCRATCH.bsh" punk@33: punk@13: `include "asim/rrr/remote_client_stub_AUDIOCORERRR.bsh" punk@36: `include "asim/rrr/remote_server_stub_AUDIOCORERRR.bsh" punk@13: punk@13: module [CONNECTED_MODULE] mkConnectedApplication (); punk@51: Core core <- mkCore(`VDEV_SCRATCH_MEMORYA); punk@51: Core anotherCore <- mkCore(`VDEV_SCRATCH_MEMORYB); punk@53: Vector#(2, Volume) channelVols = replicate(127); punk@53: Mixer mixer <- mkMixer(2, channelVols); //should be max voices but 2 for now punk@53: punk@13: Reg#(int) cycle <- mkReg(0); punk@53: Reg#(int) sampleCount <-mkReg(0); punk@52: Vector#(2, Reg#(Bool)) ac_fini <- replicateM(mkReg(False)); punk@33: punk@53: // FIFO#(AudioProcessorUnit) coreOut <- mkFIFO(); punk@53: // Services Samples punk@53: ClientStub_AUDIOCORERRR client_stub <- mkClientStub_AUDIOCORERRR(); punk@48: punk@13: punk@36: //----------------------------------------------------------- punk@36: // Debug port punk@36: punk@36: ServerStub_AUDIOCORERRR server_stub <- mkServerStub_AUDIOCORERRR(); punk@36: punk@36: punk@13: // this is for the tracing punk@13: rule printCycles; punk@13: cycle <= cycle+1; punk@13: $fdisplay(stderr, " => Cycle = %d", cycle); punk@13: endrule punk@13: punk@53: // Send to Mixer punk@53: // Right now this is sorta retarded in that I pass from the output fifo into a new fifo punk@53: // But I have to mod a bunch of things to fix this and I am not sure I understand punk@53: // things well enough to do this quickly. So here it is as it is for now. punk@53: rule mix; punk@53: let coreOut <- core.sampleOutput.get(); punk@53: let anotherOut <- anotherCore.sampleOutput.get(); punk@53: mixer.toMixer(AudioStream {voice : 0, data : tagged Valid coreOut}); punk@53: mixer.toMixer(AudioStream {voice : 1, data : tagged Valid anotherOut}); punk@53: endrule punk@53: punk@48: rule feedOutput; punk@53: // let pipelineData <- core.sampleOutput.get(); punk@53: let pipeOut <- mixer.mainOut.get(); punk@53: punk@13: AudioProcessorControl endOfFileTag = EndOfFile; punk@13: AudioProcessorControl sampleTag = Data; punk@13: punk@53: sampleCount <= sampleCount+1; punk@53: punk@53: $display("PIPE writes sample %x\n", sampleCount); punk@53: case (pipeOut) matches punk@52: tagged EndOfFile: punk@52: begin punk@52: client_stub.makeRequest_SendProcessedStream(zeroExtend(pack(endOfFileTag)),?); punk@52: ac_fini[0] <= True; punk@52: end punk@52: tagged Sample .sample: punk@52: client_stub.makeRequest_SendProcessedStream(zeroExtend(pack(sampleTag)), zeroExtend(pack(sample))); punk@25: endcase punk@53: endrule punk@13: punk@52: // Programming ghetto style! punk@52: // right now I am repeating this rule for my second core. punk@53: /* (* conservative_implicit_conditions *) punk@52: rule feedAnotherOutput; punk@52: let pipelineData <- anotherCore.sampleOutput.get(); punk@52: AudioProcessorControl endOfFileTag = EndOfFile; punk@52: AudioProcessorControl sampleTag = Data; punk@52: punk@52: $display("PIPE writes another sample\n"); punk@52: case (pipelineData) matches punk@52: tagged EndOfFile: punk@52: begin punk@52: client_stub.makeRequest_SendProcessedStream(zeroExtend(pack(endOfFileTag)),?); punk@52: ac_fini[1] <= True; punk@52: end punk@52: tagged Sample .sample: punk@52: client_stub.makeRequest_SendProcessedStream(zeroExtend(pack(sampleTag)), zeroExtend(pack(sample))); punk@52: endcase punk@52: endrule punk@53: */ punk@52: punk@52: // Can generally just stick with the EOF but since I have two Cores no mixer... punk@52: /*(* conservative_implicit_conditions *) punk@52: rule sendTerminate; punk@52: Bool done = True; punk@52: for (Integer i = 1; i < 2; i = i+1) punk@52: done = ac_fini[i] && done; punk@52: punk@52: if (done) punk@52: client_stub.makeRequest_SendTerminate(zeroExtend(pack(1))); punk@52: punk@52: endrule punk@52: */ punk@52: punk@36: //***** SERVER Side ***** punk@36: punk@52: (* conservative_implicit_conditions *) punk@36: rule feedInput; punk@36: let command <- server_stub.acceptRequest_SendUnprocessedStream(); punk@36: AudioProcessorControl ctrl = unpack(truncate(command.ctrl)); rlm@41: punk@52: VoiceId channel = unpack(truncate(command.channel)); punk@48: // $display("rlm: %x", test); rlm@41: punk@52: AudioProcessorUnit inSample; punk@52: punk@52: if(ctrl == EndOfFile) punk@52: begin punk@43: $display("lsp: PIPE received EOF "); punk@52: inSample = tagged EndOfFile; punk@52: // core.sampleInput.put(tagged EndOfFile); punk@36: end punk@36: else punk@36: begin punk@43: // $display("lsp: PIPE received Data "); punk@52: // core.sampleInput.put(tagged Sample unpack(truncate(command.sample))); punk@52: inSample = tagged Sample unpack(truncate(command.sample)); punk@52: end punk@52: punk@52: case (channel) punk@52: 0 : core.sampleInput.put(inSample); punk@52: 1 : anotherCore.sampleInput.put(inSample); punk@52: endcase punk@52: punk@36: endrule punk@13: endmodule