Skip to content
This repository has been archived by the owner on Jan 22, 2021. It is now read-only.

Commit

Permalink
Merge branch 'release/ATK-2.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrucher committed Apr 11, 2017
2 parents d665a49 + 43c81b1 commit 2a20976
Show file tree
Hide file tree
Showing 287 changed files with 6,265 additions and 2,488 deletions.
28 changes: 14 additions & 14 deletions .appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
os: Visual Studio 2015
version: '1.5.{build}'
version: '2.0.{build}'

shallow_clone: true

environment:
ATK_ROOT: c:\projects\AudioTK
ATK_OUT: c:\projects\ATK
EIGEN_ROOT: c:\projects\Eigen
ATK_ROOT: C:\projects\AudioTK
ATK_OUT: C:\projects\ATK
EIGEN_ROOT: C:\projects\Eigen
BOOST_ROOT: C:\Libraries\boost_1_63_0
FFTW_ROOT: c:\projects\fftw
FFTW_ROOT: C:\projects\fftw
matrix:
# 32 bits
- FFTW_NAME: fftw-3.3.5-dll32.zip
Expand All @@ -17,8 +17,8 @@ environment:
SHORT_MSVC_PLATFORM: x86
COMPILER: Visual Studio 14 2015
OUTPUT: static-x86
ADDITONAL_CMAKE_FLAGS: "-DMSVC_RUNTIME=Static -DENABLE_SHARED_LIBRARIES=OFF -DENABLE_TESTS=Off"
PLATFORM: MSVC-14
ADDITONAL_CMAKE_FLAGS: "-DMSVC_RUNTIME=Static -DENABLE_SHARED_LIBRARIES=OFF -DENABLE_TESTS=OFF"
MSVC_VERSION: msvc-14

# 64 bits
- FFTW_NAME: fftw-3.3.5-dll64.zip
Expand All @@ -27,8 +27,8 @@ environment:
SHORT_MSVC_PLATFORM: x64
COMPILER: Visual Studio 14 2015 Win64
OUTPUT: static-x64
ADDITONAL_CMAKE_FLAGS: "-DMSVC_RUNTIME=Static -DENABLE_SHARED_LIBRARIES=OFF -DENABLE_TESTS=Off"
PLATFORM: MSVC-14
ADDITONAL_CMAKE_FLAGS: "-DMSVC_RUNTIME=Static -DENABLE_SHARED_LIBRARIES=OFF -DENABLE_TESTS=OFF"
MSVC_VERSION: msvc-14

# 32 bits
- FFTW_NAME: fftw-3.3.5-dll32.zip
Expand All @@ -38,7 +38,7 @@ environment:
COMPILER: Visual Studio 14 2015
OUTPUT: dynamic-x86
ADDITONAL_CMAKE_FLAGS:
PLATFORM: MSVC-14
MSVC_VERSION: msvc-14

# 64 bits
- FFTW_NAME: fftw-3.3.5-dll64.zip
Expand All @@ -48,7 +48,7 @@ environment:
COMPILER: Visual Studio 14 2015 Win64
OUTPUT: dynamic-x64
ADDITONAL_CMAKE_FLAGS:
PLATFORM: MSVC-14
MSVC_VERSION: msvc-14

init:
- cmake --version
Expand All @@ -68,14 +68,14 @@ before_build:
- cd %ATK_ROOT%
- mkdir build
- cd build
- cmake -G "%COMPILER%" %ADDITONAL_CMAKE_FLAGS% -DBOOST_ROOT=%BOOST_ROOT% -DCMAKE_INSTALL_PREFIX=%ATK_OUT% -DFFTW_INCLUDES=%FFTW_ROOT% -DFFTW_LIBRARY_FFTW3=%FFTW_ROOT%\libfftw3-3.lib -DFFTW_LIBRARY_FFTW3F=%FFTW_ROOT%\libfftw3f-3.lib -DEIGEN_INCLUDE_DIRS=%EIGEN_ROOT% -DENABLE_STATIC_LIBRARIES=ON ..
- cmake -G "%COMPILER%" %ADDITONAL_CMAKE_FLAGS% -DBOOST_ROOT=%BOOST_ROOT% -DCMAKE_INSTALL_PREFIX=%ATK_OUT% -DFFTW_INCLUDES=%FFTW_ROOT% -DFFTW_LIBRARY_FFTW3=%FFTW_ROOT%\libfftw3-3.lib -DFFTW_LIBRARY_FFTW3F=%FFTW_ROOT%\libfftw3f-3.lib -DEIGEN_ROOT=%EIGEN_ROOT% -DENABLE_STATIC_LIBRARIES=ON ..

build_script:
- msbuild INSTALL.vcxproj /property:Configuration=Release

after_build:
- cd %ATK_OUT%
- 7z a %ATK_ROOT%\AudioTK.%PLATFORM%.%OUTPUT%.zip * -tzip
- 7z a %ATK_ROOT%\AudioTK.%MSVC_VERSION%.%OUTPUT%.zip * -tzip

test_script:
- set PATH=%ATK_OUT%\bin;%BOOST_ROOT%\lib%BITS%-msvc-14.0;%FFTW_ROOT%;%PATH%
Expand All @@ -84,7 +84,7 @@ test_script:
- msbuild RUN_TESTS.vcxproj /property:Configuration=Release

artifacts:
- path: AudioTK.%PLATFORM%.%OUTPUT%.zip
- path: AudioTK.%MSVC_VERSION%.%OUTPUT%.zip
name: package

deploy:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ Examples/*.txt
*.txt
*.bundle
Doxygen/
*.dat
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,25 +74,28 @@ matrix:
- ADDITONAL_CMAKE_FLAGS=
- os: osx
osx_image: xcode8.2
python: "3.4"
env:
- COMPILER=clang++
- PLATFORM=xcode-8.2
- ADDITONAL_CMAKE_FLAGS=-DCMAKE_OSX_ARCHITECTURES="i386;x86_64"
- os: osx
osx_image: xcode7.3
python: "3.4"
env:
- COMPILER=clang++
- PLATFORM=xcode-7.3
- ADDITONAL_CMAKE_FLAGS=-DCMAKE_OSX_ARCHITECTURES="i386;x86_64"

before_install:
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update ; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install eigen fftw libsndfile ; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install eigen fftw libsndfile ; fi
- wget --no-verbose --output-document=boost_1_63_0.tar.bz2 http://sourceforge.net/projects/boost/files/boost/1.63.0/boost_1_63_0.tar.bz2/download
- export BOOST_ROOT="$TRAVIS_BUILD_DIR/../boost"
- export BOOST_BUILD="$TRAVIS_BUILD_DIR/../boost-build"
- mkdir -p $BOOST_ROOT
- tar jxf boost_1_63_0.tar.bz2 --strip-components=1 -C $BOOST_ROOT
- pip install numpy

install:
- "(cd $BOOST_ROOT; ./bootstrap.sh --with-libraries=system,test)"
Expand Down
235 changes: 235 additions & 0 deletions ATK/Adaptive/BlockLMSFilter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
/**
* \file BlockLMSFilter.cpp
*/

#include "BlockLMSFilter.h"

#include <complex>
#include <cstdint>
#include <stdexcept>

#include <Eigen/Core>

#include <ATK/Core/TypeTraits.h>
#include <ATK/Utility/FFT.h>

namespace ATK
{
template<typename DataType_>
class BlockLMSFilter<DataType_>::BlockLMSFilterImpl
{
public:
typedef Eigen::Matrix<std::complex<double>, Eigen::Dynamic, 1> cwType;
typedef Eigen::Map<const cwType> cxType;
typedef Eigen::Matrix<DataType_, Eigen::Dynamic, 1> wType;
typedef Eigen::Map<const wType> xType;

/// FFT of the current coefficients
cwType wfft;
/// Current accumulated input
std::vector<DataType_> block_input;
/// Current accumulated ref
std::vector<DataType_> block_ref;
/// Current accumulated error
std::vector<DataType_> block_error;

/// Temporary storage
std::vector<std::complex<double> > block_fft;
/// Temporary storage
std::vector<std::complex<double> > block_fft2;
/// Temporary storage
std::vector<DataType_> block_ifft;

FFT<double> fft;
/// Memory factor
double alpha;
/// line search
double mu;
/// block size
std::size_t block_size;
std::size_t accumulate_block_size;
bool learning;

BlockLMSFilterImpl(std::size_t size)
:wfft(cwType::Zero(2*size)), block_input(2 * size, DataType_(0)), block_ref(size, DataType_(0)), block_error(size, DataType_(0)),
block_fft(2 * size), block_fft2(2 * size), block_ifft(2 * size), alpha(.99), mu(0.05), block_size(size), accumulate_block_size(0), learning(true)
{
fft.set_size(2 * size);
}

void apply_update()
{
++accumulate_block_size;
if (accumulate_block_size == block_size)
{
fft.process_forward(block_input.data(), block_fft2.data(), block_size * 2);
for(std::size_t i = 0; i < 2 * block_size; ++i)
{
block_fft[i] = block_fft2[i] * wfft(i, 0) * std::complex<double>(block_size * 2); // Diagonal U * FFT factor
}
fft.process_backward(block_fft.data(), block_ifft.data(), block_size * 2);
for (std::size_t i = 0; i < block_size; ++i)
{
block_ifft[block_size + i] = block_ref[i] - block_ifft[block_size + i]; // error on last elements of Y
block_error[i] = block_ifft[block_size + i];
}
if (learning)
{
std::fill(block_ifft.begin(), block_ifft.begin() + block_size, 0);
fft.process_forward(block_ifft.data(), block_fft.data(), block_size * 2); // FFT of the error stored in ifft
for (std::size_t i = 0; i < 2 * block_size; ++i)
{
block_fft[i] = std::conj(block_fft2[i]) * block_fft[i] * std::complex<double>(block_size * 2); // diagonal * FFT factor
}
fft.process_backward(block_fft.data(), block_ifft.data(), 2 * block_size);
fft.process_forward(block_ifft.data(), block_fft.data(), block_size);
wfft = alpha * wfft + static_cast<std::complex<double>>(mu) * cxType(block_fft.data(), 2 * block_size);
}

accumulate_block_size = 0;
std::memcpy(&block_input[0], &block_input[block_size], block_size * sizeof(DataType_));
}
}

void update(DataType input, DataType ref, DataType& error)
{
block_input[block_size + accumulate_block_size] = input;
error = block_ref[accumulate_block_size] - block_error[accumulate_block_size];
block_ref[accumulate_block_size] = ref;

apply_update();
}
};

template<typename DataType_>
BlockLMSFilter<DataType_>::BlockLMSFilter(std::size_t size)
:Parent(2, 1), impl(new BlockLMSFilterImpl(size))
{
if (size == 0)
{
throw std::out_of_range("Size must be strictly positive");
}
// former input delay for the non fast version is input_delay = size - 1;
}

template<typename DataType_>
BlockLMSFilter<DataType_>::~BlockLMSFilter()
{
}

template<typename DataType_>
void BlockLMSFilter<DataType_>::set_size(std::size_t size)
{
if(size == 0)
{
throw std::out_of_range("Size must be strictly positive");
}
auto block_size = impl->block_size;
impl.reset(new BlockLMSFilterImpl(size));
set_block_size(block_size);
}

template<typename DataType_>
std::size_t BlockLMSFilter<DataType_>::get_size() const
{
return input_delay - 1;
}

template<typename DataType_>
void BlockLMSFilter<DataType_>::set_block_size(std::size_t size)
{
if (size == 0)
{
throw std::out_of_range("Block size must be strictly positive");
}
impl->accumulate_block_size = 0;
impl->block_size = size;
impl->block_input.assign(2 * size, 0);
impl->block_ref.assign(size, 0);
impl->block_fft.assign(2 * size, 0);
impl->block_fft2.assign(2 * size, 0);
impl->block_ifft.assign(2 * size, 0);
}

template<typename DataType_>
std::size_t BlockLMSFilter<DataType_>::get_block_size() const
{
return impl->block_size;
}

template<typename DataType_>
void BlockLMSFilter<DataType_>::set_memory(double memory)
{
if (memory >= 1)
{
throw std::out_of_range("Memory must be less than 1");
}
if (memory <= 0)
{
throw std::out_of_range("Memory must be strictly positive");
}

impl->alpha = memory;
}

template<typename DataType_>
double BlockLMSFilter<DataType_>::get_memory() const
{
return impl->alpha;
}

template<typename DataType_>
void BlockLMSFilter<DataType_>::set_mu(double mu)
{
if (mu >= 1)
{
throw std::out_of_range("Mu must be less than 1");
}
if (mu <= 0)
{
throw std::out_of_range("Mu must be strictly positive");
}

impl->mu = mu;
}

template<typename DataType_>
double BlockLMSFilter<DataType_>::get_mu() const
{
return impl->mu;
}

template<typename DataType_>
void BlockLMSFilter<DataType_>::process_impl(std::size_t size) const
{
const DataType* ATK_RESTRICT input = converted_inputs[0];
const DataType* ATK_RESTRICT ref = converted_inputs[1];
DataType* ATK_RESTRICT output = outputs[0];

for(std::size_t i = 0; i < size; ++i)
{
impl.get()->update(input[i], ref[i], output[i]);
}
}

template<typename DataType_>
const DataType_* BlockLMSFilter<DataType_>::get_w() const
{
return nullptr;
}

template<typename DataType_>
void BlockLMSFilter<DataType_>::set_learning(bool learning)
{
impl->learning = learning;
}

template<typename DataType_>
bool BlockLMSFilter<DataType_>::get_learning() const
{
return impl->learning;
}

template class BlockLMSFilter<double>;
template class BlockLMSFilter<std::complex<double>>;
}
Loading

0 comments on commit 2a20976

Please sign in to comment.