Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Downsample before encoding or just use lowpass? (Read 9912 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Downsample before encoding or just use lowpass?

So I have a bunch of 48kHz files that I want to encode, and I'd like to know whether it's considered better practice to downsample to 44.1 before encoding or just use a lowpass. I lowpass all of my files at 20kHz regardless of the sample rate. I've read here before that LAME doesn't handle 48kHz that well, so I'm having trouble deciding what to do.

Re: Downsample before encoding or just use lowpass?

Reply #1
Hard to tell but since 44.1kHz is most often used, I'd expect LAME is mostly tuned in this format.
However the difference is most likely too small to matter. Certainly smaller than the difference from using a more advanced format than MP3.
A bigger difference would be if the playback device favors only 1 of these sampling rates and has issues with the other (increased battery usage, or low quality resampling) -- but it's specific to the device and you'd have to test it.
If playback device is equally OK with both, I'd not bother with resampling.
a fan of AutoEq + Meier Crossfeed

Re: Downsample before encoding or just use lowpass?

Reply #2
When I have a 48kHz file I never downsample or filter before making an MP3.  

The LAME developers have put a LOT of time & effort into optimizing it and it's unlikely that you're going to get better performance by altering the files (or by changing the LAME defaults).

Re: Downsample before encoding or just use lowpass?

Reply #3
@DVDdoug : What you say is true, and what magicgoose has said is also true. Sampling rate plays a role on codecs that could have a small impact depending on the kind of signal and the trade-outs that the codec has chosen.

Specifically, on lossy codecs that work in blocks, changing the sampling rate also affects the amount of samples used for each analysis block. It's not the same 1151 samples at 44.1Khz than at 48Khz, and MP3 uses the same amount of samples for 32Khz, 44Khz and 48Khz.
That's where the sentence "LAME is mostly tuned in this format" gets its meaning. The tunings are samplerate-dependant, even if just a bit.

Of course, there is no reason to think that 48Khz will give bad results, but my suggestion is more in line with magicgoose response.

Re: Downsample before encoding or just use lowpass?

Reply #4
Thanks for the valuable info, everyone. I've decided that downsampling before encoding is probably the best option.

Re: Downsample before encoding or just use lowpass?

Reply #5
I've decided that downsampling before encoding is probably the best option.
Sounds like a very sensible choice to me. 

The difference between resampling and not resampling may be small, whatever that means, but the time and cost of doing it properly by the book with batch processing in easily accessible free tools like fb2k is effectively nil.  Strikes me as crazy not to take advantage of that!


Re: Downsample before encoding or just use lowpass?

Reply #6
I've decided that downsampling before encoding is probably the best option.
Sounds like a very sensible choice to me. 

The difference between resampling and not resampling may be small, whatever that means, but the time and cost of doing it properly by the book with batch processing in easily accessible free tools like fb2k is effectively nil.  Strikes me as crazy not to take advantage of that!
it's not as easy as it may sound if you want to be careful with continuous track transitions (a famous example is Pink Floyd - Dark Side of the Moon).
foobar2000 can "not reset DSP between tracks" but it's only on/off for the whole batch. if you turn it on while converting more than 1 album, you may get unwanted residuals at the first tracks of an album and/or timing errors. if you turn it off, you may get timing errors across tracks in one album and audible glitches in between tracks.

it's possible to do it correctly and without too much manual labor, but not in foobar2000 yet, unfortunately.
(so yeah, another argument for not resampling)
a fan of AutoEq + Meier Crossfeed

Re: Downsample before encoding or just use lowpass?

Reply #7
it's not as easy as it may sound if you want to be careful with continuous track transitions (a famous example is Pink Floyd - Dark Side of the Moon).
foobar2000 can "not reset DSP between tracks" but it's only on/off for the whole batch. if you turn it on while converting more than 1 album, you may get unwanted residuals at the first tracks of an album and/or timing errors. if you turn it off, you may get timing errors across tracks in one album and audible glitches in between tracks.

it's possible to do it correctly and without too much manual labor, but not in foobar2000 yet, unfortunately.
(so yeah, another argument for not resampling)

Must admit I was not aware of any problems with fb2k, and actually had to resort to google to get a better grasp of the issue you described, and found an old thread on this forum with some discussion.

To try to test this out I ran fb2k SRC convert from 44.1kHz to 48 on a couple of albums with Dark side of the Moon at #2 (lossless to lossless), using both convert modes. 

Based on checking half the tracks there was no difference in the resulting track length down to the 1/1000 second level.

I then tried to listen for the artifacts you mention on transitions and really couldn't hear anything at all.

I don't want to sound obtuse (and generally use something else for 'serious' batch conversion) but I do use fb2k fairly often for quick and dirty conversion and wanted to try to get to the bottom of this.  Could the issue you mention have been fixed within SoX since the discussion in that old thread took place?


Re: Downsample before encoding or just use lowpass?

Reply #8
. . .Just to add, in case there is a difference in resampling up and down, I went back and did the same test with 96 kHz --> 44.1 files (don't have any original 48kHz to hand).

Again there was no difference in track times down to 1/1000th of a second

Re: Downsample before encoding or just use lowpass?

Reply #9
I then tried to listen for the artifacts you mention on transitions and really couldn't hear anything at all.

I don't want to sound obtuse (and generally use something else for 'serious' batch conversion) but I do use fb2k fairly often for quick and dirty conversion and wanted to try to get to the bottom of this.  Could the issue you mention have been fixed within SoX since the discussion in that old thread took place?
I didn't read the source code to say for sure (and I couldn't even if I tried, it's not open), but from what I've noticed some time ago, and read on the Web, if you reset the DSP state between tracks, it can't completely avoid this problem because it sees each track in isolation. I don't know if it actually implements it, but in theory it can try to be smarter-than-usual and instead of assuming that the undefined samples are zero, extrapolate the data before the track and after, and then these errors on track boundaries can be hard or impossible to notice in most places.
IIRC I tested this long time ago and could hear clicks but to be 100% certain I'd have to try again because foobar2000 and resampler DSP plugins could have had a lot of improvement since then.
However, if you don't reset DSP state between tracks, then this issue simply cannot happen, it's safer in this regard. (But then it may cause different issues if you convert a lot of albums at once, because it concatenates them all; also may be a performance penalty, because everything is done sequentially so unless the encoder is multi-threaded, it'll use only 1 thread for encoding, because it sees just 1 huge track.)
Quote
Again there was no difference in track times down to 1/1000th of a second
Individual track time changes won't be significant, and even the full album length. But the issue is that each time you go to next track, the relative delay of all subsequent samples will change because 0th sample of the next track is going to correspond to 0th sample in the output; and if there was no change of track here, it's almost never going to be an integer number. So it's a sudden sharp jitter, limited in length to 1/2 samples.
a fan of AutoEq + Meier Crossfeed

Re: Downsample before encoding or just use lowpass?

Reply #10
If you want to make much smaller VBR MP3 files, then downsampling is a way to achieve it. 

Fun chart!
sampletrebleused-for
2205011khzaudiobooks
2400012khzinternet radio
3200016khzdigital master tape
4410022khzCD
4800024khzmovies
Considering car audio, it seems logical to use sample rate 32000 to fit more files on the VBR MP3 data CD or chip. 
If file size is a concern, downsampling could be better than lowering the VBR MP3 quality setting.


Re: Downsample before encoding or just use lowpass?

Reply #11
Sample rate doesn't change MP3 file size.

 

Re: Downsample before encoding or just use lowpass?

Reply #12
Fun chart!
sampletrebleused-for
2205011khzaudiobooks
2400012khzinternet radio
3200016khzdigital master tape
4410022khzCD
4800024khzmovies
Digital master tape has very soon in digital era been 48 kHz, and was never 32 kHz. There have been variants at 44.1 kHz (which were recorded on analog video tape) and 56 kHz. Some DAT recorders had a longplay mode with 32 kHz/12 bit nonlinear resolution. Internet radio is mostly 44.1 kHz like CD, but using data reduction.

Re: Downsample before encoding or just use lowpass?

Reply #13
...Internet radio is mostly 44.1 kHz like CD, but using data reduction.
Sadly, that really does happen a lot.  It is like the mistake I've made for years--setting the quality level lower and lower, trying to squeeze more tracks onto data mp3 cd or 512mb mp3 player.  The results could have been subjectively more favorable if I had downsampled before making vbr mp3's.  This is easy for sample rate 32000, with today's good resampler software.

But, with sample rate 24000, there's a trick to it--then it could help to use a processor (sa stereo tool, tdr nova, etc) to maintain a similar treble signal density (to prevent audible treble-droop).  That's straightforward if the processor is already in the chain. 
You can check it out with Foobar2000 Converter:
Downmix channels to stereo
Resampler PPHS, 24000 ultra
Noise sharpening (add Foo Delta) set to 5%
MP3 variable bitrate (may need to experiment the vbr setting)

In this example, using Foo Delta cost ~+5kbits to include the treble effect within the very same file may need it.  So, this may read like nonsense, except for radio stations that were going to use their combo processor anyway.   The efficient 70-ish kbit files could make the audible donations/bandwidth-cost complaints less frequent.

This isn't too relevant for home replay of local FLAC files.  But, you could try it for MP3 Car Audio. 

P.S.
Here is a sample rate 24000, 51kbit stereo MP3 file with 0.94 megabyte file size. 
In my opinion, this quality level, or maybe slightly higher, fits internet radio and the car too. Hear and decide for yourself. 
The reduced file is presented for educational purpose.  Mind the trumpets...

Re: Downsample before encoding or just use lowpass?

Reply #14
Here is a sample rate 24000, 51kbit stereo MP3 file with 0.94 megabyte file size. 
Thanks for this sample! I admit that it sounds really good considering bitrate and the fact it is MP3! Maybe enough for car audio unless the car is not really silent, but I will prefer saying in the 192 to 256 range. SD cards are quite cheap nowadays and for music playback a slow one is good enough.
I think the recording is from 1956, so you won't lose much treble with this method. Still, it does not at all sound as bad as I expected for this bitrate!

Re: Downsample before encoding or just use lowpass?

Reply #15
44.1 kHz is MPEG-1 Layer III
24 kHz is MPEG-2(.5) Layer III
LAME uses slightly different psychoacoustics then. Not so well tuned I would say.
Still if you lowpass instead of resampling, you shall get almost the same bitrate/quality.

Re: Downsample before encoding or just use lowpass?

Reply #16
Quote
Sample rate doesn't change MP3 file size.
I’m not sure what you are communicating. Reducing the sample rate makes quite a difference in file size. As an example, I took a short track (2:40) recorded from analogue and made two copies, on at 44.1kHz, the other at 22.05kHz. Obviously the wav file size is quite different.

Encoding each to mp3 using LAME V0, the lower sample rate file size is 62% of the 44.1kHz file size.

I never use CBR encoding so I don’t know if I’m doing something wrong. The higher sample rate file encodes readily, the lower sample rate file fails. Since I have no expectation of needing CBR anytime soon, as in ever, I gave up after four variations.

Re: Downsample before encoding or just use lowpass?

Reply #17
It's not sample rate but frequency content.

44.1 kHz WAV will be big, 24 kHz one will be smaller, 44.1 kHz lowpassed at 12 kHz will be big.

44.1 VBR MP3 will be big, 24 kHz one will be smaller, but 44.1 kHz lowpassed at 12 kHz will be as small.

And CBR ones will be same size no matter the sampling rate.

Re: Downsample before encoding or just use lowpass?

Reply #18
Sample rate is well defined. It is the number of samples per second, thus it is one determinate of file size (the other is bit depth, which determines the size of a sample). Sample rate determines the frequency bandwidth, the maximum frequency that may be encoded by that sample rate.

44,1 kHz, 48 kHz, 24 kHz, 32 kHz, 96 kHz. etc. are sample rates. The frequency bandwidth of any particular sample rate is 1/2 the sample rate. The actual audio signal in any particular recording may have the maximum frequency that can be encoded by that sample rate or it may have a much lower maximum frequency (or may not contain any lower frequency content, or may be complete silence. That all depends on the audio digitized,) The sample size is independent of the frequencies contained in the sample.

How may bits might be used in a lossy compression is a different matter altogether.

Re: Downsample before encoding or just use lowpass?

Reply #19
Sample rate is well defined. It is the number of samples per second, thus it is one determinate of file size (the other is bit depth, which determines the size of a sample).
In lossy codecs a sample is something else and bit depth is ambiguous.
Sample rate determines the frequency bandwidth, the maximum frequency that may be encoded by that sample rate.
After lossy encoding there's no sample rate in that meaning. There is only frequency content which may but doesn't have to use whole frequency bandwidth. On decoding you may decode it to any sample rate (preferably not lower than twice the frequency content).

Re: Downsample before encoding or just use lowpass?

Reply #20
Thanks for this sample! I admit that it sounds really good considering bitrate and the fact it is MP3!...
For that 51kbit MP3 file, it is gxlame5.2 with settings:
-S -mj -b16 -F --highpass 40 --noreplaygain -V36 -h - %d

Since I had PPHS resample to 24000 ultra, that did at least 2 more things:
treble cutoff 12khz  (just a tiny percentage different than a good FM car radio)
mpeg 2 layer 3, which is an mp3 with time-strict compression (neither pre-echo nor warbles)

Also, at post#13, I had added a very mild treble effect to sort of 'refill' the average treble signal density, so, it would sound as if there was just as much treble volume as a CD (other option, just eq up 1 or 2 db at the top).  That's ever so easy at sample rate 24000, but could get laborious at sample rates lower than that.

I think that the track may have compressed unexpectedly small because the artists were taking turns instead of sounding simultaneously.  I had expected 70-ish kbits or higher average, for good quality stereo MP3. 

It surely isn't impossible that either a lowpass or downsample could make a similar file size mp3, but there could be some large difference in subjective quality due to codec tuning.  Well, the tuning thing may get exhausting for developers; but, you could stack the deck with some downsampling prior to encoding.   
Only after downsample, could I opinion that a lowpass might be useful; so I tried the combo (of 24000 rate with 10khz lowpass, for the attached file).

And, now, way down at 35kbits, here's a mono MP3, with 0.65 megabyte file size.
It is aimed at AM radio station capacity. Notice that fore-aft positioning cues have survived 35kbit MP3.
The reduced file is presented for educational purpose.  Mind the trumpets...

Re: Downsample before encoding or just use lowpass?

Reply #21
mpeg 2 layer 3, which is an mp3 with time-strict compression (neither pre-echo nor warbles)
Citation needed :)

Re: Downsample before encoding or just use lowpass?

Reply #22
Quote
neither pre-echo nor warbles

IIRC it's MPEG-1 Layer 2. Which, of course, is not Layer 3.

Re: Downsample before encoding or just use lowpass?

Reply #23
Citation needed :)
I searched but couldn't find that documentation again. However,
MPEG-1 Layer III (ordinary MP3) was made for storing
MPEG-2 Layer III (efficient MP3) was made for streaming

MPEG-1 Layer III (ordinary MP3) has sample rates of 32k/44k/48k and from 32kbits to 320kbits
MPEG-2 Layer III (efficient MP3) has sample rates of 16k/22k/24k and from 8kbits to 160kbits

Some interesting quality thresholds:
160kbit, 48k sample rate
128kbit, 44k sample rate
96kbit, 32k sample rate
80kbit, 24k sample rate

IIRC it's MPEG-1 Layer 2. Which, of course, is not Layer 3.
MP3 literally means MPEG Layer 3

Re: Downsample before encoding or just use lowpass?

Reply #24
MPEG-2 supports lower bitrates and mostly that's why it was said that it's suitable for streaming. I don't think there's anything that could limit pre-echo or warbles - there still are long and short blocks (unless they consist of different number of samples?).
24kHz is half of 48kHz so no wonder that one could come up with 80kbit and 160kbit thresholds respectively.

That lower limit of 8kbps might be worthwhile if we don't care about anything above 12kHz, but otherwise I'd stick with lowpassed MPEG-1 in case of LAME, as it was extensively tuned for CDDA (44.1kHz) audio.