Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jotego committed Nov 5, 2018
1 parent 34f63e0 commit 46809cc
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 17 deletions.
20 changes: 10 additions & 10 deletions hdl/jt12_pg_inc.v
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ module jt12_pg_inc (
output reg [16:0] phinc_pure
);

reg [10:0] fnum_mod;
reg [11:0] fnum_mod;

always @(*) begin
fnum_mod = fnum + {{3{pm_offset[7]}},pm_offset};
fnum_mod = {fnum,1'b0} + {{4{pm_offset[7]}},pm_offset};
case ( block )
3'd0: phinc_pure = { 7'd0, fnum_mod[10:1] };
3'd1: phinc_pure = { 6'd0, fnum_mod };
3'd2: phinc_pure = { 5'd0, fnum_mod, 1'd0 };
3'd3: phinc_pure = { 4'd0, fnum_mod, 2'd0 };
3'd4: phinc_pure = { 3'd0, fnum_mod, 3'd0 };
3'd5: phinc_pure = { 2'd0, fnum_mod, 4'd0 };
3'd6: phinc_pure = { 1'd0, fnum_mod, 5'd0 };
3'd7: phinc_pure = { fnum_mod, 6'd0 };
3'd0: phinc_pure = { 7'd0, fnum_mod[11:2] };
3'd1: phinc_pure = { 6'd0, fnum_mod[11:1] };
3'd2: phinc_pure = { 5'd0, fnum_mod[11:0] };
3'd3: phinc_pure = { 4'd0, fnum_mod, 1'd0 };
3'd4: phinc_pure = { 3'd0, fnum_mod, 2'd0 };
3'd5: phinc_pure = { 2'd0, fnum_mod, 3'd0 };
3'd6: phinc_pure = { 1'd0, fnum_mod, 4'd0 };
3'd7: phinc_pure = { fnum_mod, 5'd0 };
endcase
end

Expand Down
6 changes: 3 additions & 3 deletions hdl/jt12_pg_sum.v
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ module jt12_pg_sum (
output reg [ 9:0] phase_op
);

reg [16:0] phinc_premul;
reg [16:0] phinc_premul;
reg [19:0] phinc_mul;

always @(*) begin
phinc_premul = phinc_pure + {{11{detune_signed[5]}},detune_signed};
phinc_mul = ( mul==4'd0 ) ? {4'b0,phinc_premul[16:1]} : (phinc_premul * mul);
phinc_mul = ( mul==4'd0 ) ? {4'b0,phinc_premul[16:1]} : ({3'd0,phinc_premul} * mul);

phase_out = pg_rst ? 20'd0 : (phase_in + phinc_mul);
phase_out = pg_rst ? 20'd0 : (phase_in + { phinc_mul});
phase_op = phase_out[19:10];
end

Expand Down
5 changes: 3 additions & 2 deletions ver/jt12_pg_comb_tb/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,10 @@ int main(int argc, char *argv[]) {
continue;
}
if( strcmp(argv[k],"-pms")==0 ) {
if( ++k==argc ) { cerr << "ERROR: expecting pms (0-15) after -pms argument\n"; return 3; }
if( ++k==argc ) { cerr << "ERROR: expecting pms (0-7) after -pms argument\n"; return 3; }
if( sscanf( argv[k], "%d", &pms)!=1 ) { cerr << "ERROR: expecting pms (0-7) after -pms argument\n"; return 3; }
if( pms<0 || pms>7 ) { cerr << "ERROR: expecting pms (0-7) after -pms argument\n"; return 3; }
do_pm = true;
continue;
}
cout << "ERROR: unknown argument " << argv[k] << '\n';
Expand All @@ -179,7 +180,7 @@ int main(int argc, char *argv[]) {
top.phase_in = 0;
float base_freq = get_freq(top);

printf("(%2d) %d,%2d,%4d,", top.mul, top.block, top.keycode&3, top.fnum );
printf("(%2d) %d,%2d, %4d,", top.mul, top.block, top.keycode&3, top.fnum );
printf("%4.1fHz -> ", base_freq );
if( do_detune ) {
for( top.detune=1; top.detune<8; top.detune++ ) {
Expand Down
48 changes: 48 additions & 0 deletions ver/jt12_pg_comb_tb/test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

module test(
input [ 2:0] block,
input [10:0] fnum,
// Phase Modulation
input [ 4:0] lfo_mod,
input [ 2:0] pms,
// Detune
input [ 2:0] detune,

output [ 4:0] keycode,
// Phase add
input [ 3:0] mul,
input [19:0] phase_in,
input pg_rst,

output [19:0] phase_out,
output [ 9:0] phase_op
);

wire signed [ 5:0] dt;
wire [16:0] phinc;

jt12_pg_comb u_uut(
.block ( block ),
.fnum ( fnum ),
// Phase Modulation
.lfo_mod ( lfo_mod ),
.pms ( pms ),
// Detune
.detune ( detune ),

.keycode ( keycode ),
.detune_out ( dt ),
// Phase increment
.phinc_out ( phinc ),
// Phase add
.mul ( mul ),
.phase_in ( phase_in ),
.pg_rst ( pg_rst ),
.detune_in ( dt ),
.phinc_in ( phinc ),

.phase_out ( phase_out ),
.phase_op ( phase_op )
);

endmodule;
32 changes: 30 additions & 2 deletions ver/verilator/jt12_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ class SimTime {
else {
main_time = main_next;
if( --verbose_ticks == 0 ) {
cerr << "Current time " << dec << (int)(main_time/1000000) << " ms\n";
// cerr << "Current time " << dec << (int)(main_time/1000000) << " ms\n";
cerr << '.';
verbose_ticks = 48000*24/2;
}
toggle=false;
Expand Down Expand Up @@ -218,6 +219,30 @@ int main(int argc, char** argv, char** env) {
}
continue;
}
if( string(argv[k])=="-only") {
int ch;
if( sscanf(argv[++k],"%d",&ch) != 1 ) {
cout << "ERROR: needs channel number after -only\n";
return 1;
}
if( ch<0 || ch>5 ) {
cout << "ERROR: channel must be within 0-5 range\n";
return 1;
}
cout << "Only channel " << ch << " will be played\n";
for( int k=0; k<6; k++ ) {
if( k==ch ) continue;
switch(k) {
case 0: writter.block( 0xFF, 0x28, [](int v)->int{ return (v&0xf)==0? 0 : v;} ); break;
case 1: writter.block( 0xFF, 0x28, [](int v)->int{ return (v&0xf)==1? 0 : v;} ); break;
case 2: writter.block( 0xFF, 0x28, [](int v)->int{ return (v&0xf)==2? 0 : v;} ); break;
case 3: writter.block( 0xFF, 0x28, [](int v)->int{ return (v&0xf)==4? 0 : v;} ); break;
case 4: writter.block( 0xFF, 0x28, [](int v)->int{ return (v&0xf)==5? 0 : v;} ); break;
case 5: writter.block( 0xFF, 0x28, [](int v)->int{ return (v&0xf)==6? 0 : v;} ); break;
}
}
continue;
}
cout << "ERROR: Unknown argument " << argv[k] << "\n";
return 1;
}
Expand Down Expand Up @@ -374,7 +399,10 @@ int main(int argc, char** argv, char** env) {


void WaveWritter::write( int16_t* lr ) {
fsnd.write( (char*)lr, sizeof(int16_t)*2 );
int16_t g[2];
g[0] = lr[0]<<2;
g[1] = lr[1]<<2;
fsnd.write( (char*)&g, sizeof(int16_t)*2 );
}

WaveWritter::WaveWritter(const char *filename) {
Expand Down

0 comments on commit 46809cc

Please sign in to comment.