Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scsynth: PanAz: fix leaks and imprecisions #4971

Merged
merged 1 commit into from
Oct 21, 2022

Conversation

elgiano
Copy link
Contributor

@elgiano elgiano commented May 25, 2020

PanAz was having a small leak into adjacent-to-focused channels, due to
both an imprecision in sc_reciprocal and in ft->mSine. This fixes it
without touching either of the two.

Purpose and Motivation

Fixes #4970

if (chanpos > 1.f) {

Changing this to >= 1.f should fix it. ft->mSine[4096] should be zero (even if it is a very small number instead), so it makes sense to shortcut to 0 IMO.
However, due to an imprecision in float32 sc_reciprocal(), chanpos ends up not being == 1.f and so this fix doesn't work.
// 23 bit accuracy (out of 24bit)

It works however if the float64 version of sc_reciprocal is used.

I've checked other UGens usage of sc_reciprocal, I think this small imprecision causes problems only when it gets into an equality comparison, and PanAz is the only UGen doing that.

Types of changes

  • Bug fix
  • Breaking Change?
    Is this a breaking change? e.g I have several past projects where I adjusted panning positions by a small amount to account for this error.

To-do list

  • Code is tested
  • All tests are passing
  • This PR is ready for review

jrsurge
jrsurge previously requested changes Jun 2, 2020
Copy link
Member

@jrsurge jrsurge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this!

I haven't reviewed the functionality but I do have some questions from reading through the code.

There are a few points of implicit type conversion and I can't tell by looking at the code what is intentional - if I understand correctly, the error you're fixing was a result of incorrect precision, so I think it's important any precision changes are explicit so we know what behaviour is intended. I've marked all the points I could find where precision is possibly lost by implicit conversion.

I'd probably recommend having everything as double and casting as late as possible, rather than a bunch of casts everywhere.

Also, an optional question about the terminology in the tests - it doesn't block the PR at all, just a thought.

server/plugins/PanUGens.cpp Outdated Show resolved Hide resolved
server/plugins/PanUGens.cpp Outdated Show resolved Hide resolved
server/plugins/PanUGens.cpp Show resolved Hide resolved
server/plugins/PanUGens.cpp Outdated Show resolved Hide resolved
server/plugins/PanUGens.cpp Outdated Show resolved Hide resolved
server/plugins/PanUGens.cpp Show resolved Hide resolved
server/plugins/PanUGens.cpp Outdated Show resolved Hide resolved
server/plugins/PanUGens.cpp Outdated Show resolved Hide resolved
testsuite/classlibrary/TestPanAz.sc Show resolved Hide resolved
@elgiano elgiano force-pushed the panaz_correction branch from f2f035c to 9547a72 Compare June 2, 2020 20:25
Copy link
Contributor

@mossheim mossheim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks good to me, but i am not an expert with DSP code. @jrsurge would you like to review again?

@jrsurge
Copy link
Member

jrsurge commented Jun 9, 2020

@elgiano thanks for the quick response to review, greatly appreciated!
Apologies for the delay in moving forward on this.
I still have to test the functionality, but I'm reasonably confident in the code.

@brianlheim, I was wondering if this needed to wait for consensus on changes to UGens? (#4976)
Changing the behaviour of the panning seems like a breaking change to me, even though it's a fix?

@mossheim
Copy link
Contributor

I was wondering if this needed to wait for consensus on changes to UGens?

we already have a consensus as far as i'm concerned, i just haven't closed the issue yet. :)

PanAz was having a small leak into adjacent-to-focused channels, due to
both an imprecision in sc_reciprocal and in ft->mSine. This fixes it
without touching either of the two.
@mossheim
Copy link
Contributor

mossheim commented Aug 9, 2020

@jrsurge ready for another review when you're ready. :)

@elgiano
Copy link
Contributor Author

elgiano commented Aug 10, 2020

@jrsurge @brianlheim I don't know why Travis failed, but it doesn't look like it's related to anything in this PR :)

@mossheim
Copy link
Contributor

@elgiano yeah. you should be able to restart jobs in travis now if you link your account there to your github account. feel free to restart when you think a failure is spurious. if it looks like it's something that could be avoided, leave a note on the PR. this one seems like brew just froze midway through updating, nothing we can do.

@elgiano elgiano requested a review from jrsurge December 8, 2021 00:54
@elgiano
Copy link
Contributor Author

elgiano commented Feb 10, 2022

@jrsurge
Hi James, sorry to bother you, just a reminder that this PR is still open waiting for you to approve some changes you requested.

The only pending issue is if we want to do everything with doubles or only cast around the use of sc_reciprocal where we need more precision. I prefer the second (as it is now), because it results in a lower number of casts overall.

@joshpar
Copy link
Member

joshpar commented Aug 15, 2022

Hi all - we'd like to pull this in for 3.13.0 and are planning an RC for that after our meeting on Aug, 27, 2022. Anything else to add? Or can we close this?

@joshpar joshpar dismissed jrsurge’s stale review October 21, 2022 21:39

Looks ok on our side for now. Thanks James!

@joshpar joshpar merged commit 0e7d2db into supercollider:develop Oct 21, 2022
@elgiano elgiano deleted the panaz_correction branch October 26, 2022 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PanAz pos imprecision
4 participants