b@0: function [snd,listFile,index]=readSndList(listFile,DOWNLOAD,RANDO) b@0: b@0: % readSndList(listFile,DOWNLOAD,RANDO) = [snd,listFile,index] b@0: % b@0: % listFile : name of the ASCII file where all sounds are listed b@0: % DOWNLOAD (0) : load sounds in memory? (1) b@0: % RANDO (0) : sort sounds files in random order? (1) b@0: % b@0: % A soundlist consists in different .wav files name contained in an ASCII file (.txt) preceeded by an index b@0: % - The first line may contain the path for searching all the files or a blank line b@0: % - the ouput is a structure: b@0: % snd(noSnd) b@0: % .vect b@0: % .fs b@0: % .name b@0: % .path b@0: % b@0: % b@0: % if % or * are present, the lines are not taken into account b@0: % if # at beginnning stop the sound list load... b@0: % you can also put an index in front of each sounds b@0: % b@0: % note on directories: b@0: % DIRECTORY: c:\dir1\ for PC b@0: % DIRECTORY: hardisk:dir1: for MAC b@0: % b@0: % cf. makeSndList, playSndList b@0: b@0: checkin('listFile',[]); b@0: checkin('DOWNLOAD',0); b@0: checkin('RANDO',0); b@0: b@0: if isempty(listFile) b@0: [name,pathname]=uigetfile('*.txt','Sound list?'); b@0: if name==0 b@0: return; b@0: end b@0: listFile=name; b@0: else b@0: pathname=''; % current directory b@0: name=listFile; b@0: end b@0: b@0: fid=fopen([pathname name],'r'); b@0: [pathname name] % DEBUG b@0: b@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% b@0: % count the number of sound files and save the index list b@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% b@0: index=[]; b@0: nbSnd=0; b@0: while ~feof(fid) b@0: lin=fgetl(fid); b@0: [l,COUNT,ERRMSG,NEXTINDEX] = sscanf(lin,'%s',inf); b@0: if ((~isempty(l)) & (l(1)~='%') & (l(1)~='*')) b@0: if l(1)=='#' b@0: break; b@0: end b@0: [direc,COUNT,ERRMSG,NEXTINDEX] = sscanf(lin,'%s',1); b@0: if strcmp(upper(direc),'DIRECTORY:'); b@0: pathName=lin(NEXTINDEX+1:end); b@0: else b@0: nbSnd=nbSnd+1; b@0: [ind,COUNT,ERRMSG,NEXTINDEX] = sscanf(lin,'%d',1); b@0: if isempty(ind) b@0: index(nbSnd)=0; b@0: else b@0: index(nbSnd)=ind; b@0: end b@0: end b@0: end b@0: end b@0: b@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% b@0: % create the index list and snd list b@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% b@0: b@0: frewind(fid); b@0: b@0: sndName=''; b@0: pathName=''; b@0: newIndex(nbSnd)=0; b@0: index1=find(index~=0); b@0: newIndex(index(index1))=index(index1); b@0: emptyPlaces=find(newIndex==0); b@0: nbL=0; b@0: b@0: while ~feof(fid) b@0: lin=fgetl(fid); b@0: [l,COUNT,ERRMSG,NEXTINDEX] = sscanf(lin,'%s',inf); b@0: if ((~isempty(l)) & (l(1)~='%') & (l(1)~='*')) b@0: [direc,COUNT,ERRMSG,NEXTINDEX] = sscanf(lin,'%s',1); b@0: if strcmp(upper(direc),'DIRECTORY:'); b@0: pathName=lin(NEXTINDEX+1:end); b@0: else b@0: nbL=nbL+1; b@0: [name,COUNT,ERRMSG,NEXTINDEX] = sscanf(lin,'%s',1); b@0: [vol,COUNT,ERRMSG,NEXTINDEX] = sscanf(lin(NEXTINDEX+2:end),'%f',1); b@0: % if isempty(inde) b@0: % inde=emptyPlaces(1); b@0: % if length(emptyPlaces)~=1 b@0: % emptyPlaces=emptyPlaces(2:end); b@0: % end b@0: % end b@0: % if isempty(vol) b@0: % vol=1; b@0: % end b@0: sndName{nbL}=name; b@0: sndPath{nbL}=pathName; b@0: sndVol{nbL}=vol; b@0: end b@0: end b@0: end b@0: b@0: if RANDO b@0: newSort=randperm(nbSnd); b@0: end b@0: b@0: for nooSnd=1:nbSnd b@0: if RANDO b@0: noSnd=newSort(nooSnd); b@0: else b@0: noSnd=nooSnd; b@0: end b@0: b@0: if DOWNLOAD b@0: [snd(noSnd).vect,snd(noSnd).fs]=wavread([pathName sndName{nooSnd}]); b@0: else b@0: snd(noSnd).vect=''; b@0: snd(noSnd).fs=''; b@0: end b@0: snd(noSnd).name=strtok(sndName{nooSnd},'.'); b@0: snd(noSnd).path=sndPath{nooSnd}; b@0: snd(noSnd).listFile=listFile; b@0: snd(noSnd).vol=sndVol{nooSnd}; b@0: end b@0: b@0: fclose(fid);