annotate libinterp/dldfcn/audioread.cc @ 23459:ddcbf10c8c39

maint: Use C++11 nullptr rather than 0 or NULL for remaining instances in code. * sysdep.cc, __osmesa_print__.cc, audioread.cc, ov-java.cc: Use C++11 nullptr rather than 0 or NULL.
author Rik <rik@octave.org>
date Fri, 28 Apr 2017 17:20:13 -0700
parents 855122b993da
children 2230f9e10fb3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19500
8bb399569393 Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents: 19498
diff changeset
1 /*
8bb399569393 Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents: 19498
diff changeset
2
23219
3ac9f9ecfae5 maint: Update copyright dates.
John W. Eaton <jwe@octave.org>
parents: 23083
diff changeset
3 Copyright (C) 2013-2017 Vytautas JanĨauskas
21709
88657798b650 audioformats: New function to list available audio formats (bug #47464)
Damjan Angelovski <damjangelovski@gmail.com>
parents: 21694
diff changeset
4 Copyright (C) 2016 Damjan Angelovski
19500
8bb399569393 Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents: 19498
diff changeset
5
8bb399569393 Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents: 19498
diff changeset
6 This file is part of Octave.
8bb399569393 Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents: 19498
diff changeset
7
8bb399569393 Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents: 19498
diff changeset
8 Octave is free software; you can redistribute it and/or modify it
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
9 under the terms of the GNU General Public License as published by
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
10 the Free Software Foundation; either version 3 of the License, or
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
11 (at your option) any later version.
19500
8bb399569393 Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents: 19498
diff changeset
12
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
13 Octave is distributed in the hope that it will be useful, but
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
14 WITHOUT ANY WARRANTY; without even the implied warranty of
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
16 GNU General Public License for more details.
19500
8bb399569393 Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents: 19498
diff changeset
17
8bb399569393 Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents: 19498
diff changeset
18 You should have received a copy of the GNU General Public License
8bb399569393 Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents: 19498
diff changeset
19 along with Octave; see the file COPYING. If not, see
8bb399569393 Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents: 19498
diff changeset
20 <http://www.gnu.org/licenses/>.
8bb399569393 Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents: 19498
diff changeset
21
8bb399569393 Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents: 19498
diff changeset
22 */
8bb399569393 Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents: 19498
diff changeset
23
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21712
diff changeset
24 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21200
diff changeset
25 # include "config.h"
19501
1f551d169db2 Include config.h in audio project source files
Mike Miller <mtmiller@ieee.org>
parents: 19500
diff changeset
26 #endif
1f551d169db2 Include config.h in audio project source files
Mike Miller <mtmiller@ieee.org>
parents: 19500
diff changeset
27
23024
a6a7b054e4ba Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents: 22755
diff changeset
28 #include <algorithm>
19510
99522db5b911 merge audio source files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
29 #include <map>
23024
a6a7b054e4ba Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents: 22755
diff changeset
30 #include <string>
19510
99522db5b911 merge audio source files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
31
23024
a6a7b054e4ba Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents: 22755
diff changeset
32 #include "dMatrix.h"
a6a7b054e4ba Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents: 22755
diff changeset
33 #include "dRowVector.h"
19513
4cb4210bd392 use C++ style casts in audio code
John W. Eaton <jwe@octave.org>
parents: 19512
diff changeset
34 #include "oct-locbuf.h"
19559
701b43ce4467 properly close audio files
John W. Eaton <jwe@octave.org>
parents: 19554
diff changeset
35 #include "unwind-prot.h"
19513
4cb4210bd392 use C++ style casts in audio code
John W. Eaton <jwe@octave.org>
parents: 19512
diff changeset
36
19511
19f75d156ffe don't include oct.h in Octave source files
John W. Eaton <jwe@octave.org>
parents: 19510
diff changeset
37 #include "defun-dld.h"
19f75d156ffe don't include oct.h in Octave source files
John W. Eaton <jwe@octave.org>
parents: 19510
diff changeset
38 #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
39 #include "errwarn.h"
23024
a6a7b054e4ba Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents: 22755
diff changeset
40 #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
41 #include "ovl.h"
21709
88657798b650 audioformats: New function to list available audio formats (bug #47464)
Damjan Angelovski <damjangelovski@gmail.com>
parents: 21694
diff changeset
42 #include "pager.h"
88657798b650 audioformats: New function to list available audio formats (bug #47464)
Damjan Angelovski <damjangelovski@gmail.com>
parents: 21694
diff changeset
43
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21712
diff changeset
44 #if defined (HAVE_SNDFILE)
21200
fcac5dbbf9ed maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents: 21129
diff changeset
45 # include <sndfile.h>
19473
2e174b5e7703 Fix audiodevinfo, audioinfo, audioread and audiowrite build process
Vytautas Jančauskas <unaudio@gmail.com>
parents: 19468
diff changeset
46 #endif
19503
36a26a131209 Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents: 19501
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)
19559
701b43ce4467 properly close audio files
John W. Eaton <jwe@octave.org>
parents: 19554
diff changeset
49 static void
701b43ce4467 properly close audio files
John W. Eaton <jwe@octave.org>
parents: 19554
diff changeset
50 safe_close (SNDFILE *file)
701b43ce4467 properly close audio files
John W. Eaton <jwe@octave.org>
parents: 19554
diff changeset
51 {
701b43ce4467 properly close audio files
John W. Eaton <jwe@octave.org>
parents: 19554
diff changeset
52 sf_close (file);
701b43ce4467 properly close audio files
John W. Eaton <jwe@octave.org>
parents: 19554
diff changeset
53 }
701b43ce4467 properly close audio files
John W. Eaton <jwe@octave.org>
parents: 19554
diff changeset
54 #endif
701b43ce4467 properly close audio files
John W. Eaton <jwe@octave.org>
parents: 19554
diff changeset
55
19503
36a26a131209 Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents: 19501
diff changeset
56 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
57 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
58 @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
59 @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
60
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
61 @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
62 @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
63 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
64 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
65
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
66 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
67 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
68
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
69 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
70 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
71
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
72 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
73 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
74 is stored in 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
75 @end deftypefn */)
19462
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
76 {
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21712
diff changeset
77 #if defined (HAVE_SNDFILE)
19519
e616c2830413 various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents: 19516
diff changeset
78
e616c2830413 various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents: 19516
diff changeset
79 int nargin = args.length ();
e616c2830413 various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents: 19516
diff changeset
80
e616c2830413 various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents: 19516
diff changeset
81 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
82 print_usage ();
19519
e616c2830413 various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents: 19516
diff changeset
83
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20865
diff changeset
84 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
85
19462
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
86 SF_INFO info;
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
87 info.format = 0;
19519
e616c2830413 various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents: 19516
diff changeset
88 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
89
19559
701b43ce4467 properly close audio files
John W. Eaton <jwe@octave.org>
parents: 19554
diff changeset
90 if (! file)
20825
66cd994d1b79 eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents: 20790
diff changeset
91 error ("audioread: failed to open input file %s", filename.c_str ());
19559
701b43ce4467 properly close audio files
John W. Eaton <jwe@octave.org>
parents: 19554
diff changeset
92
21743
f4d7d0eb5b0c use namespace for unwind_protect class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
93 octave::unwind_protect frame;
19559
701b43ce4467 properly close audio files
John W. Eaton <jwe@octave.org>
parents: 19554
diff changeset
94
701b43ce4467 properly close audio files
John W. Eaton <jwe@octave.org>
parents: 19554
diff changeset
95 frame.add_fcn (safe_close, file);
701b43ce4467 properly close audio files
John W. Eaton <jwe@octave.org>
parents: 19554
diff changeset
96
19513
4cb4210bd392 use C++ style casts in audio code
John W. Eaton <jwe@octave.org>
parents: 19512
diff changeset
97 OCTAVE_LOCAL_BUFFER (float, data, info.frames * info.channels);
19554
398e42431dcc improve argument decoding in audioread.cc functions
John W. Eaton <jwe@octave.org>
parents: 19553
diff changeset
98
19503
36a26a131209 Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents: 19501
diff changeset
99 sf_read_float (file, data, info.frames * info.channels);
19519
e616c2830413 various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents: 19516
diff changeset
100
19554
398e42431dcc improve argument decoding in audioread.cc functions
John W. Eaton <jwe@octave.org>
parents: 19553
diff changeset
101 sf_count_t start = 0;
398e42431dcc improve argument decoding in audioread.cc functions
John W. Eaton <jwe@octave.org>
parents: 19553
diff changeset
102 sf_count_t end = info.frames;
398e42431dcc improve argument decoding in audioread.cc functions
John W. Eaton <jwe@octave.org>
parents: 19553
diff changeset
103
19519
e616c2830413 various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents: 19516
diff changeset
104 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
105 {
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
106 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
107
20228
00cf2847355d Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20163
diff changeset
108 if (range.numel () != 2)
20825
66cd994d1b79 eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents: 20790
diff changeset
109 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
110
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23220
diff changeset
111 double dstart = (octave::math::isinf (range(0)) ? info.frames : range(0));
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23220
diff changeset
112 double dend = (octave::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
113
19811
f24d9486e66b audioread: Fix sample index argument to be Matlab compatible
Mike Miller <mtmiller@ieee.org>
parents: 19697
diff changeset
114 if (dstart < 1 || dstart > dend || dend > info.frames
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22323
diff changeset
115 || octave::math::x_nint (dstart) != dstart
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22323
diff changeset
116 || octave::math::x_nint (dend) != dend)
20825
66cd994d1b79 eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents: 20790
diff changeset
117 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
118
19811
f24d9486e66b audioread: Fix sample index argument to be Matlab compatible
Mike Miller <mtmiller@ieee.org>
parents: 19697
diff changeset
119 start = dstart - 1;
19554
398e42431dcc improve argument decoding in audioread.cc functions
John W. Eaton <jwe@octave.org>
parents: 19553
diff changeset
120 end = dend;
19462
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
121 }
19519
e616c2830413 various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents: 19516
diff changeset
122
19554
398e42431dcc improve argument decoding in audioread.cc functions
John W. Eaton <jwe@octave.org>
parents: 19553
diff changeset
123 sf_count_t items = end - start;
398e42431dcc improve argument decoding in audioread.cc functions
John W. Eaton <jwe@octave.org>
parents: 19553
diff changeset
124
398e42431dcc improve argument decoding in audioread.cc functions
John W. Eaton <jwe@octave.org>
parents: 19553
diff changeset
125 Matrix audio (items, info.channels);
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 double *paudio = audio.fortran_vec ();
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 data += start * info.channels;
398e42431dcc improve argument decoding in audioread.cc functions
John W. Eaton <jwe@octave.org>
parents: 19553
diff changeset
130
398e42431dcc improve argument decoding in audioread.cc functions
John W. Eaton <jwe@octave.org>
parents: 19553
diff changeset
131 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
132 {
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
133 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
134 paudio[items*channel+i] = *data++;
19503
36a26a131209 Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents: 19501
diff changeset
135 }
19513
4cb4210bd392 use C++ style casts in audio code
John W. Eaton <jwe@octave.org>
parents: 19512
diff changeset
136
19519
e616c2830413 various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents: 19516
diff changeset
137 octave_value ret_audio;
e616c2830413 various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents: 19516
diff changeset
138
e616c2830413 various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents: 19516
diff changeset
139 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
140 {
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
141 std::string type;
19519
e616c2830413 various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents: 19516
diff changeset
142 if (nargin == 3)
19503
36a26a131209 Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents: 19501
diff changeset
143 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
144 else
19503
36a26a131209 Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents: 19501
diff changeset
145 type = args(1).string_value ();
36a26a131209 Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents: 19501
diff changeset
146
19462
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
147 if (type == "native")
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
148 {
19675
793d295fed4d Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19571
diff changeset
149 switch (info.format & SF_FORMAT_SUBMASK)
793d295fed4d Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19571
diff changeset
150 {
793d295fed4d Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19571
diff changeset
151 case SF_FORMAT_PCM_S8:
793d295fed4d Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19571
diff changeset
152 ret_audio = int8NDArray (audio * 127);
793d295fed4d Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19571
diff changeset
153 break;
793d295fed4d Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19571
diff changeset
154 case SF_FORMAT_PCM_U8:
793d295fed4d Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19571
diff changeset
155 ret_audio = uint8NDArray (audio * 127 + 127);
793d295fed4d Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19571
diff changeset
156 break;
793d295fed4d Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19571
diff changeset
157 case SF_FORMAT_PCM_16:
793d295fed4d Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19571
diff changeset
158 ret_audio = int16NDArray (audio * 32767);
793d295fed4d Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19571
diff changeset
159 break;
793d295fed4d Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19571
diff changeset
160 case SF_FORMAT_PCM_24:
793d295fed4d Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19571
diff changeset
161 ret_audio = int32NDArray (audio * 8388608);
793d295fed4d Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19571
diff changeset
162 break;
793d295fed4d Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19571
diff changeset
163 case SF_FORMAT_PCM_32:
793d295fed4d Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19571
diff changeset
164 ret_audio = int32NDArray (audio * 2147483648);
793d295fed4d Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19571
diff changeset
165 break;
793d295fed4d Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19571
diff changeset
166 default:
793d295fed4d Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19571
diff changeset
167 ret_audio = audio;
793d295fed4d Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19571
diff changeset
168 break;
793d295fed4d Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19571
diff changeset
169 }
19462
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
170 }
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
171 else
19519
e616c2830413 various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents: 19516
diff changeset
172 ret_audio = audio;
19462
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
173 }
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
174 else
19519
e616c2830413 various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents: 19516
diff changeset
175 ret_audio = audio;
19503
36a26a131209 Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents: 19501
diff changeset
176
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20865
diff changeset
177 return ovl (ret_audio, info.samplerate);
19519
e616c2830413 various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents: 19516
diff changeset
178
19468
9161b7653392 compile audio file utilities even when sndfile is not present
Vytautas Jančauskas <unaudio@gmail.com>
parents: 19463
diff changeset
179 #else
19519
e616c2830413 various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents: 19516
diff changeset
180
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21602
diff changeset
181 octave_unused_parameter (args);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21602
diff changeset
182
21103
5a83a422d8a7 Don't set 3rd argument to err_disabled_feature within core Octave.
Rik <rik@octave.org>
parents: 21100
diff changeset
183 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
184 "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
185
19468
9161b7653392 compile audio file utilities even when sndfile is not present
Vytautas Jančauskas <unaudio@gmail.com>
parents: 19463
diff changeset
186 #endif
19462
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
187 }
19510
99522db5b911 merge audio source files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
188
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21712
diff changeset
189 #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
190
19553
57efd0a020cf write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents: 19544
diff changeset
191 static int
57efd0a020cf write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents: 19544
diff changeset
192 extension_to_format (const std::string& ext)
19510
99522db5b911 merge audio source files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
193 {
19553
57efd0a020cf write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents: 19544
diff changeset
194 static bool initialized = false;
57efd0a020cf write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents: 19544
diff changeset
195
57efd0a020cf write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents: 19544
diff changeset
196 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
197
57efd0a020cf write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents: 19544
diff changeset
198 if (! initialized)
57efd0a020cf write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents: 19544
diff changeset
199 {
57efd0a020cf write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents: 19544
diff changeset
200 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
201 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
202 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
203 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
204 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
205 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
206 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
207 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
208 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
209 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
210 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
211 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
212 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
213 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
214 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
215 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
216 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
217 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
218 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
219 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
220 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
221 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
222 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
223 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
224 table["rf64"] = SF_FORMAT_RF64;
57efd0a020cf write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents: 19544
diff changeset
225
57efd0a020cf write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents: 19544
diff changeset
226 initialized = true;
57efd0a020cf write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents: 19544
diff changeset
227 }
57efd0a020cf write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents: 19544
diff changeset
228
57efd0a020cf write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents: 19544
diff changeset
229 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
230
57efd0a020cf write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents: 19544
diff changeset
231 return (it != table.end ()) ? it->second : 0;
19510
99522db5b911 merge audio source files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
232 }
19526
7f271cef5850 protect all portaudio and sndfile dependent code with #ifdefs
John W. Eaton <jwe@octave.org>
parents: 19519
diff changeset
233
19510
99522db5b911 merge audio source files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
234 #endif
99522db5b911 merge audio source files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
235
99522db5b911 merge audio source files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
236 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
237 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
238 @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
239 @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
240
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
241 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
242 @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
243
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
244 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
245 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
246
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
247 @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
248 @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
249 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
250 16.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
251
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
252 @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
253 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
254
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
255 @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
256 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
257 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
258
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
259 @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
260 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
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 Artist
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
263 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
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 Comment
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
266 Comment.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
267 @end table
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
268 @end deftypefn */)
19510
99522db5b911 merge audio source files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
269 {
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21712
diff changeset
270 #if defined (HAVE_SNDFILE)
19519
e616c2830413 various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents: 19516
diff changeset
271
e616c2830413 various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents: 19516
diff changeset
272 int nargin = args.length ();
e616c2830413 various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents: 19516
diff changeset
273
e616c2830413 various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents: 19516
diff changeset
274 if (nargin < 3)
20790
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20578
diff changeset
275 print_usage ();
19519
e616c2830413 various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents: 19516
diff changeset
276
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20865
diff changeset
277 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
278
19812
f9ca80482c41 audiowrite: Scale integer inputs before writing to an audio file
Mike Miller <mtmiller@ieee.org>
parents: 19811
diff changeset
279 double bias = 0.0;
f9ca80482c41 audiowrite: Scale integer inputs before writing to an audio file
Mike Miller <mtmiller@ieee.org>
parents: 19811
diff changeset
280 double scale = 1.0;
f9ca80482c41 audiowrite: Scale integer inputs before writing to an audio file
Mike Miller <mtmiller@ieee.org>
parents: 19811
diff changeset
281
f9ca80482c41 audiowrite: Scale integer inputs before writing to an audio file
Mike Miller <mtmiller@ieee.org>
parents: 19811
diff changeset
282 if (args(1).is_uint8_type ())
f9ca80482c41 audiowrite: Scale integer inputs before writing to an audio file
Mike Miller <mtmiller@ieee.org>
parents: 19811
diff changeset
283 bias = scale = std::pow (2.0, 7);
f9ca80482c41 audiowrite: Scale integer inputs before writing to an audio file
Mike Miller <mtmiller@ieee.org>
parents: 19811
diff changeset
284 else if (args(1).is_int16_type ())
f9ca80482c41 audiowrite: Scale integer inputs before writing to an audio file
Mike Miller <mtmiller@ieee.org>
parents: 19811
diff changeset
285 scale = std::pow (2.0, 15);
f9ca80482c41 audiowrite: Scale integer inputs before writing to an audio file
Mike Miller <mtmiller@ieee.org>
parents: 19811
diff changeset
286 else if (args(1).is_int32_type ())
f9ca80482c41 audiowrite: Scale integer inputs before writing to an audio file
Mike Miller <mtmiller@ieee.org>
parents: 19811
diff changeset
287 scale = std::pow (2.0, 31);
f9ca80482c41 audiowrite: Scale integer inputs before writing to an audio file
Mike Miller <mtmiller@ieee.org>
parents: 19811
diff changeset
288 else if (args(1).is_integer_type ())
21129
228b65504557 maint: Eliminate useless statements after err_XXX.
Rik <rik@octave.org>
parents: 21103
diff changeset
289 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
290
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20865
diff changeset
291 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
292
19553
57efd0a020cf write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents: 19544
diff changeset
293 int samplerate = args(2).int_value ();
19519
e616c2830413 various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents: 19516
diff changeset
294
19871
ed5ee3f610db Correct tests using std::string::find_XXX which did not use std::string::npos.
Rik <rik@octave.org>
parents: 19813
diff changeset
295 std::string ext;
19872
d575cd1e0da7 Replace std::size_t with bare size_t for conformity to rest of code.
Rik <rik@octave.org>
parents: 19871
diff changeset
296 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
297 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
298 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
299 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
300
57efd0a020cf write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents: 19544
diff changeset
301 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
302
19813
879cff0c05dc audiowrite: Accept a row vector input as a single channel
Mike Miller <mtmiller@ieee.org>
parents: 19812
diff changeset
303 if (audio.rows () == 1)
879cff0c05dc audiowrite: Accept a row vector input as a single channel
Mike Miller <mtmiller@ieee.org>
parents: 19812
diff changeset
304 audio = audio.transpose ();
879cff0c05dc audiowrite: Accept a row vector input as a single channel
Mike Miller <mtmiller@ieee.org>
parents: 19812
diff changeset
305
19553
57efd0a020cf write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents: 19544
diff changeset
306 OCTAVE_LOCAL_BUFFER (float, data, items_to_write);
57efd0a020cf write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents: 19544
diff changeset
307
57efd0a020cf write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents: 19544
diff changeset
308 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
309 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
310 {
57efd0a020cf write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents: 19544
diff changeset
311 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
312 {
f9ca80482c41 audiowrite: Scale integer inputs before writing to an audio file
Mike Miller <mtmiller@ieee.org>
parents: 19811
diff changeset
313 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
314 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
315 }
19553
57efd0a020cf write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents: 19544
diff changeset
316 }
57efd0a020cf write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents: 19544
diff changeset
317
19510
99522db5b911 merge audio source files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
318 SF_INFO info;
19519
e616c2830413 various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents: 19516
diff changeset
319
21602
47c76e56a1de maint: Remove extra space between end of statement and semicolon.
Rik <rik@octave.org>
parents: 21547
diff changeset
320 memset (&info, 0, sizeof (info));
19513
4cb4210bd392 use C++ style casts in audio code
John W. Eaton <jwe@octave.org>
parents: 19512
diff changeset
321
19553
57efd0a020cf write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents: 19544
diff changeset
322 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
323
57efd0a020cf write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents: 19544
diff changeset
324 if (ext == "ogg")
19510
99522db5b911 merge audio source files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
325 {
19553
57efd0a020cf write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents: 19544
diff changeset
326 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
327
57efd0a020cf write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents: 19544
diff changeset
328 // FIXME: there seems to be a bug writing ogg files in one shot
57efd0a020cf write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents: 19544
diff changeset
329 // that causes a segfault. Breaking it up into a series of
57efd0a020cf write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents: 19544
diff changeset
330 // smaller chunks seems to avoid the problem and produce valid
57efd0a020cf write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents: 19544
diff changeset
331 // files.
57efd0a020cf write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents: 19544
diff changeset
332 chunk_size = 0x1FFFFE;
19510
99522db5b911 merge audio source files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
333 }
99522db5b911 merge audio source files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
334 else
99522db5b911 merge audio source files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
335 info.format = SF_FORMAT_PCM_16;
99522db5b911 merge audio source files
John W. Eaton <jwe@octave.org>
parents: 19505
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 info.channels = audio.columns ();
57efd0a020cf write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents: 19544
diff changeset
338 info.samplerate = samplerate;
57efd0a020cf write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents: 19544
diff changeset
339 info.channels = audio.cols ();
57efd0a020cf write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents: 19544
diff changeset
340 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
341
19510
99522db5b911 merge audio source files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
342 std::string title = "";
99522db5b911 merge audio source files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
343 std::string artist = "";
99522db5b911 merge audio source files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
344 std::string comment = "";
23024
a6a7b054e4ba Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents: 22755
diff changeset
345 // FIXME: Quality is currently unused?
19512
a5eb03a7e2a5 eliminate unused variable and parameter warnings
John W. Eaton <jwe@octave.org>
parents: 19511
diff changeset
346 // float quality = 0.75;
19519
e616c2830413 various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents: 19516
diff changeset
347 for (int i = 3; i < nargin; i += 2)
19510
99522db5b911 merge audio source files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
348 {
21693
2c6d1ef071d1 avoid crash in audiowrite argument processing (bug #47875)
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
349 if (i >= nargin - 1)
2c6d1ef071d1 avoid crash in audiowrite argument processing (bug #47875)
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
350 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
351
2c6d1ef071d1 avoid crash in audiowrite argument processing (bug #47875)
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
352 std::string keyword = args(i).string_value ();
2c6d1ef071d1 avoid crash in audiowrite argument processing (bug #47875)
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
353 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
354
2c6d1ef071d1 avoid crash in audiowrite argument processing (bug #47875)
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
355 if (keyword == "BitsPerSample")
19510
99522db5b911 merge audio source files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
356 {
19675
793d295fed4d Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19571
diff changeset
357 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
358 int bits = value_arg.int_value ();
19510
99522db5b911 merge audio source files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
359 if (bits == 8)
19675
793d295fed4d Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19571
diff changeset
360 {
793d295fed4d Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19571
diff changeset
361 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
362 info.format |= SF_FORMAT_PCM_U8;
793d295fed4d Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19571
diff changeset
363 else
793d295fed4d Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19571
diff changeset
364 info.format |= SF_FORMAT_PCM_S8;
793d295fed4d Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19571
diff changeset
365 }
19510
99522db5b911 merge audio source files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
366 else if (bits == 16)
99522db5b911 merge audio source files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
367 info.format |= SF_FORMAT_PCM_16;
99522db5b911 merge audio source files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
368 else if (bits == 24)
99522db5b911 merge audio source files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
369 info.format |= SF_FORMAT_PCM_24;
99522db5b911 merge audio source files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
370 else if (bits == 32)
99522db5b911 merge audio source files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
371 info.format |= SF_FORMAT_PCM_32;
99522db5b911 merge audio source files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
372 else
20825
66cd994d1b79 eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents: 20790
diff changeset
373 error ("audiowrite: wrong number of bits specified");
19510
99522db5b911 merge audio source files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
374 }
21693
2c6d1ef071d1 avoid crash in audiowrite argument processing (bug #47875)
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
375 else if (keyword == "BitRate")
19510
99522db5b911 merge audio source files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
376 ;
23024
a6a7b054e4ba Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents: 22755
diff changeset
377 // FIXME: Quality is currently unused?
21693
2c6d1ef071d1 avoid crash in audiowrite argument processing (bug #47875)
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
378 // else if (keyword == "Quality")
2c6d1ef071d1 avoid crash in audiowrite argument processing (bug #47875)
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
379 // quality = value_arg.int_value () * 0.01;
2c6d1ef071d1 avoid crash in audiowrite argument processing (bug #47875)
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
380 else if (keyword == "Title")
2c6d1ef071d1 avoid crash in audiowrite argument processing (bug #47875)
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
381 title = value_arg.string_value ();
2c6d1ef071d1 avoid crash in audiowrite argument processing (bug #47875)
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
382 else if (keyword == "Artist")
2c6d1ef071d1 avoid crash in audiowrite argument processing (bug #47875)
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
383 artist = value_arg.string_value ();
2c6d1ef071d1 avoid crash in audiowrite argument processing (bug #47875)
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
384 else if (keyword == "Comment")
2c6d1ef071d1 avoid crash in audiowrite argument processing (bug #47875)
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
385 comment = value_arg.string_value ();
19510
99522db5b911 merge audio source files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
386 else
20825
66cd994d1b79 eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents: 20790
diff changeset
387 error ("audiowrite: wrong argument name");
19510
99522db5b911 merge audio source files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
388 }
19519
e616c2830413 various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents: 19516
diff changeset
389
19559
701b43ce4467 properly close audio files
John W. Eaton <jwe@octave.org>
parents: 19554
diff changeset
390 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
391
19553
57efd0a020cf write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents: 19544
diff changeset
392 if (! file)
20825
66cd994d1b79 eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents: 20790
diff changeset
393 error ("audiowrite: failed to open output file %s", filename.c_str ());
19519
e616c2830413 various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents: 19516
diff changeset
394
21743
f4d7d0eb5b0c use namespace for unwind_protect class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
395 octave::unwind_protect frame;
19559
701b43ce4467 properly close audio files
John W. Eaton <jwe@octave.org>
parents: 19554
diff changeset
396
701b43ce4467 properly close audio files
John W. Eaton <jwe@octave.org>
parents: 19554
diff changeset
397 frame.add_fcn (safe_close, file);
701b43ce4467 properly close audio files
John W. Eaton <jwe@octave.org>
parents: 19554
diff changeset
398
19510
99522db5b911 merge audio source files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
399 if (title != "")
99522db5b911 merge audio source files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
400 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
401
19510
99522db5b911 merge audio source files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
402 if (artist != "")
99522db5b911 merge audio source files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
403 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
404
19510
99522db5b911 merge audio source files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
405 if (comment != "")
99522db5b911 merge audio source files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
406 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
407
19553
57efd0a020cf write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents: 19544
diff changeset
408 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
409 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
410
57efd0a020cf write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents: 19544
diff changeset
411 if (chunk_size == 0)
57efd0a020cf write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents: 19544
diff changeset
412 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
413
57efd0a020cf write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents: 19544
diff changeset
414 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
415 {
57efd0a020cf write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents: 19544
diff changeset
416 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
417 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
418
57efd0a020cf write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents: 19544
diff changeset
419 sf_count_t items_written = sf_write_float (file, data+offset, chunk_size);
57efd0a020cf write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents: 19544
diff changeset
420
57efd0a020cf write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents: 19544
diff changeset
421 if (items_written != chunk_size)
20825
66cd994d1b79 eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents: 20790
diff changeset
422 error ("audiowrite: write failed, wrote %ld of %ld items\n",
66cd994d1b79 eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents: 20790
diff changeset
423 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
424
57efd0a020cf write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents: 19544
diff changeset
425 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
426 offset += chunk_size;
57efd0a020cf write ogg files in chunks to avoid apparent bug
John W. Eaton <jwe@octave.org>
parents: 19544
diff changeset
427 }
19519
e616c2830413 various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents: 19516
diff changeset
428
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20865
diff changeset
429 // FIXME: shouldn't we return something to indicate whether the file
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20865
diff changeset
430 // was written successfully?
20941
a4f5da7c5463 maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents: 20940
diff changeset
431 return ovl ();
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20865
diff changeset
432
19510
99522db5b911 merge audio source files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
433 #else
19519
e616c2830413 various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents: 19516
diff changeset
434
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21602
diff changeset
435 octave_unused_parameter (args);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21602
diff changeset
436
21103
5a83a422d8a7 Don't set 3rd argument to err_disabled_feature within core Octave.
Rik <rik@octave.org>
parents: 21100
diff changeset
437 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
438 "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
439
19510
99522db5b911 merge audio source files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
440 #endif
99522db5b911 merge audio source files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
441 }
99522db5b911 merge audio source files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
442
99522db5b911 merge audio source files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
443 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
444 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
445 @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
446 Return information about an audio file specified by @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
447 @end deftypefn */)
19510
99522db5b911 merge audio source files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
448 {
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21712
diff changeset
449 #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
450
19519
e616c2830413 various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents: 19516
diff changeset
451 if (args.length () != 1)
20790
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20578
diff changeset
452 print_usage ();
19519
e616c2830413 various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents: 19516
diff changeset
453
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20865
diff changeset
454 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
455
19510
99522db5b911 merge audio source files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
456 SF_INFO info;
99522db5b911 merge audio source files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
457 info.format = 0;
19554
398e42431dcc improve argument decoding in audioread.cc functions
John W. Eaton <jwe@octave.org>
parents: 19553
diff changeset
458 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
459
19559
701b43ce4467 properly close audio files
John W. Eaton <jwe@octave.org>
parents: 19554
diff changeset
460 if (! file)
20825
66cd994d1b79 eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents: 20790
diff changeset
461 error ("audioinfo: failed to open file %s", filename.c_str ());
19559
701b43ce4467 properly close audio files
John W. Eaton <jwe@octave.org>
parents: 19554
diff changeset
462
21743
f4d7d0eb5b0c use namespace for unwind_protect class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
463 octave::unwind_protect frame;
19559
701b43ce4467 properly close audio files
John W. Eaton <jwe@octave.org>
parents: 19554
diff changeset
464
701b43ce4467 properly close audio files
John W. Eaton <jwe@octave.org>
parents: 19554
diff changeset
465 frame.add_fcn (safe_close, file);
701b43ce4467 properly close audio files
John W. Eaton <jwe@octave.org>
parents: 19554
diff changeset
466
19519
e616c2830413 various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents: 19516
diff changeset
467 octave_scalar_map result;
e616c2830413 various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents: 19516
diff changeset
468
19554
398e42431dcc improve argument decoding in audioread.cc functions
John W. Eaton <jwe@octave.org>
parents: 19553
diff changeset
469 result.assign ("Filename", filename);
19519
e616c2830413 various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents: 19516
diff changeset
470 result.assign ("CompressionMethod", "");
e616c2830413 various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents: 19516
diff changeset
471 result.assign ("NumChannels", info.channels);
e616c2830413 various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents: 19516
diff changeset
472 result.assign ("SampleRate", info.samplerate);
e616c2830413 various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents: 19516
diff changeset
473 result.assign ("TotalSamples", info.frames);
e616c2830413 various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents: 19516
diff changeset
474
19513
4cb4210bd392 use C++ style casts in audio code
John W. Eaton <jwe@octave.org>
parents: 19512
diff changeset
475 double dframes = info.frames;
4cb4210bd392 use C++ style casts in audio code
John W. Eaton <jwe@octave.org>
parents: 19512
diff changeset
476 double drate = info.samplerate;
19519
e616c2830413 various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents: 19516
diff changeset
477 result.assign ("Duration", dframes / drate);
19510
99522db5b911 merge audio source files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
478
99522db5b911 merge audio source files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
479 int bits;
19675
793d295fed4d Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19571
diff changeset
480 switch (info.format & SF_FORMAT_SUBMASK)
793d295fed4d Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19571
diff changeset
481 {
793d295fed4d Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19571
diff changeset
482 case SF_FORMAT_PCM_S8:
793d295fed4d Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19571
diff changeset
483 bits = 8;
793d295fed4d Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19571
diff changeset
484 break;
793d295fed4d Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19571
diff changeset
485 case SF_FORMAT_PCM_U8:
793d295fed4d Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19571
diff changeset
486 bits = 8;
793d295fed4d Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19571
diff changeset
487 break;
793d295fed4d Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19571
diff changeset
488 case SF_FORMAT_PCM_16:
793d295fed4d Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19571
diff changeset
489 bits = 16;
793d295fed4d Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19571
diff changeset
490 break;
793d295fed4d Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19571
diff changeset
491 case SF_FORMAT_PCM_24:
793d295fed4d Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19571
diff changeset
492 bits = 24;
793d295fed4d Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19571
diff changeset
493 break;
793d295fed4d Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19571
diff changeset
494 case SF_FORMAT_PCM_32:
793d295fed4d Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19571
diff changeset
495 bits = 32;
793d295fed4d Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19571
diff changeset
496 break;
793d295fed4d Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19571
diff changeset
497 default:
793d295fed4d Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19571
diff changeset
498 bits = -1;
793d295fed4d Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19571
diff changeset
499 break;
793d295fed4d Fix sndfile bit width handling in audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19571
diff changeset
500 }
19510
99522db5b911 merge audio source files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
501
19519
e616c2830413 various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents: 19516
diff changeset
502 result.assign ("BitsPerSample", bits);
e616c2830413 various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents: 19516
diff changeset
503 result.assign ("BitRate", -1);
e616c2830413 various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents: 19516
diff changeset
504 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
505 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
506 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
507
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20865
diff changeset
508 return ovl (result);
19519
e616c2830413 various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents: 19516
diff changeset
509
19510
99522db5b911 merge audio source files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
510 #else
19519
e616c2830413 various style fixes for audio code
John W. Eaton <jwe@octave.org>
parents: 19516
diff changeset
511
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21602
diff changeset
512 octave_unused_parameter (args);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21602
diff changeset
513
21103
5a83a422d8a7 Don't set 3rd argument to err_disabled_feature within core Octave.
Rik <rik@octave.org>
parents: 21100
diff changeset
514 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
515 "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
516
19510
99522db5b911 merge audio source files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
517 #endif
99522db5b911 merge audio source files
John W. Eaton <jwe@octave.org>
parents: 19505
diff changeset
518 }
21709
88657798b650 audioformats: New function to list available audio formats (bug #47464)
Damjan Angelovski <damjangelovski@gmail.com>
parents: 21694
diff changeset
519
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21712
diff changeset
520 #if defined (HAVE_SNDFILE)
21712
09e1bb792dd9 Fix compilation error when building without sndfile
Mike Miller <mtmiller@octave.org>
parents: 21710
diff changeset
521
21710
f7850bd66042 audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents: 21709
diff changeset
522 static void
f7850bd66042 audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents: 21709
diff changeset
523 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
524 {
21710
f7850bd66042 audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents: 21709
diff changeset
525 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
526 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
527
88657798b650 audioformats: New function to list available audio formats (bug #47464)
Damjan Angelovski <damjangelovski@gmail.com>
parents: 21694
diff changeset
528 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
529 {
21710
f7850bd66042 audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents: 21709
diff changeset
530 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
531 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
532 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
533
f7850bd66042 audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents: 21709
diff changeset
534 SF_INFO sfinfo;
f7850bd66042 audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents: 21709
diff changeset
535 memset (&sfinfo, 0, sizeof (sfinfo));
f7850bd66042 audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents: 21709
diff changeset
536 sfinfo.channels = 1;
f7850bd66042 audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents: 21709
diff changeset
537 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
538
88657798b650 audioformats: New function to list available audio formats (bug #47464)
Damjan Angelovski <damjangelovski@gmail.com>
parents: 21694
diff changeset
539 if (sf_format_check (&sfinfo))
21710
f7850bd66042 audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents: 21709
diff changeset
540 octave_stdout << " " << info.name << std::endl;
f7850bd66042 audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents: 21709
diff changeset
541 }
21709
88657798b650 audioformats: New function to list available audio formats (bug #47464)
Damjan Angelovski <damjangelovski@gmail.com>
parents: 21694
diff changeset
542 }
88657798b650 audioformats: New function to list available audio formats (bug #47464)
Damjan Angelovski <damjangelovski@gmail.com>
parents: 21694
diff changeset
543
21712
09e1bb792dd9 Fix compilation error when building without sndfile
Mike Miller <mtmiller@octave.org>
parents: 21710
diff changeset
544 #endif
09e1bb792dd9 Fix compilation error when building without sndfile
Mike Miller <mtmiller@octave.org>
parents: 21710
diff changeset
545
21709
88657798b650 audioformats: New function to list available audio formats (bug #47464)
Damjan Angelovski <damjangelovski@gmail.com>
parents: 21694
diff changeset
546 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
547 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
548 @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
549 @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
550 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
551
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
552 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
553 with names that start with @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
554 @end deftypefn */)
21709
88657798b650 audioformats: New function to list available audio formats (bug #47464)
Damjan Angelovski <damjangelovski@gmail.com>
parents: 21694
diff changeset
555 {
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21712
diff changeset
556 #if defined (HAVE_SNDFILE)
21710
f7850bd66042 audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents: 21709
diff changeset
557
21709
88657798b650 audioformats: New function to list available audio formats (bug #47464)
Damjan Angelovski <damjangelovski@gmail.com>
parents: 21694
diff changeset
558 if (args.length () > 1)
88657798b650 audioformats: New function to list available audio formats (bug #47464)
Damjan Angelovski <damjangelovski@gmail.com>
parents: 21694
diff changeset
559 print_usage ();
88657798b650 audioformats: New function to list available audio formats (bug #47464)
Damjan Angelovski <damjangelovski@gmail.com>
parents: 21694
diff changeset
560
21710
f7850bd66042 audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents: 21709
diff changeset
561 std::string search = "";
f7850bd66042 audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents: 21709
diff changeset
562 if (args.length () > 0)
f7850bd66042 audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents: 21709
diff changeset
563 {
f7850bd66042 audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents: 21709
diff changeset
564 search = args(0).string_value ();
f7850bd66042 audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents: 21709
diff changeset
565 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
566 }
21709
88657798b650 audioformats: New function to list available audio formats (bug #47464)
Damjan Angelovski <damjangelovski@gmail.com>
parents: 21694
diff changeset
567
21710
f7850bd66042 audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents: 21709
diff changeset
568 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
569 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
570
88657798b650 audioformats: New function to list available audio formats (bug #47464)
Damjan Angelovski <damjangelovski@gmail.com>
parents: 21694
diff changeset
571 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
572 {
21710
f7850bd66042 audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents: 21709
diff changeset
573 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
574 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
575 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
576 bool match = true;
21709
88657798b650 audioformats: New function to list available audio formats (bug #47464)
Damjan Angelovski <damjangelovski@gmail.com>
parents: 21694
diff changeset
577
21710
f7850bd66042 audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents: 21709
diff changeset
578 if (! search.empty ())
f7850bd66042 audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents: 21709
diff changeset
579 {
f7850bd66042 audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents: 21709
diff changeset
580 std::string nm = info.name;
f7850bd66042 audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents: 21709
diff changeset
581 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
582 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
583 }
21709
88657798b650 audioformats: New function to list available audio formats (bug #47464)
Damjan Angelovski <damjangelovski@gmail.com>
parents: 21694
diff changeset
584
21710
f7850bd66042 audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents: 21709
diff changeset
585 if (match)
21709
88657798b650 audioformats: New function to list available audio formats (bug #47464)
Damjan Angelovski <damjangelovski@gmail.com>
parents: 21694
diff changeset
586 {
21710
f7850bd66042 audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents: 21709
diff changeset
587 octave_stdout << "name: " << info.name << std::endl;
f7850bd66042 audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents: 21709
diff changeset
588 octave_stdout << "extension: " << info.extension << std::endl;
f7850bd66042 audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents: 21709
diff changeset
589 octave_stdout << "id: " << info.format << std::endl;
f7850bd66042 audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents: 21709
diff changeset
590 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
591
21710
f7850bd66042 audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents: 21709
diff changeset
592 audio_sub_formats (info.format);
f7850bd66042 audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents: 21709
diff changeset
593 }
f7850bd66042 audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents: 21709
diff changeset
594 }
21709
88657798b650 audioformats: New function to list available audio formats (bug #47464)
Damjan Angelovski <damjangelovski@gmail.com>
parents: 21694
diff changeset
595
88657798b650 audioformats: New function to list available audio formats (bug #47464)
Damjan Angelovski <damjangelovski@gmail.com>
parents: 21694
diff changeset
596 #else
22265
15b9d7cb3098 eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
597
15b9d7cb3098 eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
598 octave_unused_parameter (args);
15b9d7cb3098 eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
599
21709
88657798b650 audioformats: New function to list available audio formats (bug #47464)
Damjan Angelovski <damjangelovski@gmail.com>
parents: 21694
diff changeset
600 err_disabled_feature ("audioformats",
88657798b650 audioformats: New function to list available audio formats (bug #47464)
Damjan Angelovski <damjangelovski@gmail.com>
parents: 21694
diff changeset
601 "getting sound formats through libsndfile");
22265
15b9d7cb3098 eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
602
21709
88657798b650 audioformats: New function to list available audio formats (bug #47464)
Damjan Angelovski <damjangelovski@gmail.com>
parents: 21694
diff changeset
603 #endif
21710
f7850bd66042 audioformats: Clean up coding style and docstring
Mike Miller <mtmiller@octave.org>
parents: 21709
diff changeset
604
23024
a6a7b054e4ba Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents: 22755
diff changeset
605 return octave_value_list ();
21709
88657798b650 audioformats: New function to list available audio formats (bug #47464)
Damjan Angelovski <damjangelovski@gmail.com>
parents: 21694
diff changeset
606 }