1 ## Copyright (C) 1995-2012 John W. Eaton
3 ## This file is part of Octave.
5 ## Octave is free software; you can redistribute it and/or modify it
6 ## under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
10 ## Octave is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ## General Public License for more details.
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>.
20 ## @deftypefn {Function File} {} loadaudio (@var{name}, @var{ext}, @var{bps})
21 ## Load audio data from the file @file{@var{name}.@var{ext}} into the
24 ## The extension @var{ext} determines how the data in the audio file is
25 ## interpreted; the extensions @file{lin} (default) and @file{raw}
26 ## correspond to linear, the extensions @file{au}, @file{mu}, or @file{snd}
27 ## to mu-law encoding.
29 ## The argument @var{bps} can be either 8 (default) or 16, and specifies
30 ## the number of bits per sample used in the audio file.
31 ## @seealso{lin2mu, mu2lin, saveaudio, playaudio, setaudio, record}
35 ## Author: AW <Andreas.Weingessel@ci.tuwien.ac.at>
36 ## Created: 10 April 1994
39 function X = loadaudio (name, ext, bps)
41 if (nargin == 0 || nargin > 3)
51 elseif (bps != 8 && bps != 16)
52 error ("loadaudio: BPS must be either 8 or 16");
55 name = [name, ".", ext];
56 num = fopen (name, "rb");
58 if (strcmp (ext, "lin") || strcmp (ext, "raw") || strcmp (ext, "pcm"))
60 [Y, c] = fread (num, inf, "uchar");
63 [X, c] = fread (num, inf, "short");
65 elseif (strcmp (ext, "mu") || strcmp (ext, "au")
66 || strcmp (ext, "snd") || strcmp(ext, "ul"))
67 [Y, c] = fread (num, inf, "uchar");
69 m = find (Y(1:64) == 0, 1, "last");
76 error ("loadaudio: unsupported extension");