Author Topic: Audio Resample algorithm question  (Read 921 times)

TCmullet

  • Full Member
  • ***
  • Posts: 134
Audio Resample algorithm question
« on: December 14, 2018, 01:00:45 PM »
Hi.  I'm greatly loving 2.7.1 64-bit.  My question is difficult to describe, so let me say what I'm doing.

I have a huge bunch of 1-hr video files from which I wish to extract and process the audio.  In the MP4, it is AC3, 192kbps.  When I save to wav, it is 48000hz.  I load into one of several wav editors, and along with numerous other editing and processing tasks, I convert from 48000hz to 44100hz.  In an older editor, it's resample algorithm makes use of user-specified parameters.  You can set "quality setting", check a box to do pre or post filtering, enable dithering or not (and set dither level).  Sometimes some of those parameters are greyed out.  The newer editor does not have any of these parameters.

Though I've used Avidemux to save audio to .wav many times, I've never bothered with the resample option, though I've used most of the other options at times.  If I use the Resample (48000 to 44100) in Avidemux, this will save me time.  However, as I don't know enough about the math of resampling...  I find it hard to even word my question...  Are there choices made when programming a resample algorithm?  Perhaps it is optimized for a certain type of audio that is anticipated as the norm for the expected videos in use?  And maybe that optimization is NOT the best one to result in best retention of audio quality.  Or perhaps it's optimized for speed and sacrificing quality.  Or vice-versa.  Any maybe the algorithm is not under the control of the Avidemux programmer(s), but is rather done by an outside entity such as ffmpeg.  So my question is, how accurate is the resample algorithm?  Perhaps I will be told "don't use it for serious (hi-fidelity) stuff; use your external wav editor (and why)".  Or "there are no various algorithm parameters; all programs do exactly the same thing".

I'd prefer to shift my resampling to Avidemux, but I want to know that I'm not sacrificing quality that I might not sacrifice with a dedicated wav editor tool.  I did a test of a 1 hour file.  Save directly to 48k file:  51 sec.  Save, resampling to 44.1k along the way:  114 sec.  Slightly more than double, so obvious, something significant is happening.  But I still have my "question".  Thank you for bearing with my difficulty in describing my concern.

eumagga0x2a

  • Moderator
  • Hero Member
  • *****
  • Posts: 3188
Re: Audio Resample algorithm question
« Reply #1 on: December 14, 2018, 01:26:45 PM »
Avidemux uses for this purpose an internal libsamplerate (an older version thereof), setting it up with the medium quality preset, hardcoded.

TCmullet

  • Full Member
  • ***
  • Posts: 134
Re: Audio Resample algorithm question
« Reply #2 on: December 14, 2018, 02:12:28 PM »
Avidemux uses for this purpose an internal libsamplerate (an older version thereof), setting it up with the medium quality preset, hardcoded.
Thank you!  You've confirmed my suspicion, though am a little disappointed.  But I understand the need to keep options for a little used feature to a minimum.  It looks like I need to exert the extra effort to do my resampling in Audacity, as I see they have various options:
https://manual.audacityteam.org/man/quality_preferences.html

Oh well, it was a thought.  I'm glad I asked.  Thank you again!

Uh....  same question, but different area...   When I convert from AC3 to PCM, is the AC3 decoding algorithm something that can vary in quality depending on how it's used?   And how is Avidemux's decoder set up?  (I'm hoping to hear that "all AC3 decoding gives the exact same results no matter who does it".  But I want the truth, even if it hurts.)

eumagga0x2a

  • Moderator
  • Hero Member
  • *****
  • Posts: 3188
Re: Audio Resample algorithm question
« Reply #3 on: December 14, 2018, 02:47:57 PM »
https://github.com/erikd/libsamplerate/blob/master/src/src_sinc.c#L120

You get 121 dB SNR with the medium preset vs 144 dB SNR with the best quality one. Is 121 dB SNR not good enough?

For AC3, Avidemux uses the internal or an external a52dec (32 bit float mode) and converts the samples to 16 bit low endian when it outputs or saves audio. For E-AC3, Avidemux uses the internal FFmpeg (libavcodec).

Quote
I'm hoping to hear that "all AC3 decoding gives the exact same results no matter who does it"

At least as long you don't apply dithering, necessary for sample format conversion. But I really don't know, I assume the real-life answer is "No".

TCmullet

  • Full Member
  • ***
  • Posts: 134
Re: Audio Resample algorithm question
« Reply #4 on: December 14, 2018, 02:56:30 PM »
https://github.com/erikd/libsamplerate/blob/master/src/src_sinc.c#L120

You get 121 dB SNR with the medium preset vs 144 dB SNR with the best quality one. Is 121 dB SNR not good enough?
121 db signal to noise ratio?  I've never heard of one that high.  But I was assuming that "quality" is defined in more terms than merely SNR.

TCmullet

  • Full Member
  • ***
  • Posts: 134
Re: Audio Resample algorithm question
« Reply #5 on: December 14, 2018, 03:01:12 PM »
Quote
I'm hoping to hear that "all AC3 decoding gives the exact same results no matter who does it"
At least as long you don't apply dithering, necessary for sample format conversion. But I really don't know, I assume the real-life answer is "No".
I have found (and am waiting on confirmation now) that supposedly dithering is used only when changing the bit-depth, not the sample rate.  I'm using 16-bit all the way.

So assuming 16-bit all the way, what should we look for when hunting for the best possible AC3-to-WAV conversion?  (And can we trust that Avidemux does it?)

eumagga0x2a

  • Moderator
  • Hero Member
  • *****
  • Posts: 3188
Re: Audio Resample algorithm question
« Reply #6 on: December 14, 2018, 03:17:02 PM »
Avidemux uses 32 bit float internally for audio. It is always converted to 16 bit LE when saving (decoded) PCM audio or passing it to the sound system, so bit depth is modified. You can avoid it only by doing all audio conversion steps (why not keeping the original AC3 stream?) in a different program.

I have no idea whether the benefit justifies the effort.

TCmullet

  • Full Member
  • ***
  • Posts: 134
Re: Audio Resample algorithm question
« Reply #7 on: December 14, 2018, 03:31:25 PM »
I"m confused.  Media info shows me that the AC3 stream in my video is 16-bit.  So apparently you are saying the AviD changes to 32float in the process of outputting 16-bit PCM.  Are you saying some other AC3-to-WAV tool might not do that?  (I don't know enough about AC3 to intuitively know.)

(I can't use the original AC3 for where I need the audio to go.  Plus I have to do editing and volume modifications along the way, therefore the need to get it to a simple .wav format.)

eumagga0x2a

  • Moderator
  • Hero Member
  • *****
  • Posts: 3188
Re: Audio Resample algorithm question
« Reply #8 on: December 14, 2018, 03:42:21 PM »
Avidemux requests float from the decoder so that the bit depth of the source audio doesn't matter. Other programs may handle audio sample format differently.

TCmullet

  • Full Member
  • ***
  • Posts: 134
Re: Audio Resample algorithm question
« Reply #9 on: December 14, 2018, 03:44:45 PM »
So my question remains (please forgive if I'm not "getting it"); is this decoding of the AC3 stream by Avidemux the best possible (or reasonably best possible) quality?

eumagga0x2a

  • Moderator
  • Hero Member
  • *****
  • Posts: 3188
Re: Audio Resample algorithm question
« Reply #10 on: December 14, 2018, 03:59:27 PM »
It is good enough for practical use cases. For audiophiles, 16 bit at 44100 Hz (the audio CD quality) is a disaster. It is still good enough unless you use high end audio equipment :-)

(I had greatest difficulty to discern 24 bit / 192 kHz audio from 16 bit / 44.1 kHz on studio equipment worth many K €.)
« Last Edit: December 14, 2018, 04:03:43 PM by eumagga0x2a »

TCmullet

  • Full Member
  • ***
  • Posts: 134
Re: Audio Resample algorithm question
« Reply #11 on: December 14, 2018, 04:25:35 PM »
I AM targetting high-end playback equipment and want best possible input.  Source is 48k AC3, but have to have 44k WAV.  So I guess the question is open.

TCmullet

  • Full Member
  • ***
  • Posts: 134
Re: Audio Resample algorithm question
« Reply #12 on: December 14, 2018, 07:11:50 PM »
It's been suggested to me by someone at Audacity that I use foobar2000 for conversions.  There IS an AC3 decoder avaiable for it.

eumagga0x2a

  • Moderator
  • Hero Member
  • *****
  • Posts: 3188
Re: Audio Resample algorithm question
« Reply #13 on: December 14, 2018, 09:51:28 PM »
Please compare the results when using foobar2000 and Avidemux and report back whether you were able to hear the difference.

TCmullet

  • Full Member
  • ***
  • Posts: 134
Re: Audio Resample algorithm question
« Reply #14 on: December 15, 2018, 09:22:11 PM »
Oh, I seriously doubt ***I*** will be able to.  My ears are over 60.  However, often a better fidelity has the effect of being less tired when listening for a long time.  Sorry that I'm not able to make much personal comparison.  But I may try.  Will have to go back and re-create some music using the AviD decoder.

I had not wanted to test different tools; just wanted to be sure I had the best possible, and proceed with massive hours of processing.