Skip to content
Snippets Groups Projects
Select Git revision
  • 9f71f0eaec155609e84b2a659904c66ad94d9b50
  • master default protected
  • develop protected
  • feature/up-conv-test
  • jst
  • fabian
  • ITAConvolution_v2024a
  • VA_v2023b
  • VA_v2023a
  • VA_v2022a
  • before_cmake_rework
  • v2021.a
  • v2020.a
  • v2019.a
  • v2018.b
  • v2018.a
  • v2017.c
  • v2017.d
  • v2017.b
  • v2017.a
  • v2016.a
21 results

ITAUniformPartitionedConvolutionTest.cpp

  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    ITAUniformPartitionedConvolutionTest.cpp 4.22 KiB
    #include <algorithm>
    #include <stdio.h>
    #include <string.h>
    #include <string>
    
    #include <ITAException.h>
    #include <ITAAudiofileReader.h>
    #include <ITAAudiofileWriter.h>
    
    #include <ITAUPConvolution.h>
    #include <ITAUPFilter.h>
    #include <ITAUPFilterPool.h>
    #include <ITAFunctors.h>
    #include <ITANumericUtils.h>
    #include <ITAStringUtils.h>
    
    using namespace std;
    
    ITAAudiofileReader *pInputReader=NULL, *pFilterReader=NULL;
    ITAAudiofileWriter *pOutputWriter=NULL;
    vector<float*> vpfInputData;
    vector<float*> vpfOutputData;
    vector<float*> vpfFilterData;
    
    void test1() {
    	// Einfaches Durchfalten. Kein Austausch
    	const int m=16;
    	const int n=8;
    	const int b=4;
    	int o = uprmul(m+n-1, b);
    
    	float* s = new float[m];
    	float* h = new float[n];
    	float* g = new float[o];
    
    	memset(s, 0, m*sizeof(float));
    	memset(h, 0, n*sizeof(float));
    	memset(g, 0, o*sizeof(float));
    
    	for (int i=0; i<(m>>1); i++) s[i] = 1;
    	for (int i=0; i<(n>>1); i++) h[i] = 1;
    
    	ITAUPConvolution* conv = new ITAUPConvolution(b, n);
    
    	ITAUPFilter* filter1 = new ITAUPFilter(b, n);
    	filter1->load(h, n);
    
    	conv->exchangeFilter(filter1);
    
    	int j=0;
    	for (int i=0; i<uprdiv(o,b); i++) {
    	//for (int i=0; i<1; i++) {
    		conv->process(s+j, g+j);
    		j += b;
    	}
    
    	delete conv;
    	delete filter1;
    
    	delete[] s;
    	delete[] h;
    	delete[] g;
    }
    
    void test2() {
    	// Einfaches Durchfalten. Einblenden
    	const int m=16;
    	const int n=8;
    	const int b=4;
    	int o = uprmul(m+n-1, b);
    
    	float* s = new float[m];
    	float* h = new float[n];
    	float* g = new float[o];
    
    	memset(s, 0, m*sizeof(float));
    	memset(h, 0, n*sizeof(float));
    	memset(g, 0, o*sizeof(float));
    
    	for (int i=0; i<(m>>1); i++) s[i] = 1;
    	for (int i=0; i<(n>>1); i++) h[i] = 1;
    
    	ITAUPConvolution* conv = new ITAUPConvolution(b, n);
    	conv->setFilterExchangeMode(ITAUPConvolution::CROSSFADE_LINEAR);
    	conv->setFilterCrossfadeLength(3);
    
    	ITAUPFilter* filter1 = new ITAUPFilter(b, n);
    	//conv->destroyFilter(filter1);
    	filter1->load(h, n);
    
    	conv->exchangeFilter(filter1);
    
    	int j=0;
    	for (int i=0; i<uprdiv(o,b); i++) {
    	//for (int i=0; i<1; i++) {
    		conv->process(s, g);
    		j += b;
    	}
    
    	delete conv;
    	delete filter1;
    
    	delete[] s;
    	delete[] h;
    	delete[] g;
    }
    
    void test3() {
    	// Einfaches Durchfalten. Einblenden
    	const int m=16;
    	const int n=8;
    	const int b=4;
    	int o = uprmul(m+n-1, b);
    
    	float* s = new float[m];
    	float* h1 = new float[n];
    	float* h2 = new float[n];
    	float* g = new float[o];
    
    	memset(s, 0, m*sizeof(float));
    	memset(h1, 0, n*sizeof(float));
    	memset(h2, 0, n*sizeof(float));
    	memset(g, 0, o*sizeof(float));
    
    	for (int i=0; i<(m>>1); i++) s[i] = 1;
    	for (int i=0; i<(n>>1); i++) h1[i] = 1;
    	h2[n-1] = 1;
    
    	ITAUPConvolution* conv = new ITAUPConvolution(b, n);
    	conv->setFilterExchangeMode(ITAUPConvolution::CROSSFADE_LINEAR);
    	conv->setFilterCrossfadeLength(3);
    
    	ITAUPFilterPool* pool = new ITAUPFilterPool(b, n, 0);
    	ITAUPFilter* filter1 = pool->requestFilter();
    	ITAUPFilter* filter2 = pool->requestFilter();
    	//conv->destroyFilter(filter1);
    	filter1->load(h1, n);
    	filter2->load(h2, n);
    
    	conv->exchangeFilter(filter1);
    
    	int j=0;
    	for (int i=0; i<uprdiv(o,b); i++) {
    	//for (int i=0; i<1; i++) {
    		if (i == 1) conv->exchangeFilter(filter2);
    		//                               vvv f�r Bereichspr�fung auf s 
    		conv->process(s, g);
    		j += b;
    	}
    
    	//writeAudiofile("out.wav", g, o, 44100);
    	printf("s = (%s)\n", FloatArrayToString(s, m, 1).c_str());
    	printf("h1 = (%s)\n", FloatArrayToString(h1, n, 1).c_str());
    	printf("h2 = (%s)\n", FloatArrayToString(h2, n, 1).c_str());
    	printf("g = (%s)\n", FloatArrayToString(g, m+n-1, 1).c_str());
    
    
    	delete conv;
    	delete pool;
    
    	delete[] s;
    	delete[] h1;
    	delete[] h2;
    	delete[] g;
    }
    
    void test_filterpool() {
    	// Einfaches Durchfalten. Einblenden
    	const int b=8;
    	const int n=8;
    	float* s = new float[n];
    
    	ITAUPConvolution* conv = new ITAUPConvolution(b, n);
    	ITAUPFilterPool* pool = new ITAUPFilterPool(b, n, 0);
    
    	ITAUPFilter* f1 = pool->requestFilter();
    	conv->exchangeFilter(f1);
    	conv->process(s, s);
    	f1->release();
    
    	ITAUPFilter* f2 = pool->requestFilter();
    	conv->exchangeFilter(f2);
    	conv->process(s, s);
    
    	ITAUPFilter* f3 = pool->requestFilter();
    	conv->exchangeFilter(f2);
    	conv->process(s, s);
    
    	delete conv;
    	delete pool;
    
    	delete[] s;
    }
    
    int main(int argc, char* argv[]) {
    
    	test1();
    	//test2();
    	//test3();
    	//test_filterpool();
    	return 0;
    }