summaryrefslogtreecommitdiff
path: root/libavcodec/aacenc.c
Commit message (Collapse)AuthorAgeFilesLines
* avcodec/aacenc: Check both channels for finitenessMichael Niedermayer2016-01-281-2/+10
| | | | | | | | | | | | | Fixes null pointer dereference Fixes: 10412fc52ecc6eab40ed67f82ca7b372/signal_sigsegv_2618c99_2129_f808373959e46afb165593332799ffbc.aif Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind Signed-off-by: Michael Niedermayer <michael@niedermayer.cc> (cherry picked from commit 057549a9ccc9fd32df71678e6abe69e10668186a) Conflicts: libavcodec/aacenc.c
* aacenc: update max_sfb when num_swb changesAndreas Cadhalpun2015-12-171-0/+1
| | | | | | | | | This fixes out-of-bounds reads in avoid_clipping. Reviewed-by: Rostislav Pehlivanov <atomnuker@gmail.com> Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com> (cherry picked from commit 5b0da6999fdd0135b6f269d3691d74720f773c85) Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
* aacenc: reorder coding toolsRostislav Pehlivanov2015-09-021-63/+88
| | | | | | | | | | | | | | | | | | | | | | | | | This commit reorders the coding tools such that they're doing what the decoder does in reverse order. The very first thing the decoder does is to decode M/S stereo if that's signalled, then prediction, IS, and finally TNS and PNS in another function. adjust_frame_information()'s application of IS and M/S was taken out into two separate functions since prediction doesn't expect to get the raw coefficients but rathe the coefficients at that part of the encoding process. The results show a much better PSNR when any combination of Intensity Stereo, Mid/Side stereo and Prediction is used, which is a sign of an increased encoder efficiency as well as the fact that the decoder gets what it expects. Otherwise, with only IS, PNS or prediction there are neither regressions nor improvements except in the case of IS, which now by itself (or with PNS) is less prone to artifacts. Enabling M/S (using stereo_mode) as well will also reduce stereo artifacts induced by IS, so in the very near future M/S may be enabled by default. Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* aacenc: disable bandtype modifying extensions when coder != twoloopRostislav Pehlivanov2015-09-011-0/+5
| | | | | | | | | If the selected coder isn't twoloop, this commit temporarily disables IS and PNS. The problem is in the encode_window_bands_info() being confused and setting invalid band_types for non-marked (normal) bands. Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* aacenc: Enable Intensity Stereo by defaultRostislav Pehlivanov2015-09-011-1/+1
| | | | | | | | | | | Since the changes made a few week ago (which were done more than a month ago) the quality and stability of intensity stereo has been notably good. There were some requests and wishes to have in on by default and therefore it has been enabled. Should any regressions arise changes will be made to preferably keep it operating rather than just disabling it by default again. Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* aacenc: Enable Perceptual Noise Substitution by defaultRostislav Pehlivanov2015-09-011-1/+1
| | | | | | | | It has been in the current encoder in its current implementation for quite some time now, so enable it by default. Will increase quality at all bitrates, especially at low ones. Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* aacenc: reorder resetting of cpe->common_windowRostislav Pehlivanov2015-09-011-1/+1
| | | | | | | Purely a cosmetic change, most of the zeroing of encoder resources should happen at the top of the main loop. Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* aacenc_tns: rework coefficient quantization and filter applicationRostislav Pehlivanov2015-09-011-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit reworks the TNS implementation to a hybrid between what the specifications say, what the decoder does and what's the best thing to do. The filter application function was copied from the decoder and modified such that it applies the inverse AR filter to the coefficients. The LPC coefficients themselves are fed into the same quantization expression that the specifications say should be used however further processing is not done, instead they're converted to the form that the decoder expects them to be in and are sent off to the compute_lpc_coeffs function exactly the way the decoder does. This function does all conversions and will return the exact coefficients that the decoder will generate, which are then applied to the coefficients. Having the exact same coefficients on both the encoder and decoder is a must since otherwise the entire sfb's over which the filter is applied will be attenuated. Despite this major rework, TNS might not work fine on some audio types at very low bitrates (e.g. sub 90kbps) as it can attenuate some coefficients too much. Users are advised to experiment with TNS at higher bitrates if they wish to use this tool or simply wait for the implementation to be improved. Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* aacenc: allocate a larger buffer for the TNS LPC contextRostislav Pehlivanov2015-09-011-1/+1
| | | | | | | | Turns out autocorrelating more than 750 coefficients at once will cause a segfault, despite there being enough space to hold an entire frame of samples into the buffer. Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* aacenc: populate tns_max_bandsRostislav Pehlivanov2015-09-011-0/+3
| | | | | | Needed for the following commits. Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* aacenc: initialize LPC context with MAX_LPC_ORDERRostislav Pehlivanov2015-08-291-1/+1
| | | | | | | | | The order should never go above TNS_MAX_ORDER (and thus cause the context to be reinitialized) but this is just in case. Also fix a comparison, since the coefficients are zero-indexed. Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* aacenc: remove TNS from the todo listRostislav Pehlivanov2015-08-291-1/+0
| | | | | | | | | | Pulses are already on the way so expect to see the list gone in the close future. TNS is already of sufficiently high quality to be enabled by default (but isn't yet, so you too can help by testing!). Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* aacenc_tns: rework the way coefficients are calculatedRostislav Pehlivanov2015-08-291-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit abandons the way the specifications state to quantize the coefficients, makes use of the new LPC float functions and is much better. The original way of converting non-normalized float samples to int32_t which out LPC system expects was wrong and it was wrong to assume the coefficients that are generated are also valid. It was essentially a full garbage-in, garbage-out system and it definitely shows when looking at spectrals and listening. The high frequencies were very overattenuated. The new LPC function performs the analysis directly. The specifications state to quantize the coefficients into four bit index values using an asin() function which of course had to have ugly ternary operators because the function turns negative if the coefficients are negative which when encoding causes invalid bitstream to get generated. This deviates from this by using the direct TNS tables, which are fairly small since you only have 4 bits at most for index values. The LPC values are directly quantized against the tables and are then used to perform filtering after the requantization, which simply fetches the array values. The end result is that TNS works much better now and doesn't attenuate anything but the actual signal, e.g. TNS removes quantization errors and does it's job correctly now. It might be enabled by default soon since it doesn't hurt and helps reduce nastyness at low bitrates. Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* aacenc_pred: rework the way prediction is doneRostislav Pehlivanov2015-08-291-22/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | This commit completely alters the algorithm of prediction. The original commit which introduced prediction was completely incorrect to even remotely care about what the actual coefficients contain or whether any options were enabled. Not my actual fault. This commit treats prediction the way the decoder does and expects to do: like lossy encryption. Everything related to prediction now happens at the very end but just before quantization and encoding of coefficients. On the decoder side, prediction happens before anything has had a chance to even access the coefficients. Also the original implementation had problems because it actually touched the band_type of special bands which already had their scalefactor indices marked and it's a wonder the asserion wasn't triggered when transmitting those. Overall, this now drastically increases audio quality and you should think about enabling it if you don't plan on playing anything encoded on really old low power ultra-embedded devices since they might not support decoding of prediction or AAC-Main. Though the specifications were written ages ago and as times change so do the FLOPS. Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* aacenc: change FF_PROFILE_UNKNOWN to AAC-Main if prediction is enabledRostislav Pehlivanov2015-08-291-2/+3
| | | | | | | This was missed when the original commits were done. FF_PROFILE_UNKNOWN is what's in avctx->profile when no audio profile is specified. Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* aacenctab: Add missing ff_ prefixesTimothy Gu2015-08-221-3/+3
| | | | | Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com> Reviewed-by: Ganesh Ajjanagadde <gajjanag@mit.edu>
* aacenc: treat unknown profile as AAC-LCRostislav Pehlivanov2015-08-211-1/+2
| | | | | | | | When the encoder is ran without specifying -profile:a the default avctx->profile value is -99 (FF_PROFILE_UKNOWN), which used to be treated as AAC-LC. Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* aacenc: implement the complete AAC-Main profileRostislav Pehlivanov2015-08-211-2/+31
| | | | | | | | | | | | | | | | | | | | | | | | This commit finalizes AAC-Main profile encoding support by implementing all mandatory and optional tools available in the specifications and current decoders. The AAC-Main profile reqires that prediction support be present (although decoders don't require it to be enabled) for an encoder to be deemed capable of AAC-Main encoding, as well as TNS, PNS and IS, all of which were implemented with previous commits or earlier of this year. Users are encouraged to test the new functionality using either -profile:a aac_main or -aac_pred 1, the former of which will enable the prediction option by default and the latter will change the profile to AAC-Main. No other options shall be changed by enabling either, it's currently up to the users to decide what's best. The current implementation works best using M/S and/or IS, so users are also welcome to enable both options and any other options (TNS, PNS) for maximum quality. Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* aacenc_tns: implement temporal noise shapingRostislav Pehlivanov2015-08-211-6/+17
| | | | | | | | | | | | | | | | | | | | This commit implements temporal noise shaping support in the encoder, along with an -aac_tns option to toggle it on or off (off by default for now). TNS will increase audio quality and reduce quantization noise by applying a multitap FIR filter across allowed coefficients and transmit side information to the decoder so it could create an inverse filter. Users are encouraged to test the new functionality by enabling -aac_tns 1 during encoding. No major bugs are observable at this time so after a while if no new problems appear and if the current implementation is deemed of high enough quality and stability it will be enabled by default, possibly at the same time the encoder has its experimental flag removed and becomes the standard aac encoder in ffmpeg. Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* aacenc: do not reject AAC-Main profileRostislav Pehlivanov2015-08-211-3/+11
| | | | | | | | | This commit permits for the use of the Main profile in encoding. The functionality of that profile will be added in the commits following. By itself, this commit does not alter anything. Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* aaccoder: move the Intensity Stereo implementation outRostislav Pehlivanov2015-08-211-3/+5
| | | | | | | | | | | | | | | | | | This commit moves the intensity stereo implementation out from aaccoder and into a separate file. This was possible using the previous commits. This commit also drastically improves the IS implementation by making it phase invariant e.g. it will always choose the best possible phase regardless of whether M/S coding is on or most of the coefficients have identical phases. This also increases the quality and reduces any distortions introduced by enablind intensity stereo. Users are encouraged to test it out using the -aac_is 1 parameter as it has always been. Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* aaccoder: move the quantization functions to a separate fileRostislav Pehlivanov2015-08-211-2/+5
| | | | | | | | | | | This commit moves the quantizer to a separate header file. This allows the quantizer to be used from a separate files outside of aaccoder without having to put another function pointer and will result in a slight speedup as the compiler can do more optimizations. This is required for commits following. Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* aacenc: create and initialize an LTP contextRostislav Pehlivanov2015-08-211-0/+2
| | | | | | | This commit only creates and initializes an LTP context which is needed for upcoming commits (TNS). Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* aacenc: populate the sce->ics.swb_offset table pointerRostislav Pehlivanov2015-08-211-0/+3
| | | | | | | | This commit simply populates the table pointer which is needed for upcoming commits (TNS, prediction, etc.). Copied from the decoder. Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* aacenc: reset special bands in the main frame encoding functionRostislav Pehlivanov2015-08-211-2/+7
| | | | | | | | | | | | | | | | This commit moves the resetting of special bands (above RESERVED_BT) to the main frame encoding function rather than the way it was done previously in their corresponding search_for_... functions. The reason why special bands need to be reset is that while normal bands get chosen for every frame by the coder (twoloop by default) the coders do not touch any special sfbs and will therefore make them persist throughout the file. If we zero them out any bands left unmarked will be chosen by the second part of the coder (the trellis function in aaccoder.c). Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* aacenc: coding style changesRostislav Pehlivanov2015-08-211-5/+7
| | | | | | | | | | | | | | | This commit only changes the coding style to a saner way of accessing coefficients (makes more sense to get the memory address of a coefficients and start from there rather than adding arbitrary numbers to offset a pointer). Some compilers might detect an out of bounds access easier. Also the way M/S and IS coefficients are calculated has been changed, but should still have the same result (with the exception that IS now applies from the normal coefficients rather than the pristine ones, this is needed for upcoming commits). Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* aacenc: Move small misc. functions to a separate fileRostislav Pehlivanov2015-08-111-11/+1
| | | | | | | | | | | As well as tables littered everywhere, functions were spread out all across the encoder's files. This moves them to a single place where they can be used by either the encoder's main files or additional encoder files. Additionally, it changes the type of some to 'inline' to enable us to simply put them in a header file and possibly gain some speed due to compiler optimizations. Signed-off-by: Claudio Freire <klaussfreire@gmail.com>
* aacenc: Move local encoder specific tables to a separate fileRostislav Pehlivanov2015-08-071-116/+2
| | | | | | | | | | | | | This commit moves any tables specific to the encoder from aacenc and aaccoder to a separate file called 'aacenctab.c/.h'. This was done as a clean up attempt as the encoder was filled with tables pasted in between functions which made it confusing to follow and track where each table and definition had been used. This commit solves this by simply exporting the smaller tables out to the aacenctab.h while the larger ones are compiled using aacenctab.c and are referenced from the header file. Signed-off-by: Claudio Freire <klaussfreire@gmail.com>
* aacenc: add description to the 'aac_coder' optionRostislav Pehlivanov2015-08-011-1/+1
| | | | | | | | | | | This commit adds a short description to the aac_coder option of the AAC encoder in order to be consistent with the other options. Generally, right now, the 'FAAC' method works fine with speech and low broadband spectrum audio. 'Fast' is just as the name suggests. 'ANMR' still needs work and 'Twoloop', the default, works well with every type of audio. Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* aacenc: remove redundant argument from coder functionsRostislav Pehlivanov2015-08-011-3/+3
| | | | | | | | | | | This commit removes a redundant argument from the functions in aaccoder. The argument lambda was redundant as it was just a copy of s->lambda, to which all functions have access to anyway. This cleans up the function pointers a bit which is helpful as there are a lot of other search_for_* functions under development and with them populated it gets messy. Reviewed-by: Claudio Freire <klaussfreire@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* Merge commit '059a934806d61f7af9ab3fd9f74994b838ea5eba'Michael Niedermayer2015-07-271-1/+1
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * commit '059a934806d61f7af9ab3fd9f74994b838ea5eba': lavc: Consistently prefix input buffer defines Conflicts: doc/examples/decoding_encoding.c libavcodec/4xm.c libavcodec/aac_adtstoasc_bsf.c libavcodec/aacdec.c libavcodec/aacenc.c libavcodec/ac3dec.h libavcodec/asvenc.c libavcodec/avcodec.h libavcodec/avpacket.c libavcodec/dvdec.c libavcodec/ffv1enc.c libavcodec/g2meet.c libavcodec/gif.c libavcodec/h264.c libavcodec/h264_mp4toannexb_bsf.c libavcodec/huffyuvdec.c libavcodec/huffyuvenc.c libavcodec/jpeglsenc.c libavcodec/libxvid.c libavcodec/mdec.c libavcodec/motionpixels.c libavcodec/mpeg4videodec.c libavcodec/mpegvideo.c libavcodec/noise_bsf.c libavcodec/nuv.c libavcodec/nvenc.c libavcodec/options.c libavcodec/parser.c libavcodec/pngenc.c libavcodec/proresenc_kostya.c libavcodec/qsvdec.c libavcodec/svq1enc.c libavcodec/tiffenc.c libavcodec/truemotion2.c libavcodec/utils.c libavcodec/utvideoenc.c libavcodec/vc1dec.c libavcodec/wmalosslessdec.c libavformat/adxdec.c libavformat/aiffdec.c libavformat/apc.c libavformat/apetag.c libavformat/avidec.c libavformat/bink.c libavformat/cafdec.c libavformat/flvdec.c libavformat/id3v2.c libavformat/isom.c libavformat/matroskadec.c libavformat/mov.c libavformat/mpc.c libavformat/mpc8.c libavformat/mpegts.c libavformat/mvi.c libavformat/mxfdec.c libavformat/mxg.c libavformat/nutdec.c libavformat/oggdec.c libavformat/oggparsecelt.c libavformat/oggparseflac.c libavformat/oggparseopus.c libavformat/oggparsespeex.c libavformat/omadec.c libavformat/rawdec.c libavformat/riffdec.c libavformat/rl2.c libavformat/rmdec.c libavformat/rtpdec_latm.c libavformat/rtpdec_mpeg4.c libavformat/rtpdec_qdm2.c libavformat/rtpdec_svq3.c libavformat/sierravmd.c libavformat/smacker.c libavformat/smush.c libavformat/spdifenc.c libavformat/takdec.c libavformat/tta.c libavformat/utils.c libavformat/vqf.c libavformat/westwood_vqa.c libavformat/xmv.c libavformat/xwma.c libavformat/yop.c Merged-by: Michael Niedermayer <michael@niedermayer.cc>
| * lavc: Consistently prefix input buffer definesVittorio Giovara2015-07-271-1/+1
| | | | | | | | Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
* | Merge commit 'def97856de6021965db86c25a732d78689bd6bb0'Michael Niedermayer2015-07-271-2/+2
|\ \ | |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * commit 'def97856de6021965db86c25a732d78689bd6bb0': lavc: AV-prefix all codec capabilities Conflicts: cmdutils.c ffmpeg.c ffplay.c libavcodec/8svx.c libavcodec/aacenc.c libavcodec/ac3dec.c libavcodec/adpcm.c libavcodec/alac.c libavcodec/atrac3plusdec.c libavcodec/bink.c libavcodec/dnxhddec.c libavcodec/dvdec.c libavcodec/dvenc.c libavcodec/ffv1dec.c libavcodec/ffv1enc.c libavcodec/fic.c libavcodec/flacdec.c libavcodec/flacenc.c libavcodec/flvdec.c libavcodec/fraps.c libavcodec/frwu.c libavcodec/gifdec.c libavcodec/h261dec.c libavcodec/hevc.c libavcodec/iff.c libavcodec/imc.c libavcodec/libopenjpegdec.c libavcodec/libvo-aacenc.c libavcodec/libvorbisenc.c libavcodec/libvpxdec.c libavcodec/libvpxenc.c libavcodec/libx264.c libavcodec/mjpegbdec.c libavcodec/mjpegdec.c libavcodec/mpegaudiodec_float.c libavcodec/msmpeg4dec.c libavcodec/mxpegdec.c libavcodec/nvenc_h264.c libavcodec/nvenc_hevc.c libavcodec/pngdec.c libavcodec/qpeg.c libavcodec/ra288.c libavcodec/rv10.c libavcodec/s302m.c libavcodec/sp5xdec.c libavcodec/takdec.c libavcodec/tiff.c libavcodec/tta.c libavcodec/utils.c libavcodec/v210dec.c libavcodec/vp6.c libavcodec/vp9.c libavcodec/wavpack.c libavcodec/yop.c Merged-by: Michael Niedermayer <michael@niedermayer.cc>
| * lavc: AV-prefix all codec capabilitiesVittorio Giovara2015-07-271-2/+2
| | | | | | | | | | | | Express bitfields more simply. Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
* | Merge commit '7c6eb0a1b7bf1aac7f033a7ec6d8cacc3b5c2615'Michael Niedermayer2015-07-271-3/+3
|\ \ | |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * commit '7c6eb0a1b7bf1aac7f033a7ec6d8cacc3b5c2615': lavc: AV-prefix all codec flags Conflicts: doc/examples/muxing.c ffmpeg.c ffmpeg_opt.c ffplay.c libavcodec/aacdec.c libavcodec/aacenc.c libavcodec/ac3dec.c libavcodec/ac3enc_float.c libavcodec/atrac1.c libavcodec/atrac3.c libavcodec/atrac3plusdec.c libavcodec/dcadec.c libavcodec/ffv1enc.c libavcodec/h264.c libavcodec/h264_loopfilter.c libavcodec/h264_mb.c libavcodec/imc.c libavcodec/libmp3lame.c libavcodec/libtheoraenc.c libavcodec/libtwolame.c libavcodec/libvpxenc.c libavcodec/libxavs.c libavcodec/libxvid.c libavcodec/mpeg12dec.c libavcodec/mpeg12enc.c libavcodec/mpegaudiodec_template.c libavcodec/mpegvideo.c libavcodec/mpegvideo_enc.c libavcodec/mpegvideo_motion.c libavcodec/nellymoserdec.c libavcodec/nellymoserenc.c libavcodec/nvenc.c libavcodec/on2avc.c libavcodec/options_table.h libavcodec/opus_celt.c libavcodec/pngenc.c libavcodec/ra288.c libavcodec/ratecontrol.c libavcodec/twinvq.c libavcodec/vc1_block.c libavcodec/vc1_loopfilter.c libavcodec/vc1_mc.c libavcodec/vc1dec.c libavcodec/vorbisdec.c libavcodec/vp3.c libavcodec/wma.c libavcodec/wmaprodec.c libavcodec/x86/hpeldsp_init.c libavcodec/x86/me_cmp_init.c Merged-by: Michael Niedermayer <michael@niedermayer.cc>
| * lavc: AV-prefix all codec flagsVittorio Giovara2015-07-271-3/+3
| | | | | | | | | | | | Convert doxygen to multiline and express bitfields more simply. Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
* | avcodec: Add a min size parameter to ff_alloc_packet2()Michael Niedermayer2015-07-271-1/+1
| | | | | | | | | | | | | | | | This parameter can be used to inform the allocation code about how much downsizing might occur, and can be used to optimize how to allocate the packet Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* | AAC Encoder: clipping avoidanceClaudio Freire2015-07-271-1/+37
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Avoid clipping due to quantization noise to produce audible artifacts, by detecting near-clipping signals and both attenuating them a little and encoding escape-encoded bands (usually the loudest) rounding towards zero instead of nearest, which tends to decrease overall energy and thus clipping. Currently fate tests measure numerical error so this change makes tests using asynth (which are near clipping) report higher error not less, because of window attenuation. Yet, they sound better, not worse (albeit subtle, other samples aren't subtle at all). Only measuring psychoacoustically weighted error would make for a representative test, so that will be left for a future patch. Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* | aacenc: move the generation of ff_aac_pow34sf_tab[]Rostislav Pehlivanov2015-07-211-4/+0
| | | | | | | | | | | | | | | | | | | | | | | | This commit moves the generation of ff_aac_pow34sf_tab[] out of the encoder and into the table generator. The original commit log for this table in 2011 actually mentions that it should be moved outside but this never happened. This is the first commit which cleans up the encoder a little. Reviewed-by: Claudio Freire <klaussfreire@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* | aacenc: fix option descriptionsRostislav Pehlivanov2015-07-071-3/+3
| | | | | | | | | | | | | | | | | | Since the new PNS implementation has been merged and is no longer considered proof of concept (as it's much more complex and better than the previous), change the comments to reflect that. We need people testing it (since all AAC profiles require it to be on by default) and having it tagged as proof of concept might drive some away. Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* | aacenc: implement Intensity Stereo encoding supportRostislav Pehlivanov2015-07-051-2/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit implements intensity stereo coding support to the native aac encoder. This is a way to increase the efficiency of the encoder by zeroing the right channel's spectral coefficients (in a channel pair) and rederiving them in the decoder using information from the scalefactor indices of special band types. This commit confomrs to the official ISO 13818-7 specifications, although due to their ambiguity certain deviations have been taken to ensure maximum sound quality. This commit has been extensively tested and has shown to not result in audiable audio artifacts unless in extreme cases. This commit also adds an option, aac_is, which has the value of 0 by default. Intensity Stereo is part of the scalable aac profile and is thus non-default. The way IS coding works is that it rederives the right channel's spectral coefficients from the left channel via the scalefactor index values left in the right channel. Since an entire band's spectral coefficients do not need to be coded, the encoder's efficiency jumps up and it unzeroes some high frequency values which it previously did not have enough bits to encode. That way less information is lost than the information lost by rederiving the spectral coefficients with some error. This is why the filesize of files encoded with IS do not decrease significantly. Users wishing that IS coding should reduce filesize are expected to reduce their encoding bitrates appropriately. This is V2 of the commit. The old version did not mark ms_mask as 0 since M/S and IS coding are incompactible, which resulted in distortions with M/S coding enabled. This version also improves phase detection by measuring it for every spectral coefficient in the band and using a simple majority rule to determine whether the coefficients are in or out of phase. Also, the energy values per spectral coefficient were changed as to reflect the official specifications. Reviewed-by: Claudio Freire <klaussfreire@gmail.com> Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* | aacenc: add support for coding of IS spectral coefficientsRostislav Pehlivanov2015-07-051-10/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | This commit adds support for the coding of intensity stereo spectral coefficients. It also fixes the Mid/Side coding of band_types higher than RESERVED_BT (M/S must not be applied to their spectral coefficients, but marking M/S as present in encode_ms_info() is okay). Much of the changes here were taken from the decoder and inverted. This commit does not change the functionality of the decoder as the previous patch in this series zeroes ms_mask and is_mask. Reviewed-by: Claudio Freire <klaussfreire@gmail.com> Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* | aaccoder: add a new perceptual noise substitution implementationRostislav Pehlivanov2015-07-051-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit finalizes the PNS implementation previously added to the encoder by moving it to a seperate function search_for_pns() and thus making it coder-generic. This new implementation makes use of the spread field of the psy bands and the lambda quality feedback paremeter. The spread of the spectrum in a band prevents PNS from being used excessively and thus preserve more phase information in high frequencies. The lambda parameter allows the number of PNS-marked bands to vary based on the lambda parameter and the amount of bits available, making better choices on which bands are to be marked as noise. Comparisons with the previous PNS implementation can be found here: https://trac.ffmpeg.org/attachment/wiki/Encode/AAC/ This is V2 of the patch, the changes from the previous version being that this version uses the new band->spread metric from aacpsy and normalizes the energy using the group size. These changes were suggested by Claudio Freire on the mailing list. Another change is the use of lambda to alter the frequency threshold. This change makes the actual threshold frequencies vary between +-2Khz of what's specified, depending on frame encoding performance. Reviewed-by: Claudio Freire <klaussfreire@gmail.com> Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* | aacenc: use the new function for setting special band scalefactor indicesRostislav Pehlivanov2015-07-051-0/+3
| | | | | | | | | | | | | | | | | | | | | | This commit enables the function added with commit 7c10b87 and uses that new function for setting any special scalefactor indices. This commit does not change the behaviour of the encoder since no bands are being marked as either NOISE_BT(due to the previous PNS implementation removed in the previous commit) or INTENSITY_BT2/INTENSITY_BT. Reviewed-by: Claudio Freire <klaussfreire@gmail.com> Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* | aacenc: reset marked IS and M/S bands upon frame encodingRostislav Pehlivanov2015-07-031-0/+2
| | | | | | | | | | | | | | | | | | | | This commit resets any bands marked as M/S or IS upon encoding a frame. This is needed because the arrays may contain some residual information upon allocation on startup and because there isn't any mechanism to reset the arrays once the frame has been encoded. Reviewed-by: Claudio Freire <klaussfreire@gmail.com> Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* | aacenc: add support for coding of intensity stereo scalefactor indicesRostislav Pehlivanov2015-06-291-1/+5
| | | | | | | | | | | | | | | | | | | | | | This commit adds support for the coding of intensity stereo scalefactor indices. It does not do any marking of such bands and as such does no functional changes to the encoder. It removes any old twoloop specific code for PNS and moves it into a seperate function which handles setting of scalefactor indices for PNS and IS bands. Reviewed-by: Claudio Freire <klaussfreire@gmail.com> Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* | avcodec/aacenc: use < 0 instead of != 0 for error checksMichael Niedermayer2015-05-161-2/+2
| | | | | | | | Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* | aaccoder: Implement Perceptual Noise Substitution for AACRostislav Pehlivanov2015-04-151-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit implements the perceptual noise substitution AAC extension. This is a proof of concept implementation, and as such, is not enabled by default. This is the fourth revision of this patch, made after some problems were noted out. Any changes made since the previous revisions have been indicated. In order to extend the encoder to use an additional codebook, the array holding each codebook has been modified with two additional entries - 13 for the NOISE_BT codebook and 12 which has a placeholder function. The cost system was modified to skip the 12th entry using an array to map the input and outputs it has. It also does not accept using the 13th codebook for any band which is not marked as containing noise, thereby restricting its ability to arbitrarily choose it for bands. The use of arrays allows the system to be easily extended to allow for intensity stereo encoding, which uses additional codebooks. The 12th entry in the codebook function array points to a function which stops the execution of the program by calling an assert with an always 'false' argument. It was pointed out in an email discussion with Claudio Freire that having a 'NULL' entry can result in unexpected behaviour and could be used as a security hole. There is no danger of this function being called during encoding due to the codebook maps introduced. Another change from version 1 of the patch is the addition of an argument to the encoder, '-aac_pns' to enable and disable the PNS. This currently defaults to disable the PNS, as it is experimental. The switch will be removed in the future, when the algorithm to select noise bands has been improved. The current algorithm simply compares the energy to the threshold (multiplied by a constant) to determine noise, however the FFPsyBand structure contains other useful figures to determine which bands carry noise more accurately. Some of the sample files provided triggered an assertion when the parameter to tune the threshold was set to a value of '2.2'. Claudio Freire reported the problem's source could be in the range of the scalefactor indices for noise and advised to measure the minimal index and clip anything above the maximum allowed value. This has been implemented and all the files which used to trigger the asserion now encode without error. The third revision of the problem also removes unneded variabes and comparisons. All of them were redundant and were of little use for when the PNS implementation would be extended. The fourth revision moved the clipping of the noise scalefactors outside the second loop of the two-loop algorithm in order to prevent their redundant calculations. Also, freq_mult has been changed to a float variable due to the fact that rounding errors can prove to be a problem at low frequencies. Considerations were taken whether the entire expression could be evaluated inside the expression , but in the end it was decided that it would be for the best if just the type of the variable were to change. Claudio Freire reported the two problems. There is no change of functionality (except for low sampling frequencies) so the spectral demonstrations at the end of this commit's message were not updated. Finally, the way energy values are converted to scalefactor indices has changed since the first commit, as per the suggestion of Claudio Freire. This may still have some drawbacks, but unlike the first commit it works without having redundant offsets and outputs what the decoder expects to have, in terms of the ranges of the scalefactor indices. Some spectral comparisons: https://trac.ffmpeg.org/attachment/wiki/Encode/AAC/Original.png (original), https://trac.ffmpeg.org/attachment/wiki/Encode/AAC/PNS_NO.png (encoded without PNS), https://trac.ffmpeg.org/attachment/wiki/Encode/AAC/PNS1.2.png (encoded with PNS, const = 1.2), https://trac.ffmpeg.org/attachment/wiki/Encode/AAC/Difference1.png (spectral difference). The constant is the value which multiplies the threshold when it gets compared to the energy, larger values means more noise will be substituded by PNS values. Example when const = 2.2: https://trac.ffmpeg.org/attachment/wiki/Encode/AAC/PNS_2.2.png Reviewed-by: Claudio Freire <klaussfreire@gmail.com> Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* | aacenc: Adjust the initial offset for PNS valuesRostislav Pehlivanov2015-04-141-1/+1
| | | | | | | | | | | | | | | | | | This commit adjusts the intial offset for PNS values, introduced with commit f7f71b5795d708763eb0c55fe5e2cb051b2b69f4 earlier. This commit shifts the value in such a way that no further offsets are required in the aaccoder.c file. Earlier version of the PNS patch had 2 offsets in both the aaccoder and aacenc. Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* | aacenc: Add support for Perceptual Noise Substitution energy valuesRostislav Pehlivanov2015-04-131-3/+14
| | | | | | | | | | | | | | | | | | | | | | | | This commit implements support for writing the noise energy values used in PNS. The difference between regular scalefactors and noise energy values is that the latter require a small preamble (NOISE_PRE + energy_value_diff) to be written as the first noise-containing band. Any following noise energy values use the previous one to base their "diff" on. Ordinary scalefactors remain unchanged other than that they ignore the noise values. This commit should not change anything by itself, the following commits will bring it in use. Signed-off-by: Michael Niedermayer <michaelni@gmx.at>