Skip to content

Commit

Permalink
freesurround/el_processor.cpp: strict aliasing fixes
Browse files Browse the repository at this point in the history
also improve readability
  • Loading branch information
ulmus-scott authored and linuxdude42 committed Feb 21, 2022
1 parent ff37351 commit 1b00c58
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions mythtv/libs/libmythfreesurround/el_processor.cpp
Expand Up @@ -30,9 +30,7 @@ extern "C" {
#include "libavutil/mem.h"

#include "libavcodec/avfft.h"
//#include "libavcodec/fft.h"
}
using FFTComplexArray = FFTSample[2];
#endif


Expand Down Expand Up @@ -69,7 +67,7 @@ class decoder_impl {
// create lavc fft buffers
m_dftL = (FFTComplex*)av_malloc(sizeof(FFTComplex) * m_n * 2);
m_dftR = (FFTComplex*)av_malloc(sizeof(FFTComplex) * m_n * 2);
m_src = (FFTComplexArray*)av_malloc(sizeof(FFTComplex)*m_n*2);
m_src = (FFTComplex*)av_malloc(sizeof(FFTComplex) * m_n * 2);
// TODO only valid because blocksize is always 8192:
// (convert blocksize to log_2 (n) instead since FFmpeg only supports sizes that are powers of 2)
m_fftContextForward = av_fft_init(13, 0);
Expand Down Expand Up @@ -448,12 +446,12 @@ class decoder_impl {

// filter the complex source signal and add it to target
void apply_filter(cfloat *signal, const float *flt, float *target) {
#ifdef USE_FFTW3
// filter the signal
for (unsigned f=0;f<=m_halfN;f++) {
m_src[f][0] = signal[f].real() * flt[f];
m_src[f][1] = signal[f].imag() * flt[f];
}
#ifdef USE_FFTW3
// transform into time domain
fftwf_execute(m_store);

Expand All @@ -472,27 +470,28 @@ class decoder_impl {
*pT2++ = *pWnd2++ * *pDst2++;
}
#else
// filter the signal
for (unsigned f = 0; f <= m_halfN; f++)
{
m_src[f].re = signal[f].real() * flt[f];
m_src[f].im = signal[f].imag() * flt[f];
}
// enforce odd symmetry
for (unsigned f=1;f<m_halfN;f++) {
m_src[m_n-f][0] = m_src[f][0];
m_src[m_n-f][1] = -m_src[f][1]; // complex conjugate
for (unsigned f = 1; f < m_halfN; f++)
{
m_src[m_n - f].re = m_src[f].re;
m_src[m_n - f].im = -m_src[f].im; // complex conjugate
}
av_fft_permute(m_fftContextReverse, (FFTComplex*)&m_src[0]);
av_fft_calc(m_fftContextReverse, (FFTComplex*)&m_src[0]);
av_fft_permute(m_fftContextReverse, m_src);
av_fft_calc(m_fftContextReverse, m_src);

float* pT1 = &target[m_currentBuf*m_halfN];
float* pWnd1 = &m_wnd[0];
float* pDst1 = &m_src[0][0];
float* pT2 = &target[(m_currentBuf^1)*m_halfN];
float* pWnd2 = &m_wnd[m_halfN];
float* pDst2 = &m_src[m_halfN][0];
// add the result to target, windowed
for (unsigned int k=0;k<m_halfN;k++)
for (unsigned int k = 0; k < m_halfN; k++)
{
// 1st part is overlap add
*pT1++ += *pWnd1++ * *pDst1; pDst1 += 2;
target[m_currentBuf * m_halfN + k] += m_src[k].re * m_wnd[k];
// 2nd part is set as has no history
*pT2++ = *pWnd2++ * *pDst2; pDst2 += 2;
target[(m_currentBuf ^ 1) * m_halfN + k] = m_src[m_halfN + k].re * m_wnd[m_halfN + k];
}
#endif
}
Expand All @@ -510,7 +509,7 @@ class decoder_impl {
// intermediate arrays (FFTs of lt & rt, processing source)
FFTComplex *m_dftL {nullptr};
FFTComplex *m_dftR {nullptr};
FFTComplexArray *m_src {nullptr};
FFTComplex *m_src {nullptr};
#endif
// buffers
std::vector<cfloat> m_frontL,m_frontR,m_avg,m_surL,m_surR; // the signal (phase-corrected) in the frequency domain
Expand Down

0 comments on commit 1b00c58

Please sign in to comment.