Mercurial > hg > octave-lyh
annotate scripts/audio/loadaudio.m @ 10793:be55736a0783
Grammarcheck the documentation from m-files.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Sun, 18 Jul 2010 20:35:16 -0700 |
parents | d1978e7364ad |
children | c776f063fefe |
rev | line source |
---|---|
7017 | 1 ## Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2004, 2005, 2006, |
2 ## 2007 John W. Eaton | |
2313 | 3 ## |
4 ## This file is part of Octave. | |
5 ## | |
6 ## Octave is free software; you can redistribute it and/or modify it | |
7 ## under the terms of the GNU General Public License as published by | |
7016 | 8 ## the Free Software Foundation; either version 3 of the License, or (at |
9 ## your option) any later version. | |
2313 | 10 ## |
11 ## Octave is distributed in the hope that it will be useful, but | |
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 ## General Public License for more details. | |
15 ## | |
16 ## You should have received a copy of the GNU General Public License | |
7016 | 17 ## along with Octave; see the file COPYING. If not, see |
18 ## <http://www.gnu.org/licenses/>. | |
2303 | 19 |
3332 | 20 ## -*- texinfo -*- |
21 ## @deftypefn {Function File} {} loadaudio (@var{name}, @var{ext}, @var{bps}) | |
22 ## Loads audio data from the file @file{@var{name}.@var{ext}} into the | |
3426 | 23 ## vector @var{x}. |
2311 | 24 ## |
3332 | 25 ## The extension @var{ext} determines how the data in the audio file is |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10635
diff
changeset
|
26 ## interpreted; the extensions @file{lin} (default) and @file{raw} |
3332 | 27 ## correspond to linear, the extensions @file{au}, @file{mu}, or @file{snd} |
28 ## to mu-law encoding. | |
3426 | 29 ## |
3332 | 30 ## The argument @var{bps} can be either 8 (default) or 16, and specifies |
31 ## the number of bits per sample used in the audio file. | |
5642 | 32 ## @seealso{lin2mu, mu2lin, saveaudio, playaudio, setaudio, record} |
3332 | 33 ## @end deftypefn |
5642 | 34 |
2311 | 35 |
2312 | 36 ## Author: AW <Andreas.Weingessel@ci.tuwien.ac.at> |
37 ## Created: 10 April 1994 | |
38 ## Adapted-By: jwe | |
39 | |
1636 | 40 function X = loadaudio (name, ext, bit) |
2325 | 41 |
1636 | 42 if (nargin == 0 || nargin > 3) |
6046 | 43 print_usage (); |
1636 | 44 endif |
45 | |
46 if (nargin == 1) | |
47 ext = "lin"; | |
48 endif | |
49 | |
50 if (nargin < 3) | |
51 bit = 8; | |
52 elseif (bit != 8 && bit != 16) | |
53 error ("loadaudio: bit must be either 8 or 16"); | |
54 endif | |
55 | |
56 name = [name, ".", ext]; | |
3167 | 57 num = fopen (name, "rb"); |
1636 | 58 |
3167 | 59 if (strcmp (ext, "lin") || strcmp (ext, "raw") || strcmp (ext, "pcm")) |
1636 | 60 if (bit == 8) |
61 [Y, c] = fread (num, inf, "uchar"); | |
62 X = Y - 127; | |
63 else | |
64 [X, c] = fread (num, inf, "short"); | |
65 endif | |
3471 | 66 elseif (strcmp (ext, "mu") || strcmp (ext, "au") |
10549 | 67 || strcmp (ext, "snd") || strcmp(ext, "ul")) |
1636 | 68 [Y, c] = fread (num, inf, "uchar"); |
2303 | 69 ## remove file header |
6024 | 70 m = find (Y(1:64) == 0, 1, "last"); |
1636 | 71 if (! isempty (m)) |
72 Y(1:m) = []; | |
73 endif | |
74 X = mu2lin (Y, bit); | |
75 else | |
76 fclose (num); | |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
77 error ("loadaudio: unsupported extension"); |
1636 | 78 endif |
79 | |
80 fclose (num); | |
2325 | 81 |
1636 | 82 endfunction |