View Issue Details

IDProjectCategoryView StatusLast Update
0009881ardourbugspublic2025-01-20 00:22
Reportera01192025 Assigned Tox42  
PrioritynormalSeveritymajorReproducibilityalways
Status resolvedResolutionfixed 
PlatformUbuntuOSLinuxOS Version(any)
Product Version8.10 
Summary0009881: MIDI clock delivered too quickly at certain BPM settings e.g. 145 BPM
DescriptionAt 145 BPM, MIDI clock messages sent by Ardour via ALSA are delivered faster than expected. This results in an offset to the expected time that gets larger as a recording goes on. At other BPM values (e.g. 120 or 240) this does not occur.

When the MIDI clock is driving something like a hardware drum machine, any MIDI or audio recorded from that source ends up increasingly out of alignment with the measures in Ardour.

(And because the offset increases with time, there is no way to nudge recordings into place as you might do to correct a constant offset.)

Over the course of a few minutes this offset becomes conspicuously large.
Steps To ReproduceThis can be observed by setting up a hardware sequencer (in fact this is the setup where the problem was first apparent):

1) Set up a hardware sequencer (e.g. a drum machine with built in sequencer) to produce MIDI notes at a regular interval, and to accept MIDI clock from Ardour. Connect the hardware sequencer via USB MIDI.
2) Create new Ardour session using ALSA, 1024 buffer size
3) Make sure MIDI Clock is generated via Edit -> Preferences -> Transport -> Generate
4) Set BPM to 145 in Ardour
5) Set MIDI connection from MIDI clock out to the hardware sequencer via Window -> MIDI Connections (a.k.a MIDI Connection Manager), Ardour Misc + Hardware tabs
6) Create a MIDI track in Ardour, with Instrument "none", accepting MIDI input from the sequencer
7) Create an audio track in Ardour to record audio from the hardware sequencer (e.g. drum machine)
8) Begin recording

The issue has been observed with two different hardware sequencers from two different manufacturers.

A more direct way to observe this is to write a small program that accepts an ALSA MIDI connection and prints expected vs actual time of arrival of the MIDI clock, and then

1) Create new Ardour session using ALSA, 1024 buffer size
2) Make sure MIDI Clock is generated via Edit -> Preferences -> Transport -> Generate
3) Set BPM to 145 in Ardour
4) Set MIDI connection from MIDI clock out to the small program via Window -> MIDI Connections (a.k.a MIDI Connection Manager), Ardour Misc + Hardware tabs
5) Hit play in Ardour
Additional InformationExcerpt of code used to print some debug info, listening on MIDI ALSA connection, called on every MIDI clock message:

  static double secondsPerClock = 0; // Calculate this from BPM and MIDI clock ticks per quarter note
  static uint64_t chronoStart = 0;
  static int clock = 0;
  uint64_t ms = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
  if (chronoStart == 0)
    chronoStart = ms;
  double chronoTime = (ms - chronoStart) / 1000.0;
  double expectedTime = clock * secondsPerClock;
  std::cout <<
      "Clock = " << clock <<
      ", expectedTime = " << expectedTime <<
      ", chronoTime = " << chronoTime <<
      ", difference to chronoTime = " << (expectedTime-chronoTime) <<
      std::endl;
  clock++;

At 145 BPM, the "difference to chronoTime" is significant and grows over time. At 120 BPM and 240 BPM, it's much smaller to begin with and seems to bounce around while (kinda) slowly increasing.

For 120 BPM, the offset to expected is small and only slowly growing from 100 seconds to 200 seconds:
Clock = 4801, expectedTime = 100.021, chronoTime = 100.024, difference to chronoTime = -0.00316667
Clock = 9601, expectedTime = 200.021, chronoTime = 200.027, difference to chronoTime = -0.00616667

For 145 BPM, the offset is much larger and growing to non-ignorable proportions from 100 seconds to 200 seconds:
Clock = 5801, expectedTime = 100.017, chronoTime = 99.949, difference to chronoTime = 0.0682414
Clock = 11601, expectedTime = 200.017, chronoTime = 199.88, difference to chronoTime = 0.137241

At 240 BPM, the offset is a reasonably negligible size from 100 seconds to 200 seconds:
Clock = 9601, expectedTime = 100.01, chronoTime = 100.013, difference to chronoTime = -0.00258333
Clock = 19201, expectedTime = 200.01, chronoTime = 200.014, difference to chronoTime = -0.00358333

Basically a recording of several minutes ends up more than a sixteenth note out of alignment at 145 BPM.

TagsNo tags attached.

Activities

x42

2025-01-19 22:32

administrator   ~0029185

This is believed fixed since 9.0-pre0-592
https://github.com/Ardour/ardour/commit/6e2d34df2d8066bccd011ba26482e09b4d8a452f

x42

2025-01-19 22:35

administrator   ~0029186

Please test with a nightly build (https://nightly.ardour.org/) which can be installed in parallel with other versions (and comes with an uninstaller). testing with the demo version is also fine.

a01192025

2025-01-19 23:50

reporter   ~0029187

I've confirmed this is fixed in nightly 9.0.pre0.730 - thanks.

x42

2025-01-20 00:22

administrator   ~0029188

Thanks for checking!

Issue History

Date Modified Username Field Change
2025-01-19 21:44 a01192025 New Issue
2025-01-19 22:32 x42 Note Added: 0029185
2025-01-19 22:35 x42 Assigned To => x42
2025-01-19 22:35 x42 Status new => feedback
2025-01-19 22:35 x42 Note Added: 0029186
2025-01-19 23:50 a01192025 Note Added: 0029187
2025-01-19 23:50 a01192025 Status feedback => assigned
2025-01-20 00:22 x42 Status assigned => resolved
2025-01-20 00:22 x42 Resolution open => fixed
2025-01-20 00:22 x42 Note Added: 0029188