2303
|
1 ### Copyright (C) 1996 John W. Eaton |
|
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 |
|
7 ### the Free Software Foundation; either version 2, or (at your option) |
|
8 ### any later version. |
|
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 |
|
16 ### along with Octave; see the file COPYING. If not, write to the Free |
|
17 ### Software Foundation, 59 Temple Place - Suite 330, Boston, MA |
|
18 ### 02111-1307, USA. |
|
19 |
1636
|
20 function X = loadaudio (name, ext, bit) |
|
21 |
2303
|
22 ## usage: X = loadaudio (name [, ext [, bit]]) |
|
23 ## |
|
24 ## Loads audio data from the file "name.ext" into the data vector X. |
|
25 ## Default value for the "ext" argument, which has to be written |
|
26 ## without the initial ".", is "lin". |
|
27 ## Currently, the following audio formats are supported: |
|
28 ## *) mu-law encoding with extension "mu", "au" or "snd" |
|
29 ## *) linear encoding with extension "lin" or "raw" |
|
30 ## |
|
31 ## The `bit' argument can be either 8 (default) or 16. |
|
32 ## Depending on the value of bit, linearly encoded files are |
|
33 ## interpreted as being in 8 and 16 bit format, respectively, and |
|
34 ## mu-law encoded files are transformed to 8 and 16-bit linear |
|
35 ## format, respectively. |
1636
|
36 |
2303
|
37 ## Written by AW (Andreas.Weingessel@ci.tuwien.ac.at) on Apr 10, 1994 |
|
38 ## Last modified by AW on Oct 29, 1994 |
1636
|
39 |
|
40 if (nargin == 0 || nargin > 3) |
|
41 usage ("loadaudio (name [, ext [, bit]])"); |
|
42 endif |
|
43 |
|
44 if (nargin == 1) |
|
45 ext = "lin"; |
|
46 endif |
|
47 |
|
48 if (nargin < 3) |
|
49 bit = 8; |
|
50 elseif (bit != 8 && bit != 16) |
|
51 error ("loadaudio: bit must be either 8 or 16"); |
|
52 endif |
|
53 |
|
54 name = [name, ".", ext]; |
|
55 num = fopen (name, "r"); |
|
56 |
|
57 if (strcmp (ext, "lin") || strcmp (ext, "raw")) |
|
58 if (bit == 8) |
|
59 [Y, c] = fread (num, inf, "uchar"); |
|
60 X = Y - 127; |
|
61 else |
|
62 [X, c] = fread (num, inf, "short"); |
|
63 endif |
|
64 elseif (strcmp (ext, "mu") || strcmp (ext, "au") || strcmp (ext, "snd")) |
|
65 [Y, c] = fread (num, inf, "uchar"); |
2303
|
66 ## remove file header |
1636
|
67 m = max (find (Y(1:64) == 0)); |
|
68 if (! isempty (m)) |
|
69 Y(1:m) = []; |
|
70 endif |
|
71 X = mu2lin (Y, bit); |
|
72 else |
|
73 fclose (num); |
|
74 error ("loadaudio does not support given extension"); |
|
75 endif |
|
76 |
|
77 fclose (num); |
|
78 |
|
79 endfunction |
|
80 |
|
81 |
|
82 |