wolffd@0: function [d,d2] = mirgetdata(x,varargin) wolffd@0: % d = mirgetdata(x) return the data contained in the object x in a wolffd@0: % structure that can be used for further computation outside MIRtoolbox. wolffd@0: % If x corresponds to one non-segmented audio sequence, the result is wolffd@0: % returned as a matrix. The columns of the matrix usually wolffd@0: % correspond to the successive frames of the audio signal. The wolffd@0: % third dimension of the matrix corresponds to the different wolffd@0: % channels of a filterbank. wolffd@0: % If x is a keystrength curve, the fourth dimension distinguishes wolffd@0: % between major and minor keys. i.e. d(:,:,:,1) is the wolffd@0: % keystrength for the major keys, and d(:,:,:,2) is the wolffd@0: % keystrength for the minor keys. wolffd@0: % If x is a key estimation, two output are returned: the first one wolffd@0: % gives the keys (from 1 to 12) and the second one indicates the wolffd@0: % modes (1 for major, 2 for minor). wolffd@0: % wolffd@0: % If x corresponds to a set of audio sequences, and if each sequence wolffd@0: % has same number of frames, the corresponding resulting matrices wolffd@0: % are concatenated columnwise one after the other. If the number wolffd@0: % of raws of the elementary matrices varies, the missing values wolffd@0: % are replaced by NaN in the final matrix. On the contrary, if wolffd@0: % the number of columns (i.e., frames) differs, then the result wolffd@0: % remains a cell array of matrices. wolffd@0: % Idem if x corresponds to one or several segmented audio wolffd@0: % sequence(s). wolffd@0: % wolffd@0: % If x is the result of a peak detection, wolffd@0: % [px,py] = getdata(x) return the position of the peaks (px) and the wolffd@0: % value corresponding to these peaks (py), in the units wolffd@0: % predefined for this data. wolffd@0: wolffd@0: if isempty(x) wolffd@0: d = {}; wolffd@0: d2 = {}; wolffd@0: return wolffd@0: end wolffd@0: wolffd@0: if isstruct(x) wolffd@0: fields = fieldnames(x); wolffd@0: for f = 1:length(fields) wolffd@0: d.(fields{f}) = mirgetdata(x.(fields{f})); wolffd@0: end wolffd@0: d2 = {}; wolffd@0: return wolffd@0: end wolffd@0: wolffd@0: if iscell(x) wolffd@0: x = x{1}; wolffd@0: end wolffd@0: v = get(x,'Data'); wolffd@0: if isa(x,'mirscalar') wolffd@0: m = get(x,'Mode'); wolffd@0: end wolffd@0: d2 = {}; wolffd@0: wolffd@0: if isa(x,'mirclassify') wolffd@0: d = get(x,'Data'); wolffd@0: return wolffd@0: end wolffd@0: wolffd@0: if isa(x,'mirsimatrix') wolffd@0: pt = []; wolffd@0: else wolffd@0: pt = get(x,'PeakPrecisePos'); wolffd@0: end wolffd@0: pv = get(x,'PeakPreciseVal'); wolffd@0: if not(isempty(pt)) && not(isempty(pt{1})) && not(isempty(pt{1}{1})) wolffd@0: d = uncell(pt); wolffd@0: d2 = uncell(pv); wolffd@0: if not(isempty(d)) wolffd@0: return wolffd@0: end wolffd@0: end wolffd@0: wolffd@0: if isa(x,'mirsimatrix') wolffd@0: pt = []; wolffd@0: else wolffd@0: pt = get(x,'PeakPosUnit'); wolffd@0: end wolffd@0: pv = get(x,'PeakVal'); wolffd@0: if not(isempty(pt)) && not(isempty(pt{1})) && not(isempty(pt{1}{1})) wolffd@0: d = uncell(pt); wolffd@0: d2 = uncell(pv); wolffd@0: if not(isempty(d)) wolffd@0: return wolffd@0: end wolffd@0: end wolffd@0: wolffd@0: d = uncell(v,isa(x,'mirscalar')); wolffd@0: if iscell(d) && not(isempty(d)) && nargin == 1 wolffd@0: disp('The result is an array of cell.') wolffd@0: disp(['If d is the name of the output variable, ',... wolffd@0: 'the successive cells can be accessed by typing d{1}, d{2}, etc.']); wolffd@0: end wolffd@0: if exist('m')==1 && not(isempty(m)) && not(isempty(m{1})) wolffd@0: d2 = uncell(m); wolffd@0: end