Skip to content

Optimize bDelayPan and divisions#3706

Open
ann0see wants to merge 1 commit into
jamulussoftware:mainfrom
ann0see:opt1/mixencodetx
Open

Optimize bDelayPan and divisions#3706
ann0see wants to merge 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 *0.5 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
const float fGain = vecvecfGains[iChanCnt][j];
const float fPan = bDelayPan ? 0.5f : vecvecfPannings[iChanCnt][j];

// calculate combined gain/pan for each stereo channel where we define
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This could do with expanding.

I thought the Server up-mixed all incoming channels to stereo (so it could treat them the same for all connected clients), did all the mixes in stereo - to allow a single path (either delay pan or not) - and then down-mixed to mono for clients with mono out.

The changes here seem to do something different but I don't quite follow it.

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.

I think there's a mono only code path?

Copy link
Copy Markdown
Collaborator

@pljones pljones May 21, 2026

Choose a reason for hiding this comment

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

There is in this new flow. What I mean is I don't understand
a) exactly what was happening before this new mono flow was introduced
b) exactly what is happening now
c) whether it's therefore having the right effect

So it needs a bigger comment in the code to explain it.

Well... it needs a good answer 😄 and then a good enough comment to explain the new code.

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.

New flow:

if delay pan:

// code for delay pan in mono or stereo mode
// not sure why there is even delay panning in mono mode but ok.

else:

// mono or stereo mixing

old flow:

if mono: 
  if delay pan:
     // delay pan mixing
  else:
    // non delay pan mixing
else:
  if delay pan:
    // parity based computation for delay pan
  else:
  // parity based mixing

Please check the code itself, not the diff as this is confusing

Copy link
Copy Markdown
Collaborator

@pljones pljones May 22, 2026

Choose a reason for hiding this comment

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

// not sure why there is even delay panning in mono mode but ok.

A mono client can pan any client in their mix and it will affect the output. ("I want more of their left channel in my mix down")

A stereo client can pan any client in their mix and it will affect the output. ("I want them moved left in my mix")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please check the code itself, not the diff as this is confusing

I can see it moves the two ifs inside out. But I can't see where the panning is applied on the source channel for a mono target now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Waiting on Team

Development

Successfully merging this pull request may close these issues.

2 participants