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

Subversion Repositories jt51

[/] [jt51/] [trunk/] [jt51/] [jt51_op.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 gryzor
/*  This file is part of JT51.
2
 
3
    JT51 is free software: you can redistribute it and/or modify
4
    it under the terms of the GNU General Public License as published by
5
    the Free Software Foundation, either version 3 of the License, or
6
    (at your option) any later version.
7
 
8
    JT51 is distributed in the hope that it will be useful,
9
    but WITHOUT ANY WARRANTY; without even the implied warranty of
10
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
    GNU General Public License for more details.
12
 
13
    You should have received a copy of the GNU General Public License
14
    along with JT51.  If not, see <http://www.gnu.org/licenses/>.
15
 
16
        Author: Jose Tejada Gomez. Twitter: @topapate
17
        Version: 1.0
18
        Date: 27-10-2016
19
        */
20
 
21
`timescale 1ns / 1ps
22
 
23
/*
24
 
25
        Pipeline operator
26
 
27
*/
28
 
29
module jt51_op(
30
        `ifdef TEST_SUPPORT
31
        input                           test_eg,
32
        input                           test_op0,
33
        `endif
34
        input                   clk,            // P1
35
        input           [19:0]   phase_cnt,
36
        input           [2:0]    con,
37
        input           [1:0]    cur_op,
38
        input           [2:0]    fb,
39
        // volume
40
        input           [9:0]    eg,
41
        // output data
42
        output reg      signed  [13:0]   out
43
);
44
 
45
 
46
reg     [ 9:0]   phase;
47
reg [ 4:0]       log_msb, log_msb2;
48
reg [12:0]       pre; // preattenuation value
49
reg [3:0]        sign;
50
reg     [12:0]   out_abs;
51
 
52
reg     [7:0]    phase_addr;
53
wire    [11:0]   log_val;        // sine mantisa, in 2's complement
54
 
55
jt51_sintable u_sintable(
56
        .phase   ( phase_addr   ),
57
        .log_val ( log_val      )
58
);
59
 
60
 
61
reg     [7:0]    pow_addr;
62
wire    [12:0]   pow_val;
63
 
64
jt51_exptable u_exptable(
65
        .pow_addr( pow_addr     ),
66
        .pow_val ( pow_val      )
67
);
68
 
69
reg     [9:0]    eg_II, eg_III;
70
`ifdef TEST_SUPPORT
71
reg     [9:0]    eg_IV, eg_V, eg_VI;
72
`endif
73
reg     signed  [19:0]   modulation;
74
wire    [2:0]    con_I, con_VII;
75
wire    [1:0]    cur_op_VII, cur_op_I;
76
wire    [2:0]    fb_I;
77
 
78
parameter mod_lat = 5; /* latency */
79
parameter mod_stg = 5*8-mod_lat; /* stages */
80
reg     [14*mod_stg-1:0] mod;
81
 
82
wire signed [13:0] mod1 = mod[ (16-mod_lat)*14-1: (15-mod_lat)*14 ];
83
wire signed [13:0] mod2 = mod[ (24-mod_lat)*14-1: (23-mod_lat)*14 ];
84
wire signed [13:0] mod3 = mod[ (32-mod_lat)*14-1: (31-mod_lat)*14 ];
85
wire signed [13:0] mod4 = mod[ (40-mod_lat)*14-1: (39-mod_lat)*14 ];
86
wire signed [13:0] mod7;
87
 
88
wire mod7_en = cur_op_I==2'd0;
89
 
90
jt51_sh2 #( .width(14), .stages(8) ) u_mod7sh(
91
        .clk    ( clk   ),
92
        .en             ( mod7_en ),
93
        .ld             ( 1'b1  ),
94
        .din    ( mod3  ),
95
    .drop       ( mod7  )
96
);
97
 
98
 
99
parameter M1=2'd0, M2=2'd1, C1=02'd2, C2=2'd3;
100
 
101
always @(*) begin
102
        case( cur_op_I )
103
                default: // M1, FL
104
                        case( fb_I )
105
                                3'd0: modulation <= 20'd0;
106
                                3'd1: modulation <= (mod3+mod7)<<1;
107
                                3'd2: modulation <= (mod3+mod7)<<2;
108
                                3'd3: modulation <= (mod3+mod7)<<3;
109
                                3'd4: modulation <= (mod3+mod7)<<4;
110
                                3'd5: modulation <= (mod3+mod7)<<5;
111
                                3'd6: modulation <= (mod3+mod7)<<6;
112
                                3'd7: modulation <= (mod3+mod7)<<7;
113
                        endcase
114
                C1: case(con_I)
115
                                3'd7, 3'd2, 3'd1:
116
                                        modulation <= 20'd0;
117
                                default:
118
                                        modulation <= mod1<<9; // M1
119
                        endcase
120
                C2: case(con_I)
121
                                default: // 3'd4, 3'd1, 3'd0:
122
                                        modulation <= mod1<<9; // M2
123
                                3'd2:
124
                                        modulation <= (mod1+mod2)<<9; // M2+M1
125
                                3'd3:
126
                                        modulation <= (mod1+mod4)<<9; // M2+C1
127
                                3'd5:
128
                                        modulation <= mod2<<9; // M1
129
                                3'd7, 3'd6:
130
                                        modulation <= 20'd0;
131
                        endcase
132
                M2: case(con_I)
133
                                default: // 3'd2, 3'd0:
134
                                        modulation <= mod2<<9; // C1
135
                                3'd1:
136
                                        modulation <= (mod2+mod4)<<9; // C1+M1
137
                                3'd5:
138
                                        modulation <= mod4<<9; // M1
139
                                3'd7, 3'd6, 3'd4, 3'd3:
140
                                        modulation <= 20'd0;
141
                        endcase
142
        endcase
143
end
144
 
145
 
146
always @(posedge clk) begin
147
        // I
148
        phase <= (phase_cnt + modulation)>>10;
149
        eg_II <= eg;
150
        // II
151
        phase_addr      <= phase[8]? ~phase[7:0]:phase[7:0];
152
        sign[0]          <= phase[9];
153
        eg_III <= eg_II;
154
        // III
155
        { log_msb, pow_addr } <= log_val[11:0] + { eg_III, 2'b0};
156
        sign[1] <= sign[0];
157
        `ifdef TEST_SUPPORT
158
        eg_IV <= eg_III;
159
        `endif
160
        // IV
161
        pre             <= pow_val;
162
        log_msb2<= log_msb;
163
        sign[2] <= sign[1];
164
        `ifdef TEST_SUPPORT
165
        eg_V <= eg_IV;
166
        `endif
167
        // V
168
        case( log_msb2 )
169
                5'h0: out_abs <= pre;
170
                5'h1: out_abs <= pre >> 1;
171
                5'h2: out_abs <= pre >> 2;
172
                5'h3: out_abs <= pre >> 3;
173
                5'h4: out_abs <= pre >> 4;
174
                5'h5: out_abs <= pre >> 5;
175
                5'h6: out_abs <= pre >> 6;
176
                5'h7: out_abs <= pre >> 7;
177
                5'h8: out_abs <= pre >> 8;
178
                5'h9: out_abs <= pre >> 9;
179
                5'hA: out_abs <= pre >> 10;
180
                5'hB: out_abs <= pre >> 11;
181
                5'hC: out_abs <= pre >> 12;
182
                default: out_abs <= 13'd0;
183
        endcase
184
        sign[3] <= sign[2];
185
        `ifdef TEST_SUPPORT
186
        eg_VI <= eg_V;
187
        `endif
188
        // VI
189
    mod[14*mod_stg-1:14] <= mod[14*(mod_stg-1)-1:0];
190
        `ifdef TEST_SUPPORT
191
        if( test_eg)
192
                mod[14-1:0]      <= eg_VI;
193
        else
194
        `endif
195
                mod[14-1:0]      <= sign[3] ? ~{1'b0,out_abs}+1'b1 : {1'b0,out_abs} ;
196
        // VII
197
        `ifdef TEST_SUPPORT
198
        if( test_op0 ) begin
199
                if( cur_op_VII==3'd0)
200
                        out <= mod[14-1:0];
201
                else
202
                        out <= 14'd0;
203
        end
204
        else
205
        `endif
206
        case( con_VII )
207
                3'd0, 3'd1, 3'd2, 3'd3:
208
                        if( cur_op_VII!=2'd3 )
209
                                out <= 14'd0;
210
                        else
211
                                out <= mod[14-1:0];
212
                3'd4:
213
                        if( cur_op_VII==2'd0 || cur_op_VII==2'd1 )
214
                                out <= 14'd0;
215
                        else
216
                                out <= mod[14-1:0];
217
                3'd5, 3'd6:
218
                        if( cur_op_VII==2'd0 )
219
                                out <= 14'd0;
220
                        else
221
                                out <= mod[14-1:0];
222
                3'd7:   out <= mod[14-1:0];
223
        endcase
224
end
225
 
226
jt51_sh #( .width(8), .stages(7) ) u_con1sh(
227
        .clk    ( clk   ),
228
        .din    ( { con, cur_op, fb }   ),
229
    .drop       ( { con_I, cur_op_I, fb_I } )
230
);
231
 
232
 
233
jt51_sh #( .width(5), .stages(6) ) u_con7sh(
234
        .clk    ( clk   ),
235
        .din    ( { con_I, cur_op_I }   ),
236
    .drop       ( { con_VII, cur_op_VII } )
237
);
238
 
239
 
240
endmodule

powered by: WebSVN 2.1.0

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