annotate Problems/generateAMT_Learning_Problem.m @ 18:bcc748594b61

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