cleanup a couple of audio file format names as reported by libsndfile
authorPaul Davis <paul@linuxaudiosystems.com>
Mon, 26 Oct 2009 20:07:25 +0000 (20:07 +0000)
committerPaul Davis <paul@linuxaudiosystems.com>
Mon, 26 Oct 2009 20:07:25 +0000 (20:07 +0000)
git-svn-id: svn://localhost/ardour2/branches/2.0-ongoing@5926 d708f5d6-7413-0410-9779-e7cbd77b26cf

libs/ardour/sndfile_helpers.cc
libs/ardour/sndfilesource.cc

index 4a85b712f1055032220bce212d945d6ef90c85a2..998e9a36c28c86b901f6a5c6d6eef5b49f1532ae 100644 (file)
@@ -17,6 +17,7 @@
 
 */
 
+#include <strings.h>
 #include <map>
 #include <vector>
 
@@ -176,7 +177,16 @@ sndfile_major_format(int format)
                        format_info.format = i;
                        sf_command (0, SFC_GET_FORMAT_MAJOR, 
                                        &format_info, sizeof (format_info));
-                       m[format_info.format & SF_FORMAT_TYPEMASK] = format_info.name;
+
+                       /* normalize a couple of names rather than use what libsndfile gives us */
+
+                       if (strncasecmp (format_info.name, "OGG", 3) == 0) {
+                               m[format_info.format & SF_FORMAT_TYPEMASK] = "Ogg";
+                       } else if (strncasecmp (format_info.name, "WAV", 3) == 0) {
+                               m[format_info.format & SF_FORMAT_TYPEMASK] = "WAV";
+                       } else {
+                               m[format_info.format & SF_FORMAT_TYPEMASK] = format_info.name;
+                       }
                }
        }
        
index b907b9739abf332545f257547606ea84711946f7..7ea3758859f6eb2c7cd908f2fe473d893ff2c956 100644 (file)
@@ -877,9 +877,15 @@ SndFileSource::get_soundfile_info (const ustring& path, SoundFileInfo& info, str
        info.samplerate  = sf_info.samplerate;
        info.channels    = sf_info.channels;
        info.length      = sf_info.frames;
-       info.format_name = string_compose("%1\n%2",
-                                          sndfile_major_format(sf_info.format),
-                                          sndfile_minor_format(sf_info.format));
+
+       string major = sndfile_major_format(sf_info.format);
+       string minor = sndfile_minor_format(sf_info.format);
+
+       if (major.length() + minor.length() < 16) { /* arbitrary */
+               info.format_name = string_compose("%1/%2", major, minor);
+       } else {
+               info.format_name = string_compose("%1\n%2", major, minor);
+       }
 
        memset (&binfo, 0, sizeof (binfo));
        info.timecode  = get_timecode_info (sf, &binfo, timecode_exists);