0
|
1 ## Copyright (C) 1999 Paul Kienzle |
|
2 ## |
|
3 ## This program is free software; you can redistribute it and/or modify |
|
4 ## it under the terms of the GNU General Public License as published by |
|
5 ## the Free Software Foundation; either version 2 of the License, or |
|
6 ## (at your option) any later version. |
|
7 ## |
|
8 ## This program is distributed in the hope that it will be useful, |
|
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 ## GNU General Public License for more details. |
|
12 ## |
|
13 ## You should have received a copy of the GNU General Public License |
|
14 ## along with this program; if not, write to the Free Software |
|
15 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
16 |
|
17 ## usage: [x, fs] = aurecord(t, fs, channels) |
|
18 ## |
|
19 ## Record for the specified time at the given sample rate. Note that |
|
20 ## the sample rate used may not match the requested sample rate. Use |
|
21 ## the returned rate instead of the requested value in further |
|
22 ## processing. Similarly, the actual number of samples and channels |
|
23 ## may not match the request, so check the size of the returned matrix. |
|
24 ## |
|
25 ## Fs defaults to 8000 Hz and channels defaults to 1. Time is measured |
|
26 ## in seconds. |
|
27 |
|
28 ## TODO: Consider converting into record.m |
|
29 ## TODO: Consider making this a .oct file, incorporating aurecord.cc |
|
30 ## TODO: Consider using aurecord_command='record %s', and read signal from /tmp/blah.wav |
|
31 function [data, rate] = aurecord(time, rate, channels) |
|
32 |
|
33 if nargin<1 || nargin>3 |
|
34 usage("[x, fs] = aurecord(t [, fs, channels])"); |
|
35 end |
|
36 if nargin<2, rate = 8000; end; |
|
37 if nargin<3, channels = 1; end; |
|
38 |
|
39 fid=popen(sprintf("aurecord -r %d -c %d -t %f", rate, channels, \ |
|
40 time), "r"); |
|
41 rate = fread(fid, 1, 'long'); |
|
42 channels = fread(fid, 1, 'long'); |
|
43 if channels == 0 |
|
44 pclose(fid); |
|
45 error("aurecord failed -- perhaps audio device is in use?\n"); |
|
46 end; |
|
47 data = fread(fid, Inf, 'short'); |
|
48 if size(data,1) > 0 |
|
49 data = reshape(data'/32768, length(data)/channels, channels); |
|
50 end |
|
51 end |