Mercurial > octave
annotate scripts/audio/@audiorecorder/audiorecorder.m @ 20852:516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
author | Rik <rik@octave.org> |
---|---|
date | Sat, 12 Dec 2015 07:31:00 -0800 |
parents | 7503499a252b |
children | 58263bea2fdf |
rev | line source |
---|---|
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19668
diff
changeset
|
1 ## Copyright (C) 2013-2015 Vytautas JanĨauskas |
19500
8bb399569393
Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents:
19497
diff
changeset
|
2 ## |
8bb399569393
Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents:
19497
diff
changeset
|
3 ## 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
|
4 ## |
8bb399569393
Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents:
19497
diff
changeset
|
5 ## Octave is free software; you can redistribute it and/or modify it |
8bb399569393
Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents:
19497
diff
changeset
|
6 ## under the terms of the GNU General Public License as published by |
8bb399569393
Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents:
19497
diff
changeset
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
8bb399569393
Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents:
19497
diff
changeset
|
8 ## your option) any later version. |
8bb399569393
Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents:
19497
diff
changeset
|
9 ## |
8bb399569393
Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents:
19497
diff
changeset
|
10 ## 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
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
8bb399569393
Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents:
19497
diff
changeset
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
8bb399569393
Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents:
19497
diff
changeset
|
13 ## General Public License for more details. |
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 ## 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
|
16 ## along with Octave; see the file COPYING. If not, see |
8bb399569393
Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents:
19497
diff
changeset
|
17 ## <http://www.gnu.org/licenses/>. |
8bb399569393
Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents:
19497
diff
changeset
|
18 |
19476
e1f98e402a7e
New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
19 ## -*- texinfo -*- |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20158
diff
changeset
|
20 ## @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
|
21 ## @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
|
22 ## @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
|
23 ## 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
|
24 ## sample rate. |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
25 ## |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
26 ## 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
|
27 ## 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
|
28 ## 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
|
29 ## function. |
19560
e75df9e43e63
disable Octave audio callback functions
John W. Eaton <jwe@octave.org>
parents:
19528
diff
changeset
|
30 ## @end deftypefn |
e75df9e43e63
disable Octave audio callback functions
John W. Eaton <jwe@octave.org>
parents:
19528
diff
changeset
|
31 |
e75df9e43e63
disable Octave audio callback functions
John W. Eaton <jwe@octave.org>
parents:
19528
diff
changeset
|
32 ## 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
|
33 ## 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
|
34 ## 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
|
35 ## all of Octave's global data... |
e75df9e43e63
disable Octave audio callback functions
John W. Eaton <jwe@octave.org>
parents:
19528
diff
changeset
|
36 ## |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20158
diff
changeset
|
37 ## @deftypefnx {} {@var{recorder} =} audiorecorder (@var{function}, @dots{}) |
19560
e75df9e43e63
disable Octave audio callback functions
John W. Eaton <jwe@octave.org>
parents:
19528
diff
changeset
|
38 ## |
19506
fdb8a62ef17a
fix docstring style in .m files
John W. Eaton <jwe@octave.org>
parents:
19505
diff
changeset
|
39 ## 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
|
40 |
e1f98e402a7e
New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
41 function recorder = audiorecorder (varargin) |
19523
5802ea7037d4
style fixes for audioplayer and audiorecorder classes
John W. Eaton <jwe@octave.org>
parents:
19509
diff
changeset
|
42 |
19476
e1f98e402a7e
New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
43 if (nargin > 5) |
e1f98e402a7e
New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
44 print_usage (); |
e1f98e402a7e
New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
45 endif |
19523
5802ea7037d4
style fixes for audioplayer and audiorecorder classes
John W. Eaton <jwe@octave.org>
parents:
19509
diff
changeset
|
46 |
19507
dac3191a5301
style fixes for audioplayer and audiorecorder .m files
John W. Eaton <jwe@octave.org>
parents:
19506
diff
changeset
|
47 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
|
48 varargin{1} = str2func (varargin{1}); |
19476
e1f98e402a7e
New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
49 endif |
19523
5802ea7037d4
style fixes for audioplayer and audiorecorder classes
John W. Eaton <jwe@octave.org>
parents:
19509
diff
changeset
|
50 |
19476
e1f98e402a7e
New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
51 recorder.recorder = __recorder_audiorecorder__ (varargin{:}); |
e1f98e402a7e
New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
52 recorder = class (recorder, "audiorecorder"); |
19523
5802ea7037d4
style fixes for audioplayer and audiorecorder classes
John W. Eaton <jwe@octave.org>
parents:
19509
diff
changeset
|
53 |
19476
e1f98e402a7e
New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
54 endfunction |
e1f98e402a7e
New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
55 |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
56 |
19668
b2fe4dbe5266
Don't play or record audio during 'make check'
Mike Miller <mtmiller@ieee.org>
parents:
19575
diff
changeset
|
57 %!demo |
19509 | 58 %! recorder = audiorecorder (44100, 16, 2); |
59 %! record (recorder, 1); | |
60 %! sleep (2); | |
61 %! player1 = audioplayer (recorder); | |
62 %! player2 = getplayer (recorder); | |
63 %! play (player1); | |
64 %! sleep (2); | |
65 %! play (player2); | |
66 %! sleep (2); | |
19668
b2fe4dbe5266
Don't play or record audio during 'make check'
Mike Miller <mtmiller@ieee.org>
parents:
19575
diff
changeset
|
67 %! stop (player1); |
b2fe4dbe5266
Don't play or record audio during 'make check'
Mike Miller <mtmiller@ieee.org>
parents:
19575
diff
changeset
|
68 %! stop (player2); |
b2fe4dbe5266
Don't play or record audio during 'make check'
Mike Miller <mtmiller@ieee.org>
parents:
19575
diff
changeset
|
69 |
b2fe4dbe5266
Don't play or record audio during 'make check'
Mike Miller <mtmiller@ieee.org>
parents:
19575
diff
changeset
|
70 ## 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
|
71 |
b2fe4dbe5266
Don't play or record audio during 'make check'
Mike Miller <mtmiller@ieee.org>
parents:
19575
diff
changeset
|
72 %!testif HAVE_PORTAUDIO |
b2fe4dbe5266
Don't play or record audio during 'make check'
Mike Miller <mtmiller@ieee.org>
parents:
19575
diff
changeset
|
73 %! recorder = audiorecorder (44100, 16, 2); |
b2fe4dbe5266
Don't play or record audio during 'make check'
Mike Miller <mtmiller@ieee.org>
parents:
19575
diff
changeset
|
74 %! data = getaudiodata (recorder, "int16"); |
b2fe4dbe5266
Don't play or record audio during 'make check'
Mike Miller <mtmiller@ieee.org>
parents:
19575
diff
changeset
|
75 %! assert (strcmp (class (data), "int16")); |
b2fe4dbe5266
Don't play or record audio during 'make check'
Mike Miller <mtmiller@ieee.org>
parents:
19575
diff
changeset
|
76 %! data = getaudiodata (recorder, "int8"); |
b2fe4dbe5266
Don't play or record audio during 'make check'
Mike Miller <mtmiller@ieee.org>
parents:
19575
diff
changeset
|
77 %! assert (strcmp (class (data), "int8")); |
b2fe4dbe5266
Don't play or record audio during 'make check'
Mike Miller <mtmiller@ieee.org>
parents:
19575
diff
changeset
|
78 %! data = getaudiodata (recorder, "uint8"); |
b2fe4dbe5266
Don't play or record audio during 'make check'
Mike Miller <mtmiller@ieee.org>
parents:
19575
diff
changeset
|
79 %! assert (strcmp (class (data), "uint8")); |
b2fe4dbe5266
Don't play or record audio during 'make check'
Mike Miller <mtmiller@ieee.org>
parents:
19575
diff
changeset
|
80 %! 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
|
81 %! assert (size (data)(2), 2); |
19476
e1f98e402a7e
New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
82 |
19528
4f615cd9a68d
Use "testif HAVE_PORTAUDIO" for new audio function tests
Andreas Weber <andy.weber.aw@gmail.com>
parents:
19523
diff
changeset
|
83 %!testif HAVE_PORTAUDIO |
19509 | 84 %! recorder = audiorecorder; |
85 %! set (recorder, {"SampleRate", "Tag", "UserData"}, {8000, "tag", [1, 2; 3, 4]}); | |
86 %! assert (recorder.SampleRate, 8000); | |
87 %! assert (recorder.Tag, "tag"); | |
88 %! assert (recorder.UserData, [1, 2; 3, 4]); | |
19476
e1f98e402a7e
New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
89 |
19528
4f615cd9a68d
Use "testif HAVE_PORTAUDIO" for new audio function tests
Andreas Weber <andy.weber.aw@gmail.com>
parents:
19523
diff
changeset
|
90 %!testif HAVE_PORTAUDIO |
19509 | 91 %! recorder = audiorecorder; |
92 %! settable = set (recorder); | |
93 %! settable.SampleRate = 8000; | |
94 %! settable.Tag = "tag"; | |
95 %! settable.UserData = [1, 2; 3, 4]; | |
96 %! set (recorder, settable); | |
97 %! assert (recorder.SampleRate, 8000); | |
98 %! assert (recorder.Tag, "tag"); | |
99 %! assert (recorder.UserData, [1, 2; 3, 4]); | |
19476
e1f98e402a7e
New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
100 |
19528
4f615cd9a68d
Use "testif HAVE_PORTAUDIO" for new audio function tests
Andreas Weber <andy.weber.aw@gmail.com>
parents:
19523
diff
changeset
|
101 %!testif HAVE_PORTAUDIO |
19509 | 102 %! recorder = audiorecorder; |
103 %! recorder.SampleRate = 8000; | |
104 %! recorder.Tag = "tag"; | |
105 %! recorder.UserData = [1, 2; 3, 4]; | |
106 %! properties = get (recorder, {"SampleRate", "Tag", "UserData"}); | |
107 %! 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
|
108 |
e1f98e402a7e
New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
109 #%!function status = callback_record (sound) |
19503
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19500
diff
changeset
|
110 #%! fid = fopen ("record.txt", "at"); |
19476
e1f98e402a7e
New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
111 #%! for index = 1:rows(sound) |
19503
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19500
diff
changeset
|
112 #%! 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
|
113 #%! endfor |
19503
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19500
diff
changeset
|
114 #%! fclose (fid); |
19476
e1f98e402a7e
New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
115 #%! status = 0; |
e1f98e402a7e
New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
116 #%!endfunction |
e1f98e402a7e
New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
117 |
19528
4f615cd9a68d
Use "testif HAVE_PORTAUDIO" for new audio function tests
Andreas Weber <andy.weber.aw@gmail.com>
parents:
19523
diff
changeset
|
118 #%!testif HAVE_PORTAUDIO |
19509 | 119 #%! recorder = audiorecorder (@callback_record, 44100); |
120 #%! unlink ("record.txt") | |
121 #%! record (recorder); | |
122 #%! sleep (2); | |
19575
7f5006dfa2eb
* audiorecorder.m: Fix test.
John W. Eaton <jwe@octave.org>
parents:
19571
diff
changeset
|
123 #%! stop (recorder); |
19509 | 124 #%! s = stat ("record.txt"); |
125 #%! assert (s.size > 0); | |
19476
e1f98e402a7e
New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
126 |
19528
4f615cd9a68d
Use "testif HAVE_PORTAUDIO" for new audio function tests
Andreas Weber <andy.weber.aw@gmail.com>
parents:
19523
diff
changeset
|
127 #%!testif HAVE_PORTAUDIO |
19509 | 128 #%! recorder = audiorecorder (@callback_record, 44100); |
129 #%! unlink ("record.txt") | |
130 #%! record (recorder); | |
131 #%! sleep (2); | |
132 #%! stop (recorder); | |
133 #%! s = stat ("record.txt"); | |
134 #%! assert (s.size > 0); |