Mercurial > hg > octave-lyh
annotate scripts/audio/loadaudio.m @ 17535:c12c688a35ed default tip lyh
Fix warnings
author | LYH <lyh.kernel@gmail.com> |
---|---|
date | Fri, 27 Sep 2013 17:43:27 +0800 |
parents | 1c89599167a6 |
children |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
12575
diff
changeset
|
1 ## Copyright (C) 1995-2012 John W. Eaton |
2313 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
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 | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
2313 | 9 ## |
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. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
2303 | 18 |
3332 | 19 ## -*- texinfo -*- |
20 ## @deftypefn {Function File} {} loadaudio (@var{name}, @var{ext}, @var{bps}) | |
12575
d0b799dafede
Grammarcheck files for 3.4.1 release.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
21 ## Load audio data from the file @file{@var{name}.@var{ext}} into the |
3426 | 22 ## vector @var{x}. |
2311 | 23 ## |
3332 | 24 ## 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
|
25 ## interpreted; the extensions @file{lin} (default) and @file{raw} |
3332 | 26 ## correspond to linear, the extensions @file{au}, @file{mu}, or @file{snd} |
27 ## to mu-law encoding. | |
3426 | 28 ## |
3332 | 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. | |
5642 | 31 ## @seealso{lin2mu, mu2lin, saveaudio, playaudio, setaudio, record} |
3332 | 32 ## @end deftypefn |
5642 | 33 |
2311 | 34 |
2312 | 35 ## Author: AW <Andreas.Weingessel@ci.tuwien.ac.at> |
36 ## Created: 10 April 1994 | |
37 ## Adapted-By: jwe | |
38 | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
39 function X = loadaudio (name, ext, bps) |
2325 | 40 |
1636 | 41 if (nargin == 0 || nargin > 3) |
6046 | 42 print_usage (); |
1636 | 43 endif |
44 | |
45 if (nargin == 1) | |
46 ext = "lin"; | |
47 endif | |
48 | |
49 if (nargin < 3) | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
50 bps = 8; |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
51 elseif (bps != 8 && bps != 16) |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
11469
diff
changeset
|
52 error ("loadaudio: BPS must be either 8 or 16"); |
1636 | 53 endif |
54 | |
55 name = [name, ".", ext]; | |
3167 | 56 num = fopen (name, "rb"); |
1636 | 57 |
3167 | 58 if (strcmp (ext, "lin") || strcmp (ext, "raw") || strcmp (ext, "pcm")) |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
59 if (bps == 8) |
1636 | 60 [Y, c] = fread (num, inf, "uchar"); |
61 X = Y - 127; | |
62 else | |
63 [X, c] = fread (num, inf, "short"); | |
64 endif | |
3471 | 65 elseif (strcmp (ext, "mu") || strcmp (ext, "au") |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
66 || strcmp (ext, "snd") || strcmp (ext, "ul")) |
1636 | 67 [Y, c] = fread (num, inf, "uchar"); |
2303 | 68 ## remove file header |
6024 | 69 m = find (Y(1:64) == 0, 1, "last"); |
1636 | 70 if (! isempty (m)) |
71 Y(1:m) = []; | |
72 endif | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
73 X = mu2lin (Y, bps); |
1636 | 74 else |
75 fclose (num); | |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
76 error ("loadaudio: unsupported extension"); |
1636 | 77 endif |
78 | |
79 fclose (num); | |
2325 | 80 |
1636 | 81 endfunction |
17346
1c89599167a6
maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
82 |