Skip to main content

Topic: AAC encoding from dff files (Read 4968 times) previous topic - next topic

0 Members and 1 Guest are viewing this topic.
  • hlloyge
  • [*][*][*][*][*]
AAC encoding from dff files
Hello all.

I have a question; I have a tune in dff (sacd rip) format which I obtained by shady sources, and it is not relevant for this discussion.

What I want to know is, how to encode it to aac? I am using foobar2000, and I loaded dff decoder plugin, and the song plays fine. But drum at the beginning peaks far above 0 dB, I guess it goes to +6. When I encode it to AAC, I use sox resampler plugin to convert it to 44100, but then it also peaks far above, but a bit less, I guess something about +3 or +4. I think it is because it is decoded AFAIK to 32bit float, which can handle higher peaks. I don't hear distortion whatsoever in original and encoded file, at least not on my desktop speakers, I haven't done any ABX test.

The question is - is this OK? I know mp3 doesn't have bit depth in the normal way wav file has; but I don't know about AAC. Can it handle that high input for encoding and decode it properly, without artifacts, or would I have to use some sort of peak limiting before encoding, or just decode it to wav and then load it up in Audacity and normalize it's peak limits to zero?

Thank you.

  • nu774
  • [*][*][*][*][*]
  • Developer
AAC encoding from dff files
Reply #1
In theory it is OK (same as MP3). However, it might depend on implementations.
At least encoder has to be able to eat float PCM. Same for decoder.

I tried this before with fb2k + qaac, and it was fine. It had peak of 1.6 or so, and peak was preserved.
Of course you have to set the maximum bitdepth to 32 on CLI encoder setting of fb2k.
If you want to check the decoded result, just convert to WAV with fb2k (also specify 32bit here).
In my case, I quickly looked at the decoded result with some Python scripting like the following:
Code: [Select]
import struct
wavdata = open('foo.wav', 'rb').read()
wavdata = wavdata[44:] # chop off the header. might be different on your case
pcm = struct.unpack('f' * (len(wavdata)/4), wavdata) # parse as float32 sequence
pcm = map(abs, pcm) # convert to abs values
print 'peak: %g, avg: %g' % (max(pcm), sum(pcm)/len(pcm))

If you want to see just the peak of it, probably scanning with replaygain is enough.
  • Last Edit: 31 January, 2012, 08:09:37 AM by nu774

  • saratoga
  • [*][*][*][*][*]
AAC encoding from dff files
Reply #2
Can foobar replaygain scan the file?  If so, the easiest/safest solution would be to replaygain scan it, then check the "prevent clipping" option when you convert it to AAC.  This way it'll get scaled to 0dB before conversion.
  • Last Edit: 31 January, 2012, 04:33:33 PM by db1989

  • C.R.Helmrich
  • [*][*][*][*][*]
  • Developer
AAC encoding from dff files
Reply #3
I agree with nu774 and saratoga. Given an encoder supporting floating-point input, a few sporadic peaks slightly above 0 dBFS in the input are OK, I guess. But remember that not every decoder can output floating-point PCM but rather truncates (and clips) to 16- or 24-bit before you can apply any level adjustments, and given such decoders you will risk audible clipping with above-0-dBFS encodings.

Chris
If I don't reply to your reply, it means I agree with you.

  • hlloyge
  • [*][*][*][*][*]
AAC encoding from dff files
Reply #4
Foobar can scan the file, but can't save the results into tags, because, AFAIK, dff has no tagging support. I've thought about that, it would be the best solution. And I don't know how to apply RG values while encoding - I could lower the output for file without RG info while playing back, I know to do that.
And although it plays fine in foobar2000 (AFAIK, foobar internally handles 32bit pcm so it will not clip), I will test out today afternoon how it sounds in iPod Touch.

Alternatively, I can transcode it to some lossless format which can handle 32bit wave input, tag it, and encode to aac.
  • Last Edit: 01 February, 2012, 05:05:02 AM by hlloyge

  • nu774
  • [*][*][*][*][*]
  • Developer
AAC encoding from dff files
Reply #5
Alternatively, as long as the encoder can take it and encode it properly, you can adjust global gain value of resulting AAC afterwards with aacgain (LC-AAC only, though).


  • benski
  • [*][*][*][*][*]
  • Developer
AAC encoding from dff files
Reply #6
One thing I've always been curious about - and perhaps Chris could answer - does the PNS tool (Perceptual Noise Substitution) create any non-determinism in decoding?  Or is the random number generator seeded from the bitstream somehow?  I'm asking mainly from the point of view of peak value detection in ReplayGain (and compensation during playback) .
  • Last Edit: 01 February, 2012, 07:29:23 PM by benski

  • saratoga
  • [*][*][*][*][*]
AAC encoding from dff files
Reply #7
One thing I've always been curious about - and perhaps Chris could answer - does the PNS tool (Perceptual Noise Substitution) create any non-determinism in decoding?  Or is the random number generator seeded from the bitstream somehow?  I'm asking mainly from the point of view of peak value detection in ReplayGain (and compensation during playback) .


I don't know what the spec says, but libfaad's pns_decode uses a random number generator which is always initialized to the same value. 

WMA Standard does something similar.

  • benski
  • [*][*][*][*][*]
  • Developer
AAC encoding from dff files
Reply #8
One thing I've always been curious about - and perhaps Chris could answer - does the PNS tool (Perceptual Noise Substitution) create any non-determinism in decoding?  Or is the random number generator seeded from the bitstream somehow?  I'm asking mainly from the point of view of peak value detection in ReplayGain (and compensation during playback) .


I don't know what the spec says, but libfaad's pns_decode uses a random number generator which is always initialized to the same value. 

WMA Standard does something similar.


So playback from the start of the file would be OK, but "random" seeking could potential cause peak values to differ?

  • saratoga
  • [*][*][*][*][*]
AAC encoding from dff files
Reply #9
So playback from the start of the file would be OK, but "random" seeking could potential cause peak values to differ?


Ha, I suppose it would.
  • Last Edit: 01 February, 2012, 08:35:34 PM by saratoga

  • hlloyge
  • [*][*][*][*][*]
AAC encoding from dff files
Reply #10
iPod Touch 2nd gen plays the file fine; I can't hear clipping artifacts, so I guess decoder handles it quite well... but it's only mere 3dB over.

Track gain : -6.61 dB
Track peak : 2.396162
Album gain : -6.24 dB
Album peak : 2.396162

It sounds quite loud, though.

  • C.R.Helmrich
  • [*][*][*][*][*]
  • Developer
AAC encoding from dff files
Reply #11
... does the PNS tool (Perceptual Noise Substitution) create any non-determinism in decoding?  Or is the random number generator seeded from the bitstream somehow?

The standard doesn't say anything about the random number generator, neither what kind of generator, nor anything about seeding that generator. So yes, peak values might be a bit non-deterministic. But I'll ask our conformance-bit-stream experts how PNS is handled there. Update: yes, a colleague told me that, as alexander writes below, the PNS conformance tool compares energies, not samples.

Chris
  • Last Edit: 02 February, 2012, 06:33:15 AM by C.R.Helmrich
If I don't reply to your reply, it means I agree with you.

  • .alexander.
  • [*][*]
AAC encoding from dff files
Reply #12
Haven't read the whole thread, just want to say that reference software contains special tool to test PNS conformance (conf_pns) that check energy in PNS subbands.