annotate toolboxes/MIRtoolbox1.3.2/MIRToolbox/@mirquery/mirquery.m @ 0:cc4b1211e677 tip

initial commit to HG from Changeset: 646 (e263d8a21543) added further path and more save "camirversion.m"
author Daniel Wolff
date Fri, 19 Aug 2016 13:07:06 +0200
parents
children
rev   line source
Daniel@0 1 function res = mirquery(varargin)
Daniel@0 2 % r = mirquery(q,b), where
Daniel@0 3 % q is the analysis of one audio file and
Daniel@0 4 % b is the analysis of a folder of audio files,
Daniel@0 5 % according to the same mirtoolbox feature,
Daniel@0 6 % returns the name of the audio files in the database b in an
Daniel@0 7 % increasing distance to q with respect to the chosen feature.
Daniel@0 8 % r = mirquery(d), where
Daniel@0 9 % d is the distance between one audio file and a folder of audio
Daniel@0 10 % file, according to a mirtoolbox feature,
Daniel@0 11 % returns the name of the audio files in an increasing distance d.
Daniel@0 12 %
Daniel@0 13 % Optional argument:
Daniel@0 14 % mirquery(...,'Best',n) returns the name of the n closest audio
Daniel@0 15 % files.
Daniel@0 16 % mirquery(..,'Distance',d) specifies the distance to use.
Daniel@0 17 % Default value: d = 'Cosine' (cf. mirdist)
Daniel@0 18
Daniel@0 19 [distfunc,nbout] = scanargin(varargin);
Daniel@0 20
Daniel@0 21 if nargin<2 || not(isa(varargin{2},'mirdata'))
Daniel@0 22 returnval=0;
Daniel@0 23 dist = varargin{1};
Daniel@0 24 name = get(dist,'Name2');
Daniel@0 25 res.query.val = [];
Daniel@0 26 res.query.name = get(dist,'Name');
Daniel@0 27 else
Daniel@0 28 returnval=1;
Daniel@0 29 query = varargin{1};
Daniel@0 30 base = varargin{2};
Daniel@0 31 name = get(base,'Name');
Daniel@0 32 res.query.val = mirgetdata(query);
Daniel@0 33 res.query.name = get(query,'Name');
Daniel@0 34 database = mirgetdata(base);
Daniel@0 35 dist = mirdist(query,base,distfunc);
Daniel@0 36 end
Daniel@0 37 datadist = mirgetdata(dist);
Daniel@0 38
Daniel@0 39 [ordist order] = sort(datadist);
Daniel@0 40 order(isnan(ordist)) = [];
Daniel@0 41 nbout = min(nbout,length(order));
Daniel@0 42 res.dist = ordist(1:nbout);
Daniel@0 43 if returnval
Daniel@0 44 res.val = database(order);
Daniel@0 45 else
Daniel@0 46 res.val = [];
Daniel@0 47 end
Daniel@0 48 res.name = name(order);
Daniel@0 49
Daniel@0 50 res = class(res,'mirquery');
Daniel@0 51
Daniel@0 52
Daniel@0 53
Daniel@0 54 function [distfunc,nbout] = scanargin(v)
Daniel@0 55 distfunc = 'Cosine';
Daniel@0 56 nbout=Inf;
Daniel@0 57 i = 1;
Daniel@0 58 while i <= length(v)
Daniel@0 59 arg = v{i};
Daniel@0 60 if ischar(arg) && strcmpi(arg,'Distance')
Daniel@0 61 if length(v)>i && ischar(v{i+1})
Daniel@0 62 i = i+1;
Daniel@0 63 distfunc = v{i};
Daniel@0 64 end
Daniel@0 65 elseif ischar(arg) && strcmpi(arg,'Best')
Daniel@0 66 if length(v)>i && isnumeric(v{i+1})
Daniel@0 67 i = i+1;
Daniel@0 68 nbout = v{i};
Daniel@0 69 end
Daniel@0 70 %else
Daniel@0 71 % error('ERROR IN MIRQUERY: Syntax error. See help mirquery.');
Daniel@0 72 end
Daniel@0 73 i = i+1;
Daniel@0 74 end