예제 #1
0
static void compute_allocation_table(CELTMode *mode, int res)
{
   int i, j, nBark;
   celt_int16_t *allocVectors;
   const int C = CHANNELS(mode);

   /* Find the number of critical bands supported by our sampling rate */
   for (nBark=1;nBark<BARK_BANDS;nBark++)
    if (bark_freq[nBark+1]*2 >= mode->Fs)
       break;

   mode->nbAllocVectors = BITALLOC_SIZE;
   allocVectors = celt_alloc(sizeof(celt_int16_t)*(BITALLOC_SIZE*mode->nbEBands));
   if (allocVectors==NULL)
      return;
   /* Compute per-codec-band allocation from per-critical-band matrix */
   for (i=0;i<BITALLOC_SIZE;i++)
   {
      celt_int32_t current = 0;
      int eband = 0;
      for (j=0;j<nBark;j++)
      {
         int edge, low;
         celt_int32_t alloc;
         edge = mode->eBands[eband+1]*res;
         alloc = band_allocation[i*BARK_BANDS+j];
         alloc = alloc*C*mode->mdctSize;
         if (edge < bark_freq[j+1])
         {
            int num, den;
            num = alloc * (edge-bark_freq[j]);
            den = bark_freq[j+1]-bark_freq[j];
            low = (num+den/2)/den;
            allocVectors[i*mode->nbEBands+eband] = (current+low+128)/256;
            current=0;
            eband++;
            current += alloc-low;
         } else {
            current += alloc;
         }   
      }
      allocVectors[i*mode->nbEBands+eband] = (current+128)/256;
   }
   mode->allocVectors = allocVectors;
}
예제 #2
0
/* Compute the amplitude (sqrt energy) in each of the bands */
void compute_band_energies(const CELTMode *m, const celt_sig *X, celt_ener *bank, int _C)
{
   int i, c, N;
   const celt_int16 *eBands = m->eBands;
   const int C = CHANNELS(_C);
   N = FRAMESIZE(m);
   for (c=0;c<C;c++)
   {
      for (i=0;i<m->nbEBands;i++)
      {
         int j;
         celt_word32 maxval=0;
         celt_word32 sum = 0;
         
         j=eBands[i]; do {
            maxval = MAX32(maxval, X[j+c*N]);
            maxval = MAX32(maxval, -X[j+c*N]);
         } while (++j<eBands[i+1]);
         
         if (maxval > 0)
         {
            int shift = celt_ilog2(maxval)-10;
            j=eBands[i]; do {
               sum = MAC16_16(sum, EXTRACT16(VSHR32(X[j+c*N],shift)),
                                   EXTRACT16(VSHR32(X[j+c*N],shift)));
            } while (++j<eBands[i+1]);
            /* We're adding one here to make damn sure we never end up with a pitch vector that's
               larger than unity norm */
            bank[i+c*m->nbEBands] = EPSILON+VSHR32(EXTEND32(celt_sqrt(sum)),-shift);
         } else {
            bank[i+c*m->nbEBands] = EPSILON;
         }
         /*printf ("%f ", bank[i+c*m->nbEBands]);*/
      }
   }
   /*printf ("\n");*/
}
예제 #3
0
static void compute_allocation_table(CELTMode *mode, int res)
{
   int i, j, eband, nBark;
   celt_int32_t *allocVectors;
   celt_int16_t *allocVectorsS;
   celt_int16_t *allocEnergy;
   const int C = CHANNELS(mode);

   /* Find the number of critical bands supported by our sampling rate */
   for (nBark=1;nBark<BARK_BANDS;nBark++)
    if (bark_freq[nBark+1]*2 >= mode->Fs)
       break;

   mode->nbAllocVectors = BITALLOC_SIZE;
   allocVectors = celt_alloc(sizeof(celt_int32_t)*(BITALLOC_SIZE*mode->nbEBands));
   allocEnergy = celt_alloc(sizeof(celt_int16_t)*(mode->nbAllocVectors*(mode->nbEBands+1)));
   /* Compute per-codec-band allocation from per-critical-band matrix */
   for (i=0;i<BITALLOC_SIZE;i++)
   {
      eband = 0;
      for (j=0;j<nBark;j++)
      {
         int edge, low;
         celt_int32_t alloc;
         edge = mode->eBands[eband+1]*res;
         alloc = band_allocation[i*BARK_BANDS+j];
         alloc = alloc*C*mode->mdctSize/256;
         if (edge < bark_freq[j+1])
         {
            int num, den;
            num = alloc * (edge-bark_freq[j]);
            den = bark_freq[j+1]-bark_freq[j];
            low = (num+den/2)/den;
            allocVectors[i*mode->nbEBands+eband] += low;
            eband++;
            allocVectors[i*mode->nbEBands+eband] += alloc-low;
         } else {
            allocVectors[i*mode->nbEBands+eband] += alloc;
         }
      }
   }
   /* Compute fine energy resolution and update the pulse allocation table to subtract that */
   for (i=0;i<mode->nbAllocVectors;i++)
   {
      int sum = 0;
      for (j=0;j<mode->nbEBands;j++)
      {
         int ebits;
         int min_bits=0;
         if (allocVectors[i*mode->nbEBands+j] > 0)
            min_bits = 1;
         ebits = IMAX(min_bits , allocVectors[i*mode->nbEBands+j] / (C*(mode->eBands[j+1]-mode->eBands[j])));
         if (ebits>7)
            ebits=7;
         /* The bits used for fine allocation can't be used for pulses */
         /* However, we give two "free" bits to all modes to compensate for the fact that some energy
            resolution is needed regardless of the frame size. */
         if (ebits>1)
            allocVectors[i*mode->nbEBands+j] -= C*(ebits-2);
         if (allocVectors[i*mode->nbEBands+j] < 0)
            allocVectors[i*mode->nbEBands+j] = 0;
         sum += ebits;
         allocEnergy[i*(mode->nbEBands+1)+j] = ebits;
      }
      allocEnergy[i*(mode->nbEBands+1)+mode->nbEBands] = sum;
   }
   mode->energy_alloc = allocEnergy;
   allocVectorsS = celt_alloc(sizeof(celt_int16_t)*(BITALLOC_SIZE*mode->nbEBands));
   for(i=0;i<(BITALLOC_SIZE*mode->nbEBands);i++)
     allocVectorsS[i] = (celt_int16_t)allocVectors[i];
   mode->allocVectors = allocVectorsS;
}
예제 #4
0
            } else {
               best_num[1] = num;
               best_den[1] = Syy;
               best_pitch[1] = i;
            }
         }
      }
      Syy += SHR32(MULT16_16(y[i+len],y[i+len]),yshift) - SHR32(MULT16_16(y[i],y[i]),yshift);
      Syy = MAX32(1, Syy);
   }
}

void pitch_downsample(const celt_sig * restrict x, celt_word16 * restrict x_lp, int len, int end, int _C, celt_sig * restrict xmem, celt_word16 * restrict filt_mem)
{
   int i;
   const int C = CHANNELS(_C);
   for (i=1;i<len>>1;i++)
      x_lp[i] = SHR32(HALF32(HALF32(x[(2*i-1)*C]+x[(2*i+1)*C])+x[2*i*C]), SIG_SHIFT);
   x_lp[0] = SHR32(HALF32(HALF32(*xmem+x[C])+x[0]), SIG_SHIFT);
   *xmem = x[end-C];
   if (C==2)
   {
      for (i=1;i<len>>1;i++)
      x_lp[i] = SHR32(HALF32(HALF32(x[(2*i-1)*C+1]+x[(2*i+1)*C+1])+x[2*i*C+1]), SIG_SHIFT);
      x_lp[0] += SHR32(HALF32(HALF32(x[C+1])+x[1]), SIG_SHIFT);
      *xmem += x[end-C+1];
   }

#if 0
   {
      int j;
예제 #5
0
파일: celt.c 프로젝트: tzhuan/llcon
   if (ratio > 2048)
      *transient_shift = 3;
   else
      *transient_shift = 0;
   
   *transient_time = n;
   
   RESTORE_STACK;
   return ratio > 20;
}

/** Apply window and compute the MDCT for all sub-frames and 
    all channels in a frame */
static void compute_mdcts(const CELTMode *mode, int shortBlocks, celt_sig_t * __restrict in, celt_sig_t * __restrict out)
{
   const int C = CHANNELS(mode);
   if (C==1 && !shortBlocks)
   {
      const mdct_lookup *lookup = MDCT(mode);
      const int overlap = OVERLAP(mode);
      mdct_forward(lookup, in, out, mode->window, overlap);
   } else if (!shortBlocks) {
      const mdct_lookup *lookup = MDCT(mode);
      const int overlap = OVERLAP(mode);
      const int N = FRAMESIZE(mode);
      int c;
      VARDECL(celt_word32_t, x);
      VARDECL(celt_word32_t, tmp);
      SAVE_STACK;
      ALLOC(x, N+overlap, celt_word32_t);
      ALLOC(tmp, N, celt_word32_t);
예제 #6
0
파일: bands.c 프로젝트: tzhuan/llcon
            bank[i+c*m->nbEBands] = EPSILON+VSHR32(EXTEND32(celt_sqrt(sum)),-shift);
         } else {
            bank[i+c*m->nbEBands] = EPSILON;
         }
         /*printf ("%f ", bank[i+c*m->nbEBands]);*/
      }
   }
   /*printf ("\n");*/
}

/* Normalise each band such that the energy is one. */
void normalise_bands(const CELTMode *m, const celt_sig_t * __restrict freq, celt_norm_t * __restrict X, const celt_ener_t *bank)
{
   int i, c, N;
   const celt_int16_t *eBands = m->eBands;
   const int C = CHANNELS(m);
   N = FRAMESIZE(m);
   for (c=0;c<C;c++)
   {
      i=0; do {
         celt_word16_t g;
         int j,shift;
         celt_word16_t E;
         shift = celt_zlog2(bank[i+c*m->nbEBands])-13;
         E = VSHR32(bank[i+c*m->nbEBands], shift);
         g = EXTRACT16(celt_rcp(SHL32(E,3)));
         j=eBands[i]; do {
            X[j*C+c] = MULT16_16_Q15(VSHR32(freq[j+c*N],shift-1),g);
         } while (++j<eBands[i+1]);
      } while (++i<m->nbEBands);
   }
예제 #7
0
파일: avprofile.c 프로젝트: dmonakhov/ortp
#define NORMAL_BITRATE(val)	(val)
#define MIME_TYPE(val)		(val)
#define CHANNELS(val)		(val)
#define FMTP(val)		(val)

#endif

PayloadType payload_type_pcmu8000= {
    TYPE( PAYLOAD_AUDIO_CONTINUOUS),
    CLOCK_RATE( 8000),
    BITS_PER_SAMPLE(8),
    ZERO_PATTERN( &offset127),
    PATTERN_LENGTH( 1),
    NORMAL_BITRATE( 64000),
    MIME_TYPE ("PCMU"),
    CHANNELS(1)
};

PayloadType payload_type_pcma8000= {
    TYPE( PAYLOAD_AUDIO_CONTINUOUS),
    CLOCK_RATE(8000),
    BITS_PER_SAMPLE(8),
    ZERO_PATTERN( &offset0xD5),
    PATTERN_LENGTH( 1),
    NORMAL_BITRATE( 64000),
    MIME_TYPE ("PCMA"),
    CHANNELS(1)
};

PayloadType payload_type_pcm8000= {
    TYPE( PAYLOAD_AUDIO_CONTINUOUS),
예제 #8
0
#define SEND_FMTP(val)		(val)
#define NO_AVPF		{PAYLOAD_TYPE_AVPF_NONE, 0}
#define AVPF(feat, intv)		{(feat), (intv)}
#define FLAGS(val)		(val)

#endif

PayloadType payload_type_pcmu8000={
	TYPE(PAYLOAD_AUDIO_CONTINUOUS),
	CLOCK_RATE(8000),
	BITS_PER_SAMPLE(8),
	ZERO_PATTERN( &offset127),
	PATTERN_LENGTH(1),
	NORMAL_BITRATE(64000),
	MIME_TYPE("PCMU"),
	CHANNELS(1),
	RECV_FMTP(NULL),
	SEND_FMTP(NULL),
	NO_AVPF,
	FLAGS(0)
};

PayloadType payload_type_pcma8000={
	TYPE(PAYLOAD_AUDIO_CONTINUOUS),
	CLOCK_RATE(8000),
	BITS_PER_SAMPLE(8),
	ZERO_PATTERN(&offset0xD5),
	PATTERN_LENGTH(1),
	NORMAL_BITRATE(64000),
	MIME_TYPE("PCMA"),
	CHANNELS(1),