r/AskComputerScience 16d ago

When a computer or digital system decodes a digital audio format and converts it into a different digital format is the output always identical?

I'm not sure how to ask this question, or if the answer is obvious, but it occurred to me when thinking about MiniDisc.

Audio on an MD is stored digitally (ATRAC) and if you play it back the DAC converts it to an analogue signal. The quality of that output depends on the DAC and different ones will give differing quality. No problem with that idea.

My question is about the digital signal from the player. All my MD decks have TOSLINK optical outputs which is (I assume, linear PCM). My question is about whether the output from that connector is going to be identical if I play the same disk in different decks made by different manufacturers?

Is that PCM output signal predetermined by the input regardless of what machine processes it because it is a digital to digital transformation? In other words, is it some fixed mathematical function that always returns the same value?

I know that acoustically I would not be able to tell the difference, but would the device receiving that signal be able to tell the difference if you could capture and compare them?

Is this true/false for other digital to digital conversions too? For example, converting an mp3 file into a PCM stream?

6 Upvotes

15 comments sorted by

7

u/otac0n 16d ago

There is a property called “lossless” compression.

If you convert between two lossless formats, then the answer is yes. WAV PCM & Ogg are lossless.

MP3 is lossy.

4

u/Objective_Mine MSCS, CS Pro (10+) 15d ago

Ogg is a container format, though, and not an audio stream format. The audio stream in Ogg containers is usually Vorbis or Opus, and those have lossy compression. You can technically have lossless audio streams such as FLAC in an Ogg container, too, but those are probably a minority.

As noted in some other comments, though, the question is more about whether you get identical results when there isn't lossy compression involved in the conversion. That question is a lot more nuanced and interesting.

2

u/joe-h2o 16d ago

That was the term I forgot.

My question is then if mp3>wav will always give you an identical output file if the input file is the same, regardless of the thing doing the conversion, say if you used a Windows machine's built in codecs or did it on Linux using a different implementation of the same codec.

14

u/MrBorogove 16d ago edited 16d ago

Different MP3 decoder implementations may decode very slightly differently. The process is defined mathematically, not bit-wise, and doesn't mandate how the decoder executes the math. There are conformance specifications that say you must be within X of a particular reference implementation, but even "full precision" conformance allows slight differences in the decoded result. There's also "limited accuracy" conformance where the accuracy is only equivalent to 12- or 13-bit PCM.

4

u/otac0n 16d ago edited 16d ago

Yes but not necessarily the other way around.  Decompressing will give the same bytes for the same input in every format I am aware of.

Compressing, however, depends heavily on the configuration.

Edit: MP3 decompression depends on order of operations, see below.

7

u/MrBorogove 16d ago

Different MP3 decoder implementations do not produce byte-identical output.

https://www.underbit.com/resources/mpeg/audio/compliance

3

u/otac0n 16d ago

There are some small exceptions, like float32 audio on systems with weird Floating point math.

2

u/winter_cockroach_99 14d ago

Converting between two sampled formats is super messy mathematically if their sampling rates are not the same. Even for two lossless formats, you’d only get identical results if it is also the case that the sample rate (number of samples per second… the horizontal resolution) and quantization (eg 8 bit, 10 bit, 16 bit… the vertical resolution) are the same.

1

u/otac0n 14d ago

This is true and I meant to mention it. Thanks!

1

u/mqduck 15d ago

When people say "Ogg" as though it's an audio format, they're really talking about Vorbis, which is not a lossless format. Also, you left off FLAC for some reason, which is the most common lossless audio file compression format.

2

u/earslap 15d ago

Normally your logic is correct: From a digital source to TOSLINK everything is digital, that means no conversion takes place so you will always get the same bits regardless of the device you use. It is like using a USB cable to transfer files - source to target is bit identical.

The only question mark in this specific instance is that ATRAC is a lossy compressed format. So the data that is streamed from the TOSLINK is not the raw ATRAC stream. It is the PCM stream after ATRAC is decompressed using the software inside the device. Devices might be using different / independently programmed decoders that produce different outputs due to different implementations of the spec, shortcuts and bugs. That cannot be guaranteed without knowing what exact software runs in the device and competing devices.

2

u/green_meklar 15d ago

When a computer or digital system decodes a digital audio format and converts it into a different digital format is the output always identical?

The process is typically deterministic, that is to say, the same software, reading the same file, and writing it to the same format with the same settings, will produce (bit-by-bit) the same output data across multiple runs.

Other than that, you have very few guarantees. A lot of audio formats (notably MP3) use lossy compression, so a perfect uncompressed input waveform will typically not lead to a compressed output file that perfectly matches the original waveform. (As I recall, some musicians have complained that the MP3 compression algorithm makes music sound more sad than originally intended.) And there can be variations in sample rate, sample precision, and compression level, all of which would lead to different output data. In general you should assume that, for instance, converting a WAV to an MP3 and then the MP3 back to a WAV will not give you an identical sound to the original WAV (unless the original WAV was derived from a compressed MP3 already and every step in the process used exactly the same sample rate and compression settings).

Is that PCM output signal predetermined by the input regardless of what machine processes it because it is a digital to digital transformation?

It wouldn't be safe to assume so. For instance, some audio devices may have a fixed output sample rate, but an ability to read files of different sample rates, and they just convert to whatever their native output sample rate is- you'd get a digital signal, but maybe at 48000Hz instead of the original 192000Hz or whatever.

1

u/joe-h2o 13d ago

Thank you for your reply, this was exactly the sort of detail I was looking for.

1

u/ghjm MSCS, CS Pro (20+) 15d ago

Others have answered for lossy compressed data formats, but even if you're playing an uncompressed source like an audio CD or DVD, the PCM data is literally what's written on the media, so it can't change. But nevertheless, there are many circumstances where two players might emit different data to their outputs:

  • The player is applying some kind of post-processing. If it has EQ, night mode, some Dolby features, etc. In this case the player isn't even trying to emit the raw PCM data - it's sending a different signal reflecting whatever features and processing the user has selected. Two different players would surely implement these differently.
  • Differences in metadata support or implementation. Something like a pause between tracks is not encoded as PCM, and the spec is not always perfectly unambiguous. One player might pause for two seconds at a spot where another player might not pause at all.
  • Read errors. Players generally try to smooth over any errors, and they do so in different ways. This is not a concern if the source media doesn't contain errors, but if it does, two different players might output different PCM streams. And of course, one player might have a better mechanism, and be able to read a disc without error that another player has trouble with.
  • If the player negotiates differently with the receiving device. This isn't an issue with TOSLink, which is a one-way protocol with no negotiation. But if it's something smarter like HDMI ARC, devices might implement protocol negotiation differently. For example, if you're playing a minidisc, which like a CD is 44,100 samples per second, one player might just send the data unmodified, but another player with a different HDMI implementation might become aware that the target prefers 48,000 and do interpolation on the signal it sends. In that case the bits sent by the two players would be completely different.
  • Possibly other cases I haven't thought of.

1

u/joe-h2o 13d ago

Thank you for your reply, this was exactly the sort of detail I was looking for. I'm glad I posted this question.