From f76387110606c8ac99e9d00427c61f79d00a1e84 Mon Sep 17 00:00:00 2001 From: Jay Robson Date: Thu, 3 Oct 2024 22:43:23 +1000 Subject: [PATCH] instruction improvements --- src/packet.cpp | 10 +++++----- src/packet.hpp | 4 +++- src/scheduler.cpp | 23 ++++++++++++++++++++--- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/packet.cpp b/src/packet.cpp index 5656dfc..f92d5b5 100644 --- a/src/packet.cpp +++ b/src/packet.cpp @@ -19,9 +19,8 @@ void packet::Clear::finalise(std::ostream& dst) const { void packet::ClearTS::finalise(std::ostream& dst) const { uint64_t v = Type::clear_ts & bm(3); v = (v << 5) | (index & bm(5)); - v = (v << 18) | (ticks & bm(18)); - v <<= 6; - output(dst, v, 4); + v = (v << 16) | (ticks & bm(16)); + output(dst, v, 3); } void packet::Set::finalise(std::ostream& dst) const { @@ -29,16 +28,17 @@ void packet::Set::finalise(std::ostream& dst) const { v = (v << 5) | (index & bm(5)); v = (v << 12) | (frequency & bm(12)); v = (v << 2) | (mode & bm(2)); - v <<= 2; + v = (v << 2) | (gain & bm(2)); output(dst, v, 3); } void packet::SetTS::finalise(std::ostream& dst) const { uint64_t v = Type::set_ts & bm(3); v = (v << 5) | (index & bm(5)); - v = (v << 18) | (ticks & bm(18)); + v = (v << 16) | (ticks & bm(16)); v = (v << 12) | (frequency & bm(12)); v = (v << 2) | (mode & bm(2)); + v = (v << 2) | (gain & bm(2)); output(dst, v, 5); } diff --git a/src/packet.hpp b/src/packet.hpp index 332c711..178f9e0 100644 --- a/src/packet.hpp +++ b/src/packet.hpp @@ -30,6 +30,7 @@ namespace packet { unsigned index; unsigned frequency; ToneType mode; + unsigned gain; void finalise(std::ostream& dst) const; }; @@ -39,6 +40,7 @@ namespace packet { unsigned ticks; unsigned frequency; ToneType mode; + unsigned gain; void finalise(std::ostream& dst) const; }; @@ -69,7 +71,7 @@ namespace packet { case Type::clear: return 1; case Type::clear_ts: - return 4; + return 3; case Type::set: return 3; case Type::set_ts: diff --git a/src/scheduler.cpp b/src/scheduler.cpp index f934803..8da7b73 100644 --- a/src/scheduler.cpp +++ b/src/scheduler.cpp @@ -31,7 +31,7 @@ bool Scheduler::add_note(unsigned key_id, unsigned ticks, bool state, packet::To if(ticks_at >= ticks) { packets.push_back({.type=packet::Type::clear, .clear={.index=channel}}); } else { - packets.push_back({.type=packet::Type::clear_ts, .clear_ts={.index=channel, .ticks=ticks}}); + packets.push_back({.type=packet::Type::clear_ts, .clear_ts={.index=channel, .ticks=ticks - ticks_at}}); ticks_at = ticks; } return true; @@ -55,9 +55,26 @@ bool Scheduler::add_note(unsigned key_id, unsigned ticks, bool state, packet::To } if(ticks_at >= ticks) { - packets.push_back({.type=packet::Type::set, .set={.index=channel_id, .frequency=key::get_freq(key_id), .mode=mode}}); + packets.push_back({ + .type=packet::Type::set, + .set={ + .index=channel_id, + .frequency=key::get_freq(key_id), + .mode=mode, + .gain=0, + }, + }); } else { - packets.push_back({.type=packet::Type::set_ts, .set_ts={.index=channel_id, .ticks=ticks, .frequency=key::get_freq(key_id), .mode=mode}}); + packets.push_back({ + .type=packet::Type::set_ts, + .set_ts={ + .index=channel_id, + .ticks=ticks - ticks_at, + .frequency=key::get_freq(key_id), + .mode=mode, + .gain=0, + }, + }); ticks_at = ticks; }