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