Mercurial > libavcodec.hg
comparison wmaprodec.c @ 10073:57d76996ccb8 libavcodec
Add some more wmapro decoder hunks
| author | faust3 |
|---|---|
| date | Fri, 21 Aug 2009 16:54:42 +0000 |
| parents | 4b91b74ff669 |
| children | bf63f070fbf7 |
comparison
equal
deleted
inserted
replaced
| 10072:0a3bf7990e39 | 10073:57d76996ccb8 |
|---|---|
| 1 /* | |
| 2 * Wmapro compatible decoder | |
| 3 * Copyright (c) 2007 Baptiste Coudurier, Benjamin Larsson, Ulion | |
| 4 * Copyright (c) 2008 - 2009 Sascha Sommer, Benjamin Larsson | |
| 5 * | |
| 6 * This file is part of FFmpeg. | |
| 7 * | |
| 8 * FFmpeg is free software; you can redistribute it and/or | |
| 9 * modify it under the terms of the GNU Lesser General Public | |
| 10 * License as published by the Free Software Foundation; either | |
| 11 * version 2.1 of the License, or (at your option) any later version. | |
| 12 * | |
| 13 * FFmpeg is distributed in the hope that it will be useful, | |
| 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 16 * Lesser General Public License for more details. | |
| 17 * | |
| 18 * You should have received a copy of the GNU Lesser General Public | |
| 19 * License along with FFmpeg; if not, write to the Free Software | |
| 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
| 21 */ | |
| 22 | |
| 23 /** | |
| 24 * @file libavcodec/wmaprodec.c | |
| 25 * @brief wmapro decoder implementation | |
| 26 * Wmapro is an MDCT based codec comparable to wma standard or AAC. | |
| 27 * The decoding therefore consists of the following steps: | |
| 28 * - bitstream decoding | |
| 29 * - reconstruction of per-channel data | |
| 30 * - rescaling and inverse quantization | |
| 31 * - IMDCT | |
| 32 * - windowing and overlapp-add | |
| 33 * | |
| 34 * The compressed wmapro bitstream is split into individual packets. | |
| 35 * Every such packet contains one or more wma frames. | |
| 36 * The compressed frames may have a variable length and frames may | |
| 37 * cross packet boundaries. | |
| 38 * Common to all wmapro frames is the number of samples that are stored in | |
| 39 * a frame. | |
| 40 * The number of samples and a few other decode flags are stored | |
| 41 * as extradata that has to be passed to the decoder. | |
| 42 * | |
| 43 * The wmapro frames themselves are again split into a variable number of | |
| 44 * subframes. Every subframe contains the data for 2^N time domain samples | |
| 45 * where N varies between 7 and 12. | |
| 46 * | |
| 47 * Example wmapro bitstream (in samples): | |
| 48 * | |
| 49 * || packet 0 || packet 1 || packet 2 packets | |
| 50 * --------------------------------------------------- | |
| 51 * || frame 0 || frame 1 || frame 2 || frames | |
| 52 * --------------------------------------------------- | |
| 53 * || | | || | | | || || subframes of channel 0 | |
| 54 * --------------------------------------------------- | |
| 55 * || | | || | | | || || subframes of channel 1 | |
| 56 * --------------------------------------------------- | |
| 57 * | |
| 58 * The frame layouts for the individual channels of a wma frame does not need | |
| 59 * to be the same. | |
| 60 * | |
| 61 * However, if the offsets and lengths of several subframes of a frame are the | |
| 62 * same, the subframes of the channels can be grouped. | |
| 63 * Every group may then use special coding techniques like M/S stereo coding | |
| 64 * to improve the compression ratio. These channel transformations do not | |
| 65 * need to be applied to a whole subframe. Instead, they can also work on | |
| 66 * individual scale factor bands (see below). | |
| 67 * The coefficients that carry the audio signal in the frequency domain | |
| 68 * are transmitted as huffman-coded vectors with 4, 2 and 1 elements. | |
| 69 * In addition to that, the encoder can switch to a runlevel coding scheme | |
| 70 * by transmitting subframe_length / 128 zero coefficients. | |
| 71 * | |
| 72 * Before the audio signal can be converted to the time domain, the | |
| 73 * coefficients have to be rescaled and inverse quantized. | |
| 74 * A subframe is therefore split into several scale factor bands that get | |
| 75 * scaled individually. | |
| 76 * Scale factors are submitted for every frame but they might be shared | |
| 77 * between the subframes of a channel. Scale factors are initially DPCM-coded. | |
| 78 * Once scale factors are shared, the differences are transmitted as runlevel | |
| 79 * codes. | |
| 80 * Every subframe length and offset combination in the frame layout shares a | |
| 81 * common quantization factor that can be adjusted for every channel by a | |
| 82 * modifier. | |
| 83 * After the inverse quantization, the coefficients get processed by an IMDCT. | |
| 84 * The resulting values are then windowed with a sine window and the first half | |
| 85 * of the values are added to the second half of the output from the previous | |
| 86 * subframe in order to reconstruct the output samples. | |
| 87 */ | |
| 88 | |
| 1 /** | 89 /** |
| 2 *@brief Uninitialize the decoder and free all resources. | 90 *@brief Uninitialize the decoder and free all resources. |
| 3 *@param avctx codec context | 91 *@param avctx codec context |
| 4 *@return 0 on success, < 0 otherwise | 92 *@return 0 on success, < 0 otherwise |
| 5 */ | 93 */ |
| 6 static av_cold int decode_end(AVCodecContext *avctx) | 94 static av_cold int decode_end(AVCodecContext *avctx) |
| 7 { | 95 { |
| 8 WMA3DecodeContext *s = avctx->priv_data; | 96 WMA3DecodeContext *s = avctx->priv_data; |
| 9 int i; | 97 int i; |
| 10 | |
| 11 av_freep(&s->num_sfb); | |
| 12 av_freep(&s->sfb_offsets); | |
| 13 av_freep(&s->subwoofer_cutoffs); | |
| 14 av_freep(&s->sf_offsets); | |
| 15 | 98 |
| 16 for (i = 0 ; i < WMAPRO_BLOCK_SIZES ; i++) | 99 for (i = 0 ; i < WMAPRO_BLOCK_SIZES ; i++) |
| 17 ff_mdct_end(&s->mdct_ctx[i]); | 100 ff_mdct_end(&s->mdct_ctx[i]); |
| 18 | 101 |
| 19 return 0; | 102 return 0; |
