7017
|
1 ## Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2003, 2004, 2005, |
|
2 ## 2006, 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} {} record (@var{sec}, @var{sampling_rate}) |
|
22 ## Records @var{sec} seconds of audio input into the vector @var{x}. The |
|
23 ## default value for @var{sampling_rate} is 8000 samples per second, or |
|
24 ## 8kHz. The program waits until the user types @key{RET} and then |
|
25 ## immediately starts to record. |
5642
|
26 ## @seealso{lin2mu, mu2lin, loadaudio, saveaudio, playaudio, setaudio} |
3332
|
27 ## @end deftypefn |
|
28 |
2312
|
29 ## Author: AW <Andreas.Weingessel@ci.tuwien.ac.at> |
|
30 ## Created: 19 September 1994 |
|
31 ## Adapted-By: jwe |
1636
|
32 |
2312
|
33 function X = record (sec, sampling_rate) |
1636
|
34 |
|
35 if (nargin == 1) |
|
36 sampling_rate = 8000; |
|
37 elseif (nargin != 2) |
6046
|
38 print_usage (); |
1636
|
39 endif |
|
40 |
2458
|
41 unwind_protect |
|
42 |
|
43 file = tmpnam (); |
1636
|
44 |
2458
|
45 input ("Please hit ENTER and speak afterwards!\n", 1); |
1636
|
46 |
4469
|
47 cmd = sprintf ("dd if=/dev/dsp of=\"%s\" bs=%d count=%d", |
2458
|
48 file, sampling_rate, sec) |
|
49 |
|
50 system (cmd); |
1636
|
51 |
3167
|
52 num = fopen (file, "rb"); |
1636
|
53 |
2458
|
54 [Y, c] = fread (num, sampling_rate * sec, "uchar"); |
|
55 |
|
56 fclose (num); |
1636
|
57 |
2458
|
58 unwind_protect_cleanup |
1636
|
59 |
2458
|
60 unlink (file); |
1636
|
61 |
2458
|
62 end_unwind_protect |
1636
|
63 |
|
64 X = Y - 127; |
|
65 |
|
66 endfunction |