mirror of
https://github.com/LMMS/lmms.git
synced 2026-03-27 02:13:32 -04:00
Historically, the PeakController has had issues like attack/decay knobs acting like on/off switches, and audio artifacts like buzzing or clicking. This patch aims to address those issues. The PeakController previously used lerp (linear interpolation) when looping through the sample buffer, which was in updateValueBuffer. This lerp utilized attack/decay values from control knobs. This is not the correct place to utilize attack/decay because the only temporal data available to the function is the frame and sample size. Therefore the coefficient should simply be the sample rate instead. Between each sample, processImpl would set m_lastSample to the RMS without any sort of lerp. This resulted in m_lastSample producing stair-like patterns over time, rather than a smooth line. For context, m_lastSample is used to set the value of whatever is connected to the PeakController. The basic lerp formula is: m_lastSample = m_lastSample + ((1 - attack) * (RMS - m_lastSample)) This is useful because an attack of 0 sets m_lastSample to RMS, whereas an attack of 1 would set m_lastSample to m_lastSample. This means our attack/decay knobs can be used on a range from "snap to the next value immediately" to "never stray from the last value". * Remove attack/decay from PeakController frame lerp. * Set frame lerp coefficient to 100.0 / sample_rate to fix buzzing. * Add lerp between samples for PeakController to fix stairstep bug. * The newly added lerp utilizes (1 - attack or decay) as the coefficient, which means the knobs actually do something now.
110 lines
2.6 KiB
C++
110 lines
2.6 KiB
C++
/*
|
|
* PeakController.h - peak-controller class
|
|
*
|
|
* Copyright (c) 2008-2009 Paul Giblock <drfaygo/at/gmail.com>
|
|
*
|
|
* This file is part of LMMS - https://lmms.io
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public
|
|
* License as published by the Free Software Foundation; either
|
|
* version 2 of the License, or (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public
|
|
* License along with this program (see COPYING); if not, write to the
|
|
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
* Boston, MA 02110-1301 USA.
|
|
*
|
|
*/
|
|
|
|
#ifndef LMMS_PEAK_CONTROLLER_H
|
|
#define LMMS_PEAK_CONTROLLER_H
|
|
|
|
#include "Controller.h"
|
|
#include "ControllerDialog.h"
|
|
|
|
class QWidget;
|
|
|
|
namespace lmms
|
|
{
|
|
|
|
|
|
class PeakControllerEffect;
|
|
|
|
using PeakControllerEffectVector = std::vector<PeakControllerEffect*>;
|
|
|
|
class LMMS_EXPORT PeakController : public Controller
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
PeakController( Model * _parent,
|
|
PeakControllerEffect *_peak_effect = nullptr );
|
|
|
|
|
|
~PeakController() override;
|
|
|
|
void saveSettings( QDomDocument & _doc, QDomElement & _this ) override;
|
|
void loadSettings( const QDomElement & _this ) override;
|
|
QString nodeName() const override;
|
|
|
|
static void initGetControllerBySetting();
|
|
static PeakController * getControllerBySetting( const QDomElement & _this );
|
|
|
|
static PeakControllerEffectVector s_effects;
|
|
|
|
|
|
public slots:
|
|
gui::ControllerDialog * createDialog( QWidget * _parent ) override;
|
|
void handleDestroyedEffect();
|
|
void updateCoeffs();
|
|
|
|
protected:
|
|
// The internal per-controller get-value function
|
|
void updateValueBuffer() override;
|
|
|
|
PeakControllerEffect * m_peakEffect;
|
|
|
|
friend class PeakControllerDialog;
|
|
|
|
private:
|
|
float m_currentSample;
|
|
//backward compatibility for <= 0.4.15
|
|
static int m_getCount;
|
|
static int m_loadCount;
|
|
static bool m_buggedFile;
|
|
|
|
float m_coeff;
|
|
bool m_coeffNeedsUpdate;
|
|
} ;
|
|
|
|
namespace gui
|
|
{
|
|
|
|
class PeakControllerDialog : public ControllerDialog
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
PeakControllerDialog( Controller * _controller, QWidget * _parent );
|
|
~PeakControllerDialog() override = default;
|
|
|
|
protected:
|
|
void contextMenuEvent( QContextMenuEvent * _me ) override;
|
|
void paintEvent( QPaintEvent * _pe ) override;
|
|
void modelChanged() override;
|
|
|
|
PeakController * m_peakController;
|
|
|
|
};
|
|
|
|
|
|
} // namespace gui
|
|
|
|
} // namespace lmms
|
|
|
|
#endif // LMMS_PEAK_CONTROLLER_H
|