@@ -38,8 +38,7 @@ MixerChannel::MixerChannel(const TrackId trackId, IAudioSourcePtr source, const
3838 const modularity::ContextPtr& iocCtx)
3939 : Injectable(iocCtx), m_trackId(trackId),
4040 m_outputSpec(outputSpec),
41- m_audioSource(std::move(source)),
42- m_compressor(std::make_unique<dsp::Compressor>(outputSpec.sampleRate))
41+ m_audioSource(std::move(source))
4342{
4443 ONLY_AUDIO_ENGINE_THREAD;
4544}
@@ -219,39 +218,35 @@ samples_t MixerChannel::process(float* buffer, samples_t samplesPerChannel)
219218
220219void MixerChannel::completeOutput (float * buffer, unsigned int samplesCount)
221220{
222- unsigned int channelsCount = audioChannelsCount ();
223- float volume = muse::db_to_linear (m_params.volume );
224- float totalSquaredSum = 0 .f ;
221+ const unsigned int channelsCount = audioChannelsCount ();
222+ const float volume = muse::db_to_linear (m_params.volume );
223+ float globalPeak = 0 .f ;
225224
226225 for (audioch_t audioChNum = 0 ; audioChNum < channelsCount; ++audioChNum) {
227- float singleChannelSquaredSum = 0 .f ;
228-
229- gain_t totalGain = dsp::balanceGain (m_params.balance , audioChNum) * volume;
226+ const gain_t totalGain = dsp::balanceGain (m_params.balance , audioChNum) * volume;
227+ float peak = 0 .f ;
230228
231229 for (unsigned int s = 0 ; s < samplesCount; ++s) {
232- int idx = s * channelsCount + audioChNum;
230+ const unsigned int idx = s * channelsCount + audioChNum;
231+ const float resultSample = buffer[idx] * totalGain;
232+ const float absSample = std::fabs (resultSample);
233233
234- float resultSample = buffer[idx] * totalGain;
235234 buffer[idx] = resultSample;
236235
237- float squaredSample = resultSample * resultSample;
238- singleChannelSquaredSum += squaredSample ;
239- totalSquaredSum += squaredSample;
236+ if (absSample > peak) {
237+ peak = absSample ;
238+ }
240239 }
241240
242- float rms = dsp::samplesRootMeanSquare (singleChannelSquaredSum, samplesCount);
243- m_audioSignalNotifier.updateSignalValues (audioChNum, rms);
244- }
241+ m_audioSignalNotifier.updateSignalValues (audioChNum, peak);
245242
246- m_isSilent = RealIsNull (totalSquaredSum);
247- m_audioSignalNotifier.notifyAboutChanges ();
248-
249- if (!m_compressor->isActive ()) {
250- return ;
243+ if (peak > globalPeak) {
244+ globalPeak = peak;
245+ }
251246 }
252247
253- float totalRms = dsp::samplesRootMeanSquare (totalSquaredSum, samplesCount * channelsCount );
254- m_compressor-> process (totalRms, buffer, channelsCount, samplesCount );
248+ m_isSilent = RealIsNull (globalPeak );
249+ m_audioSignalNotifier. notifyAboutChanges ( );
255250}
256251
257252bool MixerChannel::isSilent () const
0 commit comments