ivan@136: function data = generateAudioDeclippingProblem(soundfile, clippingLevel, windowSize, overlap, wa, ws, wd, Dict_fun, redundancyFactor) ivan@136: %% Generate Audio Declipping Problem ivan@136: % ivan@140: % generateAudioDeclippingProblem is part of the SMALLbox [1] and generates ivan@140: % Audio declipping is a problem proposed in Audio Inpaining Toolbox and ivan@140: % in [2]. ivan@140: % ivan@161: % The function takes as an optional input ivan@161: % soundfile - name of the file ivan@161: % clippingLevel - (default 0.6) ivan@161: % windowSize - 1D frame size (eg 512) ivan@161: % overlap - ammount of overlaping frames between 0 and 1 ivan@161: % wa,ws,wd - analisys, synthesis and dictionary window functions ivan@161: % ivan@161: % Dict_fun - function to be used to generate dictionary ivan@161: % redundancyFactor - overcompletness of dictionary (default 2) ivan@161: % ivan@161: % The function outputs the structure with following fields: ivan@161: % original - original signal ivan@161: % clipped - clipped signal ivan@161: % clipMask - mask indicating clipped samples ivan@161: % clippingLevel - (default 0.6) ivan@161: % Upper_Limit - maximum value of original data ivan@161: % fs - sample rate of the original signal in Hertz ivan@161: % nbits - the number of bits per sample ivan@161: % sigma - added noise level ivan@161: % B - dictionary to be used for sparse representation ivan@161: % M - measurement matrix (non-clipped data in b) ivan@161: % b - matrix of clipped frames ivan@161: % m - size od dictionary atom ivan@161: % n - number of frames to be represented ivan@161: % p - number of atoms in dictionary ivan@161: % windowSize - 1D frame size (eg 512) ivan@161: % overlap - ammount of overlaping frames between 0 and 1 ivan@161: % wa,ws, wd - analisys, synthesis and dictionary window functions ivan@161: % ivan@140: % [1] I. Damnjanovic, M. E. P. Davies, and M. P. Plumbley "SMALLbox - an ivan@140: % evaluation framework for sparse representations and dictionary ivan@140: % learning algorithms," V. Vigneron et al. (Eds.): LVA/ICA 2010, ivan@140: % Springer-Verlag, Berlin, Germany, LNCS 6365, pp. 418-425 ivan@140: % [2] A. Adler, V. Emiya, M. G. Jafari, M. Elad, R. Gribonval, and M. D. ivan@140: % Plumbley, “Audio Inpainting,” submitted to IEEE Trans. Audio, Speech, ivan@140: % and Lang. Proc., 2011, http://hal.inria.fr/inria-00577079/en/. ivan@140: ivan@136: ivan@136: % Centre for Digital Music, Queen Mary, University of London. ivan@136: % This file copyright 2011 Ivan Damnjanovic. ivan@136: % ivan@136: % This program is free software; you can redistribute it and/or ivan@136: % modify it under the terms of the GNU General Public License as ivan@136: % published by the Free Software Foundation; either version 2 of the ivan@136: % License, or (at your option) any later version. See the file ivan@136: % COPYING included with this distribution for more information. ivan@136: % ivan@136: %% ivan@136: FS=filesep; ivan@136: TMPpath=pwd; ivan@136: ivan@136: if ~ exist( 'soundfile', 'var' ) || isempty(soundfile) ivan@136: %ask for file name luis@186: [pathstr1, name, ext] = fileparts(which('SMALLboxSetup.m')); ivan@136: cd([pathstr1,FS,'data',FS,'audio']); ivan@136: [filename,pathname] = uigetfile({'*.mat; *.mid; *.wav'},'Select a file to transcribe'); luis@186: [pathstr, name, ext] = fileparts(filename); ivan@136: data.name=name; ivan@136: ivan@136: if strcmp(ext,'.mid') ivan@136: midi=readmidi(filename); ivan@136: % data.notesOriginal=midiInfo(midi); ivan@136: y=midi2audio(midi); ivan@136: wavwrite(y, 44100, 16, 'temp.wav'); ivan@136: [x.signal, x.fs, x.nbits]=wavread('temp.wav'); ivan@136: delete('temp.wav'); ivan@136: elseif strcmp(ext,'.wav') ivan@136: % cd([pathstr1,FS, 'data', FS, 'audio', FS, 'midi']); ivan@136: % filename1=[name, '.mid']; ivan@136: % if exist(filename1, 'file') ivan@136: % midi=readmidi(filename1); ivan@136: % data.notesOriginal=midiInfo(midi); ivan@136: % end ivan@136: cd([pathstr1,FS, 'data', FS, 'audio', FS, 'wav']); ivan@136: [x.signal, x.fs, x.nbits]=wavread(filename); ivan@136: else ivan@136: % cd([pathstr1,FS, 'data', FS, 'audio', FS, 'midi']); ivan@136: % filename1=[name, '.mid']; ivan@136: % if exist(filename1, 'file') ivan@136: % midi=readmidi(filename1); ivan@136: % data.notesOriginal=midiInfo(midi); ivan@136: % end ivan@136: cd([pathstr1,FS, 'data', FS, 'audio', FS, 'mat']); ivan@136: x=load([pathname,filename]); ivan@136: end ivan@136: else ivan@136: [x.signal, x.fs, x.nbits]=wavread(soundfile); luis@186: [pathstr, name, ext] = fileparts(soundfile); ivan@136: data.name=name; ivan@136: end ivan@136: ivan@136: if ~ exist( 'clippingLevel', 'var' ) || isempty(clippingLevel), clippingLevel = 0.6; end ivan@136: if ~ exist( 'windowSize', 'var' ) || isempty(windowSize), windowSize = 256; end ivan@136: if ~ exist( 'overlap', 'var' ) || isempty(overlap), overlap = 0.5; end ivan@136: if ~ exist( 'wa', 'var' ) || isempty(wa), wa = @wRect; end % Analysis window ivan@136: if ~ exist( 'ws', 'var' ) || isempty(ws), ws = @wSine; end % Synthesis window ivan@136: if ~ exist( 'wd', 'var' ) || isempty(wd), wd = @wRect; end % Weighting window for dictionary atoms ivan@136: ivan@136: %% preparing signal ivan@136: ivan@136: [problemData, solutionData] = generateDeclippingProblem(x.signal,clippingLevel); ivan@136: ivan@136: x_clip = im2colstep(problemData.x,[windowSize 1],[overlap*windowSize 1]); ivan@136: x_clip= diag(wa(windowSize)) * x_clip; ivan@137: blkMask=im2colstep(double(~problemData.IMiss),[windowSize 1],[overlap*windowSize 1]); ivan@136: ivan@136: %% Building dictionary ivan@136: if ~exist( 'redundancyFactor', 'var' ) || isempty(redundancyFactor), redundancyFactor = 2; end % Weighting window for dictionary atoms ivan@136: if exist('Dict_fun', 'var')&&~isempty(Dict_fun) ivan@136: param=struct('N', windowSize, 'redundancyFactor', redundancyFactor, 'wd', wd); ivan@136: data.B = Dict_fun(param); ivan@136: end ivan@136: ivan@136: data.b = x_clip; ivan@136: data.M = blkMask; ivan@136: data.original = solutionData.xClean; ivan@136: data.clipped = problemData.x; ivan@136: data.clipMask = problemData.IMiss; ivan@136: data.clippingLevel = clippingLevel; ivan@136: data.windowSize = windowSize; ivan@136: data.overlap = overlap; ivan@136: data.ws = ws; ivan@136: data.wa = wa; ivan@136: data.wd = wd; ivan@136: ivan@136: data.fs = x.fs; ivan@136: data.nbits = x.nbits; ivan@161: data.Upper_Limit = max(solutionData.xClean); ivan@136: [data.m, data.n] = size(x_clip); ivan@136: data.p = windowSize*redundancyFactor; %number of dictionary elements ivan@136: ivan@136: cd(TMPpath); ivan@136: ivan@136: end