Am 19.09.2013 17:36, schrieb Fons Adriaensen:
On Thu, Sep 19, 2013 at 05:18:27PM +0200, hermann meyer wrote:
Sorry, you miss-match aeolus and zita-convolver here.
As well, we didn't "add" ffmpeg support to zita-convolver, we
replace fftw3 with ffmpeg, and only use this under special
circumstances (ARM support), we didn't distribute it as
"zita-convolver library"
IFF
* the only change is the fft library used,
* the full functionality and API of the original is preserved,
* and the modified library is kept in sync with the original one,
then I have no objections to it being called 'zita-convolver',
and I would even consider to merge the two (which would ensure
the third condition).
Ciao,
Hi Fons
I've attached the diff, for your review.
Some of the changes are not necessary needed, but handy for our use case.
Ignore please the #include "gx_compiler.h" and __rt_func
regards
hermann
diff -uN ./zita-convolver/README ./zita-convolver-ffmpeg/README
--- ./zita-convolver/README 2012-12-06 11:09:33.644204127 +0100
+++ ./zita-convolver-ffmpeg/README 2013-05-05 14:16:32.446644834 +0200
@@ -1,8 +1,3 @@
Files in this directory are from zita-convolver by
-Fons Adriaensen <[email protected]>
-
-Please refer to the version official archive
-http://kokkinizita.linuxaudio.org/linuxaudio/
-
-These files are only included to ease compilation
-and installion of Guitarix. Don't modify.
+Fons Adriaensen <[email protected]>, which changes
+to use ffmpeg FFT instead of fftw3.
diff -uN ./zita-convolver/zita-convolver.cc ./zita-convolver-ffmpeg/zita-convolver.cc
--- ./zita-convolver/zita-convolver.cc 2012-12-06 11:09:33.644204127 +0100
+++ ./zita-convolver-ffmpeg/zita-convolver.cc 2013-05-08 04:35:21.602005621 +0200
@@ -22,9 +22,13 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
+#include <cmath>
+extern "C" {
+#define __STDC_CONSTANT_MACROS // needed for UINT64_C (libavutil 0.8.6)
+#include <libavutil/common.h>
+}
#include "zita-convolver.h"
-
-
+#include "gx_compiler.h"
int zita_convolver_major_version (void)
{
@@ -38,7 +42,6 @@
Convproc::Convproc (void) :
_state (ST_IDLE),
- _options (0),
_skipcnt (0),
_density (0),
_ninp (0),
@@ -61,12 +64,6 @@
}
-void Convproc::set_options (unsigned int options)
-{
- _options = options;
-}
-
-
void Convproc::set_density (float density)
{
_density = density;
@@ -147,7 +144,7 @@
if (cfft < d * cmac) npar = nmin;
}
_convlev [pind] = new Convlevel ();
- _convlev [pind]->configure (prio, offs, npar, size, _options);
+ _convlev [pind]->configure (prio, offs, npar, size);
offs += size * npar;
if (offs < maxsize)
@@ -281,7 +278,7 @@
}
-int Convproc::process (bool sync)
+int __rt_func Convproc::process (bool sync)
{
unsigned int k;
int f = 0;
@@ -303,7 +300,6 @@
{
if (++_latecnt >= 5)
{
- stop_process ();
f |= FL_LOAD;
}
}
@@ -354,7 +350,6 @@
}
_state = ST_IDLE;
- _options = 0;
_skipcnt = 0;
_density = 0;
_ninp = 0;
@@ -398,14 +393,11 @@
_stat (ST_IDLE),
_npar (0),
_parsize (0),
- _options (0),
_pthr (0),
_inp_list (0),
_out_list (0),
_plan_r2c (0),
_plan_c2r (0),
- _time_data (0),
- _prep_data (0),
_freq_data (0)
{
}
@@ -422,36 +414,28 @@
{
void *p;
- if (posix_memalign (&p, 16, size)) throw (Converror (Converror::MEM_ALLOC));
+ p = av_malloc(size);
memset (p, 0, size);
return p;
}
-
void Convlevel::configure (int prio,
unsigned int offs,
unsigned int npar,
- unsigned int parsize,
- unsigned int options)
+ unsigned int parsize)
{
- int fftwopt = (options & OPT_FFTW_MEASURE) ? FFTW_MEASURE : FFTW_ESTIMATE;
-
_prio = prio;
_offs = offs;
_npar = npar;
_parsize = parsize;
- _options = options;
- _time_data = (float *)(alloc_aligned (2 * _parsize * sizeof (float)));
- _prep_data = (float *)(alloc_aligned (2 * _parsize * sizeof (float)));
_freq_data = (fftwf_complex *)(alloc_aligned ((_parsize + 1) * sizeof (fftwf_complex)));
- _plan_r2c = fftwf_plan_dft_r2c_1d (2 * _parsize, _time_data, _freq_data, fftwopt);
- _plan_c2r = fftwf_plan_dft_c2r_1d (2 * _parsize, _freq_data, _time_data, fftwopt);
+ _plan_r2c = av_rdft_init (int(log2(2 * _parsize)), DFT_R2C);
+ _plan_c2r = av_rdft_init (int(log2(2 * _parsize)), IDFT_C2R);
if (_plan_r2c && _plan_c2r) return;
throw (Converror (Converror::MEM_ALLOC));
}
-
void Convlevel::impdata_create (unsigned int inp,
unsigned int out,
unsigned int step,
@@ -462,7 +446,7 @@
unsigned int k;
int j, j0, j1, n;
float norm;
- fftwf_complex *fftb;
+ fftwf_complex *fftb;
Macnode *M;
n = i1 - i0;
@@ -477,7 +461,7 @@
memset (M->_fftb, 0, _npar * sizeof (fftwf_complex *));
}
- norm = 0.5f / _parsize;
+ norm = 1.0f / _parsize;
for (k = 0; k < _npar; k++)
{
i1 = i0 + _parsize;
@@ -487,14 +471,16 @@
{
M->_fftb [k] = (fftwf_complex *)(alloc_aligned ((_parsize + 1) * sizeof (fftwf_complex)));
}
- memset (_prep_data, 0, 2 * _parsize * sizeof (float));
+ float *prepdata = (float*)_freq_data;
+ memset (prepdata, 0, 2 * (_parsize+1) * sizeof (float));
j0 = (i0 < 0) ? 0 : i0;
j1 = (i1 > n) ? n : i1;
- for (j = j0; j < j1; j++) _prep_data [j - i0] = norm * data [j * step];
- fftwf_execute_dft_r2c (_plan_r2c, _prep_data, _freq_data);
-#ifdef ENABLE_VECTOR_MODE
- if (_options & OPT_VECTOR_MODE) fftswap (_freq_data);
-#endif
+ for (j = j0; j < j1; j++) prepdata [j - i0] = norm * data [j * step];
+ av_rdft_calc(_plan_r2c, prepdata);
+ // adjust for packing convention
+ _freq_data[_parsize][0] = _freq_data[0][1];
+ _freq_data[0][1] = 0;
+ fftswap (_freq_data);
fftb = M->_fftb [k];
for (j = 0; j <= (int)_parsize; j++)
{
@@ -517,7 +503,7 @@
unsigned int k;
int j, j0, j1, n;
float norm;
- fftwf_complex *fftb;
+ fftwf_complex *fftb;
Macnode *M;
M = findmacnode (inp, out, false);
@@ -528,21 +514,24 @@
i1 = i0 + _npar * _parsize;
if ((i0 >= n) || (i1 <= 0)) return;
- norm = 0.5f / _parsize;
+ norm = 1.0f / _parsize;
for (k = 0; k < _npar; k++)
{
i1 = i0 + _parsize;
fftb = M->_fftb [k];
if (fftb && (i0 < n) && (i1 > 0))
{
- memset (_prep_data, 0, 2 * _parsize * sizeof (float));
+ float *prepdata = (float*)fftb;
+ memset (prepdata, 0, 2 * _parsize * sizeof (float));
j0 = (i0 < 0) ? 0 : i0;
j1 = (i1 > n) ? n : i1;
- for (j = j0; j < j1; j++) _prep_data [j - i0] = norm * data [j * step];
- fftwf_execute_dft_r2c (_plan_r2c, _prep_data, fftb);
-#ifdef ENABLE_VECTOR_MODE
- if (_options & OPT_VECTOR_MODE) fftswap (fftb);
-#endif
+ for (j = j0; j < j1; j++) prepdata [j - i0] = norm * data [j * step];
+ av_rdft_calc(_plan_r2c, prepdata);
+ // adjust for packing convention
+ fftb[_parsize][0] = fftb[0][1];
+ fftb[_parsize][1] = 0;
+ fftb[0][1] = 0;
+ fftswap (fftb);
}
i0 = i1;
}
@@ -690,15 +679,11 @@
}
_out_list = 0;
- fftwf_destroy_plan (_plan_r2c);
- fftwf_destroy_plan (_plan_c2r);
- free (_time_data);
- free (_prep_data);
+ av_rdft_end (_plan_r2c);
+ av_rdft_end (_plan_c2r);
free (_freq_data);
_plan_r2c = 0;
_plan_c2r = 0;
- _time_data = 0;
- _prep_data = 0;
_freq_data = 0;
}
@@ -710,7 +695,7 @@
}
-void Convlevel::main (void)
+void __rt_func Convlevel::main (void)
{
_stat = ST_PROC;
while (true)
@@ -728,7 +713,7 @@
}
-void Convlevel::process (bool skip)
+void __rt_func Convlevel::process (bool skip)
{
unsigned int i, j, k;
unsigned int i1, n1, n2, opi1, opi2;
@@ -758,13 +743,16 @@
for (X = _inp_list; X; X = X->_next)
{
inpd = _inpbuff [X->_inp];
- if (n1) memcpy (_time_data, inpd + i1, n1 * sizeof (float));
- if (n2) memcpy (_time_data + n1, inpd, n2 * sizeof (float));
- memset (_time_data + _parsize, 0, _parsize * sizeof (float));
- fftwf_execute_dft_r2c (_plan_r2c, _time_data, X->_ffta [_ptind]);
-#ifdef ENABLE_VECTOR_MODE
- if (_options & OPT_VECTOR_MODE) fftswap (X->_ffta [_ptind]);
-#endif
+ fftwf_complex *freqdata = X->_ffta [_ptind];
+ float *time_data = (float*)freqdata;
+ if (n1) memcpy (time_data, inpd + i1, n1 * sizeof (float));
+ if (n2) memcpy (time_data + n1, inpd, n2 * sizeof (float));
+ memset (time_data + _parsize, 0, (_parsize+2) * sizeof (float));
+ av_rdft_calc(_plan_r2c, time_data);
+ // adjust for packing convention
+ freqdata[_parsize][0] = freqdata[0][1];
+ freqdata[0][1] = 0;
+ fftswap (X->_ffta [_ptind]);
}
if (skip)
@@ -790,46 +778,32 @@
fftb = M->_fftb [j];
if (fftb)
{
-#ifdef ENABLE_VECTOR_MODE
- if (_options & OPT_VECTOR_MODE)
- {
- FV4 *A = (FV4 *) ffta;
- FV4 *B = (FV4 *) fftb;
- FV4 *D = (FV4 *) _freq_data;
- for (k = 0; k < _parsize; k += 4)
- {
- D [0] += A [0] * B [0] - A [1] * B [1];
- D [1] += A [0] * B [1] + A [1] * B [0];
- A += 2;
- B += 2;
- D += 2;
- }
- _freq_data [_parsize][0] += ffta [_parsize][0] * fftb [_parsize][0];
- _freq_data [_parsize][1] = 0;
- }
- else
-#endif
+ FV4 *A = (FV4 *) ffta;
+ FV4 *B = (FV4 *) fftb;
+ FV4 *D = (FV4 *) _freq_data;
+ for (k = 0; k < _parsize; k += 4)
{
- for (k = 0; k <= _parsize; k++)
- {
- _freq_data [k][0] += ffta [k][0] * fftb [k][0] - ffta [k][1] * fftb [k][1];
- _freq_data [k][1] += ffta [k][0] * fftb [k][1] + ffta [k][1] * fftb [k][0];
- }
+ D [0] += A [0] * B [0] - A [1] * B [1];
+ D [1] += A [0] * B [1] + A [1] * B [0];
+ A += 2;
+ B += 2;
+ D += 2;
}
+ _freq_data [_parsize][0] += ffta [_parsize][0] * fftb [_parsize][0];
+ _freq_data [_parsize][1] = 0;
}
if (i == 0) i = _npar;
i--;
}
}
-#ifdef ENABLE_VECTOR_MODE
- if (_options & OPT_VECTOR_MODE) fftswap (_freq_data);
-#endif
- fftwf_execute_dft_c2r (_plan_c2r, _freq_data, _time_data);
+ fftswap (_freq_data);
+ _freq_data[0][1] = _freq_data[_parsize][0]; // adjust for packing convention
+ av_rdft_calc(_plan_c2r, (float*)_freq_data);
outd = Y->_buff [opi1];
- for (k = 0; k < _parsize; k++) outd [k] += _time_data [k];
+ for (k = 0; k < _parsize; k++) outd [k] += ((float*)_freq_data) [k];
outd = Y->_buff [opi2];
- memcpy (outd, _time_data + _parsize, _parsize * sizeof (float));
+ memcpy (outd, ((float*)_freq_data) + _parsize, _parsize * sizeof (float));
}
}
@@ -838,7 +812,7 @@
}
-int Convlevel::readout (bool sync, unsigned int skipcnt)
+int __rt_func Convlevel::readout (bool sync, unsigned int skipcnt)
{
unsigned int i;
float *p, *q;
@@ -900,7 +874,7 @@
_inp_list = X;
X->_inp = inp;
X->_ffta = new fftwf_complex * [_npar];
- memset (X->_ffta, 0, _npar * sizeof (fftw_complex *));
+ memset (X->_ffta, 0, _npar * sizeof (fftwf_complex *));
for (i = 0; i < _npar; i++)
{
X->_ffta [i] = (fftwf_complex *)(alloc_aligned ((_parsize + 1) * sizeof (fftwf_complex)));
@@ -942,9 +916,7 @@
}
-#ifdef ENABLE_VECTOR_MODE
-
-void Convlevel::fftswap (fftwf_complex *p)
+void __rt_func Convlevel::fftswap (fftwf_complex *p)
{
unsigned int n = _parsize;
float a, b;
@@ -961,7 +933,3 @@
n -= 4;
}
}
-
-#endif
-
-
diff -uN ./zita-convolver/zita-convolver.h ./zita-convolver-ffmpeg/zita-convolver.h
--- ./zita-convolver/zita-convolver.h 2012-12-06 11:09:33.645204107 +0100
+++ ./zita-convolver-ffmpeg/zita-convolver.h 2013-05-05 14:16:32.447644815 +0200
@@ -23,9 +23,11 @@
#include <pthread.h>
+extern "C" {
+#include <libavcodec/avfft.h>
+}
#include <fftw3.h>
-
#define ZITA_CONVOLVER_MAJOR_VERSION 3
@@ -236,8 +238,7 @@
void configure (int prio,
unsigned int offs,
unsigned int npar,
- unsigned int parsize,
- unsigned int options);
+ unsigned int parsize);
void impdata_create (unsigned int inp,
unsigned int out,
@@ -292,7 +293,6 @@
unsigned int _outoffs; // offset into output buffer
unsigned int _inpsize; // size of shared input buffer
unsigned int _inpoffs; // offset into input buffer
- unsigned int _options; // various options
unsigned int _ptind; // rotating partition index
unsigned int _opind; // rotating output buffer index
int _bits; // bit identifiying this level
@@ -302,10 +302,8 @@
ZCsema _done; // sema used to wait for a cycle
Inpnode *_inp_list; // linked list of active inputs
Outnode *_out_list; // linked list of active outputs
- fftwf_plan _plan_r2c; // FFTW plan, forward FFT
- fftwf_plan _plan_c2r; // FFTW plan, inverse FFT
- float *_time_data; // workspace
- float *_prep_data; // workspace
+ RDFTContext *_plan_r2c; // FFTW plan, forward FFT
+ RDFTContext *_plan_c2r; // FFTW plan, inverse FFT
fftwf_complex *_freq_data; // workspace
float **_inpbuff; // array of shared input buffers
float **_outbuff; // array of shared output buffers
@@ -371,7 +369,7 @@
void set_density (float density);
- void set_options (unsigned int options);
+ void set_options (unsigned int options) {}
void set_skipcnt (unsigned int skipcnt);
@@ -425,7 +423,6 @@
float *_outbuff [MAXOUT]; // output buffers
unsigned int _inpoffs; // current offset in input buffers
unsigned int _outoffs; // current offset in output buffers
- unsigned int _options; // option bits
unsigned int _skipcnt; // number of frames to skip
float _density; // matrix density hint
unsigned int _ninp; // number of inputs
_______________________________________________
Linux-audio-dev mailing list
[email protected]
http://lists.linuxaudio.org/listinfo/linux-audio-dev