aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2015-12-25 19:01:55 +0000
committertrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2015-12-25 19:01:55 +0000
commit5c9ab872f2d8fbb3871e79216663e4c8213962a6 (patch)
tree3bf846a8b2acab8dad49ffcf1781674c942b827c /src
parent34302dce029704499fdc0c2ebf5988cd8baf1f7d (diff)
downloadqmmp-5c9ab872f2d8fbb3871e79216663e4c8213962a6.tar.gz
qmmp-5c9ab872f2d8fbb3871e79216663e4c8213962a6.tar.bz2
qmmp-5c9ab872f2d8fbb3871e79216663e4c8213962a6.zip
fixed channel converter
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@5884 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src')
-rw-r--r--src/qmmp/channelconverter.cpp56
-rw-r--r--src/qmmp/channelconverter_p.h3
-rw-r--r--src/qmmp/outputwriter.cpp64
-rw-r--r--src/qmmp/outputwriter_p.h6
-rw-r--r--src/qmmp/qmmpaudioengine.cpp15
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())
{