b@0
|
1 function [snd,listFile,index]=readSndList(listFile,DOWNLOAD,RANDO)
|
b@0
|
2
|
b@0
|
3 % readSndList(listFile,DOWNLOAD,RANDO) = [snd,listFile,index]
|
b@0
|
4 %
|
b@0
|
5 % listFile : name of the ASCII file where all sounds are listed
|
b@0
|
6 % DOWNLOAD (0) : load sounds in memory? (1)
|
b@0
|
7 % RANDO (0) : sort sounds files in random order? (1)
|
b@0
|
8 %
|
b@0
|
9 % A soundlist consists in different .wav files name contained in an ASCII file (.txt) preceeded by an index
|
b@0
|
10 % - The first line may contain the path for searching all the files or a blank line
|
b@0
|
11 % - the ouput is a structure:
|
b@0
|
12 % snd(noSnd)
|
b@0
|
13 % .vect
|
b@0
|
14 % .fs
|
b@0
|
15 % .name
|
b@0
|
16 % .path
|
b@0
|
17 %
|
b@0
|
18 %
|
b@0
|
19 % if % or * are present, the lines are not taken into account
|
b@0
|
20 % if # at beginnning stop the sound list load...
|
b@0
|
21 % you can also put an index in front of each sounds
|
b@0
|
22 %
|
b@0
|
23 % note on directories:
|
b@0
|
24 % DIRECTORY: c:\dir1\ for PC
|
b@0
|
25 % DIRECTORY: hardisk:dir1: for MAC
|
b@0
|
26 %
|
b@0
|
27 % cf. makeSndList, playSndList
|
b@0
|
28
|
b@0
|
29 checkin('listFile',[]);
|
b@0
|
30 checkin('DOWNLOAD',0);
|
b@0
|
31 checkin('RANDO',0);
|
b@0
|
32
|
b@0
|
33 if isempty(listFile)
|
b@0
|
34 [name,pathname]=uigetfile('*.txt','Sound list?');
|
b@0
|
35 if name==0
|
b@0
|
36 return;
|
b@0
|
37 end
|
b@0
|
38 listFile=name;
|
b@0
|
39 else
|
b@0
|
40 pathname=''; % current directory
|
b@0
|
41 name=listFile;
|
b@0
|
42 end
|
b@0
|
43
|
b@0
|
44 fid=fopen([pathname name],'r');
|
b@0
|
45 [pathname name] % DEBUG
|
b@0
|
46
|
b@0
|
47 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
b@0
|
48 % count the number of sound files and save the index list
|
b@0
|
49 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
b@0
|
50 index=[];
|
b@0
|
51 nbSnd=0;
|
b@0
|
52 while ~feof(fid)
|
b@0
|
53 lin=fgetl(fid);
|
b@0
|
54 [l,COUNT,ERRMSG,NEXTINDEX] = sscanf(lin,'%s',inf);
|
b@0
|
55 if ((~isempty(l)) & (l(1)~='%') & (l(1)~='*'))
|
b@0
|
56 if l(1)=='#'
|
b@0
|
57 break;
|
b@0
|
58 end
|
b@0
|
59 [direc,COUNT,ERRMSG,NEXTINDEX] = sscanf(lin,'%s',1);
|
b@0
|
60 if strcmp(upper(direc),'DIRECTORY:');
|
b@0
|
61 pathName=lin(NEXTINDEX+1:end);
|
b@0
|
62 else
|
b@0
|
63 nbSnd=nbSnd+1;
|
b@0
|
64 [ind,COUNT,ERRMSG,NEXTINDEX] = sscanf(lin,'%d',1);
|
b@0
|
65 if isempty(ind)
|
b@0
|
66 index(nbSnd)=0;
|
b@0
|
67 else
|
b@0
|
68 index(nbSnd)=ind;
|
b@0
|
69 end
|
b@0
|
70 end
|
b@0
|
71 end
|
b@0
|
72 end
|
b@0
|
73
|
b@0
|
74 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
b@0
|
75 % create the index list and snd list
|
b@0
|
76 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
b@0
|
77
|
b@0
|
78 frewind(fid);
|
b@0
|
79
|
b@0
|
80 sndName='';
|
b@0
|
81 pathName='';
|
b@0
|
82 newIndex(nbSnd)=0;
|
b@0
|
83 index1=find(index~=0);
|
b@0
|
84 newIndex(index(index1))=index(index1);
|
b@0
|
85 emptyPlaces=find(newIndex==0);
|
b@0
|
86 nbL=0;
|
b@0
|
87
|
b@0
|
88 while ~feof(fid)
|
b@0
|
89 lin=fgetl(fid);
|
b@0
|
90 [l,COUNT,ERRMSG,NEXTINDEX] = sscanf(lin,'%s',inf);
|
b@0
|
91 if ((~isempty(l)) & (l(1)~='%') & (l(1)~='*'))
|
b@0
|
92 [direc,COUNT,ERRMSG,NEXTINDEX] = sscanf(lin,'%s',1);
|
b@0
|
93 if strcmp(upper(direc),'DIRECTORY:');
|
b@0
|
94 pathName=lin(NEXTINDEX+1:end);
|
b@0
|
95 else
|
b@0
|
96 nbL=nbL+1;
|
b@0
|
97 [name,COUNT,ERRMSG,NEXTINDEX] = sscanf(lin,'%s',1);
|
b@0
|
98 [vol,COUNT,ERRMSG,NEXTINDEX] = sscanf(lin(NEXTINDEX+2:end),'%f',1);
|
b@0
|
99 % if isempty(inde)
|
b@0
|
100 % inde=emptyPlaces(1);
|
b@0
|
101 % if length(emptyPlaces)~=1
|
b@0
|
102 % emptyPlaces=emptyPlaces(2:end);
|
b@0
|
103 % end
|
b@0
|
104 % end
|
b@0
|
105 % if isempty(vol)
|
b@0
|
106 % vol=1;
|
b@0
|
107 % end
|
b@0
|
108 sndName{nbL}=name;
|
b@0
|
109 sndPath{nbL}=pathName;
|
b@0
|
110 sndVol{nbL}=vol;
|
b@0
|
111 end
|
b@0
|
112 end
|
b@0
|
113 end
|
b@0
|
114
|
b@0
|
115 if RANDO
|
b@0
|
116 newSort=randperm(nbSnd);
|
b@0
|
117 end
|
b@0
|
118
|
b@0
|
119 for nooSnd=1:nbSnd
|
b@0
|
120 if RANDO
|
b@0
|
121 noSnd=newSort(nooSnd);
|
b@0
|
122 else
|
b@0
|
123 noSnd=nooSnd;
|
b@0
|
124 end
|
b@0
|
125
|
b@0
|
126 if DOWNLOAD
|
b@0
|
127 [snd(noSnd).vect,snd(noSnd).fs]=wavread([pathName sndName{nooSnd}]);
|
b@0
|
128 else
|
b@0
|
129 snd(noSnd).vect='';
|
b@0
|
130 snd(noSnd).fs='';
|
b@0
|
131 end
|
b@0
|
132 snd(noSnd).name=strtok(sndName{nooSnd},'.');
|
b@0
|
133 snd(noSnd).path=sndPath{nooSnd};
|
b@0
|
134 snd(noSnd).listFile=listFile;
|
b@0
|
135 snd(noSnd).vol=sndVol{nooSnd};
|
b@0
|
136 end
|
b@0
|
137
|
b@0
|
138 fclose(fid); |