allow non-strict mode for reading replaygain tags, to fallback to track tags if album...
authorJosh Coalson <jcoalson@users.sourceforce.net>
Thu, 1 Sep 2005 01:01:08 +0000 (01:01 +0000)
committerJosh Coalson <jcoalson@users.sourceforce.net>
Thu, 1 Sep 2005 01:01:08 +0000 (01:01 +0000)
doc/html/changelog.html
doc/html/documentation.html
include/share/grabbag/replaygain.h
src/flac/decode.c
src/plugin_winamp2/playback.c
src/plugin_xmms/plugin.c
src/share/grabbag/replaygain.c

index d154b2c..9d4db2b 100644 (file)
                        <li>
                                plugins:
                                <ul>
+                                       <li>When ReplayGain is on, if tags for the preferred kind of gain (album/track) are not in a stream, the other kind will be used.</li>
                                        <li>Fixed UTF-8 decoder to disallow non-shortest-form and surrogate sequences (see <a href="http://www.unicode.org/versions/corrigendum1.html">here</a>).</li>
                                </ul>
                        </li>
index 384e6a7..6b807d4 100644 (file)
                                                </li>
                                                <li>
                                                        <span class="argument">a|t</span><br />
-                                                               &nbsp;&nbsp;Specify '<span class="argument">a</span>' to use the album gain, or '<span class="argument">t</span>' to use the track gain
+                                                               &nbsp;&nbsp;Specify '<span class="argument">a</span>' to use the album gain, or '<span class="argument">t</span>' to use the track gain.  If tags for the preferred kind (album/track) do not exist but tags for the other (track/album) do, those will be used instead.
                                                </li>
                                                <li>
                                                        <span class="argument">l|L</span><br />
index e8af2d0..ac845fc 100644 (file)
@@ -59,7 +59,7 @@ const char *grabbag__replaygain_store_to_file(const char *filename, float album_
 const char *grabbag__replaygain_store_to_file_album(const char *filename, float album_gain, float album_peak, FLAC__bool preserve_modtime);
 const char *grabbag__replaygain_store_to_file_title(const char *filename, float title_gain, float title_peak, FLAC__bool preserve_modtime);
 
-FLAC__bool grabbag__replaygain_load_from_vorbiscomment(const FLAC__StreamMetadata *block, FLAC__bool album_mode, double *gain, double *peak);
+FLAC__bool grabbag__replaygain_load_from_vorbiscomment(const FLAC__StreamMetadata *block, FLAC__bool album_mode, FLAC__bool strict, double *gain, double *peak);
 double grabbag__replaygain_compute_scale_factor(double peak, double gain, double preamp, FLAC__bool prevent_clipping);
 
 #ifdef __cplusplus
index e582de3..2296db2 100644 (file)
@@ -1106,8 +1106,8 @@ void metadata_callback(const void *decoder, const FLAC__StreamMetadata *metadata
        else if(metadata->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
                if (decoder_session->replaygain.spec.apply) {
                        double gain, peak;
-                       if (!(decoder_session->replaygain.apply = grabbag__replaygain_load_from_vorbiscomment(metadata, decoder_session->replaygain.spec.use_album_gain, &gain, &peak))) {
-                               flac__utils_printf(stderr, 1, "%s: WARNING: can't get %s ReplayGain tag\n", decoder_session->inbasefilename, decoder_session->replaygain.spec.use_album_gain? "album":"track");
+                       if (!(decoder_session->replaygain.apply = grabbag__replaygain_load_from_vorbiscomment(metadata, decoder_session->replaygain.spec.use_album_gain, /*strict=*/false, &gain, &peak))) {
+                               flac__utils_printf(stderr, 1, "%s: WARNING: can't get %s (or even %s) ReplayGain tags\n", decoder_session->inbasefilename, decoder_session->replaygain.spec.use_album_gain? "album":"track", decoder_session->replaygain.spec.use_album_gain? "track":"album");
                        }
                        else {
                                const char *ls[] = { "no", "peak", "hard" };
index 9648c34..6f23386 100644 (file)
@@ -77,7 +77,7 @@ static void metadata_callback(const FLAC__FileDecoder *decoder, const FLAC__Stre
        else if (metadata->type == FLAC__METADATA_TYPE_VORBIS_COMMENT)\r
        {\r
                double gain, peak;\r
-               if (grabbag__replaygain_load_from_vorbiscomment(metadata, cfg.replaygain.album_mode, &gain, &peak))\r
+               if (grabbag__replaygain_load_from_vorbiscomment(metadata, cfg.replaygain.album_mode, /*strict=*/false, &gain, &peak))\r
                {\r
                        file_info->has_replaygain = true;\r
                        file_info->replay_scale = grabbag__replaygain_compute_scale_factor(peak, gain, (double)cfg.replaygain.preamp, !cfg.replaygain.hard_limit);\r
index 7325785..343038e 100644 (file)
@@ -798,7 +798,7 @@ void metadata_callback_(const void *decoder, const FLAC__StreamMetadata *metadat
        }
        else if(metadata->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
                double gain, peak;
-               if(grabbag__replaygain_load_from_vorbiscomment(metadata, flac_cfg.output.replaygain.album_mode, &gain, &peak)) {
+               if(grabbag__replaygain_load_from_vorbiscomment(metadata, flac_cfg.output.replaygain.album_mode, /*strict=*/false, &gain, &peak)) {
                        file_info->has_replaygain = true;
                        file_info->replay_scale = grabbag__replaygain_compute_scale_factor(peak, gain, (double)flac_cfg.output.replaygain.preamp, /*prevent_clipping=*/!flac_cfg.output.replaygain.hard_limit);
                }
index 251e0e6..4a70796 100644 (file)
@@ -581,7 +581,7 @@ static FLAC__bool parse_double_(const FLAC__StreamMetadata_VorbisComment_Entry *
        return true;
 }
 
-FLAC__bool grabbag__replaygain_load_from_vorbiscomment(const FLAC__StreamMetadata *block, FLAC__bool album_mode, double *gain, double *peak)
+FLAC__bool grabbag__replaygain_load_from_vorbiscomment(const FLAC__StreamMetadata *block, FLAC__bool album_mode, FLAC__bool strict, double *gain, double *peak)
 {
        int gain_offset, peak_offset;
 
@@ -589,14 +589,14 @@ FLAC__bool grabbag__replaygain_load_from_vorbiscomment(const FLAC__StreamMetadat
        FLAC__ASSERT(block->type == FLAC__METADATA_TYPE_VORBIS_COMMENT);
 
        if(0 > (gain_offset = FLAC__metadata_object_vorbiscomment_find_entry_from(block, /*offset=*/0, (const char *)(album_mode? GRABBAG__REPLAYGAIN_TAG_ALBUM_GAIN : GRABBAG__REPLAYGAIN_TAG_TITLE_GAIN))))
-               return false;
+               return !strict && grabbag__replaygain_load_from_vorbiscomment(block, !album_mode, /*strict=*/true, gain, peak);
        if(0 > (peak_offset = FLAC__metadata_object_vorbiscomment_find_entry_from(block, /*offset=*/0, (const char *)(album_mode? GRABBAG__REPLAYGAIN_TAG_ALBUM_PEAK : GRABBAG__REPLAYGAIN_TAG_TITLE_PEAK))))
-               return false;
+               return !strict && grabbag__replaygain_load_from_vorbiscomment(block, !album_mode, /*strict=*/true, gain, peak);
 
        if(!parse_double_(block->data.vorbis_comment.comments + gain_offset, gain))
-               return false;
+               return !strict && grabbag__replaygain_load_from_vorbiscomment(block, !album_mode, /*strict=*/true, gain, peak);
        if(!parse_double_(block->data.vorbis_comment.comments + peak_offset, peak))
-               return false;
+               return !strict && grabbag__replaygain_load_from_vorbiscomment(block, !album_mode, /*strict=*/true, gain, peak);
 
        return true;
 }