aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2019-06-07 21:30:47 +0000
committertrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2019-06-07 21:30:47 +0000
commit3c8011ce75cdfe520a1aa7fd26be572fa9368894 (patch)
treef7a35c74991d4e6edf96ee50c4c21f5fbe2edf88 /src
parente3c013c70396242bd813e50af78d35923ea7eb62 (diff)
downloadqmmp-3c8011ce75cdfe520a1aa7fd26be572fa9368894.tar.gz
qmmp-3c8011ce75cdfe520a1aa7fd26be572fa9368894.tar.bz2
qmmp-3c8011ce75cdfe520a1aa7fd26be572fa9368894.zip
improved channel converter (#1003)
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@8893 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src')
-rw-r--r--src/qmmp/channelconverter.cpp53
-rw-r--r--src/qmmp/channelconverter_p.h6
2 files changed, 41 insertions, 18 deletions
diff --git a/src/qmmp/channelconverter.cpp b/src/qmmp/channelconverter.cpp
index bf00367f4..da7086b98 100644
--- a/src/qmmp/channelconverter.cpp
+++ b/src/qmmp/channelconverter.cpp
@@ -1,5 +1,5 @@
/***************************************************************************
- * Copyright (C) 2014-2015 by Ilya Kotov *
+ * Copyright (C) 2014-2019 by Ilya Kotov *
* forkotov02@ya.ru *
* *
* This program is free software; you can redistribute it and/or modify *
@@ -24,7 +24,7 @@ ChannelConverter::ChannelConverter(ChannelMap out_map)
{
m_disabled = true;
m_tmp_buf = nullptr;
- m_channels = 0;
+ m_tmp_size = 0;
m_out_map = out_map;
memset(m_reorder_array, 0, sizeof(m_reorder_array));
}
@@ -45,13 +45,17 @@ void ChannelConverter::configure(quint32 srate, ChannelMap in_map)
if((m_disabled = (in_map == m_out_map)))
return;
- m_channels = channels();
- m_tmp_buf = new float[m_channels];
+ if((m_disabled = (in_map.count() == 1 && m_out_map.count() == 1)))
+ return;
+
+ m_in_map = in_map;
+ m_tmp_buf = new float[QMMP_BLOCK_FRAMES * in_map.count()];
+ m_tmp_size = QMMP_BLOCK_FRAMES * in_map.count();
- QStringList reorderStringList;
- for(int i = 0; i < m_channels; ++i)
+ QStringList reorderStringList;
+ for(int i = 0; i < m_out_map.count(); ++i)
{
- m_reorder_array[i] = m_out_map.indexOf(in_map.at(i));
+ m_reorder_array[i] = m_out_map.indexOf(in_map.at(i % in_map.count()));
reorderStringList << QString("%1").arg(m_reorder_array[i]);
}
@@ -64,16 +68,35 @@ void ChannelConverter::applyEffect(Buffer *b)
if(m_disabled)
return;
- unsigned long i = 0;
- int j = 0;
+ int in_channels = m_in_map.count();
+ int out_channels = m_out_map.count();
+
+ if(b->samples > m_tmp_size)
+ {
+ delete [] m_tmp_buf;
+ m_tmp_buf = new float[b->samples];
+ m_tmp_size = b->samples;
+ }
+ memcpy(m_tmp_buf, b->data, b->samples * sizeof(float));
+
+ size_t samples = b->samples * out_channels / in_channels;
+ if(samples > b->size)
+ {
+ delete [] b->data;
+ b->data = new float[samples];
+ b->size = samples;
+ }
+
+ float *in = m_tmp_buf;
+ float *out = b->data;
- float *data = b->data;
- for(i = 0; i < b->samples / m_channels; ++i)
+ for(unsigned long i = 0; i < b->samples / in_channels; ++i)
{
- 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;
+ for(int j = 0; j < out_channels; ++j)
+ out[j] = m_reorder_array[j] < 0 ? 0 : in[m_reorder_array[j]];
+ in += in_channels;
+ out += out_channels;
}
+ b->samples = samples;
}
diff --git a/src/qmmp/channelconverter_p.h b/src/qmmp/channelconverter_p.h
index c5d4097cc..d574b5095 100644
--- a/src/qmmp/channelconverter_p.h
+++ b/src/qmmp/channelconverter_p.h
@@ -1,5 +1,5 @@
/***************************************************************************
- * Copyright (C) 2014-2015 by Ilya Kotov *
+ * Copyright (C) 2014-2019 by Ilya Kotov *
* forkotov02@ya.ru *
* *
* This program is free software; you can redistribute it and/or modify *
@@ -38,8 +38,8 @@ private:
bool m_disabled;
int m_reorder_array[9];
float *m_tmp_buf;
- int m_channels;
- ChannelMap m_out_map;
+ size_t m_tmp_size;
+ ChannelMap m_out_map, m_in_map;
};
#endif // CHANNELCONVERTER_P_H