Skip to content

Commit

Permalink
Fix mix of panned stereo track to mono
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul-Licameli committed Oct 13, 2023
1 parent 7d95e1e commit a61079e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
11 changes: 8 additions & 3 deletions libraries/lib-mixer/Mix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,14 @@ size_t Mixer::Process(const size_t maxToProcess)
for (size_t j = 0; j < limit; ++j) {
const auto pFloat = (const float *)mFloatBuffers.GetReadPosition(j);
auto &sequence = upstream.GetSequence();
if (mApplyTrackGains)
for (size_t c = 0; c < mNumChannels; ++c)
gains[c] = sequence.GetChannelGain(c);
if (mApplyTrackGains) {
for (size_t c = 0; c < mNumChannels; ++c) {
if (mNumChannels > 1)
gains[c] = sequence.GetChannelGain(c);
else
gains[c] = sequence.GetChannelGain(j);
}
}
const auto flags =
findChannelFlags(upstream.MixerSpec(j), sequence, j);
MixBuffers(mNumChannels, flags, gains, *pFloat, mTemp, result);
Expand Down
3 changes: 2 additions & 1 deletion src/effects/StereoToMono.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,11 @@ bool EffectStereoToMono::ProcessOne(TrackList &outputs,
assert(outTrack->IsLeader());
outTrack->ConvertToSampleFormat(floatSample);

double denominator = track.GetChannelGain(0) + track.GetChannelGain(1);
while (auto blockLen = mixer.Process()) {
auto buffer = mixer.GetBuffer();
for (auto i = 0; i < blockLen; i++)
((float *)buffer)[i] /= 2.0;
((float *)buffer)[i] /= denominator;

// If mixing channels that both had only 16 bit effective format
// (for example), and no gains or envelopes, still there should be
Expand Down

0 comments on commit a61079e

Please sign in to comment.