wolffd@0: function [d,tp,fp,f,b,n,ch] = mirread(extract,orig,load,folder,verbose) wolffd@0: % Read the audio file ORIG, at temporal position indicated by EXTRACT. If wolffd@0: % EXTRACT is empty, all the audio file is loaded. wolffd@0: % If LOAD is set to 0, just the meta-data is collected, and the actual wolffd@0: % audio data is not taken into consideration. If it is set to 1, the wolffd@0: % data are loaded from the current directory. If LOAD is a string, it wolffd@0: % is considered as the path of the directory. wolffd@0: % If FOLDER is set to 1, no error is returned if an audio file cannot be wolffd@0: % loaded. wolffd@0: % Output: wolffd@0: % D is the audio signal, wolffd@0: % TP are the temporal positions, wolffd@0: % FP are the two extreme temporal positions (used for frame positions), wolffd@0: % F is the sampling rate, wolffd@0: % B is the resolution in number of bits, wolffd@0: % N is the file name. wolffd@0: % CH are the channel index. wolffd@0: wolffd@0: if nargin < 5 wolffd@0: verbose = 0; wolffd@0: end wolffd@0: d = {}; wolffd@0: f = {}; wolffd@0: b = {}; wolffd@0: tp = {}; wolffd@0: fp = {}; wolffd@0: n = {}; wolffd@0: ch = {}; wolffd@0: try wolffd@0: [d,f,b,tp,fp,n,ch] = audioread(extract,@wavread,orig,load,verbose,folder); wolffd@0: catch wolffd@0: err.wav = lasterr; wolffd@0: try wolffd@0: [d,f,b,tp,fp,n,ch] = audioread(extract,@auread,orig,load,verbose,folder); wolffd@0: catch wolffd@0: err.au = lasterr; wolffd@0: try wolffd@0: [d,f,b,tp,fp,n,ch] = audioread(extract,@mp3read,orig,load,verbose,folder); wolffd@0: catch wolffd@0: err.mp3 = lasterr; wolffd@0: try wolffd@0: [d,f,b,tp,fp,n,ch] = audioread(extract,@aiffread,orig,load,verbose,folder); wolffd@0: catch wolffd@0: err.aiff = lasterr; wolffd@0: if length(orig)>4 && strcmpi(orig(end-3:end),'.bdf') wolffd@0: try wolffd@0: [d,f,b,tp,fp,n,ch] = audioread(extract,@bdfread,orig,load,verbose,folder); wolffd@0: catch wolffd@0: if not(strcmp(err.wav(1:16),'Error using ==> ') && folder) wolffd@0: misread(orig, err); wolffd@0: end wolffd@0: end wolffd@0: else wolffd@0: if not(strcmp(err.wav(1:16),'Error using ==> ') && folder) wolffd@0: misread(orig, err); wolffd@0: end wolffd@0: end wolffd@0: end wolffd@0: end wolffd@0: end wolffd@0: end wolffd@0: wolffd@0: wolffd@0: function [d,f,b,tp,fp,n,ch] = audioread(extract,reader,file,load,verbose,folder) wolffd@0: n = file; wolffd@0: if folder wolffd@0: file = ['./',file]; wolffd@0: end wolffd@0: if load wolffd@0: if isempty(extract) wolffd@0: [s,f,b] = reader(file); wolffd@0: else wolffd@0: [unused,f,b] = reader(file,1); wolffd@0: s = reader(file,extract(1:2)); wolffd@0: if length(extract) > 3 wolffd@0: s = s(:,extract(4)); wolffd@0: end wolffd@0: end wolffd@0: if verbose wolffd@0: disp([file,' loaded.']); wolffd@0: end wolffd@0: d{1} = reshape(s,size(s,1),1,size(s,2)); %channels along dim 3 wolffd@0: ch = 1:size(s,2); wolffd@0: if isempty(extract) || extract(3) wolffd@0: tp{1} = (0:size(s,1)-1)'/f; wolffd@0: else wolffd@0: tp{1} = (extract(1)-1+(0:size(s,1)-1))'/f; wolffd@0: end wolffd@0: if isempty(s) wolffd@0: fp{1} = 0; wolffd@0: else wolffd@0: fp{1} = tp{1}([1 end]); wolffd@0: end wolffd@0: else wolffd@0: [unused,f,b] = reader(file,1); wolffd@0: dsize = reader(file,'size'); wolffd@0: d = dsize(1); wolffd@0: tp = {}; wolffd@0: fp = {}; wolffd@0: ch = dsize(2); wolffd@0: end wolffd@0: wolffd@0: wolffd@0: function [y,fs,nbits] = bdfread(file,check) wolffd@0: DAT = openbdf(file); wolffd@0: NRec = DAT.Head.NRec; wolffd@0: if not(length(check)==2) wolffd@0: b = readbdf(DAT,1); wolffd@0: y = length(b.Record(43,:)) * NRec; wolffd@0: else wolffd@0: y = []; wolffd@0: if mirwaitbar wolffd@0: handle = waitbar(0,'Loading BDF channel...'); wolffd@0: else wolffd@0: handle = 0; wolffd@0: end wolffd@0: for i = 1:NRec wolffd@0: b = readbdf(DAT,i); wolffd@0: y = [y;b.Record(43,:)']; wolffd@0: if handle wolffd@0: waitbar(i/NRec,handle); wolffd@0: end wolffd@0: end wolffd@0: if handle wolffd@0: delete(handle) wolffd@0: end wolffd@0: end wolffd@0: fs = DAT.Head.SampleRate(43); wolffd@0: nbits = NaN; wolffd@0: wolffd@0: wolffd@0: function misread(file,err) wolffd@0: display('Here are the error message returned by each reader:'); wolffd@0: display(err.wav); wolffd@0: display(err.au); wolffd@0: display(err.mp3); wolffd@0: display(err.aiff); wolffd@0: mirerror('MIRREAD',['Cannot open file ',file]);