view listeningTest/multiComp/readMultiComp.m @ 0:4fd284285159

Adding listening test plus some helpful functions and scripts.
author Brecht <b.deman@qmul.ac.uk>
date Thu, 24 Apr 2014 23:53:31 +0100
parents
children
line wrap: on
line source
function tstDat=readMultiComp(testFile)

% multiple comparison 1D specifications
%
% NAME:
% multicomp test #1
% 
% nbSCALES: 1
% nbSOUNDS: 3
%
% COMBINATIONS
% 1                      (random position) 
% 2 reference position 1
% 3 position 3
%
% SCALES
% 
% SCALE:
% 1st scale
% MIN: 0  no amount
% MAX: 10 max amount
% STEP: 1 in between
%
% COMMENTS? 1			% ask if a comment field should be displayed (1=yes 0=no)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Initialization
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

tstDat.sndRef=[];
tstDat.posComb=[];

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% file parsing
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

fid=fopen(testFile,'r');
while ~feof(fid)
   lin=fgetl(fid);
   
   [word1,COUNT,ERRMSG,NEXTINDEX] = sscanf(lin,'%s',1);
   
   if (~COUNT | ~strcmp(word1,'%'))      
      switch upper(word1)
      case 'NAME'
         tstDat.name=fgetl(fid);
         
      case 'NBSOUNDS:'
         [nbComb,COUNT,ERRMSG,NEXTINDEX] = sscanf(lin(NEXTINDEX:end),'%d',1);
         tstDat.nbComb=nbComb;
         
      case 'NBSCALES:'
         [nbScale,COUNT,ERRMSG,NEXTINDEX] = sscanf(lin(NEXTINDEX:end),'%d',1);
         tstDat.nbScale=nbScale;
         
      case 'COMBINATIONS'
         for noComb=1:nbComb
            lin=fgetl(fid);
            if ~isempty(lin) 
               if lin(1)~='%'
                  [comb,COUNT,ERRMSG,NEXTINDEX] = sscanf(lin,'%d',1);
                  tstDat.comb(noComb,:)=comb;
                  % Read the reference DATA
                  lin=lin(NEXTINDEX:end);
                  [stri,COUNT,ERRMSG,NEXTINDEX] = sscanf(lin,'%s',1);
                  if findstr(lower(stri),'ref')				
                     tstDat.sndRef(end+1)=comb(1);
                     lin=lin(NEXTINDEX:end);
                     [stri,COUNT,ERRMSG,NEXTINDEX] = sscanf(lin,'%s',1);
                  end
                  % read the sounds default position
                  if findstr(lower(stri),'pos')
                     lin=lin(NEXTINDEX:end);
                  end
                  [posComb,COUNT,ERRMSG,NEXTINDEX] = sscanf(lin,'%f',inf);	
                  if ~isempty(posComb)                      % if it IS empty: set randomly!
                     tstDat.posComb(noComb,:)=posComb;
                  else
                     tstDat.posComb(noComb,:)=100*rand(1, tstDat.nbScale);     % added by Brecht to allow for random placing
                     
                  end     
               end               
            end			
         end
         %eol(fid); %BDM???
      case 'SCALES'
         % check posRef length
         nbRef=length(tstDat.sndRef);
         for noRef=1:nbRef	
            if (length(tstDat.posComb(tstDat.sndRef(noRef),:))~=nbScale)
               fprintf(1,'Watch out, the position of reference %d are not specified for all scale',noRef);
            end
         end	
         for noScale=1:nbScale
            
            while ~feof(fid)					
               lin=fgetl(fid);
               [header,COUNT,ERRMSG,NEXTINDEX] = sscanf(lin,'%s',1);					               
               switch firstWord(header)
               case 'SCALE:'
                  name=fgetl(fid);						
               case 'min'
                  lin=lin(NEXTINDEX:end);
                  [minn,COUNT,ERRMSG,NEXTINDEX]=sscanf(lin,'%d',1); %%
                  level{1}=lin(NEXTINDEX:end); %%
               case 'max'
                  lin=lin(NEXTINDEX:end);
                  [maxx,COUNT,ERRMSG,NEXTINDEX]=sscanf(lin,'%d',1); %%
                  level{3}=lin(NEXTINDEX:end); %%
               case 'step'
                  lin=lin(NEXTINDEX:end);
                  [stepp,COUNT,ERRMSG,NEXTINDEX]=sscanf(lin,'%d',1); %%
                  level{2}=lin(NEXTINDEX:end); %%
                  break
               end
               
            end
            tstDat.scale(noScale).name=name;
            tstDat.scale(noScale).maxx=maxx;
            tstDat.scale(noScale).minn=minn;
            tstDat.scale(noScale).stepp=stepp;
            tstDat.scale(noScale).level=level;
         end
      case 'COMMENTS?:'
         [COM,COUNT,ERRMSG,NEXTINDEX] = sscanf(lin(NEXTINDEX:end),'%d',1);
         tstDat.COM=COM;
      end
   end
end

fclose(fid);


function word=firstWord(word)

if ~isempty(word) 
   if word(1)=='%'
      word='';
   end
else
   word='';
end