Importing ALAC and AAC: Shooting yourself in the foot?

Help for Audacity 2.x.x on Mac OS X.

ImageThis forum is for Audacity 2.x.x on Mac OS X 10.4 and later.
Please state which version of macOS you are using,
and the exact three-section version of Audacity from "Audacity menu > About Audacity".


Audacity 1.2.x and 1.3.x are obsolete and no longer supported. If you still have those versions, please upgrade at https://www.audacityteam.org/download/.
The old forums for those versions are now closed, but you can still read the archives of the 1.2.x and 1.3.x forums.

Importing ALAC and AAC: Shooting yourself in the foot?

Permanent link to this post Posted by DJDemon » Tue Dec 26, 2017 3:21 pm

OS: macOS 10.12.6 or 10.8.5 (happens on both systems)
Audacity: Version 2.2.1

Default Sample Format is set to "32-bit float", in the preferences. This is usually reflected in the the track control panel, too. However, after importing a (16-bit) Apple Losssles or AAC file, Audacity will indicate "16-bit PCM" here. Both file types have the extension ".m4a" under macOS.

When I convert the ALAC or AAC file to any other 16 bit format such as WAV, FLAC or AIFF before feeding it to Audacity, Audacity will use 32-bit float, as expected.

I have compared the sizes of the resulting project and data files in both cases: When opening an ALAC file and saving it as a project, the resulting amount of data is approximately only 50%, compared with the case of reading the same (!) 16-bit audio data from an AIFF file and saving it as a project. So there is not just a wrong information shown in the track control panel; the problem seems to be for real.

(Still worse: When opening such a saved 16-bit PCM project again, Audacity will misleadingly show "32-bit float" in the track control panel.)

On macOS – in contrast to Linux and Windows – ALAC and AAC files are decoded by means of the operating system; the FFmpeg library is not required. At least, that's how I understand it. Could it be that the bug is rooted here and is macOS-specific? Yet there is – of course – no reason to degrade the computational accuracy to 16-bit fixed point just because of this.
DJDemon
 
Posts: 23
Joined: Fri Jul 17, 2015 12:14 pm
Operating System: OS X 10.11 El Capitan or later (macOS)

Re: Importing ALAC and AAC: Shooting yourself in the foot?

Permanent link to this post Posted by steve » Tue Dec 26, 2017 6:24 pm

I agree this is confusing, but it is working "as designed".
Audacity uses a number of different third party "importers" for importing audio. If Audacity is set to use 32-bit float by default and the importer supports 32-bit float, then you will get 32-bit float. If the importer send the audio data in a lower format, then Audacity makes no attempt to convert it to 32-bit unless you explicitly (manually) change the track format to 32-bit float.

To manually change the track sample format (after importing), see: http://manual.audacityteam.org/man/audi ... tml#format
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Site Admin
 
Posts: 45672
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Importing ALAC and AAC: Shooting yourself in the foot?

Permanent link to this post Posted by DJDemon » Tue Dec 26, 2017 6:36 pm

steve wrote:I agree this is confusing, but it is working "as designed".


"… as designed"? This is utterly stupid design! :evil:

When I select a default format of "32-bit float", I expect Audacity to respect this, regardless of how it is achieved. I don't care whether the conversion from 16-bit fixed point to 32-bit float is done by the "importer" or by Audacity itself.

Or, with other words: What are "preferences" good for, as long as they are not respected?
DJDemon
 
Posts: 23
Joined: Fri Jul 17, 2015 12:14 pm
Operating System: OS X 10.11 El Capitan or later (macOS)

Re: Importing ALAC and AAC: Shooting yourself in the foot?

Permanent link to this post Posted by steve » Tue Dec 26, 2017 7:08 pm

DJDemon wrote:"… as designed"? This is utterly stupid design! :evil:

As I have said myself many times. However, the 'best' behavior (for sound quality) is not quite as simple as you are suggesting.

Audacity works internally in 32-bit format, so if any processing is applied, then the audio is processed as 32-bit float, and the resulting samples will (mostly) be values that cannot be expressed exactly in 16-bit. Thus, if the audio is subsequently exported as 16-bit, the sample values need to be rounded in some way to 16-bit values. Mathematical rounding does not work well with audio because it causes "quantization noise" (which can sound like an unpleasant "rasping" sound when the audio level is very low), so audio applications use a special kind of rounding called "dither".

In an ideal world, if the audio file is uncompressed 16-bit format and only simple cut/paste type edits occur, and the export format is uncompressed 16-bit format, then "perfect" quality would be achieved by not converting the format. If there is no processing, then 16-bit sample values remain as exact 16-bit values, so dither is not required (should not be applied).

Being able to correctly handle both 16-bit integer and 32-bit float data goes pretty deep into the Audacity code - it's difficult and risky work, and very few users will ever even notice the difference. For those that do care, we just have to ensure that our tracks are always 32-bit float unless we have a specific need to do otherwise.

Of course, if you know any really skilled C++ developers that are willing to take on a difficult and risky job with no pay and little reward, then please do send them our way ;)
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Site Admin
 
Posts: 45672
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Importing ALAC and AAC: Shooting yourself in the foot?

Permanent link to this post Posted by DJDemon » Tue Dec 26, 2017 7:57 pm

In the vast majority of tasks to be performed with Audacity 32-bit float is the best choice, and that's why one can chose between integer and floating point formats, with 32-bit float being the default setting. That's perfectly ok! The section of the manual decscribing the Preferences menu says:
Default Sample Format: Offers a choice of three sample formats or bit-depths. This affects both imported and newly recorded material [,…]

There is absolutely no indication that certain file types (ALAC, AAC) under certain circumstances (macOS) do not fall under this rule when imported.

steve wrote:In an ideal world, if the audio file is uncompressed 16-bit format and only simple cut/paste type edits occur, and the export format is uncompressed 16-bit format, then "perfect" quality would be achieved by not converting the format.

This is entirely correct, but I did not suggest something like "auto-conversion to floating point as soon as the first multiplication or division occurs " – even though that would be pretty. I just suggest a predictable behavior, which follows the description in the manual.
DJDemon
 
Posts: 23
Joined: Fri Jul 17, 2015 12:14 pm
Operating System: OS X 10.11 El Capitan or later (macOS)

Re: Importing ALAC and AAC: Shooting yourself in the foot?

Permanent link to this post Posted by steve » Tue Dec 26, 2017 8:13 pm

DJDemon wrote:There is absolutely no indication that certain file types (ALAC, AAC) under certain circumstances (macOS) do not fall under this rule when imported.

That can be corrected.

There is a highlighted paragraph that describes the issue as it relates to Ogg files (which I believe is the same on all platforms), but I guess the person that wrote that did not have a Mac (and I'm mostly on Linux).

Could you post a short ALAC file that demonstrates the issue (just a 4 or 5 second "Chirp" will be fine) so that I can check to see what happens on each platform, then at least we can have the documentation accurate.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Site Admin
 
Posts: 45672
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Importing ALAC and AAC: Shooting yourself in the foot?

Permanent link to this post Posted by DJDemon » Tue Dec 26, 2017 8:29 pm

steve wrote:There is a highlighted paragraph that describes the issue as it relates to Ogg files (which I believe is the same on all platforms), but I guess the person that wrote that did not have a Mac (and I'm mostly on Linux).

No, that's the wrong way. ALAC and AAC should be converted automatically to 32-bit float, if this is the default format. There is no reason to treat ALAC in a different way than, e.g., FLAC, or to treat AAC in a different way than MP3, just because the conversion needs to be performed in a different module of the software.

steve wrote:Could you post a short ALAC file that demonstrates the issue (just a 4 or 5 second "Chirp" will be fine) so that I can check to see what happens on each platform, then at least we can have the documentation accurate.
Will do so, in a few minutes!
DJDemon
 
Posts: 23
Joined: Fri Jul 17, 2015 12:14 pm
Operating System: OS X 10.11 El Capitan or later (macOS)

Re: Importing ALAC and AAC: Shooting yourself in the foot?

Permanent link to this post Posted by DJDemon » Tue Dec 26, 2017 8:50 pm

Test file (the jingle of our radio station), in AIFF format:
http://www.cq131a.de/x/0-Jingle-0.aiff

Screenshot from Audacity after importing this AIFF file:
http://www.cq131a.de/x/AIFF.png

Same audio as Apple Lossless:
http://www.cq131a.de/x/0-Jingle-0.m4a

Screenshot from Audacity after importing this .m4a file:
http://www.cq131a.de/x/ALAC.png

PS:

Same audio as FLAC:
http://www.cq131a.de/x/0-Jingle-0.flac

Screenshot from Audacity after importing this .flac file:
http://www.cq131a.de/x/FLAC.png
DJDemon
 
Posts: 23
Joined: Fri Jul 17, 2015 12:14 pm
Operating System: OS X 10.11 El Capitan or later (macOS)

Re: Importing ALAC and AAC: Shooting yourself in the foot?

Permanent link to this post Posted by steve » Tue Dec 26, 2017 10:20 pm

Thanks, got it.

One more thing if you could:
In a new Audacity project, import an ALAC file, then look in "Help > Diagnostics > Show Log".
Does it say:
Code: Select all
Opening with libav
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Site Admin
 
Posts: 45672
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Importing ALAC and AAC: Shooting yourself in the foot?

Permanent link to this post Posted by DJDemon » Tue Dec 26, 2017 10:50 pm

The last 4 lines of the log file, on a machine with macOS 10.8 and FFmpeg library installed:

23:42:46: File name is /Volumes/was/tmp/test/0-Jingle-0.m4a
23:42:46: Mime type is *
23:42:46: Opening with libav
23:42:46: Open(/Volumes/was/tmp/test/0-Jingle-0.m4a) succeeded

The last 5 lines of the log file, on a machine with macOS 10.12 and FFmpeg library NOT installed:

23:46:47: File name is /Users/was/tmp/test/0-Jingle-0.m4a
23:46:47: Mime type is *
23:46:47: Opening with libav
23:46:47: Opening with quicktime
23:46:47: Open(/Users/was/tmp/test/0-Jingle-0.m4a) succeeded

NB: Same result in both cases.
DJDemon
 
Posts: 23
Joined: Fri Jul 17, 2015 12:14 pm
Operating System: OS X 10.11 El Capitan or later (macOS)

Next

Return to Mac OS X



Who is online

Users browsing this forum: No registered users and 2 guests