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