From db21f3b3428d88b19d2f82ae933830153310a1f1 Mon Sep 17 00:00:00 2001 From: trialuser02 Date: Sat, 26 Dec 2009 22:41:24 +0000 Subject: enabled replaygain support (for mp3 file with ape tags only) git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@1453 90c681e8-e032-0410-971d-27865f9a5e38 --- src/plugins/Input/mad/CMakeLists.txt | 2 + src/plugins/Input/mad/decoder_mad.cpp | 21 +++++--- src/plugins/Input/mad/decoder_mad.h | 3 +- src/plugins/Input/mad/decodermadfactory.cpp | 18 ++----- src/plugins/Input/mad/decodermadfactory.h | 3 -- src/plugins/Input/mad/mad.pro | 9 ++-- src/plugins/Input/mad/replaygainreader.cpp | 63 ++++++++++++++++++++++ src/plugins/Input/mad/replaygainreader.h | 44 +++++++++++++++ .../Input/mad/translations/mad_plugin_cs.ts | 14 ++--- .../Input/mad/translations/mad_plugin_de.ts | 14 ++--- .../Input/mad/translations/mad_plugin_it.ts | 14 ++--- .../Input/mad/translations/mad_plugin_lt.ts | 14 ++--- .../Input/mad/translations/mad_plugin_pl.ts | 14 ++--- .../Input/mad/translations/mad_plugin_ru.ts | 14 ++--- .../Input/mad/translations/mad_plugin_tr.ts | 14 ++--- .../Input/mad/translations/mad_plugin_uk_UA.ts | 14 ++--- .../Input/mad/translations/mad_plugin_zh_CN.ts | 14 ++--- .../Input/mad/translations/mad_plugin_zh_TW.ts | 14 ++--- src/qmmp/decoder.cpp | 15 +++++- src/qmmp/decoder.h | 15 +++++- src/qmmp/qmmpaudioengine.cpp | 7 ++- src/qmmp/replaygain.cpp | 32 ++++++----- src/qmmp/replaygainsettings.cpp | 6 +-- src/qmmp/soundcore.cpp | 30 ++++++++--- src/qmmp/soundcore.h | 4 +- src/ui/configdialog.cpp | 8 +-- src/ui/forms/configdialog.ui | 18 +++++++ src/ui/translations/qmmp_cs.ts | 20 +++---- src/ui/translations/qmmp_de.ts | 20 +++---- src/ui/translations/qmmp_it.ts | 20 +++---- src/ui/translations/qmmp_lt.ts | 20 +++---- src/ui/translations/qmmp_pl_PL.ts | 20 +++---- src/ui/translations/qmmp_pt_BR.ts | 20 +++---- src/ui/translations/qmmp_ru.ts | 20 +++---- src/ui/translations/qmmp_tr.ts | 20 +++---- src/ui/translations/qmmp_uk_UA.ts | 58 +++++++++++++++++--- src/ui/translations/qmmp_zh_CN.ts | 20 +++---- src/ui/translations/qmmp_zh_TW.ts | 20 +++---- 38 files changed, 452 insertions(+), 244 deletions(-) create mode 100644 src/plugins/Input/mad/replaygainreader.cpp create mode 100644 src/plugins/Input/mad/replaygainreader.h diff --git a/src/plugins/Input/mad/CMakeLists.txt b/src/plugins/Input/mad/CMakeLists.txt index 174f4f696..e4e0d8130 100644 --- a/src/plugins/Input/mad/CMakeLists.txt +++ b/src/plugins/Input/mad/CMakeLists.txt @@ -38,6 +38,7 @@ SET(libmad_SRCS settingsdialog.cpp tagextractor.cpp mpegmetadatamodel.cpp + replaygainreader.cpp ) SET(libmad_MOC_HDRS @@ -46,6 +47,7 @@ SET(libmad_MOC_HDRS decoder_mad.h tagextractor.h mpegmetadatamodel.h + replaygainreader.h ) SET(libmad_RCCS translations/translations.qrc) diff --git a/src/plugins/Input/mad/decoder_mad.cpp b/src/plugins/Input/mad/decoder_mad.cpp index 3707abcbc..f76ff9350 100644 --- a/src/plugins/Input/mad/decoder_mad.cpp +++ b/src/plugins/Input/mad/decoder_mad.cpp @@ -8,21 +8,18 @@ #include #include #include - -#include "decoder_mad.h" -#include "tagextractor.h" #include #include - #include #include +#include "tagextractor.h" +#include "replaygainreader.h" +#include "decoder_mad.h" #define XING_MAGIC (('X' << 24) | ('i' << 16) | ('n' << 8) | 'g') #define INPUT_BUFFER_SIZE (32*1024) - -DecoderMAD::DecoderMAD(QIODevice *i) - : Decoder(i) +DecoderMAD::DecoderMAD(const QString &url, QIODevice *i) : Decoder(i) { m_inited = false; m_totalTime = 0; @@ -36,6 +33,7 @@ DecoderMAD::DecoderMAD(QIODevice *i) m_output_at = 0; m_skip_frames = 0; m_eof = false; + m_url = url; } DecoderMAD::~DecoderMAD() @@ -100,7 +98,14 @@ bool DecoderMAD::initialize() mad_frame_mute (&frame); stream.next_frame = 0; stream.sync = 0; - configure(m_freq, m_channels, 16); + + if(!m_url.contains("://")) + { + ReplayGainReader rg(m_url); + configure(m_freq, m_channels, 16, rg.replayGainInfo()); + } + else + configure(m_freq, m_channels, 16); m_inited = TRUE; return TRUE; diff --git a/src/plugins/Input/mad/decoder_mad.h b/src/plugins/Input/mad/decoder_mad.h index c78e3f8c8..a98f7fbf7 100644 --- a/src/plugins/Input/mad/decoder_mad.h +++ b/src/plugins/Input/mad/decoder_mad.h @@ -22,7 +22,7 @@ extern "C" class DecoderMAD : public Decoder { public: - DecoderMAD(QIODevice *i); + DecoderMAD(const QString &url, QIODevice *i); virtual ~DecoderMAD(); // standard decoder API @@ -46,6 +46,7 @@ private: uint m_bitrate; long m_freq, m_len; qint64 m_output_bytes, m_output_at; + QString m_url; // file input buffer char *m_input_buf; diff --git a/src/plugins/Input/mad/decodermadfactory.cpp b/src/plugins/Input/mad/decodermadfactory.cpp index fa89e5f5d..2ec86e011 100644 --- a/src/plugins/Input/mad/decodermadfactory.cpp +++ b/src/plugins/Input/mad/decodermadfactory.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2008 by Ilya Kotov * + * Copyright (C) 2008-2009 by Ilya Kotov * * forkotov02@hotmail.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -30,7 +30,6 @@ #include #include #include - #include "mpegmetadatamodel.h" #include "settingsdialog.h" #include "decoder_mad.h" @@ -94,9 +93,9 @@ const DecoderProperties DecoderMADFactory::properties() const return properties; } -Decoder *DecoderMADFactory::create(const QString&, QIODevice *input) +Decoder *DecoderMADFactory::create(const QString &url, QIODevice *input) { - return new DecoderMAD(input); + return new DecoderMAD(url, input); } QList DecoderMADFactory::createPlayList(const QString &fileName, bool useMetaData) @@ -117,21 +116,17 @@ QList DecoderMADFactory::createPlayList(const QString &fileName, boo tag_array[1] = settings.value("tag_2", SettingsDialog::Disabled).toInt(); tag_array[2] = settings.value("tag_3", SettingsDialog::Disabled).toInt(); - + QByteArray name; for (int i = 0; i < 3; ++i) { switch ((uint) tag_array[i]) { case SettingsDialog::ID3v1: - { codec = QTextCodec::codecForName(settings.value("ID3v1_encoding","ISO-8859-1") .toByteArray ()); tag = fileRef.ID3v1Tag(); break; - } case SettingsDialog::ID3v2: - { - QByteArray name; name = settings.value("ID3v2_encoding","UTF-8").toByteArray (); if (name.contains("UTF")) codec = QTextCodec::codecForName ("UTF-8"); @@ -139,18 +134,13 @@ QList DecoderMADFactory::createPlayList(const QString &fileName, boo codec = QTextCodec::codecForName(name); tag = fileRef.ID3v2Tag(); break; - } case SettingsDialog::APE: - { codec = QTextCodec::codecForName ("UTF-8"); tag = fileRef.APETag(); break; - } case SettingsDialog::Disabled: - { break; } - } if (tag && !tag->isEmpty()) break; } diff --git a/src/plugins/Input/mad/decodermadfactory.h b/src/plugins/Input/mad/decodermadfactory.h index a4e18c8f4..a9831cd08 100644 --- a/src/plugins/Input/mad/decodermadfactory.h +++ b/src/plugins/Input/mad/decodermadfactory.h @@ -30,9 +30,6 @@ #include #include - - - class DecoderMADFactory : public QObject, DecoderFactory { diff --git a/src/plugins/Input/mad/mad.pro b/src/plugins/Input/mad/mad.pro index db7bab22a..d83092b77 100644 --- a/src/plugins/Input/mad/mad.pro +++ b/src/plugins/Input/mad/mad.pro @@ -4,12 +4,14 @@ HEADERS += decodermadfactory.h \ decoder_mad.h \ settingsdialog.h \ tagextractor.h \ - mpegmetadatamodel.h + mpegmetadatamodel.h \ + replaygainreader.h SOURCES += decoder_mad.cpp \ decodermadfactory.cpp \ settingsdialog.cpp \ tagextractor.cpp \ - mpegmetadatamodel.cpp + mpegmetadatamodel.cpp \ + replaygainreader.cpp TARGET = $$PLUGINS_PREFIX/Input/mad unix:QMAKE_CLEAN = $$PLUGINS_PREFIX/Input/libmad.so INCLUDEPATH += ../../../ \ @@ -47,6 +49,5 @@ unix { target.path = $$LIB_DIR/qmmp/Input INSTALLS += target } - win32:HEADERS += ../../../../src/qmmp/metadatamodel.h \ - ../../../../src/qmmp/decoderfactory.h + ../../../../src/qmmp/decoderfactory.h diff --git a/src/plugins/Input/mad/replaygainreader.cpp b/src/plugins/Input/mad/replaygainreader.cpp new file mode 100644 index 000000000..88f3dc974 --- /dev/null +++ b/src/plugins/Input/mad/replaygainreader.cpp @@ -0,0 +1,63 @@ +/*************************************************************************** + * Copyright (C) 2009 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * 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; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include "replaygainreader.h" + +ReplayGainReader::ReplayGainReader(const QString &path) +{ + TagLib::MPEG::File fileRef(path.toLocal8Bit ().constData()); + if(fileRef.APETag()) + readAPE(fileRef.APETag()); +} + +QMap ReplayGainReader::replayGainInfo() const +{ + return m_values; +} + +void ReplayGainReader::readAPE(TagLib::APE::Tag *tag) +{ + TagLib::APE::ItemListMap items = tag->itemListMap(); + if (items.contains("REPLAYGAIN_TRACK_GAIN")) + setValue(Qmmp::REPLAYGAIN_TRACK_GAIN,TStringToQString(items["REPLAYGAIN_TRACK_GAIN"].values()[0])); + if (items.contains("REPLAYGAIN_TRACK_PEAK")) + setValue(Qmmp::REPLAYGAIN_TRACK_PEAK,TStringToQString(items["REPLAYGAIN_TRACK_PEAK"].values()[0])); + if (items.contains("REPLAYGAIN_ALBUM_GAIN")) + setValue(Qmmp::REPLAYGAIN_ALBUM_GAIN,TStringToQString(items["REPLAYGAIN_ALBUM_GAIN"].values()[0])); + if (items.contains("REPLAYGAIN_ALBUM_PEAK")) + setValue(Qmmp::REPLAYGAIN_ALBUM_PEAK,TStringToQString(items["REPLAYGAIN_ALBUM_PEAK"].values()[0])); +} + +void ReplayGainReader::setValue(Qmmp::ReplayGainKey key, QString value) +{ + value.remove(" dB"); + if(value.isEmpty()) + return; + bool ok; + double v = value.toDouble(&ok); + if(ok) + m_values[key] = v; +} diff --git a/src/plugins/Input/mad/replaygainreader.h b/src/plugins/Input/mad/replaygainreader.h new file mode 100644 index 000000000..2129a69d6 --- /dev/null +++ b/src/plugins/Input/mad/replaygainreader.h @@ -0,0 +1,44 @@ +/*************************************************************************** + * Copyright (C) 2009 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * 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; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef REPLAYGAINREADER_H +#define REPLAYGAINREADER_H + +#include +#include +#include +#include + +/** + @author Ilya Kotov +*/ +class ReplayGainReader +{ +public: + ReplayGainReader(const QString &path); + QMap replayGainInfo() const; + +private: + void readAPE(TagLib::APE::Tag *tag); + void setValue(Qmmp::ReplayGainKey key, QString value); + QMap m_values; +}; + +#endif // REPLAYGAINREADER_H diff --git a/src/plugins/Input/mad/translations/mad_plugin_cs.ts b/src/plugins/Input/mad/translations/mad_plugin_cs.ts index ff4cb3afe..ac90ee91e 100644 --- a/src/plugins/Input/mad/translations/mad_plugin_cs.ts +++ b/src/plugins/Input/mad/translations/mad_plugin_cs.ts @@ -4,37 +4,37 @@ DecoderMADFactory - + MPEG Plugin Modul MPEG - + MPEG Files Soubory MPEG - + About MPEG Audio Plugin O modulu MPEG - + Qmmp MPEG Audio Plugin Vstupní modul Qmmp MPEG - + Compiled against libmad version: Zkompilováno s libmad verze: - + Writen by: Ilya Kotov <forkotov02@hotmail.ru> Autor: Ilja Kotov <forkotov02@hotmail.ru> - + Source code based on mq3 progect Zdrojový kód je založen na projektu mq3 diff --git a/src/plugins/Input/mad/translations/mad_plugin_de.ts b/src/plugins/Input/mad/translations/mad_plugin_de.ts index 4b5280861..091f7a4aa 100644 --- a/src/plugins/Input/mad/translations/mad_plugin_de.ts +++ b/src/plugins/Input/mad/translations/mad_plugin_de.ts @@ -4,37 +4,37 @@ DecoderMADFactory - + MPEG Plugin MPEG-Modul - + MPEG Files MPEG-Dateien - + About MPEG Audio Plugin Über MPEG-Audio-Modul - + Qmmp MPEG Audio Plugin Qmmp MPEG-Audio-Modul - + Compiled against libmad version: Kompiliert gegen libmad-Version: - + Writen by: Ilya Kotov <forkotov02@hotmail.ru> Autor: Ilya Kotov <forkotov02@hotmail.ru> - + Source code based on mq3 progect Quellcode basiert auf dem mq3-Projekt diff --git a/src/plugins/Input/mad/translations/mad_plugin_it.ts b/src/plugins/Input/mad/translations/mad_plugin_it.ts index cdd9f1316..df9f0126e 100644 --- a/src/plugins/Input/mad/translations/mad_plugin_it.ts +++ b/src/plugins/Input/mad/translations/mad_plugin_it.ts @@ -4,37 +4,37 @@ DecoderMADFactory - + MPEG Plugin Modulo MPEG - + MPEG Files Brani MPEG - + About MPEG Audio Plugin Info sul modulo audio MPEG - + Qmmp MPEG Audio Plugin Modulo audio MPEG per Qmmp - + Compiled against libmad version: Compilato con libmad-Version: - + Writen by: Ilya Kotov <forkotov02@hotmail.ru> Autore: Ilya Kotov <forkotov02@hotmail.ru> - + Source code based on mq3 progect Codice sorgente basato sul progetto mq3 diff --git a/src/plugins/Input/mad/translations/mad_plugin_lt.ts b/src/plugins/Input/mad/translations/mad_plugin_lt.ts index ec3ceeb58..9e6851995 100644 --- a/src/plugins/Input/mad/translations/mad_plugin_lt.ts +++ b/src/plugins/Input/mad/translations/mad_plugin_lt.ts @@ -4,37 +4,37 @@ DecoderMADFactory - + MPEG Plugin MPEG įskiepis - + MPEG Files MPEG bylos - + About MPEG Audio Plugin Apie MPEG audio įskiepį - + Qmmp MPEG Audio Plugin Qmmp MPEG įskiepis - + Compiled against libmad version: Sukurta libmad pagrindu: - + Writen by: Ilya Kotov <forkotov02@hotmail.ru> Sukūrė: Ilya Kotov <forkotov02@hotmail.ru> - + Source code based on mq3 progect Išvesties kodas sukurtas mq3 pagrindu diff --git a/src/plugins/Input/mad/translations/mad_plugin_pl.ts b/src/plugins/Input/mad/translations/mad_plugin_pl.ts index ca98436b4..209d3303d 100644 --- a/src/plugins/Input/mad/translations/mad_plugin_pl.ts +++ b/src/plugins/Input/mad/translations/mad_plugin_pl.ts @@ -4,37 +4,37 @@ DecoderMADFactory - + MPEG Plugin Wtyczka MPEG - + MPEG Files Pliki MPEG - + About MPEG Audio Plugin O wtyczce Audio MPEG - + Qmmp MPEG Audio Plugin Wtyczka MPEG Audio dla Qmmp - + Compiled against libmad version: Skompilowane przy użyciu biblioteki libmad w wersji: - + Writen by: Ilya Kotov <forkotov02@hotmail.ru> Autor: Ilja Kotov <forkotov02@hotmail.ru> - + Source code based on mq3 progect Kod źródłowy oparty na projekcie mq3 diff --git a/src/plugins/Input/mad/translations/mad_plugin_ru.ts b/src/plugins/Input/mad/translations/mad_plugin_ru.ts index 2999140bd..a913f51d7 100644 --- a/src/plugins/Input/mad/translations/mad_plugin_ru.ts +++ b/src/plugins/Input/mad/translations/mad_plugin_ru.ts @@ -4,37 +4,37 @@ DecoderMADFactory - + MPEG Plugin Модуль MPEG - + MPEG Files Файлы MPEG - + About MPEG Audio Plugin Об аудио-модуле MPEG - + Qmmp MPEG Audio Plugin Аудио-модуль MPEG для Qmmp - + Compiled against libmad version: Собрано с версией libmad: - + Writen by: Ilya Kotov <forkotov02@hotmail.ru> Разработчик: Илья Котов <forkotov02@hotmail.ru> - + Source code based on mq3 progect Исходный код основан на проекте mq3 diff --git a/src/plugins/Input/mad/translations/mad_plugin_tr.ts b/src/plugins/Input/mad/translations/mad_plugin_tr.ts index 8ddeece6f..731fefe6d 100644 --- a/src/plugins/Input/mad/translations/mad_plugin_tr.ts +++ b/src/plugins/Input/mad/translations/mad_plugin_tr.ts @@ -4,37 +4,37 @@ DecoderMADFactory - + MPEG Plugin MPEG Eklentisi - + MPEG Files MPEG Dosyaları - + About MPEG Audio Plugin MPEG Ses Eklentisi Hakkında - + Qmmp MPEG Audio Plugin Qmmp MPEG Ses Eklentisi - + Compiled against libmad version: Derlendiği libmad sürümü: - + Writen by: Ilya Kotov <forkotov02@hotmail.ru> Yazan: Ilya Kotov <forkotov02@hotmail.ru> - + Source code based on mq3 progect Kaynak kodu mq3 projesi temellidir diff --git a/src/plugins/Input/mad/translations/mad_plugin_uk_UA.ts b/src/plugins/Input/mad/translations/mad_plugin_uk_UA.ts index 5a47cc2cb..c509c85ca 100644 --- a/src/plugins/Input/mad/translations/mad_plugin_uk_UA.ts +++ b/src/plugins/Input/mad/translations/mad_plugin_uk_UA.ts @@ -4,37 +4,37 @@ DecoderMADFactory - + MPEG Plugin Модуль MPEG - + MPEG Files Файли MPEG - + About MPEG Audio Plugin Про аудіо-модуль MPEG - + Qmmp MPEG Audio Plugin Аудіо-модуль MPEG для Qmmp - + Compiled against libmad version: Зібрано з версією libmad: - + Writen by: Ilya Kotov <forkotov02@hotmail.ru> Розробник: Ілля Котов <forkotov02@hotmail.ru> - + Source code based on mq3 progect Вихідний код базується на проекті mq3 diff --git a/src/plugins/Input/mad/translations/mad_plugin_zh_CN.ts b/src/plugins/Input/mad/translations/mad_plugin_zh_CN.ts index c6ed93ab4..5b7aef659 100644 --- a/src/plugins/Input/mad/translations/mad_plugin_zh_CN.ts +++ b/src/plugins/Input/mad/translations/mad_plugin_zh_CN.ts @@ -4,37 +4,37 @@ DecoderMADFactory - + MPEG Plugin MPEG 插件 - + MPEG Files MPEG 文件 - + About MPEG Audio Plugin 关于 MPEG 音频插件 - + Qmmp MPEG Audio Plugin Qmmp MPEG 音频插件 - + Compiled against libmad version: 编译基于 libmad 的版本: - + Writen by: Ilya Kotov <forkotov02@hotmail.ru> 作者:Ilya Kotov <forkotov02@hotmail.ru> - + Source code based on mq3 progect 源代码基于 mq3 项目 diff --git a/src/plugins/Input/mad/translations/mad_plugin_zh_TW.ts b/src/plugins/Input/mad/translations/mad_plugin_zh_TW.ts index 05b2c760b..db84455c7 100644 --- a/src/plugins/Input/mad/translations/mad_plugin_zh_TW.ts +++ b/src/plugins/Input/mad/translations/mad_plugin_zh_TW.ts @@ -4,37 +4,37 @@ DecoderMADFactory - + MPEG Plugin MPEG 插件 - + MPEG Files MPEG 檔案 - + About MPEG Audio Plugin 關於 MPEG 聲訊插件 - + Qmmp MPEG Audio Plugin Qmmp MPEG 聲訊插件 - + Compiled against libmad version: 編譯基於 libmad 的版本: - + Writen by: Ilya Kotov <forkotov02@hotmail.ru> 作者:Ilya Kotov <forkotov02@hotmail.ru> - + Source code based on mq3 progect 源碼基於 mq3 項目 diff --git a/src/qmmp/decoder.cpp b/src/qmmp/decoder.cpp index 4d9cad319..d68939843 100644 --- a/src/qmmp/decoder.cpp +++ b/src/qmmp/decoder.cpp @@ -32,9 +32,15 @@ Decoder::Decoder(QIODevice *input) : m_input(input) Decoder::~Decoder() {} -void Decoder::configure(quint32 srate, int chan, int bps) +void Decoder::configure(quint32 srate, int chan, int bps, const QMap &rg) { m_parameters = AudioParameters(srate, chan, bps); + m_rg = rg; +} + +void Decoder::configure(quint32 srate, int chan, int bps) +{ + configure(srate, chan, bps, QMap()); } void Decoder::next() @@ -45,11 +51,16 @@ const QString Decoder::nextURL() return QString(); } -const AudioParameters Decoder::audioParameters() +AudioParameters Decoder::audioParameters() const { return m_parameters; } +QMap Decoder::replayGainInfo() const +{ + return m_rg; +} + QIODevice *Decoder::input() { return m_input; diff --git a/src/qmmp/decoder.h b/src/qmmp/decoder.h index e5cb647d9..30fe76465 100644 --- a/src/qmmp/decoder.h +++ b/src/qmmp/decoder.h @@ -7,13 +7,14 @@ #ifndef DECODER_H #define DECODER_H - #include #include #include #include #include +#include #include "fileinfo.h" +#include "qmmp.h" #include "audioparameters.h" class Decoder; @@ -63,7 +64,8 @@ public: virtual void next(); virtual const QString nextURL(); - const AudioParameters audioParameters(); + AudioParameters audioParameters() const; + QMap replayGainInfo() const; QIODevice *input(); /*! * Returns DecoderFactory pointer which supports file \b path or 0 if file \b path is unsupported @@ -103,6 +105,14 @@ public: static bool isEnabled(DecoderFactory* factory); protected: + /*! + * Use this function inside initialize() reimplementation to tell other plugins about audio parameters. + * @param srate Sample rate. + * @param chan Number of channels. + * @param bps Bits per sample. + * @param rg ReplayGaing information. + */ + void configure(quint32 srate, int chan, int bps, const QMap &rg); /*! * Use this function inside initialize() reimplementation to tell other plugins about audio parameters. * @param srate Sample rate. @@ -118,6 +128,7 @@ private: static QStringList m_files; AudioParameters m_parameters; QIODevice *m_input; + QMap m_rg; //replay gain information }; #endif // DECODER_H diff --git a/src/qmmp/qmmpaudioengine.cpp b/src/qmmp/qmmpaudioengine.cpp index 3485064fe..1f3b8b2f8 100644 --- a/src/qmmp/qmmpaudioengine.cpp +++ b/src/qmmp/qmmpaudioengine.cpp @@ -32,7 +32,6 @@ #include "qmmpaudioengine.h" #include "metadatamanager.h" - extern "C" { #include "equ/iir.h" @@ -311,9 +310,7 @@ void QmmpAudioEngine::stop() qint64 QmmpAudioEngine::produceSound(char *data, qint64 size, quint32 brate, int chan) { ulong sz = size < _blksize ? size : _blksize; - - //m_replayGain->applyReplayGain(data, sz); - + m_replayGain->applyReplayGain(data, sz); if (m_useEQ) { if (!m_eqInited) @@ -388,6 +385,7 @@ void QmmpAudioEngine::run() } m_decoder = m_decoders.dequeue(); + m_replayGain->setReplayGainInfo(m_decoder->replayGainInfo()); mutex()->unlock(); m_output->start(); sendMetaData(); @@ -437,6 +435,7 @@ void QmmpAudioEngine::run() m_inputs.take(m_decoder)->deleteLater (); delete m_decoder; m_decoder = m_decoders.dequeue(); + m_replayGain->setReplayGainInfo(m_decoder->replayGainInfo()); //use current output if possible if(m_decoder->audioParameters() == m_ap) { diff --git a/src/qmmp/replaygain.cpp b/src/qmmp/replaygain.cpp index cdfb47e60..5d7db77ad 100644 --- a/src/qmmp/replaygain.cpp +++ b/src/qmmp/replaygain.cpp @@ -37,12 +37,23 @@ void ReplayGain::setReplayGainInfo(const QMap &info { m_info = info; updateScale(); + if(m_settings.mode() != ReplayGainSettings::DISABLED) + { + qDebug("ReplayGain: track: gain=%f dB, peak=%f; album: gain=%f dB, peak=%f", + m_info[Qmmp::REPLAYGAIN_TRACK_GAIN], + m_info[Qmmp::REPLAYGAIN_TRACK_PEAK], + m_info[Qmmp::REPLAYGAIN_ALBUM_GAIN], + m_info[Qmmp::REPLAYGAIN_ALBUM_PEAK]); + qDebug("ReplayGain: scale=%f", m_scale); + } + else + qDebug("ReplayGain: disabled"); } void ReplayGain::setReplayGainSettings(const ReplayGainSettings &settings) { m_settings = settings; - updateScale(); + setReplayGainInfo(m_info); } void ReplayGain::applyReplayGain(char *data, qint64 size) @@ -71,7 +82,7 @@ void ReplayGain::applyReplayGain(char *data, qint64 size) void ReplayGain::updateScale() { double peak = 0.0; - m_scale = 0.0; + m_scale = 1.0; switch((int) m_settings.mode()) { case ReplayGainSettings::TRACK: @@ -84,16 +95,13 @@ void ReplayGain::updateScale() break; case ReplayGainSettings::DISABLED: m_scale = 1.0; + return; } - if(m_scale == 0.0) + if(m_scale == 1.0) m_scale = pow(10.0, m_settings.defaultGain()/20); - if(peak > 0.0 && m_scale != 1.0 && m_scale > 0.0) - { - m_scale *= pow(10.0, m_settings.preamp()/20); - if(m_settings.preventClipping()) - m_scale = m_scale*peak > 1.0 ? 1.0 / peak : m_scale; - } - if(m_scale < 0.0) - m_scale = 1.0; - m_scale = qMin(m_scale, 15.0); + m_scale *= pow(10.0, m_settings.preamp()/20); + if(peak > 0.0 && m_settings.preventClipping()) + m_scale = m_scale*peak > 1.0 ? 1.0 / peak : m_scale; + m_scale = qMin(m_scale, 5.6234); // +15 dB + m_scale = qMax(m_scale, 0.1778); // -15 dB } diff --git a/src/qmmp/replaygainsettings.cpp b/src/qmmp/replaygainsettings.cpp index 081620ab4..3a02b8e73 100644 --- a/src/qmmp/replaygainsettings.cpp +++ b/src/qmmp/replaygainsettings.cpp @@ -22,9 +22,9 @@ ReplayGainSettings::ReplayGainSettings() { - m_mode = TRACK; - m_preamp = 1.0; - m_defaultGain = 0.0; + m_mode = DISABLED; + m_preamp = 0.0; + m_defaultGain = -8.0; m_preventClipping = false; } diff --git a/src/qmmp/soundcore.cpp b/src/qmmp/soundcore.cpp index 10809c1c6..d212a6ae3 100644 --- a/src/qmmp/soundcore.cpp +++ b/src/qmmp/soundcore.cpp @@ -23,7 +23,6 @@ #include #include #include - #include "qmmpaudioengine.h" #include "decoderfactory.h" #include "effect.h" @@ -65,6 +64,14 @@ SoundCore::SoundCore(QObject *parent) connect(m_handler, SIGNAL(bufferingProgress(int)), SIGNAL(bufferingProgress(int))); m_volumeControl = VolumeControl::create(this); connect(m_volumeControl, SIGNAL(volumeChanged(int, int)), SIGNAL(volumeChanged(int, int))); + QSettings settings (Qmmp::configFile(), QSettings::IniFormat); + //replaygain settings + settings.beginGroup("ReplayGain"); + m_rgs = ReplayGainSettings(settings.value("mode", m_rgs.mode()).toInt(), + settings.value("preamp", m_rgs.preamp()).toDouble(), + settings.value("default_gain", m_rgs.defaultGain()).toDouble(), + settings.value("prevent_clipping",m_rgs.preventClipping()).toBool()); + settings.endGroup(); } @@ -243,7 +250,7 @@ bool SoundCore::enqueue(InputSource *s) setEQ(m_bands, m_preamp); setEQEnabled(m_useEQ); - setReplayGainSettings(m_replayGainSettings); + setReplayGainSettings(m_rgs); if(m_engine->enqueue(s)) { m_source = s->url(); @@ -282,7 +289,7 @@ bool SoundCore::enqueue(InputSource *s) connect(engine, SIGNAL(playbackFinished()), SIGNAL(finished())); engine->setEQ(m_bands, m_preamp); engine->setEQEnabled(m_useEQ); - engine->setReplayGainSettings(m_replayGainSettings); + engine->setReplayGainSettings(m_rgs); if (m_handler->state() == Qmmp::Playing || m_handler->state() == Qmmp::Paused) { if(m_pendingEngine) @@ -314,14 +321,23 @@ void SoundCore::startPendingEngine() ReplayGainSettings SoundCore::replayGainSettings() const { - return m_replayGainSettings; + return m_rgs; } -void SoundCore::setReplayGainSettings(const ReplayGainSettings &settings) +void SoundCore::setReplayGainSettings(const ReplayGainSettings &rgs) { - m_replayGainSettings = settings; + m_rgs = rgs; + //save replaygain settings + QSettings settings (Qmmp::configFile(), QSettings::IniFormat); + settings.beginGroup("ReplayGain"); + settings.setValue("mode", m_rgs.mode()); + settings.setValue("preamp", m_rgs.preamp()); + settings.setValue("default_gain", m_rgs.defaultGain()); + settings.setValue("prevent_clipping",m_rgs.preventClipping()); + settings.endGroup(); + //apply replaygain settings if(m_engine) - m_engine->setReplayGainSettings(settings); + m_engine->setReplayGainSettings(rgs); } SoundCore* SoundCore::instance() diff --git a/src/qmmp/soundcore.h b/src/qmmp/soundcore.h index 092cef3a0..a0860957d 100644 --- a/src/qmmp/soundcore.h +++ b/src/qmmp/soundcore.h @@ -108,7 +108,7 @@ public: QString metaData(Qmmp::MetaData key); ReplayGainSettings replayGainSettings() const; - void setReplayGainSettings(const ReplayGainSettings &settings); + void setReplayGainSettings(const ReplayGainSettings &rgs); /*! * Returns a pointer to the SoundCore instance. */ @@ -227,7 +227,7 @@ private: AbstractEngine *m_engine; AbstractEngine *m_pendingEngine; QList m_pendingSources; - ReplayGainSettings m_replayGainSettings; + ReplayGainSettings m_rgs; //ReplayGain settings }; #endif diff --git a/src/ui/configdialog.cpp b/src/ui/configdialog.cpp index dc7ea8b7f..9acdbe73c 100644 --- a/src/ui/configdialog.cpp +++ b/src/ui/configdialog.cpp @@ -78,15 +78,15 @@ ConfigDialog::ConfigDialog (QWidget *parent) connect (ui.listWidget, SIGNAL (itemClicked (QListWidgetItem *)), this, SLOT (changeSkin())); ui.listWidget->setIconSize (QSize (105,34)); m_skin = Skin::instance(); + ui.replayGainModeComboBox->addItem (tr("Track"), ReplayGainSettings::TRACK); + ui.replayGainModeComboBox->addItem (tr("Album"), ReplayGainSettings::ALBUM); + ui.replayGainModeComboBox->addItem (tr("Disabled"), ReplayGainSettings::DISABLED); readSettings(); m_reader = new SkinReader(this); loadSkins(); loadPluginsInfo(); loadFonts(); - createMenus(); - ui.replayGainModeComboBox->addItem (tr("Track"), ReplayGainSettings::TRACK); - ui.replayGainModeComboBox->addItem (tr("Album"), ReplayGainSettings::ALBUM); - ui.replayGainModeComboBox->addItem (tr("Disabled"), ReplayGainSettings::DISABLED); + createMenus(); } ConfigDialog::~ConfigDialog() diff --git a/src/ui/forms/configdialog.ui b/src/ui/forms/configdialog.ui index c6d80dfbb..1f3ec19f9 100644 --- a/src/ui/forms/configdialog.ui +++ b/src/ui/forms/configdialog.ui @@ -1076,6 +1076,15 @@ 0 + + -15.000000000000000 + + + 15.000000000000000 + + + 0.010000000000000 + @@ -1112,6 +1121,15 @@ 0 + + -15.000000000000000 + + + 15.000000000000000 + + + 0.010000000000000 + diff --git a/src/ui/translations/qmmp_cs.ts b/src/ui/translations/qmmp_cs.ts index 13da193d8..1e2004a88 100644 --- a/src/ui/translations/qmmp_cs.ts +++ b/src/ui/translations/qmmp_cs.ts @@ -205,18 +205,18 @@ Umělec - + Album Album - + Track - + Disabled @@ -471,23 +471,23 @@ - - + + dB - + Default gain: - + Use peak info to prevent clipping - + Close Zavřít @@ -563,12 +563,12 @@ - + Audio Zvuk - + Use software volume control Používat softwarové ovládání hlasitosti diff --git a/src/ui/translations/qmmp_de.ts b/src/ui/translations/qmmp_de.ts index a872ee3d3..5af7d64c7 100644 --- a/src/ui/translations/qmmp_de.ts +++ b/src/ui/translations/qmmp_de.ts @@ -205,18 +205,18 @@ Interpret - + Album Album - + Track - + Disabled @@ -471,23 +471,23 @@ - - + + dB - + Default gain: - + Use peak info to prevent clipping - + Close Schließen @@ -563,12 +563,12 @@ - + Audio Audio - + Use software volume control Softwaregesteuerte Lautstärkeregelung diff --git a/src/ui/translations/qmmp_it.ts b/src/ui/translations/qmmp_it.ts index 1fb7ddbfa..cc446ed57 100644 --- a/src/ui/translations/qmmp_it.ts +++ b/src/ui/translations/qmmp_it.ts @@ -205,18 +205,18 @@ Interprete - + Album Album - + Track - + Disabled @@ -376,7 +376,7 @@ Avanzato - + Close Chiudi @@ -417,7 +417,7 @@ - + Audio Audio @@ -482,23 +482,23 @@ - - + + dB - + Default gain: - + Use peak info to prevent clipping - + Use software volume control Utilizza il controllo volume del programma diff --git a/src/ui/translations/qmmp_lt.ts b/src/ui/translations/qmmp_lt.ts index 46cab600d..de63d8d3a 100644 --- a/src/ui/translations/qmmp_lt.ts +++ b/src/ui/translations/qmmp_lt.ts @@ -205,18 +205,18 @@ Atlikėjas - + Album Albumas - + Track - + Disabled @@ -376,7 +376,7 @@ Papildomi - + Close Užverti @@ -417,7 +417,7 @@ - + Audio Audio @@ -483,23 +483,23 @@ - - + + dB - + Default gain: - + Use peak info to prevent clipping - + Use software volume control Naudoti programinį garso valdymą diff --git a/src/ui/translations/qmmp_pl_PL.ts b/src/ui/translations/qmmp_pl_PL.ts index 612d306e6..f84c9765a 100644 --- a/src/ui/translations/qmmp_pl_PL.ts +++ b/src/ui/translations/qmmp_pl_PL.ts @@ -205,18 +205,18 @@ Artysta - + Album Album - + Track - + Disabled @@ -376,7 +376,7 @@ Zaawansowane - + Close Zamknij @@ -417,7 +417,7 @@ - + Audio Dźwięk @@ -482,23 +482,23 @@ - - + + dB - + Default gain: - + Use peak info to prevent clipping - + Use software volume control Użyj programowej regulacji głośności diff --git a/src/ui/translations/qmmp_pt_BR.ts b/src/ui/translations/qmmp_pt_BR.ts index 73102fc97..9f9191aca 100644 --- a/src/ui/translations/qmmp_pt_BR.ts +++ b/src/ui/translations/qmmp_pt_BR.ts @@ -205,18 +205,18 @@ Artista - + Album Álbum - + Track - + Disabled @@ -376,7 +376,7 @@ Avançado - + Close Fechar @@ -417,7 +417,7 @@ - + Audio @@ -482,23 +482,23 @@ - - + + dB - + Default gain: - + Use peak info to prevent clipping - + Use software volume control diff --git a/src/ui/translations/qmmp_ru.ts b/src/ui/translations/qmmp_ru.ts index 7ce763a2e..52af46efd 100644 --- a/src/ui/translations/qmmp_ru.ts +++ b/src/ui/translations/qmmp_ru.ts @@ -205,18 +205,18 @@ Исполнитель - + Album Альбом - + Track - + Disabled @@ -376,7 +376,7 @@ Дополнительно - + Close Закрыть @@ -417,7 +417,7 @@ - + Audio Аудио @@ -482,23 +482,23 @@ - - + + dB - + Default gain: - + Use peak info to prevent clipping - + Use software volume control Использовать программную регулировку громкости diff --git a/src/ui/translations/qmmp_tr.ts b/src/ui/translations/qmmp_tr.ts index 443a53f0b..efad72251 100644 --- a/src/ui/translations/qmmp_tr.ts +++ b/src/ui/translations/qmmp_tr.ts @@ -205,18 +205,18 @@ Sanatçı - + Album Albüm - + Track - + Disabled @@ -376,7 +376,7 @@ Gelişmiş - + Close Kapat @@ -417,7 +417,7 @@ - + Audio Ses @@ -482,23 +482,23 @@ - - + + dB - + Default gain: - + Use peak info to prevent clipping - + Use software volume control Yazılımsal ses kontrolünü kullan diff --git a/src/ui/translations/qmmp_uk_UA.ts b/src/ui/translations/qmmp_uk_UA.ts index f337dcd63..bb650259a 100644 --- a/src/ui/translations/qmmp_uk_UA.ts +++ b/src/ui/translations/qmmp_uk_UA.ts @@ -173,16 +173,28 @@ ConfigDialog + + + + Enabled Увімкнено + + + + Description Пояснення + + + + Filename Ім'я файлу @@ -193,17 +205,18 @@ Виконавець + Album Альбом - + Track Трек - + Disabled Вимкнено @@ -288,11 +301,14 @@ Список: + ??? ??? + + ... ... @@ -333,6 +349,7 @@ Налаштування + Information Інформація @@ -343,6 +360,7 @@ Зовнішній вигляд + Playlist Список @@ -358,7 +376,7 @@ Додатково - + Close Закрити @@ -398,7 +416,8 @@ Файловий діалог - + + Audio Звук @@ -463,22 +482,23 @@ Преамплітуда: - + + dB - + Default gain: Нормалізація за умовчанням: - + Use peak info to prevent clipping Використовувати інформацію піків для запобігання відсікання - + Use software volume control Використовувати програмний контроль гучності @@ -613,6 +633,8 @@ Головне вікно + + 0 @@ -626,6 +648,7 @@ EqWidget + preset предвстановлення @@ -679,11 +702,14 @@ JumpToTrackDialog + Unqueue Зняти з черги + + Queue В чергу @@ -865,26 +891,31 @@ Падіння аналізатора + Slowest Найповільніше + Slow Повільне + Medium Середнє + Fast Швидке + Fastest Найшвидше @@ -1013,6 +1044,7 @@ &Про програму + Playlist Files Файли списків @@ -1151,31 +1183,37 @@ Сортувати + By Title За назвою + By Album За альбомом + By Artist За артистом + By Filename За ім'ям файлу + By Path + Filename За шляхом та файлом + By Date За датою @@ -1286,6 +1324,7 @@ + By Track Number @@ -1319,11 +1358,13 @@ Новий + Delete Видалити + ... ... @@ -1342,6 +1383,7 @@ Налаштування спливаючої інформації + 0 diff --git a/src/ui/translations/qmmp_zh_CN.ts b/src/ui/translations/qmmp_zh_CN.ts index e2492252d..cbcc7d63b 100644 --- a/src/ui/translations/qmmp_zh_CN.ts +++ b/src/ui/translations/qmmp_zh_CN.ts @@ -205,18 +205,18 @@ 艺术家 - + Album 专辑 - + Track - + Disabled @@ -376,7 +376,7 @@ 高级 - + Close 关闭 @@ -417,7 +417,7 @@ - + Audio 音频 @@ -482,23 +482,23 @@ - - + + dB - + Default gain: - + Use peak info to prevent clipping - + Use software volume control 使用软设备音量控制 diff --git a/src/ui/translations/qmmp_zh_TW.ts b/src/ui/translations/qmmp_zh_TW.ts index b6a9c405b..c83e8ad6d 100644 --- a/src/ui/translations/qmmp_zh_TW.ts +++ b/src/ui/translations/qmmp_zh_TW.ts @@ -205,18 +205,18 @@ 藝術家 - + Album 專輯 - + Track - + Disabled @@ -376,7 +376,7 @@ 進階 - + Close 關閉 @@ -417,7 +417,7 @@ - + Audio 聲訊 @@ -482,23 +482,23 @@ - - + + dB - + Default gain: - + Use peak info to prevent clipping - + Use software volume control 使用軟裝置音量控制 -- cgit v1.2.3-13-gbd6f