comparison nonExposed/generateScene.m @ 19:8d33767e070a

fix channel export, norm, and crossfade length
author Gregoire Lafay <gregoire.lafay@irccyn.ec-nantes.fr>
date Wed, 13 Jan 2016 16:27:09 +0100
parents fc99c676c280
children 0163f857f13f
comparison
equal deleted inserted replaced
18:ce14979b84f8 19:8d33767e070a
52 if (i>1) 52 if (i>1)
53 scale = adjustScaleForEBR(waves, bg, 1, sceneSchedule(i).ebr, 1, 0.01); 53 scale = adjustScaleForEBR(waves, bg, 1, sceneSchedule(i).ebr, 1, 0.01);
54 end 54 end
55 if (length(waves) < trackLength) 55 if (length(waves) < trackLength)
56 % need to loop the sample to fill the bg. Linear crossfade 56 % need to loop the sample to fill the bg. Linear crossfade
57 loop = waves; 57 fadeLen = sr;
58 fadeLen = 20000;
59 fadeIn = transpose(0:1/fadeLen:1); 58 fadeIn = transpose(0:1/fadeLen:1);
60 fadeOut = transpose(1:-1/fadeLen:0); 59 fadeOut = transpose(1:-1/fadeLen:0);
60 loop = waves;
61 loop(1:fadeLen) = loop(1:fadeLen) .* fadeIn(1:fadeLen); 61 loop(1:fadeLen) = loop(1:fadeLen) .* fadeIn(1:fadeLen);
62 loop(length(loop)-fadeLen+1:length(loop)) = loop(length(loop)+1-fadeLen:length(loop)) .* fadeOut(1:fadeLen); 62 loop(length(loop)-fadeLen+1:length(loop)) = loop(length(loop)+1-fadeLen:length(loop)) .* fadeOut(1:fadeLen);
63 loop = scale * loop.'; 63 loop = scale * loop';
64 startLoop=waves;
65 startLoop(length(startLoop)-fadeLen+1:length(startLoop)) = startLoop(length(startLoop)+1-fadeLen:length(startLoop)) .* fadeOut(1:fadeLen);
66 startLoop = scale * startLoop';
64 for l=0:floor(trackLength/(length(loop)-fadeLen)) 67 for l=0:floor(trackLength/(length(loop)-fadeLen))
65 t1 = 1+l*(length(loop)-fadeLen); 68 t1 = 1+l*(length(loop)-fadeLen);
66 t2 = min(length(bg), t1+length(loop)-1); 69 t2 = min(length(bg), t1+length(loop)-1);
67 tracks(id,t1:t2) = tracks(id,t1:t2) + loop(1:t2-t1+1); 70 if l
71 tracks(id,t1:t2) = tracks(id,t1:t2) + loop(1:t2-t1+1);
72 else
73 tracks(id,t1:t2) = tracks(id,t1:t2) + startLoop(1:t2-t1+1);
74 end
68 end 75 end
69 else 76 else
70 dim = min(trackLength, length(waves)); 77 dim = min(trackLength, length(waves));
71 tracks(id,1:dim) = tracks(id,1:dim) + scale*(waves(1:dim).'); 78 tracks(id,1:dim) = tracks(id,1:dim) + scale*waves(1:dim)';
72 end 79 end
73 if (i==1) 80 if (i==1)
74 bg = tracks(id,:); 81 bg = tracks(id,:);
75 else 82 else
76 bg = bg+tracks(id,:); 83 bg = bg+tracks(id,:);
134 % checkClassPresence(sceneSchedule,sceneObjects); 141 % checkClassPresence(sceneSchedule,sceneObjects);
135 142
136 save ([outputPath 'annotation/' outputFileName '.mat'],'score', 'sceneObjects', 'sceneSchedule','dominantTrack', 'dominantObject','simulatedEBR'); 143 save ([outputPath 'annotation/' outputFileName '.mat'],'score', 'sceneObjects', 'sceneSchedule','dominantTrack', 'dominantObject','simulatedEBR');
137 saveAnnotationTxt(sceneSchedule,outputPath,outputFileName); 144 saveAnnotationTxt(sceneSchedule,outputPath,outputFileName);
138 145
146 w = sum(tracks,1);
147 if norm %Normalize to [-norm,norm]
148 w = w*norm/max(abs(w));
149 end
150
151 audiowrite([outputPath 'sound/' outputFileName '_channel_mix' '.wav'],w,sr);
152
139 switch channelOption 153 switch channelOption
140 case 0 154 case 1
141 w = sum(tracks,1);
142 if norm %Normalize to [-norm,norm] 155 if norm %Normalize to [-norm,norm]
143 w = w/(max(abs(w)))*norm; 156 tracks = tracks*norm/max(abs(sum(tracks,1)));
144 end 157 end
145 audiowrite([outputPath 'sound/' outputFileName '.wav'],w,sr); 158 audiowrite([outputPath 'sound/' outputFileName '_channel_split' '.wav'],tracks',sr);
146 case 1
147 if norm % each track will be normalized to [-norm,norm]
148 tracks = bsxfun(@times,tracks',norm./max(a,abs(tracks),2))';
149 end
150 audiowrite([outputPath 'sound/' outputFileName '.wav'],tracks',sr);
151 case 2 159 case 2
152 if norm % each track will be normalized to [-norm,norm] 160 if norm %Normalize to [-norm,norm]
153 tracks = bsxfun(@times,tracks',norm./max(a,abs(tracks),2))'; 161 tracks = tracks*norm/max(abs(sum(tracks,1)));
154 end 162 end
155 for jj=1:size(tracks,1) 163 for jj=1:size(tracks,1)
156 audiowrite([outputPath 'sound/' outputFileName '_channel_' num2str(jj) '.wav'],tracks(jj,:),sr); 164 audiowrite([outputPath 'sound/' outputFileName '_channel_' num2str(jj) '_class_' sceneObjects(jj).classLabel '.wav'],tracks(jj,:),sr);
157 end 165 end
158 end 166 end
159 167
160 168
161 if figuresOption 169 if figuresOption
162 settingFigure.cmap = generateColormap(sceneObjects); 170 settingFigure.cmap = generateColormap(sceneObjects);
163 settingFigure.width=29.7; % cm 171 settingFigure.width=29.7; % cm
164 settingFigure.height=21; % cm 172 settingFigure.height=21; % cm