Skip to content

Commit

Permalink
Follow-up #294
Browse files Browse the repository at this point in the history
- Corrected the MTC output timing
  • Loading branch information
vanvught committed Dec 31, 2024
1 parent 2d83530 commit eb4131a
Show file tree
Hide file tree
Showing 17 changed files with 318 additions and 226 deletions.
2 changes: 1 addition & 1 deletion lib-hal/include/hardware.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ enum class Mode {

namespace hal {
#if !defined (CONFIG_HAL_TIMERS_COUNT)
# define CONFIG_HAL_TIMERS_COUNT 8
# define CONFIG_HAL_TIMERS_COUNT 12
#endif

static constexpr uint32_t SOFTWARE_TIMERS_MAX = CONFIG_HAL_TIMERS_COUNT;
Expand Down
2 changes: 1 addition & 1 deletion lib-hal/superloop/softwaretimers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ static int32_t m_nNextId;

TimerHandle_t SoftwareTimerAdd(const uint32_t nIntervalMillis, const TimerCallbackFunction_t pCallbackFunction) {
if (m_nTimersCount >= hal::SOFTWARE_TIMERS_MAX) {
#ifdef NDEBUG
#ifndef NDEBUG
console_error("SoftwareTimerAdd: Max timer limit reached\n");
#endif
return -1;
Expand Down
4 changes: 0 additions & 4 deletions lib-ltc/include/arm/artnetreader.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ class ArtNetReader {
void Stop();

void Run() {
LtcOutputs::Get()->UpdateMidiQuarterFrameMessage(reinterpret_cast<const struct ltc::TimeCode*>(&m_MidiTimeCode));

__DMB();
if (gv_ltc_nUpdatesPerSecond != 0) {
Hardware::Get()->SetMode(hardware::ledblink::Mode::DATA);
Expand All @@ -70,8 +68,6 @@ class ArtNetReader {
void Handler(const struct artnet::TimeCode *);

private:
midi::Timecode m_MidiTimeCode;

static inline ArtNetReader *s_pThis;
};

Expand Down
2 changes: 0 additions & 2 deletions lib-ltc/include/arm/ltcetcreader.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ class LtcEtcReader final : public LtcEtcHandler {
void Stop();

void Run() {
LtcOutputs::Get()->UpdateMidiQuarterFrameMessage(reinterpret_cast<const struct ltc::TimeCode *>(&m_MidiTimeCode));

__DMB();
if (gv_ltc_nUpdatesPerSecond != 0) {
Hardware::Get()->SetMode(hardware::ledblink::Mode::DATA);
Expand Down
10 changes: 5 additions & 5 deletions lib-ltc/include/arm/ltcoutputs.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class LtcOutputs {

void Init();
void Update(const struct ltc::TimeCode *ptLtcTimeCode);
void UpdateMidiQuarterFrameMessage(const struct ltc::TimeCode *ptLtcTimeCode);

void ShowSysTime();
void ShowBPM(uint32_t nBPM);
Expand All @@ -45,18 +44,19 @@ class LtcOutputs {

void Print();

static LtcOutputs* Get() {
static LtcOutputs *Get() {
return s_pThis;
}

private:
bool m_bShowSysTime;
bool m_bMidiQuarterFramePieceRunning { false };

ltc::Type m_TypePrevious { ltc::Type::INVALID };
uint32_t m_nMidiQuarterFramePiece { 0 };
uint32_t m_nRtpMidiQuarterFramePiece { 0 };
int32_t m_nSecondsPrevious { 60 };

char m_aTimeCode[ltc::timecode::CODE_MAX_LENGTH];
char m_aSystemTime[ltc::timecode::SYSTIME_MAX_LENGTH];
int32_t m_nSecondsPrevious { 60 };
char m_cBPM[9];

static inline LtcOutputs *s_pThis;
Expand Down
1 change: 0 additions & 1 deletion lib-ltc/include/arm/midireader.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class MidiReader {
void Update();

private:
midi::Timecode m_MidiTimeCode;
midi::TimecodeType m_TimeCodeType { midi::TimecodeType::UNKNOWN };
uint8_t m_nPartPrevious { 0 };
bool m_bDirection { true };
Expand Down
2 changes: 1 addition & 1 deletion lib-ltc/include/arm/systimereader.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class SystimeReader {
}

private:
void SetFps(uint8_t nFps);
void static staticCallbackFunction(const uint8_t *pBuffer, uint32_t nSize, uint32_t nFromIp, uint16_t nFromPort) {
s_pThis->Input(pBuffer, nSize, nFromIp, nFromPort);
}
Expand All @@ -63,7 +64,6 @@ class SystimeReader {
uint32_t m_nBytesReceived { 0 };
char *m_pUdpBuffer { nullptr };
time_t m_nTimePrevious { 0 };
midi::Timecode m_MidiTimeCode;
bool m_bIsStarted { false };

static inline SystimeReader *s_pThis;
Expand Down
2 changes: 0 additions & 2 deletions lib-ltc/include/arm/tcnetreader.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ class TCNetReader {
void Stop();

void Run() {
LtcOutputs::Get()->UpdateMidiQuarterFrameMessage(reinterpret_cast<const struct ltc::TimeCode*>(&m_MidiTimeCode));

__DMB();
if (gv_ltc_nUpdatesPerSecond != 0) {
Hardware::Get()->SetMode(hardware::ledblink::Mode::DATA);
Expand Down
13 changes: 7 additions & 6 deletions lib-ltc/src/arm/artnetreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,19 @@ void ArtNetReader::Stop() {
DEBUG_EXIT
}

void ArtNetReader::Handler(const struct artnet::TimeCode *ArtNetTimeCode) {
gv_ltc_nUpdates = gv_ltc_nUpdates + 1;
void ArtNetReader::Handler(const struct artnet::TimeCode *pArtNetTimeCode) {

if (!ltc::g_DisabledOutputs.bLtc) {
LtcSender::Get()->SetTimeCode(reinterpret_cast<const struct ltc::TimeCode *>(ArtNetTimeCode));
LtcSender::Get()->SetTimeCode(reinterpret_cast<const struct ltc::TimeCode *>(pArtNetTimeCode));
}

if (!ltc::g_DisabledOutputs.bEtc) {
LtcEtc::Get()->Send(reinterpret_cast<const struct midi::Timecode *>(ArtNetTimeCode));
LtcEtc::Get()->Send(reinterpret_cast<const struct midi::Timecode *>(pArtNetTimeCode));
}

memcpy(&m_MidiTimeCode, ArtNetTimeCode, sizeof(struct midi::Timecode));
memcpy(&g_ltc_LtcTimeCode, pArtNetTimeCode, sizeof(struct midi::Timecode));

LtcOutputs::Get()->Update(reinterpret_cast<const struct ltc::TimeCode *>(pArtNetTimeCode));

LtcOutputs::Get()->Update(reinterpret_cast<const struct ltc::TimeCode *>(ArtNetTimeCode));
gv_ltc_nUpdates = gv_ltc_nUpdates + 1;
}
36 changes: 13 additions & 23 deletions lib-ltc/src/arm/ltcgenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,20 +198,8 @@ void LtcGenerator::Start() {
assert(m_nHandle != -1);

LtcOutputs::Get()->Init();
LtcOutputs::Get()->Update(static_cast<const struct ltc::TimeCode *>(&g_ltc_LtcTimeCode));

if (!ltc::g_DisabledOutputs.bLtc) {
LtcSender::Get()->SetTimeCode(const_cast<const struct ltc::TimeCode*>(&g_ltc_LtcTimeCode), false);
}

if (!ltc::g_DisabledOutputs.bArtNet) {
ArtNetNode::Get()->SendTimeCode(reinterpret_cast<const struct artnet::TimeCode*>(&g_ltc_LtcTimeCode));
}

if (!ltc::g_DisabledOutputs.bEtc) {
LtcEtc::Get()->Send(reinterpret_cast<const struct midi::Timecode *>(&g_ltc_LtcTimeCode));
}

LtcOutputs::Get()->Update(const_cast<const struct ltc::TimeCode*>(&g_ltc_LtcTimeCode));
Hardware::Get()->SetMode(hardware::ledblink::Mode::NORMAL);

DEBUG_EXIT
Expand Down Expand Up @@ -385,18 +373,18 @@ void LtcGenerator::ActionSetRate(const char *pTimeCodeRate) {
#endif
//
if (!ltc::g_DisabledOutputs.bLtc) {
LtcSender::Get()->SetTimeCode(const_cast<const struct ltc::TimeCode*>(&g_ltc_LtcTimeCode), false);
LtcSender::Get()->SetTimeCode(const_cast<const struct ltc::TimeCode *>(&g_ltc_LtcTimeCode), false);
}

if (!ltc::g_DisabledOutputs.bArtNet) {
ArtNetNode::Get()->SendTimeCode(reinterpret_cast<const struct artnet::TimeCode*>(&g_ltc_LtcTimeCode));
ArtNetNode::Get()->SendTimeCode(reinterpret_cast<const struct artnet::TimeCode *>(&g_ltc_LtcTimeCode));
}

if (!ltc::g_DisabledOutputs.bEtc) {
LtcEtc::Get()->Send(reinterpret_cast<const struct midi::Timecode *>(&g_ltc_LtcTimeCode));
}

LtcOutputs::Get()->Update(const_cast<const struct ltc::TimeCode*>(&g_ltc_LtcTimeCode));
LtcOutputs::Get()->Update(const_cast<const struct ltc::TimeCode *>(&g_ltc_LtcTimeCode));
}
}

Expand Down Expand Up @@ -630,6 +618,12 @@ void LtcGenerator::Print() {
printf(" Stop : %.2d.%.2d.%.2d:%.2d\n", m_pStopLtcTimeCode->nHours, m_pStopLtcTimeCode->nMinutes, m_pStopLtcTimeCode->nSeconds, m_pStopLtcTimeCode->nFrames);
}

#if !defined(__clang__)
# pragma GCC push_options
# pragma GCC optimize ("O3")
# pragma GCC optimize ("no-tree-loop-distribute-patterns")
#endif

void LtcGenerator::Increment() {
if ((!m_bIgnoreStop) && (__builtin_expect((memcmp(&g_ltc_LtcTimeCode, m_pStopLtcTimeCode, sizeof(struct ltc::TimeCode)) == 0), 0))) {
if (m_State == STARTED) {
Expand Down Expand Up @@ -729,27 +723,23 @@ void LtcGenerator::SetTimeCode(int32_t nSeconds) {
}

void LtcGenerator::Update() {
if (m_State != STOPPED) {
LtcOutputs::Get()->UpdateMidiQuarterFrameMessage(const_cast<const struct ltc::TimeCode*>(&g_ltc_LtcTimeCode));
}

__DMB();
if (gv_ltc_bTimeCodeAvailable) {
gv_ltc_bTimeCodeAvailable = false;

if (!ltc::g_DisabledOutputs.bLtc) {
LtcSender::Get()->SetTimeCode(static_cast<const struct ltc::TimeCode*>(&g_ltc_LtcTimeCode), false);
LtcSender::Get()->SetTimeCode(static_cast<const struct ltc::TimeCode *>(&g_ltc_LtcTimeCode), false);
}

if (!ltc::g_DisabledOutputs.bArtNet) {
ArtNetNode::Get()->SendTimeCode(reinterpret_cast<const struct artnet::TimeCode*>(&g_ltc_LtcTimeCode));
ArtNetNode::Get()->SendTimeCode(reinterpret_cast<const struct artnet::TimeCode *>(&g_ltc_LtcTimeCode));
}

if (!ltc::g_DisabledOutputs.bEtc) {
LtcEtc::Get()->Send(reinterpret_cast<const struct midi::Timecode *>(&g_ltc_LtcTimeCode));
}

LtcOutputs::Get()->Update(static_cast<const struct ltc::TimeCode*>(&g_ltc_LtcTimeCode));
LtcOutputs::Get()->Update(static_cast<const struct ltc::TimeCode *>(&g_ltc_LtcTimeCode));

if (__builtin_expect((m_tDirection == ltcgenerator::Direction::DIRECTION_FORWARD), 1)) {
if (__builtin_expect((m_tPitch == ltcgenerator::Pitch::PITCH_NORMAL), 1)) {
Expand Down
Loading

0 comments on commit eb4131a

Please sign in to comment.