QUOTE (2Bdecided @ Aug 10 2007, 10:39)

I've been wondering for a while if mp3gain (and other tools) could be modified to drop the gain on blocks that would clip at the setting the user has specified. You could get clever and drop a simple psychoacoustic or distortion analysis model in there to only reduce the gain to the point where the clipping became inaudible, rather than non existant.
The blocks in compressed audio get cross-faded by design, so you're not going to get clicks by riding the gain, but it won't sound as professional as real DRC because you won't have the level of control (time-wise or amplitude-wise). If you push it too far, it will sound awful, but it might help some people.
Nice idea. I've had similar but different thoughts to make use of the loudness and peak information calculated during Replaygain analysis.
I think there could be two options.
Clip-Limiter As you said, clip prevention by frame-wise gain reduction where it's expected to be audible. This could certainly be done if the RG analysis is done on encoder frame intervals, rather than the 50ms of the original
ReplayGain proposal.
To some extent look-ahead could be used so that in the worst cases the gain before and after the clipping frame could be scaled back gradually, if this is thought to be beneficial (though I doubt it - the gain pumping is probably least objectionable when confined close to the moment of the transient).
This could be used as a peak limiter for people whose equipment makes them search for target loudness over 89 dB SPL, to limit audible clipping distortion.
Dynamic Range CompressionA second option of what to do with this technique is for some gentle dynamic range compression, e.g. for listening to highly dynamic music in a fairly noisy environment, whilst retaining the punch and impact of transients, just pulling the quieter passages up to an audible level but still a good deal quieter than the loud passages. It would apply equally for night-time quiet listening to avoid disturbing other people.
I like the idea of being able to apply each of these using the global gain value like mp3gain and aacgain or fb2k when applying gain directly to the MP3. Ideally, you could use a normal copy on your PC then when exporting to your DAP or a CD-RW or flash memory for the car, you could apply the appropriate adjustment profile to the MP3 or AAC files on the fly with no re-encoding effort or re-analysis of the decoded data.
To facilitate this, you'd simply could store a frame-by-frame loudness and peak-sample value in a metafile. A text file such as comma-separated values (CSV format), while inefficient compared to a binary encoding, would do just fine, or possibly something based around mp3DirectCut's .mpd Project files. If you have a model that determines where clipping is imperceptible you could store this maximum transparent gain (e.g. +4 would be +6.021 dB (=3 steps of 1.505 dB) in the same manner as mp3gain's format for Undo tags works. You could also store an Undo field to make it reversible, but this would have to apply to the whole file.
If you had frame-by-frame loudness stored to around 0.1 dB accuracy, for example, you could rapidly calculate Album Gain from tracks with Track Gain info stored in this way, or recalculate Album Gain for a double-album that was treated as two separate albums because of (CD1) etc in the Album Title tag. All you have to do is amalgamate the lists of loudness values then sort them and find the 95th percentile, which is the Album's perceived loudness.
The alternative to frame-by-frame storage of such info is not to retain all the loudness values, but simply specify ranges where there is no change, then frames where there is a change and what change is required.
For the dynamic compression option, you'd simply specify which passages require additional gain, and how much, and perhaps specify any fades in much the same manner as mp3DirectCut MPD files.
MPD files also allow multiple files to be joined and pieces to be cut out and rearranged. While this is powerful, it's of limited use for normal stuff, though the most powerful solution would be to incorporate full ReplayGain scanning into mp3DirectCut.
Combined approachPeople seeking >89 dB targets because of limited equipment and listening in noisy environments would probably want an extra boost to quiet passages AND an overall gain requiring peak limiting to make it about as loud as possible without too much distortion and with a bit of long-term dynamic variation but not so much that it becomes inaudible behind the background noise.