jamulussoftware / jamulussoftware/jamulus

Server: compute the fade-in gain once per channel per frame, not once per channel pair

Open
#3,945 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

AI refactoring
Dominant language
C
Stars
1.1k
Forks
248
Avg merge
2d 3h
Merged PRs (30d)
9

Description

🤖 AI: Follow-up to ann0see/jamulus#293, opened at @ann0see's request.

What is the current behaviour and why should it be changed?

The gain loop in DecodeReceiveData calls GetFadeInGain() twice per channel pair, once for the source channel (line 909) and once for the target (line 915): 2N²−N int-to-float conversions and float divisions per frame, 44850 at N=150. The N values behind them are constant for the frame. Both counters are written only in PutAudioData and OnNetTranspPropsReceived, reached under CServer::Mutex from PutAudioData and OnProtocolMessageReceived, and OnTimer holds that mutex for the whole decode phase, single- or multithreaded.

Describe possible approaches

Read each connected channel's fade-in gain once into a CVector<float> in the loop that builds vecChanIDsCurConChan, and multiply by vecfFadeInGains[j] and vecfFadeInGains[iChanCnt] at lines 909 and 915 — #293's one-read-per-channel pattern applied to the remaining per-pair accessor, independent of that PR. The output is unchanged: a benchmark of the two loop shapes with a lock-free gain read produces byte-identical matrices at N=50, 100 and 150, and times the fade-in term alone (Raspberry Pi 4 Model B, g++ 14.2 -O2, median of 5 batches, 64-sample frame):

N per pair per frame saving share of a 1.33 ms frame
50 15.4 µs 5.4 µs 10.0 µs 0.75%
100 59.4 µs 21.3 µs 38.1 µs 2.9%
150 136.3 µs 40.6 µs 95.7 µs 7.2%

At the default 128-sample frame the microseconds are the same and the shares halve.

Has this feature been discussed and generally agreed?

Requested by @ann0see on #293; no PR until the design is agreed here.


🤖 This message was written by AI and reviewed by @mcfnord.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/server.cpp at the loop building vecChanIDsCurConChan and inspect DecodeReceiveData, then read GetFadeInGain() in src/channel.h. Verify that each connected channel's gain is obtained once per frame and reused for both pair calculations, while output remains unchanged; use the linked benchmark to compare the loop shapes.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
audio-video-rtc, performance
Issue type
Refactor
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.