Mercurial > octave
annotate scripts/audio/@audiorecorder/audiorecorder.m @ 30564:796f54d4ddbf stable
update Octave Project Developers copyright for the new year
In files that have the "Octave Project Developers" copyright notice,
update for 2021.
In all .txi and .texi files except gpl.txi and gpl.texi in the
doc/liboctave and doc/interpreter directories, change the copyright
to "Octave Project Developers", the same as used for other source
files. Update copyright notices for 2022 (not done since 2019). For
gpl.txi and gpl.texi, change the copyright notice to be "Free Software
Foundation, Inc." and leave the date at 2007 only because this file
only contains the text of the GPL, not anything created by the Octave
Project Developers.
Add Paul Thomas to contributors.in.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 28 Dec 2021 18:22:40 -0500 |
parents | 01de0045b2e3 |
children | 82b685157e2b |
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 ## |
30564
796f54d4ddbf
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
30330
diff
changeset
|
3 ## Copyright (C) 2013-2022 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/>. |
19500
8bb399569393
Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents:
19497
diff
changeset
|
7 ## |
8bb399569393
Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents:
19497
diff
changeset
|
8 ## This file is part of Octave. |
8bb399569393
Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents:
19497
diff
changeset
|
9 ## |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23361
diff
changeset
|
10 ## Octave is free software: you can redistribute it and/or modify it |
19500
8bb399569393
Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents:
19497
diff
changeset
|
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:
23361
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. |
19500
8bb399569393
Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents:
19497
diff
changeset
|
14 ## |
8bb399569393
Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents:
19497
diff
changeset
|
15 ## Octave is distributed in the hope that it will be useful, but |
8bb399569393
Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents:
19497
diff
changeset
|
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. |
19500
8bb399569393
Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents:
19497
diff
changeset
|
19 ## |
8bb399569393
Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents:
19497
diff
changeset
|
20 ## You should have received a copy of the GNU General Public License |
8bb399569393
Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents:
19497
diff
changeset
|
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:
23361
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 ######################################################################## |
19500
8bb399569393
Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents:
19497
diff
changeset
|
25 |
19476
e1f98e402a7e
New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
26 ## -*- texinfo -*- |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20158
diff
changeset
|
27 ## @deftypefn {} {@var{recorder} =} audiorecorder () |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20158
diff
changeset
|
28 ## @deftypefnx {} {@var{recorder} =} audiorecorder (@var{fs}, @var{nbits}, @var{channels}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20158
diff
changeset
|
29 ## @deftypefnx {} {@var{recorder} =} audiorecorder (@var{fs}, @var{nbits}, @var{channels}, @var{id}) |
19505
ce02743b6f2a
Fix texinfo docstring syntax for all audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19503
diff
changeset
|
30 ## Create an audiorecorder object recording 8 bit mono audio at 8000 Hz |
20158
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
31 ## sample rate. |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
32 ## |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
33 ## The optional arguments @var{fs}, @var{nbits}, @var{channels}, and @var{id} |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
34 ## specify the sample rate, bit depth, number of channels and recording |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
35 ## device id, respectively. Device IDs may be found using the audiodevinfo |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
36 ## function. |
19560
e75df9e43e63
disable Octave audio callback functions
John W. Eaton <jwe@octave.org>
parents:
19528
diff
changeset
|
37 ## @end deftypefn |
e75df9e43e63
disable Octave audio callback functions
John W. Eaton <jwe@octave.org>
parents:
19528
diff
changeset
|
38 |
e75df9e43e63
disable Octave audio callback functions
John W. Eaton <jwe@octave.org>
parents:
19528
diff
changeset
|
39 ## FIXME: callbacks don't work properly, apparently because portaudio |
e75df9e43e63
disable Octave audio callback functions
John W. Eaton <jwe@octave.org>
parents:
19528
diff
changeset
|
40 ## will execute the callbacks in a separate thread, and calling Octave |
e75df9e43e63
disable Octave audio callback functions
John W. Eaton <jwe@octave.org>
parents:
19528
diff
changeset
|
41 ## functions in a separate thread which is likely to cause trouble with |
e75df9e43e63
disable Octave audio callback functions
John W. Eaton <jwe@octave.org>
parents:
19528
diff
changeset
|
42 ## all of Octave's global data... |
e75df9e43e63
disable Octave audio callback functions
John W. Eaton <jwe@octave.org>
parents:
19528
diff
changeset
|
43 ## |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20158
diff
changeset
|
44 ## @deftypefnx {} {@var{recorder} =} audiorecorder (@var{function}, @dots{}) |
19560
e75df9e43e63
disable Octave audio callback functions
John W. Eaton <jwe@octave.org>
parents:
19528
diff
changeset
|
45 ## |
19506
fdb8a62ef17a
fix docstring style in .m files
John W. Eaton <jwe@octave.org>
parents:
19505
diff
changeset
|
46 ## Given a function handle, use that function to process the audio. |
19476
e1f98e402a7e
New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
47 |
e1f98e402a7e
New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
48 function recorder = audiorecorder (varargin) |
19523
5802ea7037d4
style fixes for audioplayer and audiorecorder classes
John W. Eaton <jwe@octave.org>
parents:
19509
diff
changeset
|
49 |
19476
e1f98e402a7e
New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
50 if (nargin > 5) |
e1f98e402a7e
New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
51 print_usage (); |
e1f98e402a7e
New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
52 endif |
19523
5802ea7037d4
style fixes for audioplayer and audiorecorder classes
John W. Eaton <jwe@octave.org>
parents:
19509
diff
changeset
|
53 |
19507
dac3191a5301
style fixes for audioplayer and audiorecorder .m files
John W. Eaton <jwe@octave.org>
parents:
19506
diff
changeset
|
54 if (nargin > 0 && ischar (varargin{1})) |
19503
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19500
diff
changeset
|
55 varargin{1} = str2func (varargin{1}); |
19476
e1f98e402a7e
New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
56 endif |
19523
5802ea7037d4
style fixes for audioplayer and audiorecorder classes
John W. Eaton <jwe@octave.org>
parents:
19509
diff
changeset
|
57 |
19476
e1f98e402a7e
New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
58 recorder.recorder = __recorder_audiorecorder__ (varargin{:}); |
e1f98e402a7e
New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
59 recorder = class (recorder, "audiorecorder"); |
19523
5802ea7037d4
style fixes for audioplayer and audiorecorder classes
John W. Eaton <jwe@octave.org>
parents:
19509
diff
changeset
|
60 |
19476
e1f98e402a7e
New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
61 endfunction |
e1f98e402a7e
New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
62 |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
63 |
19668
b2fe4dbe5266
Don't play or record audio during 'make check'
Mike Miller <mtmiller@ieee.org>
parents:
19575
diff
changeset
|
64 %!demo |
19509 | 65 %! recorder = audiorecorder (44100, 16, 2); |
66 %! record (recorder, 1); | |
20923
58263bea2fdf
Unified "sleep" functions to "octave_sleep" in C++ and "pause" in Octave.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
20852
diff
changeset
|
67 %! pause (2); |
19509 | 68 %! player1 = audioplayer (recorder); |
69 %! player2 = getplayer (recorder); | |
70 %! play (player1); | |
20923
58263bea2fdf
Unified "sleep" functions to "octave_sleep" in C++ and "pause" in Octave.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
20852
diff
changeset
|
71 %! pause (2); |
19509 | 72 %! play (player2); |
20923
58263bea2fdf
Unified "sleep" functions to "octave_sleep" in C++ and "pause" in Octave.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
20852
diff
changeset
|
73 %! pause (2); |
19668
b2fe4dbe5266
Don't play or record audio during 'make check'
Mike Miller <mtmiller@ieee.org>
parents:
19575
diff
changeset
|
74 %! stop (player1); |
b2fe4dbe5266
Don't play or record audio during 'make check'
Mike Miller <mtmiller@ieee.org>
parents:
19575
diff
changeset
|
75 %! stop (player2); |
b2fe4dbe5266
Don't play or record audio during 'make check'
Mike Miller <mtmiller@ieee.org>
parents:
19575
diff
changeset
|
76 |
b2fe4dbe5266
Don't play or record audio during 'make check'
Mike Miller <mtmiller@ieee.org>
parents:
19575
diff
changeset
|
77 ## Tests of audiorecorder must not actually record anything. |
b2fe4dbe5266
Don't play or record audio during 'make check'
Mike Miller <mtmiller@ieee.org>
parents:
19575
diff
changeset
|
78 |
23361
7fbf0d4e48c9
skip some audio tests if no audio devices are available
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
79 %!testif HAVE_PORTAUDIO; audiodevinfo (1) > 0 |
19668
b2fe4dbe5266
Don't play or record audio during 'make check'
Mike Miller <mtmiller@ieee.org>
parents:
19575
diff
changeset
|
80 %! recorder = audiorecorder (44100, 16, 2); |
b2fe4dbe5266
Don't play or record audio during 'make check'
Mike Miller <mtmiller@ieee.org>
parents:
19575
diff
changeset
|
81 %! data = getaudiodata (recorder, "int16"); |
b2fe4dbe5266
Don't play or record audio during 'make check'
Mike Miller <mtmiller@ieee.org>
parents:
19575
diff
changeset
|
82 %! assert (strcmp (class (data), "int16")); |
b2fe4dbe5266
Don't play or record audio during 'make check'
Mike Miller <mtmiller@ieee.org>
parents:
19575
diff
changeset
|
83 %! data = getaudiodata (recorder, "int8"); |
b2fe4dbe5266
Don't play or record audio during 'make check'
Mike Miller <mtmiller@ieee.org>
parents:
19575
diff
changeset
|
84 %! assert (strcmp (class (data), "int8")); |
b2fe4dbe5266
Don't play or record audio during 'make check'
Mike Miller <mtmiller@ieee.org>
parents:
19575
diff
changeset
|
85 %! data = getaudiodata (recorder, "uint8"); |
b2fe4dbe5266
Don't play or record audio during 'make check'
Mike Miller <mtmiller@ieee.org>
parents:
19575
diff
changeset
|
86 %! assert (strcmp (class (data), "uint8")); |
b2fe4dbe5266
Don't play or record audio during 'make check'
Mike Miller <mtmiller@ieee.org>
parents:
19575
diff
changeset
|
87 %! assert (size (data)(1), recorder.TotalSamples); |
b2fe4dbe5266
Don't play or record audio during 'make check'
Mike Miller <mtmiller@ieee.org>
parents:
19575
diff
changeset
|
88 %! assert (size (data)(2), 2); |
19476
e1f98e402a7e
New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
89 |
23361
7fbf0d4e48c9
skip some audio tests if no audio devices are available
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
90 %!testif HAVE_PORTAUDIO; audiodevinfo (1) > 0 |
28892
3cac3ceb9629
maint: Use coding style with parentheses after function name to distinguish from a variable.
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
91 %! recorder = audiorecorder (); |
30330
01de0045b2e3
maint: Shorten some long lines to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
92 %! set (recorder, {"SampleRate", "Tag", "UserData"}, |
01de0045b2e3
maint: Shorten some long lines to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
93 %! {8000, "tag", [1, 2; 3, 4]}); |
19509 | 94 %! assert (recorder.SampleRate, 8000); |
95 %! assert (recorder.Tag, "tag"); | |
96 %! assert (recorder.UserData, [1, 2; 3, 4]); | |
19476
e1f98e402a7e
New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
97 |
23361
7fbf0d4e48c9
skip some audio tests if no audio devices are available
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
98 %!testif HAVE_PORTAUDIO; audiodevinfo (1) > 0 |
28892
3cac3ceb9629
maint: Use coding style with parentheses after function name to distinguish from a variable.
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
99 %! recorder = audiorecorder (); |
19509 | 100 %! settable = set (recorder); |
101 %! settable.SampleRate = 8000; | |
102 %! settable.Tag = "tag"; | |
103 %! settable.UserData = [1, 2; 3, 4]; | |
104 %! set (recorder, settable); | |
105 %! assert (recorder.SampleRate, 8000); | |
106 %! assert (recorder.Tag, "tag"); | |
107 %! assert (recorder.UserData, [1, 2; 3, 4]); | |
19476
e1f98e402a7e
New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
108 |
23361
7fbf0d4e48c9
skip some audio tests if no audio devices are available
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
109 %!testif HAVE_PORTAUDIO; audiodevinfo (1) > 0 |
28892
3cac3ceb9629
maint: Use coding style with parentheses after function name to distinguish from a variable.
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
110 %! recorder = audiorecorder (); |
19509 | 111 %! recorder.SampleRate = 8000; |
112 %! recorder.Tag = "tag"; | |
113 %! recorder.UserData = [1, 2; 3, 4]; | |
114 %! properties = get (recorder, {"SampleRate", "Tag", "UserData"}); | |
115 %! assert (properties, {8000, "tag", [1, 2; 3, 4]}); | |
19476
e1f98e402a7e
New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
116 |
e1f98e402a7e
New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
117 #%!function status = callback_record (sound) |
19503
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19500
diff
changeset
|
118 #%! fid = fopen ("record.txt", "at"); |
19476
e1f98e402a7e
New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
119 #%! for index = 1:rows(sound) |
19503
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19500
diff
changeset
|
120 #%! fprintf (fid, "%.4f, %.4f\n", sound(index, 1), sound(index, 2)); |
19476
e1f98e402a7e
New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
121 #%! endfor |
19503
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19500
diff
changeset
|
122 #%! fclose (fid); |
19476
e1f98e402a7e
New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
123 #%! status = 0; |
e1f98e402a7e
New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
124 #%!endfunction |
e1f98e402a7e
New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
125 |
19528
4f615cd9a68d
Use "testif HAVE_PORTAUDIO" for new audio function tests
Andreas Weber <andy.weber.aw@gmail.com>
parents:
19523
diff
changeset
|
126 #%!testif HAVE_PORTAUDIO |
19509 | 127 #%! recorder = audiorecorder (@callback_record, 44100); |
128 #%! unlink ("record.txt") | |
129 #%! record (recorder); | |
20923
58263bea2fdf
Unified "sleep" functions to "octave_sleep" in C++ and "pause" in Octave.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
20852
diff
changeset
|
130 #%! pause (2); |
19575
7f5006dfa2eb
* audiorecorder.m: Fix test.
John W. Eaton <jwe@octave.org>
parents:
19571
diff
changeset
|
131 #%! stop (recorder); |
19509 | 132 #%! s = stat ("record.txt"); |
133 #%! assert (s.size > 0); | |
19476
e1f98e402a7e
New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
134 |
19528
4f615cd9a68d
Use "testif HAVE_PORTAUDIO" for new audio function tests
Andreas Weber <andy.weber.aw@gmail.com>
parents:
19523
diff
changeset
|
135 #%!testif HAVE_PORTAUDIO |
19509 | 136 #%! recorder = audiorecorder (@callback_record, 44100); |
137 #%! unlink ("record.txt") | |
138 #%! record (recorder); | |
20923
58263bea2fdf
Unified "sleep" functions to "octave_sleep" in C++ and "pause" in Octave.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
20852
diff
changeset
|
139 #%! pause (2); |
19509 | 140 #%! stop (recorder); |
141 #%! s = stat ("record.txt"); | |
142 #%! assert (s.size > 0); |