How does the new sv_get_time_map() DLL method work?

Multi-platform modular music creation studio
Post Reply
grig
Posts: 14
Joined: Tue Nov 12, 2019 12:31 am

How does the new sv_get_time_map() DLL method work?

Post by grig »

How does sv_get_time_map() work? How do I unpack and use the buffer of map values?

I would like to trigger an event at exactly the right interval to be in time with the beat, at any BPM, using sv_set_event_t().

It's seems that a tick is not always the same duration in seconds. Correct?

Can I use this to calculate the duration in ticks before the end of a loop? Is it more accurate if the number of lines read is small (shorter amounts of time)?

What if I wanted to trigger a loaded SunSynth module? Does it have an independent tick duration?

Code: Select all

...

/* Flags for sv_get_time_map(): */
#define SV_TIME_MAP_SPEED	0
#define SV_TIME_MAP_FRAMECNT	1
#define SV_TIME_MAP_TYPE_MASK	3

...

/*
   sv_get_time_map()
   Parameters:
     slot;
     start_line - first line to read (usually 0);
     len - number of lines to read;
     dest - pointer to the buffer (size = len*sizeof(uint32_t)) for storing the map values;
     flags:
       SV_TIME_MAP_SPEED: dest[X] = BPM | ( TPL << 16 ) (speed at the beginning of line X);
       SV_TIME_MAP_FRAMECNT: dest[X] = frame counter at the beginning of line X;
   Return value: 0 if successful, or negative value in case of some error.
*/
int sv_get_time_map( int slot, int start_line, int len, uint32_t* dest, int flags ) SUNVOX_FN_ATTR;

...


Thank you!
User avatar
NightRadio
Site Admin
Posts: 3954
Joined: Fri Jan 23, 2004 12:28 am
Location: Ekaterinburg. Russia
Contact:

Re: How does the new sv_get_time_map() DLL method work?

Post by NightRadio »

How does sv_get_time_map() work? How do I unpack and use the buffer of map values?
If you want to know where the BPM and/or TPL are changing:

Code: Select all

int len = 32;
uint32_t map[ len ]; //map for 32 lines
sv_get_time_map( slot, 0, len, &map, SV_TIME_MAP_SPEED ); //get BPM+TPL
int v = map[ 4 ]; //BPM+TPL on line 4
int bpm = v & 0xFFFF; //BPM on line 4
int tpl = ( v >> 16 ) & 0xFFFF; //TPL on line 4
If you want to know the length (in frames or seconds) of some project intervals:

Code: Select all

int len = 32;
uint32_t map[ len ]; //map for 32 lines
sv_get_time_map( slot, 0, len, &map, SV_TIME_MAP_FRAMECNT ); //get frame counter
int f = map[ 4 ]; //frame counter on line 4
//map[ 0 ] is always 0, because the frame counter starts from zero
//length of the first 32 lines in seconds = ( map[ 32 ] - map[ 0 ] ) * 1000 / sample_rate;
//frame length in seconds = 1 / sample_rate

It's seems that a tick is not always the same duration in seconds. Correct?
Probably you confuses two different time spaces

1) System time space for sv_set_event_t(), sv_get_ticks(), sv_get_ticks_per_second()
The system tick duration (in seconds) is always the same on the same system: = 1 / sv_get_ticks_per_second().
Current system time in ticks = sv_get_ticks().

2) Project time space: frame counter, ticks, beats.
Project tick length in milliseconds = 60000 / BPM / 24
grig
Posts: 14
Joined: Tue Nov 12, 2019 12:31 am

Re: How does the new sv_get_time_map() DLL method work?

Post by grig »

Thank you!
Post Reply