[FFmpeg-soc] [soc]: r2475 - in aacenc: aacenc.c aacpsy.c aacpsy.h
kostya
subversion at mplayerhq.hu
Wed Jun 18 08:15:48 CEST 2008
Author: kostya
Date: Wed Jun 18 08:15:47 2008
New Revision: 2475
Log:
Pulse encoding support
Modified:
aacenc/aacenc.c
aacenc/aacpsy.c
aacenc/aacpsy.h
Modified: aacenc/aacenc.c
==============================================================================
--- aacenc/aacenc.c (original)
+++ aacenc/aacenc.c Wed Jun 18 08:15:47 2008
@@ -476,6 +476,21 @@ static void encode_scale_factor_data(AVC
}
}
+static void encode_pulse_data(AVCodecContext *avctx, AACEncContext *s, cpe_struct *cpe, int channel)
+{
+ int i;
+
+ put_bits(&s->pb, 1, cpe->ch[channel].pulse.present);
+ if(!cpe->ch[channel].pulse.present) return;
+
+ put_bits(&s->pb, 2, cpe->ch[channel].pulse.num_pulse_minus1);
+ put_bits(&s->pb, 6, cpe->ch[channel].pulse.start);
+ for(i = 0; i <= cpe->ch[channel].pulse.num_pulse_minus1; i++){
+ put_bits(&s->pb, 5, cpe->ch[channel].pulse.offset[i]);
+ put_bits(&s->pb, 4, cpe->ch[channel].pulse.amp[i]);
+ }
+}
+
static void encode_spectral_data(AVCodecContext *avctx, AACEncContext *s, cpe_struct *cpe, int channel)
{
int start, i, w, w2;
@@ -520,7 +535,7 @@ static int encode_individual_channel(AVC
if(!cpe->common_window) put_ics_info(avctx, &cpe->ch[channel].ics);
encode_section_data(avctx, s, cpe, channel);
encode_scale_factor_data(avctx, s, cpe, channel);
- put_bits(&s->pb, 1, 0); //pulse
+ encode_pulse_data(avctx, s, cpe, channel);
put_bits(&s->pb, 1, 0); //tns
put_bits(&s->pb, 1, 0); //ssr
encode_spectral_data(avctx, s, cpe, channel);
Modified: aacenc/aacpsy.c
==============================================================================
--- aacenc/aacpsy.c (original)
+++ aacenc/aacpsy.c Wed Jun 18 08:15:47 2008
@@ -55,6 +55,7 @@ static void psy_null_process(AACPsyConte
{
int start, sum, maxsfb;
int ch, g, i;
+ int pulses, poff[4], pamp[4];
//detect M/S
if(apc->avctx->channels > 1 && cpe->common_window){
@@ -70,6 +71,7 @@ static void psy_null_process(AACPsyConte
for(ch = 0; ch < apc->avctx->channels; ch++){
start = 0;
cpe->ch[ch].gain = SCALE_ONE_POS;
+ cpe->ch[ch].pulse.present = 0;
for(g = 0; g < apc->num_bands1024; g++){
sum = 0;
cpe->ch[ch].sf_idx[0][g] = SCALE_ONE_POS;
@@ -85,6 +87,34 @@ static void psy_null_process(AACPsyConte
sum += !!cpe->ch[ch].icoefs[start+i];
}
cpe->ch[ch].zeroes[0][g] = !sum;
+ //try finding pulses
+ if(!cpe->ch[ch].pulse.present){
+ pulses = 0;
+ memset(poff,0,sizeof(poff));
+ memset(pamp,0,sizeof(pamp));
+ for(i = 0; i < apc->bands1024[g]; i++){
+ if(pulses > 4 || (pulses && i > cpe->ch[ch].pulse.offset[pulses-1] - 31)) break;
+ if(FFABS(cpe->ch[ch].icoefs[start+i]) > 4 && pulses < 4){
+ poff[pulses] = i;
+ pamp[pulses] = FFMIN(FFABS(cpe->ch[ch].icoefs[start+i]) - 1, 15);
+ pulses++;
+ }
+ }
+ if(pulses){
+ cpe->ch[ch].pulse.present = 1;
+ cpe->ch[ch].pulse.start = g;
+ cpe->ch[ch].pulse.num_pulse_minus1 = pulses - 1;
+ for(i = 0; i < pulses; i++){
+ cpe->ch[ch].pulse.amp[i] = pamp[i];
+ cpe->ch[ch].pulse.offset[i] = i ? poff[i] - poff[i-1] : poff[0];
+
+ if(cpe->ch[ch].icoefs[start+poff[i]] > 0)
+ cpe->ch[ch].icoefs[start+poff[i]] -= pamp[i];
+ else
+ cpe->ch[ch].icoefs[start+poff[i]] += pamp[i];
+ }
+ }
+ }
start += apc->bands1024[g];
}
for(maxsfb = apc->num_bands1024; maxsfb > 0 && cpe->ch[ch].zeroes[0][maxsfb-1]; maxsfb--);
Modified: aacenc/aacpsy.h
==============================================================================
--- aacenc/aacpsy.h (original)
+++ aacenc/aacpsy.h Wed Jun 18 08:15:47 2008
@@ -44,6 +44,17 @@ enum {
};
/**
+ * Pulse tool
+ */
+typedef struct {
+ int present;
+ int num_pulse_minus1;
+ int start;
+ int offset[4];
+ int amp[4];
+} pulse_struct;
+
+/**
* Individual Channel Stream
*/
typedef struct {
@@ -79,6 +90,7 @@ typedef struct {
* Thus, when used inside CPE elements, both channels must have equal gain.
*/
ics_struct ics;
+ pulse_struct pulse;
int zeroes[8][64];
int sf_idx[8][64];
int cb[8][64]; ///< Codebooks
More information about the FFmpeg-soc
mailing list