shithub: opus-tools

Download patch

ref: 2e207ac9db9f3274afb81439602cc2a54fc213bb
parent: 77136343e3ac3e0610a3cedd89a7a6ec70761123
author: Gregory Maxwell <[email protected]>
date: Tue Feb 5 10:04:36 EST 2013

Make sure the flac input replay gain tag parsing uses the C locale.

My best read of the spec suggests that the the replay gain tags should always
 be formatted with the "." radix (rather than, say, ",") and certainly our
 parsing should not depend in the user's locale setting.

--- a/src/flac.c
+++ b/src/flac.c
@@ -4,6 +4,7 @@
 #include <stdlib.h>
 #include <math.h>
 #include <string.h>
+#include <locale.h>
 #include "flac.h"
 #include "opus_header.h"
 
@@ -103,6 +104,7 @@
         double gain;
         int saw_album_gain;
         int saw_track_gain;
+        char *saved_locale;
         if(!inopt->copy_comments)break;
         num_comments=metadata->data.vorbis_comment.num_comments;
         comments=metadata->data.vorbis_comment.comments;
@@ -110,6 +112,8 @@
         album_gain=track_gain=0;
         /*The default reference loudness for ReplayGain is 89.0 dB*/
         reference_loudness=89;
+        /*The code below uses strtod for the gain tags, so make sure the locale is C*/
+        saved_locale=setlocale(LC_NUMERIC,"C");
         for(i=0;i<num_comments;i++){
           char *entry;
           char *end;
@@ -158,6 +162,7 @@
           }
           comment_add(&inopt->comments,&inopt->comments_length,NULL,entry);
         }
+        setlocale(LC_NUMERIC,saved_locale);
         /*Set the header gain to the album gain after converting to the R128
           reference level.*/
         if(saw_album_gain){