newsAdvanced Gtk+ Sequencer - News: Delay and attack correction in GSequencer

Latest News
GSequencer version 3.10.5 released posted by jkraehemann, Sun 29 Aug 2021 07:41:14 AM UTC - 0 replies
implement VST3 C API Wrapper posted by jkraehemann, Tue 10 Aug 2021 12:53:03 PM UTC - 0 replies
refactored utility functions posted by jkraehemann, Tue 03 Aug 2021 06:26:38 AM UTC - 0 replies
GSequencer version 3.9.1 released posted by jkraehemann, Wed 30 Jun 2021 06:07:07 AM UTC - 0 replies
preparation for migration to Gtk4 posted by jkraehemann, Thu 18 Feb 2021 10:38:40 AM UTC - 0 replies
[Submit News]
[103 news in archive]

Delay and attack correction in GSequencer

Item posted by Joël Krähemann <jkraehemann> on Mon 07 Dec 2020 03:54:04 PM UTC.

This delay and attack is related to timing playing notes. A delay specifies how many times buffer_size occur until next note is played. And attack means in this context at what frame position to insert the note.

Need for correction

AgsSoundcard implementations have got an array of delay and attack sized 2 times AGS_SOUNDCARD_DEFAULT_PERIOD. But currently only fist period is used.

Assumed you have got a project with following tempo and presets:

BPM = 136
segment = 1 / 16 * 4

samplerate = 44100
buffer_size = 1024

This gives you an absolute delay of:

absolute_delay = 60.0 * ((samplerate / buffer_size) / bpm) * segment = 4.749971278

This results in a variable attack depending on offset played. This is not how things work in GSequencer.

The corrected delay

The delay is corrected in such a way that attack is periodically. This means after AGS_SOUNDCARD_DEFAULT_PERIOD times delay we obtain:

attack = 0

The magic behind attack is calculated in ags_soundcard_util.c

So we calculate the remaining frames after AGS_SOUNDCARD_DEFAULT_PERIOD and use total_correct_frame_count to adjust absolute_delay.

default_tact_frames = absolute_delay * buffer_size;

total_correct_frame_count = ((guint) AGS_SOUNDCARD_DEFAULT_PERIOD * default_tact_frames) % buffer_size;

correct_frame_count = (gdouble) total_correct_frame_count / AGS_SOUNDCARD_DEFAULT_PERIOD;

corrected_delay = absolute_delay + (correct_frame_count / buffer_size);

So our delay changes from 4.749971278 to 4.750918277. The difference is 0.000946999, resulting in a inaccuracy of approximately 1 thousandth of a segment duration.

Here we have got 8 playing keys within a second. This segment duration of 0.125 seconds divided by 1000 gives you the inaccuracy in time.

by Joël

No messages in Delay and attack correction in GSequencer


Back to the top

Powered by Savane 3.7