idamnjanovic@10: function data = generateAMT_Learning_Problem(nfft, windowSize, overlap) ivan@128: %% Generate Automatic Music Transcription Problem idamnjanovic@21: % idamnjanovic@10: % generateAMT_Learning_Problem is a part of the SMALLbox and generates idamnjanovic@10: % a problem that can be used for comparison of Dictionary Learning/Sparse idamnjanovic@10: % Representation techniques in automatic music transcription scenario. idamnjanovic@10: % The function prompts a user for an audio file (mid, wav, mat) reads it idamnjanovic@10: % and generates a spectrogram given fft size (default nfft=4096), analysis idamnjanovic@10: % window size (windowSize=2822), and analysis window overlap (overlap = idamnjanovic@10: % 0.5). idamnjanovic@10: % idamnjanovic@10: % The output of the function is stucture with following fields: idamnjanovic@10: % b - matrix with magnitudes of the spectrogram idamnjanovic@10: % f - vector of frequencies at wihch spectrogram is computed idamnjanovic@10: % windowSize - analysis window size idamnjanovic@10: % overlap - analysis window overlap idamnjanovic@10: % fs - sampling frequency idamnjanovic@10: % m - number of frequenciy points in spectrogram idamnjanovic@10: % n - number of time points in the spectrogram idamnjanovic@10: % p - number of dictionary elements to be learned (eg 88 for piano) idamnjanovic@10: % notesOriginal - notes of the original audio to be used for idamnjanovic@10: % comparison (if midi of the original exists) idamnjanovic@10: % name - name of the audio file to transcribe ivan@128: ivan@128: % Centre for Digital Music, Queen Mary, University of London. ivan@128: % This file copyright 2009 Ivan Damnjanovic. ivan@128: % ivan@128: % This program is free software; you can redistribute it and/or ivan@128: % modify it under the terms of the GNU General Public License as ivan@128: % published by the Free Software Foundation; either version 2 of the ivan@128: % License, or (at your option) any later version. See the file ivan@128: % COPYING included with this distribution for more information. ivan@128: % idamnjanovic@10: %% idamnjanovic@10: FS=filesep; idamnjanovic@10: if ~ exist( 'nfft', 'var' ) || isempty(nfft), nfft = 4096; end idamnjanovic@10: if ~ exist( 'windowSize', 'var' ) || isempty(windowSize), windowSize = 2822; end idamnjanovic@10: if ~ exist( 'overlap', 'var' ) || isempty(overlap), overlap = 0.5; end idamnjanovic@10: idamnjanovic@10: %% idamnjanovic@10: %ask for file name idamnjanovic@10: TMPpath=pwd; idamnjanovic@10: [pathstr1, name, ext, versn] = fileparts(which('SMALLboxSetup.m')); idamnjanovic@10: cd([pathstr1,FS,'data',FS,'audio']); idamnjanovic@10: [filename,pathname] = uigetfile({'*.mat; *.mid; *.wav'},'Select a file to transcribe'); idamnjanovic@10: [pathstr, name, ext, versn] = fileparts(filename); idamnjanovic@10: data.name=name; idamnjanovic@10: idamnjanovic@10: data.notesOriginal=[]; idamnjanovic@10: idamnjanovic@10: if strcmp(ext,'.mid') idamnjanovic@10: midi=readmidi(filename); idamnjanovic@10: data.notesOriginal=midiInfo(midi); idamnjanovic@10: y=midi2audio(midi); idamnjanovic@10: wavwrite(y, 44100, 16, 'temp.wav'); idamnjanovic@10: [x.signal, x.fs, x.nbits]=wavread('temp.wav'); idamnjanovic@10: delete('temp.wav'); idamnjanovic@10: elseif strcmp(ext,'.wav') idamnjanovic@10: cd([pathstr1,FS, 'data', FS, 'audio', FS, 'midi']); idamnjanovic@10: filename1=[name, '.mid']; idamnjanovic@10: if exist(filename1, 'file') idamnjanovic@10: midi=readmidi(filename1); idamnjanovic@10: data.notesOriginal=midiInfo(midi); idamnjanovic@10: end idamnjanovic@10: cd([pathstr1,FS, 'data', FS, 'audio', FS, 'wav']); idamnjanovic@10: [x.signal, x.fs, x.nbits]=wavread(filename); idamnjanovic@10: else idamnjanovic@10: cd([pathstr1,FS, 'data', FS, 'audio', FS, 'midi']); idamnjanovic@10: filename1=[name, '.mid']; idamnjanovic@10: if exist(filename1, 'file') idamnjanovic@10: midi=readmidi(filename1); idamnjanovic@10: data.notesOriginal=midiInfo(midi); idamnjanovic@10: end idamnjanovic@10: cd([pathstr1,FS, 'data', FS, 'audio', FS, 'mat']); idamnjanovic@10: x=load([pathname,filename]); idamnjanovic@10: end idamnjanovic@10: %% idamnjanovic@10: [X, frX]=spectrogram(x.signal, hanning(windowSize), overlap*windowSize, nfft, x.fs); idamnjanovic@10: %% idamnjanovic@10: data.b=abs(X); idamnjanovic@10: data.f=frX; idamnjanovic@10: data.windowSize=windowSize; idamnjanovic@10: data.overlap=overlap; idamnjanovic@10: data.fs=x.fs; idamnjanovic@10: data.m=size(X,1); idamnjanovic@10: data.n=size(X,2); idamnjanovic@10: idamnjanovic@10: data.p=88; %number of dictionary elements (ie notes to recover) idamnjanovic@10: cd(TMPpath); idamnjanovic@10: idamnjanovic@10: end