Mercurial > hg > ape
view listeningTest/soundList/readSndList.m @ 15:24be5e9ce25b tip
Update README
author | Brecht De Man <brecht.deman@bcu.ac.uk> |
---|---|
date | Thu, 20 Sep 2018 12:23:20 +0200 |
parents | 4fd284285159 |
children |
line wrap: on
line source
function [snd,listFile,index]=readSndList(listFile,DOWNLOAD,RANDO) % readSndList(listFile,DOWNLOAD,RANDO) = [snd,listFile,index] % % listFile : name of the ASCII file where all sounds are listed % DOWNLOAD (0) : load sounds in memory? (1) % RANDO (0) : sort sounds files in random order? (1) % % A soundlist consists in different .wav files name contained in an ASCII file (.txt) preceeded by an index % - The first line may contain the path for searching all the files or a blank line % - the ouput is a structure: % snd(noSnd) % .vect % .fs % .name % .path % % % if % or * are present, the lines are not taken into account % if # at beginnning stop the sound list load... % you can also put an index in front of each sounds % % note on directories: % DIRECTORY: c:\dir1\ for PC % DIRECTORY: hardisk:dir1: for MAC % % cf. makeSndList, playSndList checkin('listFile',[]); checkin('DOWNLOAD',0); checkin('RANDO',0); if isempty(listFile) [name,pathname]=uigetfile('*.txt','Sound list?'); if name==0 return; end listFile=name; else pathname=''; % current directory name=listFile; end fid=fopen([pathname name],'r'); [pathname name] % DEBUG %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % count the number of sound files and save the index list %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% index=[]; nbSnd=0; while ~feof(fid) lin=fgetl(fid); [l,COUNT,ERRMSG,NEXTINDEX] = sscanf(lin,'%s',inf); if ((~isempty(l)) & (l(1)~='%') & (l(1)~='*')) if l(1)=='#' break; end [direc,COUNT,ERRMSG,NEXTINDEX] = sscanf(lin,'%s',1); if strcmp(upper(direc),'DIRECTORY:'); pathName=lin(NEXTINDEX+1:end); else nbSnd=nbSnd+1; [ind,COUNT,ERRMSG,NEXTINDEX] = sscanf(lin,'%d',1); if isempty(ind) index(nbSnd)=0; else index(nbSnd)=ind; end end end end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % create the index list and snd list %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% frewind(fid); sndName=''; pathName=''; newIndex(nbSnd)=0; index1=find(index~=0); newIndex(index(index1))=index(index1); emptyPlaces=find(newIndex==0); nbL=0; while ~feof(fid) lin=fgetl(fid); [l,COUNT,ERRMSG,NEXTINDEX] = sscanf(lin,'%s',inf); if ((~isempty(l)) & (l(1)~='%') & (l(1)~='*')) [direc,COUNT,ERRMSG,NEXTINDEX] = sscanf(lin,'%s',1); if strcmp(upper(direc),'DIRECTORY:'); pathName=lin(NEXTINDEX+1:end); else nbL=nbL+1; [name,COUNT,ERRMSG,NEXTINDEX] = sscanf(lin,'%s',1); [vol,COUNT,ERRMSG,NEXTINDEX] = sscanf(lin(NEXTINDEX+2:end),'%f',1); % if isempty(inde) % inde=emptyPlaces(1); % if length(emptyPlaces)~=1 % emptyPlaces=emptyPlaces(2:end); % end % end % if isempty(vol) % vol=1; % end sndName{nbL}=name; sndPath{nbL}=pathName; sndVol{nbL}=vol; end end end if RANDO newSort=randperm(nbSnd); end for nooSnd=1:nbSnd if RANDO noSnd=newSort(nooSnd); else noSnd=nooSnd; end if DOWNLOAD [snd(noSnd).vect,snd(noSnd).fs]=wavread([pathName sndName{nooSnd}]); else snd(noSnd).vect=''; snd(noSnd).fs=''; end snd(noSnd).name=strtok(sndName{nooSnd},'.'); snd(noSnd).path=sndPath{nooSnd}; snd(noSnd).listFile=listFile; snd(noSnd).vol=sndVol{nooSnd}; end fclose(fid);