// This module generates an audio stream from a file with using the // standard dataValid/takingData handshake interface // We generate dataValid randomly. You will want to use a FIFO to collect // the data generated by this module. `timescale 1ns / 1ns module audioin_tf(/*AUTOARG*/ // Outputs data, dataValid, // Inputs clk, reset, takingData ); input clk, reset; // System clock output [15:0] data; output dataValid; input takingData; parameter FileName = "infile.raw"; parameter MAXSIZE = 1024; // Generate this much data // We generate dataValid RATE/128 % of the time parameter RATE = 70; /*AUTOREG*/ // Beginning of automatic regs (for this module's undeclared outputs) reg dataValid; // End of automatics reg [15:0] test_count; // Video input memory reg [15:0] audioMem[0:MAXSIZE-1]; initial begin $display("Loading data from %s", FileName); $readmemh(FileName, audioMem); end // Assert current data from file assign data = audioMem[test_count]; always @(posedge clk) begin if (reset) begin dataValid <= 0; test_count <= 0; end else if (dataValid & takingData) begin // Proceed to next value test_count <= test_count + 1; if (test_count >= MAXSIZE) begin $finish; end end // Set dataValid for the next cycle dataValid <= (($random & 127) < RATE); end endmodule // fifo_in_tf