Mercurial > octave-antonio
annotate scripts/audio/@audioplayer/audioplayer.m @ 20158:7503499a252b stable
doc: Update docstrings to have one sentence summary as first line.
Update scripts in audio, elfun, general, geometry, and image directories.
* scripts/audio/@audioplayer/__get_properties__.m,
scripts/audio/@audioplayer/audioplayer.m, scripts/audio/@audioplayer/get.m,
scripts/audio/@audioplayer/isplaying.m, scripts/audio/@audioplayer/play.m,
scripts/audio/@audioplayer/playblocking.m, scripts/audio/@audioplayer/set.m,
scripts/audio/@audioplayer/subsasgn.m, scripts/audio/@audioplayer/subsref.m,
scripts/audio/@audiorecorder/audiorecorder.m,
scripts/audio/@audiorecorder/get.m,
scripts/audio/@audiorecorder/getaudiodata.m,
scripts/audio/@audiorecorder/getplayer.m,
scripts/audio/@audiorecorder/isrecording.m,
scripts/audio/@audiorecorder/play.m, scripts/audio/@audiorecorder/record.m,
scripts/audio/@audiorecorder/recordblocking.m,
scripts/audio/@audiorecorder/set.m, scripts/audio/@audiorecorder/stop.m,
scripts/audio/@audiorecorder/subsasgn.m,
scripts/audio/@audiorecorder/subsref.m, scripts/audio/lin2mu.m,
scripts/audio/mu2lin.m, scripts/audio/record.m, scripts/audio/sound.m,
scripts/audio/soundsc.m, scripts/audio/wavread.m, scripts/audio/wavwrite.m,
scripts/elfun/cosd.m, scripts/elfun/sind.m, scripts/elfun/tand.m,
scripts/general/accumarray.m, scripts/general/accumdim.m,
scripts/general/bitcmp.m, scripts/general/bitget.m, scripts/general/bitset.m,
scripts/general/blkdiag.m, scripts/general/cart2pol.m,
scripts/general/cart2sph.m, scripts/general/cell2mat.m,
scripts/general/celldisp.m, scripts/general/chop.m,
scripts/general/circshift.m, scripts/general/common_size.m,
scripts/general/cplxpair.m, scripts/general/cumtrapz.m,
scripts/general/dblquad.m, scripts/general/deal.m, scripts/general/del2.m,
scripts/general/display.m, scripts/general/divergence.m,
scripts/general/fieldnames.m, scripts/general/flip.m,
scripts/general/flipdim.m, scripts/general/fliplr.m, scripts/general/flipud.m,
scripts/general/gradient.m, scripts/general/interp3.m,
scripts/general/interpft.m, scripts/general/interpn.m,
scripts/general/loadobj.m, scripts/general/logspace.m,
scripts/general/methods.m, scripts/general/nargchk.m,
scripts/general/narginchk.m, scripts/general/nargoutchk.m,
scripts/general/nextpow2.m, scripts/general/nthargout.m,
scripts/general/num2str.m, scripts/general/pol2cart.m,
scripts/general/polyarea.m, scripts/general/postpad.m,
scripts/general/prepad.m, scripts/general/profile.m, scripts/general/quadgk.m,
scripts/general/quadl.m, scripts/general/quadv.m, scripts/general/randi.m,
scripts/general/rat.m, scripts/general/repmat.m, scripts/general/rot90.m,
scripts/general/rotdim.m, scripts/general/saveobj.m, scripts/general/shift.m,
scripts/general/shiftdim.m, scripts/general/sortrows.m,
scripts/general/sph2cart.m, scripts/general/structfun.m,
scripts/general/subsindex.m, scripts/general/trapz.m,
scripts/general/triplequad.m, scripts/geometry/delaunayn.m,
scripts/geometry/dsearch.m, scripts/geometry/dsearchn.m,
scripts/geometry/griddata.m, scripts/geometry/griddata3.m,
scripts/geometry/griddatan.m, scripts/geometry/inpolygon.m,
scripts/geometry/rectint.m, scripts/geometry/tsearchn.m,
scripts/geometry/voronoi.m, scripts/geometry/voronoin.m,
scripts/help/__unimplemented__.m, scripts/help/doc.m,
scripts/help/doc_cache_create.m, scripts/help/get_first_help_sentence.m,
scripts/help/help.m, scripts/help/lookfor.m, scripts/help/print_usage.m,
scripts/help/type.m, scripts/help/which.m, scripts/image/autumn.m,
scripts/image/bone.m, scripts/image/brighten.m, scripts/image/cmpermute.m,
scripts/image/colorcube.m, scripts/image/contrast.m, scripts/image/cool.m,
scripts/image/copper.m, scripts/image/cubehelix.m, scripts/image/flag.m,
scripts/image/gmap40.m, scripts/image/gray.m, scripts/image/gray2ind.m,
scripts/image/hot.m, scripts/image/hsv.m, scripts/image/image.m,
scripts/image/imagesc.m, scripts/image/imfinfo.m, scripts/image/imformats.m,
scripts/image/imread.m, scripts/image/imshow.m, scripts/image/imwrite.m,
scripts/image/iscolormap.m, scripts/image/jet.m, scripts/image/lines.m,
scripts/image/ntsc2rgb.m, scripts/image/ocean.m, scripts/image/pink.m,
scripts/image/prism.m, scripts/image/rainbow.m, scripts/image/rgb2ntsc.m,
scripts/image/spinmap.m, scripts/image/spring.m, scripts/image/summer.m,
scripts/image/white.m, scripts/image/winter.m:
Update docstrings to have one sentence summary as first line.
Re-structure to have line lengths <= 80 chars.
author | Rik <rik@octave.org> |
---|---|
date | Sun, 03 May 2015 09:36:20 -0700 |
parents | 9fc020886ae9 |
children |
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:
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 -*- |
19571
72304a4e010a
Use Octave coding conventions for documentation of audio functions.
Rik <rik@octave.org>
parents:
19560
diff
changeset
|
20 ## @deftypefn {Function File} {@var{player} =} audioplayer (@var{y}, @var{fs}) |
19506
fdb8a62ef17a
fix docstring style in .m files
John W. Eaton <jwe@octave.org>
parents:
19505
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:
19505
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:
19505
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:
19505
diff
changeset
|
24 ## @deftypefnx {Function File} {@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 |
19506
fdb8a62ef17a
fix docstring style in .m files
John W. Eaton <jwe@octave.org>
parents:
19505
diff
changeset
|
41 ## y = randn (2, 44100) - 0.5; |
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 ## |
19560
e75df9e43e63
disable Octave audio callback functions
John W. Eaton <jwe@octave.org>
parents:
19528
diff
changeset
|
53 ## @deftypefnx {Function File} {@var{player} =} audioplayer (@var{function}, @dots{}) |
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 |
5802ea7037d4
style fixes for audioplayer and audiorecorder classes
John W. Eaton <jwe@octave.org>
parents:
19509
diff
changeset
|
85 || (nargin < 2 && (isa (varargin{1}, "function_handle") |
5802ea7037d4
style fixes for audioplayer and audiorecorder classes
John W. Eaton <jwe@octave.org>
parents:
19509
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; |
b2fe4dbe5266
Don't play or record audio during 'make check'
Mike Miller <mtmiller@ieee.org>
parents:
19571
diff
changeset
|
114 %! audio = randn (2, 2*fs) - 0.5; |
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); |
b2fe4dbe5266
Don't play or record audio during 'make check'
Mike Miller <mtmiller@ieee.org>
parents:
19571
diff
changeset
|
117 %! sleep (1); |
b2fe4dbe5266
Don't play or record audio during 'make check'
Mike Miller <mtmiller@ieee.org>
parents:
19571
diff
changeset
|
118 %! pause (player); |
b2fe4dbe5266
Don't play or record audio during 'make check'
Mike Miller <mtmiller@ieee.org>
parents:
19571
diff
changeset
|
119 %! sleep (1); |
b2fe4dbe5266
Don't play or record audio during 'make check'
Mike Miller <mtmiller@ieee.org>
parents:
19571
diff
changeset
|
120 %! resume (player); |
b2fe4dbe5266
Don't play or record audio during 'make check'
Mike Miller <mtmiller@ieee.org>
parents:
19571
diff
changeset
|
121 %! sleep (1); |
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 |
19509 | 127 %! mono = randn (1, 44100) - 0.5; |
128 %! stereo = randn (2, 44100) - 0.5; | |
129 %! fs = 44100; | |
130 %! player1 = audioplayer (mono, fs); | |
131 %! player2 = audioplayer (stereo, fs); | |
132 %! assert (player1.NumberOfChannels, 1); | |
133 %! assert (player2.NumberOfChannels, 2); | |
134 %! assert (player1.SampleRate, 44100); | |
135 %! assert (player2.SampleRate, 44100); | |
136 %! assert (player1.TotalSamples, 44100); | |
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 |
19509 | 140 %! audio = randn (2, 44100) - 0.5; |
141 %! fs = 44100; | |
142 %! player = audioplayer (audio, fs); | |
143 %! set (player, {"SampleRate", "Tag", "UserData"}, {8000, "tag", [1, 2; 3, 4]}); | |
144 %! assert (player.SampleRate, 8000); | |
145 %! assert (player.Tag, "tag"); | |
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 |
19509 | 149 %! audio = randn (2, 44100) - 0.5; |
150 %! fs = 44100; | |
151 %! player = audioplayer (audio, fs); | |
152 %! settable = set (player); | |
153 %! settable.SampleRate = 8000; | |
154 %! settable.Tag = "tag"; | |
155 %! settable.UserData = [1, 2; 3, 4]; | |
156 %! set (player, settable); | |
157 %! assert (player.SampleRate, 8000); | |
158 %! assert (player.Tag, "tag"); | |
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 |
19509 | 162 %! audio = randn (2, 44100) - 0.5; |
163 %! fs = 44100; | |
164 %! player = audioplayer (audio, fs); | |
165 %! player.SampleRate = 8000; | |
166 %! player.Tag = "tag"; | |
167 %! player.UserData = [1, 2; 3, 4]; | |
168 %! properties = get (player, {"SampleRate", "Tag", "UserData"}); | |
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); |
e75df9e43e63
disable Octave audio callback functions
John W. Eaton <jwe@octave.org>
parents:
19528
diff
changeset
|
179 #%! sleep (2); |
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); |
e75df9e43e63
disable Octave audio callback functions
John W. Eaton <jwe@octave.org>
parents:
19528
diff
changeset
|
186 #%! sleep (2); |
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); |