comparison Problems/generateAMTProblem.m @ 161:f42aa8bcb82f ivand_dev

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