diff options
Diffstat (limited to 'src/plugins/Effect/srconverter')
| -rw-r--r-- | src/plugins/Effect/srconverter/CMakeLists.txt | 76 | ||||
| -rw-r--r-- | src/plugins/Effect/srconverter/effectsrconverterfactory.cpp | 57 | ||||
| -rw-r--r-- | src/plugins/Effect/srconverter/effectsrconverterfactory.h | 46 | ||||
| -rw-r--r-- | src/plugins/Effect/srconverter/settingsdialog.cpp | 48 | ||||
| -rw-r--r-- | src/plugins/Effect/srconverter/settingsdialog.h | 46 | ||||
| -rw-r--r-- | src/plugins/Effect/srconverter/settingsdialog.ui | 124 | ||||
| -rw-r--r-- | src/plugins/Effect/srconverter/srconverter.cpp | 125 | ||||
| -rw-r--r-- | src/plugins/Effect/srconverter/srconverter.h | 59 | ||||
| -rw-r--r-- | src/plugins/Effect/srconverter/srconverter.pro | 34 |
9 files changed, 615 insertions, 0 deletions
diff --git a/src/plugins/Effect/srconverter/CMakeLists.txt b/src/plugins/Effect/srconverter/CMakeLists.txt new file mode 100644 index 000000000..ef95abf79 --- /dev/null +++ b/src/plugins/Effect/srconverter/CMakeLists.txt @@ -0,0 +1,76 @@ +project(libsrconverter) + +cmake_minimum_required(VERSION 2.4.0) + + +INCLUDE(UsePkgConfig) +INCLUDE(FindQt4) + +find_package(Qt4 REQUIRED) # find and setup Qt4 for this project +include(${QT_USE_FILE}) + +# qt plugin +ADD_DEFINITIONS( -Wall ) +ADD_DEFINITIONS(${QT_DEFINITIONS}) +ADD_DEFINITIONS(-DQT_PLUGIN) +ADD_DEFINITIONS(-DQT_NO_DEBUG) +ADD_DEFINITIONS(-DQT_SHARED) +ADD_DEFINITIONS(-DQT_THREAD) + +include_directories(${CMAKE_CURRENT_BINARY_DIR}) + +SET(QT_INCLUDES + ${QT_INCLUDES} + ${CMAKE_CURRENT_BINARY_DIR}/../../../ +) + +# libqmmp +include_directories(${CMAKE_CURRENT_BINARY_DIR}/../../../) +link_directories(${CMAKE_CURRENT_BINARY_DIR}/../../../) + +PKGCONFIG(samplerate SAMPLERATE_INCLUDE_DIR SAMPLERATE_LINK_DIR SAMPLERATE_LINK_FLAGS SAMPLERATE_CFLAGS) + +IF(NOT SAMPLERATE_LINK_FLAGS) + SET(SAMPLERATE_LINK_FLAGS -lsamplerate) +ENDIF(NOT SAMPLERATE_LINK_FLAGS) + +include_directories(${SAMPLERATE_INCLUDE_DIR}) +link_directories(${SAMPLERATE_LINK_DIR}) + +ADD_DEFINITIONS(${SAMPLERATE_CFLAGS}) + +SET(libsrconverter_SRCS + srconverter.cpp + settingsdialog.cpp + effectsrconverterfactory.cpp +) + +SET(libsrconverter_MOC_HDRS + srconverter.h + settingsdialog.h + effectsrconverterfactory.h +) + +#SET(libsrconverter_RCCS translations/translations.qrc) + +#QT4_ADD_RESOURCES(libsrconverter_RCC_SRCS ${libsrconverter_RCCS}) + +QT4_WRAP_CPP(libsrconverter_MOC_SRCS ${libsrconverter_MOC_HDRS}) + +# user interface + + +SET(libsrconverter_UIS + settingsdialog.ui +) + +QT4_WRAP_UI(libsrconverter_UIS_H ${libsrconverter_UIS}) +# Don't forget to include output directory, otherwise +# the UI file won't be wrapped! +include_directories(${CMAKE_CURRENT_BINARY_DIR}) + +ADD_LIBRARY(srconverter SHARED ${libsrconverter_SRCS} ${libsrconverter_MOC_SRCS} ${libsrconverter_UIS_H} + ${libsrconverter_RCC_SRCS}) +target_link_libraries(srconverter ${QT_LIBRARIES} -lqmmp ${SAMPLERATE_LINK_FLAGS}) +install(TARGETS srconverter DESTINATION ${LIB_DIR}/qmmp/Effect) + diff --git a/src/plugins/Effect/srconverter/effectsrconverterfactory.cpp b/src/plugins/Effect/srconverter/effectsrconverterfactory.cpp new file mode 100644 index 000000000..bd4f93c1b --- /dev/null +++ b/src/plugins/Effect/srconverter/effectsrconverterfactory.cpp @@ -0,0 +1,57 @@ +/*************************************************************************** + * Copyright (C) 2007 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 <QtGui> + +#include "settingsdialog.h" +#include "effectsrconverterfactory.h" +#include "srconverter.h" + +const EffectProperties EffectSRConverterFactory::properties() const +{ + EffectProperties properties; + properties.name = tr("SRC Plugin"); + return properties; +}; + +Effect *EffectSRConverterFactory::create(QObject *parent) +{ + return new SRConverter(parent); +}; + +void EffectSRConverterFactory::showSettings(QWidget *parent) +{ + SettingsDialog *s = new SettingsDialog(parent); + s ->show(); +}; + +void EffectSRConverterFactory::showAbout(QWidget *parent) +{ + QMessageBox::about (parent, tr("About Sample Rate Converter Plugin"), + tr("Qmmp Sample Rate Converter Plugin")+"\n"+ + tr("Writen by: Ilya Kotov <forkotov02@hotmail.ru>")); +}; + +QTranslator *EffectSRConverterFactory::createTranslator(QObject *parent) +{ + return 0; +}; + +Q_EXPORT_PLUGIN(EffectSRConverterFactory) diff --git a/src/plugins/Effect/srconverter/effectsrconverterfactory.h b/src/plugins/Effect/srconverter/effectsrconverterfactory.h new file mode 100644 index 000000000..4112a3af5 --- /dev/null +++ b/src/plugins/Effect/srconverter/effectsrconverterfactory.h @@ -0,0 +1,46 @@ +/*************************************************************************** + * Copyright (C) 2007 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 EFFECTSRCONVERTERFACTORY_H +#define EFFECTSRCONVERTERFACTORY_H + + +#include <QObject> + +#include <effectfactory.h> +#include <effect.h> + +/** + @author Ilya Kotov <forkotov02@hotmail.ru> +*/ +class EffectSRConverterFactory : public QObject, public EffectFactory +{ +Q_OBJECT +Q_INTERFACES(EffectFactory); + +public: + const EffectProperties properties() const; + Effect *create(QObject *parent); + void showSettings(QWidget *parent); + void showAbout(QWidget *parent); + QTranslator *createTranslator(QObject *parent); +}; + + +#endif diff --git a/src/plugins/Effect/srconverter/settingsdialog.cpp b/src/plugins/Effect/srconverter/settingsdialog.cpp new file mode 100644 index 000000000..d4e017bba --- /dev/null +++ b/src/plugins/Effect/srconverter/settingsdialog.cpp @@ -0,0 +1,48 @@ +/*************************************************************************** + * Copyright (C) 2007 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 <QSettings> +#include <QDir> + +#include "settingsdialog.h" + +SettingsDialog::SettingsDialog(QWidget *parent) + : QDialog(parent) +{ + ui.setupUi(this); + setAttribute(Qt::WA_DeleteOnClose, TRUE); + QSettings settings(QDir::homePath()+"/.qmmp/qmmprc", QSettings::IniFormat); + ui.srSpinBox->setValue(settings.value("SRC/sample_rate",48000).toInt()); + ui.engineComboBox->setCurrentIndex(settings.value("SRC/engine", 0).toInt()); + connect (ui.okButton, SIGNAL(clicked()),SLOT(writeSettings())); +} + + +SettingsDialog::~SettingsDialog() +{ +} + +void SettingsDialog::writeSettings() +{ + QSettings settings(QDir::homePath()+"/.qmmp/qmmprc", QSettings::IniFormat); + settings.setValue("SRC/sample_rate",ui.srSpinBox->value()); + settings.setValue("SRC/engine", ui.engineComboBox->currentIndex()); + accept(); +} diff --git a/src/plugins/Effect/srconverter/settingsdialog.h b/src/plugins/Effect/srconverter/settingsdialog.h new file mode 100644 index 000000000..b7c466477 --- /dev/null +++ b/src/plugins/Effect/srconverter/settingsdialog.h @@ -0,0 +1,46 @@ +/*************************************************************************** + * Copyright (C) 2007 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 SETTINGSDIALOG_H +#define SETTINGSDIALOG_H + +#include <QDialog> + +#include "ui_settingsdialog.h" + +/** + @author Ilya Kotov <forkotov02@hotmail.ru> +*/ +class SettingsDialog : public QDialog +{ +Q_OBJECT +public: + SettingsDialog(QWidget *parent = 0); + + ~SettingsDialog(); + +private slots: + void writeSettings(); + +private: + Ui::SettingsDialog ui; + +}; + +#endif diff --git a/src/plugins/Effect/srconverter/settingsdialog.ui b/src/plugins/Effect/srconverter/settingsdialog.ui new file mode 100644 index 000000000..e837c9cf0 --- /dev/null +++ b/src/plugins/Effect/srconverter/settingsdialog.ui @@ -0,0 +1,124 @@ +<ui version="4.0" > + <class>SettingsDialog</class> + <widget class="QDialog" name="SettingsDialog" > + <property name="geometry" > + <rect> + <x>0</x> + <y>0</y> + <width>357</width> + <height>107</height> + </rect> + </property> + <property name="windowTitle" > + <string>Sample Rate Converter Plugin Settings</string> + </property> + <layout class="QGridLayout" > + <item row="0" column="0" > + <widget class="QLabel" name="label" > + <property name="text" > + <string>Sample Rate (Hz):</string> + </property> + </widget> + </item> + <item row="0" column="1" > + <widget class="QSpinBox" name="srSpinBox" > + <property name="maximum" > + <number>96000</number> + </property> + <property name="singleStep" > + <number>100</number> + </property> + <property name="value" > + <number>48000</number> + </property> + </widget> + </item> + <item row="1" column="0" > + <widget class="QLabel" name="label_2" > + <property name="text" > + <string>Interpolation Engine:</string> + </property> + </widget> + </item> + <item row="1" column="1" > + <widget class="QComboBox" name="engineComboBox" > + <item> + <property name="text" > + <string>Best Sinc Interpolation</string> + </property> + </item> + <item> + <property name="text" > + <string>Medium Sinc Interpolation</string> + </property> + </item> + <item> + <property name="text" > + <string>Fastest Sinc Interpolation</string> + </property> + </item> + <item> + <property name="text" > + <string>ZOH Interpolation</string> + </property> + </item> + <item> + <property name="text" > + <string>Linear Interpolation</string> + </property> + </item> + </widget> + </item> + <item row="2" column="0" > + <spacer> + <property name="orientation" > + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" > + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item row="2" column="1" > + <layout class="QHBoxLayout" > + <item> + <widget class="QPushButton" name="okButton" > + <property name="text" > + <string>&OK</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="cancelButton" > + <property name="text" > + <string>&Cancel</string> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + <resources/> + <connections> + <connection> + <sender>cancelButton</sender> + <signal>clicked()</signal> + <receiver>SettingsDialog</receiver> + <slot>reject()</slot> + <hints> + <hint type="sourcelabel" > + <x>302</x> + <y>88</y> + </hint> + <hint type="destinationlabel" > + <x>42</x> + <y>69</y> + </hint> + </hints> + </connection> + </connections> +</ui> diff --git a/src/plugins/Effect/srconverter/srconverter.cpp b/src/plugins/Effect/srconverter/srconverter.cpp new file mode 100644 index 000000000..0e733c8c4 --- /dev/null +++ b/src/plugins/Effect/srconverter/srconverter.cpp @@ -0,0 +1,125 @@ +/*************************************************************************** + * Copyright (C) 2007 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 <QSettings> +#include <QDir> +#include <math.h> + +#include "srconverter.h" + +SRConverter::SRConverter(QObject* parent) : Effect(parent) +{ + m_isSrcAlloc = FALSE; + int converter_type_array[] = {SRC_SINC_BEST_QUALITY, SRC_SINC_MEDIUM_QUALITY, SRC_SINC_FASTEST, + SRC_ZERO_ORDER_HOLD, SRC_LINEAR}; + m_srcIn = 0; + m_srcOut = 0; + m_src_state = 0; + m_srcError = 0; + QSettings settings(QDir::homePath()+"/.qmmp/qmmprc", QSettings::IniFormat); + m_overSamplingFs = settings.value("SRC/sample_rate",48000).toInt(); + m_converter_type = converter_type_array[settings.value("SRC/engine", 0).toInt()]; +} + +SRConverter::~SRConverter() +{ + src_reset (m_src_state) ; + freeSRC(); + m_src_data.data_in = 0; + m_src_data.data_out = 0; + m_src_data.end_of_input = 0; + m_src_data.input_frames = 0; + m_src_data.output_frames = 0; + if (m_isSrcAlloc) + { + free(m_srcIn); + free(m_srcOut); + free(m_wOut); + m_isSrcAlloc = FALSE; + } +} + +const ulong SRConverter::process(char *in_data, const ulong size, char **out_data) +{ + if (m_isSrcAlloc) + { + free(m_srcIn); + free(m_srcOut); + free(m_wOut); + m_isSrcAlloc = FALSE; + } + ulong wbytes = 0; + + if (m_src_state && size > 0) + { + int lrLength = size/2; + int overLrLength= (int)floor(lrLength*(m_src_data.src_ratio+1)); + m_srcIn = (float*) malloc(sizeof(float)*lrLength); + m_srcOut = (float*) malloc(sizeof(float)*overLrLength); + m_wOut = (short int*) malloc(sizeof(short int)*overLrLength); + src_short_to_float_array((short int*)in_data, m_srcIn, lrLength); + m_isSrcAlloc = TRUE; + m_src_data.data_in = m_srcIn; + m_src_data.data_out = m_srcOut; + m_src_data.end_of_input = 0; + m_src_data.input_frames = lrLength/2; + m_src_data.output_frames = overLrLength/2; + if ((m_srcError = src_process(m_src_state, &m_src_data)) > 0) + { + qWarning("SRConverter: src_process(): %s\n", src_strerror(m_srcError)); + } + else + { + src_float_to_short_array(m_srcOut, m_wOut, m_src_data.output_frames_gen*2); + wbytes = m_src_data.output_frames_gen*4; + *out_data = new char[wbytes]; + memcpy(*out_data, (char*) m_wOut, wbytes); + } + } + return wbytes; +} + +void SRConverter::configure(ulong freq, int chan, int res) +{ + Effect::configure(freq, chan, res); + freeSRC(); + uint rate = freq; + { + m_src_state = src_new(m_converter_type, 2, &m_srcError); + if (m_src_state) + { + m_src_data.src_ratio = (float)m_overSamplingFs/(float)rate; + rate = m_overSamplingFs; + } + else + qDebug("SRConverter: src_new(): %s", src_strerror(m_srcError)); + } +} + +const ulong SRConverter::frequency() +{ + return m_overSamplingFs; +} + +void SRConverter::freeSRC() +{ + if (m_src_state != NULL) + m_src_state = src_delete(m_src_state); +} diff --git a/src/plugins/Effect/srconverter/srconverter.h b/src/plugins/Effect/srconverter/srconverter.h new file mode 100644 index 000000000..8c6dcb6d3 --- /dev/null +++ b/src/plugins/Effect/srconverter/srconverter.h @@ -0,0 +1,59 @@ +/*************************************************************************** + * Copyright (C) 2007 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 SRCONVERTER_H +#define SRCONVERTER_H + +#include <effect.h> + +extern "C" +{ +#include <samplerate.h> +} + +/** + @author Ilya Kotov <forkotov02@hotmail.ru> +*/ + +class SRConverter : public Effect +{ + Q_OBJECT +public: + SRConverter(QObject *parent = 0); + + virtual ~SRConverter(); + + const ulong process(char *in_data, const ulong size, char **out_data); + void configure(ulong freq, int chan, int res); + const ulong frequency(); + +private: + void freeSRC(); + SRC_STATE *m_src_state; + SRC_DATA m_src_data; + int m_overSamplingFs; + int m_srcError; + int m_converter_type; + bool m_isSrcAlloc; + float *m_srcIn, *m_srcOut; + short *m_wOut; + ulong m_freq; +}; + +#endif diff --git a/src/plugins/Effect/srconverter/srconverter.pro b/src/plugins/Effect/srconverter/srconverter.pro new file mode 100644 index 000000000..af20c1e92 --- /dev/null +++ b/src/plugins/Effect/srconverter/srconverter.pro @@ -0,0 +1,34 @@ +include(../../plugins.pri) + +HEADERS += srconverter.h \ + effectsrconverterfactory.h \ + settingsdialog.h + +SOURCES += srconverter.cpp \ + effectsrconverterfactory.cpp \ + settingsdialog.cpp + +TARGET=$$PLUGINS_PREFIX/Effect/srconverter +QMAKE_CLEAN =$$PLUGINS_PREFIX/Effect/libsrconverter.so +INCLUDEPATH += ../../../qmmp +CONFIG += release \ +warn_on \ +plugin \ +link_pkgconfig + +PKGCONFIG += samplerate +TEMPLATE = lib +QMAKE_LIBDIR += ../../../../lib +LIBS += -lqmmp -L/usr/lib -I/usr/include + +#TRANSLATIONS = translations/ffmpeg_plugin_ru.ts +#RESOURCES = translations/translations.qrc + +isEmpty(LIB_DIR){ + LIB_DIR = /lib +} +target.path = $$LIB_DIR/qmmp/Effect +INSTALLS += target + +FORMS += settingsdialog.ui + |
