Skip to content

Commit

Permalink
algorithm is working :)
Browse files Browse the repository at this point in the history
  • Loading branch information
jwcxz committed Apr 26, 2013
1 parent 1dd5a9e commit 7af8157
Show file tree
Hide file tree
Showing 13 changed files with 13,244 additions and 1,405 deletions.
2 changes: 1 addition & 1 deletion bsv/BeatClassifier.bsv
Expand Up @@ -71,7 +71,7 @@ module mkBeatClassifierTest(BeatClassifier);
Reg#(PulserCount) mpc <- mkReg(0);
Reg#(Bool) tick <- mkReg(False);

Reg#(TempoIncrement) increment <- mkReg(calc_tempo_increment(120));
Reg#(TempoIncrement) increment <- mkReg(calc_tempo_increment(125/4.0));
Reg#(MetronomeCounter) counter <- mkReg(0);

rule ignore(True);
Expand Down
46 changes: 14 additions & 32 deletions bsv/BeatTracker.bsv
Expand Up @@ -37,14 +37,14 @@ module mkBeatTracker(BeatTracker);
Reg#(UInt#(TLog#(TAdd#(NumMetronomes,1)))) mb_out_count <- mkReg(0);

rule init(!init_done);
//*
mb[0].set_tempo(calc_tempo_increment(120));
mb[1].set_tempo(calc_tempo_increment(130));
mb[2].set_tempo(calc_tempo_increment(140));
mb[3].set_tempo(calc_tempo_increment(150));
/*
mb[0].set_tempo(calc_tempo_increment(150));
mb[1].set_tempo(calc_tempo_increment(140));
mb[2].set_tempo(calc_tempo_increment(130));
mb[3].set_tempo(calc_tempo_increment(120));
// */

/* {{{
//* {{{
for (Integer m=0; m<valueof(NumMetronomes); m=m+1) begin
mb[m].set_tempo(calc_tempo_increment(min_tempo+fromInteger(m)));
end
Expand Down Expand Up @@ -81,20 +81,19 @@ module mkBeatTracker(BeatTracker);
if ( mb_out_count == fromInteger(valueof(TSub#(NumMetronomes, 1))) ) begin
mb_out_count <= fromInteger(0);
sync_next <= False;
end else begin
mb_out_count <= mb_out_count + fromInteger(1);
end
end
let x <- mb[mb_out_count].inject_beat(beat_guess_i);
TopLvlOut dout = pack(x)[valueof(MetronomeCounterSize)-1:valueof(MetronomeCounterSize)-8];
if (sync_next) bt_info.enq(dout);
if (sync_next) bt_info.enq(make_output(x));
endrule
// }}} */


//* {{{
/* {{{
rule beat_injector_start(init_done && mb_out_count == fromInteger(0));
let beat_guess_i <- bc.response.get();
beat_guess <= beat_guess_i;
Expand All @@ -120,54 +119,37 @@ module mkBeatTracker(BeatTracker);
// }}} */


/* {{{
//* {{{
rule beat_injector_start(init_done && mb_out_count == fromInteger(0));
let beat_guess_i <- bc.response.get();
beat_guess <= beat_guess_i;

let x <- mb[0].inject_beat(beat_guess_i);
if (sync_next) bt_info.enq(make_output(x));

sync_this <= sync_next;
sync_next <= False;

if (valueof(NumMetronomes) > 1) begin
mb_out_count <= fromInteger(1);
end else begin
sync_next <= False;
end
endrule

rule beat_injector_cont(init_done &&
mb_out_count > fromInteger(0) &&
mb_out_count < fromInteger(valueof(NumMetronomes)));
let x <- mb[mb_out_count].inject_beat(beat_guess);
if (sync_next) bt_info.enq(make_output(x));
if (sync_this) bt_info.enq(make_output(x));

if ( mb_out_count == fromInteger(valueof(TSub#(NumMetronomes, 1))) ) begin
mb_out_count <= fromInteger(0);
sync_next <= False;
end else begin
mb_out_count <= mb_out_count + fromInteger(1);
end
endrule
// }}} */


/* {{{
rule beat_injector(init_done);
let beat_info <- bc.response.get();
for (Integer m=0; m<valueof(NumMetronomes); m=m+1) begin
let x <- mb[m].inject_beat(beat_info);
bt_info.enq(pack(x));
if (m==0) begin
bt_info.enq(pack(x));
end
end
endrule
// }}} */


method Action q_sync() if (!sync_next);
sync_next <= True;
endmethod
Expand Down
8 changes: 4 additions & 4 deletions bsv/Types.bsv
Expand Up @@ -7,16 +7,16 @@ import FShow::*;
Real clk_freq = 25e6;
Real min_tempo = 120;

typedef 4 NumMetronomes;
typedef 60 NumMetronomes;

// number of samples to store in energy calculation buffer
typedef 12 SampleCountSize;

// metronome pulse frequency: clk_freq / 2**MetronomePulseCountSize
typedef 11 PulserCountSize;
typedef 10 PulserCountSize;

// resolution of metronome counter
typedef 20 MetronomeCounterSize;
typedef 21 MetronomeCounterSize;



Expand Down Expand Up @@ -54,7 +54,7 @@ typedef MetronomeCounter PhaseErr;
// Functions
function TempoIncrement calc_tempo_increment (Real tempo);
Real pulse_freq = clk_freq * 1/fromInteger(pulser_count_max+1);
Real increment = tempo * 1/60.0 * (1/pulse_freq) * fromInteger(metronome_counter_max+1);
Real increment = tempo * 4.0 * 1/60.0 * (1/pulse_freq) * fromInteger(metronome_counter_max+1);

TempoIncrement ti = fromInteger(round(increment));
return ti;
Expand Down
Binary file modified fpga/bsc/BeatClassifier.bo
Binary file not shown.
Binary file modified fpga/bsc/BeatTracker.bo
Binary file not shown.
Binary file modified fpga/bsc/Metronome.bo
Binary file not shown.
Binary file modified fpga/bsc/Types.bo
Binary file not shown.
Binary file modified fpga/bsc/mkBeatTracker.ba
Binary file not shown.

0 comments on commit 7af8157

Please sign in to comment.