comparison toolboxes/MIRtoolbox1.3.2/MIRToolbox/@mirquery/mirquery.m @ 0:e9a9cd732c1e tip

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