A bit of AAC news

July 20th, 2008

I’ve not abandoned work on AAC encoder completely.
For example, I think now my psy model calculates and handles bitrate better. Now the only goals I set to myself are:

  • Make encoder provide psy model lookahead samples for block switching
  • Finetune psy model, or more specifically:
    • block switching decision
    • finish M/S case handling (for now it does not update all psy model information and result in artifacts on several test samples)
    • adjust scalefactors to reduce quantisation distortion
    • some other tricks from 3GPP TS26.403?

After that there are several ways to go: improve quality until it beats other encoders (at least libfaac), implement SBR/PS encoding (the latter is easier to do), introduce multichannel coding.

I suspect that at least one person will suggest to do it all.

Turtles All the Way

July 20th, 2008

Just in time I though I’ve fully understood RV4 loop filter. It uses both coded block pattern and some other pattern. I thought it was CBP from the previous frame, but it turned out to be some special deblocking pattern calculated for each block in interframes after decoding that block. That calculation is easy – it just selects a set of subblocks to check, compare some values and if the difference is less than 3 then set a bit in deblock pattern. Now the only thing left is to find out is where those values come from.

Again and again on RV40 loop filter

July 15th, 2008

I’ve mostly understood how RV40 loop filter works.

Just not to forget main principles I document it here (this blog was created for such things after all).

  • CBPs from left, top and bottom neighbours are used in filter, and if frame type is interframe then CBPs for those blocks in that reference frame are used as well.
  • There are two actual filter types – weak and strong, both are described in H.264 drafts.
  • Edges in subblock are filtered in the next order: bottom, left, top. Top edge is filtered only for the subblocks in the first row.
  • There are many filter parameters passed: dither argument (for strong filter, depends on subblock position), two thresholds taken from ClipTable, threshold taken from alpha_tab, threshold taken from beta_tab and the same value multiplied by 3 or 4 (four is for Y plane filters in not extremely big pictures).
  • The problem was to determine what ClipTable parameters should be used, as it has an additional dimension, more on it below.

There are seven values taken from ClipTable total:

  1. ClipTable[0][current block quantiser]
  2. ClipTable[2][current block quantiser]
  3. ClipTable[2][global quantiser set in header]
  4. ClipTable[x][current block quantiser]
  5. ClipTable[x][top neighbour quantiser]
  6. ClipTable[x][left neighbour quantiser]
  7. ClipTable[x][bottom neighbour quantiser]

That x value is 2 for the intra block types and P-frame interblock with DCs coded separately, 1 otherwise.
As I understand, ClipTable[x][current block quantiser] is used by default and other valuer are used for corner cases (subblock on the side of the edge is uncoded, belongs to another macroblock or does not exist at all).

I should look at H.264 loop filter description (thanks to all who sent me the pointers to the book by Iain Richardson), it seems suspiciously similar.

Troubles with Psy Model

July 14th, 2008

I’m battling with psychoacoustic model. 3GPP TS26.403 seemed clear at the start but then problems have begun.

The main problem is perceptual entropy estimation. Since MDCT coefficients differ by magnitude in FFmpeg and 3GPP, perceptual entropy estimated by formulae from 3GPP differs much from actual number of bits to code. Also 3GPP encoder always makes scalefactor lie in range 104…164, beats me why (and its center does not correspond to scale = 1.0 either).

I have to investigate further before continuing work on psy model. I also hope to see AAC decoder in FFmpeg SVN soon and push my work on encoder there as well.

Again on RV40 loop filter

July 10th, 2008

While work on AAC encoder is slowly progressing (now it’s mostly psychoacoustics left to do and maybe HE-AAC if somebody will convince me), I’m looking at side tasks to make my life a bit more colourful.
For now those tasks are writing SSE2 optimization for Monkey’s Audio decoder (and that is the first piece of SIMD assembly I’ve ever written) and working on RV40 loop filter.
To give people false hope, it’s more understandable by now. Only one function argument is not obvious. And Dark Shikari, you were wrong – RV40 is 99,5% alike with H264 draft (not 99% you said), as loop filter is suspiciously similar to H264 one.

AAC: Nachrichten pro Woche

July 5th, 2008

Here is this week portion of AAC-related news:

  • I was working on psychoacoustic model and fixes for it. Now encoder should always produce correct files (i.e. decodable without bitstream errors). Sound quality may be low though.
  • There was a bug in MDCT calculation which resulted in wrong spectrum.
  • My test device for AAC has broken 🙁 Where I can find a decent pair of headphones that won’t break that easily? Especially in this country.

And just in case my mentor’s reading this, here are my plans:

  • Improve and finish 3GPP TS26.403-based psychoacoustic model.
  • Implement block switching.
  • Add sine windows.
  • Sync my encoder with current AAC decoder code (maybe it will be committed by then?)

AAC: weekly report

July 1st, 2008

I’m working on creating psychoacoustic model from recommendations presented in 3GPP TS26.403. Implementation is very rough but at least it can produce the files with desired bitrate (not quite that bitrate but ~2kbps around it).

Now the tasks are to eliminate noise from encoded material and add block switching. Maybe window switching as well.
Oh, and commit that all to FFmpeg SVN.

AAC: going to psychoacoustics

June 24th, 2008

Looks like Gabriel Bouvigne of mp3-tech.org (how many information I got from there!) and Lame fame took interest in AAC encoder. For now I’m following his advise and trying to implement psychoacoustic model after 3GPP TS 26.403 document. It should be simple yet effective enough.

In the other news: AAC decoder mutates to become fit for FFmpeg SVN inclusion. I hope that will happen soon. Keep going, Robert, and keep reviewing, Michael!

Update on AAC progress

June 16th, 2008

If you are interested in what happens with my encoder, here’s a piece of report.

Simple encoding works. That means you can encode files with it now and they can be played back and you’ll be able to recognize the sound. Also I’ve separated psychoacoustic model and encoder itself, so it calls model to ask what windowing to use and what scaling/coefficients to encode.
Can I say this concludes the task for this summer of code? Technically yes but there are few points I ought to finish.

Encoder side:

  • MDCT for the cases different from simple 1024-point window (8 short windows sequence and two transition windows)
  • correct bitstream writing for 8SS case
  • probably multichannel encoding (it’s useless until we have defined multichannel audio API though)

Psychoacoustic model(s) side:

  • good psychoacoustic model 🙂
  • quantizer which allows rate control
  • something else?

I can add some models after the work is complete too and probably tune it for my ears and music I like to listen to. Reading papers I got on psychoacoustic models should help.

Back to work then.

Some progress in AAC encoder

June 9th, 2008

OK, now I have simple and not very correct AAC encoder. Because of quantization step missing (spectral coefficients should be downscaled by cube root from them) resulting AAC becomes louder and FAAD complain on quantisation value being too large. FFmpeg future AAC decoder just silently clips it. In any case, it produces sound close to original.

Since no psychoacoustics is employed for now, bitrate is too high (~400kbps per channel, no joint stereo savings too).

So, the plan is to:

  • Fix and optimize bitstream writing (yes, bitstream packing is far from optimal too)
  • Psychoacoustic model (I hope it will be easier than multichannel audio API in FFmpeg)
  • Bitrate control

Back to work…