wolffd@0: classdef MTTMixedFeatureSon < MTTAudioFeature & handle wolffd@0: % --- wolffd@0: % This Class contains a wrapper for sons feature extraction wolffd@0: % wolffd@0: % The usual workflow for these features constist of three steps wolffd@0: % 1. extract: extracts the basic single-file dependent features wolffd@0: % 2. define_global_transform: calculates the global feature wolffd@0: % transformation parameters wolffd@0: % 3. finalise: applies the common transformations to a specific feature wolffd@0: % --- wolffd@0: wolffd@0: properties(Constant = true) wolffd@0: wolffd@0: % svn hook wolffd@0: my_revision = str2double(substr('$Rev: 741 $', 5, -1)); wolffd@0: end wolffd@0: wolffd@0: properties wolffd@0: % --- wolffd@0: % Set default parameters wolffd@0: % --- wolffd@0: my_params = struct( ... wolffd@0: 'son_filename','features_rbm_50x1010', ... wolffd@0: 'son_conf', '' ... wolffd@0: ); wolffd@0: end wolffd@0: wolffd@0: % --- wolffd@0: % member functions wolffd@0: % --- wolffd@0: methods wolffd@0: wolffd@0: % --- wolffd@0: % constructor: pointer to feature in database wolffd@0: % --- wolffd@0: function feature = MTTMixedFeatureSon(varargin) wolffd@0: wolffd@0: feature = feature@MTTAudioFeature(varargin{:}); wolffd@0: wolffd@0: end wolffd@0: % --- wolffd@0: % extract feature data from raw audio features wolffd@0: % --- wolffd@0: function data = extract(feature, clip) wolffd@0: % --- wolffd@0: % get features. this includes possible wolffd@0: % local normalisations wolffd@0: % --- wolffd@0: wolffd@0: global globalvars; wolffd@0: global comparison_ids; wolffd@0: global sonfeatbase; wolffd@0: global db_MTTClip; wolffd@0: wolffd@0: if isempty(sonfeatbase); wolffd@0: sonfeatbase = load(feature.my_params.son_filename); wolffd@0: end wolffd@0: % wolffd@0: wolffd@0: % --- wolffd@0: % note: this should reference clip.my_db wolffd@0: % get the actual clip id wolffd@0: idx = db_MTTClip.comparison_ids(clip.id); wolffd@0: wolffd@0: % --- wolffd@0: % NOTE: we just copy everything in a big matrix and then wolffd@0: % normalise the data later wolffd@0: % --- wolffd@0: if isfield(sonfeatbase,'nfvec') wolffd@0: rawf = sonfeatbase.nfvec; wolffd@0: elseif isfield(sonfeatbase,'sonfeatures') wolffd@0: rawf = sonfeatbase.sonfeatures'; wolffd@0: end wolffd@0: wolffd@0: if idx <= size(rawf,2) wolffd@0: wolffd@0: % get the vector from loaded data wolffd@0: data.sonraw = rawf(:,idx); wolffd@0: wolffd@0: else wolffd@0: % --- wolffd@0: % CAVE: Clip indices outside wolffd@0: % the range of the supplied mat file wolffd@0: % are filled up with zeros wolffd@0: % --- wolffd@0: data.sonraw = zeros(size(rawf,1),1); wolffd@0: end wolffd@0: wolffd@0: wolffd@0: wolffd@0: data.vector_info = {'Sonfeat'}; wolffd@0: % padd further info struct wolffd@0: data.vector_info(end+1:size(data.sonraw,1)) =... wolffd@0: cell(size(data.sonraw,1) - numel(data.vector_info) , 1); wolffd@0: wolffd@0: % --- wolffd@0: % prepare field for final features wolffd@0: % --- wolffd@0: data.final.vector = []; wolffd@0: data.final.vector_info = struct(); wolffd@0: data.final.dim = 0; wolffd@0: wolffd@0: % save info data wolffd@0: data.info.type = 'MTTMixedFeatureSon'; wolffd@0: data.info.owner_id = clip.id; wolffd@0: data.info.creatorrev = feature.my_revision; wolffd@0: wolffd@0: % save parameters wolffd@0: data.info.params = feature.my_params; wolffd@0: end wolffd@0: wolffd@0: function define_global_transform(features) wolffd@0: % calculate and set normalization factors from the group of wolffd@0: % input features. These features will be set for the full database wolffd@0: wolffd@0: final = zeros(size(features(1).data.sonraw,1), numel(features)); wolffd@0: for i = 1:numel(features) wolffd@0: if ~isempty(features(i).data.sonraw) wolffd@0: final(:,i) = features(i).data.sonraw; wolffd@0: end wolffd@0: end wolffd@0: wolffd@0: % set common to 1 to tell normalisation is done wolffd@0: features(1).my_db.set_common([1]); wolffd@0: wolffd@0: % save the normalised features straight away! wolffd@0: features.finalise(final); wolffd@0: end wolffd@0: wolffd@0: wolffd@0: function finalise(features, final) wolffd@0: % applies a final transformation and wolffd@0: % collects the information of this feature within a single vector wolffd@0: % see info for types in specific dimensions wolffd@0: % check if features have been finalised already wolffd@0: wolffd@0: % --- wolffd@0: % set feature labelling wolffd@0: % --- wolffd@0: wolffd@0: info = {}; wolffd@0: wolffd@0: % --- wolffd@0: % construct resulting feature vector out of features wolffd@0: % --- wolffd@0: if nargin == 2 && isempty(final) wolffd@0: wolffd@0: % the final vector etc already are set to zero; wolffd@0: return; wolffd@0: wolffd@0: elseif nargin == 2 && (numel(features) == size(final, 2)) wolffd@0: % the features have already been preassembled wolffd@0: wolffd@0: for i = 1:numel(features) wolffd@0: wolffd@0: % check for neccesary parameters wolffd@0: if isempty(features(i).my_db.commondb) wolffd@0: wolffd@0: error('Define the global transformation first') wolffd@0: return; wolffd@0: end wolffd@0: wolffd@0: features(i).data.final.vector = final(:,i); wolffd@0: features(i).data.final.dim = size(final,1); wolffd@0: wolffd@0: % fill up info struct and append to feature wolffd@0: features(i).data.final.vector_info.labels = ... wolffd@0: features(i).data.vector_info; wolffd@0: end wolffd@0: else wolffd@0: % --- wolffd@0: % if features have been added after gettin gnormalisation wolffd@0: % parameters, ther should be still an option to include wolffd@0: % them wolffd@0: % --- wolffd@0: wolffd@0: for i = 1:numel(features) wolffd@0: wolffd@0: % check for neccesary parameters wolffd@0: if isempty(features(i).my_db.commondb) wolffd@0: wolffd@0: error('Define the global transformation first') wolffd@0: return; wolffd@0: end wolffd@0: wolffd@0: final = zeros(numel(features(1).data.sonraw), numel(features)); wolffd@0: for i = 1:numel(features) wolffd@0: if ~isempty(features(i).data.sonraw) wolffd@0: final(:,i) = features(i).data.sonraw; wolffd@0: end wolffd@0: end wolffd@0: features(i).data.final.vector = final; wolffd@0: features(i).data.final.dim = size(final,1); wolffd@0: wolffd@0: % fill up info struct and append to feature wolffd@0: features(i).data.final.vector_info.labels = ... wolffd@0: features(i).data.vector_info; wolffd@0: end wolffd@0: wolffd@0: end wolffd@0: wolffd@0: % --- wolffd@0: % TODO: Maybe delete more basic features again at this point? wolffd@0: % --- wolffd@0: end wolffd@0: wolffd@0: % --- wolffd@0: % destructor: do we really want to remove this wolffd@0: % from the database? No, but wolffd@0: % TODO: create marker for unused objects in db, and a cleanup wolffd@0: % function wolffd@0: % --- wolffd@0: function delete(feature) wolffd@0: wolffd@0: end wolffd@0: end wolffd@0: end