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