Mercurial > octave
annotate libinterp/dldfcn/audioread.cc @ 33034:49128bdb9eb2
use explicit lambda-expression captures (bug #65318)
Previously, we recommended using implicit capture by value (if
possible) in all lambda expressions in Octave. However, this choice
causes trouble in the transition period leading up to C++20, when the
meaning changes for capturing 'this' by reference when the default
capture is '='. Since all lambda expressions in Octave only need to
capture a few variables it seems better and relatively easy to simply
name all captured variable explicitly. (The maximum number of
captured variables currently appears to be seven, including 'this',
but the vast majority are capturing just one or two.)
Affected files: Canvas.cc, GLCanvas.cc, QTerminal.cc,
command-widget.cc, documentation.cc, files-dock-widget.cc,
interpreter-qobject.cc, file-editor-tab.cc, file-editor.cc,
octave-qscintilla.cc, main-window.cc, octave-dock-widget.cc,
octave-qobject.cc, set-path-model.cc, settings-dialog.cc,
variable-editor-model.cc, variable-editor.cc, call-stack.cc,
gl2ps-print.cc, graphics.cc, input.cc, interpreter.cc, load-path.cc,
mex.cc, pr-output.cc, strfns.cc, sysdep.cc, __delaunayn__.cc,
audiodevinfo.cc, audioread.cc, oct-parse.yy, pt-eval.cc,
Array-util.cc, Range.h, lo-sysdep.cc, lo-regexp.cc, oct-glob.cc,
oct-string.cc, and url-transfer.cc.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 16 Feb 2024 14:42:54 -0500 |
parents | f53ac65ffba6 |
children |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 //////////////////////////////////////////////////////////////////////// |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 // |
32632
2e484f9f1f18
maint: update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
32195
diff
changeset
|
3 // Copyright (C) 2013-2024 The Octave Project Developers |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
4 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 // See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 // distribution or <https://octave.org/copyright/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
7 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
8 // This file is part of Octave. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
9 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
10 // Octave is free software: you can redistribute it and/or modify it |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
11 // under the terms of the GNU General Public License as published by |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
12 // the Free Software Foundation, either version 3 of the License, or |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
13 // (at your option) any later version. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
14 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
15 // Octave is distributed in the hope that it will be useful, but |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
16 // WITHOUT ANY WARRANTY; without even the implied warranty of |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
18 // GNU General Public License for more details. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
19 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
20 // You should have received a copy of the GNU General Public License |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
21 // along with Octave; see the file COPYING. If not, see |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
22 // <https://www.gnu.org/licenses/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 //////////////////////////////////////////////////////////////////////// |
19500
8bb399569393
Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents:
19498
diff
changeset
|
25 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21712
diff
changeset
|
26 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21200
diff
changeset
|
27 # include "config.h" |
19501
1f551d169db2
Include config.h in audio project source files
Mike Miller <mtmiller@ieee.org>
parents:
19500
diff
changeset
|
28 #endif |
1f551d169db2
Include config.h in audio project source files
Mike Miller <mtmiller@ieee.org>
parents:
19500
diff
changeset
|
29 |
23024
a6a7b054e4ba
Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
30 #include <algorithm> |
19510 | 31 #include <map> |
23024
a6a7b054e4ba
Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
32 #include <string> |
19510 | 33 |
23024
a6a7b054e4ba
Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
34 #include "dMatrix.h" |
a6a7b054e4ba
Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
35 #include "dRowVector.h" |
23873
9ada3f4f4e28
audioinfo: return absolute file name in info structure
Mike Miller <mtmiller@octave.org>
parents:
23868
diff
changeset
|
36 #include "file-ops.h" |
9ada3f4f4e28
audioinfo: return absolute file name in info structure
Mike Miller <mtmiller@octave.org>
parents:
23868
diff
changeset
|
37 #include "file-stat.h" |
19513
4cb4210bd392
use C++ style casts in audio code
John W. Eaton <jwe@octave.org>
parents:
19512
diff
changeset
|
38 #include "oct-locbuf.h" |
19559
701b43ce4467
properly close audio files
John W. Eaton <jwe@octave.org>
parents:
19554
diff
changeset
|
39 #include "unwind-prot.h" |
19513
4cb4210bd392
use C++ style casts in audio code
John W. Eaton <jwe@octave.org>
parents:
19512
diff
changeset
|
40 |
19511
19f75d156ffe
don't include oct.h in Octave source files
John W. Eaton <jwe@octave.org>
parents:
19510
diff
changeset
|
41 #include "defun-dld.h" |
19f75d156ffe
don't include oct.h in Octave source files
John W. Eaton <jwe@octave.org>
parents:
19510
diff
changeset
|
42 #include "error.h" |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21096
diff
changeset
|
43 #include "errwarn.h" |
23024
a6a7b054e4ba
Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
44 #include "ov.h" |
20940
48b2ad5ee801
maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents:
20939
diff
changeset
|
45 #include "ovl.h" |
21709
88657798b650
audioformats: New function to list available audio formats (bug #47464)
Damjan Angelovski <damjangelovski@gmail.com>
parents:
21694
diff
changeset
|
46 #include "pager.h" |
88657798b650
audioformats: New function to list available audio formats (bug #47464)
Damjan Angelovski <damjangelovski@gmail.com>
parents:
21694
diff
changeset
|
47 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21712
diff
changeset
|
48 #if defined (HAVE_SNDFILE) |
21200
fcac5dbbf9ed
maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
49 # include <sndfile.h> |
19473
2e174b5e7703
Fix audiodevinfo, audioinfo, audioread and audiowrite build process
Vytautas Jančauskas <unaudio@gmail.com>
parents:
19468
diff
changeset
|
50 #endif |
19503
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
51 |
31605
e88a07dec498
maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
52 OCTAVE_BEGIN_NAMESPACE(octave) |
29958
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29858
diff
changeset
|
53 |
19503
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
54 DEFUN_DLD (audioread, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
55 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
56 @deftypefn {} {[@var{y}, @var{fs}] =} audioread (@var{filename}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
57 @deftypefnx {} {[@var{y}, @var{fs}] =} audioread (@var{filename}, @var{samples}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
58 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
59 @deftypefnx {} {[@var{y}, @var{fs}] =} audioread (@var{filename}, @var{datatype}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
60 @deftypefnx {} {[@var{y}, @var{fs}] =} audioread (@var{filename}, @var{samples}, @var{datatype}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
61 Read the audio file @var{filename} and return the audio data @var{y} and |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
62 sampling rate @var{fs}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
63 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
64 The audio data is stored as matrix with rows corresponding to audio frames |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
65 and columns corresponding to channels. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
66 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
67 The optional two-element vector argument @var{samples} specifies starting |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
68 and ending frames. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
69 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
70 The optional argument @var{datatype} specifies the datatype to return. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
71 If it is @qcode{"native"}, then the type of data depends on how the data |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
72 is stored in the audio file. |
23866
4f68899f9e5b
doc: improve docstrings for audioformats, audioinfo, audioread, and audiowrite
Mike Miller <mtmiller@octave.org>
parents:
23853
diff
changeset
|
73 @seealso{audiowrite, audioformats, audioinfo} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
74 @end deftypefn */) |
19462
0243b86b3cee
Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
75 { |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21712
diff
changeset
|
76 #if defined (HAVE_SNDFILE) |
19519
e616c2830413
various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents:
19516
diff
changeset
|
77 |
e616c2830413
various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents:
19516
diff
changeset
|
78 int nargin = args.length (); |
e616c2830413
various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents:
19516
diff
changeset
|
79 |
e616c2830413
various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents:
19516
diff
changeset
|
80 if (nargin < 1 || nargin > 3) |
20790
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20578
diff
changeset
|
81 print_usage (); |
19519
e616c2830413
various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents:
19516
diff
changeset
|
82 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20865
diff
changeset
|
83 std::string filename = args(0).xstring_value ("audioread: FILENAME must be a string"); |
19571
72304a4e010a
Use Octave coding conventions for documentation of audio functions.
Rik <rik@octave.org>
parents:
19559
diff
changeset
|
84 |
19462
0243b86b3cee
Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
85 SF_INFO info; |
0243b86b3cee
Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
86 info.format = 0; |
19519
e616c2830413
various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents:
19516
diff
changeset
|
87 SNDFILE *file = sf_open (filename.c_str (), SFM_READ, &info); |
19554
398e42431dcc
improve argument decoding in audioread.cc functions
John W. Eaton <jwe@octave.org>
parents:
19553
diff
changeset
|
88 |
19559
701b43ce4467
properly close audio files
John W. Eaton <jwe@octave.org>
parents:
19554
diff
changeset
|
89 if (! file) |
23963
3dd89a7b92c8
display message from libsndfile if opening files fails (bug #51859)
Markus Mützel <markus.muetzel@gmx.de>
parents:
23873
diff
changeset
|
90 error ("audioread: failed to open input file '%s': %s", |
3dd89a7b92c8
display message from libsndfile if opening files fails (bug #51859)
Markus Mützel <markus.muetzel@gmx.de>
parents:
23873
diff
changeset
|
91 filename.c_str (), sf_strerror (file)); |
19559
701b43ce4467
properly close audio files
John W. Eaton <jwe@octave.org>
parents:
19554
diff
changeset
|
92 |
33034
49128bdb9eb2
use explicit lambda-expression captures (bug #65318)
John W. Eaton <jwe@octave.org>
parents:
32660
diff
changeset
|
93 unwind_action close_open_file ([file] () { sf_close (file); }); |
19559
701b43ce4467
properly close audio files
John W. Eaton <jwe@octave.org>
parents:
19554
diff
changeset
|
94 |
29858
6dc298d3261c
Handle malformed sound headers which do not specify number of frames (bug #60888).
Rik <rik@octave.org>
parents:
29655
diff
changeset
|
95 // FIXME: It would be nicer to use a C++ expandable data container and |
6dc298d3261c
Handle malformed sound headers which do not specify number of frames (bug #60888).
Rik <rik@octave.org>
parents:
29655
diff
changeset
|
96 // read a file of unknown length into memory in chunks and determine the |
6dc298d3261c
Handle malformed sound headers which do not specify number of frames (bug #60888).
Rik <rik@octave.org>
parents:
29655
diff
changeset
|
97 // number of samples after reading. See bug #60888. |
6dc298d3261c
Handle malformed sound headers which do not specify number of frames (bug #60888).
Rik <rik@octave.org>
parents:
29655
diff
changeset
|
98 if (info.frames == SF_COUNT_MAX) |
6dc298d3261c
Handle malformed sound headers which do not specify number of frames (bug #60888).
Rik <rik@octave.org>
parents:
29655
diff
changeset
|
99 error ("audioread: malformed header does not specify number of samples"); |
6dc298d3261c
Handle malformed sound headers which do not specify number of frames (bug #60888).
Rik <rik@octave.org>
parents:
29655
diff
changeset
|
100 |
27414
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
101 OCTAVE_LOCAL_BUFFER (double, data, info.frames * info.channels); |
19554
398e42431dcc
improve argument decoding in audioread.cc functions
John W. Eaton <jwe@octave.org>
parents:
19553
diff
changeset
|
102 |
27414
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
103 sf_read_double (file, data, info.frames * info.channels); |
19519
e616c2830413
various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents:
19516
diff
changeset
|
104 |
19554
398e42431dcc
improve argument decoding in audioread.cc functions
John W. Eaton <jwe@octave.org>
parents:
19553
diff
changeset
|
105 sf_count_t start = 0; |
398e42431dcc
improve argument decoding in audioread.cc functions
John W. Eaton <jwe@octave.org>
parents:
19553
diff
changeset
|
106 sf_count_t end = info.frames; |
398e42431dcc
improve argument decoding in audioread.cc functions
John W. Eaton <jwe@octave.org>
parents:
19553
diff
changeset
|
107 |
19519
e616c2830413
various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents:
19516
diff
changeset
|
108 if ((nargin == 2 && ! args(1).is_string ()) || nargin == 3) |
19462
0243b86b3cee
Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
109 { |
0243b86b3cee
Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
110 RowVector range = args(1).row_vector_value (); |
19519
e616c2830413
various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents:
19516
diff
changeset
|
111 |
20228
00cf2847355d
Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20163
diff
changeset
|
112 if (range.numel () != 2) |
20825
66cd994d1b79
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20790
diff
changeset
|
113 error ("audioread: invalid specification for range of frames"); |
19554
398e42431dcc
improve argument decoding in audioread.cc functions
John W. Eaton <jwe@octave.org>
parents:
19553
diff
changeset
|
114 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
115 double dstart = (math::isinf (range(0)) ? info.frames : range(0)); |
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
116 double dend = (math::isinf (range(1)) ? info.frames : range(1)); |
19554
398e42431dcc
improve argument decoding in audioread.cc functions
John W. Eaton <jwe@octave.org>
parents:
19553
diff
changeset
|
117 |
19811
f24d9486e66b
audioread: Fix sample index argument to be Matlab compatible
Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
118 if (dstart < 1 || dstart > dend || dend > info.frames |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
119 || math::x_nint (dstart) != dstart |
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
120 || math::x_nint (dend) != dend) |
20825
66cd994d1b79
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20790
diff
changeset
|
121 error ("audioread: invalid specification for range of frames"); |
19554
398e42431dcc
improve argument decoding in audioread.cc functions
John W. Eaton <jwe@octave.org>
parents:
19553
diff
changeset
|
122 |
19811
f24d9486e66b
audioread: Fix sample index argument to be Matlab compatible
Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
123 start = dstart - 1; |
19554
398e42431dcc
improve argument decoding in audioread.cc functions
John W. Eaton <jwe@octave.org>
parents:
19553
diff
changeset
|
124 end = dend; |
19462
0243b86b3cee
Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
125 } |
19519
e616c2830413
various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents:
19516
diff
changeset
|
126 |
19554
398e42431dcc
improve argument decoding in audioread.cc functions
John W. Eaton <jwe@octave.org>
parents:
19553
diff
changeset
|
127 sf_count_t items = end - start; |
398e42431dcc
improve argument decoding in audioread.cc functions
John W. Eaton <jwe@octave.org>
parents:
19553
diff
changeset
|
128 |
398e42431dcc
improve argument decoding in audioread.cc functions
John W. Eaton <jwe@octave.org>
parents:
19553
diff
changeset
|
129 Matrix audio (items, info.channels); |
19519
e616c2830413
various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents:
19516
diff
changeset
|
130 |
32660
f53ac65ffba6
maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents:
32632
diff
changeset
|
131 double *paudio = audio.rwdata (); |
19554
398e42431dcc
improve argument decoding in audioread.cc functions
John W. Eaton <jwe@octave.org>
parents:
19553
diff
changeset
|
132 |
398e42431dcc
improve argument decoding in audioread.cc functions
John W. Eaton <jwe@octave.org>
parents:
19553
diff
changeset
|
133 data += start * info.channels; |
398e42431dcc
improve argument decoding in audioread.cc functions
John W. Eaton <jwe@octave.org>
parents:
19553
diff
changeset
|
134 |
398e42431dcc
improve argument decoding in audioread.cc functions
John W. Eaton <jwe@octave.org>
parents:
19553
diff
changeset
|
135 for (int i = 0; i < items; i++) |
19462
0243b86b3cee
Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
136 { |
0243b86b3cee
Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
137 for (int channel = 0; channel < info.channels; channel++) |
19554
398e42431dcc
improve argument decoding in audioread.cc functions
John W. Eaton <jwe@octave.org>
parents:
19553
diff
changeset
|
138 paudio[items*channel+i] = *data++; |
19503
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
139 } |
19513
4cb4210bd392
use C++ style casts in audio code
John W. Eaton <jwe@octave.org>
parents:
19512
diff
changeset
|
140 |
19519
e616c2830413
various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents:
19516
diff
changeset
|
141 octave_value ret_audio; |
e616c2830413
various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents:
19516
diff
changeset
|
142 |
e616c2830413
various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents:
19516
diff
changeset
|
143 if ((nargin == 2 && args(1).is_string ()) || nargin == 3) |
19462
0243b86b3cee
Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
144 { |
0243b86b3cee
Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
145 std::string type; |
19519
e616c2830413
various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents:
19516
diff
changeset
|
146 if (nargin == 3) |
19503
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
147 type = args(2).string_value (); |
19462
0243b86b3cee
Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
148 else |
19503
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
149 type = args(1).string_value (); |
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
150 |
19462
0243b86b3cee
Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
151 if (type == "native") |
0243b86b3cee
Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
152 { |
19675
793d295fed4d
Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19571
diff
changeset
|
153 switch (info.format & SF_FORMAT_SUBMASK) |
793d295fed4d
Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19571
diff
changeset
|
154 { |
793d295fed4d
Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19571
diff
changeset
|
155 case SF_FORMAT_PCM_S8: |
27414
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
156 ret_audio = int8NDArray (audio * 128); |
19675
793d295fed4d
Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19571
diff
changeset
|
157 break; |
793d295fed4d
Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19571
diff
changeset
|
158 case SF_FORMAT_PCM_U8: |
27414
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
159 ret_audio = uint8NDArray (audio * 128 + 128); |
19675
793d295fed4d
Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19571
diff
changeset
|
160 break; |
793d295fed4d
Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19571
diff
changeset
|
161 case SF_FORMAT_PCM_16: |
27414
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
162 ret_audio = int16NDArray (audio * 32768); |
19675
793d295fed4d
Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19571
diff
changeset
|
163 break; |
793d295fed4d
Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19571
diff
changeset
|
164 case SF_FORMAT_PCM_24: |
793d295fed4d
Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19571
diff
changeset
|
165 ret_audio = int32NDArray (audio * 8388608); |
793d295fed4d
Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19571
diff
changeset
|
166 break; |
793d295fed4d
Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19571
diff
changeset
|
167 case SF_FORMAT_PCM_32: |
793d295fed4d
Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19571
diff
changeset
|
168 ret_audio = int32NDArray (audio * 2147483648); |
793d295fed4d
Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19571
diff
changeset
|
169 break; |
25409
4f6c985ca28a
Fix various bugs with audioread, audiowrite, audioinfo (bug #53975).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
170 case SF_FORMAT_FLOAT: |
4f6c985ca28a
Fix various bugs with audioread, audiowrite, audioinfo (bug #53975).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
171 ret_audio = FloatNDArray (audio); |
4f6c985ca28a
Fix various bugs with audioread, audiowrite, audioinfo (bug #53975).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
172 break; |
19675
793d295fed4d
Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19571
diff
changeset
|
173 default: |
793d295fed4d
Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19571
diff
changeset
|
174 ret_audio = audio; |
793d295fed4d
Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19571
diff
changeset
|
175 break; |
793d295fed4d
Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19571
diff
changeset
|
176 } |
19462
0243b86b3cee
Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
177 } |
0243b86b3cee
Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
178 else |
19519
e616c2830413
various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents:
19516
diff
changeset
|
179 ret_audio = audio; |
19462
0243b86b3cee
Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
180 } |
0243b86b3cee
Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
181 else |
19519
e616c2830413
various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents:
19516
diff
changeset
|
182 ret_audio = audio; |
19503
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
183 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20865
diff
changeset
|
184 return ovl (ret_audio, info.samplerate); |
19519
e616c2830413
various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents:
19516
diff
changeset
|
185 |
19468
9161b7653392
compile audio file utilities even when sndfile is not present
Vytautas Jančauskas <unaudio@gmail.com>
parents:
19463
diff
changeset
|
186 #else |
19519
e616c2830413
various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents:
19516
diff
changeset
|
187 |
21691
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21602
diff
changeset
|
188 octave_unused_parameter (args); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21602
diff
changeset
|
189 |
21103
5a83a422d8a7
Don't set 3rd argument to err_disabled_feature within core Octave.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
190 err_disabled_feature ("audioread", |
5a83a422d8a7
Don't set 3rd argument to err_disabled_feature within core Octave.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
191 "reading and writing sound files through libsndfile"); |
19519
e616c2830413
various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents:
19516
diff
changeset
|
192 |
19468
9161b7653392
compile audio file utilities even when sndfile is not present
Vytautas Jančauskas <unaudio@gmail.com>
parents:
19463
diff
changeset
|
193 #endif |
19462
0243b86b3cee
Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
194 } |
19510 | 195 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21712
diff
changeset
|
196 #if defined (HAVE_SNDFILE) |
19526
7f271cef5850
protect all portaudio and sndfile dependent code with #ifdefs
John W. Eaton <jwe@octave.org>
parents:
19519
diff
changeset
|
197 |
19553
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
198 static int |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
199 extension_to_format (const std::string& ext) |
19510 | 200 { |
19553
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
201 static bool initialized = false; |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
202 |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
203 static std::map<std::string, int> table; |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
204 |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
205 if (! initialized) |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
206 { |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
207 table["wav"] = SF_FORMAT_WAV; |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
208 table["aiff"] = SF_FORMAT_AIFF; |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
209 table["au"] = SF_FORMAT_AU; |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
210 table["raw"] = SF_FORMAT_RAW; |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
211 table["paf"] = SF_FORMAT_PAF; |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
212 table["svx"] = SF_FORMAT_SVX; |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
213 table["nist"] = SF_FORMAT_NIST; |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
214 table["voc"] = SF_FORMAT_VOC; |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
215 table["ircam"] = SF_FORMAT_IRCAM; |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
216 table["w64"] = SF_FORMAT_W64; |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
217 table["mat4"] = SF_FORMAT_MAT4; |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
218 table["mat5"] = SF_FORMAT_MAT5; |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
219 table["pvf"] = SF_FORMAT_PVF; |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
220 table["xi"] = SF_FORMAT_XI; |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
221 table["htk"] = SF_FORMAT_HTK; |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
222 table["sds"] = SF_FORMAT_SDS; |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
223 table["avr"] = SF_FORMAT_AVR; |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
224 table["wavex"] = SF_FORMAT_WAVEX; |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
225 table["sd2"] = SF_FORMAT_SD2; |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
226 table["flac"] = SF_FORMAT_FLAC; |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
227 table["caf"] = SF_FORMAT_CAF; |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
228 table["wve"] = SF_FORMAT_WVE; |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
229 table["ogg"] = SF_FORMAT_OGG; |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
230 table["mpc2k"] = SF_FORMAT_MPC2K; |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
231 table["rf64"] = SF_FORMAT_RF64; |
32195
9cb43336c3b3
audiowrite: Allow writing mp3 through libsndfile API (bug #64388).
John Donoghue <john.donoghue@ieee.org>
parents:
31706
diff
changeset
|
232 #if defined (HAVE_LIB_SNDFILE_FORMAT_MP3) |
9cb43336c3b3
audiowrite: Allow writing mp3 through libsndfile API (bug #64388).
John Donoghue <john.donoghue@ieee.org>
parents:
31706
diff
changeset
|
233 table["m1a"] = SF_FORMAT_MPEG; |
9cb43336c3b3
audiowrite: Allow writing mp3 through libsndfile API (bug #64388).
John Donoghue <john.donoghue@ieee.org>
parents:
31706
diff
changeset
|
234 #endif |
19553
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
235 |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
236 initialized = true; |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
237 } |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
238 |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
239 std::map<std::string, int>::const_iterator it = table.find (ext); |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
240 |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
241 return (it != table.end ()) ? it->second : 0; |
19510 | 242 } |
19526
7f271cef5850
protect all portaudio and sndfile dependent code with #ifdefs
John W. Eaton <jwe@octave.org>
parents:
19519
diff
changeset
|
243 |
19510 | 244 #endif |
245 | |
246 DEFUN_DLD (audiowrite, args, , | |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
247 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
248 @deftypefn {} {} audiowrite (@var{filename}, @var{y}, @var{fs}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
249 @deftypefnx {} {} audiowrite (@var{filename}, @var{y}, @var{fs}, @var{name}, @var{value}, @dots{}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
250 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
251 Write audio data from the matrix @var{y} to @var{filename} at sampling rate |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
252 @var{fs} with the file format determined by the file extension. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
253 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
254 Additional name/value argument pairs may be used to specify the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
255 following options: |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
256 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
257 @table @samp |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
258 @item BitsPerSample |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
259 Number of bits per sample. Valid values are 8, 16, 24, and 32. Default is |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
260 16. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
261 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
262 @item BitRate |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
263 Valid argument name, but ignored. Left for compatibility with @sc{matlab}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
264 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
265 @item Quality |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
266 Quality setting for the Ogg Vorbis compressor. Values can range between 0 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
267 and 100 with 100 being the highest quality setting. Default is 75. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
268 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
269 @item Title |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
270 Title for the audio file. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
271 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
272 @item Artist |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
273 Artist name. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
274 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
275 @item Comment |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
276 Comment. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
277 @end table |
23866
4f68899f9e5b
doc: improve docstrings for audioformats, audioinfo, audioread, and audiowrite
Mike Miller <mtmiller@octave.org>
parents:
23853
diff
changeset
|
278 @seealso{audioread, audioformats, audioinfo} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
279 @end deftypefn */) |
19510 | 280 { |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21712
diff
changeset
|
281 #if defined (HAVE_SNDFILE) |
19519
e616c2830413
various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents:
19516
diff
changeset
|
282 |
e616c2830413
various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents:
19516
diff
changeset
|
283 int nargin = args.length (); |
e616c2830413
various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents:
19516
diff
changeset
|
284 |
e616c2830413
various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents:
19516
diff
changeset
|
285 if (nargin < 3) |
20790
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20578
diff
changeset
|
286 print_usage (); |
19519
e616c2830413
various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents:
19516
diff
changeset
|
287 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20865
diff
changeset
|
288 std::string filename = args(0).xstring_value ("audiowrite: FILENAME must be a string"); |
19519
e616c2830413
various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents:
19516
diff
changeset
|
289 |
19812
f9ca80482c41
audiowrite: Scale integer inputs before writing to an audio file
Mike Miller <mtmiller@ieee.org>
parents:
19811
diff
changeset
|
290 double bias = 0.0; |
f9ca80482c41
audiowrite: Scale integer inputs before writing to an audio file
Mike Miller <mtmiller@ieee.org>
parents:
19811
diff
changeset
|
291 double scale = 1.0; |
f9ca80482c41
audiowrite: Scale integer inputs before writing to an audio file
Mike Miller <mtmiller@ieee.org>
parents:
19811
diff
changeset
|
292 |
f9ca80482c41
audiowrite: Scale integer inputs before writing to an audio file
Mike Miller <mtmiller@ieee.org>
parents:
19811
diff
changeset
|
293 if (args(1).is_uint8_type ()) |
27414
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
294 bias = scale = 127.5; |
19812
f9ca80482c41
audiowrite: Scale integer inputs before writing to an audio file
Mike Miller <mtmiller@ieee.org>
parents:
19811
diff
changeset
|
295 else if (args(1).is_int16_type ()) |
27414
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
296 scale = 32768; // 2^15 |
19812
f9ca80482c41
audiowrite: Scale integer inputs before writing to an audio file
Mike Miller <mtmiller@ieee.org>
parents:
19811
diff
changeset
|
297 else if (args(1).is_int32_type ()) |
27414
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
298 scale = 2147483648; // 2^31 |
23580
2230f9e10fb3
maint: Deprecate is_integer_type and replace with isinteger.
Rik <rik@octave.org>
parents:
23459
diff
changeset
|
299 else if (args(1).isinteger ()) |
21129
228b65504557
maint: Eliminate useless statements after err_XXX.
Rik <rik@octave.org>
parents:
21103
diff
changeset
|
300 err_wrong_type_arg ("audiowrite", args(1)); |
19812
f9ca80482c41
audiowrite: Scale integer inputs before writing to an audio file
Mike Miller <mtmiller@ieee.org>
parents:
19811
diff
changeset
|
301 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20865
diff
changeset
|
302 Matrix audio = args(1).matrix_value (); |
19812
f9ca80482c41
audiowrite: Scale integer inputs before writing to an audio file
Mike Miller <mtmiller@ieee.org>
parents:
19811
diff
changeset
|
303 |
27416
602298e76e91
Resolve audiowrite FIXME about input validation for sample rate input FS.
Rik <rik@octave.org>
parents:
27414
diff
changeset
|
304 if (! args(2).is_scalar_type () || ! args(2).isnumeric ()) |
602298e76e91
Resolve audiowrite FIXME about input validation for sample rate input FS.
Rik <rik@octave.org>
parents:
27414
diff
changeset
|
305 error ("audiowrite: sample rate FS must be a positive scalar integer"); |
19553
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
306 int samplerate = args(2).int_value (); |
27416
602298e76e91
Resolve audiowrite FIXME about input validation for sample rate input FS.
Rik <rik@octave.org>
parents:
27414
diff
changeset
|
307 if (samplerate < 1) |
602298e76e91
Resolve audiowrite FIXME about input validation for sample rate input FS.
Rik <rik@octave.org>
parents:
27414
diff
changeset
|
308 error ("audiowrite: sample rate FS must be a positive scalar integer"); |
19519
e616c2830413
various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents:
19516
diff
changeset
|
309 |
19871
ed5ee3f610db
Correct tests using std::string::find_XXX which did not use std::string::npos.
Rik <rik@octave.org>
parents:
19813
diff
changeset
|
310 std::string ext; |
29654
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
311 std::size_t dotpos = filename.find_last_of ('.'); |
19871
ed5ee3f610db
Correct tests using std::string::find_XXX which did not use std::string::npos.
Rik <rik@octave.org>
parents:
19813
diff
changeset
|
312 if (dotpos != std::string::npos) |
ed5ee3f610db
Correct tests using std::string::find_XXX which did not use std::string::npos.
Rik <rik@octave.org>
parents:
19813
diff
changeset
|
313 ext = filename.substr (dotpos + 1); |
19553
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
314 std::transform (ext.begin (), ext.end (), ext.begin (), ::tolower); |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
315 |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
316 sf_count_t items_to_write = audio.rows () * audio.columns (); |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
317 |
19813
879cff0c05dc
audiowrite: Accept a row vector input as a single channel
Mike Miller <mtmiller@ieee.org>
parents:
19812
diff
changeset
|
318 if (audio.rows () == 1) |
879cff0c05dc
audiowrite: Accept a row vector input as a single channel
Mike Miller <mtmiller@ieee.org>
parents:
19812
diff
changeset
|
319 audio = audio.transpose (); |
879cff0c05dc
audiowrite: Accept a row vector input as a single channel
Mike Miller <mtmiller@ieee.org>
parents:
19812
diff
changeset
|
320 |
27414
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
321 OCTAVE_LOCAL_BUFFER (double, data, items_to_write); |
19553
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
322 |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
323 sf_count_t idx = 0; |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
324 for (int i = 0; i < audio.rows (); i++) |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
325 { |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
326 for (int j = 0; j < audio.columns (); j++) |
19812
f9ca80482c41
audiowrite: Scale integer inputs before writing to an audio file
Mike Miller <mtmiller@ieee.org>
parents:
19811
diff
changeset
|
327 { |
f9ca80482c41
audiowrite: Scale integer inputs before writing to an audio file
Mike Miller <mtmiller@ieee.org>
parents:
19811
diff
changeset
|
328 double elem = (audio.xelem (i, j) - bias) / scale; |
f9ca80482c41
audiowrite: Scale integer inputs before writing to an audio file
Mike Miller <mtmiller@ieee.org>
parents:
19811
diff
changeset
|
329 data[idx++] = std::min (std::max (elem, -1.0), 1.0); |
f9ca80482c41
audiowrite: Scale integer inputs before writing to an audio file
Mike Miller <mtmiller@ieee.org>
parents:
19811
diff
changeset
|
330 } |
19553
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
331 } |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
332 |
19510 | 333 SF_INFO info; |
19519
e616c2830413
various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents:
19516
diff
changeset
|
334 |
21602
47c76e56a1de
maint: Remove extra space between end of statement and semicolon.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
335 memset (&info, 0, sizeof (info)); |
19513
4cb4210bd392
use C++ style casts in audio code
John W. Eaton <jwe@octave.org>
parents:
19512
diff
changeset
|
336 |
19553
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
337 sf_count_t chunk_size = 0; |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
338 |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
339 if (ext == "ogg") |
19510 | 340 { |
19553
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
341 info.format = SF_FORMAT_VORBIS; |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
342 |
25572
64bcc3ab2f6a
Write audio OGG files in smaller chunk sizes (bug #54280).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
343 // FIXME: There seems to be a bug writing ogg files in one shot that |
64bcc3ab2f6a
Write audio OGG files in smaller chunk sizes (bug #54280).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
344 // causes a segfault: https://bugs.debian.org/760898. |
64bcc3ab2f6a
Write audio OGG files in smaller chunk sizes (bug #54280).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
345 // Breaking it up into a series of smaller chunks appears to avoid the |
64bcc3ab2f6a
Write audio OGG files in smaller chunk sizes (bug #54280).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
346 // problem and produces valid files. |
64bcc3ab2f6a
Write audio OGG files in smaller chunk sizes (bug #54280).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
347 chunk_size = 0x100000; |
19510 | 348 } |
32195
9cb43336c3b3
audiowrite: Allow writing mp3 through libsndfile API (bug #64388).
John Donoghue <john.donoghue@ieee.org>
parents:
31706
diff
changeset
|
349 #if defined (HAVE_LIB_SNDFILE_FORMAT_MP3) |
9cb43336c3b3
audiowrite: Allow writing mp3 through libsndfile API (bug #64388).
John Donoghue <john.donoghue@ieee.org>
parents:
31706
diff
changeset
|
350 else if (ext == "mp1") |
9cb43336c3b3
audiowrite: Allow writing mp3 through libsndfile API (bug #64388).
John Donoghue <john.donoghue@ieee.org>
parents:
31706
diff
changeset
|
351 info.format = SF_FORMAT_MPEG|SF_FORMAT_MPEG_LAYER_I; |
9cb43336c3b3
audiowrite: Allow writing mp3 through libsndfile API (bug #64388).
John Donoghue <john.donoghue@ieee.org>
parents:
31706
diff
changeset
|
352 else if (ext == "mp2") |
9cb43336c3b3
audiowrite: Allow writing mp3 through libsndfile API (bug #64388).
John Donoghue <john.donoghue@ieee.org>
parents:
31706
diff
changeset
|
353 info.format = SF_FORMAT_MPEG|SF_FORMAT_MPEG_LAYER_II; |
9cb43336c3b3
audiowrite: Allow writing mp3 through libsndfile API (bug #64388).
John Donoghue <john.donoghue@ieee.org>
parents:
31706
diff
changeset
|
354 else if (ext == "mp3") |
9cb43336c3b3
audiowrite: Allow writing mp3 through libsndfile API (bug #64388).
John Donoghue <john.donoghue@ieee.org>
parents:
31706
diff
changeset
|
355 info.format = SF_FORMAT_MPEG|SF_FORMAT_MPEG_LAYER_III; |
9cb43336c3b3
audiowrite: Allow writing mp3 through libsndfile API (bug #64388).
John Donoghue <john.donoghue@ieee.org>
parents:
31706
diff
changeset
|
356 #endif |
19510 | 357 else |
358 info.format = SF_FORMAT_PCM_16; | |
359 | |
19553
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
360 info.channels = audio.columns (); |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
361 info.samplerate = samplerate; |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
362 info.format |= extension_to_format (ext); |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
363 |
19510 | 364 std::string title = ""; |
365 std::string artist = ""; | |
366 std::string comment = ""; | |
23868
ff9758331d78
audiowrite: add support for Quality option on Ogg Vorbis files (bug #51704)
Mike Miller <mtmiller@octave.org>
parents:
23866
diff
changeset
|
367 double quality = 0.75; |
ff9758331d78
audiowrite: add support for Quality option on Ogg Vorbis files (bug #51704)
Mike Miller <mtmiller@octave.org>
parents:
23866
diff
changeset
|
368 |
19519
e616c2830413
various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents:
19516
diff
changeset
|
369 for (int i = 3; i < nargin; i += 2) |
19510 | 370 { |
21693
2c6d1ef071d1
avoid crash in audiowrite argument processing (bug #47875)
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
371 if (i >= nargin - 1) |
2c6d1ef071d1
avoid crash in audiowrite argument processing (bug #47875)
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
372 error ("audiowrite: invalid number of arguments"); |
2c6d1ef071d1
avoid crash in audiowrite argument processing (bug #47875)
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
373 |
23853
f8660521678e
audiowrite: improve keyword option validation and error reporting
Mike Miller <mtmiller@octave.org>
parents:
23807
diff
changeset
|
374 std::string keyword_orig = args(i).string_value (); |
f8660521678e
audiowrite: improve keyword option validation and error reporting
Mike Miller <mtmiller@octave.org>
parents:
23807
diff
changeset
|
375 std::string keyword = args(i).xtolower ().string_value (); |
21693
2c6d1ef071d1
avoid crash in audiowrite argument processing (bug #47875)
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
376 octave_value value_arg = args(i+1); |
2c6d1ef071d1
avoid crash in audiowrite argument processing (bug #47875)
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
377 |
23853
f8660521678e
audiowrite: improve keyword option validation and error reporting
Mike Miller <mtmiller@octave.org>
parents:
23807
diff
changeset
|
378 if (keyword == "bitspersample") |
19510 | 379 { |
19675
793d295fed4d
Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19571
diff
changeset
|
380 info.format &= ~SF_FORMAT_SUBMASK; |
21693
2c6d1ef071d1
avoid crash in audiowrite argument processing (bug #47875)
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
381 int bits = value_arg.int_value (); |
19510 | 382 if (bits == 8) |
19675
793d295fed4d
Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19571
diff
changeset
|
383 { |
793d295fed4d
Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19571
diff
changeset
|
384 if ((info.format & SF_FORMAT_TYPEMASK) == SF_FORMAT_WAV) |
793d295fed4d
Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19571
diff
changeset
|
385 info.format |= SF_FORMAT_PCM_U8; |
793d295fed4d
Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19571
diff
changeset
|
386 else |
793d295fed4d
Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19571
diff
changeset
|
387 info.format |= SF_FORMAT_PCM_S8; |
793d295fed4d
Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19571
diff
changeset
|
388 } |
19510 | 389 else if (bits == 16) |
390 info.format |= SF_FORMAT_PCM_16; | |
391 else if (bits == 24) | |
25409
4f6c985ca28a
Fix various bugs with audioread, audiowrite, audioinfo (bug #53975).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
392 { |
4f6c985ca28a
Fix various bugs with audioread, audiowrite, audioinfo (bug #53975).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
393 if ((info.format & SF_FORMAT_TYPEMASK) == SF_FORMAT_WAV) |
4f6c985ca28a
Fix various bugs with audioread, audiowrite, audioinfo (bug #53975).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
394 info.format |= SF_FORMAT_PCM_32; |
4f6c985ca28a
Fix various bugs with audioread, audiowrite, audioinfo (bug #53975).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
395 else |
4f6c985ca28a
Fix various bugs with audioread, audiowrite, audioinfo (bug #53975).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
396 info.format |= SF_FORMAT_PCM_24; |
4f6c985ca28a
Fix various bugs with audioread, audiowrite, audioinfo (bug #53975).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
397 } |
19510 | 398 else if (bits == 32) |
24006
d21de523dbce
Write WAV files of 32-bits in FLOAT format rather than PCM_32 (bug #45490).
Rik <rik@octave.org>
parents:
23963
diff
changeset
|
399 { |
d21de523dbce
Write WAV files of 32-bits in FLOAT format rather than PCM_32 (bug #45490).
Rik <rik@octave.org>
parents:
23963
diff
changeset
|
400 if ((info.format & SF_FORMAT_TYPEMASK) == SF_FORMAT_WAV |
d21de523dbce
Write WAV files of 32-bits in FLOAT format rather than PCM_32 (bug #45490).
Rik <rik@octave.org>
parents:
23963
diff
changeset
|
401 && args(1).isfloat ()) |
d21de523dbce
Write WAV files of 32-bits in FLOAT format rather than PCM_32 (bug #45490).
Rik <rik@octave.org>
parents:
23963
diff
changeset
|
402 info.format |= SF_FORMAT_FLOAT; |
d21de523dbce
Write WAV files of 32-bits in FLOAT format rather than PCM_32 (bug #45490).
Rik <rik@octave.org>
parents:
23963
diff
changeset
|
403 else |
d21de523dbce
Write WAV files of 32-bits in FLOAT format rather than PCM_32 (bug #45490).
Rik <rik@octave.org>
parents:
23963
diff
changeset
|
404 info.format |= SF_FORMAT_PCM_32; |
d21de523dbce
Write WAV files of 32-bits in FLOAT format rather than PCM_32 (bug #45490).
Rik <rik@octave.org>
parents:
23963
diff
changeset
|
405 } |
d21de523dbce
Write WAV files of 32-bits in FLOAT format rather than PCM_32 (bug #45490).
Rik <rik@octave.org>
parents:
23963
diff
changeset
|
406 else if (bits == 64) |
d21de523dbce
Write WAV files of 32-bits in FLOAT format rather than PCM_32 (bug #45490).
Rik <rik@octave.org>
parents:
23963
diff
changeset
|
407 info.format |= SF_FORMAT_DOUBLE; |
19510 | 408 else |
20825
66cd994d1b79
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20790
diff
changeset
|
409 error ("audiowrite: wrong number of bits specified"); |
19510 | 410 } |
23853
f8660521678e
audiowrite: improve keyword option validation and error reporting
Mike Miller <mtmiller@octave.org>
parents:
23807
diff
changeset
|
411 else if (keyword == "bitrate") |
f8660521678e
audiowrite: improve keyword option validation and error reporting
Mike Miller <mtmiller@octave.org>
parents:
23807
diff
changeset
|
412 warning_with_id ("Octave:audiowrite:unused-parameter", |
f8660521678e
audiowrite: improve keyword option validation and error reporting
Mike Miller <mtmiller@octave.org>
parents:
23807
diff
changeset
|
413 "audiowrite: 'BitRate' accepted for Matlab " |
f8660521678e
audiowrite: improve keyword option validation and error reporting
Mike Miller <mtmiller@octave.org>
parents:
23807
diff
changeset
|
414 "compatibility, but is ignored"); |
f8660521678e
audiowrite: improve keyword option validation and error reporting
Mike Miller <mtmiller@octave.org>
parents:
23807
diff
changeset
|
415 else if (keyword == "quality") |
23868
ff9758331d78
audiowrite: add support for Quality option on Ogg Vorbis files (bug #51704)
Mike Miller <mtmiller@octave.org>
parents:
23866
diff
changeset
|
416 { |
24006
d21de523dbce
Write WAV files of 32-bits in FLOAT format rather than PCM_32 (bug #45490).
Rik <rik@octave.org>
parents:
23963
diff
changeset
|
417 if (! value_arg.is_scalar_type ()) |
d21de523dbce
Write WAV files of 32-bits in FLOAT format rather than PCM_32 (bug #45490).
Rik <rik@octave.org>
parents:
23963
diff
changeset
|
418 error ("audiowrite: Quality value must be a scalar"); |
d21de523dbce
Write WAV files of 32-bits in FLOAT format rather than PCM_32 (bug #45490).
Rik <rik@octave.org>
parents:
23963
diff
changeset
|
419 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
420 double value = |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
421 value_arg.xdouble_value ("audiowrite: Quality value must be a numeric scalar between 0 and 100"); |
23868
ff9758331d78
audiowrite: add support for Quality option on Ogg Vorbis files (bug #51704)
Mike Miller <mtmiller@octave.org>
parents:
23866
diff
changeset
|
422 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
423 if (math::isnan (value) || value < 0 || value > 100) |
24006
d21de523dbce
Write WAV files of 32-bits in FLOAT format rather than PCM_32 (bug #45490).
Rik <rik@octave.org>
parents:
23963
diff
changeset
|
424 error ("audiowrite: Quality value must be a number between 0 and 100"); |
23868
ff9758331d78
audiowrite: add support for Quality option on Ogg Vorbis files (bug #51704)
Mike Miller <mtmiller@octave.org>
parents:
23866
diff
changeset
|
425 |
ff9758331d78
audiowrite: add support for Quality option on Ogg Vorbis files (bug #51704)
Mike Miller <mtmiller@octave.org>
parents:
23866
diff
changeset
|
426 quality = value / 100; |
ff9758331d78
audiowrite: add support for Quality option on Ogg Vorbis files (bug #51704)
Mike Miller <mtmiller@octave.org>
parents:
23866
diff
changeset
|
427 } |
23853
f8660521678e
audiowrite: improve keyword option validation and error reporting
Mike Miller <mtmiller@octave.org>
parents:
23807
diff
changeset
|
428 else if (keyword == "title") |
21693
2c6d1ef071d1
avoid crash in audiowrite argument processing (bug #47875)
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
429 title = value_arg.string_value (); |
23853
f8660521678e
audiowrite: improve keyword option validation and error reporting
Mike Miller <mtmiller@octave.org>
parents:
23807
diff
changeset
|
430 else if (keyword == "artist") |
21693
2c6d1ef071d1
avoid crash in audiowrite argument processing (bug #47875)
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
431 artist = value_arg.string_value (); |
23853
f8660521678e
audiowrite: improve keyword option validation and error reporting
Mike Miller <mtmiller@octave.org>
parents:
23807
diff
changeset
|
432 else if (keyword == "comment") |
21693
2c6d1ef071d1
avoid crash in audiowrite argument processing (bug #47875)
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
433 comment = value_arg.string_value (); |
19510 | 434 else |
23853
f8660521678e
audiowrite: improve keyword option validation and error reporting
Mike Miller <mtmiller@octave.org>
parents:
23807
diff
changeset
|
435 error ("audiowrite: unrecognized option: '%s'", keyword_orig.c_str ()); |
19510 | 436 } |
19519
e616c2830413
various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents:
19516
diff
changeset
|
437 |
19559
701b43ce4467
properly close audio files
John W. Eaton <jwe@octave.org>
parents:
19554
diff
changeset
|
438 SNDFILE *file = sf_open (filename.c_str (), SFM_WRITE, &info); |
19519
e616c2830413
various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents:
19516
diff
changeset
|
439 |
19553
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
440 if (! file) |
23963
3dd89a7b92c8
display message from libsndfile if opening files fails (bug #51859)
Markus Mützel <markus.muetzel@gmx.de>
parents:
23873
diff
changeset
|
441 error ("audiowrite: failed to open output file '%s': %s", |
3dd89a7b92c8
display message from libsndfile if opening files fails (bug #51859)
Markus Mützel <markus.muetzel@gmx.de>
parents:
23873
diff
changeset
|
442 filename.c_str (), sf_strerror (file)); |
19519
e616c2830413
various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents:
19516
diff
changeset
|
443 |
33034
49128bdb9eb2
use explicit lambda-expression captures (bug #65318)
John W. Eaton <jwe@octave.org>
parents:
32660
diff
changeset
|
444 unwind_action close_open_file ([file] () { sf_close (file); }); |
19559
701b43ce4467
properly close audio files
John W. Eaton <jwe@octave.org>
parents:
19554
diff
changeset
|
445 |
28223
45763d59cb4f
use nullptr instead of NULL or 0 in a few more places
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
446 sf_command (file, SFC_SET_NORM_DOUBLE, nullptr, SF_TRUE); |
45763d59cb4f
use nullptr instead of NULL or 0 in a few more places
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
447 sf_command (file, SFC_SET_CLIPPING, nullptr, SF_TRUE) ; |
23868
ff9758331d78
audiowrite: add support for Quality option on Ogg Vorbis files (bug #51704)
Mike Miller <mtmiller@octave.org>
parents:
23866
diff
changeset
|
448 sf_command (file, SFC_SET_VBR_ENCODING_QUALITY, &quality, sizeof (quality)); |
ff9758331d78
audiowrite: add support for Quality option on Ogg Vorbis files (bug #51704)
Mike Miller <mtmiller@octave.org>
parents:
23866
diff
changeset
|
449 |
19510 | 450 if (title != "") |
451 sf_set_string (file, SF_STR_TITLE, title.c_str ()); | |
19519
e616c2830413
various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents:
19516
diff
changeset
|
452 |
19510 | 453 if (artist != "") |
454 sf_set_string (file, SF_STR_ARTIST, artist.c_str ()); | |
19519
e616c2830413
various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents:
19516
diff
changeset
|
455 |
19510 | 456 if (comment != "") |
457 sf_set_string (file, SF_STR_COMMENT, comment.c_str ()); | |
19519
e616c2830413
various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents:
19516
diff
changeset
|
458 |
19553
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
459 sf_count_t total_items_written = 0; |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
460 sf_count_t offset = 0; |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
461 |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
462 if (chunk_size == 0) |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
463 chunk_size = items_to_write; |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
464 |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
465 while (total_items_written < items_to_write) |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
466 { |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
467 if (items_to_write - offset < chunk_size) |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
468 chunk_size = items_to_write - offset; |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
469 |
27414
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
470 sf_count_t items_written = sf_write_double (file, data+offset, chunk_size); |
19553
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
471 |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
472 if (items_written != chunk_size) |
26162
ef1ef6364a6a
Silence compiler warnings about incorrect format specifiers cross-compiling (bug #55046).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25573
diff
changeset
|
473 error ("audiowrite: write failed, wrote %" PRId64 " of %" PRId64 |
ef1ef6364a6a
Silence compiler warnings about incorrect format specifiers cross-compiling (bug #55046).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25573
diff
changeset
|
474 " items\n", items_written, chunk_size); |
19553
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
475 |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
476 total_items_written += items_written; |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
477 offset += chunk_size; |
57efd0a020cf
write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents:
19544
diff
changeset
|
478 } |
19519
e616c2830413
various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents:
19516
diff
changeset
|
479 |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
480 // FIXME: Shouldn't we return something to indicate whether the file |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
481 // was written successfully? On the other hand, Matlab doesn't |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
482 // return anything. |
20941
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
483 return ovl (); |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20865
diff
changeset
|
484 |
19510 | 485 #else |
19519
e616c2830413
various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents:
19516
diff
changeset
|
486 |
21691
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21602
diff
changeset
|
487 octave_unused_parameter (args); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21602
diff
changeset
|
488 |
21103
5a83a422d8a7
Don't set 3rd argument to err_disabled_feature within core Octave.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
489 err_disabled_feature ("audiowrite", |
5a83a422d8a7
Don't set 3rd argument to err_disabled_feature within core Octave.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
490 "reading and writing sound files through libsndfile"); |
19519
e616c2830413
various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents:
19516
diff
changeset
|
491 |
19510 | 492 #endif |
493 } | |
494 | |
24006
d21de523dbce
Write WAV files of 32-bits in FLOAT format rather than PCM_32 (bug #45490).
Rik <rik@octave.org>
parents:
23963
diff
changeset
|
495 /* |
27414
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
496 ## Joint audiowrite/audioread tests |
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
497 ## 8-bit Unsigned PCM |
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
498 %!testif HAVE_SNDFILE <*56889> |
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
499 %! fname = [tempname() ".wav"]; |
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
500 %! unwind_protect |
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
501 %! y1 = uint8 ([0, 1, 2, 253, 254, 255]); |
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
502 %! audiowrite (fname, y1, 8000, "BitsPerSample", 8); |
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
503 %! y2 = audioread (fname, "native"); |
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
504 %! unwind_protect_cleanup |
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
505 %! unlink (fname); |
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
506 %! end_unwind_protect |
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
507 %! assert (y1(:), y2); |
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
508 |
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
509 ## 8-bit Signed PCM |
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
510 %!testif HAVE_SNDFILE <*56889> |
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
511 %! fname = [tempname() ".au"]; |
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
512 %! unwind_protect |
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
513 %! y1 = uint8 ([0, 1, 2, 253, 254, 255]); |
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
514 %! audiowrite (fname, y1, 8000, "BitsPerSample", 8); |
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
515 %! y2 = audioread (fname, "native"); |
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
516 %! unwind_protect_cleanup |
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
517 %! unlink (fname); |
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
518 %! end_unwind_protect |
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
519 %! assert (y2, int8 ([-128; -127; -126; 125; 126; 127])); |
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
520 |
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
521 ## 16-bit Signed PCM |
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
522 %!testif HAVE_SNDFILE <*56889> |
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
523 %! fname = [tempname() ".wav"]; |
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
524 %! unwind_protect |
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
525 %! y1 = int16 ([-32768, -32767, -32766, 32765, 32766, 32767]); |
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
526 %! audiowrite (fname, y1, 8000, "BitsPerSample", 16); |
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
527 %! y2 = audioread (fname, "native"); |
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
528 %! unwind_protect_cleanup |
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
529 %! unlink (fname); |
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
530 %! end_unwind_protect |
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
531 %! assert (y1(:), y2); |
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
532 |
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
533 ## 24-bit Signed PCM |
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
534 %!testif HAVE_SNDFILE <*56889> |
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
535 %! fname = [tempname() ".au"]; |
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
536 %! unwind_protect |
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
537 %! y1 = [-8388608, -8388607, -8388606, 8388605, 8388606, 8388607] / 8388608; |
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
538 %! audiowrite (fname, y1, 8000, "BitsPerSample", 24); |
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
539 %! y2 = audioread (fname, "native"); |
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
540 %! unwind_protect_cleanup |
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
541 %! unlink (fname); |
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
542 %! end_unwind_protect |
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
543 %! assert (int32 ([-8388608; -8388607; -8388606; 8388605; 8388606; 8388607]), |
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
544 %! y2); |
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
545 |
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
546 ## 32-bit Signed PCM |
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
547 %!testif HAVE_SNDFILE <*56889> |
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
548 %! fname = [tempname() ".wav"]; |
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
549 %! unwind_protect |
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
550 %! y1 = int32 ([-2147483648, -2147483647, -2147483646, 2147483645, 2147483646, 2147483647 ]); |
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
551 %! audiowrite (fname, y1, 8000, "BitsPerSample", 32); |
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
552 %! y2 = audioread (fname, "native"); |
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
553 %! unwind_protect_cleanup |
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
554 %! unlink (fname); |
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
555 %! end_unwind_protect |
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
556 %! assert (y1(:), y2); |
5283c505f92b
Fix numerous errors in audiowrite/audioread (bug #56889).
Rik <rik@octave.org>
parents:
26387
diff
changeset
|
557 |
24006
d21de523dbce
Write WAV files of 32-bits in FLOAT format rather than PCM_32 (bug #45490).
Rik <rik@octave.org>
parents:
23963
diff
changeset
|
558 ## Test input validation |
d21de523dbce
Write WAV files of 32-bits in FLOAT format rather than PCM_32 (bug #45490).
Rik <rik@octave.org>
parents:
23963
diff
changeset
|
559 %!testif HAVE_SNDFILE |
d21de523dbce
Write WAV files of 32-bits in FLOAT format rather than PCM_32 (bug #45490).
Rik <rik@octave.org>
parents:
23963
diff
changeset
|
560 %! fail ("audiowrite (1, 1, 8e3)", "FILENAME must be a string"); |
30346
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
29961
diff
changeset
|
561 %! fail ("audiowrite ('foo', int64 (1), 8e3)", |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
29961
diff
changeset
|
562 %! "wrong type argument 'int64 scalar'"); |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
29961
diff
changeset
|
563 %! fail ("audiowrite ('foo', [0 1], [8e3, 8e3])", |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
29961
diff
changeset
|
564 %! "FS must be a positive scalar"); |
27416
602298e76e91
Resolve audiowrite FIXME about input validation for sample rate input FS.
Rik <rik@octave.org>
parents:
27414
diff
changeset
|
565 %! fail ("audiowrite ('foo', 1, {8e3})", "FS must be a .* integer"); |
602298e76e91
Resolve audiowrite FIXME about input validation for sample rate input FS.
Rik <rik@octave.org>
parents:
27414
diff
changeset
|
566 %! fail ("audiowrite ('foo', 1, -8e3)", "FS must be a positive"); |
30346
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
29961
diff
changeset
|
567 %! fail ("audiowrite ('foo', 1, 8e3, 'bitspersample')", |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
29961
diff
changeset
|
568 %! "invalid number of arguments"); |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
29961
diff
changeset
|
569 %! fail ("audiowrite ('foo', 1, 8e3, 'bitspersample', 48)", |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
29961
diff
changeset
|
570 %! "wrong number of bits specified"); |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
29961
diff
changeset
|
571 %! fail ("audiowrite ('foo', 1, 8e3, 'quality', [2 3 4])", |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
29961
diff
changeset
|
572 %! "Quality value must be a scalar"); |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
29961
diff
changeset
|
573 %! fail ("audiowrite ('foo', 1, 8e3, 'quality', NaN)", |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
29961
diff
changeset
|
574 %! "Quality value must be .* between 0 and 100"); |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
29961
diff
changeset
|
575 %! fail ("audiowrite ('foo', 1, 8e3, 'quality', -1)", |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
29961
diff
changeset
|
576 %! "Quality value must be .* between 0 and 100"); |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
29961
diff
changeset
|
577 %! fail ("audiowrite ('foo', 1, 8e3, 'quality', 101)", |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
29961
diff
changeset
|
578 %! "Quality value must be .* between 0 and 100"); |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
29961
diff
changeset
|
579 %! fail ("audiowrite ('foo', 1, 8e3, 'foo', 'bar')", |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
29961
diff
changeset
|
580 %! "unrecognized option: 'foo'"); |
24006
d21de523dbce
Write WAV files of 32-bits in FLOAT format rather than PCM_32 (bug #45490).
Rik <rik@octave.org>
parents:
23963
diff
changeset
|
581 */ |
d21de523dbce
Write WAV files of 32-bits in FLOAT format rather than PCM_32 (bug #45490).
Rik <rik@octave.org>
parents:
23963
diff
changeset
|
582 |
19510 | 583 DEFUN_DLD (audioinfo, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
584 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
585 @deftypefn {} {@var{info} =} audioinfo (@var{filename}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
586 Return information about an audio file specified by @var{filename}. |
23866
4f68899f9e5b
doc: improve docstrings for audioformats, audioinfo, audioread, and audiowrite
Mike Miller <mtmiller@octave.org>
parents:
23853
diff
changeset
|
587 |
4f68899f9e5b
doc: improve docstrings for audioformats, audioinfo, audioread, and audiowrite
Mike Miller <mtmiller@octave.org>
parents:
23853
diff
changeset
|
588 The output @var{info} is a structure containing the following fields: |
4f68899f9e5b
doc: improve docstrings for audioformats, audioinfo, audioread, and audiowrite
Mike Miller <mtmiller@octave.org>
parents:
23853
diff
changeset
|
589 |
4f68899f9e5b
doc: improve docstrings for audioformats, audioinfo, audioread, and audiowrite
Mike Miller <mtmiller@octave.org>
parents:
23853
diff
changeset
|
590 @table @samp |
4f68899f9e5b
doc: improve docstrings for audioformats, audioinfo, audioread, and audiowrite
Mike Miller <mtmiller@octave.org>
parents:
23853
diff
changeset
|
591 @item Filename |
4f68899f9e5b
doc: improve docstrings for audioformats, audioinfo, audioread, and audiowrite
Mike Miller <mtmiller@octave.org>
parents:
23853
diff
changeset
|
592 Name of the audio file. |
4f68899f9e5b
doc: improve docstrings for audioformats, audioinfo, audioread, and audiowrite
Mike Miller <mtmiller@octave.org>
parents:
23853
diff
changeset
|
593 |
4f68899f9e5b
doc: improve docstrings for audioformats, audioinfo, audioread, and audiowrite
Mike Miller <mtmiller@octave.org>
parents:
23853
diff
changeset
|
594 @item CompressionMethod |
4f68899f9e5b
doc: improve docstrings for audioformats, audioinfo, audioread, and audiowrite
Mike Miller <mtmiller@octave.org>
parents:
23853
diff
changeset
|
595 Audio compression method. Unused, only present for compatibility with |
4f68899f9e5b
doc: improve docstrings for audioformats, audioinfo, audioread, and audiowrite
Mike Miller <mtmiller@octave.org>
parents:
23853
diff
changeset
|
596 @sc{matlab}. |
4f68899f9e5b
doc: improve docstrings for audioformats, audioinfo, audioread, and audiowrite
Mike Miller <mtmiller@octave.org>
parents:
23853
diff
changeset
|
597 |
4f68899f9e5b
doc: improve docstrings for audioformats, audioinfo, audioread, and audiowrite
Mike Miller <mtmiller@octave.org>
parents:
23853
diff
changeset
|
598 @item NumChannels |
4f68899f9e5b
doc: improve docstrings for audioformats, audioinfo, audioread, and audiowrite
Mike Miller <mtmiller@octave.org>
parents:
23853
diff
changeset
|
599 Number of audio channels. |
4f68899f9e5b
doc: improve docstrings for audioformats, audioinfo, audioread, and audiowrite
Mike Miller <mtmiller@octave.org>
parents:
23853
diff
changeset
|
600 |
4f68899f9e5b
doc: improve docstrings for audioformats, audioinfo, audioread, and audiowrite
Mike Miller <mtmiller@octave.org>
parents:
23853
diff
changeset
|
601 @item SampleRate |
4f68899f9e5b
doc: improve docstrings for audioformats, audioinfo, audioread, and audiowrite
Mike Miller <mtmiller@octave.org>
parents:
23853
diff
changeset
|
602 Sample rate of the audio, in Hertz. |
4f68899f9e5b
doc: improve docstrings for audioformats, audioinfo, audioread, and audiowrite
Mike Miller <mtmiller@octave.org>
parents:
23853
diff
changeset
|
603 |
4f68899f9e5b
doc: improve docstrings for audioformats, audioinfo, audioread, and audiowrite
Mike Miller <mtmiller@octave.org>
parents:
23853
diff
changeset
|
604 @item TotalSamples |
4f68899f9e5b
doc: improve docstrings for audioformats, audioinfo, audioread, and audiowrite
Mike Miller <mtmiller@octave.org>
parents:
23853
diff
changeset
|
605 Number of samples in the file. |
4f68899f9e5b
doc: improve docstrings for audioformats, audioinfo, audioread, and audiowrite
Mike Miller <mtmiller@octave.org>
parents:
23853
diff
changeset
|
606 |
4f68899f9e5b
doc: improve docstrings for audioformats, audioinfo, audioread, and audiowrite
Mike Miller <mtmiller@octave.org>
parents:
23853
diff
changeset
|
607 @item Duration |
4f68899f9e5b
doc: improve docstrings for audioformats, audioinfo, audioread, and audiowrite
Mike Miller <mtmiller@octave.org>
parents:
23853
diff
changeset
|
608 Duration of the audio, in seconds. |
4f68899f9e5b
doc: improve docstrings for audioformats, audioinfo, audioread, and audiowrite
Mike Miller <mtmiller@octave.org>
parents:
23853
diff
changeset
|
609 |
4f68899f9e5b
doc: improve docstrings for audioformats, audioinfo, audioread, and audiowrite
Mike Miller <mtmiller@octave.org>
parents:
23853
diff
changeset
|
610 @item BitsPerSample |
4f68899f9e5b
doc: improve docstrings for audioformats, audioinfo, audioread, and audiowrite
Mike Miller <mtmiller@octave.org>
parents:
23853
diff
changeset
|
611 Number of bits per sample. |
4f68899f9e5b
doc: improve docstrings for audioformats, audioinfo, audioread, and audiowrite
Mike Miller <mtmiller@octave.org>
parents:
23853
diff
changeset
|
612 |
4f68899f9e5b
doc: improve docstrings for audioformats, audioinfo, audioread, and audiowrite
Mike Miller <mtmiller@octave.org>
parents:
23853
diff
changeset
|
613 @item BitRate |
25003
2365c2661b3c
doc: Spellcheck documentation ahead of 4.4 release.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
614 Audio bit rate. Unused, only present for compatibility with @sc{matlab}. |
23866
4f68899f9e5b
doc: improve docstrings for audioformats, audioinfo, audioread, and audiowrite
Mike Miller <mtmiller@octave.org>
parents:
23853
diff
changeset
|
615 |
4f68899f9e5b
doc: improve docstrings for audioformats, audioinfo, audioread, and audiowrite
Mike Miller <mtmiller@octave.org>
parents:
23853
diff
changeset
|
616 @item Title |
4f68899f9e5b
doc: improve docstrings for audioformats, audioinfo, audioread, and audiowrite
Mike Miller <mtmiller@octave.org>
parents:
23853
diff
changeset
|
617 @qcode{"Title"} audio metadata value as a string, or empty if not present. |
4f68899f9e5b
doc: improve docstrings for audioformats, audioinfo, audioread, and audiowrite
Mike Miller <mtmiller@octave.org>
parents:
23853
diff
changeset
|
618 |
4f68899f9e5b
doc: improve docstrings for audioformats, audioinfo, audioread, and audiowrite
Mike Miller <mtmiller@octave.org>
parents:
23853
diff
changeset
|
619 @item Artist |
4f68899f9e5b
doc: improve docstrings for audioformats, audioinfo, audioread, and audiowrite
Mike Miller <mtmiller@octave.org>
parents:
23853
diff
changeset
|
620 @qcode{"Artist"} audio metadata value as a string, or empty if not present. |
4f68899f9e5b
doc: improve docstrings for audioformats, audioinfo, audioread, and audiowrite
Mike Miller <mtmiller@octave.org>
parents:
23853
diff
changeset
|
621 |
4f68899f9e5b
doc: improve docstrings for audioformats, audioinfo, audioread, and audiowrite
Mike Miller <mtmiller@octave.org>
parents:
23853
diff
changeset
|
622 @item Comment |
4f68899f9e5b
doc: improve docstrings for audioformats, audioinfo, audioread, and audiowrite
Mike Miller <mtmiller@octave.org>
parents:
23853
diff
changeset
|
623 @qcode{"Comment"} audio metadata value as a string, or empty if not present. |
4f68899f9e5b
doc: improve docstrings for audioformats, audioinfo, audioread, and audiowrite
Mike Miller <mtmiller@octave.org>
parents:
23853
diff
changeset
|
624 @end table |
4f68899f9e5b
doc: improve docstrings for audioformats, audioinfo, audioread, and audiowrite
Mike Miller <mtmiller@octave.org>
parents:
23853
diff
changeset
|
625 @seealso{audioread, audiowrite} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
626 @end deftypefn */) |
19510 | 627 { |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21712
diff
changeset
|
628 #if defined (HAVE_SNDFILE) |
19526
7f271cef5850
protect all portaudio and sndfile dependent code with #ifdefs
John W. Eaton <jwe@octave.org>
parents:
19519
diff
changeset
|
629 |
19519
e616c2830413
various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents:
19516
diff
changeset
|
630 if (args.length () != 1) |
20790
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20578
diff
changeset
|
631 print_usage (); |
19519
e616c2830413
various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents:
19516
diff
changeset
|
632 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20865
diff
changeset
|
633 std::string filename = args(0).xstring_value ("audioinfo: FILENAME must be a string"); |
19554
398e42431dcc
improve argument decoding in audioread.cc functions
John W. Eaton <jwe@octave.org>
parents:
19553
diff
changeset
|
634 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
635 sys::file_stat fs (filename); |
23873
9ada3f4f4e28
audioinfo: return absolute file name in info structure
Mike Miller <mtmiller@octave.org>
parents:
23868
diff
changeset
|
636 if (! fs.exists ()) |
9ada3f4f4e28
audioinfo: return absolute file name in info structure
Mike Miller <mtmiller@octave.org>
parents:
23868
diff
changeset
|
637 error ("audioinfo: FILENAME '%s' not found", filename.c_str ()); |
9ada3f4f4e28
audioinfo: return absolute file name in info structure
Mike Miller <mtmiller@octave.org>
parents:
23868
diff
changeset
|
638 |
19510 | 639 SF_INFO info; |
640 info.format = 0; | |
19554
398e42431dcc
improve argument decoding in audioread.cc functions
John W. Eaton <jwe@octave.org>
parents:
19553
diff
changeset
|
641 SNDFILE *file = sf_open (filename.c_str (), SFM_READ, &info); |
19519
e616c2830413
various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents:
19516
diff
changeset
|
642 |
19559
701b43ce4467
properly close audio files
John W. Eaton <jwe@octave.org>
parents:
19554
diff
changeset
|
643 if (! file) |
23963
3dd89a7b92c8
display message from libsndfile if opening files fails (bug #51859)
Markus Mützel <markus.muetzel@gmx.de>
parents:
23873
diff
changeset
|
644 error ("audioinfo: failed to open input file '%s': %s", |
3dd89a7b92c8
display message from libsndfile if opening files fails (bug #51859)
Markus Mützel <markus.muetzel@gmx.de>
parents:
23873
diff
changeset
|
645 filename.c_str (), sf_strerror (file)); |
19559
701b43ce4467
properly close audio files
John W. Eaton <jwe@octave.org>
parents:
19554
diff
changeset
|
646 |
33034
49128bdb9eb2
use explicit lambda-expression captures (bug #65318)
John W. Eaton <jwe@octave.org>
parents:
32660
diff
changeset
|
647 unwind_action close_open_file ([file] () { sf_close (file); }); |
19559
701b43ce4467
properly close audio files
John W. Eaton <jwe@octave.org>
parents:
19554
diff
changeset
|
648 |
19519
e616c2830413
various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents:
19516
diff
changeset
|
649 octave_scalar_map result; |
e616c2830413
various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents:
19516
diff
changeset
|
650 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
651 std::string full_name = sys::canonicalize_file_name (filename); |
23873
9ada3f4f4e28
audioinfo: return absolute file name in info structure
Mike Miller <mtmiller@octave.org>
parents:
23868
diff
changeset
|
652 |
9ada3f4f4e28
audioinfo: return absolute file name in info structure
Mike Miller <mtmiller@octave.org>
parents:
23868
diff
changeset
|
653 result.assign ("Filename", full_name); |
19519
e616c2830413
various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents:
19516
diff
changeset
|
654 result.assign ("CompressionMethod", ""); |
e616c2830413
various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents:
19516
diff
changeset
|
655 result.assign ("NumChannels", info.channels); |
e616c2830413
various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents:
19516
diff
changeset
|
656 result.assign ("SampleRate", info.samplerate); |
29858
6dc298d3261c
Handle malformed sound headers which do not specify number of frames (bug #60888).
Rik <rik@octave.org>
parents:
29655
diff
changeset
|
657 double dframes; |
6dc298d3261c
Handle malformed sound headers which do not specify number of frames (bug #60888).
Rik <rik@octave.org>
parents:
29655
diff
changeset
|
658 if (info.frames != SF_COUNT_MAX) |
6dc298d3261c
Handle malformed sound headers which do not specify number of frames (bug #60888).
Rik <rik@octave.org>
parents:
29655
diff
changeset
|
659 dframes = info.frames; |
6dc298d3261c
Handle malformed sound headers which do not specify number of frames (bug #60888).
Rik <rik@octave.org>
parents:
29655
diff
changeset
|
660 else |
6dc298d3261c
Handle malformed sound headers which do not specify number of frames (bug #60888).
Rik <rik@octave.org>
parents:
29655
diff
changeset
|
661 dframes = -1; |
6dc298d3261c
Handle malformed sound headers which do not specify number of frames (bug #60888).
Rik <rik@octave.org>
parents:
29655
diff
changeset
|
662 result.assign ("TotalSamples", dframes); |
19519
e616c2830413
various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents:
19516
diff
changeset
|
663 |
29858
6dc298d3261c
Handle malformed sound headers which do not specify number of frames (bug #60888).
Rik <rik@octave.org>
parents:
29655
diff
changeset
|
664 if (dframes != -1) |
6dc298d3261c
Handle malformed sound headers which do not specify number of frames (bug #60888).
Rik <rik@octave.org>
parents:
29655
diff
changeset
|
665 { |
6dc298d3261c
Handle malformed sound headers which do not specify number of frames (bug #60888).
Rik <rik@octave.org>
parents:
29655
diff
changeset
|
666 double drate = info.samplerate; |
6dc298d3261c
Handle malformed sound headers which do not specify number of frames (bug #60888).
Rik <rik@octave.org>
parents:
29655
diff
changeset
|
667 result.assign ("Duration", dframes / drate); |
6dc298d3261c
Handle malformed sound headers which do not specify number of frames (bug #60888).
Rik <rik@octave.org>
parents:
29655
diff
changeset
|
668 } |
6dc298d3261c
Handle malformed sound headers which do not specify number of frames (bug #60888).
Rik <rik@octave.org>
parents:
29655
diff
changeset
|
669 else |
6dc298d3261c
Handle malformed sound headers which do not specify number of frames (bug #60888).
Rik <rik@octave.org>
parents:
29655
diff
changeset
|
670 result.assign ("Duration", -1); |
19510 | 671 |
672 int bits; | |
19675
793d295fed4d
Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19571
diff
changeset
|
673 switch (info.format & SF_FORMAT_SUBMASK) |
793d295fed4d
Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19571
diff
changeset
|
674 { |
793d295fed4d
Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19571
diff
changeset
|
675 case SF_FORMAT_PCM_S8: |
793d295fed4d
Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19571
diff
changeset
|
676 bits = 8; |
793d295fed4d
Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19571
diff
changeset
|
677 break; |
793d295fed4d
Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19571
diff
changeset
|
678 case SF_FORMAT_PCM_U8: |
793d295fed4d
Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19571
diff
changeset
|
679 bits = 8; |
793d295fed4d
Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19571
diff
changeset
|
680 break; |
793d295fed4d
Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19571
diff
changeset
|
681 case SF_FORMAT_PCM_16: |
793d295fed4d
Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19571
diff
changeset
|
682 bits = 16; |
793d295fed4d
Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19571
diff
changeset
|
683 break; |
793d295fed4d
Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19571
diff
changeset
|
684 case SF_FORMAT_PCM_24: |
793d295fed4d
Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19571
diff
changeset
|
685 bits = 24; |
793d295fed4d
Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19571
diff
changeset
|
686 break; |
793d295fed4d
Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19571
diff
changeset
|
687 case SF_FORMAT_PCM_32: |
793d295fed4d
Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19571
diff
changeset
|
688 bits = 32; |
793d295fed4d
Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19571
diff
changeset
|
689 break; |
25409
4f6c985ca28a
Fix various bugs with audioread, audiowrite, audioinfo (bug #53975).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
690 case SF_FORMAT_FLOAT: |
4f6c985ca28a
Fix various bugs with audioread, audiowrite, audioinfo (bug #53975).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
691 bits = 32; |
4f6c985ca28a
Fix various bugs with audioread, audiowrite, audioinfo (bug #53975).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
692 break; |
4f6c985ca28a
Fix various bugs with audioread, audiowrite, audioinfo (bug #53975).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
693 case SF_FORMAT_DOUBLE: |
4f6c985ca28a
Fix various bugs with audioread, audiowrite, audioinfo (bug #53975).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
694 bits = 64; |
4f6c985ca28a
Fix various bugs with audioread, audiowrite, audioinfo (bug #53975).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
695 break; |
19675
793d295fed4d
Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19571
diff
changeset
|
696 default: |
793d295fed4d
Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19571
diff
changeset
|
697 bits = -1; |
793d295fed4d
Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19571
diff
changeset
|
698 break; |
793d295fed4d
Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19571
diff
changeset
|
699 } |
19510 | 700 |
19519
e616c2830413
various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents:
19516
diff
changeset
|
701 result.assign ("BitsPerSample", bits); |
e616c2830413
various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents:
19516
diff
changeset
|
702 result.assign ("BitRate", -1); |
e616c2830413
various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents:
19516
diff
changeset
|
703 result.assign ("Title", sf_get_string (file, SF_STR_TITLE)); |
e616c2830413
various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents:
19516
diff
changeset
|
704 result.assign ("Artist", sf_get_string (file, SF_STR_ARTIST)); |
e616c2830413
various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents:
19516
diff
changeset
|
705 result.assign ("Comment", sf_get_string (file, SF_STR_COMMENT)); |
e616c2830413
various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents:
19516
diff
changeset
|
706 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20865
diff
changeset
|
707 return ovl (result); |
19519
e616c2830413
various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents:
19516
diff
changeset
|
708 |
19510 | 709 #else |
19519
e616c2830413
various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents:
19516
diff
changeset
|
710 |
21691
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21602
diff
changeset
|
711 octave_unused_parameter (args); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21602
diff
changeset
|
712 |
21103
5a83a422d8a7
Don't set 3rd argument to err_disabled_feature within core Octave.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
713 err_disabled_feature ("audioinfo", |
5a83a422d8a7
Don't set 3rd argument to err_disabled_feature within core Octave.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
714 "reading and writing sound files through libsndfile"); |
19519
e616c2830413
various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents:
19516
diff
changeset
|
715 |
19510 | 716 #endif |
717 } | |
21709
88657798b650
audioformats: New function to list available audio formats (bug #47464)
Damjan Angelovski <damjangelovski@gmail.com>
parents:
21694
diff
changeset
|
718 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21712
diff
changeset
|
719 #if defined (HAVE_SNDFILE) |
21712
09e1bb792dd9
Fix compilation error when building without sndfile
Mike Miller <mtmiller@octave.org>
parents:
21710
diff
changeset
|
720 |
21710
f7850bd66042
audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents:
21709
diff
changeset
|
721 static void |
f7850bd66042
audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents:
21709
diff
changeset
|
722 audio_sub_formats (int format) |
21709
88657798b650
audioformats: New function to list available audio formats (bug #47464)
Damjan Angelovski <damjangelovski@gmail.com>
parents:
21694
diff
changeset
|
723 { |
21710
f7850bd66042
audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents:
21709
diff
changeset
|
724 int count; |
23459
ddcbf10c8c39
maint: Use C++11 nullptr rather than 0 or NULL for remaining instances in code.
Rik <rik@octave.org>
parents:
23450
diff
changeset
|
725 sf_command (nullptr, SFC_GET_FORMAT_SUBTYPE_COUNT, &count, sizeof (int)); |
21709
88657798b650
audioformats: New function to list available audio formats (bug #47464)
Damjan Angelovski <damjangelovski@gmail.com>
parents:
21694
diff
changeset
|
726 |
88657798b650
audioformats: New function to list available audio formats (bug #47464)
Damjan Angelovski <damjangelovski@gmail.com>
parents:
21694
diff
changeset
|
727 for (int i = 0; i < count; i++) |
88657798b650
audioformats: New function to list available audio formats (bug #47464)
Damjan Angelovski <damjangelovski@gmail.com>
parents:
21694
diff
changeset
|
728 { |
21710
f7850bd66042
audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents:
21709
diff
changeset
|
729 SF_FORMAT_INFO info; |
21709
88657798b650
audioformats: New function to list available audio formats (bug #47464)
Damjan Angelovski <damjangelovski@gmail.com>
parents:
21694
diff
changeset
|
730 info.format = i; |
23459
ddcbf10c8c39
maint: Use C++11 nullptr rather than 0 or NULL for remaining instances in code.
Rik <rik@octave.org>
parents:
23450
diff
changeset
|
731 sf_command (nullptr, SFC_GET_FORMAT_SUBTYPE, &info, sizeof (info)); |
21710
f7850bd66042
audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents:
21709
diff
changeset
|
732 |
f7850bd66042
audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents:
21709
diff
changeset
|
733 SF_INFO sfinfo; |
f7850bd66042
audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents:
21709
diff
changeset
|
734 memset (&sfinfo, 0, sizeof (sfinfo)); |
f7850bd66042
audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents:
21709
diff
changeset
|
735 sfinfo.channels = 1; |
f7850bd66042
audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents:
21709
diff
changeset
|
736 sfinfo.format = (format & SF_FORMAT_TYPEMASK) | info.format; |
21709
88657798b650
audioformats: New function to list available audio formats (bug #47464)
Damjan Angelovski <damjangelovski@gmail.com>
parents:
21694
diff
changeset
|
737 |
88657798b650
audioformats: New function to list available audio formats (bug #47464)
Damjan Angelovski <damjangelovski@gmail.com>
parents:
21694
diff
changeset
|
738 if (sf_format_check (&sfinfo)) |
21710
f7850bd66042
audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents:
21709
diff
changeset
|
739 octave_stdout << " " << info.name << std::endl; |
f7850bd66042
audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents:
21709
diff
changeset
|
740 } |
21709
88657798b650
audioformats: New function to list available audio formats (bug #47464)
Damjan Angelovski <damjangelovski@gmail.com>
parents:
21694
diff
changeset
|
741 } |
88657798b650
audioformats: New function to list available audio formats (bug #47464)
Damjan Angelovski <damjangelovski@gmail.com>
parents:
21694
diff
changeset
|
742 |
21712
09e1bb792dd9
Fix compilation error when building without sndfile
Mike Miller <mtmiller@octave.org>
parents:
21710
diff
changeset
|
743 #endif |
09e1bb792dd9
Fix compilation error when building without sndfile
Mike Miller <mtmiller@octave.org>
parents:
21710
diff
changeset
|
744 |
21709
88657798b650
audioformats: New function to list available audio formats (bug #47464)
Damjan Angelovski <damjangelovski@gmail.com>
parents:
21694
diff
changeset
|
745 DEFUN_DLD (audioformats, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
746 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
747 @deftypefn {} {} audioformats () |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
748 @deftypefnx {} {} audioformats (@var{format}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
749 Display information about all supported audio formats. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
750 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
751 If the optional argument @var{format} is given, then display only formats |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
752 with names that start with @var{format}. |
23866
4f68899f9e5b
doc: improve docstrings for audioformats, audioinfo, audioread, and audiowrite
Mike Miller <mtmiller@octave.org>
parents:
23853
diff
changeset
|
753 @seealso{audioread, audiowrite} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
754 @end deftypefn */) |
21709
88657798b650
audioformats: New function to list available audio formats (bug #47464)
Damjan Angelovski <damjangelovski@gmail.com>
parents:
21694
diff
changeset
|
755 { |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21712
diff
changeset
|
756 #if defined (HAVE_SNDFILE) |
21710
f7850bd66042
audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents:
21709
diff
changeset
|
757 |
21709
88657798b650
audioformats: New function to list available audio formats (bug #47464)
Damjan Angelovski <damjangelovski@gmail.com>
parents:
21694
diff
changeset
|
758 if (args.length () > 1) |
88657798b650
audioformats: New function to list available audio formats (bug #47464)
Damjan Angelovski <damjangelovski@gmail.com>
parents:
21694
diff
changeset
|
759 print_usage (); |
88657798b650
audioformats: New function to list available audio formats (bug #47464)
Damjan Angelovski <damjangelovski@gmail.com>
parents:
21694
diff
changeset
|
760 |
21710
f7850bd66042
audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents:
21709
diff
changeset
|
761 std::string search = ""; |
f7850bd66042
audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents:
21709
diff
changeset
|
762 if (args.length () > 0) |
f7850bd66042
audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents:
21709
diff
changeset
|
763 { |
f7850bd66042
audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents:
21709
diff
changeset
|
764 search = args(0).string_value (); |
f7850bd66042
audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents:
21709
diff
changeset
|
765 std::transform (search.begin (), search.end (), search.begin (), tolower); |
f7850bd66042
audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents:
21709
diff
changeset
|
766 } |
21709
88657798b650
audioformats: New function to list available audio formats (bug #47464)
Damjan Angelovski <damjangelovski@gmail.com>
parents:
21694
diff
changeset
|
767 |
21710
f7850bd66042
audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents:
21709
diff
changeset
|
768 int count; |
23459
ddcbf10c8c39
maint: Use C++11 nullptr rather than 0 or NULL for remaining instances in code.
Rik <rik@octave.org>
parents:
23450
diff
changeset
|
769 sf_command (nullptr, SFC_GET_FORMAT_MAJOR_COUNT, &count, sizeof (int)); |
21709
88657798b650
audioformats: New function to list available audio formats (bug #47464)
Damjan Angelovski <damjangelovski@gmail.com>
parents:
21694
diff
changeset
|
770 |
88657798b650
audioformats: New function to list available audio formats (bug #47464)
Damjan Angelovski <damjangelovski@gmail.com>
parents:
21694
diff
changeset
|
771 for (int i = 0; i < count; i++) |
88657798b650
audioformats: New function to list available audio formats (bug #47464)
Damjan Angelovski <damjangelovski@gmail.com>
parents:
21694
diff
changeset
|
772 { |
21710
f7850bd66042
audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents:
21709
diff
changeset
|
773 SF_FORMAT_INFO info; |
21709
88657798b650
audioformats: New function to list available audio formats (bug #47464)
Damjan Angelovski <damjangelovski@gmail.com>
parents:
21694
diff
changeset
|
774 info.format = i; |
23459
ddcbf10c8c39
maint: Use C++11 nullptr rather than 0 or NULL for remaining instances in code.
Rik <rik@octave.org>
parents:
23450
diff
changeset
|
775 sf_command (nullptr, SFC_GET_FORMAT_MAJOR, &info, sizeof (info)); |
21710
f7850bd66042
audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents:
21709
diff
changeset
|
776 bool match = true; |
21709
88657798b650
audioformats: New function to list available audio formats (bug #47464)
Damjan Angelovski <damjangelovski@gmail.com>
parents:
21694
diff
changeset
|
777 |
21710
f7850bd66042
audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents:
21709
diff
changeset
|
778 if (! search.empty ()) |
f7850bd66042
audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents:
21709
diff
changeset
|
779 { |
f7850bd66042
audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents:
21709
diff
changeset
|
780 std::string nm = info.name; |
f7850bd66042
audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents:
21709
diff
changeset
|
781 std::transform (nm.begin (), nm.end (), nm.begin (), tolower); |
f7850bd66042
audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents:
21709
diff
changeset
|
782 match = nm.compare (0, search.length (), search) == 0; |
f7850bd66042
audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents:
21709
diff
changeset
|
783 } |
21709
88657798b650
audioformats: New function to list available audio formats (bug #47464)
Damjan Angelovski <damjangelovski@gmail.com>
parents:
21694
diff
changeset
|
784 |
21710
f7850bd66042
audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents:
21709
diff
changeset
|
785 if (match) |
21709
88657798b650
audioformats: New function to list available audio formats (bug #47464)
Damjan Angelovski <damjangelovski@gmail.com>
parents:
21694
diff
changeset
|
786 { |
21710
f7850bd66042
audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents:
21709
diff
changeset
|
787 octave_stdout << "name: " << info.name << std::endl; |
f7850bd66042
audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents:
21709
diff
changeset
|
788 octave_stdout << "extension: " << info.extension << std::endl; |
f7850bd66042
audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents:
21709
diff
changeset
|
789 octave_stdout << "id: " << info.format << std::endl; |
f7850bd66042
audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents:
21709
diff
changeset
|
790 octave_stdout << "subformats:" << std::endl; |
21709
88657798b650
audioformats: New function to list available audio formats (bug #47464)
Damjan Angelovski <damjangelovski@gmail.com>
parents:
21694
diff
changeset
|
791 |
21710
f7850bd66042
audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents:
21709
diff
changeset
|
792 audio_sub_formats (info.format); |
f7850bd66042
audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents:
21709
diff
changeset
|
793 } |
f7850bd66042
audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents:
21709
diff
changeset
|
794 } |
21709
88657798b650
audioformats: New function to list available audio formats (bug #47464)
Damjan Angelovski <damjangelovski@gmail.com>
parents:
21694
diff
changeset
|
795 |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
796 return octave_value_list (); |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
797 |
21709
88657798b650
audioformats: New function to list available audio formats (bug #47464)
Damjan Angelovski <damjangelovski@gmail.com>
parents:
21694
diff
changeset
|
798 #else |
22265
15b9d7cb3098
eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
799 |
15b9d7cb3098
eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
800 octave_unused_parameter (args); |
15b9d7cb3098
eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
801 |
21709
88657798b650
audioformats: New function to list available audio formats (bug #47464)
Damjan Angelovski <damjangelovski@gmail.com>
parents:
21694
diff
changeset
|
802 err_disabled_feature ("audioformats", |
88657798b650
audioformats: New function to list available audio formats (bug #47464)
Damjan Angelovski <damjangelovski@gmail.com>
parents:
21694
diff
changeset
|
803 "getting sound formats through libsndfile"); |
22265
15b9d7cb3098
eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
804 |
21709
88657798b650
audioformats: New function to list available audio formats (bug #47464)
Damjan Angelovski <damjangelovski@gmail.com>
parents:
21694
diff
changeset
|
805 #endif |
88657798b650
audioformats: New function to list available audio formats (bug #47464)
Damjan Angelovski <damjangelovski@gmail.com>
parents:
21694
diff
changeset
|
806 } |
29958
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29858
diff
changeset
|
807 |
31605
e88a07dec498
maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
808 OCTAVE_END_NAMESPACE(octave) |