Mercurial > hg > smallbox
comparison Problems/generateAudioDeclippingProblem.m @ 136:1334d2302dd9 ivand_dev
Added Audio declipping problem (problem, reconstruct and example function)
author | Ivan Damnjanovic lnx <ivan.damnjanovic@eecs.qmul.ac.uk> |
---|---|
date | Thu, 14 Jul 2011 16:26:07 +0100 |
parents | |
children | 9207d56c5547 |
comparison
equal
deleted
inserted
replaced
134:10343fb66448 | 136:1334d2302dd9 |
---|---|
1 function data = generateAudioDeclippingProblem(soundfile, clippingLevel, windowSize, overlap, wa, ws, wd, Dict_fun, redundancyFactor) | |
2 %% Generate Audio Declipping Problem | |
3 % | |
4 % CHANGE!!!generateAMT_Learning_Problem is a part of the SMALLbox and generates | |
5 % a problem that can be used for comparison of Dictionary Learning/Sparse | |
6 % Representation techniques in automatic music transcription scenario. | |
7 % The function prompts a user for an audio file (mid, wav, mat) reads it | |
8 % and generates a spectrogram given fft size (default nfft=4096), analysis | |
9 % window size (windowSize=2822), and analysis window overlap (overlap = | |
10 % 0.5). | |
11 % | |
12 % The output of the function is stucture with following fields: | |
13 % b - matrix with magnitudes of the spectrogram | |
14 % f - vector of frequencies at wihch spectrogram is computed | |
15 % windowSize - analysis window size | |
16 % overlap - analysis window overlap | |
17 % fs - sampling frequency | |
18 % m - number of frequenciy points in spectrogram | |
19 % n - number of time points in the spectrogram | |
20 % p - number of dictionary elements to be learned (eg 88 for piano) | |
21 % notesOriginal - notes of the original audio to be used for | |
22 % comparison (if midi of the original exists) | |
23 % name - name of the audio file to transcribe | |
24 | |
25 % Centre for Digital Music, Queen Mary, University of London. | |
26 % This file copyright 2011 Ivan Damnjanovic. | |
27 % | |
28 % This program is free software; you can redistribute it and/or | |
29 % modify it under the terms of the GNU General Public License as | |
30 % published by the Free Software Foundation; either version 2 of the | |
31 % License, or (at your option) any later version. See the file | |
32 % COPYING included with this distribution for more information. | |
33 % | |
34 %% | |
35 FS=filesep; | |
36 TMPpath=pwd; | |
37 | |
38 if ~ exist( 'soundfile', 'var' ) || isempty(soundfile) | |
39 %ask for file name | |
40 [pathstr1, name, ext, versn] = fileparts(which('SMALLboxSetup.m')); | |
41 cd([pathstr1,FS,'data',FS,'audio']); | |
42 [filename,pathname] = uigetfile({'*.mat; *.mid; *.wav'},'Select a file to transcribe'); | |
43 [pathstr, name, ext, versn] = fileparts(filename); | |
44 data.name=name; | |
45 | |
46 if strcmp(ext,'.mid') | |
47 midi=readmidi(filename); | |
48 % data.notesOriginal=midiInfo(midi); | |
49 y=midi2audio(midi); | |
50 wavwrite(y, 44100, 16, 'temp.wav'); | |
51 [x.signal, x.fs, x.nbits]=wavread('temp.wav'); | |
52 delete('temp.wav'); | |
53 elseif strcmp(ext,'.wav') | |
54 % cd([pathstr1,FS, 'data', FS, 'audio', FS, 'midi']); | |
55 % filename1=[name, '.mid']; | |
56 % if exist(filename1, 'file') | |
57 % midi=readmidi(filename1); | |
58 % data.notesOriginal=midiInfo(midi); | |
59 % end | |
60 cd([pathstr1,FS, 'data', FS, 'audio', FS, 'wav']); | |
61 [x.signal, x.fs, x.nbits]=wavread(filename); | |
62 else | |
63 % cd([pathstr1,FS, 'data', FS, 'audio', FS, 'midi']); | |
64 % filename1=[name, '.mid']; | |
65 % if exist(filename1, 'file') | |
66 % midi=readmidi(filename1); | |
67 % data.notesOriginal=midiInfo(midi); | |
68 % end | |
69 cd([pathstr1,FS, 'data', FS, 'audio', FS, 'mat']); | |
70 x=load([pathname,filename]); | |
71 end | |
72 else | |
73 [x.signal, x.fs, x.nbits]=wavread(soundfile); | |
74 [pathstr, name, ext, versn] = fileparts(soundfile); | |
75 data.name=name; | |
76 end | |
77 | |
78 if ~ exist( 'clippingLevel', 'var' ) || isempty(clippingLevel), clippingLevel = 0.6; end | |
79 if ~ exist( 'windowSize', 'var' ) || isempty(windowSize), windowSize = 256; end | |
80 if ~ exist( 'overlap', 'var' ) || isempty(overlap), overlap = 0.5; end | |
81 if ~ exist( 'wa', 'var' ) || isempty(wa), wa = @wRect; end % Analysis window | |
82 if ~ exist( 'ws', 'var' ) || isempty(ws), ws = @wSine; end % Synthesis window | |
83 if ~ exist( 'wd', 'var' ) || isempty(wd), wd = @wRect; end % Weighting window for dictionary atoms | |
84 | |
85 %% preparing signal | |
86 | |
87 [problemData, solutionData] = generateDeclippingProblem(x.signal,clippingLevel); | |
88 | |
89 x_clip = im2colstep(problemData.x,[windowSize 1],[overlap*windowSize 1]); | |
90 x_clip= diag(wa(windowSize)) * x_clip; | |
91 blkMask=im2colstep(double(~problemData.IMiss),[256 1],[128 1]); | |
92 | |
93 %% Building dictionary | |
94 if ~exist( 'redundancyFactor', 'var' ) || isempty(redundancyFactor), redundancyFactor = 2; end % Weighting window for dictionary atoms | |
95 if exist('Dict_fun', 'var')&&~isempty(Dict_fun) | |
96 param=struct('N', windowSize, 'redundancyFactor', redundancyFactor, 'wd', wd); | |
97 data.B = Dict_fun(param); | |
98 end | |
99 | |
100 data.b = x_clip; | |
101 data.M = blkMask; | |
102 data.original = solutionData.xClean; | |
103 data.clipped = problemData.x; | |
104 data.clipMask = problemData.IMiss; | |
105 data.clippingLevel = clippingLevel; | |
106 data.windowSize = windowSize; | |
107 data.overlap = overlap; | |
108 data.ws = ws; | |
109 data.wa = wa; | |
110 data.wd = wd; | |
111 | |
112 data.fs = x.fs; | |
113 data.nbits = x.nbits; | |
114 | |
115 [data.m, data.n] = size(x_clip); | |
116 data.p = windowSize*redundancyFactor; %number of dictionary elements | |
117 | |
118 cd(TMPpath); | |
119 | |
120 end |