summaryrefslogtreecommitdiff
path: root/libavcodec/aacenc.c
diff options
context:
space:
mode:
authorKostya Shishkov <kostya.shishkov@gmail.com>2008-08-16 05:47:18 +0000
committerKostya Shishkov <kostya.shishkov@gmail.com>2008-08-16 05:47:18 +0000
commit817015e4e2e8d9efbec446033341c9117f889bb8 (patch)
tree0eaca2261b1988c4da5c7b70dda59710bdff012d /libavcodec/aacenc.c
parent38a1c7f2be4e0599c4c47c0b7eb55caa09c67fd4 (diff)
Add approved chunks to AAC encoder
Originally committed as revision 14785 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec/aacenc.c')
-rw-r--r--libavcodec/aacenc.c60
1 files changed, 58 insertions, 2 deletions
diff --git a/libavcodec/aacenc.c b/libavcodec/aacenc.c
index 858a7b69a4..838863b8b8 100644
--- a/libavcodec/aacenc.c
+++ b/libavcodec/aacenc.c
@@ -27,8 +27,7 @@
/***********************************
* TODOs:
* psy model selection with some option
- * change greedy codebook search into something more optimal, like Viterbi algorithm
- * determine run lengths along with codebook
+ * add sane pulse detection
***********************************/
#include "avcodec.h"
@@ -130,6 +129,16 @@ static const uint8_t aac_chan_configs[6][5] = {
};
/**
+ * AAC encoder context
+ */
+typedef struct {
+ PutBitContext pb;
+ MDCTContext mdct1024; ///< long (1024 samples) frame transform context
+ MDCTContext mdct128; ///< short (128 samples) frame transform context
+ DSPContext dsp;
+} AACEncContext;
+
+/**
* Make AAC audio config object.
* @see 1.6.2.1 "Syntax - AudioSpecificConfig"
*/
@@ -176,6 +185,11 @@ static av_cold int aac_encode_init(AVCodecContext *avctx)
dsputil_init(&s->dsp, avctx);
ff_mdct_init(&s->mdct1024, 11, 0);
ff_mdct_init(&s->mdct128, 8, 0);
+ // window init
+ ff_kbd_window_init(ff_aac_kbd_long_1024, 4.0, 1024);
+ ff_kbd_window_init(ff_aac_kbd_short_128, 6.0, 128);
+ ff_sine_window_init(ff_sine_1024, 1024);
+ ff_sine_window_init(ff_sine_128, 128);
s->samples = av_malloc(2 * 1024 * avctx->channels * sizeof(s->samples[0]));
s->cpe = av_mallocz(sizeof(ChannelElement) * aac_chan_configs[avctx->channels-1][0]);
@@ -212,6 +226,48 @@ static void put_ics_info(AVCodecContext *avctx, IndividualChannelStream *info)
}
/**
+ * Encode pulse data.
+ */
+static void encode_pulses(AVCodecContext *avctx, AACEncContext *s, Pulse *pulse, int channel)
+{
+ int i;
+
+ put_bits(&s->pb, 1, !!pulse->num_pulse);
+ if(!pulse->num_pulse) return;
+
+ put_bits(&s->pb, 2, pulse->num_pulse - 1);
+ put_bits(&s->pb, 6, pulse->start);
+ for(i = 0; i < pulse->num_pulse; i++){
+ put_bits(&s->pb, 5, pulse->offset[i]);
+ put_bits(&s->pb, 4, pulse->amp[i]);
+ }
+}
+
+/**
+ * Encode spectral coefficients processed by psychoacoustic model.
+ */
+static void encode_spectral_coeffs(AVCodecContext *avctx, AACEncContext *s, ChannelElement *cpe, int channel)
+{
+ int start, i, w, w2, wg;
+
+ w = 0;
+ for(wg = 0; wg < cpe->ch[channel].ics.num_window_groups; wg++){
+ start = 0;
+ for(i = 0; i < cpe->ch[channel].ics.max_sfb; i++){
+ if(cpe->ch[channel].zeroes[w][i]){
+ start += cpe->ch[channel].ics.swb_sizes[i];
+ continue;
+ }
+ for(w2 = w; w2 < w + cpe->ch[channel].ics.group_len[wg]; w2++){
+ encode_band_coeffs(s, cpe, channel, start + w2*128, cpe->ch[channel].ics.swb_sizes[i], cpe->ch[channel].band_type[w][i]);
+ }
+ start += cpe->ch[channel].ics.swb_sizes[i];
+ }
+ w += cpe->ch[channel].ics.group_len[wg];
+ }
+}
+
+/**
* Write some auxiliary information about the created AAC file.
*/
static void put_bitstream_info(AVCodecContext *avctx, AACEncContext *s, const char *name)