diff options
| -rw-r--r-- | src/plugins/Effect/srconverter/srconverter.cpp | 52 | ||||
| -rw-r--r-- | src/plugins/Effect/srconverter/srconverter.h | 3 |
2 files changed, 40 insertions, 15 deletions
diff --git a/src/plugins/Effect/srconverter/srconverter.cpp b/src/plugins/Effect/srconverter/srconverter.cpp index f5731e499..969cd5eb0 100644 --- a/src/plugins/Effect/srconverter/srconverter.cpp +++ b/src/plugins/Effect/srconverter/srconverter.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2007-2012 by Ilya Kotov * + * Copyright (C) 2007-2013 by Ilya Kotov * * forkotov02@hotmail.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -22,7 +22,6 @@ #include <math.h> #include <stdlib.h> #include <qmmp/qmmp.h> - #include "srconverter.h" SRConverter::SRConverter() : Effect() @@ -31,6 +30,7 @@ SRConverter::SRConverter() : Effect() SRC_ZERO_ORDER_HOLD, SRC_LINEAR}; m_src_state = 0; m_srcError = 0; + m_sz = 0; QSettings settings(Qmmp::configFile(), QSettings::IniFormat); m_overSamplingFs = settings.value("SRC/sample_rate",48000).toInt(); m_converter_type = converter_type_array[settings.value("SRC/engine", 0).toInt()]; @@ -38,40 +38,60 @@ SRConverter::SRConverter() : Effect() 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; + m_sz = 0; } void SRConverter::applyEffect(Buffer *b) { if (m_src_state && b->nbytes > 0) { - m_src_data.input_frames = b->nbytes / 2 / channels(); + m_src_data.end_of_input = 0; + m_src_data.input_frames = b->nbytes / m_sz / channels(); m_src_data.data_in = new float [m_src_data.input_frames * channels()]; m_src_data.output_frames = m_src_data.src_ratio * m_src_data.input_frames + 1; - m_src_data.end_of_input = 0; m_src_data.data_out = new float [m_src_data.output_frames * channels()]; - src_short_to_float_array((short*) b->data, m_src_data.data_in, - m_src_data.input_frames * channels()); + + + if(format() == Qmmp::PCM_S16LE) + { + src_short_to_float_array((short*) b->data, m_src_data.data_in, + m_src_data.input_frames * channels()); + } + else + { + src_int_to_float_array((int*) b->data, m_src_data.data_in, + m_src_data.input_frames * channels()); + } + if ((m_srcError = src_process(m_src_state, &m_src_data)) > 0) { qWarning("SRConverter: src_process(): %s\n", src_strerror(m_srcError)); } else { - qint16 *out_data = new qint16 [m_src_data.output_frames_gen * channels()]; - src_float_to_short_array(m_src_data.data_out, out_data, - m_src_data.output_frames_gen*channels()); - b->nbytes = m_src_data.output_frames_gen * channels() * 2; + uchar *out_data = new uchar[m_src_data.output_frames_gen * channels() * m_sz];; + if(format() == Qmmp::PCM_S16LE) + { + src_float_to_short_array(m_src_data.data_out, (short*)out_data, + m_src_data.output_frames_gen * channels()); + + } + else + { + src_float_to_int_array(m_src_data.data_out, (int*)out_data, + m_src_data.output_frames_gen * channels()); + } + b->nbytes = m_src_data.output_frames_gen * channels() * m_sz; if(b->nbytes > b->size) { delete [] b->data; - b->data = (uchar *) out_data; + b->data = out_data; } else { @@ -88,7 +108,7 @@ void SRConverter::applyEffect(Buffer *b) void SRConverter::configure(quint32 freq, int chan, Qmmp::AudioFormat format) { freeSRC(); - if(freq != m_overSamplingFs) + if(freq != m_overSamplingFs && format != Qmmp::PCM_S8) { m_src_state = src_new(m_converter_type, chan, &m_srcError); if (m_src_state) @@ -100,11 +120,15 @@ void SRConverter::configure(quint32 freq, int chan, Qmmp::AudioFormat format) qDebug("SRConverter: src_new(): %s", src_strerror(m_srcError)); } Effect::configure(m_overSamplingFs, chan, format); + m_sz = audioParameters().sampleSize(); } void SRConverter::freeSRC() { if (m_src_state) - m_src_state = src_delete(m_src_state); + { + src_reset(m_src_state); + src_delete(m_src_state); + } m_src_state = 0; } diff --git a/src/plugins/Effect/srconverter/srconverter.h b/src/plugins/Effect/srconverter/srconverter.h index 0f5e17e15..f25ebc491 100644 --- a/src/plugins/Effect/srconverter/srconverter.h +++ b/src/plugins/Effect/srconverter/srconverter.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2007-2012 by Ilya Kotov * + * Copyright (C) 2007-2013 by Ilya Kotov * * forkotov02@hotmail.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -43,6 +43,7 @@ private: quint32 m_overSamplingFs; int m_srcError; int m_converter_type; + int m_sz; //sample size quint32 m_freq; }; |
