My audio file pcm_f32le has some values above 0 db. I'd like to cut/clip everything above 0. I know that I can use alimiter or loudnorm but the goal is to make values more than 0 to be equal to 0 and keep everything else unchanged. I cannot find appropriate command for this in the documentation.
+ Reply to Thread
Results 1 to 22 of 22
I need a command line tool. Also I don't need to restore clipped values. I want to cut everything above 0 and nothing more.
I want to cut everything above 0 and nothing more.
BTW, best practices of pro audio is to always set the nominal level at ~-18-24dB or so, to accommodate the digital equivalent of headroom.
Second, your example looks to already be clipping. IOW, it has already removed any signal that would have been above 0dB.
Note that your 2nd pic is a frequency-based plot. Yes, because of the clipping, and the square-waving, you have those added odd harmonics (aka spurious aliasing artifacts, which unfortunately are also correllated with the signal and so are even more noticeable than non-correllated noise). Those are what you are seeing in the frequency area above the normal limits. Those harmonics are lower in level (remember, you're not seeing LEVEL on the X or Y axes of the plot, except by looking at the intensity of the color - notice that the bulk of the intensity is in the lower frequencies).
Third, why on earth would you NOT want to un-clip? The way to restore the signal properly (beyond the preferred method of re-capturing using proper signal levels to begin with), is to un-clip. Un-clipping will result in the overall level of the signal being reduced to accommodate, and then synthesizing the peaks (based on sinusoidal extrapolation). This will do what I believe you are ultimately wanting to do, whether you realize it or not.
Fourth, I don't know of any command-line tools that are worthwhile that feature un-clipping (aka "clip restoration", "peak restoration", etc).
Although it might be possible, FFmpeg is primarily a video toolkit. I would use a compressor/limiter effect in a wave editor, or if I had to do it from the command-line, I'd use SoX (-l or the compand effect).
I would not just replace everything with zeroes; that will add audible harmonics because it's pure clipping, no different than just doing a na´ve conversion to an integer bit depth. You want to use a limiter because it will e.g. logarithmically squish everything above -3 dB so that it fits into into the 0 to -3 dB range.
* as the OP implies in the last question, one of these extremes (+1.0 or -1.0) might be an estimate; I'd have to look it up or experiment in an editor.
Last edited by ItaloFan; 20th Nov 2020 at 13:36.
Yes, I didn't catch it the first time, but his last post made that quite clear.
HOWEVER, unless this stuff was captured by some of the latest Sound Devices, or Zoom, or Tentacle Sync gear (all $$), it may CURRENTLY be 32bit float, but it wasn't captured that way. And my guess is that in the (standard PCM) capturing, it looks to have been clipped. Just because something is expressed in 32bit float format does not mean it can't represent clipped material.
The OP keeps mentioning "0dB" when referring to the spectral (frequency-based) plot - which he highlighted. But there is no gauge of 0dB on that. The cutoff seems to be ~11 or 12 kHz (probably 11.025, which is common for 22.050kHz aka 1/2 of 44.1kHz sampling rate). If you really want to remove items above the 11.025kHz line (which is what I think you think you are trying to do), either resample again to 22.050kHz (which should automatically apply an anti-aliasing filter at the Fs/2 cutoff of 11.025), or just use a brick wall Low-Pass filter at 11.025kHz without resampling.
And again, this kind of stuff is NOT best served using CLI tools.
Last edited by Cornucopia; 20th Nov 2020 at 17:32.
I selected clipped area, reduced the volume and got all clipped information back. My file is in float format pcm_f32le.
[Attachment 55920 - Click to enlarge]
I think I can open wav file as a numpy array and then replace all values above 0 with 0.
[Attachment 55921 - Click to enlarge]
But I'm not sure what is the right range for pcm_f32le [-1.0, 1.0) or [-1.0, 1.0] or (-1.0, 1.0)?
Note: if you actually DO have a 32bitFloat file that came from one of those new 32bitFloat devices, here is a link to what the demo'er experienced and how to get seemingly "clipped" signals to act un-clipped...
First, the user records a 32-bit float file on a compatible recorder to record a 32-bit float file. When the DAW first reads a 32-bit float file, signals greater than 0 dBFS may first appear clipped since, by default, files are read in with 0 dB of gain applied.
By applying attenuation to the file in the DAW, signals above 0 dBFS can be brought below 0 dBFS, undistorted, and used just like any 24- or 16-bit file.
There's no going back. The cat's out of the bag.
Anyway, from what I can gather those things have dual A/D converters sensitive to different input gains on each input, sharing the work with the combined output being 32 bit float. And some of the YouTube videos indicate it works quite well. There's no way to adjust the input gain in 32 bit mode, but from what I can tell the device doesn't try to adjust the gain either. One YouTube sceptic did say he was a little impressed when it came to amplifying very quiet sections, in respect to the noise floor, and thanks to the awesomeness of 32 bit float.
The spectrogram indicates a low-quality lossy source, like maybe a 64 kbps MP3. If he has access to an MP3, a better way to deal with it would be to downward-adjust the global gain field in the MP3 frames, e.g. with a tool designed for ReplayGain adjustments (MP3Gain/AACGain or foobar2000).
You are right it is a low-quality mp3. But occasionally there are some 1 frame peaks above 0. When I cut them out with numpy array I see the same artifacts on the spectrogram above 12 kHz. I think the best thing I can do is to use hard limiter.
Clipping (sudden flattening of wave tops) creates a square wave, which is the sum of infinite harmonics, so yes, when you introduce hard clipping, your spectrogram will show broadband spikes of noise in those places.
As I mentioned, I'd want to use a ReplayGain-applying tool to scale down the volume of the MP3. It could have been made from a heavily clipped source that is now partially clipped due to the nature of MP3 encoding, or it could have been made from an unclipped source but the MP3 was made obnoxiously loud due to its internal volume control (the global gain field in each frame). Either way, if we reduce that volume, we can then apply dynamic range compression as needed to bring the volume up to where you want without introducing any new clipping.
Feel free to PM a link to the file and I'll have a look.
If you're patient, you can adjust the volume of single MP3 frame with MP3DirectCut (it can be a bit "fiddly"). Converting to a wave file too still helps, because MP3DirectCut doesn't display a real waveform, so opening a wave file in another program can tell you where to look in MP3DirectCut. Changes are you'll only be able to reduce the volume of small sections of audio by a few dB without causing audible glitches, but it might be worth a try.
For the record, the MP3 format is capable of encoding peaks above 0dB, at least to some extent, and the same applies to AAC. Unfortunately though, not all codecs accept a 32 bit float input, and in the case of LAME which I think does, it converts to 24 bit before it encodes and clips the peaks that way. I'm fairly certain ffmpeg's version encodes 32 bit float directly and can therefore encode peaks above 0dB, although I kind of remember +6dB to +10dB being about as much as the encoder itself was happy with. It's been a while since I've tried, but I remember QAAC handling peaks well over +10dB.
So I agree with ItaloFan. Try using something like Mp3Gain or foobar2000 to adjust the volume down over-all (it's lossless for MP3/AAC) to see if looks prettier when it's decoded. Failing that, if I need to squish the occasional peak and I'm converting anyway, I mostly use foobar2000's limiter and convert/limit in a single step. The Advanced Limiter seems to do a good job, but it doesn't kick in until the audio samples hit 0dB (I don't think) so the true peaks can still exceed 0dB. My tip of the day.... I add the Amplify DSP to the conversion chain first to increase the volume by a few dB, followed by the limiter, and followed by the Amplify DSP again to reverse the volume boost. For example
Amplify (+3dB) -> Limiter -> Amplify (-3dB)
would limit to -3dB, as the audio is processed in 32 bit float.
These days, the thought of having to convert to wave, import into an editor, run a filter, adjust it, run it again, export, convert.... it's depressing just thinking about it.
Yeah, 32bit float very cool. Puts normalizing on a whole new level (pun intended), or in another sense makes it moot.
The idea of banking inputs on recorders (e.g. input 1 has mic A at low sensitivity, input 2 has same mic A at high sensitivity) is not new. In fact, I was doing that very thing, AND combining them into a much higher bitdepth consolidated master signal as much as 15 years ago. But then it was 24 or 32 bit int format. This just extends that idea even further.
The thing with mixing these is not a complete panacea, however. The adage of "every channel you mix into the master adds to the noise floor" is still true, but it just helps with the linearity and lack of quantization distortion when you work fully in 32bit float. Which isn't insignificant.
[Attachment 55957 - Click to enlarge].
I swear the next time some c%n$ asks me to subscribe to a f%#@ YouTube channel while I'm watching a video my head will explode.....
I'm off on a bit of a tangent here, but perfection should be shared
This guy has taken the art of trolling to such an amazing level..... as I watched I found myself wondering if this could be as close as it gets to the perfect troll.
The Dark Side of the Moon: analog & digital comparison (CD, SACD, Vinyl, Tape)
The idea of clipping above 0 was wrong. Hard limiter works better. Thank you everybody.
Do not tell him about long doubles.