Skip to content

Optimize bDelayPan and divisions#3706

Merged
ann0see merged 1 commit into
jamulussoftware:mainfrom
ann0see:opt1/mixencodetx
May 30, 2026
Merged

Optimize bDelayPan and divisions#3706
ann0see merged 1 commit into
jamulussoftware:mainfrom
ann0see:opt1/mixencodetx

Conversation

@ann0see
Copy link
Copy Markdown
Member

@ann0see ann0see commented May 20, 2026

Short description of changes

Moves delay pan checking slightly out of loop as this setting does not change often.
Moreover replaces some divisions with /2.0f and remove some modulo computations

CHANGELOG: Server: Optimize mixing

Context: Fixes an issue?

Related to: #3662

Does this change need documentation? What needs to be documented and how?

No

Status of this Pull Request

Ready for review

What is missing until this pull request can be merged?

Tested and it seems to work, I still would like an external test.

Checklist

  • I've verified that this Pull Request follows the general code principles
  • I tested my code and it does what I want
  • My code follows the style guide
  • I waited some time after this Pull Request was opened and all GitHub checks completed without errors.
  • I've filled all the content above

Comment thread src/server.cpp
Comment on lines -1120 to -1129
if ( ( i & 1 ) == 0 )
{
// if even : left channel
vecfIntermProcBuf[i] += vecsData[i] * fGainL;
}
else
{
// if odd : right channel
vecfIntermProcBuf[i] += vecsData[i] * fGainR;
}
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Got rid of modulo computation

@ann0see ann0see requested review from pljones and softins May 20, 2026 20:38
@ann0see ann0see added this to Tracking May 20, 2026
@github-project-automation github-project-automation Bot moved this to Triage in Tracking May 20, 2026
@ann0see ann0see moved this from Triage to Waiting on Team in Tracking May 20, 2026
@ann0see ann0see force-pushed the opt1/mixencodetx branch 2 times, most recently from c6038cc to ccd6f5e Compare May 20, 2026 20:45
Copy link
Copy Markdown
Member Author

@ann0see ann0see left a comment

Choose a reason for hiding this comment

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

The function is still way too complex imo.

@ann0see ann0see force-pushed the opt1/mixencodetx branch from ccd6f5e to 62a6218 Compare May 20, 2026 20:47
@ann0see
Copy link
Copy Markdown
Member Author

ann0see commented May 20, 2026

To avoid having the clipping to short twice, we may want someting like

    // convert from double to short with clipping
    for ( i = 0; i < ( ( bTargetIsMono ? 1 : 2 ) * iServerFrameSizeSamples ); i++ )
    {
        vecsSendData[i] = Float2Short ( vecfIntermProcBuf[i] );
    }

Maybe...

@ann0see ann0see force-pushed the opt1/mixencodetx branch from 62a6218 to d6372fb Compare May 20, 2026 20:57
Comment thread src/server.cpp
Comment thread src/server.cpp Outdated
Comment thread src/server.cpp Outdated
@softins
Copy link
Copy Markdown
Member

softins commented May 25, 2026

I will study this code soon and make any comments...

Copy link
Copy Markdown
Member

@softins softins left a comment

Choose a reason for hiding this comment

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

OK, to be certain, I made separate copies of the MixEncodeTransmitData function, two from main and two from this PR. I then edited one of each to remove the if (bDelayPan) sections and the other one of each to remove the corresponding else sections instead.

I was then able to compare the "before" and "after" with no delaypan, and the "before" and "after" with delaypan, ignoring whitespace, to be sure the logic was still exactly the same in each case. I am satisfied that it is.

So this PR preserves exactly the existing behaviour of Jamulus, appears to be potentially cleaner and more efficient, and I'm approving it for merging as-is on this basis.

I think any proposal to modify and potentially improve the design of this function should be a separate PR, discussed and thoroughly tested on its own merits.

Copy link
Copy Markdown
Collaborator

@pljones pljones left a comment

Choose a reason for hiding this comment

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

OK, you're right, comparing the full files makes it easier.

It's the mono/stereo and delayPan if statements that are swapped so you do all of delayPan (with mono and stereo versions) and then all of !delayPan (with mono and stereo versions), which does make more sense.

I still prefer the / 2 (rather, / 2f - having cast to float and targeting a vector of floats) to * 0.5f for readability. "Half of" is an easier concept than "50% of".

@ann0see ann0see force-pushed the opt1/mixencodetx branch 2 times, most recently from 855d378 to 84609cf Compare May 29, 2026 20:27
@ann0see ann0see force-pushed the opt1/mixencodetx branch from 84609cf to c073963 Compare May 29, 2026 20:29
@ann0see ann0see requested review from pljones and softins May 29, 2026 20:30
Comment thread src/server.cpp
Comment thread src/server.cpp
@ann0see ann0see merged commit 2736f69 into jamulussoftware:main May 30, 2026
15 checks passed
@github-project-automation github-project-automation Bot moved this from Waiting on Team to Done in Tracking May 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants