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

Subversion Repositories sqmusic

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /
    from Rev 17 to Rev 18
    Reverse comparison

Rev 17 → Rev 18

/sqmusic/trunk/memos/opn.ods Cannot display: file marked as a binary type. svn:mime-type = application/vnd.oasis.opendocument.spreadsheet
/sqmusic/trunk/sqm/sq_pg.v
10,6 → 10,41
 
*/
 
`timescale 1ns/1ps
 
module sq_slot(
input clk,
input reset_n,
input [10:0] fnumber,
input [2:0] block,
input [3:0] multiple
);
wire [9:0]phase;
wire [12:0] sin_log, sin_linear;
 
sq_pg pg(
.clk (clk),
.reset_n (reset_n),
.fnumber (fnumber),
.block (block),
.multiple(multiple),
.phase (phase) );
 
sq_sin sin(
.clk (clk),
.reset_n (reset_n),
.phase (phase),
.val (sin_log) );
sq_pow pow(
.clk (clk),
.reset_n (reset_n),
.x (sin_log),
.y (sin_linear) );
 
endmodule
 
module sq_pg(
input clk,
input reset_n,
21,38 → 56,74
reg [19:0] count;
assign phase = count[19:10];
 
wire [19:0]fmult;
wire [19:0]fmult = fnumber << block;
 
always @(*) begin
case( multiple )
4'b0: fmult = (phase << block) >> 1'b1;
default: fmult = (phase<<block)*multiple;
endcase
end
 
always @(posedge clk or negedge reset_n ) begin
if( !reset_n )
count <= 20'b0;
else begin
count <= count + fmult;
count <= count + ( multiple==4'b0 ? fmult>> 1 : fmult*multiple);
end
end
 
endmodule
 
///////////////////////////////////////////////////////////////////
module sq_sin(
// input clk,
// input reset_n,
input clk,
input reset_n,
input [9:0]phase,
output [19:0] val
)
output [12:0] val // LSB is the sign. 0=positive, 1=negative
);
 
reg [19:0] sin_table[1023:0];
reg [12:0] sin_table[1023:0];
 
initial begin
$readmemh("sin_table.hex", sin_table);
$readmemh("../tables/sin_table.hex", sin_table);
end
reg [9:0]last_phase;
assign val = sin_table[last_phase];
 
assign val = sin_table[phase];
always @(posedge clk or negedge reset_n ) begin
if( !reset_n )
last_phase <= 10'b0;
else begin
last_phase <= phase;
end
end
endmodule
///////////////////////////////////////////////////////////////////
// sq_pow => reverse the log2 conversion
module sq_pow(
input clk,
input reset_n,
input [12:0]x,
output [12:0]y // LSB is the sign. 0=positive, 1=negative
);
 
reg [12:0] pow_table[255:0];
 
initial begin
$readmemh("../tables/pow_table.hex", pow_table);
end
reg [7:0]index;
reg [2:0]exp;
reg sign;
 
wire [12:0] raw = pow_table[index] >> exp;
assign y = sign ? ~raw+13'b1 : raw; // regular 2's complement
 
always @(posedge clk or negedge reset_n ) begin
if( !reset_n ) begin
index <= 8'b0;
exp <= 3'b0;
sign <= 1'b0;
end
else begin
exp <= x[12:10];
index <= x[9:1];
sign <= x[0];
end
end
 
endmodule
/sqmusic/trunk/cpp/args.h
47,12 → 47,20
argument_t* def_arg;
std::string program_name;
argument_t help_arg;
void clean_args() {
for( int j=0; j<legal_args.size(); j++ ) {
argument_t& a = *legal_args[j];
if( a.short_name=="-h" && a.long_name!="help" )
{ help_arg.short_name.clear(); break; } // remove -h for help if already used
}
}
void throw_error( std::string x ) /*throw const char**/ { throw x.c_str(); }
public:
void throw_error( std::string x ) /*throw const char**/ { throw x.c_str(); }
Args( int argc, char *argv[], arg_vector_t& legal_args ) //throw const char *
: legal_args( legal_args ),
help_arg( legal_args, "help", argument_t::flag, "Display usage information")
{
{
clean_args(); // eliminate duplicated values
// look for default argument
def_arg=NULL;
for( int j=0; j<legal_args.size(); j++ ) {
132,7 → 140,7
std::cout << "\t";
std::string aux;
if( !a.long_name.empty() ) aux = a.long_name;
if( !a.long_name.empty() && !a.long_name.empty() ) aux += " | ";
if( !a.long_name.empty() && !a.short_name.empty() ) aux += " | ";
if( !a.short_name.empty() ) aux+= a.short_name;
std::cout << brackets( a, aux );
switch( a.type ) {
/sqmusic/trunk/cpp/sintable.cc
0,0 → 1,121
/*
sintable: sine wave table generator
Based on MAME's fm.c file.
 
(c) Jose Tejada Gomez, May 2013
You can use this file following the GNU GENERAL PUBLIC LICENSE version 3
Read the details of the license in:
http://www.gnu.org/licenses/gpl.txt
Send comments to: jose.tejada at ieee.org
 
*/
 
#include <iostream>
#include <cmath>
#include "../cpp/args.h"
 
using namespace std;
 
#define ENV_BITS 10
#define ENV_LEN (1<<ENV_BITS)
#define ENV_STEP (128.0/ENV_LEN)
#define TL_RES_LEN (256) /* 8 bits addressing (real chip) */
#define SIN_BITS 10
#define SIN_LEN (1<<SIN_BITS)
#define SIN_MASK (SIN_LEN-1)
 
signed int tl_tab[TL_RES_LEN];
unsigned int sin_tab[SIN_LEN];
 
void init_tables(void) // copied from fm.c
{
signed int i,x;
signed int n;
double o,m;
 
for (x=0; x<TL_RES_LEN; x++)
{
m = (1<<16) / pow(2, (x+1) * (ENV_STEP/4.0) / 8.0);
m = floor(m);
 
/* we never reach (1<<16) here due to the (x+1) */
/* result fits within 16 bits at maximum */
 
n = (int)m; /* 16 bits here */
n >>= 4; /* 12 bits here */
if (n&1) /* round to nearest */
n = (n>>1)+1;
else
n = n>>1;
/* 11 bits here (rounded) */
n <<= 2; /* 13 bits here (as in real chip) */
tl_tab[ x ] = n;
}
 
for (i=0; i<SIN_LEN; i++)
{
/* non-standard sinus */
m = sin( ((i*2)+1) * M_PI / SIN_LEN ); /* checked against the real chip */
 
/* we never reach zero here due to ((i*2)+1) */
if (m>0.0)
o = 8*log(1.0/m)/log(2.0); /* convert to 'decibels' */
else
o = 8*log(-1.0/m)/log(2.0); /* convert to 'decibels' */
 
o = o / (ENV_STEP/4);
 
n = (int)(2.0*o);
if (n&1) /* round to nearest */
n = (n>>1)+1;
else
n = n>>1;
 
sin_tab[ i ] = n*2 + (m>=0.0? 0: 1 );
/*logerror("FM.C: sin [%4i]= %4i (tl_tab value=%5i)\n", i, sin_tab[i],tl_tab[sin_tab[i]]);*/
}
}
 
void dump_tl_tab() {
for( int i=0; i<TL_RES_LEN; i++ ) {
cout << tl_tab[i] << "\n";
}
}
 
void dump_sin_tab() {
for( int i=0; i<SIN_LEN; i++ ) {
cout << sin_tab[i] << "\n";
}
}
 
void dump_composite() {
// cout.setf( ios::hex, ios::basefield );
for( int i=0; i<SIN_LEN; i++ ) {
cout << sin_tab[i] << "," << tl_tab[ sin_tab[i] ] << "\n";
}
}
 
unsigned conv( double x ) {
double xmax = 0xFFFFF; // 20 bits, all ones
return (unsigned)(xmax* 20*log(x+0.5));
}
 
int main(int argc, char *argv[]) {
arg_vector_t legal_args;
argument_t arg_hex( legal_args, "hex", argument_t::flag,
"set output to hexadecimal mode" );
argument_t arg_sin( legal_args, "sin", argument_t::flag,
"dump sine wave" );
argument_t arg_pow( legal_args, "pow", argument_t::flag,
"dump power table" );
Args args_parser( argc, argv, legal_args );
if( args_parser.help_request() ) { return 0; }
if( argc==1 ) { args_parser.show_help(); return 0; }
init_tables();
//dump_composite();
if( arg_hex.is_set() ) cout.setf( ios::hex, ios::basefield );
if( arg_pow.is_set() ) dump_tl_tab();
if( arg_sin.is_set() ) dump_sin_tab();
return 0;
}
/sqmusic/trunk/tables/pow_table.hex
0,0 → 1,256
1fe8
1fd4
1fbc
1fa8
1f90
1f7c
1f68
1f50
1f3c
1f24
1f10
1efc
1ee4
1ed0
1eb8
1ea4
1e90
1e7c
1e64
1e50
1e3c
1e28
1e10
1dfc
1de8
1dd4
1dc0
1da8
1d94
1d80
1d6c
1d58
1d44
1d30
1d1c
1d08
1cf4
1ce0
1ccc
1cb8
1ca4
1c90
1c7c
1c68
1c54
1c40
1c2c
1c18
1c08
1bf4
1be0
1bcc
1bb8
1ba4
1b94
1b80
1b6c
1b58
1b48
1b34
1b20
1b10
1afc
1ae8
1ad4
1ac4
1ab0
1aa0
1a8c
1a78
1a68
1a54
1a44
1a30
1a20
1a0c
19fc
19e8
19d8
19c4
19b4
19a0
1990
197c
196c
195c
1948
1938
1924
1914
1904
18f0
18e0
18d0
18c0
18ac
189c
188c
1878
1868
1858
1848
1838
1824
1814
1804
17f4
17e4
17d4
17c0
17b0
17a0
1790
1780
1770
1760
1750
1740
1730
1720
1710
1700
16f0
16e0
16d0
16c0
16b0
16a0
1690
1680
1670
1664
1654
1644
1634
1624
1614
1604
15f8
15e8
15d8
15c8
15bc
15ac
159c
158c
1580
1570
1560
1550
1544
1534
1524
1518
1508
14f8
14ec
14dc
14d0
14c0
14b0
14a4
1494
1488
1478
146c
145c
1450
1440
1430
1424
1418
1408
13fc
13ec
13e0
13d0
13c4
13b4
13a8
139c
138c
1380
1370
1364
1358
1348
133c
1330
1320
1314
1308
12f8
12ec
12e0
12d4
12c4
12b8
12ac
12a0
1290
1284
1278
126c
1260
1250
1244
1238
122c
1220
1214
1208
11f8
11ec
11e0
11d4
11c8
11bc
11b0
11a4
1198
118c
1180
1174
1168
115c
1150
1144
1138
112c
1120
1114
1108
10fc
10f0
10e4
10d8
10cc
10c0
10b4
10a8
10a0
1094
1088
107c
1070
1064
1058
1050
1044
1038
102c
1020
1018
100c
1000
/sqmusic/trunk/tables/sin_table.hex
0,0 → 1,1024
10b2
d86
c0e
b16
a5c
9c8
94c
8e2
886
834
7ea
7a6
76a
730
6fc
6ca
69c
672
648
622
5fe
5da
5b8
59a
57a
55e
540
526
50c
4f2
4da
4c2
4ac
496
480
46c
458
444
430
41e
40c
3fa
3ea
3d8
3c8
3b8
3a8
39a
38a
37c
36e
360
352
344
336
32a
31e
310
304
2f8
2ee
2e2
2d6
2cc
2c0
2b6
2aa
2a0
296
28c
282
278
26e
266
25c
252
24a
242
238
230
228
21e
216
20e
206
1fe
1f6
1f0
1e8
1e0
1d8
1d2
1ca
1c4
1bc
1b6
1ae
1a8
1a2
19a
194
18e
188
182
17c
176
170
16a
164
15e
158
152
14e
148
142
13e
138
132
12e
128
124
11e
11a
114
110
10c
106
102
fe
fa
f4
f0
ec
e8
e4
e0
dc
d8
d4
d0
cc
c8
c4
c0
bc
b8
b6
b2
ae
aa
a6
a4
a0
9c
9a
96
94
90
8c
8a
86
84
80
7e
7c
78
76
72
70
6e
6a
68
66
62
60
5e
5c
5a
56
54
52
50
4e
4c
4a
48
46
44
42
40
3e
3c
3a
38
36
34
32
30
2e
2e
2c
2a
28
28
26
24
22
22
20
1e
1e
1c
1a
1a
18
18
16
14
14
12
12
10
10
e
e
e
c
c
a
a
a
8
8
8
6
6
6
4
4
4
4
2
2
2
2
2
2
2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
2
2
2
2
2
2
4
4
4
4
6
6
6
8
8
8
a
a
a
c
c
e
e
e
10
10
12
12
14
14
16
18
18
1a
1a
1c
1e
1e
20
22
22
24
26
28
28
2a
2c
2e
2e
30
32
34
36
38
3a
3c
3e
40
42
44
46
48
4a
4c
4e
50
52
54
56
5a
5c
5e
60
62
66
68
6a
6e
70
72
76
78
7c
7e
80
84
86
8a
8c
90
94
96
9a
9c
a0
a4
a6
aa
ae
b2
b6
b8
bc
c0
c4
c8
cc
d0
d4
d8
dc
e0
e4
e8
ec
f0
f4
fa
fe
102
106
10c
110
114
11a
11e
124
128
12e
132
138
13e
142
148
14e
152
158
15e
164
16a
170
176
17c
182
188
18e
194
19a
1a2
1a8
1ae
1b6
1bc
1c4
1ca
1d2
1d8
1e0
1e8
1f0
1f6
1fe
206
20e
216
21e
228
230
238
242
24a
252
25c
266
26e
278
282
28c
296
2a0
2aa
2b6
2c0
2cc
2d6
2e2
2ee
2f8
304
310
31e
32a
336
344
352
360
36e
37c
38a
39a
3a8
3b8
3c8
3d8
3ea
3fa
40c
41e
430
444
458
46c
480
496
4ac
4c2
4da
4f2
50c
526
540
55e
57a
59a
5b8
5da
5fe
622
648
672
69c
6ca
6fc
730
76a
7a6
7ea
834
886
8e2
94c
9c8
a5c
b16
c0e
d86
10b2
10b3
d87
c0f
b17
a5d
9c9
94d
8e3
887
835
7eb
7a7
76b
731
6fd
6cb
69d
673
649
623
5ff
5db
5b9
59b
57b
55f
541
527
50d
4f3
4db
4c3
4ad
497
481
46d
459
445
431
41f
40d
3fb
3eb
3d9
3c9
3b9
3a9
39b
38b
37d
36f
361
353
345
337
32b
31f
311
305
2f9
2ef
2e3
2d7
2cd
2c1
2b7
2ab
2a1
297
28d
283
279
26f
267
25d
253
24b
243
239
231
229
21f
217
20f
207
1ff
1f7
1f1
1e9
1e1
1d9
1d3
1cb
1c5
1bd
1b7
1af
1a9
1a3
19b
195
18f
189
183
17d
177
171
16b
165
15f
159
153
14f
149
143
13f
139
133
12f
129
125
11f
11b
115
111
10d
107
103
ff
fb
f5
f1
ed
e9
e5
e1
dd
d9
d5
d1
cd
c9
c5
c1
bd
b9
b7
b3
af
ab
a7
a5
a1
9d
9b
97
95
91
8d
8b
87
85
81
7f
7d
79
77
73
71
6f
6b
69
67
63
61
5f
5d
5b
57
55
53
51
4f
4d
4b
49
47
45
43
41
3f
3d
3b
39
37
35
33
31
2f
2f
2d
2b
29
29
27
25
23
23
21
1f
1f
1d
1b
1b
19
19
17
15
15
13
13
11
11
f
f
f
d
d
b
b
b
9
9
9
7
7
7
5
5
5
5
3
3
3
3
3
3
3
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
3
3
3
3
3
3
3
5
5
5
5
7
7
7
9
9
9
b
b
b
d
d
f
f
f
11
11
13
13
15
15
17
19
19
1b
1b
1d
1f
1f
21
23
23
25
27
29
29
2b
2d
2f
2f
31
33
35
37
39
3b
3d
3f
41
43
45
47
49
4b
4d
4f
51
53
55
57
5b
5d
5f
61
63
67
69
6b
6f
71
73
77
79
7d
7f
81
85
87
8b
8d
91
95
97
9b
9d
a1
a5
a7
ab
af
b3
b7
b9
bd
c1
c5
c9
cd
d1
d5
d9
dd
e1
e5
e9
ed
f1
f5
fb
ff
103
107
10d
111
115
11b
11f
125
129
12f
133
139
13f
143
149
14f
153
159
15f
165
16b
171
177
17d
183
189
18f
195
19b
1a3
1a9
1af
1b7
1bd
1c5
1cb
1d3
1d9
1e1
1e9
1f1
1f7
1ff
207
20f
217
21f
229
231
239
243
24b
253
25d
267
26f
279
283
28d
297
2a1
2ab
2b7
2c1
2cd
2d7
2e3
2ef
2f9
305
311
31f
32b
337
345
353
361
36f
37d
38b
39b
3a9
3b9
3c9
3d9
3eb
3fb
40d
41f
431
445
459
46d
481
497
4ad
4c3
4db
4f3
50d
527
541
55f
57b
59b
5b9
5db
5ff
623
649
673
69d
6cb
6fd
731
76b
7a7
7eb
835
887
8e3
94d
9c9
a5d
b17
c0f
d87
10b3
/sqmusic/trunk/ver/sq_opn_basic.v
0,0 → 1,46
/*
SQmusic
 
(c) Jose Tejada Gomez, 9th May 2013
You can use this file following the GNU GENERAL PUBLIC LICENSE version 3
Read the details of the license in:
http://www.gnu.org/licenses/gpl.txt
Send comments to: jose.tejada@ieee.org
 
*/
 
`timescale 1ns/1ps
 
module sq_opn_basic;
 
reg clk, reset_n;
 
parameter fnumber = 11'h40E;
parameter block = 3'h4;
parameter multiple= 4'h1;
 
initial begin
$dumpvars(0,sq_opn_basic);
$dumpon;
reset_n = 0;
#300 reset_n=1;
#1e8 // 10ms
$finish;
end
 
always begin
clk = 0;
forever #(125/2) clk = ~clk & reset_n;
end
 
sq_slot slot(
.clk (clk),
.reset_n (reset_n),
.fnumber (fnumber),
.block (block),
.multiple(multiple)
);
 
endmodule
/sqmusic/trunk/ver/sq_opn_basic.gather
0,0 → 1,2
sq_opn_basic.v
../sqm/sq_pg.v

powered by: WebSVN 2.1.0

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