wolffd@0: function varargout = mirlowenergy(x,varargin) wolffd@0: % p = mirlowenergy(f) computes the percentage of frames showing a RMS wolffd@0: % energy that is lower than a given threshold. wolffd@0: % For instance, for a musical excerpt with some very loud frames and wolffd@0: % lots of silent frames, we would get a high low-energy rate. wolffd@0: % Optional argument: wolffd@0: % mirlowenergy(...,'Threshold',t) expressed as a ratio to the average wolffd@0: % energy over the frames. wolffd@0: % Default value: t = 1 wolffd@0: % mirlowenergy(...,'Frame',l,h) specifies the use of frames of wolffd@0: % length l seconds and a hop rate h. wolffd@0: % Default values: l = .05 s, h = .5 wolffd@0: % mirlowenergy(...,'Root',0) uses mean square instead of root mean wolffd@0: % square wolffd@0: % mirlowenergy(...,'ASR') computes the Average Silence Ratio, which wolffd@0: % corresponds in fact to mirlowenergy(...,'Root',0,'Threshold',t) wolffd@0: % where t is fixed here by default to t = .5 wolffd@0: % [p,e] = mirlowenergy(...) also returns the RMS energy curve. wolffd@0: wolffd@0: asr.key = 'ASR'; wolffd@0: asr.type = 'Boolean'; wolffd@0: asr.default = 0; wolffd@0: option.asr = asr; wolffd@0: wolffd@0: root.key = 'Root'; wolffd@0: root.type = 'Boolean'; wolffd@0: root.default = 1; wolffd@0: option.root = root; wolffd@0: wolffd@0: thr.key = 'Threshold'; wolffd@0: thr.type = 'Integer'; wolffd@0: thr.default = NaN; wolffd@0: option.thr = thr; wolffd@0: wolffd@0: frame.key = 'Frame'; wolffd@0: frame.type = 'Integer'; wolffd@0: frame.number = 2; wolffd@0: frame.default = [.05 .5]; wolffd@0: option.frame = frame; wolffd@0: wolffd@0: specif.option = option; wolffd@0: wolffd@0: specif.combinechunk = {'Average',@nothing}; wolffd@0: specif.extensive = 1; wolffd@0: wolffd@0: varargout = mirfunction(@mirlowenergy,x,varargin,nargout,specif,@init,@main); wolffd@0: wolffd@0: wolffd@0: function [x type] = init(x,option) wolffd@0: if option.asr wolffd@0: option.root = 0; wolffd@0: end wolffd@0: if isamir(x,'miraudio') wolffd@0: if isframed(x) wolffd@0: x = mirrms(x,'Root',option.root); wolffd@0: else wolffd@0: x = mirrms(x,'Frame',option.frame.length.val,option.frame.length.unit,... wolffd@0: option.frame.hop.val,option.frame.hop.unit,... wolffd@0: 'Root',option.root); wolffd@0: end wolffd@0: end wolffd@0: type = 'mirscalar'; wolffd@0: wolffd@0: wolffd@0: function e = main(r,option,postoption) wolffd@0: if iscell(r) wolffd@0: r = r{1}; wolffd@0: end wolffd@0: if isnan(option.thr) wolffd@0: if option.asr wolffd@0: option.thr = .5; wolffd@0: else wolffd@0: option.thr = 1; wolffd@0: end wolffd@0: end wolffd@0: v = mircompute(@algo,get(r,'Data'),option.thr); wolffd@0: fp = mircompute(@noframe,get(r,'FramePos')); wolffd@0: e = mirscalar(r,'Data',v,'Title','Low energy','Unit','/1','FramePos',fp); wolffd@0: e = {e,r}; wolffd@0: wolffd@0: wolffd@0: function v = algo(d,thr) wolffd@0: v = sum(d < repmat(thr*mean(d,2),[1 size(d,2) 1])); wolffd@0: v = v / size(d,2); wolffd@0: wolffd@0: wolffd@0: function fp = noframe(fp) wolffd@0: fp = [fp(1);fp(end)]; wolffd@0: wolffd@0: wolffd@0: function y = nothing(old,new) wolffd@0: y = old;