annotate libinterp/dldfcn/audiowrite.cc @ 19539:ce02743b6f2a

Fix texinfo docstring syntax for all audio functions * libinterp/dldfcn/audiodevinfo.cc, libinterp/dldfcn/audioinfo.cc, libinterp/dldfcn/audioread.cc, libinterp/dldfcn/audiowrite.cc, scripts/audio/@audioplayer/__get_properties__.m, scripts/audio/@audioplayer/audioplayer.m, scripts/audio/@audioplayer/display.m, scripts/audio/@audioplayer/get.m, scripts/audio/@audioplayer/isplaying.m, scripts/audio/@audioplayer/pause.m, scripts/audio/@audioplayer/play.m, scripts/audio/@audioplayer/playblocking.m, scripts/audio/@audioplayer/resume.m, scripts/audio/@audioplayer/set.m, scripts/audio/@audioplayer/stop.m, scripts/audio/@audiorecorder/audiorecorder.m, scripts/audio/@audiorecorder/display.m, scripts/audio/@audiorecorder/get.m, scripts/audio/@audiorecorder/getaudiodata.m, scripts/audio/@audiorecorder/getplayer.m, scripts/audio/@audiorecorder/isrecording.m, scripts/audio/@audiorecorder/pause.m, scripts/audio/@audiorecorder/play.m, scripts/audio/@audiorecorder/record.m, scripts/audio/@audiorecorder/recordblocking.m, scripts/audio/@audiorecorder/resume.m, scripts/audio/@audiorecorder/set.m, scripts/audio/@audiorecorder/stop.m: Fix texinfo docstring formatting, wrap long lines, and use consistent lowercase variable names.
author Mike Miller <mtmiller@ieee.org>
date Thu, 03 Oct 2013 09:50:01 -0400
parents 36a26a131209
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19534
8bb399569393 Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents: 19532
diff changeset
1 /*
8bb399569393 Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents: 19532
diff changeset
2
8bb399569393 Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents: 19532
diff changeset
3 Copyright (C) 2013 Vytautas JanĨauskas
8bb399569393 Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents: 19532
diff changeset
4
8bb399569393 Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents: 19532
diff changeset
5 This file is part of Octave.
8bb399569393 Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents: 19532
diff changeset
6
8bb399569393 Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents: 19532
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
8bb399569393 Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents: 19532
diff changeset
8 under the terms of the GNU General Public License as published by the
8bb399569393 Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents: 19532
diff changeset
9 Free Software Foundation; either version 3 of the License, or (at your
8bb399569393 Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents: 19532
diff changeset
10 option) any later version.
8bb399569393 Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents: 19532
diff changeset
11
8bb399569393 Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents: 19532
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
8bb399569393 Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents: 19532
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8bb399569393 Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents: 19532
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
8bb399569393 Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents: 19532
diff changeset
15 for more details.
8bb399569393 Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents: 19532
diff changeset
16
8bb399569393 Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents: 19532
diff changeset
17 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: 19532
diff changeset
18 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: 19532
diff changeset
19 <http://www.gnu.org/licenses/>.
8bb399569393 Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents: 19532
diff changeset
20
8bb399569393 Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents: 19532
diff changeset
21 */
8bb399569393 Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents: 19532
diff changeset
22
19535
1f551d169db2 Include config.h in audio project source files
Mike Miller <mtmiller@ieee.org>
parents: 19534
diff changeset
23 #ifdef HAVE_CONFIG_H
1f551d169db2 Include config.h in audio project source files
Mike Miller <mtmiller@ieee.org>
parents: 19534
diff changeset
24 #include <config.h>
1f551d169db2 Include config.h in audio project source files
Mike Miller <mtmiller@ieee.org>
parents: 19534
diff changeset
25 #endif
1f551d169db2 Include config.h in audio project source files
Mike Miller <mtmiller@ieee.org>
parents: 19534
diff changeset
26
19497
157eeaa53277 Fix includes in audioread, audiowrite and audioinfo
Vytautas Jančauskas <unaudio@gmail.com>
parents: 19496
diff changeset
27 #include "oct.h"
157eeaa53277 Fix includes in audioread, audiowrite and audioinfo
Vytautas Jančauskas <unaudio@gmail.com>
parents: 19496
diff changeset
28 #include "ov-struct.h"
19507
2e174b5e7703 Fix audiodevinfo, audioinfo, audioread and audiowrite build process
Vytautas Jančauskas <unaudio@gmail.com>
parents: 19502
diff changeset
29 #ifdef HAVE_SNDFILE
19537
36a26a131209 Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents: 19535
diff changeset
30 #include <sndfile.h>
19507
2e174b5e7703 Fix audiodevinfo, audioinfo, audioread and audiowrite build process
Vytautas Jančauskas <unaudio@gmail.com>
parents: 19502
diff changeset
31 #endif
19496
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
32 #include <string>
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
33 #include <map>
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
34
19525
93f26237c30b fix some missing semicolons and add some conditional compilation constructs to audio functions
Vytautas Jančauskas <unaudio@gmail.com>
parents: 19507
diff changeset
35 #ifdef HAVE_SNDFILE
19537
36a26a131209 Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents: 19535
diff changeset
36 static void
36a26a131209 Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents: 19535
diff changeset
37 fill_extension_table (std::map<std::string, int> &table)
19496
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
38 {
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
39 table["wav"] = SF_FORMAT_WAV;
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
40 table["aiff"] = SF_FORMAT_AIFF;
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
41 table["au"] = SF_FORMAT_AU;
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
42 table["raw"] = SF_FORMAT_RAW;
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
43 table["paf"] = SF_FORMAT_PAF;
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
44 table["svx"] = SF_FORMAT_SVX;
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
45 table["nist"] = SF_FORMAT_NIST;
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
46 table["voc"] = SF_FORMAT_VOC;
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
47 table["ircam"] = SF_FORMAT_IRCAM;
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
48 table["w64"] = SF_FORMAT_W64;
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
49 table["mat4"] = SF_FORMAT_MAT4;
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
50 table["mat5"] = SF_FORMAT_MAT5;
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
51 table["pvf"] = SF_FORMAT_PVF;
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
52 table["xi"] = SF_FORMAT_XI;
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
53 table["htk"] = SF_FORMAT_HTK;
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
54 table["sds"] = SF_FORMAT_SDS;
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
55 table["avr"] = SF_FORMAT_AVR;
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
56 table["wavex"] = SF_FORMAT_WAVEX;
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
57 table["sd2"] = SF_FORMAT_SD2;
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
58 table["flac"] = SF_FORMAT_FLAC;
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
59 table["caf"] = SF_FORMAT_CAF;
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
60 table["wve"] = SF_FORMAT_WVE;
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
61 table["ogg"] = SF_FORMAT_OGG;
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
62 table["mpc2k"] = SF_FORMAT_MPC2K;
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
63 table["rf64"] = SF_FORMAT_RF64;
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
64 }
19525
93f26237c30b fix some missing semicolons and add some conditional compilation constructs to audio functions
Vytautas Jančauskas <unaudio@gmail.com>
parents: 19507
diff changeset
65 #endif
19537
36a26a131209 Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents: 19535
diff changeset
66
36a26a131209 Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents: 19535
diff changeset
67 DEFUN_DLD (audiowrite, args, ,
19539
ce02743b6f2a Fix texinfo docstring syntax for all audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19537
diff changeset
68 "-*- texinfo -*-\n\
ce02743b6f2a Fix texinfo docstring syntax for all audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19537
diff changeset
69 @deftypefn {Loadable Function} {} audiowrite (@var{filename}, @var{y}, @var{fs})\n\
19496
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
70 \n\
19539
ce02743b6f2a Fix texinfo docstring syntax for all audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19537
diff changeset
71 Write audio data from the matrix @var{y} to a file specified by @var{filename},\n\
ce02743b6f2a Fix texinfo docstring syntax for all audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19537
diff changeset
72 file format will be determined by the file extension.\n\
19496
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
73 \n\
19532
0ac6a4e7369b change docstrings in audio defundld cc files to work with new texinfo
Vytautas Jančauskas <unaudio@gmail.com>
parents: 19525
diff changeset
74 @end deftypefn\n\
19539
ce02743b6f2a Fix texinfo docstring syntax for all audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19537
diff changeset
75 @deftypefn {Loadable Function} {} audiowrite (@var{filename}, @var{y}, @var{fs}, @var{name}, @var{value})\n\
19496
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
76 \n\
19539
ce02743b6f2a Fix texinfo docstring syntax for all audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19537
diff changeset
77 Lets you specify additional parameters when writing the file. Those parameters\n\
ce02743b6f2a Fix texinfo docstring syntax for all audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19537
diff changeset
78 are given in the table below:\n\
19496
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
79 \n\
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
80 @table @samp\n\
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
81 @item BitsPerSample\n\
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
82 Number of bits per sample, valid values are 8, 16, 24 and 32. Default is 16.\n\
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
83 @item BitRate\n\
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
84 Valid argument name, but ignored. Left for compatibility with MATLAB.\n\
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
85 @item Quality\n\
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
86 Quality setting for the Ogg Vorbis compressor. Values can range between 0 and 100 with 100 being the highest quality setting. Default is 75.\n\
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
87 @item Title\n\
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
88 Title for the audio file.\n\
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
89 @item Artist\n\
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
90 Artist name.\n\
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
91 @item Comment\n\
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
92 Comment.\n\
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
93 @end table\n\
19537
36a26a131209 Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents: 19535
diff changeset
94 @end deftypefn")
19496
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
95 {
19502
9161b7653392 compile audio file utilities even when sndfile is not present
Vytautas Jančauskas <unaudio@gmail.com>
parents: 19497
diff changeset
96 octave_scalar_map retval;
9161b7653392 compile audio file utilities even when sndfile is not present
Vytautas Jančauskas <unaudio@gmail.com>
parents: 19497
diff changeset
97 #ifdef HAVE_SNDFILE
19496
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
98 std::map<std::string, int> extension_to_format;
19537
36a26a131209 Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents: 19535
diff changeset
99 fill_extension_table (extension_to_format);
19496
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
100 std::string filename = args(0).string_value ();
19537
36a26a131209 Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents: 19535
diff changeset
101 std::string extension = filename.substr (filename.find_last_of (".") + 1);
36a26a131209 Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents: 19535
diff changeset
102 std::transform (extension.begin (), extension.end (), extension.begin (), ::tolower);
19496
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
103 Matrix audio = args(1).matrix_value ();
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
104 SNDFILE *file;
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
105 SF_INFO info;
19537
36a26a131209 Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents: 19535
diff changeset
106 float *data = (float *)malloc (audio.rows () * audio.cols () * sizeof (float));
19496
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
107 for (int i = 0; i < audio.cols (); i++)
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
108 {
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
109 for (int j = 0; j < audio.rows (); j++)
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
110 {
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
111 data[j * audio.cols () + i] = audio(j, i);
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
112 }
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
113 }
19537
36a26a131209 Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents: 19535
diff changeset
114
19496
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
115 if (extension == "ogg")
19537
36a26a131209 Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents: 19535
diff changeset
116 info.format = SF_FORMAT_VORBIS;
19496
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
117 else
19537
36a26a131209 Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents: 19535
diff changeset
118 info.format = SF_FORMAT_PCM_16;
36a26a131209 Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents: 19535
diff changeset
119
19496
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
120 std::string title = "";
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
121 std::string artist = "";
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
122 std::string comment = "";
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
123 float quality = 0.75;
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
124 for (int i = 3; i < args.length (); i += 2)
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
125 {
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
126 if (args(i).string_value () == "BitsPerSample")
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
127 {
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
128 int bits = args(i + 1).int_value ();
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
129 if (bits == 8)
19537
36a26a131209 Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents: 19535
diff changeset
130 info.format |= SF_FORMAT_PCM_S8;
19496
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
131 else if (bits == 16)
19537
36a26a131209 Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents: 19535
diff changeset
132 info.format |= SF_FORMAT_PCM_16;
19496
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
133 else if (bits == 24)
19537
36a26a131209 Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents: 19535
diff changeset
134 info.format |= SF_FORMAT_PCM_24;
19496
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
135 else if (bits == 32)
19537
36a26a131209 Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents: 19535
diff changeset
136 info.format |= SF_FORMAT_PCM_32;
19496
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
137 else
19537
36a26a131209 Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents: 19535
diff changeset
138 error ("audiowrite: wrong number of bits specified");
19496
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
139 }
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
140 else if (args(i).string_value () == "BitRate")
19537
36a26a131209 Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents: 19535
diff changeset
141 ;
19496
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
142 else if (args(i).string_value () == "Quality")
19537
36a26a131209 Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents: 19535
diff changeset
143 quality = args(i + 1).int_value () * 0.01;
19496
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
144 else if (args(i).string_value () == "Title")
19537
36a26a131209 Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents: 19535
diff changeset
145 title = args(i + 1).string_value ();
19496
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
146 else if (args(i).string_value () == "Artist")
19537
36a26a131209 Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents: 19535
diff changeset
147 artist = args(i + 1).string_value ();
19496
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
148 else if (args(i).string_value () == "Comment")
19537
36a26a131209 Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents: 19535
diff changeset
149 comment = args(i + 1).string_value ();
19496
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
150 else
19537
36a26a131209 Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents: 19535
diff changeset
151 error ("audiowrite: wrong argument name");
19496
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
152 }
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
153 info.samplerate = args(2).int_value ();
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
154 info.channels = audio.cols ();
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
155 info.format |= extension_to_format[extension];
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
156 file = sf_open (filename.c_str (), SFM_WRITE, &info);
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
157 if (title != "")
19537
36a26a131209 Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents: 19535
diff changeset
158 sf_set_string (file, SF_STR_TITLE, title.c_str ());
19496
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
159 if (artist != "")
19537
36a26a131209 Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents: 19535
diff changeset
160 sf_set_string (file, SF_STR_ARTIST, artist.c_str ());
19496
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
161 if (comment != "")
19537
36a26a131209 Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents: 19535
diff changeset
162 sf_set_string (file, SF_STR_COMMENT, comment.c_str ());
19496
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
163 sf_write_float (file, data, audio.rows () * audio.cols ());
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
164 sf_close (file);
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
165 free (data);
19502
9161b7653392 compile audio file utilities even when sndfile is not present
Vytautas Jančauskas <unaudio@gmail.com>
parents: 19497
diff changeset
166 #else
19537
36a26a131209 Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents: 19535
diff changeset
167 error ("sndfile not found on your system and thus audiowrite is not functional");
19502
9161b7653392 compile audio file utilities even when sndfile is not present
Vytautas Jančauskas <unaudio@gmail.com>
parents: 19497
diff changeset
168 #endif
19537
36a26a131209 Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents: 19535
diff changeset
169 return octave_value (retval);
19496
0243b86b3cee Added libsndfile based audio file utilities to the source tree
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
170 }