ivan@136
|
1 function data = generateAudioDeclippingProblem(soundfile, clippingLevel, windowSize, overlap, wa, ws, wd, Dict_fun, redundancyFactor)
|
ivan@136
|
2 %% Generate Audio Declipping Problem
|
ivan@136
|
3 %
|
ivan@140
|
4 % generateAudioDeclippingProblem is part of the SMALLbox [1] and generates
|
ivan@140
|
5 % Audio declipping is a problem proposed in Audio Inpaining Toolbox and
|
ivan@140
|
6 % in [2].
|
ivan@140
|
7 %
|
ivan@140
|
8 % [1] I. Damnjanovic, M. E. P. Davies, and M. P. Plumbley "SMALLbox - an
|
ivan@140
|
9 % evaluation framework for sparse representations and dictionary
|
ivan@140
|
10 % learning algorithms," V. Vigneron et al. (Eds.): LVA/ICA 2010,
|
ivan@140
|
11 % Springer-Verlag, Berlin, Germany, LNCS 6365, pp. 418-425
|
ivan@140
|
12 % [2] A. Adler, V. Emiya, M. G. Jafari, M. Elad, R. Gribonval, and M. D.
|
ivan@140
|
13 % Plumbley, “Audio Inpainting,” submitted to IEEE Trans. Audio, Speech,
|
ivan@140
|
14 % and Lang. Proc., 2011, http://hal.inria.fr/inria-00577079/en/.
|
ivan@140
|
15
|
ivan@136
|
16
|
ivan@136
|
17 % Centre for Digital Music, Queen Mary, University of London.
|
ivan@136
|
18 % This file copyright 2011 Ivan Damnjanovic.
|
ivan@136
|
19 %
|
ivan@136
|
20 % This program is free software; you can redistribute it and/or
|
ivan@136
|
21 % modify it under the terms of the GNU General Public License as
|
ivan@136
|
22 % published by the Free Software Foundation; either version 2 of the
|
ivan@136
|
23 % License, or (at your option) any later version. See the file
|
ivan@136
|
24 % COPYING included with this distribution for more information.
|
ivan@136
|
25 %
|
ivan@136
|
26 %%
|
ivan@136
|
27 FS=filesep;
|
ivan@136
|
28 TMPpath=pwd;
|
ivan@136
|
29
|
ivan@136
|
30 if ~ exist( 'soundfile', 'var' ) || isempty(soundfile)
|
ivan@136
|
31 %ask for file name
|
ivan@136
|
32 [pathstr1, name, ext, versn] = fileparts(which('SMALLboxSetup.m'));
|
ivan@136
|
33 cd([pathstr1,FS,'data',FS,'audio']);
|
ivan@136
|
34 [filename,pathname] = uigetfile({'*.mat; *.mid; *.wav'},'Select a file to transcribe');
|
ivan@136
|
35 [pathstr, name, ext, versn] = fileparts(filename);
|
ivan@136
|
36 data.name=name;
|
ivan@136
|
37
|
ivan@136
|
38 if strcmp(ext,'.mid')
|
ivan@136
|
39 midi=readmidi(filename);
|
ivan@136
|
40 % data.notesOriginal=midiInfo(midi);
|
ivan@136
|
41 y=midi2audio(midi);
|
ivan@136
|
42 wavwrite(y, 44100, 16, 'temp.wav');
|
ivan@136
|
43 [x.signal, x.fs, x.nbits]=wavread('temp.wav');
|
ivan@136
|
44 delete('temp.wav');
|
ivan@136
|
45 elseif strcmp(ext,'.wav')
|
ivan@136
|
46 % cd([pathstr1,FS, 'data', FS, 'audio', FS, 'midi']);
|
ivan@136
|
47 % filename1=[name, '.mid'];
|
ivan@136
|
48 % if exist(filename1, 'file')
|
ivan@136
|
49 % midi=readmidi(filename1);
|
ivan@136
|
50 % data.notesOriginal=midiInfo(midi);
|
ivan@136
|
51 % end
|
ivan@136
|
52 cd([pathstr1,FS, 'data', FS, 'audio', FS, 'wav']);
|
ivan@136
|
53 [x.signal, x.fs, x.nbits]=wavread(filename);
|
ivan@136
|
54 else
|
ivan@136
|
55 % cd([pathstr1,FS, 'data', FS, 'audio', FS, 'midi']);
|
ivan@136
|
56 % filename1=[name, '.mid'];
|
ivan@136
|
57 % if exist(filename1, 'file')
|
ivan@136
|
58 % midi=readmidi(filename1);
|
ivan@136
|
59 % data.notesOriginal=midiInfo(midi);
|
ivan@136
|
60 % end
|
ivan@136
|
61 cd([pathstr1,FS, 'data', FS, 'audio', FS, 'mat']);
|
ivan@136
|
62 x=load([pathname,filename]);
|
ivan@136
|
63 end
|
ivan@136
|
64 else
|
ivan@136
|
65 [x.signal, x.fs, x.nbits]=wavread(soundfile);
|
ivan@136
|
66 [pathstr, name, ext, versn] = fileparts(soundfile);
|
ivan@136
|
67 data.name=name;
|
ivan@136
|
68 end
|
ivan@136
|
69
|
ivan@136
|
70 if ~ exist( 'clippingLevel', 'var' ) || isempty(clippingLevel), clippingLevel = 0.6; end
|
ivan@136
|
71 if ~ exist( 'windowSize', 'var' ) || isempty(windowSize), windowSize = 256; end
|
ivan@136
|
72 if ~ exist( 'overlap', 'var' ) || isempty(overlap), overlap = 0.5; end
|
ivan@136
|
73 if ~ exist( 'wa', 'var' ) || isempty(wa), wa = @wRect; end % Analysis window
|
ivan@136
|
74 if ~ exist( 'ws', 'var' ) || isempty(ws), ws = @wSine; end % Synthesis window
|
ivan@136
|
75 if ~ exist( 'wd', 'var' ) || isempty(wd), wd = @wRect; end % Weighting window for dictionary atoms
|
ivan@136
|
76
|
ivan@136
|
77 %% preparing signal
|
ivan@136
|
78
|
ivan@136
|
79 [problemData, solutionData] = generateDeclippingProblem(x.signal,clippingLevel);
|
ivan@136
|
80
|
ivan@136
|
81 x_clip = im2colstep(problemData.x,[windowSize 1],[overlap*windowSize 1]);
|
ivan@136
|
82 x_clip= diag(wa(windowSize)) * x_clip;
|
ivan@137
|
83 blkMask=im2colstep(double(~problemData.IMiss),[windowSize 1],[overlap*windowSize 1]);
|
ivan@136
|
84
|
ivan@136
|
85 %% Building dictionary
|
ivan@136
|
86 if ~exist( 'redundancyFactor', 'var' ) || isempty(redundancyFactor), redundancyFactor = 2; end % Weighting window for dictionary atoms
|
ivan@136
|
87 if exist('Dict_fun', 'var')&&~isempty(Dict_fun)
|
ivan@136
|
88 param=struct('N', windowSize, 'redundancyFactor', redundancyFactor, 'wd', wd);
|
ivan@136
|
89 data.B = Dict_fun(param);
|
ivan@136
|
90 end
|
ivan@136
|
91
|
ivan@136
|
92 data.b = x_clip;
|
ivan@136
|
93 data.M = blkMask;
|
ivan@136
|
94 data.original = solutionData.xClean;
|
ivan@136
|
95 data.clipped = problemData.x;
|
ivan@136
|
96 data.clipMask = problemData.IMiss;
|
ivan@136
|
97 data.clippingLevel = clippingLevel;
|
ivan@136
|
98 data.windowSize = windowSize;
|
ivan@136
|
99 data.overlap = overlap;
|
ivan@136
|
100 data.ws = ws;
|
ivan@136
|
101 data.wa = wa;
|
ivan@136
|
102 data.wd = wd;
|
ivan@136
|
103
|
ivan@136
|
104 data.fs = x.fs;
|
ivan@136
|
105 data.nbits = x.nbits;
|
ivan@136
|
106
|
ivan@136
|
107 [data.m, data.n] = size(x_clip);
|
ivan@136
|
108 data.p = windowSize*redundancyFactor; %number of dictionary elements
|
ivan@136
|
109
|
ivan@136
|
110 cd(TMPpath);
|
ivan@136
|
111
|
ivan@136
|
112 end
|