Discussion:
[mad-user] dB gain --> command-line volume switch?
Ert
2004-03-05 16:43:44 UTC
Permalink
Hiya.

This isn't really a MAD question, but it was suggested to me to try
this list: I'm trying to implement some support for the output of the
'normalize' package in my mp3 player of choice, but ran into the
problem that it doesn't seem that either mpg123 or mpg321 currently
support the RVA2 volume adjustment tag in ID3v2.4 tags. So I wrote a
little routine in the jukebox wrapper program I'm using ('Tunez') to
pull out normalize's backwards-compatible ID3v2.3 "XRVA" tag data.

Practical upshot is that before I call mpg321 I know that I want my
file to be played, say, 5 dB louder or 10 dB quieter, but don't know
how to translate that into the " -gain " argument's 0-100 scale on
mpg123 or mpg321. I could figure this out by trial and error, but was
hoping there might be a more definitive conversion. Anyone have any
thoughts?

Thanks!
- Ert Dredge
Rob Leslie
2004-03-05 20:08:53 UTC
Permalink
Post by Ert
This isn't really a MAD question, but it was suggested to me to try
this list: I'm trying to implement some support for the output of the
'normalize' package in my mp3 player of choice, but ran into the
problem that it doesn't seem that either mpg123 or mpg321 currently
support the RVA2 volume adjustment tag in ID3v2.4 tags. So I wrote a
little routine in the jukebox wrapper program I'm using ('Tunez') to
pull out normalize's backwards-compatible ID3v2.3 "XRVA" tag data.
Practical upshot is that before I call mpg321 I know that I want my
file to be played, say, 5 dB louder or 10 dB quieter, but don't know
how to translate that into the " -gain " argument's 0-100 scale on
mpg123 or mpg321. I could figure this out by trial and error, but was
hoping there might be a more definitive conversion. Anyone have any
thoughts?
I don't think Joe Drew (the author of mpg321) subscribes to this list,
but my quick check suggests mpg321's "-gain" option simply scales the
output samples by the given linear percentage. Although this would seem
to imply you couldn't increase the volume (only reduce it), it appears
no check is performed on the percentage range, so I think it is
possible to pass values >100.

To convert a decibel scalefactor to a linear one, use this formula:

linear = 10^(decibel / 20)

Then of course multiply by 100 and round to get an integer percentage.

Examples:
+5 dB => 178%
-10 dB => 32%

FWIW, if you're not absolutely tied to mpg123 or mpg321, madplay
supports decibel scalefactors directly from the command-line, and
furthermore already has native support for RVA2 volume adjustment tags.

Cheers,
--
Rob Leslie
***@mars.org
Ert
2004-03-05 20:31:26 UTC
Permalink
Hiya, Rob.
Post by Rob Leslie
Post by Ert
This isn't really a MAD question, but it was suggested to me to try
this list: I'm trying to implement some support for the output of
the 'normalize' package in my mp3 player of choice, but ran into the
problem that it doesn't seem that either mpg123 or mpg321 currently
support the RVA2 volume adjustment tag in ID3v2.4 tags. So I wrote a
little routine in the jukebox wrapper program I'm using ('Tunez') to
pull out normalize's backwards-compatible ID3v2.3 "XRVA" tag data.
Practical upshot is that before I call mpg321 I know that I want my
file to be played, say, 5 dB louder or 10 dB quieter, but don't know
how to translate that into the " -gain " argument's 0-100 scale on
mpg123 or mpg321. I could figure this out by trial and error, but
was hoping there might be a more definitive conversion. Anyone have
any thoughts?
I don't think Joe Drew (the author of mpg321) subscribes to this list
[...]
...same person who pointed me here, in fact. ;-)
Post by Rob Leslie
[...] but my quick check suggests mpg321's "-gain" option simply
scales the output samples by the given linear percentage. Although
this would seem to imply you couldn't increase the volume (only reduce
it), it appears no check is performed on the percentage range, so I
think it is possible to pass values >100.
linear = 10^(decibel / 20)
Then of course multiply by 100 and round to get an integer percentage.
+5 dB => 178%
-10 dB => 32%
Perfect, actually! I can just set 50 as my baseline volume choice, if
100 turns out to be an upper limit, then scale up or down as need be.
It'll serve the basic purpose, anyway.
Post by Rob Leslie
FWIW, if you're not absolutely tied to mpg123 or mpg321, madplay
supports decibel scalefactors directly from the command-line, and
furthermore already has native support for RVA2 volume adjustment tags.
Hm, perhaps I'll try moving to that. Didn't realize that anyone was
reading RVA2 at this point.

Thanks!

- Ert

Loading...