Mercurial > hg > smallbox
comparison Problems/generateAMT_Learning_Problem.m @ 10:207a6ae9a76f version1.0
(none)
author | idamnjanovic |
---|---|
date | Mon, 22 Mar 2010 15:06:25 +0000 |
parents | |
children | 0211faef9add |
comparison
equal
deleted
inserted
replaced
9:28f2b5fe3483 | 10:207a6ae9a76f |
---|---|
1 function data = generateAMT_Learning_Problem(nfft, windowSize, overlap) | |
2 %%% Generate Automatic Music Transcription Problem | |
3 % Ivan Damnjanovic 2010 | |
4 % | |
5 % | |
6 % generateAMT_Learning_Problem is a part of the SMALLbox and generates | |
7 % a problem that can be used for comparison of Dictionary Learning/Sparse | |
8 % Representation techniques in automatic music transcription scenario. | |
9 % The function prompts a user for an audio file (mid, wav, mat) reads it | |
10 % and generates a spectrogram given fft size (default nfft=4096), analysis | |
11 % window size (windowSize=2822), and analysis window overlap (overlap = | |
12 % 0.5). | |
13 % | |
14 % The output of the function is stucture with following fields: | |
15 % b - matrix with magnitudes of the spectrogram | |
16 % f - vector of frequencies at wihch spectrogram is computed | |
17 % windowSize - analysis window size | |
18 % overlap - analysis window overlap | |
19 % fs - sampling frequency | |
20 % m - number of frequenciy points in spectrogram | |
21 % n - number of time points in the spectrogram | |
22 % p - number of dictionary elements to be learned (eg 88 for piano) | |
23 % notesOriginal - notes of the original audio to be used for | |
24 % comparison (if midi of the original exists) | |
25 % name - name of the audio file to transcribe | |
26 | |
27 %% | |
28 FS=filesep; | |
29 if ~ exist( 'nfft', 'var' ) || isempty(nfft), nfft = 4096; end | |
30 if ~ exist( 'windowSize', 'var' ) || isempty(windowSize), windowSize = 2822; end | |
31 if ~ exist( 'overlap', 'var' ) || isempty(overlap), overlap = 0.5; end | |
32 | |
33 %% | |
34 %ask for file name | |
35 TMPpath=pwd; | |
36 [pathstr1, name, ext, versn] = fileparts(which('SMALLboxSetup.m')); | |
37 cd([pathstr1,FS,'data',FS,'audio']); | |
38 [filename,pathname] = uigetfile({'*.mat; *.mid; *.wav'},'Select a file to transcribe'); | |
39 [pathstr, name, ext, versn] = fileparts(filename); | |
40 data.name=name; | |
41 | |
42 data.notesOriginal=[]; | |
43 | |
44 if strcmp(ext,'.mid') | |
45 midi=readmidi(filename); | |
46 data.notesOriginal=midiInfo(midi); | |
47 y=midi2audio(midi); | |
48 wavwrite(y, 44100, 16, 'temp.wav'); | |
49 [x.signal, x.fs, x.nbits]=wavread('temp.wav'); | |
50 delete('temp.wav'); | |
51 elseif strcmp(ext,'.wav') | |
52 cd([pathstr1,FS, 'data', FS, 'audio', FS, 'midi']); | |
53 filename1=[name, '.mid']; | |
54 if exist(filename1, 'file') | |
55 midi=readmidi(filename1); | |
56 data.notesOriginal=midiInfo(midi); | |
57 end | |
58 cd([pathstr1,FS, 'data', FS, 'audio', FS, 'wav']); | |
59 [x.signal, x.fs, x.nbits]=wavread(filename); | |
60 else | |
61 cd([pathstr1,FS, 'data', FS, 'audio', FS, 'midi']); | |
62 filename1=[name, '.mid']; | |
63 if exist(filename1, 'file') | |
64 midi=readmidi(filename1); | |
65 data.notesOriginal=midiInfo(midi); | |
66 end | |
67 cd([pathstr1,FS, 'data', FS, 'audio', FS, 'mat']); | |
68 x=load([pathname,filename]); | |
69 end | |
70 %% | |
71 [X, frX]=spectrogram(x.signal, hanning(windowSize), overlap*windowSize, nfft, x.fs); | |
72 %% | |
73 data.b=abs(X); | |
74 data.f=frX; | |
75 data.windowSize=windowSize; | |
76 data.overlap=overlap; | |
77 data.fs=x.fs; | |
78 data.m=size(X,1); | |
79 data.n=size(X,2); | |
80 | |
81 data.p=88; %number of dictionary elements (ie notes to recover) | |
82 cd(TMPpath); | |
83 | |
84 end |