changeset 23873:9ada3f4f4e28

audioinfo: return absolute file name in info structure * audioread.cc (Faudioinfo): Return absolute file name of file argument in audio info structure. Check for file existence to differentiate from failure to read audio format with sndfile.
author Mike Miller <mtmiller@octave.org>
date Thu, 10 Aug 2017 14:55:47 -0700
parents 9b39ec2e0952
children 28588cfe69fd
files libinterp/dldfcn/audioread.cc
diffstat 1 files changed, 10 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/dldfcn/audioread.cc	Thu Aug 10 17:35:19 2017 -0400
+++ b/libinterp/dldfcn/audioread.cc	Thu Aug 10 14:55:47 2017 -0700
@@ -31,6 +31,8 @@
 
 #include "dMatrix.h"
 #include "dRowVector.h"
+#include "file-ops.h"
+#include "file-stat.h"
 #include "oct-locbuf.h"
 #include "unwind-prot.h"
 
@@ -505,12 +507,16 @@
 
   std::string filename = args(0).xstring_value ("audioinfo: FILENAME must be a string");
 
+  octave::sys::file_stat fs (filename);
+  if (! fs.exists ())
+    error ("audioinfo: FILENAME '%s' not found", filename.c_str ());
+
   SF_INFO info;
   info.format = 0;
   SNDFILE *file = sf_open (filename.c_str (), SFM_READ, &info);
 
   if (! file)
-    error ("audioinfo: failed to open file %s", filename.c_str ());
+    error ("audioinfo: failed to open file '%s'", filename.c_str ());
 
   octave::unwind_protect frame;
 
@@ -518,7 +524,9 @@
 
   octave_scalar_map result;
 
-  result.assign ("Filename", filename);
+  std::string full_name = octave::sys::canonicalize_file_name (filename);
+
+  result.assign ("Filename", full_name);
   result.assign ("CompressionMethod", "");
   result.assign ("NumChannels", info.channels);
   result.assign ("SampleRate", info.samplerate);