forked from jorgehatccrma/AudioMorphing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestAutoMorph_jorgeh.m
129 lines (108 loc) · 3.47 KB
/
TestAutoMorph_jorgeh.m
1
addpath('../MorphExp/yin/');lambdaList=[0:0.25:1];if exist('morning') ~= 1 [mc, sr] = wavread('MorningCorner.wav'); morning = mc(1:16000); corner = mc(16001:length(mc)); clear mc; %sr=22050;endframeIncrement = 64;windowSize = 256;yin_params.minf0 = 100;yin_params.maxf0 = 300;yin_params.hop = frameIncrement;yin_params.bufsize = 512; % need to be more than sr/minf0yin_params.sr = sr;yin_params.wsize = 128; % jorgeh: not sure about this oneif exist('morningpitch') ~= 1 %cornerpitch=pitchsnake(corner,sr,sr/frameIncrement,100,300); yin_s1=yin(corner,yin_params); cornerpitch = 440*(2.^(yin_s1.f0)); cornerwidth = length(cornerpitch)-4; % the -4 is a hack for now %morningpitch=pitchsnake(morning,sr,sr/frameIncrement,100,300); yin_s2=yin(morning,yin_params); morningpitch = 440*(2.^(yin_s2.f0)); morningwidth = length(morningpitch)-4; % the -4 is a hack for nowendif exist('morningmfcc') ~= 1 morningmfcc = mfcc2(morning, sr, sr/frameIncrement); morningmfcc = morningmfcc(:,1:morningwidth); cornermfcc = mfcc2(corner, sr, sr/frameIncrement); cornermfcc = cornermfcc(:,1:cornerwidth);endif exist('morningspect') ~= 1 morningspect = ppspect(morning,windowSize); morningspect = morningspect(:,1:morningwidth); cornerspect = ppspect(corner,windowSize); cornerspect = cornerspect(:,1:cornerwidth);endif exist('path1') ~= 1 [error,path1,path2] = dtw(morningmfcc, cornermfcc);end% Now (optionally) plot the result. if 0 m = max(size(morningspect,2), size(cornerspect,2)); d1 = 257; subplot(3,1,1); imagesc(morningspect); axis([1 m 1 d1]); title('Signal 1'); s15 = zeros(size(morningspect)); for i=1:size(morningspect,2) s15(:,i) = cornerspect(:,path1(i)); end subplot(3,1,2); imagesc(s15); axis([1 m 1 d1]); title('Signal 2 warped to be like Signal 1'); subplot(3,1,3); imagesc(cornerspect); axis([1 m 1 d1]); title('Signal 2');end% OK, now we have the two spectrograms: morningspect and cornerspect% We have warping paths: path1 and path2% We have pitch values: morningpitch and cornerpitchspecLength = size(cornerspect,1);f=(1:specLength)'-1;f0 = flipud(morningspect);f1 = flipud(cornerspect);final=[];for lambda=lambdaList [index1,index2]=TimeWarpPaths(path1,path2,lambda); specLength = length(index1); image = zeros(size(cornerspect,1),specLength); alpha = cornerpitch(index2)./morningpitch(index1); for i=1:specLength i0=round(f/(1 + lambda*(alpha(i) - 1))) + 1; i0=max(1,min(specLength,i0)); %i1=alpha(i)*(i0-1) + 1; % this was the original, but it was %making the code crash i1=round(alpha(i)*f/(1 + lambda*(alpha(i) - 1))) + 1; % I got this % one from the old AudioMorph code (see ../MorphExp/AudioMorph, % around line 193) i1=max(1,min(specLength,i1)); image(:,i) = lambda*f1(i1,index2(i)) + (1-lambda)*f0(i0,index1(i)); end image=flipud(image); final=[final image];end%%% jorgeh: At this point, the spectrum's freq axis is fliped and the values % are "negated". This is just a quick hack to "fix" it and test the % inversion. Alsosig = 1-1./(1+exp(linspace(-6, 20, size(final,1))));final = flipud(255-final);% make the morphed sound? Doesn't really workaddpath('../Inversion');y = SpectrumInversion(SpectralTilt(final,-1),frameIncrement, ... windowSize, 100);%% plot resultssubplot(1,2,1);imagesc(flipud(final))colormap('jet');subplot(1,2,2);specInv = spectrogram(y, hann(windowSize), windowSize-frameIncrement);imagesc(flipud(abs(specInv)));colormap('jet');