Mercurial > octave
annotate scripts/audio/@audiorecorder/audiorecorder.m @ 20923:58263bea2fdf
Unified "sleep" functions to "octave_sleep" in C++ and "pause" in Octave.
* doc/interpreter/system.txi: removed sleep and usleep from doc.
* libinterp/corefcn/sysdep.cc (pause): updated docstring.
* libinterp/corefcn/sysdep.cc (sleep): moved to deprecate sleep.m.
* libinterp/corefcn/sysdep.cc (usleep): moved to deprecate usleep.m.
* scripts/deprecated/sleep.m: moved here from sysdep.cc.
* scripts/deprecated/usleep.m: moved here from sysdep.cc.
* scripts/deprecated/module.mk: add sleep.m and usleep.m to build system.
* NEWS: deprecation news for sleep and usleep.
* libinterp/corefcn/data.cc: examples updated.
* libinterp/corefcn/syscalls.cc: examples updated.
* scripts/audio/@audioplayer/audioplayer.m: examples updated.
* scripts/audio/@audiorecorder/audiorecorder.m: examples updated.
* scripts/plot/util/ginput.m: examples updated.
* scripts/plot/util/private/__gnuplot_get_var__.m: use pause.
* scripts/plot/util/private/__gnuplot_ginput__.m: use pause.
* libinterp/corefcn/utils.cc (octave_sleep): Unified "sleep" functions here.
* libinterp/corefcn/utils.h: removed header cutils.h.
* libinterp/corefcn/graphics.cc (drawnow): use octave_sleep.
* libinterp/corefcn/graphics.cc (waitfor): use octave_sleep.
* libinterp/corefcn/toplev.cc (clean_up_and_exit): use octave_sleep.
* libinterp/corefcn/cutils.c: removed no longer needed code.
* libinterp/corefcn/cutils.h: removed no longer needed header.
* libinterp/corefcn/matherr.c: removed orphaned code.
* libinterp/corefcn/module.mk: removed cutils.h, cutils.c, and matherr.c from
build system.
author | Kai T. Ohlhus <k.ohlhus@gmail.com> |
---|---|
date | Thu, 17 Dec 2015 16:04:13 +0100 |
parents | 516bb87ea72e |
children | bac0d6f07a3e |
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); | |
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
|
60 %! pause (2); |
19509 | 61 %! player1 = audioplayer (recorder); |
62 %! player2 = getplayer (recorder); | |
63 %! 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
|
64 %! pause (2); |
19509 | 65 %! 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
|
66 %! pause (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); | |
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
|
122 #%! pause (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); | |
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
|
131 #%! pause (2); |
19509 | 132 #%! stop (recorder); |
133 #%! s = stat ("record.txt"); | |
134 #%! assert (s.size > 0); |