-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnote_player.v
More file actions
54 lines (47 loc) · 1.57 KB
/
Copy pathnote_player.v
File metadata and controls
54 lines (47 loc) · 1.57 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
module note_player(
input clk,
input reset,
input play_enable, // When high we play, when low we don't.
input [5:0] note_to_load, // The note to play
input [5:0] duration_to_load, // The duration of the note to play
input load_new_note, // Tells us when we have a new note to load
output done_with_note, // When we are done with the note this stays high.
input beat, // This is our 1/48th second beat
input generate_next_sample, // Tells us when the codec wants a new sample
output [15:0] sample_out, // Our sample output
output new_sample_ready // Tells the codec when we've got a sample
);
wire [19:0] step_size;
wire [5:0] freq_rom_in;
dffre #(.WIDTH(6)) freq_reg (
.clk(clk),
.r(reset),
.en(load_new_note),
.d(note_to_load),
.q(freq_rom_in)
);
frequency_rom freq_rom(
.clk(clk),
.addr(freq_rom_in),
.dout(step_size)
);
sine_reader sine_read(
.clk(clk),
.reset(reset),
.step_size(step_size),
.generate_next(play_enable && generate_next_sample),
.sample_ready(new_sample_ready),
.sample(sample_out)
);
wire [5:0] state, next_state;
dffre #(.WIDTH(6)) state_reg (
.clk(clk),
.r(reset),
.en((beat || load_new_note) && play_enable),
.d(next_state),
.q(state)
);
assign next_state = (reset || done_with_note || load_new_note)
? duration_to_load : state - 1;
assign done_with_note = (state == 6'b0) && beat;
endmodule