`timescale 1ns / 1ps

module lab7_3(
    output audio_mclk,
    output audio_lrck,
    output audio_sck,
    output audio_sdin,
    input clk,
    input rst_n,
    input do,
    input re,
    input mi,
    input fa,
    input so,
    input dip
    );

    wire [15:0] audio_left, audio_right;
    reg [21:0] note, noter, noterf;
    
    always@*
        if(do)
            begin
            note = 22'd191571;
            noter = 22'd151515;
            end
        else if(re)
            begin
            note = 22'd170648;
            noter = 22'd143266;
            end
        else if(mi)
            begin
            note = 22'd151515;
            noter = 22'd127551;
            end
        else if(fa)
            begin
            note = 22'd143266;
            noter = 22'd113636;
            end
        else if(so)
            begin
            note = 22'd127551;
            noter = 22'd101215;
            end
        else 
            begin
            note = 22'd0;
            noter = 22'd0;
            end
        always@*
            if(dip) noterf = noter; 
            else noterf = note;      
    speaker_control U_speaker_control(
      .audio_mclk(audio_mclk),
      .audio_lrck(audio_lrck),
      .audio_sck(audio_sck),
      .audio_sdin(audio_sdin),
      .clk(clk),
      .rst_n(rst_n),
      .audio_left(audio_left),
      .audio_right(audio_right)
    );
    note_frequency U_left(
      .audio_sound(audio_left),
      .note_div(note),
      .clk(clk),
      .rst_n(rst_n)
    );    
    note_frequency U_right(
      .audio_sound(audio_right),
      .note_div(noterf),
      .clk(clk),
      .rst_n(rst_n)
    );    
endmodule
