-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaudio_codec.v
More file actions
104 lines (82 loc) · 2.11 KB
/
Copy pathaudio_codec.v
File metadata and controls
104 lines (82 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
module audio_codec(
input [1:0] iSrc_Select,
input iCLK_18_4,
input [15:0] sound,
output oAUD_DATA,
output oAUD_LRCK,
output reg oAUD_BCK
);
parameter REF_CLK = 18432000; // 18.432 MHz
parameter SAMPLE_RATE = 48000; // 48 KHz (×àñòîòà äèñêðåòèçàöèè)
parameter DATA_WIDTH = 16; // 16 Bits (Sample size)
parameter CHANNEL_NUM = 2; // Dual Channel
parameter SIN_SAMPLE_DATA = 48;
parameter SIN_SANPLE = 0; // Input Source Number
// Internal Registers and Wires
reg [3:0] BCK_DIV;
reg [8:0] LRCK_1X_DIV;
reg [7:0] LRCK_2X_DIV;
reg [6:0] LRCK_4X_DIV;
reg [3:0] SEL_Cont;
reg LRCK_1X;
reg LRCK_2X;
reg LRCK_4X;
// AUD_BCK Generator
always @(posedge iCLK_18_4) begin
if (BCK_DIV >= REF_CLK / (SAMPLE_RATE * DATA_WIDTH * CHANNEL_NUM * 2) - 1) begin
BCK_DIV <= 0;
oAUD_BCK <= ~oAUD_BCK;
end else
BCK_DIV <= BCK_DIV+1;
end
// AUD_LRCK Generator
always @(posedge iCLK_18_4) begin
if (LRCK_1X_DIV >= REF_CLK / (SAMPLE_RATE * 2) - 1) begin // LRCK 1X
LRCK_1X_DIV <= 0;
LRCK_1X <= ~LRCK_1X;
end else
LRCK_1X_DIV <= LRCK_1X_DIV + 1;
if (LRCK_2X_DIV >= REF_CLK / (SAMPLE_RATE * 4) - 1) begin // LRCK 2X
LRCK_2X_DIV <= 0;
LRCK_2X <= ~LRCK_2X;
end else
LRCK_2X_DIV <= LRCK_2X_DIV + 1;
if (LRCK_4X_DIV >= REF_CLK / (SAMPLE_RATE * 8) - 1) begin // LRCK 4X
LRCK_4X_DIV <= 0;
LRCK_4X <= ~LRCK_4X;
end else
LRCK_4X_DIV <= LRCK_4X_DIV + 1;
end
assign oAUD_LRCK = LRCK_1X;
// Sin LUT ADDR Generator
// always@(negedge LRCK_1X) begin
// if (SIN_Cont < SIN_SAMPLE_DATA - 1)
// SIN_Cont <= SIN_Cont + 1;
// else
// SIN_Cont <= 0;
// end
// Wave-Source generate
wire [15:0] music1_ramp;
wire [15:0] sound_o;
assign sound_o = music1_ramp;
always @(negedge oAUD_BCK) begin
SEL_Cont <= SEL_Cont + 1;
end
assign oAUD_DATA = sound_o[~SEL_Cont];
// Ramp address generater
reg [15:0] ramp;
wire [15:0] ramp_max = 60000;
// CH1 Ramp
always@(negedge LRCK_1X) begin
if (ramp > ramp_max)
ramp = 0;
else
ramp = ramp + sound;
end
wire [5:0] ramp_ramp = ramp[15:10];
// Sine wave
wave_gen_sin r1(
.ramp(ramp_ramp),
.music_o(music1_ramp)
);
endmodule