Mercurial > octave
annotate scripts/audio/record.m @ 31706:597f3ee61a48 stable
update Octave Project Developers copyright for the new year
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 06 Jan 2023 13:11:27 -0500 |
parents | 505ed551e366 |
children | 2e484f9f1f18 |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 ######################################################################## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 ## |
31706
597f3ee61a48
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
31664
diff
changeset
|
3 ## Copyright (C) 1995-2023 The Octave Project Developers |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
4 ## |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 ## See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 ## distribution or <https://octave.org/copyright/>. |
2313 | 7 ## |
8 ## This file is part of Octave. | |
9 ## | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
10 ## Octave is free software: you can redistribute it and/or modify it |
2313 | 11 ## under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
12 ## the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
13 ## (at your option) any later version. |
2313 | 14 ## |
15 ## Octave is distributed in the hope that it will be useful, but | |
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
18 ## GNU General Public License for more details. |
2313 | 19 ## |
20 ## You should have received a copy of the GNU General Public License | |
7016 | 21 ## along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
22 ## <https://www.gnu.org/licenses/>. |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 ## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 ######################################################################## |
2303 | 25 |
3332 | 26 ## -*- texinfo -*- |
31664
505ed551e366
doc: Ensure DOCSTRING has an output when function returns a value (bug #61681)
Rik <rik@octave.org>
parents:
30571
diff
changeset
|
27 ## @deftypefn {} {@var{data} =} record (@var{sec}) |
505ed551e366
doc: Ensure DOCSTRING has an output when function returns a value (bug #61681)
Rik <rik@octave.org>
parents:
30571
diff
changeset
|
28 ## @deftypefnx {} {@var{data} =} record (@var{sec}, @var{fs}) |
19677
0f557da98f5b
record.m: Overhaul function.
Mike Miller <mtmiller@ieee.org>
parents:
19647
diff
changeset
|
29 ## Record @var{sec} seconds of audio from the system's default audio input at |
20158
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
30 ## a sampling rate of 8000 samples per second. |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
31 ## |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
32 ## If the optional argument @var{fs} is given, it specifies the sampling rate |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
33 ## for recording. |
19677
0f557da98f5b
record.m: Overhaul function.
Mike Miller <mtmiller@ieee.org>
parents:
19647
diff
changeset
|
34 ## |
0f557da98f5b
record.m: Overhaul function.
Mike Miller <mtmiller@ieee.org>
parents:
19647
diff
changeset
|
35 ## For more control over audio recording, use the @code{audiorecorder} class. |
30568
82b685157e2b
doc: Update documentation in audio/ directory.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
36 ## @seealso{@audiorecorder/audiorecorder, sound, soundsc} |
3332 | 37 ## @end deftypefn |
38 | |
30571
faf96757915a
record.m, soundsc.m: Small code tweaks for Octave conventions.
Rik <rik@octave.org>
parents:
30568
diff
changeset
|
39 function data = record (sec, fs = 8000) |
1636 | 40 |
28886
d8318c12d903
test: remove unnecessary BIST tests in m-files checking for excessive number of inputs.
Rik <rik@octave.org>
parents:
28789
diff
changeset
|
41 if (nargin < 1) |
6046 | 42 print_usage (); |
1636 | 43 endif |
44 | |
28886
d8318c12d903
test: remove unnecessary BIST tests in m-files checking for excessive number of inputs.
Rik <rik@octave.org>
parents:
28789
diff
changeset
|
45 if (! (isscalar (sec) && sec >= 0)) |
19683
f96671da51a6
record.m: Improve input validation
Mike Miller <mtmiller@ieee.org>
parents:
19680
diff
changeset
|
46 error ("record: recording duration SEC must be a non-negative number"); |
f96671da51a6
record.m: Improve input validation
Mike Miller <mtmiller@ieee.org>
parents:
19680
diff
changeset
|
47 endif |
f96671da51a6
record.m: Improve input validation
Mike Miller <mtmiller@ieee.org>
parents:
19680
diff
changeset
|
48 |
28886
d8318c12d903
test: remove unnecessary BIST tests in m-files checking for excessive number of inputs.
Rik <rik@octave.org>
parents:
28789
diff
changeset
|
49 if (! (isscalar (fs) && fs > 0)) |
19683
f96671da51a6
record.m: Improve input validation
Mike Miller <mtmiller@ieee.org>
parents:
19680
diff
changeset
|
50 error ("record: sample rate FS must be a positive number"); |
f96671da51a6
record.m: Improve input validation
Mike Miller <mtmiller@ieee.org>
parents:
19680
diff
changeset
|
51 endif |
f96671da51a6
record.m: Improve input validation
Mike Miller <mtmiller@ieee.org>
parents:
19680
diff
changeset
|
52 |
30571
faf96757915a
record.m, soundsc.m: Small code tweaks for Octave conventions.
Rik <rik@octave.org>
parents:
30568
diff
changeset
|
53 data = []; |
1636 | 54 |
19683
f96671da51a6
record.m: Improve input validation
Mike Miller <mtmiller@ieee.org>
parents:
19680
diff
changeset
|
55 if (sec > 0) |
f96671da51a6
record.m: Improve input validation
Mike Miller <mtmiller@ieee.org>
parents:
19680
diff
changeset
|
56 rec = audiorecorder (fs, 16, 1); |
1636 | 57 |
19683
f96671da51a6
record.m: Improve input validation
Mike Miller <mtmiller@ieee.org>
parents:
19680
diff
changeset
|
58 recordblocking (rec, sec); |
f96671da51a6
record.m: Improve input validation
Mike Miller <mtmiller@ieee.org>
parents:
19680
diff
changeset
|
59 |
30571
faf96757915a
record.m, soundsc.m: Small code tweaks for Octave conventions.
Rik <rik@octave.org>
parents:
30568
diff
changeset
|
60 data = getaudiodata (rec); |
19683
f96671da51a6
record.m: Improve input validation
Mike Miller <mtmiller@ieee.org>
parents:
19680
diff
changeset
|
61 endif |
1636 | 62 |
63 endfunction | |
17338
1c89599167a6
maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
64 |
19677
0f557da98f5b
record.m: Overhaul function.
Mike Miller <mtmiller@ieee.org>
parents:
19647
diff
changeset
|
65 |
19683
f96671da51a6
record.m: Improve input validation
Mike Miller <mtmiller@ieee.org>
parents:
19680
diff
changeset
|
66 ## Tests of record must not actually record anything. |
f96671da51a6
record.m: Improve input validation
Mike Miller <mtmiller@ieee.org>
parents:
19680
diff
changeset
|
67 %!assert (isempty (record (0))) |
19677
0f557da98f5b
record.m: Overhaul function.
Mike Miller <mtmiller@ieee.org>
parents:
19647
diff
changeset
|
68 |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
69 ## Test input validation |
28886
d8318c12d903
test: remove unnecessary BIST tests in m-files checking for excessive number of inputs.
Rik <rik@octave.org>
parents:
28789
diff
changeset
|
70 %!error <SEC must be a non-negative number> record (ones (2,2)) |
d8318c12d903
test: remove unnecessary BIST tests in m-files checking for excessive number of inputs.
Rik <rik@octave.org>
parents:
28789
diff
changeset
|
71 %!error <SEC must be a non-negative number> record (-1) |
d8318c12d903
test: remove unnecessary BIST tests in m-files checking for excessive number of inputs.
Rik <rik@octave.org>
parents:
28789
diff
changeset
|
72 %!error <FS must be a positive number> record (1, ones (2,2)) |
d8318c12d903
test: remove unnecessary BIST tests in m-files checking for excessive number of inputs.
Rik <rik@octave.org>
parents:
28789
diff
changeset
|
73 %!error <FS must be a positive number> record (1, -1) |