Skip to content

Commit

Permalink
Fix channel panning ramps.
Browse files Browse the repository at this point in the history
It looks like in FT2, panning is made using an exponential scale, based
on sqrt. This PR allows to match panning performed by MilkyTracker
and OpenMPT. 

MilkyTracker:
https://github.com/milkytracker/MilkyTracker/blob/be016986168a4d03b8d160303fa61296070a6e2c/src/milkyplay/ChannelMixer.cpp#L583

FT2-clone:
https://github.com/8bitbubsy/ft2-clone/blob/8af2e42736b61a36a0d54bede93a47a1bab35f5d/src/ft2_audio.c#L192

The attached test makes it easy to reproduce the issue.

Co-developed with @bryc who also prepared the test.
  • Loading branch information
rasky committed Apr 13, 2021
1 parent 2a458e5 commit ad599b8
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/play.c
Original file line number Diff line number Diff line change
Expand Up @@ -1362,8 +1362,8 @@ static void xm_sample(xm_context_t* ctx, float* left, float* right) {
const float fval = xm_next_of_sample(ch);

if(!ch->muted && !ch->instrument->muted) {
*left += fval * ch->actual_volume * (1.f - ch->actual_panning);
*right += fval * ch->actual_volume * ch->actual_panning;
*left += fval * ch->actual_volume * sqrt(1.f - ch->actual_panning);
*right += fval * ch->actual_volume * sqrt(ch->actual_panning);
}

#if XM_RAMPING
Expand Down
Binary file added tests/panning-law.xm
Binary file not shown.

0 comments on commit ad599b8

Please sign in to comment.