%function cout = filtersinesamples(c, window, separation, order, ftype, f, distortc)
%cout = filtersinesamples(c, window, separation, order, ftype, f, distortc)
%this was a script turned function
%takes in 2-d cell array of audio samples c
%window is a vector of window lengths
%separation is a vector of separations (0 < sep <= 1)
%order is a vector of orders (multiple of 2)
%ftype is a cell vector of ftypes (either 'b' or 'cR' R = ripple)
%f is a cell vector of frequency arrays
%distortc is a cell vector of cutoff vectors
%cout is a cell array of the processed audio vectors

s = 1.059463;

%this makes a bunch of samples between high A and Bb.
%a = 1;
%b = 1;

%f1 = 880;
%f2 = 880 * s^1;

%c = sinesamples(44100, f1, f2, 2.5, 2, 3);
%c = c(a, b);
%up to about 932

%recall that the distort function looks like this:
%y = distort(x, window, overlap, f, separation, order, c, fs, ftype)
%we will give vectors for every parameter that we can change and then
%process every sample in with every permutation of these parameters

%windows will all be triangle, but specify the sizes we are using:
%window = [ 256 380 512];
overlap = 2; %always
%separation = [.5 .8 1];
%order = [2 4 6];
fs = 44100;
%ftype = {'b', 'c1', 'c3'};

window = [186, 278, 370, 150, 234, 322]; %must be even so that overlap will divide into window
%separation = [.2 .4 .6 .8  1];
separation = [1 .7];
%order = [2 4 6];
order = [2 4];
%ftype = {'b', 'c1', 'c3'};
ftype = {'b'};
%f = {logspace(log10(860), log10(1000), 10), logspace(log10(860),
%log10(1000), 20), logspace(log10(860), log10(1000), 30),logspace(log10(860), log10(1000), 40), logspace(log10(860), log10(1000), 50) };\
f = {logspace(log10(860), log10(1000), 10), logspace(log10(860), log10(1000), 20)};
distortc = {[]};

%frequencies:
%f = {logspace(log10(860), log10(950), 10), logspace(log10(860), log10(950), 20), logspace(log10(860), log10(950), 30),logspace(log10(860), log10(950), 40) };

%c's:
%distortc = {[]};

[n(1) n(2)] = size(c);
n(3) = length(window);
n(4) = length(separation);
n(5) = length(order);
n(6) = length(ftype);
n(7) = length(f);
n(8) = length(distortc);

perms = prod(n); %total number of times we will run distort
current = 1;

cout = cell(n(1), n(2), n(3), n(4), n(5), n(6), n(7), n(8));

for i = 1:n(1)
    for j = 1:n(2)
        for k = 1:n(3)
            for l = 1:n(4)
                for m = 1:n(5)
                   for o = 1:n(6)
                       for p = 1:n(7)
                           for q = 1:n(8)
                               current
                               current = current + 1;
                               perms
   cout{i,j,k,l,m,o,p,q} = distort(c{i,j}, trianglewindow(window(k)), overlap, f{p}, separation(l),...
       order(m), distortc{q}, fs, ftype{o}, @cleansynth);
                           end
                       end
                   end
                end
            end
        end
    end
end