supercollider
supercollider copied to clipboard
sclang: fix signal_thresh_xf typo
Purpose and Motivation
When calling .thresh
on a Signal, the supplied threshold is squared:
Signal.sineFill(1024, [1]).thresh(0.5).reject(_==0).minItem
// -> ~0.25
// Signal.thresh zeroes out everything below threshold.squared?
// as expected SimpleNumber.thresh zeroes out everything below a threshold
({1.0.rand2}!1024).thresh(0.5).reject(_==0).minItem
// -> ~0.5
I would expect thresh
to do the same operation on SimpleNumbers and Signals. Am I missing something?
The threshold gets squared only for signal_thresh_fx, in lang/LangSource/PyrSignal.cpp
:
https://github.com/supercollider/supercollider/blob/6de068ba83587d33d06d1b21f99b7a73ef5d8997/lang/LangSource/PyrSignal.cpp#L216
It looks like a copy-paste leftover from signal_ring4_xf, which is just above. Removing this line produces the expected behavior.
Types of changes
- Bug fix
To-do list
- [x] Code is tested
- [x] All tests are passing
- [ ] Updated documentation
- [x] This PR is ready for review
I think we could put a note that the function had a bug until the version where we fix it, like https://doc.sccode.org/Classes/Buffer.html#-cheby
What do you think about something like this? @joshpar
note::
In older versions, this function was implemented incorrectly, evaluating the square of provided threshold. This behavior is fixed starting from SuperCollider 3.13. However, note that older code might now give different results.
::
@dyfer
However, I'm not sure why is this labeled as API change. Doesn't "API change" only refer to changes to files in include
?
I'm not sure why is this labeled as API change. Doesn't "API change" only refer to changes to files in include?
No. If there's version A and version B, and you run the same sclang code in both versions but the result is different (or the same server messages), that's an API change.
@elgiano could you add the note in the documentation? I have a suggestion to put the version at the beginning of the sentence, what do you think?
note::
Before SuperCollider 3.13 this function was implemented incorrectly, evaluating the square of provided threshold. This behavior is now fixed, but note that older code might give different results.
::
Sure, but we miss the whole method, so I put this:
method::thresh
Thresholding replaces every value < threshold with 0.
note::
Before SuperCollider 3.13 this function was implemented incorrectly, evaluating the square of provided threshold. This behavior is now fixed, but note that older code might give different results.
::
I've also put it to the top of the list of Binary Messages
is it would be the only one with a description.
Thanks @elgiano !