diff options
| -rw-r--r-- | src/qmmp/channelconverter.cpp | 56 | ||||
| -rw-r--r-- | src/qmmp/channelconverter_p.h | 3 | ||||
| -rw-r--r-- | src/qmmp/outputwriter.cpp | 64 | ||||
| -rw-r--r-- | src/qmmp/outputwriter_p.h | 6 | ||||
| -rw-r--r-- | src/qmmp/qmmpaudioengine.cpp | 15 |
5 files changed, 47 insertions, 97 deletions
diff --git a/src/qmmp/channelconverter.cpp b/src/qmmp/channelconverter.cpp index 3fb21082b..b8139e4e6 100644 --- a/src/qmmp/channelconverter.cpp +++ b/src/qmmp/channelconverter.cpp @@ -24,7 +24,6 @@ ChannelConverter::ChannelConverter(ChannelMap out_map) { m_disabled = true; m_tmp_buf = 0; - m_frame_size = 0; m_channels = 0; m_out_map = out_map; memset(m_reorder_array, 0, sizeof(m_reorder_array)); @@ -47,8 +46,7 @@ void ChannelConverter::configure(quint32 srate, ChannelMap in_map) return; m_channels = channels(); - m_frame_size = audioParameters().sampleSize() * channels(); - m_tmp_buf = new unsigned char[m_frame_size]; + m_tmp_buf = new float[m_channels]; QStringList reorderStringList; for(int i = 0; i < m_channels; ++i) @@ -63,55 +61,19 @@ void ChannelConverter::configure(quint32 srate, ChannelMap in_map) void ChannelConverter::applyEffect(Buffer *b) { - /*if(m_disabled) + if(m_disabled) return; unsigned long i = 0; int j = 0; - switch(m_format) + float *data = b->data; + for(i = 0; i < b->samples; ++i) { - case Qmmp::PCM_S8: - { - unsigned char *data = b->data; - unsigned char *prev_data = m_tmp_buf; - for(i = 0; i < b->nbytes/m_frame_size; ++i) - { - memcpy(m_tmp_buf, data, m_frame_size); - for(j = 0; j < m_channels; ++j) - data[j] = m_reorder_array[j] < 0 ? 0 : prev_data[m_reorder_array[j]]; - data += m_channels; - } - break; - } - case Qmmp::PCM_S16LE: - { - quint16 *data = (quint16 *) b->data; - quint16 *prev_data = (quint16 *) m_tmp_buf; - for(i = 0; i < b->nbytes/m_frame_size; ++i) - { - memcpy(m_tmp_buf, data, m_frame_size); - for(j = 0; j < m_channels; ++j) - data[j] = m_reorder_array[j] < 0 ? 0 : prev_data[m_reorder_array[j]]; - data += m_channels; - } - break; + memcpy(m_tmp_buf, data, m_channels * sizeof(float)); + for(j = 0; j < m_channels; ++j) + data[j] = m_reorder_array[j] < 0 ? 0 : m_tmp_buf[m_reorder_array[j]]; + data += m_channels; } - case Qmmp::PCM_S24LE: - case Qmmp::PCM_S32LE: - { - quint32 *data = (quint32 *) b->data; - quint32 *prev_data = (quint32 *) m_tmp_buf; - for(i = 0; i < b->nbytes/m_frame_size; ++i) - { - memcpy(m_tmp_buf, data, m_frame_size); - for(j = 0; j < m_channels; ++j) - data[j] = m_reorder_array[j] < 0 ? 0 : prev_data[m_reorder_array[j]]; - data += m_channels; - } - break; - } - default: - ; - }*/ + } diff --git a/src/qmmp/channelconverter_p.h b/src/qmmp/channelconverter_p.h index 499e76961..0667c4ee8 100644 --- a/src/qmmp/channelconverter_p.h +++ b/src/qmmp/channelconverter_p.h @@ -37,8 +37,7 @@ public: private: bool m_disabled; int m_reorder_array[9]; - unsigned char *m_tmp_buf; - int m_frame_size; + float *m_tmp_buf; int m_channels; ChannelMap m_out_map; }; diff --git a/src/qmmp/outputwriter.cpp b/src/qmmp/outputwriter.cpp index cc66b4158..6ba10702a 100644 --- a/src/qmmp/outputwriter.cpp +++ b/src/qmmp/outputwriter.cpp @@ -74,7 +74,8 @@ OutputWriter::OutputWriter (QObject* parent) : QThread (parent) m_useEq = false; m_muted = false; m_settings = QmmpSettings::instance(); - m_converter = new AudioConverter(); + m_format_converter = 0; + m_channel_converter = 0; } OutputWriter::~OutputWriter() @@ -89,7 +90,10 @@ OutputWriter::~OutputWriter() delete[] m_visBuffer; m_visBuffer = 0; } - delete m_converter; + if(m_format_converter) + delete m_format_converter; + if(m_channel_converter) + delete m_channel_converter; } bool OutputWriter::initialize(quint32 freq, ChannelMap map) @@ -269,59 +273,46 @@ void OutputWriter::dispatchVisual (Buffer *buffer) m_visBuffer = 0;*/ } -void OutputWriter::applyConverters(Buffer *buffer) -{ - for (int i = 0; i < m_converters.count(); ++i) - { - m_converters[i]->applyEffect(buffer); - } -} - void OutputWriter::clearVisuals() { foreach (Visual *visual, *Visual::visuals()) { visual->mutex()->lock (); - visual->clear (); + visual->clear(); visual->mutex()->unlock(); } } bool OutputWriter::prepareConverters() { - m_converter->configure(m_output->audioParameters().format()); - /*qDeleteAll(m_converters); - m_converters.clear(); - - AudioParameters ap = m_output->audioParameters(); + if(m_format_converter) + { + delete m_format_converter; + m_format_converter = 0; + } + if(m_channel_converter) + { + delete m_channel_converter; + m_channel_converter = 0; + } - if(channels() != m_output->channels()) + if(m_channels != m_output->channels()) { qWarning("OutputWriter: unsupported channel number"); return false; } - if(format() != ap.format()) + if(m_in_params.format() != m_format) { - if(m_output->format() == Qmmp::PCM_S16LE) - { - qDebug("OutputWriter: using 16 bit comverter"); - m_converters << new AudioConverter(); - m_converters.last()->configure(sampleRate(), channelMap(), format()); - } - else - { - qWarning("OutputWriter: unsupported audio format"); - return false; - } + m_format_converter = new AudioConverter(); + m_format_converter->configure(m_format); } - if(channelMap() != ap.channelMap()) + if(m_in_params.channelMap() != m_chan_map) { - m_converters << new ChannelConverter(ap.channelMap()); - m_converters.last()->configure(sampleRate(), channelMap(), ap.format()); - }*/ - + m_channel_converter = new ChannelConverter(m_chan_map); + m_channel_converter->configure(m_in_params.sampleRate(), m_in_params.channelMap()); + } return true; } @@ -426,13 +417,14 @@ void OutputWriter::run() SoftwareVolume::instance()->changeVolume(b, m_channels, m_format); if (m_muted) memset(b->data, 0, b->size * sizeof(float)); - applyConverters(b); + if(m_channel_converter) + m_channel_converter->applyEffect(b); l = 0; m = 0; size_t samples = b->samples; unsigned char buf[samples * 2]; - m_converter->fromFloat(b->data, buf, samples); + m_format_converter->fromFloat(b->data, buf, samples); while (l < samples * 2 && !m_pause && !m_prev_pause) diff --git a/src/qmmp/outputwriter_p.h b/src/qmmp/outputwriter_p.h index 944826dd9..2c1412796 100644 --- a/src/qmmp/outputwriter_p.h +++ b/src/qmmp/outputwriter_p.h @@ -33,6 +33,7 @@ class StateHandler; class Output; class Effect; class AudioConverter; +class ChannelConverter; /** @internal @brief Output thread. @@ -116,7 +117,6 @@ private: int channels); void dispatch(const Qmmp::State &state); void dispatchVisual(Buffer *buffer); - void applyConverters(Buffer *buffer); void clearVisuals(); bool prepareConverters(); @@ -140,8 +140,8 @@ private: Output *m_output; bool m_muted; AudioParameters m_in_params; - QList<Effect *> m_converters; - AudioConverter *m_converter; + AudioConverter *m_format_converter; + ChannelConverter *m_channel_converter; }; #endif // OUTPUTWRITER_P_H diff --git a/src/qmmp/qmmpaudioengine.cpp b/src/qmmp/qmmpaudioengine.cpp index cf8376d17..7da96a5c2 100644 --- a/src/qmmp/qmmpaudioengine.cpp +++ b/src/qmmp/qmmpaudioengine.cpp @@ -600,12 +600,6 @@ OutputWriter *QmmpAudioEngine::createOutput() StateHandler::instance()->dispatch(Qmmp::FatalError); return 0; } - - /*if(m_output_buf) - delete [] m_output_buf; - m_bks = output->recycler()->blockSamples() * m_ap.sampleSize(); - m_output_size = m_bks * 4; - m_output_buf = new unsigned char[m_output_size];*/ return output; } @@ -637,9 +631,12 @@ void QmmpAudioEngine::prepareEffects(Decoder *d) QList <Effect *> tmp_effects = m_effects; m_effects.clear(); - m_effects << new ChannelConverter(m_ap.channelMap().remaped()); - m_effects.at(0)->configure(m_ap.sampleRate(), m_ap.channelMap()); - m_ap = m_effects.at(0)->audioParameters(); + if(m_ap.channelMap() != m_ap.channelMap().remaped()) + { + m_effects << new ChannelConverter(m_ap.channelMap().remaped()); + m_effects.last()->configure(m_ap.sampleRate(), m_ap.channelMap()); + m_ap = m_effects.last()->audioParameters(); + } foreach(EffectFactory *factory, Effect::enabledFactories()) { |
