annotate scripts/audio/@audiorecorder/play.m @ 30569:2d6e60776588

Overhaul @audiorecorder class. Eliminate unnecessary input validation that one argument is supplied to class methods as interpreter guarantees the first argument is an @audiorecorder object. Accept case-insensitive property names for get()/set() functions. Add BIST tests on a per function basis rather than only in @audiorecorder constructor. * @audiorecorder/__get_properties__.m: Eliminate nargin checking. Use intermediate variable hrecorder to clarify code. Use ifelse() to simplify 5-line if/else/endif tree. * @audiorecorder/audiorecorder.m: Add input validation to prevent use of callback functions (not currently supported). Add FIXME note and comment out rudimentary support for callback functions. Remove tests of @audiorecorder functionality to the methods files. Add input validation BIST tests for callback function validation. * @audiorecorder/disp.m: Eliminate nargin checking. Mark file as tested for BIST. * @audiorecorder/get.m: Rename "retval" to "value" in function prototype. Use input parameters with names matching documentation rather than varargin. Use new function getproperty() to do actual property retrieval rather than getfield(). Add BIST tests. * @audiorecorder/get.m (getproperty): New function. Function checks property names without regard to case sensitivity and also issues a meaningful error message if the property name does not exist. * @audiorecorder/getaudiodata.m: Eliminate nargin checking. Use intermediate variable hrecorder to clarify code. Use input parameters with names matching documentation rather than varargin. Add case statements for "double" and "single" to support these datatypes. Add input validation for DATATYPE input. Use transpose rather than Hermitian conjugate on data which is never complex. Add BIST tests. * @audiorecorder/getplayer.m: Eliminate nargin checking. Use input parameters with names matching documentation rather than varargin. Add BIST tests, but commented out for now. * @audiorecorder/isrecording.m: Eliminate nargin checking. Add BIST tests. * @audiorecorder/pause.m: Eliminate nargin checking. Mark file as tested for BIST. * @audiorecorder/play.m: Eliminate nargin checking. Use input parameters with names matching documentation rather than varargin. Mark file as tested for BIST. * @audiorecorder/record.m: Eliminate nargin checking. Use input parameters with names matching documentation rather than varargin. Use intermediate variable hrecorder to clarify code. Mark file as tested for BIST. * @audiorecorder/recordblocking.m: Use input parameters with names matching documentation rather than varargin. Mark file as tested for BIST. * @audiorecorder/resume.m: Eliminate nargin checking. Mark file as tested for BIST. * @audiorecorder/set.m: Eliminate nargin checking of first argument. Use input parameter "recorder" for first argument rather than varargin. Use intermediate variable hrecorder to clarify code. Add BIST tests. * @audiorecorder/set.m (setproperty): Use lower() to implement case insensitive matching of property names. Rewrite error() message to be clearer and report the incorrect name. * @audiorecorder/stop.m: Eliminate nargin checking. Mark file as tested for BIST. * @audiorecorder/subsasgn.m: Change output variable name to "recorder" for clarity. Add BIST tests. * @audiorecorder/subsref.m: Add BIST tests.
author Rik <rik@octave.org>
date Thu, 30 Dec 2021 11:20:10 -0800
parents 82b685157e2b
children ed7b17c7ddf3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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: 29358
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: 23220
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: 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.
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: 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 ########################################################################
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: 20181
diff changeset
27 ## @deftypefn {} {@var{player} =} play (@var{recorder})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20181
diff changeset
28 ## @deftypefnx {} {@var{player} =} play (@var{recorder}, @var{start})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20181
diff changeset
29 ## @deftypefnx {} {@var{player} =} play (@var{recorder}, [@var{start}, @var{end}])
30568
82b685157e2b doc: Update documentation in audio/ directory.
Rik <rik@octave.org>
parents: 30564
diff changeset
30 ## Play the audio recorded in @var{recorder} without blocking and return a
82b685157e2b doc: Update documentation in audio/ directory.
Rik <rik@octave.org>
parents: 30564
diff changeset
31 ## corresponding audioplayer object.
20181
aa36fb998a4d maint: Remove unnecessary whitespace at end of lines.
Rik <rik@octave.org>
parents: 20158
diff changeset
32 ##
20158
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
33 ## If the optional argument @var{start} is provided, begin playing
30568
82b685157e2b doc: Update documentation in audio/ directory.
Rik <rik@octave.org>
parents: 30564
diff changeset
34 ## @var{start} seconds into the recording.
20181
aa36fb998a4d maint: Remove unnecessary whitespace at end of lines.
Rik <rik@octave.org>
parents: 20158
diff changeset
35 ##
19506
fdb8a62ef17a fix docstring style in .m files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
36 ## If the optional argument @var{end} is provided, stop playing at
30568
82b685157e2b doc: Update documentation in audio/ directory.
Rik <rik@octave.org>
parents: 30564
diff changeset
37 ## @var{end} seconds into the recording.
82b685157e2b doc: Update documentation in audio/ directory.
Rik <rik@octave.org>
parents: 30564
diff changeset
38 ## @seealso{@audiorecorder/getplayer, @audioplayer/audioplayer,
82b685157e2b doc: Update documentation in audio/ directory.
Rik <rik@octave.org>
parents: 30564
diff changeset
39 ## @audiorecorder/audiorecorder}
19476
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
40 ## @end deftypefn
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
41
30569
2d6e60776588 Overhaul @audiorecorder class.
Rik <rik@octave.org>
parents: 30568
diff changeset
42 function player = play (recorder, start)
19523
5802ea7037d4 style fixes for audioplayer and audiorecorder classes
John W. Eaton <jwe@octave.org>
parents: 19507
diff changeset
43
30569
2d6e60776588 Overhaul @audiorecorder class.
Rik <rik@octave.org>
parents: 30568
diff changeset
44 data = getaudiodata (recorder);
2d6e60776588 Overhaul @audiorecorder class.
Rik <rik@octave.org>
parents: 30568
diff changeset
45 player = audioplayer (data,
2d6e60776588 Overhaul @audiorecorder class.
Rik <rik@octave.org>
parents: 30568
diff changeset
46 get (recorder, "SampleRate"),
2d6e60776588 Overhaul @audiorecorder class.
Rik <rik@octave.org>
parents: 30568
diff changeset
47 get (recorder, "BitsPerSample"));
19523
5802ea7037d4 style fixes for audioplayer and audiorecorder classes
John W. Eaton <jwe@octave.org>
parents: 19507
diff changeset
48
19476
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
49 if (nargin == 1)
19503
36a26a131209 Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents: 19500
diff changeset
50 play (player);
19476
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
51 else
30569
2d6e60776588 Overhaul @audiorecorder class.
Rik <rik@octave.org>
parents: 30568
diff changeset
52 play (player, start);
19476
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
53 endif
19523
5802ea7037d4 style fixes for audioplayer and audiorecorder classes
John W. Eaton <jwe@octave.org>
parents: 19507
diff changeset
54
19500
8bb399569393 Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents: 19497
diff changeset
55 endfunction
30569
2d6e60776588 Overhaul @audiorecorder class.
Rik <rik@octave.org>
parents: 30568
diff changeset
56
2d6e60776588 Overhaul @audiorecorder class.
Rik <rik@octave.org>
parents: 30568
diff changeset
57
2d6e60776588 Overhaul @audiorecorder class.
Rik <rik@octave.org>
parents: 30568
diff changeset
58 ## No tests possible for this function
2d6e60776588 Overhaul @audiorecorder class.
Rik <rik@octave.org>
parents: 30568
diff changeset
59 %!assert (1)