1-
2- #include " FluidBuffers.hpp"
3- #include " Windows.hpp"
4-
51#include < cmath>
62
3+ #include " data/FluidBuffers.hpp"
4+ #include " algorithms/Windows.hpp"
5+
76using fluid::FluidTensor;
87using fluid::slice;
98using fluid::FluidSource;
@@ -12,40 +11,40 @@ int main(int argc, char* argv[])
1211{
1312// using fluid::FluidSource;
1413// using fluid::FluidSink;
15- //
14+ //
1615// FluidSource<double> source(100);
17- //
16+ //
1817// FluidTensor<double, 2> input(1,55);
1918// std::iota(input.begin(), input.end(),0);
20- // std::cout << input << '\n';
19+ // std::cout << input << '\n';
2120// source.push(input);
2221// source.push(input);
2322//
2423// source.reset();
25- //
26- //
24+ //
25+ //
2726// FluidTensor<double, 2> ramp_to_99(1,100);
2827// std::iota(ramp_to_99.begin(),ramp_to_99.end(),0);
29- // source.push(ramp_to_99);
30- //
28+ // source.push(ramp_to_99);
29+ //
3130// for(int i = 0 ; i < 10; ++i)
3231// {
3332// FluidTensor<double,2> output = source.pull(10);
3433// std::cout << output << '\n';
3534// }
36- //
37- //
38- //
35+ //
36+ //
37+ //
3938// source.reset();
4039// source.resize(1024);
41- //
40+ //
4241// FluidTensor<double, 2> cycle(1,64);
4342// std::iota(cycle.begin(), cycle.end(), 0);
4443// cycle.apply([](double&x){
4544// x = std::cos(2 * M_PI * x * (1/64));
4645// });
47- //
48- //
46+ //
47+ //
4948// //Simulate data coming in smaller packets than being pulled out (implies a latency...)
5049// //should see in the console that available grows, and then gets consumed
5150// for(int i = 0; i < 64; ++i)
@@ -58,14 +57,14 @@ int main(int argc, char* argv[])
5857// }
5958// std::cout << "After " << source.available() << '\n';
6059// }
61- //
60+ //
6261// /************************************************************************
6362// OLA end to end test
6463// - Write in data to source, extract with hop
6564// – window segment, ola into sink
6665// – pull out from sink and compare with original
6766// **************************************************************************/
68- //
67+ //
6968// size_t framesize = 1024;
7069// //read with overlap of four
7170// size_t hop = framesize >> 2;
@@ -74,7 +73,7 @@ int main(int argc, char* argv[])
7473//
7574// size_t signal_length = framesize * n_frames;
7675// size_t padded_length = signal_length + framesize;
77- //
76+ //
7877// //Make a tensor for the signal, with half a frame's zero padding each end
7978// FluidTensor<double, 2> sine(1,padded_length);
8079// //Grab the bit without zero padding
@@ -88,42 +87,41 @@ int main(int argc, char* argv[])
8887// FluidTensor<double,2> window(1,framesize);
8988// std::vector<double> win=fluid::windows::windowFuncs[fluid::windows::WindowType::Hann](framesize);
9089// std::copy(win.begin(), win.end(), window.begin());
91- //
90+ //
9291// //Buffer in
9392// FluidSource<double> sine_in(padded_length);
9493// //Buffer out
9594// FluidSink<double> sine_out(1,padded_length);
9695// //Normalisation buffer for window
9796// FluidSink<double> norm_out(1,padded_length);
98- //
97+ //
9998// //push signal in
10099// sine_in.push(sine);
101- //
100+ //
102101// //Pull out frames from source, window and push in to sink
103102// for(int i = 0; i<n_hops;++i)
104103// {
105104// FluidTensor<double,2> frame = sine_in.pull(framesize,hop)
106105// .apply(window,[](double& x, double w){x*=w;});
107- //
106+ //
108107// norm_out.push(window,hop);
109108// sine_out.push(frame,hop);
110109// }
111- //
110+ //
112111// //Grab the whole result from sink
113112// FluidTensor<double,2> result = sine_out.pull(padded_length);
114- //
113+ //
115114// //Apply OLA normalisation
116115// result.apply(norm_out.pull(padded_length),[](double& x, double y)
117116// {
118117// if(x)
119118// x /= y > 0? y : 1 ;
120119// });
121- //
120+ //
122121// //Subtract original from result
123122// result.apply(sine, [](double& x, double y){ x -= y; });
124- // //sum this difference
123+ // //sum this difference
125124// double sum_of_diff = std::accumulate(result.begin(), result.end(), 0.0);
126125// //we want it to be small, kthx
127126// std::cout << "Difference summed " << sum_of_diff << '\n';
128127}
129-
0 commit comments