Menu

Quick Hack.....

2001-04-03
2001-04-04
  • Jeremy Rumpf

    Jeremy Rumpf - 2001-04-03

    Hello,

    This is a nice little plugin, been thinking of something along these lines for quite some time. Anyhow, while playing a bit, I notice that some songs that start out at a very high intensity (way greater than the silence level), will cause the gain to jump to the maximum. This may cause a bit of clipping for the first couple seconds or so of the song.

    I suppose one work around would be to set the maximum multiplier low enough to avoid clipping, but then some of my lower level encoded mp3's can't attain enough gain to reach similar levels.

    As a quick hack, I put a hold on running adjust_gain until the smooth que/buffer was around 50% full. By this time the gain will have had a bit more time and smooth data to level off a bit. A small side affect is the fact that a song that starts off at a high intensity will "jump" in volume after the first second or so, but I figure that's a lot better than blasting the speakers :).  Setting the silence level to about .0050 helped a bit.

    I agree with the TODO that the max level of each song should be stored somewhere for retrieval, perhaps sm->max? Is there any effort underway on this or anything similar? I may have some time here in the comings months to play and wouldn't want to dup efforts :)

    Cheers,
    Jeremy

    Patch to normvol.c
    created with diff -u normvol.c.orig  normvol.c

    --- normvol.c.orig      Tue Apr  3 14:21:23 2001
    +++ normvol.c   Tue Apr  3 14:49:25 2001
    @@ -32,6 +32,7 @@

    #define NO_GAIN 0.01
    #define SMOOTH_SAMPLES 100
    +#define MINIMUM_SAMPLES SMOOTH_SAMPLES/2

    /* Keep the log on the values, and smooth them */
    static smooth_t * smooth[MAX_CHANNELS];
    @@ -134,6 +135,7 @@
    static int normvol_mod_samples(gpointer* d, gint length, AFormat afmt, gint srate, gint nch)
    {
            double level = -1.0;
    +       static unsigned short minimum_sample_count = 0;
            gint to_avoid_warning = srate;
            srate = to_avoid_warning;

    @@ -155,7 +157,10 @@

            /* Check if the song changed */
            if (song_changed())
    +       {
                    restart_smoothing();
    +               minimum_sample_count = 0;
    +       }

            /* Calculate power level for this sample */
            calc_power_level(d, length, nch);
    @@ -182,16 +187,22 @@
                    /* Calculate the gain for the level */
                    double gain = normalize_level / level;

    -#ifdef PRINT_MONITOR
    -               printf(", Gain: %f", gain);
    -#endif

                    /* Make sure the gain is not above the maximum multiplier */
                    if (gain > max_mult)
                            gain = max_mult;

    +#ifdef PRINT_MONITOR
    +               printf(", Gain: %f", gain);
    +#endif
    +
                    /* Adjust the gain with the smoothed value */
    -               adjust_gain(d, length, gain);
    +               if (minimum_sample_count >= MINIMUM_SAMPLES)
    +                       adjust_gain(d, length, gain);
    +               else
    +               {
    +                       minimum_sample_count++;
    +               }

                    /* printf("Max level is %f, Gain is %f\n", level, gain); */
            }

     
    • Baruch Even

      Baruch Even - 2001-04-03

      Thanks for your input!
      I'll check the patch more carefully later on.

      I do not actively work on the plugin anymore due to lack of time, if you are interested in contributing to it, I'd be glad to accept, review and apply the patches.

      Regarding the problem that you raised, I need to consider it more carefully, I hope to have some time during next week to go over it. I do know however that there are various problems and special cases lurking.

      I'm happy that you found the plugin usefull (and took the time to say it, it helps to know that my work is appreciated and used).

      Baruch

       
      • Jeremy Rumpf

        Jeremy Rumpf - 2001-04-03

        Sounds great, I should of never looked at it because now I'm coming up with new ideas just watching xmms run. Perhaps one idea is utilizing a fade in when the songs starts as the smooth que/buffer fills. When an equilibrium is reached between the fade in and the calculated gain value, return to normal tracking of the level. Hmmm, just a thought. If/When I get around to making some mods I'll post them up to you. One other thing, is there any docs on the plugin interface to xmms? Else, I might have some further questions :) I fully understand how the smoother works etc, but I'm lacking a bit how the level data and the new gain are extracted/set from xmms. More to follow......

        Jeremy

         
    • Baruch Even

      Baruch Even - 2001-04-04

      For the fade in you might want to use the crossfade plugin, in the new version it has a way to solve a wierd lockup that sometimes happens (a lockup when using crossfade and volnorm together).

      There are virtually no docs on the plugin interface, but it's simple enough to understand from the header files and the existing plugins (that's how I learned it).

      It'll probably be easier to continue this in e-mail.

       

Log in to post a comment.

Auth0 Logo