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

Subversion Repositories mdct

[/] [mdct/] [trunk/] [source/] [DCT1D.vhd] - Blame information for rev 18

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 mikel262
--------------------------------------------------------------------------------
2
--                                                                            --
3
--                          V H D L    F I L E                                --
4
--                          COPYRIGHT (C) 2006                                --
5
--                                                                            --
6
--------------------------------------------------------------------------------
7
--
8
-- Title       : DCT1D
9
-- Design      : MDCT Core
10
-- Author      : Michal Krepa
11
--
12
--------------------------------------------------------------------------------
13
--
14
-- File        : DCT1D.VHD
15
-- Created     : Sat Mar 5 7:37 2006
16
--
17
--------------------------------------------------------------------------------
18
--
19
--  Description : 1D Discrete Cosine Transform (1st stage)
20
--
21
--------------------------------------------------------------------------------
22
 
23
 
24
library IEEE;
25
  use IEEE.STD_LOGIC_1164.all;
26
  use IEEE.NUMERIC_STD.all;
27
 
28
library WORK;
29
  use WORK.MDCT_PKG.all;
30
 
31
--------------------------------------------------------------------------------
32
-- ENTITY
33
--------------------------------------------------------------------------------
34
entity DCT1D is
35
        port(
36
                  clk          : in STD_LOGIC;
37
                  rst          : in std_logic;
38
      dcti         : in std_logic_vector(IP_W-1 downto 0);
39
      idv          : in STD_LOGIC;
40
      romedatao0   : in STD_LOGIC_VECTOR(ROMDATA_W-1 downto 0);
41
      romedatao1   : in STD_LOGIC_VECTOR(ROMDATA_W-1 downto 0);
42
      romedatao2   : in STD_LOGIC_VECTOR(ROMDATA_W-1 downto 0);
43
      romedatao3   : in STD_LOGIC_VECTOR(ROMDATA_W-1 downto 0);
44
      romedatao4   : in STD_LOGIC_VECTOR(ROMDATA_W-1 downto 0);
45
      romedatao5   : in STD_LOGIC_VECTOR(ROMDATA_W-1 downto 0);
46
      romedatao6   : in STD_LOGIC_VECTOR(ROMDATA_W-1 downto 0);
47
      romedatao7   : in STD_LOGIC_VECTOR(ROMDATA_W-1 downto 0);
48
      romedatao8   : in STD_LOGIC_VECTOR(ROMDATA_W-1 downto 0);
49
      romodatao0   : in STD_LOGIC_VECTOR(ROMDATA_W-1 downto 0);
50
      romodatao1   : in STD_LOGIC_VECTOR(ROMDATA_W-1 downto 0);
51
      romodatao2   : in STD_LOGIC_VECTOR(ROMDATA_W-1 downto 0);
52
      romodatao3   : in STD_LOGIC_VECTOR(ROMDATA_W-1 downto 0);
53
      romodatao4   : in STD_LOGIC_VECTOR(ROMDATA_W-1 downto 0);
54
      romodatao5   : in STD_LOGIC_VECTOR(ROMDATA_W-1 downto 0);
55
      romodatao6   : in STD_LOGIC_VECTOR(ROMDATA_W-1 downto 0);
56
      romodatao7   : in STD_LOGIC_VECTOR(ROMDATA_W-1 downto 0);
57
      romodatao8   : in STD_LOGIC_VECTOR(ROMDATA_W-1 downto 0);
58
 
59
      odv          : out STD_LOGIC;
60
      dcto         : out std_logic_vector(OP_W-1 downto 0);
61
      romeaddro0   : out STD_LOGIC_VECTOR(ROMADDR_W-1 downto 0);
62
      romeaddro1   : out STD_LOGIC_VECTOR(ROMADDR_W-1 downto 0);
63
      romeaddro2   : out STD_LOGIC_VECTOR(ROMADDR_W-1 downto 0);
64
      romeaddro3   : out STD_LOGIC_VECTOR(ROMADDR_W-1 downto 0);
65
      romeaddro4   : out STD_LOGIC_VECTOR(ROMADDR_W-1 downto 0);
66
      romeaddro5   : out STD_LOGIC_VECTOR(ROMADDR_W-1 downto 0);
67
      romeaddro6   : out STD_LOGIC_VECTOR(ROMADDR_W-1 downto 0);
68
      romeaddro7   : out STD_LOGIC_VECTOR(ROMADDR_W-1 downto 0);
69
      romeaddro8   : out STD_LOGIC_VECTOR(ROMADDR_W-1 downto 0);
70
      romoaddro0   : out STD_LOGIC_VECTOR(ROMADDR_W-1 downto 0);
71
      romoaddro1   : out STD_LOGIC_VECTOR(ROMADDR_W-1 downto 0);
72
      romoaddro2   : out STD_LOGIC_VECTOR(ROMADDR_W-1 downto 0);
73
      romoaddro3   : out STD_LOGIC_VECTOR(ROMADDR_W-1 downto 0);
74
      romoaddro4   : out STD_LOGIC_VECTOR(ROMADDR_W-1 downto 0);
75
      romoaddro5   : out STD_LOGIC_VECTOR(ROMADDR_W-1 downto 0);
76
      romoaddro6   : out STD_LOGIC_VECTOR(ROMADDR_W-1 downto 0);
77
      romoaddro7   : out STD_LOGIC_VECTOR(ROMADDR_W-1 downto 0);
78
      romoaddro8   : out STD_LOGIC_VECTOR(ROMADDR_W-1 downto 0);
79
      ramwaddro    : out STD_LOGIC_VECTOR(RAMADRR_W-1 downto 0);
80
      ramdatai     : out STD_LOGIC_VECTOR(RAMDATA_W-1 downto 0);
81
      ramwe        : out STD_LOGIC;
82 15 mikel262
      wmemsel      : out STD_LOGIC
83 2 mikel262
                );
84
end DCT1D;
85
 
86
--------------------------------------------------------------------------------
87
-- ARCHITECTURE
88
--------------------------------------------------------------------------------
89
architecture RTL of DCT1D is
90
 
91
  type INPUT_DATA is array (N-1 downto 0) of SIGNED(IP_W downto 0);
92
 
93
  signal databuf_reg    : INPUT_DATA;
94
  signal latchbuf_reg   : INPUT_DATA;
95
  signal col_reg        : UNSIGNED(RAMADRR_W/2-1 downto 0);
96
  signal row_reg        : UNSIGNED(RAMADRR_W/2-1 downto 0);
97 15 mikel262
  signal rowr_reg       : UNSIGNED(RAMADRR_W/2-1 downto 0);
98
  signal inpcnt_reg     : UNSIGNED(RAMADRR_W/2-1 downto 0);
99 2 mikel262
  signal ramdatai_s     : STD_LOGIC_VECTOR(RAMDATA_W-1 downto 0);
100
  signal ramwe_s        : STD_LOGIC;
101 15 mikel262
  signal wmemsel_reg    : STD_LOGIC;
102
  signal stage2_reg     : STD_LOGIC;
103
  signal stage2_cnt_reg : UNSIGNED(RAMADRR_W-1 downto 0);
104
  signal col_2_reg      : UNSIGNED(RAMADRR_W/2-1 downto 0);
105 2 mikel262
begin
106
 
107
  ramwe_sg:
108
  ramwe    <= ramwe_s;
109
 
110
  ramdatai_sg:
111
  ramdatai <= ramdatai_s;
112
 
113
  -- temporary
114
  odv_sg:
115
  odv      <= ramwe_s;
116
  dcto_sg:
117
  dcto     <= ramdatai_s(RAMDATA_W-1) & ramdatai_s(RAMDATA_W-1) & ramdatai_s;
118
 
119 15 mikel262
  wmemsel_sg:
120
  wmemsel <= wmemsel_reg;
121
 
122 18 mikel262
  process(clk)
123 2 mikel262
  begin
124 18 mikel262
    if clk = '1' and clk'event then
125
      if rst = '1' then
126
        inpcnt_reg     <= (others => '0');
127
        latchbuf_reg   <= (others => (others => '0'));
128
        databuf_reg    <= (others => (others => '0'));
129
        stage2_reg     <= '0';
130
        stage2_cnt_reg <= (others => '1');
131
        ramdatai_s     <= (others => '0');
132
        ramwe_s        <= '0';
133
        ramwaddro      <= (others => '0');
134
        col_reg        <= (others => '0');
135
        row_reg        <= (others => '0');
136
        wmemsel_reg    <= '0';
137
        col_2_reg      <= (others => '0');
138
      else
139
 
140
        stage2_reg     <= '0';
141
        ramwe_s        <= '0';
142
 
143
        --------------------------------
144
        -- 1st stage
145
        --------------------------------
146
        if idv = '1' then
147
 
148
          inpcnt_reg    <= inpcnt_reg + 1;
149
 
150
          -- right shift input data
151
          latchbuf_reg(N-2 downto 0) <= latchbuf_reg(N-1 downto 1);
152
          latchbuf_reg(N-1)          <= SIGNED('0' & dcti) - LEVEL_SHIFT;
153
 
154
          if inpcnt_reg = N-1 then
155
            -- after this sum databuf_reg is in range of -256 to 254 (min to max) 
156
            databuf_reg(0)  <= latchbuf_reg(1)+(SIGNED('0' & dcti) - LEVEL_SHIFT);
157
            databuf_reg(1)  <= latchbuf_reg(2)+latchbuf_reg(7);
158
            databuf_reg(2)  <= latchbuf_reg(3)+latchbuf_reg(6);
159
            databuf_reg(3)  <= latchbuf_reg(4)+latchbuf_reg(5);
160
            databuf_reg(4)  <= latchbuf_reg(1)-(SIGNED('0' & dcti) - LEVEL_SHIFT);
161
            databuf_reg(5)  <= latchbuf_reg(2)-latchbuf_reg(7);
162
            databuf_reg(6)  <= latchbuf_reg(3)-latchbuf_reg(6);
163
            databuf_reg(7)  <= latchbuf_reg(4)-latchbuf_reg(5);
164
            stage2_reg      <= '1';
165
          end if;
166 10 mikel262
        end if;
167 18 mikel262
        --------------------------------
168 2 mikel262
 
169 18 mikel262
        --------------------------------
170
        -- 2nd stage
171
        --------------------------------
172
        if stage2_cnt_reg < N then
173
 
174
          if stage2_cnt_reg(0) = '0' then
175
            ramdatai_s <= STD_LOGIC_VECTOR(RESIZE
176
              (RESIZE(SIGNED(romedatao0),DA_W) +
177
              (RESIZE(SIGNED(romedatao1),DA_W-1) & '0') +
178
              (RESIZE(SIGNED(romedatao2),DA_W-2) & "00") +
179
              (RESIZE(SIGNED(romedatao3),DA_W-3) & "000") +
180
              (RESIZE(SIGNED(romedatao4),DA_W-4) & "0000") +
181
              (RESIZE(SIGNED(romedatao5),DA_W-5) & "00000") +
182
              (RESIZE(SIGNED(romedatao6),DA_W-6) & "000000") +
183
              (RESIZE(SIGNED(romedatao7),DA_W-7) & "0000000") -
184
              (RESIZE(SIGNED(romedatao8),DA_W-8) & "00000000"),
185
                                          DA_W)(DA_W-1 downto 12));
186
          else
187
            ramdatai_s <= STD_LOGIC_VECTOR(RESIZE
188
              (RESIZE(SIGNED(romodatao0),DA_W) +
189
              (RESIZE(SIGNED(romodatao1),DA_W-1) & '0') +
190
              (RESIZE(SIGNED(romodatao2),DA_W-2) & "00") +
191
              (RESIZE(SIGNED(romodatao3),DA_W-3) & "000") +
192
              (RESIZE(SIGNED(romodatao4),DA_W-4) & "0000") +
193
              (RESIZE(SIGNED(romodatao5),DA_W-5) & "00000") +
194
              (RESIZE(SIGNED(romodatao6),DA_W-6) & "000000") +
195
              (RESIZE(SIGNED(romodatao7),DA_W-7) & "0000000") -
196
              (RESIZE(SIGNED(romodatao8),DA_W-8) & "00000000"),
197
                                          DA_W)(DA_W-1 downto 12));
198
          end if;
199
 
200
          stage2_cnt_reg <= stage2_cnt_reg + 1;
201
 
202
          -- write RAM
203
          ramwe_s   <= '1';
204
          -- reverse col/row order for transposition purpose
205
          ramwaddro <= STD_LOGIC_VECTOR(col_2_reg & row_reg);
206
          -- increment column counter
207
          col_reg   <= col_reg + 1;
208
          col_2_reg <= col_2_reg + 1;
209
 
210
          -- finished processing one input row
211
          if col_reg = 0 then
212
            row_reg         <= row_reg + 1;
213
            -- switch to 2nd memory
214
            if row_reg = N - 1 then
215
              wmemsel_reg <= not wmemsel_reg;
216
              col_reg         <= (others => '0');
217
            end if;
218
          end if;
219
 
220 15 mikel262
        end if;
221
 
222 18 mikel262
        if stage2_reg = '1' then
223
          stage2_cnt_reg <= (others => '0');
224
          col_reg        <= (0=>'1',others => '0');
225
          col_2_reg      <= (others => '0');
226
        end if;
227
        ----------------------------------    
228 15 mikel262
      end if;
229 2 mikel262
    end if;
230
  end process;
231
 
232 4 mikel262
  -- read precomputed MAC results from LUT
233 15 mikel262
  romeaddro0 <= STD_LOGIC_VECTOR(col_reg(RAMADRR_W/2-1 downto 1)) &
234 4 mikel262
           databuf_reg(0)(0) &
235
           databuf_reg(1)(0) &
236
           databuf_reg(2)(0) &
237
           databuf_reg(3)(0);
238 15 mikel262
  romeaddro1 <= STD_LOGIC_VECTOR(col_reg(RAMADRR_W/2-1 downto 1)) &
239 4 mikel262
           databuf_reg(0)(1) &
240
           databuf_reg(1)(1) &
241
           databuf_reg(2)(1) &
242
           databuf_reg(3)(1);
243 15 mikel262
  romeaddro2 <= STD_LOGIC_VECTOR(col_reg(RAMADRR_W/2-1 downto 1)) &
244 4 mikel262
           databuf_reg(0)(2) &
245
           databuf_reg(1)(2) &
246
           databuf_reg(2)(2) &
247
           databuf_reg(3)(2);
248 15 mikel262
  romeaddro3 <= STD_LOGIC_VECTOR(col_reg(RAMADRR_W/2-1 downto 1)) &
249 4 mikel262
           databuf_reg(0)(3) &
250
           databuf_reg(1)(3) &
251
           databuf_reg(2)(3) &
252
           databuf_reg(3)(3);
253 15 mikel262
  romeaddro4  <= STD_LOGIC_VECTOR( col_reg(RAMADRR_W/2-1 downto 1)) &
254 4 mikel262
           databuf_reg(0)(4) &
255
           databuf_reg(1)(4) &
256
           databuf_reg(2)(4) &
257
           databuf_reg(3)(4);
258 15 mikel262
  romeaddro5  <= STD_LOGIC_VECTOR(col_reg(RAMADRR_W/2-1 downto 1)) &
259 4 mikel262
           databuf_reg(0)(5) &
260
           databuf_reg(1)(5) &
261
           databuf_reg(2)(5) &
262
           databuf_reg(3)(5);
263 15 mikel262
  romeaddro6  <= STD_LOGIC_VECTOR(col_reg(RAMADRR_W/2-1 downto 1)) &
264 4 mikel262
           databuf_reg(0)(6) &
265
           databuf_reg(1)(6) &
266
           databuf_reg(2)(6) &
267
           databuf_reg(3)(6);
268 15 mikel262
  romeaddro7  <= STD_LOGIC_VECTOR(col_reg(RAMADRR_W/2-1 downto 1)) &
269 4 mikel262
           databuf_reg(0)(7) &
270
           databuf_reg(1)(7) &
271
           databuf_reg(2)(7) &
272
           databuf_reg(3)(7);
273 15 mikel262
  romeaddro8  <= STD_LOGIC_VECTOR(col_reg(RAMADRR_W/2-1 downto 1)) &
274 4 mikel262
           databuf_reg(0)(8) &
275
           databuf_reg(1)(8) &
276
           databuf_reg(2)(8) &
277 15 mikel262
           databuf_reg(3)(8);
278 4 mikel262
 
279
  -- odd
280
  romoaddro0 <= STD_LOGIC_VECTOR(col_reg(RAMADRR_W/2-1 downto 1)) &
281
             databuf_reg(4)(0) &
282
             databuf_reg(5)(0) &
283
             databuf_reg(6)(0) &
284
             databuf_reg(7)(0);
285
  romoaddro1 <= STD_LOGIC_VECTOR(col_reg(RAMADRR_W/2-1 downto 1)) &
286
             databuf_reg(4)(1) &
287
             databuf_reg(5)(1) &
288
             databuf_reg(6)(1) &
289
             databuf_reg(7)(1);
290
  romoaddro2 <= STD_LOGIC_VECTOR(col_reg(RAMADRR_W/2-1 downto 1)) &
291
             databuf_reg(4)(2) &
292
             databuf_reg(5)(2) &
293
             databuf_reg(6)(2) &
294
             databuf_reg(7)(2);
295
  romoaddro3 <= STD_LOGIC_VECTOR(col_reg(RAMADRR_W/2-1 downto 1)) &
296
             databuf_reg(4)(3) &
297
             databuf_reg(5)(3) &
298
             databuf_reg(6)(3) &
299
             databuf_reg(7)(3);
300
  romoaddro4 <= STD_LOGIC_VECTOR(col_reg(RAMADRR_W/2-1 downto 1)) &
301
             databuf_reg(4)(4) &
302
             databuf_reg(5)(4) &
303
             databuf_reg(6)(4) &
304
             databuf_reg(7)(4);
305
  romoaddro5 <= STD_LOGIC_VECTOR(col_reg(RAMADRR_W/2-1 downto 1)) &
306
             databuf_reg(4)(5) &
307
             databuf_reg(5)(5) &
308
             databuf_reg(6)(5) &
309
             databuf_reg(7)(5);
310
  romoaddro6 <= STD_LOGIC_VECTOR(col_reg(RAMADRR_W/2-1 downto 1)) &
311
             databuf_reg(4)(6) &
312
             databuf_reg(5)(6) &
313
             databuf_reg(6)(6) &
314
             databuf_reg(7)(6);
315
  romoaddro7 <= STD_LOGIC_VECTOR(col_reg(RAMADRR_W/2-1 downto 1)) &
316
             databuf_reg(4)(7) &
317
             databuf_reg(5)(7) &
318
             databuf_reg(6)(7) &
319
             databuf_reg(7)(7);
320
  romoaddro8 <= STD_LOGIC_VECTOR(col_reg(RAMADRR_W/2-1 downto 1)) &
321
             databuf_reg(4)(8) &
322
             databuf_reg(5)(8) &
323
             databuf_reg(6)(8) &
324
             databuf_reg(7)(8);
325 15 mikel262
 
326 4 mikel262
 
327 2 mikel262
end RTL;
328
--------------------------------------------------------------------------------

powered by: WebSVN 2.1.0

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