Mercurial > octave
comparison libinterp/dldfcn/audioread.cc @ 20939:b17fda023ca6
maint: Use new C++ archetype in more files.
Place input validation first in files.
Move declaration of retval down in function to be closer to point of usage.
Eliminate else clause after if () error.
Use "return ovl()" where it makes sense.
* find.cc, gammainc.cc, gcd.cc, getgrent.cc, getpwent.cc, givens.cc,
graphics.cc, help.cc, hess.cc, hex2num.cc, input.cc, kron.cc, load-path.cc,
load-save.cc, lookup.cc, mappers.cc, matrix_type.cc, mgorth.cc, nproc.cc,
ordschur.cc, pager.cc, pinv.cc, pr-output.cc, profiler.cc, psi.cc, quad.cc,
rcond.cc, regexp.cc, schur.cc, sighandlers.cc, sparse.cc, str2double.cc,
strfind.cc, strfns.cc, sub2ind.cc, svd.cc, sylvester.cc, symtab.cc,
syscalls.cc, sysdep.cc, time.cc, toplev.cc, tril.cc, tsearch.cc, typecast.cc,
urlwrite.cc, utils.cc, variables.cc, __delaunayn__.cc, __eigs__.cc,
__glpk__.cc, __magick_read__.cc, __osmesa_print__.cc, __voronoi__.cc, amd.cc,
audiodevinfo.cc, audioread.cc, chol.cc, colamd.cc, dmperm.cc, fftw.cc, qr.cc,
symbfact.cc, symrcm.cc, ov-bool-mat.cc, ov-cell.cc, ov-class.cc,
ov-classdef.cc, ov-fcn-handle.cc, ov-fcn-inline.cc, ov-flt-re-mat.cc,
ov-java.cc, ov-null-mat.cc, ov-oncleanup.cc, ov-re-mat.cc, ov-struct.cc,
ov-typeinfo.cc, ov-usr-fcn.cc, ov.cc, octave.cc:
Use new C++ archetype in more files.
author | Rik <rik@octave.org> |
---|---|
date | Fri, 18 Dec 2015 15:37:22 -0800 |
parents | 4a6d4375a0ca |
children | 48b2ad5ee801 |
comparison
equal
deleted
inserted
replaced
20938:aac911d8847b | 20939:b17fda023ca6 |
---|---|
68 The optional argument @var{datatype} specifies the datatype to return.\n\ | 68 The optional argument @var{datatype} specifies the datatype to return.\n\ |
69 If it is @qcode{\"native\"}, then the type of data depends on how the data\n\ | 69 If it is @qcode{\"native\"}, then the type of data depends on how the data\n\ |
70 is stored in the audio file.\n\ | 70 is stored in the audio file.\n\ |
71 @end deftypefn") | 71 @end deftypefn") |
72 { | 72 { |
73 octave_value_list retval; | |
74 | |
75 #ifdef HAVE_SNDFILE | 73 #ifdef HAVE_SNDFILE |
76 | 74 |
77 int nargin = args.length (); | 75 int nargin = args.length (); |
78 | 76 |
79 if (nargin < 1 || nargin > 3) | 77 if (nargin < 1 || nargin > 3) |
80 print_usage (); | 78 print_usage (); |
81 | 79 |
82 std::string filename = args(0).string_value (); | 80 std::string filename = args(0).xstring_value ("audioread: FILENAME must be a string"); |
83 | 81 |
84 SF_INFO info; | 82 SF_INFO info; |
85 info.format = 0; | 83 info.format = 0; |
86 SNDFILE *file = sf_open (filename.c_str (), SFM_READ, &info); | 84 SNDFILE *file = sf_open (filename.c_str (), SFM_READ, &info); |
87 | 85 |
169 ret_audio = audio; | 167 ret_audio = audio; |
170 } | 168 } |
171 else | 169 else |
172 ret_audio = audio; | 170 ret_audio = audio; |
173 | 171 |
174 retval = ovl (ret_audio, info.samplerate); | 172 return ovl (ret_audio, info.samplerate); |
175 | 173 |
176 #else | 174 #else |
177 | |
178 error ("sndfile not found on your system and thus audioread is not functional"); | 175 error ("sndfile not found on your system and thus audioread is not functional"); |
179 | 176 #endif |
180 #endif | |
181 | |
182 return retval; | |
183 } | 177 } |
184 | 178 |
185 #ifdef HAVE_SNDFILE | 179 #ifdef HAVE_SNDFILE |
186 | 180 |
187 static int | 181 static int |
260 @item Comment\n\ | 254 @item Comment\n\ |
261 Comment.\n\ | 255 Comment.\n\ |
262 @end table\n\ | 256 @end table\n\ |
263 @end deftypefn") | 257 @end deftypefn") |
264 { | 258 { |
265 // FIXME: shouldn't we return something to indicate whether the file | |
266 // was written successfully? | |
267 | |
268 octave_value retval; | |
269 | |
270 #ifdef HAVE_SNDFILE | 259 #ifdef HAVE_SNDFILE |
271 | 260 |
272 int nargin = args.length (); | 261 int nargin = args.length (); |
273 | 262 |
274 if (nargin < 3) | 263 if (nargin < 3) |
275 print_usage (); | 264 print_usage (); |
276 | 265 |
277 std::string filename = args(0).string_value (); | 266 std::string filename = args(0).xstring_value ("audiowrite: FILENAME must be a string"); |
278 | |
279 Matrix audio = args(1).matrix_value (); | |
280 | 267 |
281 double bias = 0.0; | 268 double bias = 0.0; |
282 double scale = 1.0; | 269 double scale = 1.0; |
283 | 270 |
284 if (args(1).is_uint8_type ()) | 271 if (args(1).is_uint8_type ()) |
288 else if (args(1).is_int32_type ()) | 275 else if (args(1).is_int32_type ()) |
289 scale = std::pow (2.0, 31); | 276 scale = std::pow (2.0, 31); |
290 else if (args(1).is_integer_type ()) | 277 else if (args(1).is_integer_type ()) |
291 { | 278 { |
292 gripe_wrong_type_arg ("audiowrite", args(1)); | 279 gripe_wrong_type_arg ("audiowrite", args(1)); |
293 return retval; | 280 return octave_value_list (); |
294 } | 281 } |
282 | |
283 Matrix audio = args(1).matrix_value (); | |
295 | 284 |
296 int samplerate = args(2).int_value (); | 285 int samplerate = args(2).int_value (); |
297 | 286 |
298 std::string ext; | 287 std::string ext; |
299 size_t dotpos = filename.find_last_of ("."); | 288 size_t dotpos = filename.find_last_of ("."); |
423 | 412 |
424 total_items_written += items_written; | 413 total_items_written += items_written; |
425 offset += chunk_size; | 414 offset += chunk_size; |
426 } | 415 } |
427 | 416 |
417 // FIXME: shouldn't we return something to indicate whether the file | |
418 // was written successfully? | |
419 return octave_value_list (); | |
420 | |
428 #else | 421 #else |
429 | 422 |
430 error ("sndfile not found on your system and thus audiowrite is not functional"); | 423 error ("sndfile not found on your system and thus audiowrite is not functional"); |
431 | 424 |
432 #endif | 425 #endif |
433 | |
434 return retval; | |
435 } | 426 } |
436 | 427 |
437 DEFUN_DLD (audioinfo, args, , | 428 DEFUN_DLD (audioinfo, args, , |
438 "-*- texinfo -*-\n\ | 429 "-*- texinfo -*-\n\ |
439 @deftypefn {} {@var{info} =} audioinfo (@var{filename})\n\ | 430 @deftypefn {} {@var{info} =} audioinfo (@var{filename})\n\ |
440 Return information about an audio file specified by @var{filename}.\n\ | 431 Return information about an audio file specified by @var{filename}.\n\ |
441 @end deftypefn") | 432 @end deftypefn") |
442 { | 433 { |
443 octave_value retval; | 434 #ifdef HAVE_SNDFILE |
444 | |
445 #ifdef HAVE_SNDFILE | |
446 | |
447 if (args.length () != 1) | 435 if (args.length () != 1) |
448 print_usage (); | 436 print_usage (); |
449 | 437 |
450 std::string filename = args(0).string_value (); | 438 std::string filename = args(0).xstring_value ("audioinfo: FILENAME must be a string"); |
451 | 439 |
452 SF_INFO info; | 440 SF_INFO info; |
453 info.format = 0; | 441 info.format = 0; |
454 SNDFILE *file = sf_open (filename.c_str (), SFM_READ, &info); | 442 SNDFILE *file = sf_open (filename.c_str (), SFM_READ, &info); |
455 | 443 |
499 result.assign ("BitRate", -1); | 487 result.assign ("BitRate", -1); |
500 result.assign ("Title", sf_get_string (file, SF_STR_TITLE)); | 488 result.assign ("Title", sf_get_string (file, SF_STR_TITLE)); |
501 result.assign ("Artist", sf_get_string (file, SF_STR_ARTIST)); | 489 result.assign ("Artist", sf_get_string (file, SF_STR_ARTIST)); |
502 result.assign ("Comment", sf_get_string (file, SF_STR_COMMENT)); | 490 result.assign ("Comment", sf_get_string (file, SF_STR_COMMENT)); |
503 | 491 |
504 retval = result; | 492 return ovl (result); |
505 | 493 |
506 #else | 494 #else |
507 | 495 |
508 error ("sndfile not found on your system and thus audioinfo is not functional"); | 496 error ("sndfile not found on your system and thus audioinfo is not functional"); |
509 | 497 |
510 #endif | 498 #endif |
511 | |
512 return retval; | |
513 } | 499 } |