-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathbitcrush.sv
61 lines (55 loc) · 1.77 KB
/
bitcrush.sv
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
// Bit Crusher
//
// Reduce number of bits on channels 1-3 according to the voltage
// on channel 0.
//
// Mapping:
// - Input 0: Bitcrusher mask setting (0-5V)
// - Input 1-3: Audio inputs
// - Output 0: Input 0 (mirrored)
// - Output 1-3: Audio outputs (bitcrushed)
module bitcrush #(
parameter W = 16
)(
input rst,
input clk,
input strobe,
input signed [W-1:0] sample_in0,
input signed [W-1:0] sample_in1,
input signed [W-1:0] sample_in2,
input signed [W-1:0] sample_in3,
output signed [W-1:0] sample_out0,
output signed [W-1:0] sample_out1,
output signed [W-1:0] sample_out2,
output signed [W-1:0] sample_out3,
input [7:0] jack
);
logic signed [W-1:0] mask;
logic signed [W-1:0] out0;
logic signed [W-1:0] out1;
logic signed [W-1:0] out2;
logic signed [W-1:0] out3;
assign mask = (sample_in0 > 4*5000) ? 16'b1111111111111111 :
(sample_in0 > 4*4500) ? 16'b1111111111100000 :
(sample_in0 > 4*4000) ? 16'b1111111111000000 :
(sample_in0 > 4*3500) ? 16'b1111111110000000 :
(sample_in0 > 4*3000) ? 16'b1111111100000000 :
(sample_in0 > 4*2500) ? 16'b1111111000000000 :
(sample_in0 > 4*2000) ? 16'b1111110000000000 :
(sample_in0 > 4*1500) ? 16'b1111100000000000 :
(sample_in0 > 4*1000) ? 16'b1111000000000000 :
(sample_in0 > 4* 500) ? 16'b1110000000000000 :
16'b1100000000000000;
always_ff @(posedge clk) begin
if (strobe) begin
out0 <= sample_in0;
out1 <= sample_in1 & mask;
out2 <= sample_in2 & mask;
out3 <= sample_in3 & mask;
end
end
assign sample_out0 = out0;
assign sample_out1 = out1;
assign sample_out2 = out2;
assign sample_out3 = out3;
endmodule