samer@43: % sndfile - audio signal from audio file samer@0: % samer@0: % sndfile :: samer@43: % path | cell { nonneg, nonneg, path } ~'file name or { start, end, path }' samer@0: % options { samer@43: % enc :: {'mp3','aac','flac','ogg'}; samer@0: % channels :: natural/nan ~'desired number of channels'; samer@0: % rate :: nonneg/nan ~'desired sampling rate'; samer@0: % bits :: natural/16 ~'desired bits per sample'; samer@0: % } samer@0: % -> signal(C,R). samer@0: % samer@43: % This will use mp3file, aacfile or flacfile for those types of file, but jsndfile samer@43: % for anything else, including OGG files. samer@43: % samer@0: % If channels or rate are not nan, audio format will be converted to match. samer@0: % If either of them are nan, the corresponding value from the audio file will samer@0: % be left unchanged. samer@43: samer@0: function s=sndfile(file,varargin) samer@43: opts=options('enc','unknown',varargin{:}); samer@42: if iscell(file) samer@42: s=taket(file{2}-file{1},dropt(file{1},sndfile(file{3}))) samer@42: return samer@42: end samer@0: string=sprintf('sndfile(''%s'')',file); samer@43: if strcmp(opts.enc,'mp3') || endswith(file,'mp3') || endswith(file,'MP3') samer@43: s=mp3file(file,'stringfn',@()string,opts); % Java version doesn't remove padding correctly samer@43: elseif strcmp(opts.enc,'aac') || endswith(file,'m4a') samer@43: s=aacfile(file,'stringfn',@()string,opts); samer@43: elseif strcmp(opts.enc,'flac') || endswith(file,'flac') samer@43: s=flacfile(file,'stringfn',@()string,opts); samer@0: else samer@43: s=jsndfile(file,varargin{:}); samer@0: end samer@0: end samer@0: