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

LinXFade2 pans backward in at least some cases #1294

Closed
jamshark70 opened this issue Jan 22, 2015 · 3 comments
Closed

LinXFade2 pans backward in at least some cases #1294

jamshark70 opened this issue Jan 22, 2015 · 3 comments
Assignees
Labels
bug Issues that relate to unexpected/unwanted behavior. Don't use for PRs. comp: server plugins

Comments

@jamshark70
Copy link
Contributor

OK, this is really patently obviously a bug.

a = {
    var a = DC.kr(0), b = DC.kr(1), iTrig = Trig1.kr(Impulse.kr(0), 1);
    Poll.kr(iTrig, LinXFade2.kr(a, b, -1));
    FreeSelf.kr(iTrig <= 0);
    Silent.ar(1)
}.play;

--> UGen(LinXFade2): 1

Pan position -1 should output a's value (0), decidedly not b.

There is some weird chicanery in the source code, about flipping the pan position backward -- LinXFade2_Ctor:

    unit->m_amp = 1.f - (unit->m_pos * 0.5f + 0.5f);

Why are we doing 1.f - ()? Possibly some of the _next functions then re-invert the pan, but not all of them. I haven't got time to sort that out.

UGen:blend depends on LinXFade2, so that means UGen:blend is also broken.

@jamshark70
Copy link
Contributor Author

In my local copy, I have reverted 1e00486 and the above test case functions correctly.

I'll assign this issue to scztt to review this commit.

@scztt
Copy link
Contributor

scztt commented Jan 28, 2015

Before my change, the SIMD cases of LinXFade were reversed, so reverting won't do anything but trade one bug for another.

I believe the (1.0f - ...) matches the amp that's required in LinXFade2_next_k_nova - but the reversal isn't appropriate for other places that use unit->m_amp. I think:

  1. unit->m_amp should be reverted to (unit->m_pos * 0.5f + 0.5f), so that m_amp corresponds to the amp of the second (right) channel.
  2. LinXFade2_next_k_nova and any other LinXFade2 functions should be swept to make sure they're using this definition of unit->m_amp and unit->m_pos.

I think it might be just LinXFade2_next_k_nova that needs to be changed, but it would be good to check at least? Can you send me unit tests for the cases that you're seeing failures, so I can make sure I get those cases to pass?

@jamshark70
Copy link
Contributor Author

I think you're right about the problem being specifically the nova functions.

LinXFade2_Ctor shows three cases, based on the rate of the pan input:

  • Scalar rate: LinXFade2_next_i_nova
  • Control rate: LinXFade2_next_k_nova
  • Audio rate: LinXFade2_next_a

Audio rate is the only one that doesn't use nova, and in the following test, it's the only one that works correctly.

a = {
    var a = DC.kr(0), b = DC.kr(1), iTrig = Trig1.kr(Impulse.kr(0), 1),
    pans = [-1, DC.kr(-1), DC.ar(-1)];
    Poll.kr(iTrig, LinXFade2.kr(a, b, pans));
    FreeSelf.kr(iTrig <= 0);
    Silent.ar(1)
}.play;

UGen(LinXFade2): 1  // calc. by LinXFade2_next_i_nova -- wrong
UGen(LinXFade2): 1  // calc. by LinXFade2_next_k_nova -- wrong
UGen(LinXFade2): 0  // calc. by LinXFade2_next_a -- correct

I'm too short of time today to rebuild SC without nova optimization, but the formulas in the nova-less _k and _i functions match _a, so I believe they are also okay.

I agree with your proposed solution: unit->m_amp should follow the user's input value (for clarity if for no other reason). Since the flaw is really in the _nova functions, then these should be fixed.

timblechmann added a commit to timblechmann/supercollider that referenced this issue Feb 24, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issues that relate to unexpected/unwanted behavior. Don't use for PRs. comp: server plugins
Projects
None yet
Development

No branches or pull requests

2 participants