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