comparison mirex2012-matlab/doMultiF0.m @ 2:8017dd4a650d

Add MIREX 2012 code
author Chris Cannam
date Wed, 19 Mar 2014 09:09:23 +0000
parents
children e92376d450b0
comparison
equal deleted inserted replaced
1:662b0a8b17b9 2:8017dd4a650d
1 function [] = doMultiF0(inputFile,outputFile)
2
3
4 % Transcribe file
5 fprintf('%s',['Preprocessing............']);
6 [ph pz sumY] = transcriptionMultipleTemplates(inputFile,12,1.1,1.3);
7 fprintf('\n');
8 fprintf('%s',['Postprocessing...........']);
9 pianoRoll = repmat(sumY,88,1).*pz(1:88,:);
10 pianoRoll = pianoRoll';
11 for j=[1:15 74:88] pianoRoll(:,j)=0; end;
12 pianoRoll = medfilt1(pianoRoll,3);
13
14
15 % Max polyphony 5
16 [B,IX] =sort(pianoRoll,2,'descend');
17 tempPianoRoll = zeros(size(pianoRoll,1),88);
18 for j=1:size(pianoRoll,1) for k=1:5 tempPianoRoll(j,IX(j,k)) = B(j,k); end; end;
19 pianoRoll = tempPianoRoll;
20
21
22 % Expand piano-roll and perform thresholding
23 expandedPianoRoll = zeros(4*size(pianoRoll,1),88);
24 for j=1:4*size(pianoRoll,1)
25 expandedPianoRoll(j,:) = pianoRoll(floor((j-1)/4)+1,:);
26 end;
27 finalPianoRoll = (expandedPianoRoll>4.8)';
28
29
30 % Create output and perform minimum duration pruning
31 auxPianoRoll = diff([zeros(1,88); finalPianoRoll'; zeros(1,88);],1); k=0;
32 for i=1:88
33 onsets = find(auxPianoRoll(:,i)==1);
34 offsets = find(auxPianoRoll(:,i)==-1);
35 for j=1:length(onsets)
36 if((offsets(j)/100-0.01) - (onsets(j)/100) > 0.05)
37 k=k+1;
38 nmat(k,1) = onsets(j)/100;
39 nmat(k,2) = offsets(j)/100-0.01;
40 nmat(k,3) = 27.5*2.^((( i-1)*10 )/120);
41 end;
42 end;
43 end;
44 nmat = sortrows(nmat,1);
45
46
47 % Print output
48 fid=fopen(outputFile,'w');
49 for i=1:size(nmat,1)
50 fprintf(fid,'%.2f\t%.2f\t%.2f\n',nmat(i,1),nmat(i,2),nmat(i,3));
51 end;
52 fclose(fid);
53 fprintf('%s','done');
54 fprintf('\n');
55
56
57 exit;