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

Subversion Repositories next186mp3

[/] [next186mp3/] [trunk/] [HW/] [soundwave.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 ndumitrach
`timescale 1ns / 1ps
2
//////////////////////////////////////////////////////////////////////////////////
3
//
4
// This file is part of the Next186 Soc PC project
5
// http://opencores.org/project,next186
6
//
7
// Filename: sound_gen.v
8
// Description: Part of the Next186 SoC PC project, 
9
//              stereo 2x16bit pulse density modulated sound generator
10
//      44100 samples/sec
11
//              Disney Sound Source and Covox Speech compatible
12
// Version 1.0
13
// Creation date: Jan2015
14
//
15
// Author: Nicolae Dumitrache 
16
// e-mail: ndumitrache@opencores.org
17
//
18
/////////////////////////////////////////////////////////////////////////////////
19
// 
20
// Copyright (C) 2012 Nicolae Dumitrache
21
// 
22
// This source file may be used and distributed without 
23
// restriction provided that this copyright statement is not 
24
// removed from the file and that any derivative work contains 
25
// the original copyright notice and the associated disclaimer.
26
// 
27
// This source file is free software; you can redistribute it 
28
// and/or modify it under the terms of the GNU Lesser General 
29
// Public License as published by the Free Software Foundation;
30
// either version 2.1 of the License, or (at your option) any 
31
// later version. 
32
// 
33
// This source is distributed in the hope that it will be 
34
// useful, but WITHOUT ANY WARRANTY; without even the implied 
35
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
36
// PURPOSE. See the GNU Lesser General Public License for more 
37
// details. 
38
// 
39
// You should have received a copy of the GNU Lesser General 
40
// Public License along with this source; if not, download it 
41
// from http://www.opencores.org/lgpl.shtml 
42
// 
43
//////////////////////////////////////////////////////////////////////////////////
44
// Additional Comments: 
45
//
46
//      byte write: both channels are the same (Covox emulation), the 8bit sample value is shifted by 8, the channel selector is reset to LEFT
47
// word write: LEFT first, the queue is updated only after RIGHT value is written
48
// sample rate: 44100Hz
49
//////////////////////////////////////////////////////////////////////////////////
50
module soundwave(
51
                input CLK,
52
                input CLK44100x256,
53
                input [15:0]data,
54
                input we,
55
                input word,
56
                output full,    // when not full, write max 2x1152 16bit samples
57
                output dss_full,
58
                output reg AUDIO_L,
59
                output reg AUDIO_R
60
        );
61
 
62
         reg [31:0]wdata;
63
         reg lr = 1'b0;
64
         reg [2:0]write = 3'b000;
65
         wire [31:0]sample;
66
         reg [31:0]lval = 0;
67
         reg [31:0]rval = 0;
68
         reg [8:0]clkdiv = 0;
69
         wire lsign = lval[31:16] < sample[15:0];
70
         wire rsign = rval[31:16] < sample[31:16];
71
         wire empty;
72
         assign dss_full = !empty;      // Disney sound source queue full
73
 
74
         sndfifo sndfifo_inst
75
         (
76
          .wr_clk(CLK), // input wr_clk
77
          .rd_clk(CLK44100x256), // input rd_clk
78
          .din(wdata), // input [31 : 0] din
79
          .wr_en(|write), // input wr_en
80
          .rd_en(clkdiv[8]), // input rd_en
81
          .dout(sample), // output [31 : 0] dout
82
//        .full(full), // output full
83
//        .empty(empty), // output empty
84
          .prog_full(full), // output prog_full
85
          .prog_empty(empty)
86
        );
87
 
88
 
89
         always @(posedge CLK44100x256) begin
90
                clkdiv[8:0] <= clkdiv[7:0] + 1'b1;
91
 
92
                lval <= lval - lval[31:7] + (lsign << 25);
93
                AUDIO_L <= lsign;
94
 
95
                rval <= rval - rval[31:7] + (rsign << 25);
96
                AUDIO_R <= rsign;
97
         end
98
 
99
 
100
        always @(posedge CLK) begin
101
                if(we)
102
                        if(word) begin
103
                                lr <= !lr;
104
                                write <= {2'b00, lr};
105
                                if(lr) wdata[31:16] <= {!data[15], data[14:0]};
106
                                else wdata[15:0] <= {!data[15], data[14:0]};
107
                        end else begin
108
                                lr <= 1'b0;             // left
109
                                write <= 3'b110;
110
                                wdata <= {1'b0, data[7:0], 8'b00000000, data[7:0], 7'b0000000};
111
                        end
112
                else write <= write - |write;
113
        end
114
 
115
 
116
endmodule

powered by: WebSVN 2.1.0

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