%real test!

FFTSiz = 8192;  %********** this or 8192 should work
FFThalf = FFTSiz/2;


% make this 1-Channel for sanity.
[orig, Fs, nbits]= getsound(FFTSiz);  % for use in anger
%fakedata;   % for debugging
% at this point orig is a COLUMN vector 



origarr = Newbreakup(orig,FFTSiz);
% this puts orig out as ROWs of origarr!
origrows = size(origarr,1);
resultarr=zeros(size(origarr));
bigfftarr=zeros(size(origarr));
finalwav = orig;  % this is a column vector


%ps = fftarr .* conj(fftarr); later we can displayall this
%plot(ps);
 

 
factor1 = 2^(4/12);  %major third
factor2 = 2^(7/12);  %perfect fifth
factor3 = 2^(10/12);  %dominant seventh

%result1 = zeros(fftsiz,1);  % try result2 for now

for k = 1:origrows  % Get fft of orig, one row @ time
    bigfftarr(k,:) = fft(origarr(k,:),FFTSiz);
end

for factor = [factor1 ]

for k = 1:origrows  % Get fft of orig, one row @ time
     fftarr = bigfftarr(k,:);
         for i = 2:FFThalf+1  % remap half and flip it
%    result1(i) = remapf(i/factor,fftarr);  % gotta divide
    result2(i) = remapf2(i,factor,fftarr);
%    result1(fftsiz-i+2) =  conj(result1(i));    %poor mans conj
    result2(FFTSiz-i+2) = conj(result2(i));    %poor mans conj
    end


% now try to normalize amplitudes back
ps2 = sum(sum(result2 .* conj(result2)));  %weight
ps2 = sqrt(ps2);

fftsum = sum(sum(fftarr(2:FFTSiz) .* conj(fftarr(2:FFTSiz))))
fftsum = sqrt(fftsum);

result2 = result2 *(fftsum/ps2);
result2(1) = fftarr(1);  % and use old peak value
%ps1 = sum(sum(result1 .* conj(result1)))  % weight
%ps1 = sqrt(ps1);
%result1 = result1 *(fftsum/ps1);
%ps1 = result1 .* conj(result1);

%ps2 = result2 .* conj(result2); this is really the new ps.

%figure
%plot(fftshift(ps), '-b')
%hold on
%plot(fftshift(ps1), '-r')
%figure
%plot(fftshift(ps), '-b')
%hold on
%plot(fftshift(ps2), '-g')

%recover1 = ifft(result1);

recover2 = real(ifft(result2,FFTSiz)); % ROW vector
resultarr (k,:) = recover2;
end % end of dealing with rows of the orig array
wavout = Newreassemble(resultarr);
% wavout is a COL vector
fprintf('\nFactor %d. Hit any key to listen:',factor);
    pause
    wavplay(wavout,Fs);
putsound(wavout);  %hear it twice?
finalwav = finalwav + wavout;
end % end of factors
finalwav = normwav(finalwav, 1.0);
putsound(finalwav);
%hold off
%figure
%plot(real(recover1), 'b');
%figure
%plot(real(recover2), 'r');


