annotate core/magnatagatune/MTTMixedFeatureSon.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1 classdef MTTMixedFeatureSon < MTTAudioFeature & handle
wolffd@0 2 % ---
wolffd@0 3 % This Class contains a wrapper for sons feature extraction
wolffd@0 4 %
wolffd@0 5 % The usual workflow for these features constist of three steps
wolffd@0 6 % 1. extract: extracts the basic single-file dependent features
wolffd@0 7 % 2. define_global_transform: calculates the global feature
wolffd@0 8 % transformation parameters
wolffd@0 9 % 3. finalise: applies the common transformations to a specific feature
wolffd@0 10 % ---
wolffd@0 11
wolffd@0 12 properties(Constant = true)
wolffd@0 13
wolffd@0 14 % svn hook
wolffd@0 15 my_revision = str2double(substr('$Rev: 741 $', 5, -1));
wolffd@0 16 end
wolffd@0 17
wolffd@0 18 properties
wolffd@0 19 % ---
wolffd@0 20 % Set default parameters
wolffd@0 21 % ---
wolffd@0 22 my_params = struct( ...
wolffd@0 23 'son_filename','features_rbm_50x1010', ...
wolffd@0 24 'son_conf', '' ...
wolffd@0 25 );
wolffd@0 26 end
wolffd@0 27
wolffd@0 28 % ---
wolffd@0 29 % member functions
wolffd@0 30 % ---
wolffd@0 31 methods
wolffd@0 32
wolffd@0 33 % ---
wolffd@0 34 % constructor: pointer to feature in database
wolffd@0 35 % ---
wolffd@0 36 function feature = MTTMixedFeatureSon(varargin)
wolffd@0 37
wolffd@0 38 feature = feature@MTTAudioFeature(varargin{:});
wolffd@0 39
wolffd@0 40 end
wolffd@0 41 % ---
wolffd@0 42 % extract feature data from raw audio features
wolffd@0 43 % ---
wolffd@0 44 function data = extract(feature, clip)
wolffd@0 45 % ---
wolffd@0 46 % get features. this includes possible
wolffd@0 47 % local normalisations
wolffd@0 48 % ---
wolffd@0 49
wolffd@0 50 global globalvars;
wolffd@0 51 global comparison_ids;
wolffd@0 52 global sonfeatbase;
wolffd@0 53 global db_MTTClip;
wolffd@0 54
wolffd@0 55 if isempty(sonfeatbase);
wolffd@0 56 sonfeatbase = load(feature.my_params.son_filename);
wolffd@0 57 end
wolffd@0 58 %
wolffd@0 59
wolffd@0 60 % ---
wolffd@0 61 % note: this should reference clip.my_db
wolffd@0 62 % get the actual clip id
wolffd@0 63 idx = db_MTTClip.comparison_ids(clip.id);
wolffd@0 64
wolffd@0 65 % ---
wolffd@0 66 % NOTE: we just copy everything in a big matrix and then
wolffd@0 67 % normalise the data later
wolffd@0 68 % ---
wolffd@0 69 if isfield(sonfeatbase,'nfvec')
wolffd@0 70 rawf = sonfeatbase.nfvec;
wolffd@0 71 elseif isfield(sonfeatbase,'sonfeatures')
wolffd@0 72 rawf = sonfeatbase.sonfeatures';
wolffd@0 73 end
wolffd@0 74
wolffd@0 75 if idx <= size(rawf,2)
wolffd@0 76
wolffd@0 77 % get the vector from loaded data
wolffd@0 78 data.sonraw = rawf(:,idx);
wolffd@0 79
wolffd@0 80 else
wolffd@0 81 % ---
wolffd@0 82 % CAVE: Clip indices outside
wolffd@0 83 % the range of the supplied mat file
wolffd@0 84 % are filled up with zeros
wolffd@0 85 % ---
wolffd@0 86 data.sonraw = zeros(size(rawf,1),1);
wolffd@0 87 end
wolffd@0 88
wolffd@0 89
wolffd@0 90
wolffd@0 91 data.vector_info = {'Sonfeat'};
wolffd@0 92 % padd further info struct
wolffd@0 93 data.vector_info(end+1:size(data.sonraw,1)) =...
wolffd@0 94 cell(size(data.sonraw,1) - numel(data.vector_info) , 1);
wolffd@0 95
wolffd@0 96 % ---
wolffd@0 97 % prepare field for final features
wolffd@0 98 % ---
wolffd@0 99 data.final.vector = [];
wolffd@0 100 data.final.vector_info = struct();
wolffd@0 101 data.final.dim = 0;
wolffd@0 102
wolffd@0 103 % save info data
wolffd@0 104 data.info.type = 'MTTMixedFeatureSon';
wolffd@0 105 data.info.owner_id = clip.id;
wolffd@0 106 data.info.creatorrev = feature.my_revision;
wolffd@0 107
wolffd@0 108 % save parameters
wolffd@0 109 data.info.params = feature.my_params;
wolffd@0 110 end
wolffd@0 111
wolffd@0 112 function define_global_transform(features)
wolffd@0 113 % calculate and set normalization factors from the group of
wolffd@0 114 % input features. These features will be set for the full database
wolffd@0 115
wolffd@0 116 final = zeros(size(features(1).data.sonraw,1), numel(features));
wolffd@0 117 for i = 1:numel(features)
wolffd@0 118 if ~isempty(features(i).data.sonraw)
wolffd@0 119 final(:,i) = features(i).data.sonraw;
wolffd@0 120 end
wolffd@0 121 end
wolffd@0 122
wolffd@0 123 % set common to 1 to tell normalisation is done
wolffd@0 124 features(1).my_db.set_common([1]);
wolffd@0 125
wolffd@0 126 % save the normalised features straight away!
wolffd@0 127 features.finalise(final);
wolffd@0 128 end
wolffd@0 129
wolffd@0 130
wolffd@0 131 function finalise(features, final)
wolffd@0 132 % applies a final transformation and
wolffd@0 133 % collects the information of this feature within a single vector
wolffd@0 134 % see info for types in specific dimensions
wolffd@0 135 % check if features have been finalised already
wolffd@0 136
wolffd@0 137 % ---
wolffd@0 138 % set feature labelling
wolffd@0 139 % ---
wolffd@0 140
wolffd@0 141 info = {};
wolffd@0 142
wolffd@0 143 % ---
wolffd@0 144 % construct resulting feature vector out of features
wolffd@0 145 % ---
wolffd@0 146 if nargin == 2 && isempty(final)
wolffd@0 147
wolffd@0 148 % the final vector etc already are set to zero;
wolffd@0 149 return;
wolffd@0 150
wolffd@0 151 elseif nargin == 2 && (numel(features) == size(final, 2))
wolffd@0 152 % the features have already been preassembled
wolffd@0 153
wolffd@0 154 for i = 1:numel(features)
wolffd@0 155
wolffd@0 156 % check for neccesary parameters
wolffd@0 157 if isempty(features(i).my_db.commondb)
wolffd@0 158
wolffd@0 159 error('Define the global transformation first')
wolffd@0 160 return;
wolffd@0 161 end
wolffd@0 162
wolffd@0 163 features(i).data.final.vector = final(:,i);
wolffd@0 164 features(i).data.final.dim = size(final,1);
wolffd@0 165
wolffd@0 166 % fill up info struct and append to feature
wolffd@0 167 features(i).data.final.vector_info.labels = ...
wolffd@0 168 features(i).data.vector_info;
wolffd@0 169 end
wolffd@0 170 else
wolffd@0 171 % ---
wolffd@0 172 % if features have been added after gettin gnormalisation
wolffd@0 173 % parameters, ther should be still an option to include
wolffd@0 174 % them
wolffd@0 175 % ---
wolffd@0 176
wolffd@0 177 for i = 1:numel(features)
wolffd@0 178
wolffd@0 179 % check for neccesary parameters
wolffd@0 180 if isempty(features(i).my_db.commondb)
wolffd@0 181
wolffd@0 182 error('Define the global transformation first')
wolffd@0 183 return;
wolffd@0 184 end
wolffd@0 185
wolffd@0 186 final = zeros(numel(features(1).data.sonraw), numel(features));
wolffd@0 187 for i = 1:numel(features)
wolffd@0 188 if ~isempty(features(i).data.sonraw)
wolffd@0 189 final(:,i) = features(i).data.sonraw;
wolffd@0 190 end
wolffd@0 191 end
wolffd@0 192 features(i).data.final.vector = final;
wolffd@0 193 features(i).data.final.dim = size(final,1);
wolffd@0 194
wolffd@0 195 % fill up info struct and append to feature
wolffd@0 196 features(i).data.final.vector_info.labels = ...
wolffd@0 197 features(i).data.vector_info;
wolffd@0 198 end
wolffd@0 199
wolffd@0 200 end
wolffd@0 201
wolffd@0 202 % ---
wolffd@0 203 % TODO: Maybe delete more basic features again at this point?
wolffd@0 204 % ---
wolffd@0 205 end
wolffd@0 206
wolffd@0 207 % ---
wolffd@0 208 % destructor: do we really want to remove this
wolffd@0 209 % from the database? No, but
wolffd@0 210 % TODO: create marker for unused objects in db, and a cleanup
wolffd@0 211 % function
wolffd@0 212 % ---
wolffd@0 213 function delete(feature)
wolffd@0 214
wolffd@0 215 end
wolffd@0 216 end
wolffd@0 217 end