Old 06-26-2018, 04:25 AM   #1
geraintluff
Human being with feelings
 
geraintluff's Avatar
 
Join Date: Nov 2009
Location: mostly inside my own head
Posts: 348
Default JSFX: srate=0 in @init

I have found some weird behaviour in JSFX, weird enough that I think it's a bug.

Description

Under certain circumstances, "srate" is = 0 in @init when triggered by play/seek. I have narrowed down a set of conditions where I can reproduce it - it only happens for me if all three are met:
  • Latency must be non-zero (e.g. place "Time Adjustment Delay" with negative delay before effect)
  • The JSFX must have its interface visible
  • The JSFX must have a @gfx section defined
Under these circumstances, most of the time I observe two @init calls happening on play/seek - once with srate=0, the immediately afterwards with a proper value.

Here are some screenshots (or backup link) illustrating the issue, including the fact that it doesn't happen if the conditions above are not met.

Expected Behaviour

I expected srate to be reliably non-zero. It is under all other circumstances I have found.

Consequences

Some of my @gfx code assumed/required srate-derived values to be non-zero in order to terminate. This meant REAPER would sometimes became unresponsive and needed to be forced closed (losing project state) upon play/seek.

The hang is inconsistent because the @gfx call needs to happen at exactly the right time (between two @init executions), and is project-specific (because it requires some latency from earlier effects).

Workaround

I can add this line to @init:
Code:
!srate ? srate = 44100;
This fixes the problem and makes all my srate-derived values sane, but it's a weird thing to put in all of my effects.

Since there is immediately another call to @init (with a non-zero srate value) it doesn't matter whether this value is accurate, it just should be plausible (non-zero) to avoid problems in @gfx.

Steps to reproduce

Place the built-in "Time Adjustment Delay" with the delay time set to -1000ms.

After that, add the debugging effect below. Open up the debugger, repeatedly hit play/pause, and observe the values of debug.srateN.

Here is a debugging JSFX that lets you see the 6 most recent srate values in the debugger:
Code:
desc:srate logger

@init
// Show the last 6 srate values in the debugger
debug.srate6 = debug.srate5;
debug.srate5 = debug.srate4;
debug.srate4 = debug.srate3;
debug.srate3 = debug.srate2;
debug.srate2 = debug.srate;
debug.srate = srate;
 
@serialize
// stop it from resetting the variables on playback start
foo = 1;

@gfx
// Block must be defined for the bug to appear - actual content isn't relevant
gfx_r = rand();
gfx_g = rand();
gfx_b = rand();
gfx_a = 1;
gfx_rect(gfx_w*rand(), gfx_h*rand(), 10, 10);
System

Found with REAPER v5.92/64 on Mac (OS X El Capitan, 10.11.6).
__________________
JSFX set | Bandcamp/SoundCloud/Spotify

Last edited by geraintluff; 06-26-2018 at 10:34 AM.
geraintluff is online now   Reply With Quote
Old 06-26-2018, 08:16 AM   #2
mschnell
Human being with feelings
 
mschnell's Avatar
 
Join Date: Jun 2013
Location: Krefeld, Germany
Posts: 14,789
Default

AFAIK it's somewhere documented that srate might not yet be set in @init.

> srate = srate || 44100;

This does not make much sense.

-Michael
mschnell is online now   Reply With Quote
Old 06-26-2018, 09:14 AM   #3
geraintluff
Human being with feelings
 
geraintluff's Avatar
 
Join Date: Nov 2009
Location: mostly inside my own head
Posts: 348
Default

Quote:
Originally Posted by mschnell View Post
AFAIK it's somewhere documented that srate might not yet be set in @init.

> srate = srate || 44100;

This does not make much sense.

-Michael
Thanks, fixed - I was writing JavaScript at the same time and typed the wrong thing out. The docs also list srate as a "read-only" variable, but that only seems to mean that changes to it won't persist (or change the audio config or whatever).

I couldn't find that warning. It does ring a bell, but there's something in the docs that says that you're not guaranteed an @init call when samplerate changes, and I could be thinking of that.

If it was on first-load, that would also make a bit of sense to me (although again, some dummy default samplerate would be better). It's the way that it flips back to 0 when everything is set up that confuses me.
__________________
JSFX set | Bandcamp/SoundCloud/Spotify

Last edited by geraintluff; 06-26-2018 at 10:34 AM.
geraintluff is online now   Reply With Quote
Old 06-26-2018, 12:55 PM   #4
mschnell
Human being with feelings
 
mschnell's Avatar
 
Join Date: Jun 2013
Location: Krefeld, Germany
Posts: 14,789
Default

Quote:
Originally Posted by geraintluff View Post
some dummy default samplerate would be better....
mysrate = srate ? srate : 44100;

-Michael
mschnell is online now   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 06:29 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.