annotate scripts/audio/@audioplayer/audioplayer.m @ 23219:3ac9f9ecfae5 stable

maint: Update copyright dates.
author John W. Eaton <jwe@octave.org>
date Wed, 22 Feb 2017 12:39:29 -0500
parents 6763f91685da
children 092078913d54
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
23219
3ac9f9ecfae5 maint: Update copyright dates.
John W. Eaton <jwe@octave.org>
parents: 22544
diff changeset
1 ## Copyright (C) 2013-2017 Vytautas JanĨauskas
19500
8bb399569393 Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents: 19496
diff changeset
2 ##
8bb399569393 Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents: 19496
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: 19496
diff changeset
4 ##
8bb399569393 Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents: 19496
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: 19496
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: 19496
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: 19496
diff changeset
8 ## your option) any later version.
8bb399569393 Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents: 19496
diff changeset
9 ##
8bb399569393 Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents: 19496
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: 19496
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: 19496
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: 19496
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: 19496
diff changeset
14 ##
8bb399569393 Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents: 19496
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: 19496
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: 19496
diff changeset
17 ## <http://www.gnu.org/licenses/>.
8bb399569393 Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents: 19496
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{player} =} audioplayer (@var{y}, @var{fs})
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{player} =} audioplayer (@var{y}, @var{fs}, @var{nbits})
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{player} =} audioplayer (@var{y}, @var{fs}, @var{nbits}, @var{id})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20158
diff changeset
23 ## @deftypefnx {} {@var{player} =} audioplayer (@var{recorder})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20158
diff changeset
24 ## @deftypefnx {} {@var{player} =} audioplayer (@var{recorder}, @var{id})
19505
ce02743b6f2a Fix texinfo docstring syntax for all audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19503
diff changeset
25 ## Create an audioplayer object that will play back data @var{y} at sample
20158
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
26 ## rate @var{fs}.
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
27 ##
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
28 ## The optional arguments @var{nbits}, and @var{id} specify the bit depth and
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
29 ## player device id, respectively. Device IDs may be found using the
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
30 ## audiodevinfo function. Given an audioplayer object, use the data from the
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
31 ## object to initialize the player.
19476
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
32 ##
19571
72304a4e010a Use Octave coding conventions for documentation of audio functions.
Rik <rik@octave.org>
parents: 19560
diff changeset
33 ## The signal @var{y} can be a vector or a two-dimensional array.
19476
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
34 ##
19505
ce02743b6f2a Fix texinfo docstring syntax for all audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19503
diff changeset
35 ## The following example will create an audioplayer object that will play
ce02743b6f2a Fix texinfo docstring syntax for all audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19503
diff changeset
36 ## back one second of white noise at 44100 sample rate using 8 bits per
ce02743b6f2a Fix texinfo docstring syntax for all audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19503
diff changeset
37 ## sample.
19476
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
38 ##
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
39 ## @example
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
40 ## @group
22441
bb8914d68f25 Fix noise signal generation in audioplayer doc string and demos (bug #49011)
Mike Miller <mtmiller@octave.org>
parents: 22323
diff changeset
41 ## y = 0.25 * randn (2, 44100);
19506
fdb8a62ef17a fix docstring style in .m files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
42 ## player = audioplayer (y, 44100, 8);
fdb8a62ef17a fix docstring style in .m files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
43 ## play (player);
19476
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
44 ## @end group
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
45 ## @end example
19571
72304a4e010a Use Octave coding conventions for documentation of audio functions.
Rik <rik@octave.org>
parents: 19560
diff changeset
46 ## @end deftypefn
19560
e75df9e43e63 disable Octave audio callback functions
John W. Eaton <jwe@octave.org>
parents: 19528
diff changeset
47
e75df9e43e63 disable Octave audio callback functions
John W. Eaton <jwe@octave.org>
parents: 19528
diff changeset
48 ## 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
49 ## 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
50 ## 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
51 ## all of Octave's global data...
19476
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
52 ##
20852
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20158
diff changeset
53 ## @deftypefnx {} {@var{player} =} audioplayer (@var{function}, @dots{})
19560
e75df9e43e63 disable Octave audio callback functions
John W. Eaton <jwe@octave.org>
parents: 19528
diff changeset
54 ##
e75df9e43e63 disable Octave audio callback functions
John W. Eaton <jwe@octave.org>
parents: 19528
diff changeset
55 ## Given a function handle, use that function to process the audio.
e75df9e43e63 disable Octave audio callback functions
John W. Eaton <jwe@octave.org>
parents: 19528
diff changeset
56 #
19505
ce02743b6f2a Fix texinfo docstring syntax for all audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19503
diff changeset
57 ## The following example will create and register a callback that generates
ce02743b6f2a Fix texinfo docstring syntax for all audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19503
diff changeset
58 ## a sine wave on both channels.
19476
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
59 ##
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
60 ## @example
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
61 ## @group
19506
fdb8a62ef17a fix docstring style in .m files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
62 ## function [ sound, status ] = callback_sine (frames)
fdb8a62ef17a fix docstring style in .m files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
63 ## global lphase = 0.0;
fdb8a62ef17a fix docstring style in .m files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
64 ## global rphase = 0.0;
fdb8a62ef17a fix docstring style in .m files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
65 ## incl = 440.0 / 44100.0;
fdb8a62ef17a fix docstring style in .m files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
66 ## incr = 443.0 / 44100.0;
fdb8a62ef17a fix docstring style in .m files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
67 ## nl = incl * frames;
fdb8a62ef17a fix docstring style in .m files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
68 ## nr = incr * frames;
fdb8a62ef17a fix docstring style in .m files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
69 ## left = sin (2.0 * pi * [lphase:incl:lphase+nl]);
fdb8a62ef17a fix docstring style in .m files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
70 ## right = sin (2.0 * pi * [rphase:incr:rphase+nr]);
fdb8a62ef17a fix docstring style in .m files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
71 ## sound = [left', right'];
fdb8a62ef17a fix docstring style in .m files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
72 ## status = 0;
fdb8a62ef17a fix docstring style in .m files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
73 ## lphase = lphase + nl;
fdb8a62ef17a fix docstring style in .m files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
74 ## rphase = rphase + nr;
fdb8a62ef17a fix docstring style in .m files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
75 ## endfunction
fdb8a62ef17a fix docstring style in .m files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
76 ## player = audioplayer (@@callback_sine, 44100);
fdb8a62ef17a fix docstring style in .m files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
77 ## play (player);
fdb8a62ef17a fix docstring style in .m files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
78 ## # play for as long as you want
fdb8a62ef17a fix docstring style in .m files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
79 ## stop (player);
19476
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
80 ## @end group
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
81
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
82 function player = audioplayer (varargin)
19523
5802ea7037d4 style fixes for audioplayer and audiorecorder classes
John W. Eaton <jwe@octave.org>
parents: 19509
diff changeset
83
5802ea7037d4 style fixes for audioplayer and audiorecorder classes
John W. Eaton <jwe@octave.org>
parents: 19509
diff changeset
84 if (nargin < 1 || nargin > 4
22544
6763f91685da audioplayer: fix input validation, fix crash when called with a single argument
Mike Miller <mtmiller@octave.org>
parents: 22441
diff changeset
85 || (nargin < 2 && ! (is_function_handle (varargin{1})
6763f91685da audioplayer: fix input validation, fix crash when called with a single argument
Mike Miller <mtmiller@octave.org>
parents: 22441
diff changeset
86 || ischar (varargin{1}))))
19476
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
87 print_usage ();
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
88 endif
19523
5802ea7037d4 style fixes for audioplayer and audiorecorder classes
John W. Eaton <jwe@octave.org>
parents: 19509
diff changeset
89
5802ea7037d4 style fixes for audioplayer and audiorecorder classes
John W. Eaton <jwe@octave.org>
parents: 19509
diff changeset
90 if (isa (varargin{1}, "audiorecorder"))
5802ea7037d4 style fixes for audioplayer and audiorecorder classes
John W. Eaton <jwe@octave.org>
parents: 19509
diff changeset
91 if (nargin == 1)
19503
36a26a131209 Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents: 19500
diff changeset
92 player = getplayer (varargin{1});
19523
5802ea7037d4 style fixes for audioplayer and audiorecorder classes
John W. Eaton <jwe@octave.org>
parents: 19509
diff changeset
93 elseif (nargin == 2)
19476
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
94 recorder = varargin{1};
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
95 data = getaudiodata (recorder);
19507
dac3191a5301 style fixes for audioplayer and audiorecorder .m files
John W. Eaton <jwe@octave.org>
parents: 19506
diff changeset
96 player = audioplayer (data, get (recorder, "SampleRate"),
dac3191a5301 style fixes for audioplayer and audiorecorder .m files
John W. Eaton <jwe@octave.org>
parents: 19506
diff changeset
97 get (recorder, "BitsPerSample"), varargin{2});
19476
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
98 else
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
99 print_usage ();
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
100 endif
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
101 else
19507
dac3191a5301 style fixes for audioplayer and audiorecorder .m files
John W. Eaton <jwe@octave.org>
parents: 19506
diff changeset
102 if (ischar (varargin{1}))
19503
36a26a131209 Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents: 19500
diff changeset
103 varargin{1} = str2func (varargin{1});
19476
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
104 endif
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
105 player.player = __player_audioplayer__ (varargin{:});
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
106 player = class (player, "audioplayer");
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
107 endif
19523
5802ea7037d4 style fixes for audioplayer and audiorecorder classes
John W. Eaton <jwe@octave.org>
parents: 19509
diff changeset
108
19476
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
109 endfunction
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
110
19833
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
111
19668
b2fe4dbe5266 Don't play or record audio during 'make check'
Mike Miller <mtmiller@ieee.org>
parents: 19571
diff changeset
112 %!demo
b2fe4dbe5266 Don't play or record audio during 'make check'
Mike Miller <mtmiller@ieee.org>
parents: 19571
diff changeset
113 %! fs = 44100;
22441
bb8914d68f25 Fix noise signal generation in audioplayer doc string and demos (bug #49011)
Mike Miller <mtmiller@octave.org>
parents: 22323
diff changeset
114 %! audio = 0.25 * randn (2, 2*fs);
19668
b2fe4dbe5266 Don't play or record audio during 'make check'
Mike Miller <mtmiller@ieee.org>
parents: 19571
diff changeset
115 %! player = audioplayer (audio, fs);
b2fe4dbe5266 Don't play or record audio during 'make check'
Mike Miller <mtmiller@ieee.org>
parents: 19571
diff changeset
116 %! play (player);
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
117 %! pause (1);
19668
b2fe4dbe5266 Don't play or record audio during 'make check'
Mike Miller <mtmiller@ieee.org>
parents: 19571
diff changeset
118 %! pause (player);
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
119 %! pause (1);
19668
b2fe4dbe5266 Don't play or record audio during 'make check'
Mike Miller <mtmiller@ieee.org>
parents: 19571
diff changeset
120 %! resume (player);
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
121 %! pause (1);
19668
b2fe4dbe5266 Don't play or record audio during 'make check'
Mike Miller <mtmiller@ieee.org>
parents: 19571
diff changeset
122 %! stop (player);
b2fe4dbe5266 Don't play or record audio during 'make check'
Mike Miller <mtmiller@ieee.org>
parents: 19571
diff changeset
123
b2fe4dbe5266 Don't play or record audio during 'make check'
Mike Miller <mtmiller@ieee.org>
parents: 19571
diff changeset
124 ## Tests of audioplayer must not actually play anything.
b2fe4dbe5266 Don't play or record audio during 'make check'
Mike Miller <mtmiller@ieee.org>
parents: 19571
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
22441
bb8914d68f25 Fix noise signal generation in audioplayer doc string and demos (bug #49011)
Mike Miller <mtmiller@octave.org>
parents: 22323
diff changeset
127 %! mono = 0.25 * randn (1, 44100);
bb8914d68f25 Fix noise signal generation in audioplayer doc string and demos (bug #49011)
Mike Miller <mtmiller@octave.org>
parents: 22323
diff changeset
128 %! stereo = 0.25 * randn (2, 44100);
19509
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19507
diff changeset
129 %! fs = 44100;
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19507
diff changeset
130 %! player1 = audioplayer (mono, fs);
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19507
diff changeset
131 %! player2 = audioplayer (stereo, fs);
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19507
diff changeset
132 %! assert (player1.NumberOfChannels, 1);
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19507
diff changeset
133 %! assert (player2.NumberOfChannels, 2);
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19507
diff changeset
134 %! assert (player1.SampleRate, 44100);
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19507
diff changeset
135 %! assert (player2.SampleRate, 44100);
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19507
diff changeset
136 %! assert (player1.TotalSamples, 44100);
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19507
diff changeset
137 %! assert (player2.TotalSamples, 44100);
19476
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
138
19528
4f615cd9a68d Use "testif HAVE_PORTAUDIO" for new audio function tests
Andreas Weber <andy.weber.aw@gmail.com>
parents: 19523
diff changeset
139 %!testif HAVE_PORTAUDIO
22441
bb8914d68f25 Fix noise signal generation in audioplayer doc string and demos (bug #49011)
Mike Miller <mtmiller@octave.org>
parents: 22323
diff changeset
140 %! audio = 0.25 * randn (2, 44100);
19509
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19507
diff changeset
141 %! fs = 44100;
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19507
diff changeset
142 %! player = audioplayer (audio, fs);
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19507
diff changeset
143 %! set (player, {"SampleRate", "Tag", "UserData"}, {8000, "tag", [1, 2; 3, 4]});
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19507
diff changeset
144 %! assert (player.SampleRate, 8000);
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19507
diff changeset
145 %! assert (player.Tag, "tag");
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19507
diff changeset
146 %! assert (player.UserData, [1, 2; 3, 4]);
19476
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
147
19528
4f615cd9a68d Use "testif HAVE_PORTAUDIO" for new audio function tests
Andreas Weber <andy.weber.aw@gmail.com>
parents: 19523
diff changeset
148 %!testif HAVE_PORTAUDIO
22441
bb8914d68f25 Fix noise signal generation in audioplayer doc string and demos (bug #49011)
Mike Miller <mtmiller@octave.org>
parents: 22323
diff changeset
149 %! audio = 0.25 * randn (2, 44100);
19509
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19507
diff changeset
150 %! fs = 44100;
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19507
diff changeset
151 %! player = audioplayer (audio, fs);
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19507
diff changeset
152 %! settable = set (player);
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19507
diff changeset
153 %! settable.SampleRate = 8000;
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19507
diff changeset
154 %! settable.Tag = "tag";
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19507
diff changeset
155 %! settable.UserData = [1, 2; 3, 4];
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19507
diff changeset
156 %! set (player, settable);
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19507
diff changeset
157 %! assert (player.SampleRate, 8000);
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19507
diff changeset
158 %! assert (player.Tag, "tag");
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19507
diff changeset
159 %! assert (player.UserData, [1, 2; 3, 4]);
19476
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
160
19528
4f615cd9a68d Use "testif HAVE_PORTAUDIO" for new audio function tests
Andreas Weber <andy.weber.aw@gmail.com>
parents: 19523
diff changeset
161 %!testif HAVE_PORTAUDIO
22441
bb8914d68f25 Fix noise signal generation in audioplayer doc string and demos (bug #49011)
Mike Miller <mtmiller@octave.org>
parents: 22323
diff changeset
162 %! audio = 0.25 * randn (2, 44100);
19509
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19507
diff changeset
163 %! fs = 44100;
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19507
diff changeset
164 %! player = audioplayer (audio, fs);
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19507
diff changeset
165 %! player.SampleRate = 8000;
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19507
diff changeset
166 %! player.Tag = "tag";
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19507
diff changeset
167 %! player.UserData = [1, 2; 3, 4];
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19507
diff changeset
168 %! properties = get (player, {"SampleRate", "Tag", "UserData"});
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19507
diff changeset
169 %! 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
170
19560
e75df9e43e63 disable Octave audio callback functions
John W. Eaton <jwe@octave.org>
parents: 19528
diff changeset
171 #%!function [sound, status] = callback (samples)
e75df9e43e63 disable Octave audio callback functions
John W. Eaton <jwe@octave.org>
parents: 19528
diff changeset
172 #%! sound = rand (samples, 2) - 0.5;
e75df9e43e63 disable Octave audio callback functions
John W. Eaton <jwe@octave.org>
parents: 19528
diff changeset
173 #%! status = 0;
e75df9e43e63 disable Octave audio callback functions
John W. Eaton <jwe@octave.org>
parents: 19528
diff changeset
174 #%!endfunction
19476
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
175
19560
e75df9e43e63 disable Octave audio callback functions
John W. Eaton <jwe@octave.org>
parents: 19528
diff changeset
176 #%!testif HAVE_PORTAUDIO
e75df9e43e63 disable Octave audio callback functions
John W. Eaton <jwe@octave.org>
parents: 19528
diff changeset
177 #%! player = audioplayer (@callback, 44100);
e75df9e43e63 disable Octave audio callback functions
John W. Eaton <jwe@octave.org>
parents: 19528
diff changeset
178 #%! play (player);
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
179 #%! pause (2);
19560
e75df9e43e63 disable Octave audio callback functions
John W. Eaton <jwe@octave.org>
parents: 19528
diff changeset
180 #%! stop (player);
e75df9e43e63 disable Octave audio callback functions
John W. Eaton <jwe@octave.org>
parents: 19528
diff changeset
181 #%! assert (1);
19476
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
182
19560
e75df9e43e63 disable Octave audio callback functions
John W. Eaton <jwe@octave.org>
parents: 19528
diff changeset
183 #%!testif HAVE_PORTAUDIO
e75df9e43e63 disable Octave audio callback functions
John W. Eaton <jwe@octave.org>
parents: 19528
diff changeset
184 #%! player = audioplayer ("callback", 44100, 16);
e75df9e43e63 disable Octave audio callback functions
John W. Eaton <jwe@octave.org>
parents: 19528
diff changeset
185 #%! play (player);
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
186 #%! pause (2);
19560
e75df9e43e63 disable Octave audio callback functions
John W. Eaton <jwe@octave.org>
parents: 19528
diff changeset
187 #%! stop (player);
e75df9e43e63 disable Octave audio callback functions
John W. Eaton <jwe@octave.org>
parents: 19528
diff changeset
188 #%! assert (1);