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