Daniel@0: function res = mirquery(varargin) Daniel@0: % r = mirquery(q,b), where Daniel@0: % q is the analysis of one audio file and Daniel@0: % b is the analysis of a folder of audio files, Daniel@0: % according to the same mirtoolbox feature, Daniel@0: % returns the name of the audio files in the database b in an Daniel@0: % increasing distance to q with respect to the chosen feature. Daniel@0: % r = mirquery(d), where Daniel@0: % d is the distance between one audio file and a folder of audio Daniel@0: % file, according to a mirtoolbox feature, Daniel@0: % returns the name of the audio files in an increasing distance d. Daniel@0: % Daniel@0: % Optional argument: Daniel@0: % mirquery(...,'Best',n) returns the name of the n closest audio Daniel@0: % files. Daniel@0: % mirquery(..,'Distance',d) specifies the distance to use. Daniel@0: % Default value: d = 'Cosine' (cf. mirdist) Daniel@0: Daniel@0: [distfunc,nbout] = scanargin(varargin); Daniel@0: Daniel@0: if nargin<2 || not(isa(varargin{2},'mirdata')) Daniel@0: returnval=0; Daniel@0: dist = varargin{1}; Daniel@0: name = get(dist,'Name2'); Daniel@0: res.query.val = []; Daniel@0: res.query.name = get(dist,'Name'); Daniel@0: else Daniel@0: returnval=1; Daniel@0: query = varargin{1}; Daniel@0: base = varargin{2}; Daniel@0: name = get(base,'Name'); Daniel@0: res.query.val = mirgetdata(query); Daniel@0: res.query.name = get(query,'Name'); Daniel@0: database = mirgetdata(base); Daniel@0: dist = mirdist(query,base,distfunc); Daniel@0: end Daniel@0: datadist = mirgetdata(dist); Daniel@0: Daniel@0: [ordist order] = sort(datadist); Daniel@0: order(isnan(ordist)) = []; Daniel@0: nbout = min(nbout,length(order)); Daniel@0: res.dist = ordist(1:nbout); Daniel@0: if returnval Daniel@0: res.val = database(order); Daniel@0: else Daniel@0: res.val = []; Daniel@0: end Daniel@0: res.name = name(order); Daniel@0: Daniel@0: res = class(res,'mirquery'); Daniel@0: Daniel@0: Daniel@0: Daniel@0: function [distfunc,nbout] = scanargin(v) Daniel@0: distfunc = 'Cosine'; Daniel@0: nbout=Inf; Daniel@0: i = 1; Daniel@0: while i <= length(v) Daniel@0: arg = v{i}; Daniel@0: if ischar(arg) && strcmpi(arg,'Distance') Daniel@0: if length(v)>i && ischar(v{i+1}) Daniel@0: i = i+1; Daniel@0: distfunc = v{i}; Daniel@0: end Daniel@0: elseif ischar(arg) && strcmpi(arg,'Best') Daniel@0: if length(v)>i && isnumeric(v{i+1}) Daniel@0: i = i+1; Daniel@0: nbout = v{i}; Daniel@0: end Daniel@0: %else Daniel@0: % error('ERROR IN MIRQUERY: Syntax error. See help mirquery.'); Daniel@0: end Daniel@0: i = i+1; Daniel@0: end