samer@43
|
1 % sndfile - audio signal from audio file
|
samer@0
|
2 %
|
samer@0
|
3 % sndfile ::
|
samer@43
|
4 % path | cell { nonneg, nonneg, path } ~'file name or { start, end, path }'
|
samer@0
|
5 % options {
|
samer@43
|
6 % enc :: {'mp3','aac','flac','ogg'};
|
samer@0
|
7 % channels :: natural/nan ~'desired number of channels';
|
samer@0
|
8 % rate :: nonneg/nan ~'desired sampling rate';
|
samer@0
|
9 % bits :: natural/16 ~'desired bits per sample';
|
samer@0
|
10 % }
|
samer@0
|
11 % -> signal(C,R).
|
samer@0
|
12 %
|
samer@43
|
13 % This will use mp3file, aacfile or flacfile for those types of file, but jsndfile
|
samer@43
|
14 % for anything else, including OGG files.
|
samer@43
|
15 %
|
samer@0
|
16 % If channels or rate are not nan, audio format will be converted to match.
|
samer@0
|
17 % If either of them are nan, the corresponding value from the audio file will
|
samer@0
|
18 % be left unchanged.
|
samer@43
|
19
|
samer@0
|
20 function s=sndfile(file,varargin)
|
samer@43
|
21 opts=options('enc','unknown',varargin{:});
|
samer@42
|
22 if iscell(file)
|
samer@42
|
23 s=taket(file{2}-file{1},dropt(file{1},sndfile(file{3})))
|
samer@42
|
24 return
|
samer@42
|
25 end
|
samer@0
|
26 string=sprintf('sndfile(''%s'')',file);
|
samer@43
|
27 if strcmp(opts.enc,'mp3') || endswith(file,'mp3') || endswith(file,'MP3')
|
samer@43
|
28 s=mp3file(file,'stringfn',@()string,opts); % Java version doesn't remove padding correctly
|
samer@43
|
29 elseif strcmp(opts.enc,'aac') || endswith(file,'m4a')
|
samer@43
|
30 s=aacfile(file,'stringfn',@()string,opts);
|
samer@43
|
31 elseif strcmp(opts.enc,'flac') || endswith(file,'flac')
|
samer@43
|
32 s=flacfile(file,'stringfn',@()string,opts);
|
samer@0
|
33 else
|
samer@43
|
34 s=jsndfile(file,varargin{:});
|
samer@0
|
35 end
|
samer@0
|
36 end
|
samer@0
|
37
|