module stud_strobe #(parameter WIDTH=8)(
	input              clk_i,
	input        	   rst_n_i,
	input  [1:0] 	   osr_i,
	output             audio_rd_o
);

reg strb, next_strb;
reg[WIDTH-1:0] counter, next_counter;
localparam [7:0] OSR32 = 8'd31;
localparam [7:0] OSR64 = 8'd63;
localparam [7:0] OSR128 = 8'd127;
localparam [7:0] OSR256 = 8'd255;


assign audio_rd_o = strb;

always @(posedge clk_i) begin
	    // we use a synchronous reset
    if (!rst_n_i) begin
	strb	   <= 1'b0;
	counter    <= {WIDTH{1'b0}};
    end else begin
	strb	   <= next_strb;
	counter    <= next_counter;
    end
  end

  always @(counter, osr_i, strb)begin
	next_counter = counter;
	next_strb  = strb;
	next_counter = counter - 1'b1;
	if (counter == 8'd0)begin
		case(osr_i)
		2'b00: begin
			next_counter = OSR32;
		end
		2'b01: begin
			next_counter = OSR64;
		end
		2'b10: begin
			next_counter = OSR128;
		end
		2'b11: begin
			next_counter = OSR256;
		end
		default: next_counter = OSR128;
		endcase
	end
	if (next_counter == 8'd0)begin //generate strobe every time the counter reaches 0
		next_strb = 1'b1;
	end else begin
		next_strb = 1'b0;
	end
  end


endmodule