Merge remote-tracking branch 'greg/master'
authorJean-Marc Valin <jmvalin@jmvalin.ca>
Mon, 3 Oct 2011 04:51:32 +0000 (00:51 -0400)
committerJean-Marc Valin <jmvalin@jmvalin.ca>
Mon, 3 Oct 2011 04:51:32 +0000 (00:51 -0400)
Conflicts:
src/opus_encoder.c

1  2 
src/opus_encoder.c

@@@ -76,7 -76,7 +76,8 @@@ struct OpusEncoder 
      opus_val32   hp_mem[4];
      int          mode;
      int          prev_mode;
 +    int          prev_channels;
+     int          prev_framesize;
      int          bandwidth;
      /* Sampling rate (at the API level) */
      int          first;
@@@ -329,38 -326,17 +327,46 @@@ static void hp_cutoff(const opus_val16 
  #endif
  }
  
- OpusEncoder *opus_encoder_create(opus_int32 Fs, int channels, int mode, int *error)
 +static void stereo_fade(const opus_val16 *in, opus_val16 *out, opus_val16 g1, opus_val16 g2,
 +        int overlap, int frame_size, int channels, const opus_val16 *window, opus_int32 Fs)
 +{
 +    int i;
 +    int inc = 48000/Fs;
 +    g1 = Q15ONE-g1;
 +    g2 = Q15ONE-g2;
 +    for (i=0;i<overlap;i++)
 +    {
 +       opus_val32 diff;
 +       opus_val16 g, w;
 +       w = MULT16_16_Q15(window[i*inc], window[i*inc]);
 +       g = SHR32(MAC16_16(MULT16_16(w,g2),
 +             Q15ONE-w, g1), 15);
 +       diff = EXTRACT16(HALF32((opus_val32)in[i*channels] - (opus_val32)in[i*channels+1]));
 +       diff = MULT16_16_Q15(g, diff);
 +       out[i*channels] = out[i*channels] - diff;
 +       out[i*channels+1] = out[i*channels+1] + diff;
 +    }
 +    for (;i<frame_size;i++)
 +    {
 +       opus_val32 diff;
 +       diff = EXTRACT16(HALF32((opus_val32)in[i*channels] - (opus_val32)in[i*channels+1]));
 +       diff = MULT16_16_Q15(g2, diff);
 +       out[i*channels] = out[i*channels] - diff;
 +       out[i*channels+1] = out[i*channels+1] + diff;
 +    }
 +}
 +
+ OpusEncoder *opus_encoder_create(opus_int32 Fs, int channels, int application, int *error)
  {
     int ret;
+    if((Fs!=48000&&Fs!=24000&&Fs!=16000&&Fs!=12000&&Fs!=8000)||(channels!=1&&channels!=2)||
+        (application != OPUS_APPLICATION_VOIP && application != OPUS_APPLICATION_AUDIO
+        && application != OPUS_APPLICATION_RESTRICTED_LOWDELAY))
+    {
+       if (error)
+          *error = OPUS_BAD_ARG;
+       return NULL;
+    }
     OpusEncoder *st = (OpusEncoder *)opus_alloc(opus_encoder_get_size(channels));
     if (st == NULL)
     {
@@@ -987,8 -957,7 +1000,9 @@@ int opus_encode_float(OpusEncoder *st, 
          st->prev_mode = MODE_CELT_ONLY;
      else
          st->prev_mode = st->mode;
 +    st->prev_channels = st->stream_channels;
+     st->prev_framesize = frame_size;
 +
      st->first = 0;
      RESTORE_STACK;
      return ret+1+redundancy_bytes;