ac3.h File Reference

#include "ac3tab.h"

Go to the source code of this file.

Data Structures

struct  AC3BitAllocParameters
struct  AC3HeaderInfo

Defines

#define AC3_MAX_CODED_FRAME_SIZE   3840
#define AC3_MAX_CHANNELS   6
#define NB_BLOCKS   6
#define AC3_FRAME_SIZE   (NB_BLOCKS * 256)
#define EXP_REUSE   0
#define EXP_NEW   1
#define EXP_D15   1
#define EXP_D25   2
#define EXP_D45   3

Enumerations

enum  AC3DeltaStrategy { DBA_REUSE = 0, DBA_NEW, DBA_NONE, DBA_RESERVED }
enum  AC3ChannelMode {
  AC3_CHMODE_DUALMONO = 0, AC3_CHMODE_MONO, AC3_CHMODE_STEREO, AC3_CHMODE_3F,
  AC3_CHMODE_2F1R, AC3_CHMODE_3F1R, AC3_CHMODE_2F2R, AC3_CHMODE_3F2R
}
enum  EAC3FrameType { EAC3_FRAME_TYPE_INDEPENDENT = 0, EAC3_FRAME_TYPE_DEPENDENT, EAC3_FRAME_TYPE_AC3_CONVERT, EAC3_FRAME_TYPE_RESERVED }

Functions

void ac3_common_init (void)
void ff_ac3_bit_alloc_calc_psd (int8_t *exp, int start, int end, int16_t *psd, int16_t *band_psd)
void ff_ac3_bit_alloc_calc_mask (AC3BitAllocParameters *s, int16_t *band_psd, int start, int end, int fast_gain, int is_lfe, int dba_mode, int dba_nsegs, uint8_t *dba_offsets, uint8_t *dba_lengths, uint8_t *dba_values, int16_t *mask)
void ff_ac3_bit_alloc_calc_bap (int16_t *mask, int16_t *psd, int start, int end, int snr_offset, int floor, const uint8_t *bap_tab, uint8_t *bap)
void ac3_parametric_bit_allocation (AC3BitAllocParameters *s, uint8_t *bap, int8_t *exp, int start, int end, int snr_offset, int fast_gain, int is_lfe, int dba_mode, int dba_nsegs, uint8_t *dba_offsets, uint8_t *dba_lengths, uint8_t *dba_values)


Detailed Description

Common code between AC3 encoder and decoder.

Definition in file ac3.h.


Define Documentation

#define AC3_FRAME_SIZE   (NB_BLOCKS * 256)

Definition at line 36 of file ac3.h.

Referenced by AC3_encode_init(), and ac3_sync().

#define AC3_MAX_CHANNELS   6

Definition at line 33 of file ac3.h.

Referenced by AC3_encode_frame(), and ac3_parse_audio_block().

#define AC3_MAX_CODED_FRAME_SIZE   3840

Definition at line 32 of file ac3.h.

Referenced by output_frame_header().

#define EXP_D15   1

Definition at line 42 of file ac3.h.

Referenced by compute_exp_strategy(), and encode_exp().

#define EXP_D25   2

Definition at line 43 of file ac3.h.

Referenced by compute_exp_strategy(), and encode_exp().

#define EXP_D45   3

Definition at line 44 of file ac3.h.

Referenced by compute_exp_strategy(), decode_exponents(), and encode_exp().

#define EXP_NEW   1

Definition at line 40 of file ac3.h.

Referenced by compute_exp_strategy().

#define EXP_REUSE   0

Definition at line 39 of file ac3.h.

Referenced by AC3_encode_frame(), bit_alloc_masking(), and compute_exp_strategy().

#define NB_BLOCKS   6

Definition at line 35 of file ac3.h.

Referenced by AC3_encode_frame(), bit_alloc(), bit_alloc_masking(), compute_bit_allocation(), and compute_exp_strategy().


Enumeration Type Documentation

enum AC3ChannelMode

Channel mode (audio coding mode)

Enumerator:
AC3_CHMODE_DUALMONO 
AC3_CHMODE_MONO 
AC3_CHMODE_STEREO 
AC3_CHMODE_3F 
AC3_CHMODE_2F1R 
AC3_CHMODE_3F1R 
AC3_CHMODE_2F2R 
AC3_CHMODE_3F2R 

Definition at line 55 of file ac3.h.

enum AC3DeltaStrategy

Delta bit allocation strategy

Enumerator:
DBA_REUSE 
DBA_NEW 
DBA_NONE 
DBA_RESERVED 

Definition at line 47 of file ac3.h.

00047              {
00048     DBA_REUSE = 0,
00049     DBA_NEW,
00050     DBA_NONE,
00051     DBA_RESERVED
00052 } AC3DeltaStrategy;

enum EAC3FrameType

Enumerator:
EAC3_FRAME_TYPE_INDEPENDENT 
EAC3_FRAME_TYPE_DEPENDENT 
EAC3_FRAME_TYPE_AC3_CONVERT 
EAC3_FRAME_TYPE_RESERVED 

Definition at line 106 of file ac3.h.


Function Documentation

void ac3_common_init ( void   ) 

Initializes some tables. note: This function must remain thread safe because it is called by the AVParser init code.

Definition at line 228 of file ac3.c.

References band_start_tab, bin_to_band_tab, and ff_ac3_critical_band_size_tab.

Referenced by ac3_decode_init(), and AC3_encode_init().

00229 {
00230     int i, j, k, l, v;
00231     /* compute bndtab and masktab from bandsz */
00232     k = 0;
00233     l = 0;
00234     for(i=0;i<50;i++) {
00235         band_start_tab[i] = l;
00236         v = ff_ac3_critical_band_size_tab[i];
00237         for(j=0;j<v;j++) bin_to_band_tab[k++]=i;
00238         l += v;
00239     }
00240     band_start_tab[50] = l;
00241 }

void ac3_parametric_bit_allocation ( AC3BitAllocParameters s,
uint8_t *  bap,
int8_t *  exp,
int  start,
int  end,
int  snr_offset,
int  fast_gain,
int  is_lfe,
int  dba_mode,
int  dba_nsegs,
uint8_t *  dba_offsets,
uint8_t *  dba_lengths,
uint8_t *  dba_values 
)

Definition at line 202 of file ac3.c.

References ff_ac3_bap_tab, ff_ac3_bit_alloc_calc_bap(), ff_ac3_bit_alloc_calc_mask(), ff_ac3_bit_alloc_calc_psd(), AC3BitAllocParameters::floor, and mask.

00208 {
00209     int16_t psd[256];   /* scaled exponents */
00210     int16_t band_psd[50]; /* interpolated exponents */
00211     int16_t mask[50];   /* masking value */
00212 
00213     ff_ac3_bit_alloc_calc_psd(exp, start, end, psd, band_psd);
00214 
00215     ff_ac3_bit_alloc_calc_mask(s, band_psd, start, end, fast_gain, is_lfe,
00216                                dba_mode, dba_nsegs, dba_offsets, dba_lengths, dba_values,
00217                                mask);
00218 
00219     ff_ac3_bit_alloc_calc_bap(mask, psd, start, end, snr_offset, s->floor,
00220                               ff_ac3_bap_tab, bap);
00221 }

void ff_ac3_bit_alloc_calc_bap ( int16_t *  mask,
int16_t *  psd,
int  start,
int  end,
int  snr_offset,
int  floor,
const uint8_t *  bap_tab,
uint8_t *  bap 
)

Calculates bit allocation pointers. The SNR is the difference between the masking curve and the signal. AC-3 uses this value for each frequency bin to allocate bits. The snroffset parameter is a global adjustment to the SNR for all bins.

Parameters:
[in] mask masking curve
[in] psd signal power for each frequency bin
[in] start starting bin location
[in] end ending bin location
[in] snr_offset SNR adjustment
[in] floor noise floor
[in] bap_tab look-up table for bit allocation pointers
[out] bap bit allocation pointers

Definition at line 175 of file ac3.c.

References av_clip(), band_start_tab, bin_to_band_tab, ff_ac3_critical_band_size_tab, FFMAX, and FFMIN.

Referenced by ac3_parametric_bit_allocation(), and bit_alloc().

00178 {
00179     int i, j, k, end1, v, address;
00180 
00181     /* special case, if snr offset is -960, set all bap's to zero */
00182     if(snr_offset == -960) {
00183         memset(bap, 0, 256);
00184         return;
00185     }
00186 
00187     i = start;
00188     j = bin_to_band_tab[start];
00189     do {
00190         v = (FFMAX(mask[j] - snr_offset - floor, 0) & 0x1FE0) + floor;
00191         end1 = FFMIN(band_start_tab[j] + ff_ac3_critical_band_size_tab[j], end);
00192         for (k = i; k < end1; k++) {
00193             address = av_clip((psd[i] - v) >> 5, 0, 63);
00194             bap[i] = bap_tab[address];
00195             i++;
00196         }
00197     } while (end > band_start_tab[j++]);
00198 }

void ff_ac3_bit_alloc_calc_mask ( AC3BitAllocParameters s,
int16_t *  band_psd,
int  start,
int  end,
int  fast_gain,
int  is_lfe,
int  dba_mode,
int  dba_nsegs,
uint8_t *  dba_offsets,
uint8_t *  dba_lengths,
uint8_t *  dba_values,
int16_t *  mask 
)

Calculates the masking curve. First, the excitation is calculated using parameters in s and the signal power in each critical band. The excitation is compared with a predefined hearing threshold table to produce the masking curve. If delta bit allocation information is provided, it is used for adjusting the masking curve, usually to give a closer match to a better psychoacoustic model.

Parameters:
[in] s adjustable bit allocation parameters
[in] band_psd signal power for each critical band
[in] start starting bin location
[in] end ending bin location
[in] fast_gain fast gain (estimated signal-to-mask ratio)
[in] is_lfe whether or not the channel being processed is the LFE
[in] dba_mode delta bit allocation mode (none, reuse, or new)
[in] dba_nsegs number of delta segments
[in] dba_offsets location offsets for each segment
[in] dba_lengths length of each segment
[in] dba_values delta bit allocation for each segment
[out] mask calculated masking curve

Definition at line 83 of file ac3.c.

References bin_to_band_tab, calc_lowcomp(), calc_lowcomp1(), AC3BitAllocParameters::cpl_fast_leak, AC3BitAllocParameters::cpl_slow_leak, AC3BitAllocParameters::db_per_bit, DBA_NEW, DBA_REUSE, delta, AC3BitAllocParameters::fast_decay, ff_ac3_hearing_threshold_tab, FFMAX, FFMIN, AC3BitAllocParameters::slow_decay, AC3BitAllocParameters::slow_gain, AC3BitAllocParameters::sr_code, and AC3BitAllocParameters::sr_shift.

Referenced by ac3_parametric_bit_allocation(), and bit_alloc_masking().

00088 {
00089     int16_t excite[50]; /* excitation */
00090     int bin, k;
00091     int bndstrt, bndend, begin, end1, tmp;
00092     int lowcomp, fastleak, slowleak;
00093 
00094     /* excitation function */
00095     bndstrt = bin_to_band_tab[start];
00096     bndend = bin_to_band_tab[end-1] + 1;
00097 
00098     if (bndstrt == 0) {
00099         lowcomp = 0;
00100         lowcomp = calc_lowcomp1(lowcomp, band_psd[0], band_psd[1], 384);
00101         excite[0] = band_psd[0] - fast_gain - lowcomp;
00102         lowcomp = calc_lowcomp1(lowcomp, band_psd[1], band_psd[2], 384);
00103         excite[1] = band_psd[1] - fast_gain - lowcomp;
00104         begin = 7;
00105         for (bin = 2; bin < 7; bin++) {
00106             if (!(is_lfe && bin == 6))
00107                 lowcomp = calc_lowcomp1(lowcomp, band_psd[bin], band_psd[bin+1], 384);
00108             fastleak = band_psd[bin] - fast_gain;
00109             slowleak = band_psd[bin] - s->slow_gain;
00110             excite[bin] = fastleak - lowcomp;
00111             if (!(is_lfe && bin == 6)) {
00112                 if (band_psd[bin] <= band_psd[bin+1]) {
00113                     begin = bin + 1;
00114                     break;
00115                 }
00116             }
00117         }
00118 
00119         end1=bndend;
00120         if (end1 > 22) end1=22;
00121 
00122         for (bin = begin; bin < end1; bin++) {
00123             if (!(is_lfe && bin == 6))
00124                 lowcomp = calc_lowcomp(lowcomp, band_psd[bin], band_psd[bin+1], bin);
00125 
00126             fastleak = FFMAX(fastleak - s->fast_decay, band_psd[bin] - fast_gain);
00127             slowleak = FFMAX(slowleak - s->slow_decay, band_psd[bin] - s->slow_gain);
00128             excite[bin] = FFMAX(fastleak - lowcomp, slowleak);
00129         }
00130         begin = 22;
00131     } else {
00132         /* coupling channel */
00133         begin = bndstrt;
00134 
00135         fastleak = (s->cpl_fast_leak << 8) + 768;
00136         slowleak = (s->cpl_slow_leak << 8) + 768;
00137     }
00138 
00139     for (bin = begin; bin < bndend; bin++) {
00140         fastleak = FFMAX(fastleak - s->fast_decay, band_psd[bin] - fast_gain);
00141         slowleak = FFMAX(slowleak - s->slow_decay, band_psd[bin] - s->slow_gain);
00142         excite[bin] = FFMAX(fastleak, slowleak);
00143     }
00144 
00145     /* compute masking curve */
00146 
00147     for (bin = bndstrt; bin < bndend; bin++) {
00148         tmp = s->db_per_bit - band_psd[bin];
00149         if (tmp > 0) {
00150             excite[bin] += tmp >> 2;
00151         }
00152         mask[bin] = FFMAX(ff_ac3_hearing_threshold_tab[bin >> s->sr_shift][s->sr_code], excite[bin]);
00153     }
00154 
00155     /* delta bit allocation */
00156 
00157     if (dba_mode == DBA_REUSE || dba_mode == DBA_NEW) {
00158         int band, seg, delta;
00159         band = 0;
00160         for (seg = 0; seg < FFMIN(8, dba_nsegs); seg++) {
00161             band = FFMIN(49, band + dba_offsets[seg]);
00162             if (dba_values[seg] >= 4) {
00163                 delta = (dba_values[seg] - 3) << 7;
00164             } else {
00165                 delta = (dba_values[seg] - 4) << 7;
00166             }
00167             for (k = 0; k < dba_lengths[seg]; k++) {
00168                 mask[band] += delta;
00169                 band++;
00170             }
00171         }
00172     }
00173 }

void ff_ac3_bit_alloc_calc_psd ( int8_t *  exp,
int  start,
int  end,
int16_t *  psd,
int16_t *  band_psd 
)

Calculates the log power-spectral density of the input signal. This gives a rough estimate of signal power in the frequency domain by using the spectral envelope (exponents). The psd is also separately grouped into critical bands for use in the calculating the masking curve. 128 units in psd = -6 dB. The dbknee parameter in AC3BitAllocParameters determines the reference level.

Parameters:
[in] exp frequency coefficient exponents
[in] start starting bin location
[in] end ending bin location
[out] psd signal power for each frequency bin
[out] band_psd signal power for each critical band

Definition at line 55 of file ac3.c.

References band_start_tab, bin_to_band_tab, ff_ac3_log_add_tab, FFABS, FFMAX, and FFMIN.

Referenced by ac3_parametric_bit_allocation(), and bit_alloc_masking().

00057 {
00058     int bin, i, j, k, end1, v;
00059 
00060     /* exponent mapping to PSD */
00061     for(bin=start;bin<end;bin++) {
00062         psd[bin]=(3072 - (exp[bin] << 7));
00063     }
00064 
00065     /* PSD integration */
00066     j=start;
00067     k=bin_to_band_tab[start];
00068     do {
00069         v=psd[j];
00070         j++;
00071         end1 = FFMIN(band_start_tab[k+1], end);
00072         for(i=j;i<end1;i++) {
00073             /* logadd */
00074             int adr = FFMIN(FFABS(v - psd[j]) >> 1, 255);
00075             v = FFMAX(v, psd[j]) + ff_ac3_log_add_tab[adr];
00076             j++;
00077         }
00078         band_psd[k]=v;
00079         k++;
00080     } while (end > band_start_tab[k]);
00081 }


Generated on Thu Aug 28 16:44:29 2008 for libextractor by  doxygen 1.5.1