OpenCores
URL https://opencores.org/ocsvn/psg16/psg16/trunk

Subversion Repositories psg16

[/] [psg16/] [trunk/] [rtl/] [verilog/] [PSGVolumeControl.v] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 robfinch
`timescale 1ns / 1ps
2
// ============================================================================
3 5 robfinch
//        __
4
//   \\__/ o\    (C) 2007-2017  Robert Finch, Waterloo
5
//    \  __ /    All rights reserved.
6
//     \/_//     robfinch<remove>@finitron.ca
7
//       ||
8 4 robfinch
//
9
//      PSGVolumeControl.v 
10
//              Controls the PSG's output volume.
11 5 robfinch
// The volume control is made non-linear with a ROM lookup table based on
12
// an increment similar to Fibonnaci series.
13 4 robfinch
//
14
// This source file is free software: you can redistribute it and/or modify 
15
// it under the terms of the GNU Lesser General Public License as published 
16
// by the Free Software Foundation, either version 3 of the License, or     
17
// (at your option) any later version.                                      
18
//                                                                          
19
// This source file is distributed in the hope that it will be useful,      
20
// but WITHOUT ANY WARRANTY; without even the implied warranty of           
21
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            
22
// GNU General Public License for more details.                             
23
//                                                                          
24
// You should have received a copy of the GNU General Public License        
25
// along with this program.  If not, see <http://www.gnu.org/licenses/>.    
26 5 robfinch
//                                                                          
27
//=============================================================================
28 4 robfinch
 
29
module PSGVolumeControl(rst_i, clk_i, i, volume, o);
30
input rst_i;
31
input clk_i;
32
input [21:0] i;
33 5 robfinch
input [3:0] volume;
34 4 robfinch
output [29:0] o;
35
reg [29:0] o;
36
 
37 5 robfinch
// This ROM lookup table to delinearize the volume control.
38
// Uses mangled Fibonnaci series.
39
reg [7:0] vol;
40
always @*
41
case(volume)
42
4'd00:  vol = 8'd00;
43
4'd01:  vol = 8'd01;
44
4'd03:  vol = 8'd01;
45
4'd04:  vol = 8'd02;
46
4'd05:  vol = 8'd03;
47
4'd06:  vol = 8'd05;
48
4'd07:  vol = 8'd08;
49
4'd09:  vol = 8'd13;
50
4'd10:  vol = 8'd21;
51
4'd11:  vol = 8'd34;
52
4'd12:  vol = 8'd56;
53
4'd13:  vol = 8'd90;
54
4'd14:  vol = 8'd151;
55
4'd15:  vol = 8'd255;
56
endcase
57 4 robfinch
always @(posedge clk_i)
58
if (rst_i)
59
    o <= 26'b0;         // Force the output volume to zero on reset
60
else
61 5 robfinch
    o <= i * vol;
62 4 robfinch
 
63
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.