annotate scripts/audio/@audioplayer/audioplayer.m @ 19605:72304a4e010a

Use Octave coding conventions for documentation of audio functions. * audio.txi, audioread.cc, @audioplayer/audioplayer.m, @audioplayer/get.m, @audioplayer/play.m, @audioplayer/playblocking.m, @audioplayer/set.m, @audiorecorder/audiorecorder.m, @audiorecorder/get.m, @audiorecorder/getaudiodata.m, @audiorecorder/play.m, @audiorecorder/record.m, @audiorecorder/set.m: Use Octave documentation standards. * audiodevinfo.cc: Limit lines to 80 chars. Indent according to GNU style.
author Rik <rik@octave.org>
date Tue, 13 Jan 2015 08:54:25 -0800
parents e75df9e43e63
children b2fe4dbe5266
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19534
8bb399569393 Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents: 19530
diff changeset
1 ## Copyright (C) 2013 Vytautas JanĨauskas
8bb399569393 Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents: 19530
diff changeset
2 ##
8bb399569393 Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents: 19530
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: 19530
diff changeset
4 ##
8bb399569393 Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents: 19530
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: 19530
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: 19530
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: 19530
diff changeset
8 ## your option) any later version.
8bb399569393 Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents: 19530
diff changeset
9 ##
8bb399569393 Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents: 19530
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: 19530
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: 19530
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: 19530
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: 19530
diff changeset
14 ##
8bb399569393 Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents: 19530
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: 19530
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: 19530
diff changeset
17 ## <http://www.gnu.org/licenses/>.
8bb399569393 Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents: 19530
diff changeset
18
19510
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
19 ## -*- texinfo -*-
19605
72304a4e010a Use Octave coding conventions for documentation of audio functions.
Rik <rik@octave.org>
parents: 19594
diff changeset
20 ## @deftypefn {Function File} {@var{player} =} audioplayer (@var{y}, @var{fs})
19540
fdb8a62ef17a fix docstring style in .m files
John W. Eaton <jwe@octave.org>
parents: 19539
diff changeset
21 ## @deftypefnx {Function File} {@var{player} =} audioplayer (@var{y}, @var{fs}, @var{nbits})
fdb8a62ef17a fix docstring style in .m files
John W. Eaton <jwe@octave.org>
parents: 19539
diff changeset
22 ## @deftypefnx {Function File} {@var{player} =} audioplayer (@var{y}, @var{fs}, @var{nbits}, @var{id})
fdb8a62ef17a fix docstring style in .m files
John W. Eaton <jwe@octave.org>
parents: 19539
diff changeset
23 ## @deftypefnx {Function File} {@var{player} =} audioplayer (@var{recorder})
fdb8a62ef17a fix docstring style in .m files
John W. Eaton <jwe@octave.org>
parents: 19539
diff changeset
24 ## @deftypefnx {Function File} {@var{player} =} audioplayer (@var{recorder}, @var{id})
19539
ce02743b6f2a Fix texinfo docstring syntax for all audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19537
diff changeset
25 ## Create an audioplayer object that will play back data @var{y} at sample
19540
fdb8a62ef17a fix docstring style in .m files
John W. Eaton <jwe@octave.org>
parents: 19539
diff changeset
26 ## rate @var{fs}. The optional arguments @var{nbits}, and @var{id}
fdb8a62ef17a fix docstring style in .m files
John W. Eaton <jwe@octave.org>
parents: 19539
diff changeset
27 ## specify the bit depth and player device id, respectively. Device IDs
fdb8a62ef17a fix docstring style in .m files
John W. Eaton <jwe@octave.org>
parents: 19539
diff changeset
28 ## may be found using the audiodevinfo function.
fdb8a62ef17a fix docstring style in .m files
John W. Eaton <jwe@octave.org>
parents: 19539
diff changeset
29 ## Given an audioplayer object, use the data from the object to
fdb8a62ef17a fix docstring style in .m files
John W. Eaton <jwe@octave.org>
parents: 19539
diff changeset
30 ## initialize the player.
19510
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
31 ##
19605
72304a4e010a Use Octave coding conventions for documentation of audio functions.
Rik <rik@octave.org>
parents: 19594
diff changeset
32 ## The signal @var{y} can be a vector or a two-dimensional array.
19510
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
33 ##
19539
ce02743b6f2a Fix texinfo docstring syntax for all audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19537
diff changeset
34 ## 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: 19537
diff changeset
35 ## 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: 19537
diff changeset
36 ## sample.
19510
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
37 ##
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
38 ## @example
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
39 ## @group
19540
fdb8a62ef17a fix docstring style in .m files
John W. Eaton <jwe@octave.org>
parents: 19539
diff changeset
40 ## y = randn (2, 44100) - 0.5;
fdb8a62ef17a fix docstring style in .m files
John W. Eaton <jwe@octave.org>
parents: 19539
diff changeset
41 ## player = audioplayer (y, 44100, 8);
fdb8a62ef17a fix docstring style in .m files
John W. Eaton <jwe@octave.org>
parents: 19539
diff changeset
42 ## play (player);
19510
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
43 ## @end group
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
44 ## @end example
19605
72304a4e010a Use Octave coding conventions for documentation of audio functions.
Rik <rik@octave.org>
parents: 19594
diff changeset
45 ## @end deftypefn
19594
e75df9e43e63 disable Octave audio callback functions
John W. Eaton <jwe@octave.org>
parents: 19562
diff changeset
46
e75df9e43e63 disable Octave audio callback functions
John W. Eaton <jwe@octave.org>
parents: 19562
diff changeset
47 ## FIXME: callbacks don't work properly, apparently because portaudio
e75df9e43e63 disable Octave audio callback functions
John W. Eaton <jwe@octave.org>
parents: 19562
diff changeset
48 ## will execute the callbacks in a separate thread, and calling Octave
e75df9e43e63 disable Octave audio callback functions
John W. Eaton <jwe@octave.org>
parents: 19562
diff changeset
49 ## 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: 19562
diff changeset
50 ## all of Octave's global data...
19510
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
51 ##
19594
e75df9e43e63 disable Octave audio callback functions
John W. Eaton <jwe@octave.org>
parents: 19562
diff changeset
52 ## @deftypefnx {Function File} {@var{player} =} audioplayer (@var{function}, @dots{})
e75df9e43e63 disable Octave audio callback functions
John W. Eaton <jwe@octave.org>
parents: 19562
diff changeset
53 ##
e75df9e43e63 disable Octave audio callback functions
John W. Eaton <jwe@octave.org>
parents: 19562
diff changeset
54 ## Given a function handle, use that function to process the audio.
e75df9e43e63 disable Octave audio callback functions
John W. Eaton <jwe@octave.org>
parents: 19562
diff changeset
55 #
19539
ce02743b6f2a Fix texinfo docstring syntax for all audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19537
diff changeset
56 ## 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: 19537
diff changeset
57 ## a sine wave on both channels.
19510
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
58 ##
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
59 ## @example
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
60 ## @group
19540
fdb8a62ef17a fix docstring style in .m files
John W. Eaton <jwe@octave.org>
parents: 19539
diff changeset
61 ## function [ sound, status ] = callback_sine (frames)
fdb8a62ef17a fix docstring style in .m files
John W. Eaton <jwe@octave.org>
parents: 19539
diff changeset
62 ## global lphase = 0.0;
fdb8a62ef17a fix docstring style in .m files
John W. Eaton <jwe@octave.org>
parents: 19539
diff changeset
63 ## global rphase = 0.0;
fdb8a62ef17a fix docstring style in .m files
John W. Eaton <jwe@octave.org>
parents: 19539
diff changeset
64 ## incl = 440.0 / 44100.0;
fdb8a62ef17a fix docstring style in .m files
John W. Eaton <jwe@octave.org>
parents: 19539
diff changeset
65 ## incr = 443.0 / 44100.0;
fdb8a62ef17a fix docstring style in .m files
John W. Eaton <jwe@octave.org>
parents: 19539
diff changeset
66 ## nl = incl * frames;
fdb8a62ef17a fix docstring style in .m files
John W. Eaton <jwe@octave.org>
parents: 19539
diff changeset
67 ## nr = incr * frames;
fdb8a62ef17a fix docstring style in .m files
John W. Eaton <jwe@octave.org>
parents: 19539
diff changeset
68 ## left = sin (2.0 * pi * [lphase:incl:lphase+nl]);
fdb8a62ef17a fix docstring style in .m files
John W. Eaton <jwe@octave.org>
parents: 19539
diff changeset
69 ## right = sin (2.0 * pi * [rphase:incr:rphase+nr]);
fdb8a62ef17a fix docstring style in .m files
John W. Eaton <jwe@octave.org>
parents: 19539
diff changeset
70 ## sound = [left', right'];
fdb8a62ef17a fix docstring style in .m files
John W. Eaton <jwe@octave.org>
parents: 19539
diff changeset
71 ## status = 0;
fdb8a62ef17a fix docstring style in .m files
John W. Eaton <jwe@octave.org>
parents: 19539
diff changeset
72 ## lphase = lphase + nl;
fdb8a62ef17a fix docstring style in .m files
John W. Eaton <jwe@octave.org>
parents: 19539
diff changeset
73 ## rphase = rphase + nr;
fdb8a62ef17a fix docstring style in .m files
John W. Eaton <jwe@octave.org>
parents: 19539
diff changeset
74 ## endfunction
fdb8a62ef17a fix docstring style in .m files
John W. Eaton <jwe@octave.org>
parents: 19539
diff changeset
75 ## player = audioplayer (@@callback_sine, 44100);
fdb8a62ef17a fix docstring style in .m files
John W. Eaton <jwe@octave.org>
parents: 19539
diff changeset
76 ## play (player);
fdb8a62ef17a fix docstring style in .m files
John W. Eaton <jwe@octave.org>
parents: 19539
diff changeset
77 ## # play for as long as you want
fdb8a62ef17a fix docstring style in .m files
John W. Eaton <jwe@octave.org>
parents: 19539
diff changeset
78 ## stop (player);
19510
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
79 ## @end group
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
80
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
81 function player = audioplayer (varargin)
19557
5802ea7037d4 style fixes for audioplayer and audiorecorder classes
John W. Eaton <jwe@octave.org>
parents: 19543
diff changeset
82
5802ea7037d4 style fixes for audioplayer and audiorecorder classes
John W. Eaton <jwe@octave.org>
parents: 19543
diff changeset
83 if (nargin < 1 || nargin > 4
5802ea7037d4 style fixes for audioplayer and audiorecorder classes
John W. Eaton <jwe@octave.org>
parents: 19543
diff changeset
84 || (nargin < 2 && (isa (varargin{1}, "function_handle")
5802ea7037d4 style fixes for audioplayer and audiorecorder classes
John W. Eaton <jwe@octave.org>
parents: 19543
diff changeset
85 || ischar (varargin{1}))))
19510
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
86 print_usage ();
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
87 endif
19557
5802ea7037d4 style fixes for audioplayer and audiorecorder classes
John W. Eaton <jwe@octave.org>
parents: 19543
diff changeset
88
5802ea7037d4 style fixes for audioplayer and audiorecorder classes
John W. Eaton <jwe@octave.org>
parents: 19543
diff changeset
89 if (isa (varargin{1}, "audiorecorder"))
5802ea7037d4 style fixes for audioplayer and audiorecorder classes
John W. Eaton <jwe@octave.org>
parents: 19543
diff changeset
90 if (nargin == 1)
19537
36a26a131209 Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents: 19534
diff changeset
91 player = getplayer (varargin{1});
19557
5802ea7037d4 style fixes for audioplayer and audiorecorder classes
John W. Eaton <jwe@octave.org>
parents: 19543
diff changeset
92 elseif (nargin == 2)
19510
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
93 recorder = varargin{1};
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
94 data = getaudiodata (recorder);
19541
dac3191a5301 style fixes for audioplayer and audiorecorder .m files
John W. Eaton <jwe@octave.org>
parents: 19540
diff changeset
95 player = audioplayer (data, get (recorder, "SampleRate"),
dac3191a5301 style fixes for audioplayer and audiorecorder .m files
John W. Eaton <jwe@octave.org>
parents: 19540
diff changeset
96 get (recorder, "BitsPerSample"), varargin{2});
19510
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
97 else
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
98 print_usage ();
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
99 endif
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
100 else
19541
dac3191a5301 style fixes for audioplayer and audiorecorder .m files
John W. Eaton <jwe@octave.org>
parents: 19540
diff changeset
101 if (ischar (varargin{1}))
19537
36a26a131209 Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents: 19534
diff changeset
102 varargin{1} = str2func (varargin{1});
19510
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
103 endif
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
104 player.player = __player_audioplayer__ (varargin{:});
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
105 player = class (player, "audioplayer");
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
106 endif
19557
5802ea7037d4 style fixes for audioplayer and audiorecorder classes
John W. Eaton <jwe@octave.org>
parents: 19543
diff changeset
107
19510
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
108 endfunction
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
109
19562
4f615cd9a68d Use "testif HAVE_PORTAUDIO" for new audio function tests
Andreas Weber <andy.weber.aw@gmail.com>
parents: 19557
diff changeset
110 %!testif HAVE_PORTAUDIO
19543
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19541
diff changeset
111 %! mono = randn (1, 44100) - 0.5;
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19541
diff changeset
112 %! stereo = randn (2, 44100) - 0.5;
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19541
diff changeset
113 %! fs = 44100;
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19541
diff changeset
114 %! player1 = audioplayer (mono, fs);
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19541
diff changeset
115 %! player2 = audioplayer (stereo, fs);
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19541
diff changeset
116 %! assert (player1.NumberOfChannels, 1);
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19541
diff changeset
117 %! assert (player2.NumberOfChannels, 2);
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19541
diff changeset
118 %! assert (player1.SampleRate, 44100);
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19541
diff changeset
119 %! assert (player2.SampleRate, 44100);
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19541
diff changeset
120 %! assert (player1.TotalSamples, 44100);
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19541
diff changeset
121 %! assert (player2.TotalSamples, 44100);
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19541
diff changeset
122 %! playblocking (player1);
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19541
diff changeset
123 %! playblocking (player2);
19510
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
124
19562
4f615cd9a68d Use "testif HAVE_PORTAUDIO" for new audio function tests
Andreas Weber <andy.weber.aw@gmail.com>
parents: 19557
diff changeset
125 %!testif HAVE_PORTAUDIO
19543
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19541
diff changeset
126 %! audio = randn (2, 88200) - 0.5;
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19541
diff changeset
127 %! fs = 44100;
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19541
diff changeset
128 %! player = audioplayer (audio, fs);
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19541
diff changeset
129 %! assert (!isplaying (player));
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19541
diff changeset
130 %! play (player);
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19541
diff changeset
131 %! assert (isplaying (player));
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19541
diff changeset
132 %! sleep (1);
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19541
diff changeset
133 %! pause (player);
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19541
diff changeset
134 %! assert (!isplaying (player));
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19541
diff changeset
135 %! sleep (1);
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19541
diff changeset
136 %! resume (player);
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19541
diff changeset
137 %! assert (isplaying (player));
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19541
diff changeset
138 %! sleep (1);
19510
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
139
19562
4f615cd9a68d Use "testif HAVE_PORTAUDIO" for new audio function tests
Andreas Weber <andy.weber.aw@gmail.com>
parents: 19557
diff changeset
140 %!testif HAVE_PORTAUDIO
19543
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19541
diff changeset
141 %! audio = randn (2, 88200) - 0.5;
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19541
diff changeset
142 %! fs = 44100;
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19541
diff changeset
143 %! player = audioplayer (audio, fs);
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19541
diff changeset
144 %! assert (!isplaying (player));
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19541
diff changeset
145 %! play (player);
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19541
diff changeset
146 %! assert (isplaying (player));
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19541
diff changeset
147 %! sleep (1);
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19541
diff changeset
148 %! stop (player);
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19541
diff changeset
149 %! sleep (1);
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19541
diff changeset
150 %! assert (!isplaying (player));
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19541
diff changeset
151 %! assert (player.CurrentSample, 0);
19510
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
152
19562
4f615cd9a68d Use "testif HAVE_PORTAUDIO" for new audio function tests
Andreas Weber <andy.weber.aw@gmail.com>
parents: 19557
diff changeset
153 %!testif HAVE_PORTAUDIO
19543
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19541
diff changeset
154 %! audio = randn (2, 44100) - 0.5;
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19541
diff changeset
155 %! fs = 44100;
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19541
diff changeset
156 %! player = audioplayer (audio, fs);
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19541
diff changeset
157 %! set (player, {"SampleRate", "Tag", "UserData"}, {8000, "tag", [1, 2; 3, 4]});
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19541
diff changeset
158 %! assert (player.SampleRate, 8000);
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19541
diff changeset
159 %! assert (player.Tag, "tag");
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19541
diff changeset
160 %! assert (player.UserData, [1, 2; 3, 4]);
19510
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
161
19562
4f615cd9a68d Use "testif HAVE_PORTAUDIO" for new audio function tests
Andreas Weber <andy.weber.aw@gmail.com>
parents: 19557
diff changeset
162 %!testif HAVE_PORTAUDIO
19543
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19541
diff changeset
163 %! audio = randn (2, 44100) - 0.5;
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19541
diff changeset
164 %! fs = 44100;
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19541
diff changeset
165 %! player = audioplayer (audio, fs);
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19541
diff changeset
166 %! settable = set (player);
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19541
diff changeset
167 %! settable.SampleRate = 8000;
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19541
diff changeset
168 %! settable.Tag = "tag";
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19541
diff changeset
169 %! settable.UserData = [1, 2; 3, 4];
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19541
diff changeset
170 %! set (player, settable);
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19541
diff changeset
171 %! assert (player.SampleRate, 8000);
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19541
diff changeset
172 %! assert (player.Tag, "tag");
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19541
diff changeset
173 %! assert (player.UserData, [1, 2; 3, 4]);
19510
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
174
19562
4f615cd9a68d Use "testif HAVE_PORTAUDIO" for new audio function tests
Andreas Weber <andy.weber.aw@gmail.com>
parents: 19557
diff changeset
175 %!testif HAVE_PORTAUDIO
19543
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19541
diff changeset
176 %! audio = randn (2, 44100) - 0.5;
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19541
diff changeset
177 %! fs = 44100;
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19541
diff changeset
178 %! player = audioplayer (audio, fs);
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19541
diff changeset
179 %! player.SampleRate = 8000;
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19541
diff changeset
180 %! player.Tag = "tag";
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19541
diff changeset
181 %! player.UserData = [1, 2; 3, 4];
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19541
diff changeset
182 %! properties = get (player, {"SampleRate", "Tag", "UserData"});
2a16dac2176f fix audioplayer tests
John W. Eaton <jwe@octave.org>
parents: 19541
diff changeset
183 %! assert (properties, {8000, "tag", [1, 2; 3, 4]});
19510
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
184
19594
e75df9e43e63 disable Octave audio callback functions
John W. Eaton <jwe@octave.org>
parents: 19562
diff changeset
185 #%!function [sound, status] = callback (samples)
e75df9e43e63 disable Octave audio callback functions
John W. Eaton <jwe@octave.org>
parents: 19562
diff changeset
186 #%! sound = rand (samples, 2) - 0.5;
e75df9e43e63 disable Octave audio callback functions
John W. Eaton <jwe@octave.org>
parents: 19562
diff changeset
187 #%! status = 0;
e75df9e43e63 disable Octave audio callback functions
John W. Eaton <jwe@octave.org>
parents: 19562
diff changeset
188 #%!endfunction
19510
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
189
19594
e75df9e43e63 disable Octave audio callback functions
John W. Eaton <jwe@octave.org>
parents: 19562
diff changeset
190 #%!testif HAVE_PORTAUDIO
e75df9e43e63 disable Octave audio callback functions
John W. Eaton <jwe@octave.org>
parents: 19562
diff changeset
191 #%! player = audioplayer (@callback, 44100);
e75df9e43e63 disable Octave audio callback functions
John W. Eaton <jwe@octave.org>
parents: 19562
diff changeset
192 #%! play (player);
e75df9e43e63 disable Octave audio callback functions
John W. Eaton <jwe@octave.org>
parents: 19562
diff changeset
193 #%! sleep (2);
e75df9e43e63 disable Octave audio callback functions
John W. Eaton <jwe@octave.org>
parents: 19562
diff changeset
194 #%! stop (player);
e75df9e43e63 disable Octave audio callback functions
John W. Eaton <jwe@octave.org>
parents: 19562
diff changeset
195 #%! assert (1);
19510
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
196
19594
e75df9e43e63 disable Octave audio callback functions
John W. Eaton <jwe@octave.org>
parents: 19562
diff changeset
197 #%!testif HAVE_PORTAUDIO
e75df9e43e63 disable Octave audio callback functions
John W. Eaton <jwe@octave.org>
parents: 19562
diff changeset
198 #%! player = audioplayer ("callback", 44100, 16);
e75df9e43e63 disable Octave audio callback functions
John W. Eaton <jwe@octave.org>
parents: 19562
diff changeset
199 #%! play (player);
e75df9e43e63 disable Octave audio callback functions
John W. Eaton <jwe@octave.org>
parents: 19562
diff changeset
200 #%! sleep (2);
e75df9e43e63 disable Octave audio callback functions
John W. Eaton <jwe@octave.org>
parents: 19562
diff changeset
201 #%! stop (player);
e75df9e43e63 disable Octave audio callback functions
John W. Eaton <jwe@octave.org>
parents: 19562
diff changeset
202 #%! assert (1);