@@ -41,8 +41,7 @@ MixerChannel::MixerChannel(const TrackId trackId, const OutputSpec& outputSpec,
4141 : Injectable(iocCtx), m_trackId(trackId),
4242 m_outputSpec(outputSpec),
4343 m_audioSource(std::move(source)),
44- m_getPlaybackPosition(getPlaybackPosition),
45- m_compressor(std::make_unique<dsp::Compressor>(outputSpec.sampleRate))
44+ m_getPlaybackPosition(getPlaybackPosition)
4645{
4746 ONLY_AUDIO_ENGINE_THREAD;
4847}
@@ -223,39 +222,35 @@ samples_t MixerChannel::process(float* buffer, samples_t samplesPerChannel)
223222
224223void MixerChannel::completeOutput (float * buffer, unsigned int samplesCount)
225224{
226- unsigned int channelsCount = audioChannelsCount ();
227- float volume = muse::db_to_linear (m_params.volume );
228- float totalSquaredSum = 0 .f ;
225+ const unsigned int channelsCount = audioChannelsCount ();
226+ const float volume = muse::db_to_linear (m_params.volume );
227+ float globalPeak = 0 .f ;
229228
230229 for (audioch_t audioChNum = 0 ; audioChNum < channelsCount; ++audioChNum) {
231- float singleChannelSquaredSum = 0 .f ;
232-
233- gain_t totalGain = dsp::balanceGain (m_params.balance , audioChNum) * volume;
230+ const gain_t totalGain = dsp::balanceGain (m_params.balance , audioChNum) * volume;
231+ float peak = 0 .f ;
234232
235233 for (unsigned int s = 0 ; s < samplesCount; ++s) {
236- int idx = s * channelsCount + audioChNum;
234+ const unsigned int idx = s * channelsCount + audioChNum;
235+ const float resultSample = buffer[idx] * totalGain;
236+ const float absSample = std::fabs (resultSample);
237237
238- float resultSample = buffer[idx] * totalGain;
239238 buffer[idx] = resultSample;
240239
241- float squaredSample = resultSample * resultSample;
242- singleChannelSquaredSum += squaredSample ;
243- totalSquaredSum += squaredSample;
240+ if (absSample > peak) {
241+ peak = absSample ;
242+ }
244243 }
245244
246- float rms = dsp::samplesRootMeanSquare (singleChannelSquaredSum, samplesCount);
247- m_audioSignalNotifier.updateSignalValues (audioChNum, rms);
248- }
245+ m_audioSignalNotifier.updateSignalValues (audioChNum, peak);
249246
250- m_isSilent = RealIsNull (totalSquaredSum);
251- m_audioSignalNotifier.notifyAboutChanges ();
252-
253- if (!m_compressor->isActive ()) {
254- return ;
247+ if (peak > globalPeak) {
248+ globalPeak = peak;
249+ }
255250 }
256251
257- float totalRms = dsp::samplesRootMeanSquare (totalSquaredSum, samplesCount * channelsCount );
258- m_compressor-> process (totalRms, buffer, channelsCount, samplesCount );
252+ m_isSilent = RealIsNull (globalPeak );
253+ m_audioSignalNotifier. notifyAboutChanges ( );
259254}
260255
261256bool MixerChannel::isSilent () const
0 commit comments