2847
|
1 ## Copyright (C) 1996, 1997 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 |
|
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. |
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. |
|
26 ## @end deftypefn |
|
27 |
|
28 ## See also: lin2mu, mu2lin, loadaudio, saveaudio, playaudio, setaudio |
|
29 |
2311
|
30 ## usage: X = record (sec [, sampling_rate]) |
|
31 ## |
|
32 ## Records sec seconds of audio into the vector X. |
|
33 ## The default value for the sampling_rate is 8000, ie. 8kHz. |
|
34 ## The program waits for you to hit the ENTER key, then the recording |
|
35 ## starts immediatly. |
1636
|
36 |
2312
|
37 ## Author: AW <Andreas.Weingessel@ci.tuwien.ac.at> |
|
38 ## Created: 19 September 1994 |
|
39 ## Adapted-By: jwe |
1636
|
40 |
2312
|
41 function X = record (sec, sampling_rate) |
1636
|
42 |
|
43 if (nargin == 1) |
|
44 sampling_rate = 8000; |
|
45 elseif (nargin != 2) |
|
46 usage ("X = record (sec [, sampling_rate])"); |
|
47 endif |
|
48 |
2458
|
49 unwind_protect |
|
50 |
|
51 file = tmpnam (); |
1636
|
52 |
2458
|
53 input ("Please hit ENTER and speak afterwards!\n", 1); |
1636
|
54 |
2458
|
55 cmd = sprintf ("dd if=/dev/dsp of=%s bs=%d count=%d", |
|
56 file, sampling_rate, sec) |
|
57 |
|
58 system (cmd); |
1636
|
59 |
3167
|
60 num = fopen (file, "rb"); |
1636
|
61 |
2458
|
62 [Y, c] = fread (num, sampling_rate * sec, "uchar"); |
|
63 |
|
64 fclose (num); |
1636
|
65 |
2458
|
66 unwind_protect_cleanup |
1636
|
67 |
2458
|
68 unlink (file); |
1636
|
69 |
2458
|
70 end_unwind_protect |
1636
|
71 |
|
72 X = Y - 127; |
|
73 |
|
74 endfunction |