annotate Problems/generateAMT_Learning_Problem.m @ 21:0211faef9add

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