Got stereo support to work in CELT-only mode
authorJean-Marc Valin <jean-marc.valin@octasic.com>
Mon, 31 Jan 2011 17:41:49 +0000 (12:41 -0500)
committerJean-Marc Valin <jean-marc.valin@octasic.com>
Mon, 31 Jan 2011 17:41:49 +0000 (12:41 -0500)
src/opus_decoder.c
src/opus_decoder.h
src/opus_encoder.c
src/opus_encoder.h

index 242fed0..72f76a3 100644 (file)
@@ -58,7 +58,7 @@ OpusDecoder *opus_decoder_create(int Fs, int channels)
     st = (OpusDecoder*)raw_state;
     st->silk_dec = (void*)(raw_state+sizeof(OpusDecoder));
     st->celt_dec = (CELTDecoder*)(raw_state+sizeof(OpusDecoder)+silkDecSizeBytes);
-    st->channels = channels;
+    st->stream_channels = st->channels = channels;
 
     st->Fs = Fs;
 
@@ -111,6 +111,7 @@ int opus_decode(OpusDecoder *st, const unsigned char *data,
             else
                 audiosize = (st->Fs<<audiosize)/100;
         }
+        st->stream_channels = (data[0]&0x4) ? 2 : 1;
         /*printf ("%d %d %d\n", st->mode, st->bandwidth, audiosize);*/
 
         len -= 1;
@@ -180,6 +181,7 @@ int opus_decode(OpusDecoder *st, const unsigned char *data,
                break;
            }
            celt_decoder_ctl(st->celt_dec, CELT_SET_END_BAND(endband));
+           celt_decoder_ctl(st->celt_dec, CELT_SET_CHANNELS(st->stream_channels));
 
         /* Encode high band with CELT */
         celt_ret = celt_decode_with_ec(st->celt_dec, data, len, pcm_celt, frame_size, &dec);
index f4f012a..3a39c87 100644 (file)
@@ -39,6 +39,7 @@ struct OpusDecoder {
        CELTDecoder *celt_dec;
        void        *silk_dec;
        int          channels;
+       int          stream_channels;
 
     int          mode;
     int          bandwidth;
index fa507d0..0cfc30d 100644 (file)
@@ -58,7 +58,7 @@ OpusEncoder *opus_encoder_create(int Fs, int channels)
     st = (OpusEncoder*)raw_state;
     st->silk_enc = (void*)(raw_state+sizeof(OpusEncoder));
     st->celt_enc = (CELTEncoder*)(raw_state+sizeof(OpusEncoder)+silkEncSizeBytes);
-    st->channels = channels;
+    st->stream_channels = st->channels = channels;
 
     st->Fs = Fs;
 
@@ -168,6 +168,7 @@ int opus_encode(OpusEncoder *st, const short *pcm, int frame_size,
                break;
            }
            celt_encoder_ctl(st->celt_enc, CELT_SET_END_BAND(endband));
+           celt_encoder_ctl(st->celt_enc, CELT_SET_CHANNELS(st->stream_channels));
 
            for (i=0;i<ENCODER_DELAY_COMPENSATION*st->channels;i++)
                pcm_buf[i] = st->delay_buffer[i];
@@ -178,7 +179,9 @@ int opus_encode(OpusEncoder *st, const short *pcm, int frame_size,
 
         if (st->vbr_rate != 0)
         {
-            int tmp = (st->vbr_rate-6000)/2;
+            int tmp;
+
+            tmp = (st->mode == MODE_HYBRID) ? (st->vbr_rate-6000)/2 : st->vbr_rate;
             tmp = ((ec_enc_tell(&enc, 0)+4)>>3) + tmp * frame_size/(8*st->Fs);
             if (tmp <= bytes_per_packet)
                 bytes_per_packet = tmp;
@@ -219,6 +222,7 @@ int opus_encode(OpusEncoder *st, const short *pcm, int frame_size,
         data[0] |= (st->bandwidth-BANDWIDTH_SUPERWIDEBAND)<<4;
         data[0] |= (period-2)<<3;
     }
+    data[0] |= (st->stream_channels==2)<<2;
     /*printf ("%x\n", (int)data[0]);*/
 
     return ret+1;
index 1f061db..1b0271e 100644 (file)
@@ -43,6 +43,7 @@ struct OpusEncoder {
        CELTEncoder *celt_enc;
        void        *silk_enc;
        int          channels;
+       int          stream_channels;
 
     int          mode;
        int          bandwidth;