[easytag] Fix reading header information from Opus files



commit e8296e2848c9dd28bf4a1399f853e5aebef89f61
Author: David King <amigadave amigadave com>
Date:   Wed Apr 2 17:21:24 2014 +0100

    Fix reading header information from Opus files
    
    Correctly read the sample rate and duration from Opus files.
    Additionally, handle images in an Opus comment.

 src/opus_header.c |   29 +++++++++++++++++++++--------
 src/picture.c     |    1 +
 2 files changed, 22 insertions(+), 8 deletions(-)
---
diff --git a/src/opus_header.c b/src/opus_header.c
index 61bbfc8..a623893 100644
--- a/src/opus_header.c
+++ b/src/opus_header.c
@@ -153,21 +153,37 @@ et_opus_read_file_info (GFile *gfile, ET_File_Info *ETFileInfo,
     g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
 
     file = et_opus_open_file (gfile, error);
+
     if (!file)
     {
         g_assert (error == NULL || *error != NULL);
         return FALSE;
     }
 
-    info = g_file_query_info (gfile, G_FILE_ATTRIBUTE_STANDARD_SIZE,
-                              G_FILE_QUERY_INFO_NONE, NULL, NULL);
-
+    /* FIXME: Improve error-checking. */
     head = op_head (file, -1);
+    /* TODO: Read the vendor string from the Vorbis comment? */
     ETFileInfo->version = head->version;
-    ETFileInfo->bitrate = op_bitrate (file, -1);
-    ETFileInfo->samplerate = head->input_sample_rate;
+    ETFileInfo->bitrate = op_bitrate (file, -1) / 1000;
     ETFileInfo->mode = head->channel_count;
 
+    /* All Opus audio is encoded at 48 kHz, but the input sample rate can
+     * differ, and then input_sample_rate will be set. */
+    if (head->input_sample_rate != 0)
+    {
+        ETFileInfo->samplerate = head->input_sample_rate;
+    }
+    else
+    {
+        ETFileInfo->samplerate = 48000;
+    }
+
+    ETFileInfo->duration = op_pcm_total (file, -1) / 48000;
+    op_free (file);
+
+    info = g_file_query_info (gfile, G_FILE_ATTRIBUTE_STANDARD_SIZE,
+                              G_FILE_QUERY_INFO_NONE, NULL, NULL);
+
     if (info)
     {
         ETFileInfo->size = g_file_info_get_size (info);
@@ -177,9 +193,6 @@ et_opus_read_file_info (GFile *gfile, ET_File_Info *ETFileInfo,
     {
         ETFileInfo->size = 0;
     }
-    
-    ETFileInfo->duration = op_pcm_total (file, -1);
-    op_free (file);
 
     g_assert (error == NULL || *error == NULL);
     return TRUE;
diff --git a/src/picture.c b/src/picture.c
index 1aa5605..0a53dc1 100644
--- a/src/picture.c
+++ b/src/picture.c
@@ -459,6 +459,7 @@ et_picture_load_file (GFile *file, gpointer user_data)
             // Other tag types
             case ID3_TAG:
             case OGG_TAG:
+            case OPUS_TAG:
             case APE_TAG:
             case FLAC_TAG:
             case WAVPACK_TAG:


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]