idamnjanovic@10
|
1 function data = generateAMT_Learning_Problem(nfft, windowSize, overlap)
|
ivan@128
|
2 %% Generate Automatic Music Transcription Problem
|
idamnjanovic@21
|
3 %
|
idamnjanovic@10
|
4 % generateAMT_Learning_Problem is a part of the SMALLbox and generates
|
idamnjanovic@10
|
5 % a problem that can be used for comparison of Dictionary Learning/Sparse
|
idamnjanovic@10
|
6 % Representation techniques in automatic music transcription scenario.
|
idamnjanovic@10
|
7 % The function prompts a user for an audio file (mid, wav, mat) reads it
|
idamnjanovic@10
|
8 % and generates a spectrogram given fft size (default nfft=4096), analysis
|
idamnjanovic@10
|
9 % window size (windowSize=2822), and analysis window overlap (overlap =
|
idamnjanovic@10
|
10 % 0.5).
|
idamnjanovic@10
|
11 %
|
idamnjanovic@10
|
12 % The output of the function is stucture with following fields:
|
idamnjanovic@10
|
13 % b - matrix with magnitudes of the spectrogram
|
idamnjanovic@10
|
14 % f - vector of frequencies at wihch spectrogram is computed
|
idamnjanovic@10
|
15 % windowSize - analysis window size
|
idamnjanovic@10
|
16 % overlap - analysis window overlap
|
idamnjanovic@10
|
17 % fs - sampling frequency
|
idamnjanovic@10
|
18 % m - number of frequenciy points in spectrogram
|
idamnjanovic@10
|
19 % n - number of time points in the spectrogram
|
idamnjanovic@10
|
20 % p - number of dictionary elements to be learned (eg 88 for piano)
|
idamnjanovic@10
|
21 % notesOriginal - notes of the original audio to be used for
|
idamnjanovic@10
|
22 % comparison (if midi of the original exists)
|
idamnjanovic@10
|
23 % name - name of the audio file to transcribe
|
ivan@128
|
24
|
ivan@128
|
25 % Centre for Digital Music, Queen Mary, University of London.
|
ivan@128
|
26 % This file copyright 2009 Ivan Damnjanovic.
|
ivan@128
|
27 %
|
ivan@128
|
28 % This program is free software; you can redistribute it and/or
|
ivan@128
|
29 % modify it under the terms of the GNU General Public License as
|
ivan@128
|
30 % published by the Free Software Foundation; either version 2 of the
|
ivan@128
|
31 % License, or (at your option) any later version. See the file
|
ivan@128
|
32 % COPYING included with this distribution for more information.
|
ivan@128
|
33 %
|
idamnjanovic@10
|
34 %%
|
idamnjanovic@10
|
35 FS=filesep;
|
idamnjanovic@10
|
36 if ~ exist( 'nfft', 'var' ) || isempty(nfft), nfft = 4096; end
|
idamnjanovic@10
|
37 if ~ exist( 'windowSize', 'var' ) || isempty(windowSize), windowSize = 2822; end
|
idamnjanovic@10
|
38 if ~ exist( 'overlap', 'var' ) || isempty(overlap), overlap = 0.5; end
|
idamnjanovic@10
|
39
|
idamnjanovic@10
|
40 %%
|
idamnjanovic@10
|
41 %ask for file name
|
idamnjanovic@10
|
42 TMPpath=pwd;
|
idamnjanovic@10
|
43 [pathstr1, name, ext, versn] = fileparts(which('SMALLboxSetup.m'));
|
idamnjanovic@10
|
44 cd([pathstr1,FS,'data',FS,'audio']);
|
idamnjanovic@10
|
45 [filename,pathname] = uigetfile({'*.mat; *.mid; *.wav'},'Select a file to transcribe');
|
idamnjanovic@10
|
46 [pathstr, name, ext, versn] = fileparts(filename);
|
idamnjanovic@10
|
47 data.name=name;
|
idamnjanovic@10
|
48
|
idamnjanovic@10
|
49 data.notesOriginal=[];
|
idamnjanovic@10
|
50
|
idamnjanovic@10
|
51 if strcmp(ext,'.mid')
|
idamnjanovic@10
|
52 midi=readmidi(filename);
|
idamnjanovic@10
|
53 data.notesOriginal=midiInfo(midi);
|
idamnjanovic@10
|
54 y=midi2audio(midi);
|
idamnjanovic@10
|
55 wavwrite(y, 44100, 16, 'temp.wav');
|
idamnjanovic@10
|
56 [x.signal, x.fs, x.nbits]=wavread('temp.wav');
|
idamnjanovic@10
|
57 delete('temp.wav');
|
idamnjanovic@10
|
58 elseif strcmp(ext,'.wav')
|
idamnjanovic@10
|
59 cd([pathstr1,FS, 'data', FS, 'audio', FS, 'midi']);
|
idamnjanovic@10
|
60 filename1=[name, '.mid'];
|
idamnjanovic@10
|
61 if exist(filename1, 'file')
|
idamnjanovic@10
|
62 midi=readmidi(filename1);
|
idamnjanovic@10
|
63 data.notesOriginal=midiInfo(midi);
|
idamnjanovic@10
|
64 end
|
idamnjanovic@10
|
65 cd([pathstr1,FS, 'data', FS, 'audio', FS, 'wav']);
|
idamnjanovic@10
|
66 [x.signal, x.fs, x.nbits]=wavread(filename);
|
idamnjanovic@10
|
67 else
|
idamnjanovic@10
|
68 cd([pathstr1,FS, 'data', FS, 'audio', FS, 'midi']);
|
idamnjanovic@10
|
69 filename1=[name, '.mid'];
|
idamnjanovic@10
|
70 if exist(filename1, 'file')
|
idamnjanovic@10
|
71 midi=readmidi(filename1);
|
idamnjanovic@10
|
72 data.notesOriginal=midiInfo(midi);
|
idamnjanovic@10
|
73 end
|
idamnjanovic@10
|
74 cd([pathstr1,FS, 'data', FS, 'audio', FS, 'mat']);
|
idamnjanovic@10
|
75 x=load([pathname,filename]);
|
idamnjanovic@10
|
76 end
|
idamnjanovic@10
|
77 %%
|
idamnjanovic@10
|
78 [X, frX]=spectrogram(x.signal, hanning(windowSize), overlap*windowSize, nfft, x.fs);
|
idamnjanovic@10
|
79 %%
|
idamnjanovic@10
|
80 data.b=abs(X);
|
idamnjanovic@10
|
81 data.f=frX;
|
idamnjanovic@10
|
82 data.windowSize=windowSize;
|
idamnjanovic@10
|
83 data.overlap=overlap;
|
idamnjanovic@10
|
84 data.fs=x.fs;
|
idamnjanovic@10
|
85 data.m=size(X,1);
|
idamnjanovic@10
|
86 data.n=size(X,2);
|
idamnjanovic@10
|
87
|
idamnjanovic@10
|
88 data.p=88; %number of dictionary elements (ie notes to recover)
|
idamnjanovic@10
|
89 cd(TMPpath);
|
idamnjanovic@10
|
90
|
idamnjanovic@10
|
91 end
|