Mercurial > octave-antonio
annotate scripts/audio/soundsc.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 |
---|---|
19682
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
1 ## Copyright (C) 2015 Mike Miller |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
2 ## |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
3 ## This file is part of Octave. |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
4 ## |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
5 ## Octave is free software; you can redistribute it and/or modify it |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
6 ## under the terms of the GNU General Public License as published by |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
8 ## your option) any later version. |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
9 ## |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
10 ## Octave is distributed in the hope that it will be useful, but |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
13 ## General Public License for more details. |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
14 ## |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
15 ## You should have received a copy of the GNU General Public License |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
16 ## along with Octave; see the file COPYING. If not, see |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
17 ## <http://www.gnu.org/licenses/>. |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
18 |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
19 ## -*- texinfo -*- |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
20 ## @deftypefn {Function File} {} soundsc (@var{y}) |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
21 ## @deftypefnx {Function File} {} soundsc (@var{y}, @var{fs}) |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
22 ## @deftypefnx {Function File} {} soundsc (@var{y}, @var{fs}, @var{nbits}) |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
23 ## @deftypefnx {Function File} {} soundsc (@dots{}, [@var{ymin}, @var{ymax}]) |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
24 ## Scale the audio data @var{y} and play it at sample rate @var{fs} to the |
20158
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
25 ## default audio device. |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
26 ## |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
27 ## The audio signal @var{y} can be a vector or a two-column array, representing |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
28 ## mono or stereo audio, respectively. |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
29 ## |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
30 ## If @var{fs} is not given, a default sample rate of 8000 samples per second |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
31 ## is used. |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
32 ## |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
33 ## The optional argument @var{nbits} specifies the bit depth to play to the |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
34 ## audio device and defaults to 8 bits. |
19682
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
35 ## |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
36 ## By default, @var{y} is automatically normalized to the range [-1, 1]. If the |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
37 ## range [@var{ymin}, @var{ymax}] is given, then elements of @var{y} that fall |
19795
ca7599ae464d
doc: Grammarcheck documentation ahead of 4.0 release.
Rik <rik@octave.org>
parents:
19682
diff
changeset
|
38 ## within the range @var{ymin} @leq{} @var{y} @leq{} @var{ymax} are scaled to |
ca7599ae464d
doc: Grammarcheck documentation ahead of 4.0 release.
Rik <rik@octave.org>
parents:
19682
diff
changeset
|
39 ## the range [-1, 1] instead. |
19682
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
40 ## |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
41 ## For more control over audio playback, use the @code{audioplayer} class. |
20158
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
42 ## @seealso{sound, record} |
19682
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
43 ## @end deftypefn |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
44 |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
45 function soundsc (y, fs, nbits, yrange) |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
46 |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
47 if (nargin < 1 || nargin > 4) |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
48 print_usage (); |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
49 endif |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
50 |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
51 if (nargin < 4) |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
52 yrange = []; |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
53 endif |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
54 |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
55 if (nargin < 2 || isempty (fs)) |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
56 fs = 8000; |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19795
diff
changeset
|
57 elseif (nargin == 2 && numel (fs) > 1) |
19682
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
58 yrange = fs; |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
59 fs = 8000; |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
60 elseif (! (isscalar (fs) && (fs > 0))) |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
61 error ("soundsc: sample rate FS must be a positive number"); |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
62 endif |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
63 |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
64 if (nargin < 3 || isempty (nbits)) |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
65 nbits = 8; |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19795
diff
changeset
|
66 elseif (nargin == 3 && numel (nbits) > 1) |
19682
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
67 yrange = nbits; |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
68 nbits = 8; |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
69 elseif (! (isscalar (nbits) && (nbits == 8 || nbits == 16 || nbits == 24))) |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
70 error ("soundsc: bit depth NBITS must be 8, 16, or 24"); |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
71 endif |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
72 |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
73 if (isreal (yrange) && (numel (yrange) == 2) && (yrange(1) <= yrange(2))) |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
74 ymin = yrange(1); |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
75 ymax = yrange(2); |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
76 elseif (isempty (yrange)) |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
77 ymin = min (y(:)); |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
78 ymax = max (y(:)); |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
79 else |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
80 error ("soundsc: audio range must be a 2-element [YMIN, YMAX] vector"); |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
81 endif |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
82 |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
83 ymin = double (ymin); |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
84 ymax = double (ymax); |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
85 ymedian = (ymax + ymin) / 2; |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
86 yscale = 2 / (ymax - ymin); |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
87 |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
88 y = (double (y) - ymedian) .* yscale; |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
89 |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
90 play = audioplayer (y, fs, nbits); |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
91 |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
92 playblocking (play); |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
93 |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
94 endfunction |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
95 |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
96 |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
97 ## Tests of soundsc must not actually play anything. |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
98 |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19795
diff
changeset
|
99 ## Test input validation |
19682
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
100 %!error soundsc () |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
101 %!error soundsc (1,2,3,4,5) |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
102 %!error soundsc (1, -1) |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
103 %!error soundsc (1, [], 2) |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
104 %!error soundsc (1, [2 1]) |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
105 %!error soundsc (1, [1 2 3]) |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
106 %!error soundsc (1, 8000, [2 1]) |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
107 %!error soundsc (1, 8000, [1 2 3]) |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
108 %!error soundsc (1, 8000, 8, [2 1]) |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
109 %!error soundsc (1, 8000, 8, [1 2 3]) |
c2478360291f
New functions sound and soundsc
Mike Miller <mtmiller@ieee.org>
parents:
diff
changeset
|
110 |