module stud_fifo_master #(parameter FIFO_LENGTH = 128, SIGNAL_WIDTH = 16, WB_DATA_WIDTH = 32, WB_SEL_WIDTH = 4, SYNC_LEN = 2)
	(
    	input [SIGNAL_WIDTH-1:0] 	fifo_i,
    	input [3:0] 			test_sine_psc_i,
	input fifo_rdy_i, audio_rd_i, rst_n_i, clk_i, test_mode_i, 
    	output reg [SIGNAL_WIDTH-1:0] 	audio_o,
    	output fifo_ack_o, fifo_full_o, fifo_empty_o 
	);
    	/* Internal signals */
    	wire [SIGNAL_WIDTH-1:0] fifo_audio_o, sine_audio_o, sine_buffered_o;
    	reg [SIGNAL_WIDTH-1:0] fifo_data_internal;
    	reg fifo_data_rdy;
    
	/* MODULES */
    	stud_fifo #(FIFO_LENGTH, SIGNAL_WIDTH, SYNC_LEN) fifo1(
		.fifo_i(fifo_data_internal),
		.fifo_rdy_i(fifo_data_rdy),
		.audio_rd_i(audio_rd_i),
		.rst_n_i(rst_n_i),
		.clk_i(clk_i),
		.fifo_ack_o(fifo_ack_o),
		.fifo_full_o(fifo_full_o),
		.fifo_empty_o(fifo_empty_o),
		.audio_o(fifo_audio_o)
	);
    
    	stud_sine_generator sine_gen1 (
        	.clk_i(clk_i),
        	.rst_n_i(rst_n_i),
        	.psc_i(test_sine_psc_i),
        	.sine_o(sine_audio_o)
    	);
    
    	stud_synchronizer #(1, SIGNAL_WIDTH) sine_buffer (
		.clk_i(audio_rd_i),
		.rst_n_i(rst_n_i),
		.input_i(sine_audio_o),
		.output_o(sine_buffered_o)
	);
	
	always @(posedge clk_i)
	begin
        	// If test mode is active, connect sine generator buffer to output
		if(test_mode_i) begin
            		audio_o <= sine_buffered_o;
		end else begin
			audio_o <= fifo_audio_o;
		end
			
		fifo_data_internal <= fifo_i;
		fifo_data_rdy <= fifo_rdy_i;
    	end
endmodule