diff options
| author | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2021-09-19 14:34:05 +0000 |
|---|---|---|
| committer | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2021-09-19 14:34:05 +0000 |
| commit | bf033d40386c2654b2a2b60dd8a90a43099d3be4 (patch) | |
| tree | a629022bce2682211d86997d5b03e8310ddc1a62 /src/plugins/Input/xmp/decoder_xmp.cpp | |
| parent | c034c4d62c0b02404bd65c9cab478e3ae00d0883 (diff) | |
| download | qmmp-bf033d40386c2654b2a2b60dd8a90a43099d3be4.tar.gz qmmp-bf033d40386c2654b2a2b60dd8a90a43099d3be4.tar.bz2 qmmp-bf033d40386c2654b2a2b60dd8a90a43099d3be4.zip | |
replaced modplug by xmp
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@10304 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src/plugins/Input/xmp/decoder_xmp.cpp')
| -rw-r--r-- | src/plugins/Input/xmp/decoder_xmp.cpp | 137 |
1 files changed, 137 insertions, 0 deletions
diff --git a/src/plugins/Input/xmp/decoder_xmp.cpp b/src/plugins/Input/xmp/decoder_xmp.cpp new file mode 100644 index 000000000..0aa52dccf --- /dev/null +++ b/src/plugins/Input/xmp/decoder_xmp.cpp @@ -0,0 +1,137 @@ +/*************************************************************************** + * Copyright (C) 2015-2021 by Ilya Kotov * + * forkotov02@ya.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., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#include <QObject> +#include <QSettings> +#include <QDir> +#include <QSettings> +#include "decoder_xmp.h" + +// Decoder class + +DecoderXmp *DecoderXmp::m_instance = nullptr; + +DecoderXmp::DecoderXmp(const QString &path) : Decoder(nullptr), m_path(path) +{ + m_instance = this; +} + +DecoderXmp::~DecoderXmp() +{ + if(m_instance == this) + m_instance = nullptr; + deinit(); +} + +DecoderXmp *DecoderXmp::instance() +{ + return m_instance; +} + +bool DecoderXmp::initialize() +{ + m_ctx = xmp_create_context(); + + int err = xmp_load_module(m_ctx, m_path.toLocal8Bit().data()); + if(err != 0) + { + qWarning("DecoderXmp: unable to load module file, error = %d", err); + xmp_free_context(m_ctx); + m_ctx = nullptr; + return false; + } + + xmp_module_info mi; + xmp_get_module_info(m_ctx, &mi); + + m_totalTime = mi.seq_data[0].duration; + + QSettings settings(Qmmp::configFile(), QSettings::IniFormat); + m_srate = settings.value("Xmp/sample_rate", 44100).toInt(); + + xmp_start_player(m_ctx, m_srate, 0); + readSettings(); + + configure(m_srate, 2, Qmmp::PCM_S16LE); + return true; +} + +qint64 DecoderXmp::totalTime() const +{ + return m_totalTime; +} + +int DecoderXmp::bitrate() const +{ + return 8; +} + +qint64 DecoderXmp::read(unsigned char *audio, qint64 maxSize) +{ + int c = xmp_play_buffer(m_ctx, audio, maxSize, 1); + + if(c == 0) + return maxSize; + else if(c == -XMP_END) + return 0; + + return -1; +} + +void DecoderXmp::seek(qint64 pos) +{ + xmp_seek_time(m_ctx, pos); +} + +void DecoderXmp::deinit() +{ + if(m_ctx) + { + xmp_end_player(m_ctx); + xmp_release_module(m_ctx); + xmp_free_context(m_ctx); + m_ctx = nullptr; + } +} + +void DecoderXmp::readSettings() +{ + if(m_ctx) + { + QSettings settings(Qmmp::configFile(), QSettings::IniFormat); + settings.beginGroup("Xmp"); + xmp_set_player(m_ctx, XMP_PLAYER_AMP, settings.value("amp_factor", 1).toInt()); + xmp_set_player(m_ctx, XMP_PLAYER_MIX, settings.value("stereo_mix", 70).toInt()); + xmp_set_player(m_ctx, XMP_PLAYER_INTERP, settings.value("interpolation", XMP_INTERP_LINEAR).toInt()); + int flags = 0; + if(settings.value("lowpass", false).toBool()) + flags |= XMP_DSP_LOWPASS; + xmp_set_player(m_ctx, XMP_PLAYER_DSP, flags); + flags = 0; + if(settings.value("vblank", false).toBool()) + flags |= XMP_FLAGS_VBLANK; + if(settings.value("fx9bug", false).toBool()) + flags |= XMP_FLAGS_FX9BUG; + xmp_set_player(m_ctx, XMP_PLAYER_FLAGS, flags); + + + settings.endGroup(); + } +} |
