Skip to content

Commit

Permalink
Fix several bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
hagenw committed Oct 11, 2018
1 parent 4057fbf commit 37143cc
Show file tree
Hide file tree
Showing 126 changed files with 4,284 additions and 875 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ function process( obj, wavFilepath )
%% -------------------------------------------------------------------------------

% override of Core.IdProcInterface's method
function fileProcessed = hasFileAlreadyBeenProcessed( ~, ~ )
function [fileProcessed,cacheDir] = hasFileAlreadyBeenProcessed( ~, ~ )
fileProcessed = false;
cacheDir = [];
end
%% -------------------------------------------------------------------------------

Expand Down Expand Up @@ -130,11 +131,12 @@ function delete( obj )
%% -------------------------------------------------------------------------------
function processInternal( obj, varargin )
obj.inputProc.sceneId = obj.sceneId;
in = obj.loadInputData( obj.curWavFilepath, 'afeData', 'annotations' );
if nargin < 2 || any( strcmpi( 'afeBlocks', varargin ) )
in = obj.loadInputData( obj.curWavFilepath, 'afeData', 'annotations' );
[obj.blockAnnotations,obj.afeBlocks] = ...
obj.blockify( in.afeData, in.annotations );
else
in = obj.loadInputData( obj.curWavFilepath, 'annotations' );
obj.blockAnnotations = obj.blockify( in.afeData, in.annotations );
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
classdef FullFileBlockCreator < BlockCreators.Base
%
%% -----------------------------------------------------------------------------------
properties (SetAccess = private)
end

%% -----------------------------------------------------------------------------------
methods

function obj = FullFileBlockCreator()
obj = obj@BlockCreators.Base( inf, 0 );
end
%% -------------------------------------------------------------------------------

end

%% -----------------------------------------------------------------------------------
methods (Access = protected)

function outputDeps = getBlockCreatorInternOutputDependencies( obj )
outputDeps.v = 1;
end
%% -------------------------------------------------------------------------------

function [blockAnnots,afeBlocks] = blockify( obj, afeData, annotations )
currentDependencies = obj.getOutputDependencies();
sceneConfig = currentDependencies.preceding.preceding.sceneCfg;
annotations = BlockCreators.StandardBlockCreator.extendAnnotations( ...
sceneConfig, annotations );
anyAFEsignal = afeData(1);
if isa( anyAFEsignal, 'cell' ), anyAFEsignal = anyAFEsignal{1}; end;
streamLen_s = double( size( anyAFEsignal.Data, 1 ) ) / anyAFEsignal.FsHz;
if nargout > 1
afeBlocks = {afeData};
end
blockAnnots = annotations;
blockAnnots.blockOnset = 0;
blockAnnots.blockOffset = streamLen_s;
end
%% -------------------------------------------------------------------------------

end
%% -----------------------------------------------------------------------------------

methods (Static)

%% -------------------------------------------------------------------------------
%% -------------------------------------------------------------------------------

end

end



Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
function outputDeps = getBlockCreatorInternOutputDependencies( obj )
outputDeps.sbc = getBlockCreatorInternOutputDependencies@...
BlockCreators.StandardBlockCreator( obj );
outputDeps.v = 1;
outputDeps.v = 3;
end
%% -------------------------------------------------------------------------------

Expand All @@ -32,6 +32,10 @@
blockAnnots = blockify@BlockCreators.StandardBlockCreator( ...
obj, afeData, annotations );
end
[blockAnnots(:).nrj] = deal(struct('t',[],'nrj',[]));
[blockAnnots(:).nrjOthers] = deal(struct('t',[],'nrjOthers',[]));
[blockAnnots(:).srcSNRactive] = deal(struct('t',[],'srcSNRactive',[]));
[blockAnnots(:).srcSNR2] = deal(struct('t',[],'srcSNR2',[]));
aFields = fieldnames( blockAnnots );
isSequenceAnnotation = cellfun( @(af)(...
isstruct( blockAnnots(1).(af) ) && ...
Expand All @@ -40,30 +44,74 @@
), aFields );
sequenceAfields = aFields(isSequenceAnnotation);
for ii = 1 : numel( blockAnnots )
blockAnnots(ii) = ...
BlockCreators.MeanStandardBlockCreator.adjustPreMeanAnnotations( ...
blockAnnots(ii) );
for jj = 1 : numel( sequenceAfields )
seqAname = sequenceAfields{jj};
annot = blockAnnots(ii).(seqAname);
if length( annot.t ) == size( annot.(seqAname), 1 )
if iscell( annot.(seqAname) )
annotSeq = annot.(seqAname);
if length( annot.t ) == size( annotSeq, 1 )
if iscell( annotSeq )
as_szs = cellfun( @(c)( size( c, 2 ) ), annotSeq(1,:) );
blockAnnots(ii).(seqAname) = ...
cellSqueezeFun( @mean, annot.(seqAname), 1, true );
mat2cell( nanmean( cell2mat( annotSeq ), 1 ), 1, as_szs );
else
blockAnnots(ii).(seqAname) = mean( annot.(seqAname), 1 );
blockAnnots(ii).(seqAname) = nanmean( annotSeq, 1 );
end
else
error( 'unexpected annotations sequence structure' );
end
end
blockAnnots(ii) = ...
BlockCreators.MeanStandardBlockCreator.extendMeanAnnotations( ...
blockAnnots(ii) );
end
end
%% -------------------------------------------------------------------------------
%% -------------------------------------------------------------------------------

end
%% -----------------------------------------------------------------------------------

methods (Static)

%% -------------------------------------------------------------------------------

% TODO: this is the wrong place for the annotation computation; it
% should be done in SceneEarSignalProc -- and is now here, for the
% moment, to avoid recomputation with SceneEarSignalProc.

function avgdBlockAnnots = extendMeanAnnotations( avgdBlockAnnots )
srcsGlobalRefEnergyMeanChannel = cellfun( ...
@(c)(sum(c) ./ 2 ), avgdBlockAnnots.globalSrcEnergy );
srcsGlobalRefEnergyMeanChannel_db = 10 * log10( srcsGlobalRefEnergyMeanChannel );
haveSrcsEnergy = srcsGlobalRefEnergyMeanChannel_db > -40;
isAmbientSource = isnan( avgdBlockAnnots.srcAzms );
haveSrcsEnergy(isAmbientSource) = [];
avgdBlockAnnots.nActivePointSrcs = single( sum( haveSrcsEnergy ) );
avgdBlockAnnots.srcSNR2 = 10 * log10( avgdBlockAnnots.nrj ./ avgdBlockAnnots.nrjOthers );
avgdBlockAnnots.nrj = 10 * log10( avgdBlockAnnots.nrj );
avgdBlockAnnots.nrjOthers = 10 * log10( avgdBlockAnnots.nrjOthers );
avgdBlockAnnots.globalSrcEnergy = cellfun( @(c)(10 * log10( c )), ...
avgdBlockAnnots.globalSrcEnergy, 'UniformOutput', false );
end
%% -------------------------------------------------------------------------------

% TODO: this is the wrong place for the annotation computation; it
% should be done in SceneEarSignalProc -- and is now here, for the
% moment, to avoid recomputation with SceneEarSignalProc.

function annotations = adjustPreMeanAnnotations( annotations )
annotations.srcSNRactive.t = annotations.globalSrcEnergy.t;
annotations.srcSNRactive.srcSNRactive = annotations.srcSNR_db.srcSNR_db;
allSrcsInactive = annotations.nActivePointSrcs.nActivePointSrcs == 0;
annotations.srcSNRactive.srcSNRactive(allSrcsInactive,:) = nan;
annotations.srcSNRactive.srcSNRactive = annotations.srcSNRactive.srcSNRactive;
annotations.nrj.t = annotations.globalSrcEnergy.t;
annotations.nrj.nrj = 10.^(annotations.nrj_db.nrj_db./10);
annotations.nrjOthers.t = annotations.globalSrcEnergy.t;
annotations.nrjOthers.nrjOthers = 10.^(annotations.nrjOthers_db.nrjOthers_db./10);
end
%% -------------------------------------------------------------------------------

end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@
methods (Access = protected)

function outputDeps = getBlockCreatorInternOutputDependencies( obj )
outputDeps.v = 2;
outputDeps.v = 4;
end
%% -------------------------------------------------------------------------------

function [blockAnnots,afeBlocks] = blockify( obj, afeData, annotations )
currentDependencies = obj.getOutputDependencies();
sceneConfig = currentDependencies.preceding.preceding.sceneCfg;
annotations = BlockCreators.StandardBlockCreator.extendAnnotations( ...
sceneConfig, annotations );
anyAFEsignal = afeData(1);
if isa( anyAFEsignal, 'cell' ), anyAFEsignal = anyAFEsignal{1}; end;
streamLen_s = double( size( anyAFEsignal.Data, 1 ) ) / anyAFEsignal.FsHz;
Expand Down Expand Up @@ -80,13 +84,60 @@
blockAnnots = flipud( blockAnnots );
end
%% -------------------------------------------------------------------------------

end
%% -----------------------------------------------------------------------------------

methods (Static)

%% -------------------------------------------------------------------------------

% TODO: this is the wrong place for the annotation computation; it
% should be done in SceneEarSignalProc -- and is now here, for the
% moment, to avoid recomputation with SceneEarSignalProc.

function annotations = extendAnnotations( sceneConfig, annotations )
annotations.srcSNR_db.t = annotations.globalSrcEnergy.t;
annotations.srcSNR_db.srcSNR_db = zeros( size( annotations.globalSrcEnergy.globalSrcEnergy ) );
annotations.nrj_db.t = annotations.globalSrcEnergy.t;
annotations.nrj_db.nrj_db = zeros( size( annotations.globalSrcEnergy.globalSrcEnergy ) );
annotations.nrjOthers_db.t = annotations.globalSrcEnergy.t;
annotations.nrjOthers_db.nrjOthers_db = zeros( size( annotations.globalSrcEnergy.globalSrcEnergy ) );
annotations.nActivePointSrcs.t = annotations.globalSrcEnergy.t;
annotations.nActivePointSrcs.nActivePointSrcs = zeros( size( annotations.globalSrcEnergy.globalSrcEnergy ) );
if std( sceneConfig.snrRefs ) ~= 0
error( 'AMLTTP:usage:snrRefMustBeSame', 'different snrRefs not supported' );
end
snrRef = sceneConfig.snrRefs(1);
nSrcs = size( annotations.globalSrcEnergy.globalSrcEnergy, 2 );
srcsGlobalRefEnergyMeanChannel = zeros( ...
size( annotations.globalSrcEnergy.globalSrcEnergy ) );
for ss = 1 : nSrcs
srcsGlobalRefEnergyMeanChannel(:,ss) = mean( ...
cell2mat( annotations.globalSrcEnergy.globalSrcEnergy(:,ss) ), 2 );
end
srcsGlobalRefEnergyMeanChannel_db = 10 * log10( srcsGlobalRefEnergyMeanChannel );
snrRefNrjOffsets = cell2mat( annotations.globalNrjOffsets.globalNrjOffsets ) ...
- annotations.globalNrjOffsets.globalNrjOffsets{snrRef};
annotations.globalNrjOffsets = snrRefNrjOffsets;
for ss = 1 : nSrcs
otherIdxs = 1 : size( srcsGlobalRefEnergyMeanChannel, 2 );
otherIdxs(ss) = [];
srcsCurrentSrcRefEnergy_db = srcsGlobalRefEnergyMeanChannel_db ...
- snrRefNrjOffsets(ss);
srcsCurrentSrcRefEnergy = 10.^(srcsCurrentSrcRefEnergy_db./10);
sumOtherSrcsEnergy = sum( srcsCurrentSrcRefEnergy(:,otherIdxs), 2 );
sumOthersSrcsEnergy_db = 10 * log10( sumOtherSrcsEnergy );
annotations.nrjOthers_db.nrjOthers_db(:,ss) = single( sumOthersSrcsEnergy_db );
annotations.nrj_db.nrj_db(:,ss) = single( srcsCurrentSrcRefEnergy_db(:,ss) );
annotations.srcSNR_db.srcSNR_db(:,ss) = single( ...
srcsCurrentSrcRefEnergy_db(:,ss) - sumOthersSrcsEnergy_db );
end
haveSrcsEnergy = srcsGlobalRefEnergyMeanChannel_db > -40;
isAmbientSource = all( isnan( annotations.srcAzms.srcAzms ), 1 );
haveSrcsEnergy(:,isAmbientSource) = [];
annotations.nActivePointSrcs.nActivePointSrcs = single( sum( haveSrcsEnergy, 2 ) );
end
%% -------------------------------------------------------------------------------

end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function connectToOutputFrom( obj, outputtingProc )
end
%% ----------------------------------------------------------------

function checkDataFiles( obj, otherOverlay )
function cacheDirs = checkDataFiles( obj, otherOverlay )
fprintf( '\nChecking file list: %s\n%s\n', ...
obj.dataFileProcessor.procName, ...
repmat( '=', 1, 20 + numel( obj.dataFileProcessor.procName ) ) );
Expand All @@ -64,8 +64,13 @@ function checkDataFiles( obj, otherOverlay )
obj.dataFileProcessor.getSingleProcessCacheAccess();
DataProcs.MultiSceneCfgsIdProcWrapper.doEarlyHasProcessedStop( true, false );
end
fileHasBeenProcessed = ...
obj.dataFileProcessor.hasFileAlreadyBeenProcessed( dataFile.fileName );
if nargout > 0 && ~exist( 'cacheDirs', 'var' )
[fileHasBeenProcessed,cacheDirs] = ...
obj.dataFileProcessor.hasFileAlreadyBeenProcessed( dataFile.fileName );
else
fileHasBeenProcessed = ...
obj.dataFileProcessor.hasFileAlreadyBeenProcessed( dataFile.fileName );
end
if ii == 1
DataProcs.MultiSceneCfgsIdProcWrapper.doEarlyHasProcessedStop( true, true );
obj.dataFileProcessor.saveCacheDirectory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ function loadCacheDirectory( obj, filename )
end
%% -------------------------------------------------------------------------------

function maintenance( obj )
function maintenance( obj, deleteEmpties )
cDirs = dir( [obj.topCacheDirectory filesep 'cache.*'] );
cacheDirs = cell( 0, 3 );
fprintf( '-> read cache folders\n' );
Expand All @@ -159,7 +159,7 @@ function maintenance( obj )
pause;
else
cdContents = dir( [obj.topCacheDirectory filesep cDirs(ii).name filesep '*.mat'] );
if all( strcmpi( 'cfg.mat', {cdContents.name} ) | strcmpi( 'fdesc.mat', {cdContents.name} ) )
if deleteEmpties && all( strcmpi( 'cfg.mat', {cdContents.name} ) | strcmpi( 'fdesc.mat', {cdContents.name} ) )
rmdir( [obj.topCacheDirectory filesep cDirs(ii).name], 's' );
fprintf( 'deleting empty cache folder ' );
else
Expand Down Expand Up @@ -310,11 +310,12 @@ function maintenance( obj )
end
%% -------------------------------------------------------------------------------

function standaloneMaintain( cacheTopDir )
function standaloneMaintain( cacheTopDir, deleteEmpties )
if nargin < 2, deleteEmpties = true; end
cache = Core.IdCacheDirectory();
cache.setCacheTopDir( cacheTopDir );
cache.loadCacheDirectory();
cache.maintenance();
cache.maintenance( deleteEmpties );
end
%% -------------------------------------------------------------------------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,17 @@ function init( obj )
end
%% -------------------------------------------------------------------------------

function fileProcessed = hasFileAlreadyBeenProcessed( obj, wavFilepath )
function [fileProcessed,cacheDir] = hasFileAlreadyBeenProcessed( obj, wavFilepath )
if isempty( wavFilepath ), fileProcessed = false; return; end
fileProcessed = exist( obj.getOutputFilepath( wavFilepath ), 'file' );
cacheFile = obj.getOutputFilepath( wavFilepath );
if obj.forceCacheRewrite
fileProcessed = false;
else
fileProcessed = exist( cacheFile, 'file' );
end
if nargout > 1
cacheDir = fileparts( cacheFile );
end
end
%% -------------------------------------------------------------------------------

Expand Down Expand Up @@ -222,6 +230,22 @@ function save( obj, wavFilepath, out )

end

%% --------------------------------------------------------------------
methods (Static)

function b = forceCacheRewrite( newValue )
persistent fcrw;
if isempty( fcrw )
fcrw = false;
end
if nargin > 0
fcrw = newValue;
else
b = fcrw;
end
end

end
%% -----------------------------------------------------------------------------------
methods (Abstract)
process( obj, wavFilepath )
Expand Down

0 comments on commit 37143cc

Please sign in to comment.