Mercurial > hg > simscene-py
changeset 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 | ce14979b84f8 |
children | 3e78af49b119 |
files | demo.m nonExposed/generateScene.m simScene.m |
diffstat | 3 files changed, 28 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/demo.m Wed Jan 13 14:59:46 2016 +0100 +++ b/demo.m Wed Jan 13 16:27:09 2016 +0100 @@ -30,7 +30,7 @@ disp(sceneId); simScene(inputPath,outputPath,score,... - 'timeMode',timeMode,'ebrMode',ebrMode,'outputFileName',sceneId,'norm',.9); + 'timeMode',timeMode,'ebrMode',ebrMode,'outputFileName',sceneId,'channel',2); %% timeMode: 'replicate' -- ebrMode: 'replicate'
--- a/nonExposed/generateScene.m Wed Jan 13 14:59:46 2016 +0100 +++ b/nonExposed/generateScene.m Wed Jan 13 16:27:09 2016 +0100 @@ -54,21 +54,28 @@ end if (length(waves) < trackLength) % need to loop the sample to fill the bg. Linear crossfade - loop = waves; - fadeLen = 20000; + fadeLen = sr; fadeIn = transpose(0:1/fadeLen:1); fadeOut = transpose(1:-1/fadeLen:0); + loop = waves; loop(1:fadeLen) = loop(1:fadeLen) .* fadeIn(1:fadeLen); loop(length(loop)-fadeLen+1:length(loop)) = loop(length(loop)+1-fadeLen:length(loop)) .* fadeOut(1:fadeLen); - loop = scale * loop.'; + loop = scale * loop'; + startLoop=waves; + startLoop(length(startLoop)-fadeLen+1:length(startLoop)) = startLoop(length(startLoop)+1-fadeLen:length(startLoop)) .* fadeOut(1:fadeLen); + startLoop = scale * startLoop'; for l=0:floor(trackLength/(length(loop)-fadeLen)) t1 = 1+l*(length(loop)-fadeLen); t2 = min(length(bg), t1+length(loop)-1); - tracks(id,t1:t2) = tracks(id,t1:t2) + loop(1:t2-t1+1); + if l + tracks(id,t1:t2) = tracks(id,t1:t2) + loop(1:t2-t1+1); + else + tracks(id,t1:t2) = tracks(id,t1:t2) + startLoop(1:t2-t1+1); + end end else dim = min(trackLength, length(waves)); - tracks(id,1:dim) = tracks(id,1:dim) + scale*(waves(1:dim).'); + tracks(id,1:dim) = tracks(id,1:dim) + scale*waves(1:dim)'; end if (i==1) bg = tracks(id,:); @@ -136,27 +143,28 @@ save ([outputPath 'annotation/' outputFileName '.mat'],'score', 'sceneObjects', 'sceneSchedule','dominantTrack', 'dominantObject','simulatedEBR'); saveAnnotationTxt(sceneSchedule,outputPath,outputFileName); +w = sum(tracks,1); +if norm %Normalize to [-norm,norm] + w = w*norm/max(abs(w)); +end + +audiowrite([outputPath 'sound/' outputFileName '_channel_mix' '.wav'],w,sr); + switch channelOption - case 0 - w = sum(tracks,1); + case 1 if norm %Normalize to [-norm,norm] - w = w/(max(abs(w)))*norm; + tracks = tracks*norm/max(abs(sum(tracks,1))); end - audiowrite([outputPath 'sound/' outputFileName '.wav'],w,sr); - case 1 - if norm % each track will be normalized to [-norm,norm] - tracks = bsxfun(@times,tracks',norm./max(a,abs(tracks),2))'; - end - audiowrite([outputPath 'sound/' outputFileName '.wav'],tracks',sr); + audiowrite([outputPath 'sound/' outputFileName '_channel_split' '.wav'],tracks',sr); case 2 - if norm % each track will be normalized to [-norm,norm] - tracks = bsxfun(@times,tracks',norm./max(a,abs(tracks),2))'; + if norm %Normalize to [-norm,norm] + tracks = tracks*norm/max(abs(sum(tracks,1))); end for jj=1:size(tracks,1) - audiowrite([outputPath 'sound/' outputFileName '_channel_' num2str(jj) '.wav'],tracks(jj,:),sr); + audiowrite([outputPath 'sound/' outputFileName '_channel_' num2str(jj) '_class_' sceneObjects(jj).classLabel '.wav'],tracks(jj,:),sr); end end - + if figuresOption settingFigure.cmap = generateColormap(sceneObjects);
--- a/simScene.m Wed Jan 13 14:59:46 2016 +0100 +++ b/simScene.m Wed Jan 13 16:27:09 2016 +0100 @@ -161,7 +161,7 @@ addpath(genpath('nonExposed')); -[timeMode,ebrMode,instanceAnnotFile,instanceAudioFile,figuresOption,sampleChoice,outputFileName,minSpace,endCut,eventInfoPath,norm,channelsOption]=process_options(varargin,'timeMode','generate','ebrMode','generate','instanceAnnotFile','none','instanceAudioFile','none','figure',0,'sampleChoice','random','outputFileName','simulatedScene','minSpace',-1,'endCut',0,'eventInfoPath','','norm',0,'channel',0); +[timeMode,ebrMode,instanceAnnotFile,instanceAudioFile,figuresOption,sampleChoice,outputFileName,minSpace,endCut,eventInfoPath,norm,channelsOption]=process_options(varargin,'timeMode','generate','ebrMode','generate','instanceAnnotFile','none','instanceAudioFile','none','figure',0,'sampleChoice','random','outputFileName','simulatedScene','minSpace',-1,'endCut',0,'eventInfoPath','','norm',.75,'channel',0); sr=44100;