File indexing completed on 2024-04-28 04:43:20

0001 /*
0002     Copyright (C) 2013 Harald Sitter <sitter@kde.org>
0003 
0004     This library is free software; you can redistribute it and/or
0005     modify it under the terms of the GNU Lesser General Public
0006     License as published by the Free Software Foundation; either
0007     version 2.1 of the License, or (at your option) any later version.
0008 
0009     This library is distributed in the hope that it will be useful,
0010     but WITHOUT ANY WARRANTY; without even the implied warranty of
0011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012     Lesser General Public License for more details.
0013 
0014     You should have received a copy of the GNU Lesser General Public
0015     License along with this library.  If not, see <http://www.gnu.org/licenses/>.
0016 */
0017 
0018 #include "equalizereffect.h"
0019 
0020 #include "mediaplayer.h"
0021 #include "utils/debug.h"
0022 
0023 namespace Phonon {
0024 namespace VLC {
0025 
0026 EqualizerEffect::EqualizerEffect(QObject *parent)
0027     : QObject(parent)
0028     , SinkNode()
0029     , EffectInterface()
0030     , m_equalizer(libvlc_audio_equalizer_new())
0031 {
0032     // Amarok decided to make up rules because phonon didn't manage to
0033     // pre-amp string needs to be pre-amp
0034     // bands need to be xxHz
0035     // That way they can be consistently mapped to localized/formatted strings.
0036 
0037     EffectParameter preamp(-1, "pre-amp", {} /* hint */, 0.0f, -20.0f, 20.0f);
0038     m_bands.append(preamp);
0039 
0040     const unsigned int bandCount = libvlc_audio_equalizer_get_band_count();
0041     for (unsigned int i = 0; i < bandCount; ++i) {
0042         const float frequency = libvlc_audio_equalizer_get_band_frequency(i);
0043         const QString name = QString("%1Hz").arg(QString::number(frequency));
0044         EffectParameter parameter(i, name, {} /* hint */, 0.0f, -20.0f, 20.0f);
0045         m_bands.append(parameter);
0046     }
0047 }
0048 
0049 EqualizerEffect::~EqualizerEffect()
0050 {
0051     libvlc_audio_equalizer_release(m_equalizer);
0052 }
0053 
0054 QList<EffectParameter> EqualizerEffect::parameters() const
0055 {
0056     return m_bands;
0057 }
0058 
0059 QVariant EqualizerEffect::parameterValue(const EffectParameter &parameter) const
0060 {
0061     return libvlc_audio_equalizer_get_amp_at_index(m_equalizer, parameter.id());
0062 }
0063 
0064 void EqualizerEffect::setParameterValue(const EffectParameter &parameter,
0065                                         const QVariant &newValue)
0066 {
0067     if (parameter.id() == -1)
0068         libvlc_audio_equalizer_set_preamp(m_equalizer, newValue.toFloat());
0069     else
0070         libvlc_audio_equalizer_set_amp_at_index(m_equalizer, newValue.toFloat(), parameter.id());
0071 }
0072 
0073 void EqualizerEffect::handleConnectToMediaObject(MediaObject *mediaObject)
0074 {
0075     Q_UNUSED(mediaObject);
0076     m_player->setEqualizer(m_equalizer);
0077 }
0078 
0079 } // namespace VLC
0080 } // namespace Phonon