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