From 8492850b3fb1d670941ca9a3fc96d1d9b541aa4e Mon Sep 17 00:00:00 2001 From: Memphiz Date: Sun, 10 May 2015 18:00:46 +0200 Subject: [fft] - added kissfft based rfft implementation and unit tests for it --- xbmc/utils/rfft.cpp | 75 ++++++++++++++++++++++++++++++++++++++++++++ xbmc/utils/rfft.h | 46 +++++++++++++++++++++++++++ xbmc/utils/test/Testrfft.cpp | 46 +++++++++++++++++++++++++++ 3 files changed, 167 insertions(+) create mode 100644 xbmc/utils/rfft.cpp create mode 100644 xbmc/utils/rfft.h create mode 100644 xbmc/utils/test/Testrfft.cpp diff --git a/xbmc/utils/rfft.cpp b/xbmc/utils/rfft.cpp new file mode 100644 index 0000000000..f2e6a255fc --- /dev/null +++ b/xbmc/utils/rfft.cpp @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2015 Team Kodi + * http://kodi.tv + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XBMC; see the file COPYING. If not, see + * . + * + */ + +#include "rfft.h" + +#if defined(TARGET_WINDOWS) && !defined(_USE_MATH_DEFINES) +#define _USE_MATH_DEFINES +#endif +#include + +RFFT::RFFT(int size, bool windowed) : + m_size(size), m_windowed(windowed) +{ + m_cfg = kiss_fftr_alloc(m_size,0,nullptr,nullptr); +} + +void RFFT::calc(const float* input, float* output) +{ + // temporary buffers + std::vector linput(m_size), rinput(m_size); + std::vector loutput(m_size), routput(m_size); + + for (size_t i=0;i + +void RFFT::hann(std::vector& data) +{ + for (size_t i=0;i. + * + */ + +#include "contrib/kissfft/kiss_fftr.h" +#include + +//! \brief Class performing a RFFT of interleaved stereo data. +class RFFT +{ +public: + //! \brief The constructor creates a RFFT plan. + //! \brief size Length of time data for a single channel. + //! \brief windowed Whether or not to apply a Hann window to data. + RFFT(int size, bool windowed=false); + + //! \brief Calculate FFTs + //! \param input Input data of size 2*m_size + //! \param output Output data of size m_size. + void calc(const float* input, float* output); +protected: + //! \brief Apply a Hann window to a buffer. + //! \param data Vector with data to apply window to. + static void hann(std::vector& data); + + size_t m_size; //!< Size for a single channel. + bool m_windowed; //!< Whether or not a Hann window is applied. + kiss_fftr_cfg m_cfg; //!< FFT plan +}; diff --git a/xbmc/utils/test/Testrfft.cpp b/xbmc/utils/test/Testrfft.cpp new file mode 100644 index 0000000000..3b382e6479 --- /dev/null +++ b/xbmc/utils/test/Testrfft.cpp @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2015 Team Kodi + * http://kodi.tv + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XBMC; see the file COPYING. If not, see + * . + * + */ + +#include "utils/rfft.h" + +#include "gtest/gtest.h" + +TEST(TestRFFT, SimpleSignal) +{ + const int size = 32; + const int freq1 = 5; + const int freq2[] = {1,7}; + std::vector input(2*size); + std::vector output(size); + for (size_t i=0;i