More stereo work
authorJean-Marc Valin <jean-marc.valin@octasic.com>
Mon, 31 Jan 2011 16:53:28 +0000 (11:53 -0500)
committerJean-Marc Valin <jean-marc.valin@octasic.com>
Mon, 31 Jan 2011 16:53:28 +0000 (11:53 -0500)
src/opus_decoder.c
src/opus_decoder.h
src/opus_encoder.c
src/opus_encoder.h

index 52d044a..242fed0 100644 (file)
@@ -53,11 +53,12 @@ OpusDecoder *opus_decoder_create(int Fs, int channels)
     if( ret ) {
         /* Handle error */
     }
     if( ret ) {
         /* Handle error */
     }
-    celtDecSizeBytes = celt_decoder_get_size(1);
+    celtDecSizeBytes = celt_decoder_get_size(channels);
     raw_state = calloc(sizeof(OpusDecoder)+silkDecSizeBytes+celtDecSizeBytes, 1);
     st = (OpusDecoder*)raw_state;
     st->silk_dec = (void*)(raw_state+sizeof(OpusDecoder));
     st->celt_dec = (CELTDecoder*)(raw_state+sizeof(OpusDecoder)+silkDecSizeBytes);
     raw_state = calloc(sizeof(OpusDecoder)+silkDecSizeBytes+celtDecSizeBytes, 1);
     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->Fs = Fs;
 
 
     st->Fs = Fs;
 
@@ -81,7 +82,7 @@ int opus_decode(OpusDecoder *st, const unsigned char *data,
        ec_byte_buffer buf;
     SKP_SILK_SDK_DecControlStruct DecControl;
     SKP_int32 silk_frame_size;
        ec_byte_buffer buf;
     SKP_SILK_SDK_DecControlStruct DecControl;
     SKP_int32 silk_frame_size;
-    short pcm_celt[960];
+    short pcm_celt[960*2];
     int audiosize;
 
     if (data != NULL)
     int audiosize;
 
     if (data != NULL)
@@ -147,7 +148,7 @@ int opus_decode(OpusDecoder *st, const unsigned char *data,
             /* Handle error */
         }
     } else {
             /* Handle error */
         }
     } else {
-        for (i=0;i<frame_size;i++)
+        for (i=0;i<frame_size*st->channels;i++)
             pcm[i] = 0;
     }
 
             pcm[i] = 0;
     }
 
@@ -182,7 +183,7 @@ int opus_decode(OpusDecoder *st, const unsigned char *data,
 
         /* Encode high band with CELT */
         celt_ret = celt_decode_with_ec(st->celt_dec, data, len, pcm_celt, frame_size, &dec);
 
         /* Encode high band with CELT */
         celt_ret = celt_decode_with_ec(st->celt_dec, data, len, pcm_celt, frame_size, &dec);
-        for (i=0;i<frame_size;i++)
+        for (i=0;i<frame_size*st->channels;i++)
             pcm[i] += pcm_celt[i];
     }
        return celt_ret;
             pcm[i] += pcm_celt[i];
     }
        return celt_ret;
index c7a3be6..f4f012a 100644 (file)
@@ -38,6 +38,7 @@
 struct OpusDecoder {
        CELTDecoder *celt_dec;
        void        *silk_dec;
 struct OpusDecoder {
        CELTDecoder *celt_dec;
        void        *silk_dec;
+       int          channels;
 
     int          mode;
     int          bandwidth;
 
     int          mode;
     int          bandwidth;
index 54a5c3d..fa507d0 100644 (file)
@@ -53,11 +53,12 @@ OpusEncoder *opus_encoder_create(int Fs, int channels)
     if( ret ) {
        /* Handle error */
     }
     if( ret ) {
        /* Handle error */
     }
-    celtEncSizeBytes = celt_encoder_get_size(1);
+    celtEncSizeBytes = celt_encoder_get_size(channels);
     raw_state = calloc(sizeof(OpusEncoder)+silkEncSizeBytes+celtEncSizeBytes, 1);
     st = (OpusEncoder*)raw_state;
     st->silk_enc = (void*)(raw_state+sizeof(OpusEncoder));
     st->celt_enc = (CELTEncoder*)(raw_state+sizeof(OpusEncoder)+silkEncSizeBytes);
     raw_state = calloc(sizeof(OpusEncoder)+silkEncSizeBytes+celtEncSizeBytes, 1);
     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->Fs = Fs;
 
 
     st->Fs = Fs;
 
@@ -149,7 +150,7 @@ int opus_encode(OpusEncoder *st, const short *pcm, int frame_size,
        if (st->mode != MODE_SILK_ONLY && st->bandwidth > BANDWIDTH_WIDEBAND)
        {
                int endband;
        if (st->mode != MODE_SILK_ONLY && st->bandwidth > BANDWIDTH_WIDEBAND)
        {
                int endband;
-           short pcm_buf[960];
+           short pcm_buf[960*2];
 
            switch(st->bandwidth)
            {
 
            switch(st->bandwidth)
            {
@@ -168,10 +169,10 @@ int opus_encode(OpusEncoder *st, const short *pcm, int frame_size,
            }
            celt_encoder_ctl(st->celt_enc, CELT_SET_END_BAND(endband));
 
            }
            celt_encoder_ctl(st->celt_enc, CELT_SET_END_BAND(endband));
 
-           for (i=0;i<ENCODER_DELAY_COMPENSATION;i++)
+           for (i=0;i<ENCODER_DELAY_COMPENSATION*st->channels;i++)
                pcm_buf[i] = st->delay_buffer[i];
                pcm_buf[i] = st->delay_buffer[i];
-        for (;i<frame_size;i++)
-            pcm_buf[i] = pcm[i-ENCODER_DELAY_COMPENSATION];
+        for (;i<frame_size*st->channels;i++)
+            pcm_buf[i] = pcm[i-ENCODER_DELAY_COMPENSATION*st->channels];
 
         celt_encoder_ctl(st->celt_enc, CELT_SET_PREDICTION(1));
 
 
         celt_encoder_ctl(st->celt_enc, CELT_SET_PREDICTION(1));
 
@@ -185,8 +186,8 @@ int opus_encode(OpusEncoder *st, const short *pcm, int frame_size,
         }
            /* Encode high band with CELT */
            ret = celt_encode_with_ec(st->celt_enc, pcm_buf, frame_size, NULL, bytes_per_packet, &enc);
         }
            /* Encode high band with CELT */
            ret = celt_encode_with_ec(st->celt_enc, pcm_buf, frame_size, NULL, bytes_per_packet, &enc);
-           for (i=0;i<ENCODER_DELAY_COMPENSATION;i++)
-               st->delay_buffer[i] = pcm[frame_size-ENCODER_DELAY_COMPENSATION+i];
+           for (i=0;i<ENCODER_DELAY_COMPENSATION*st->channels;i++)
+               st->delay_buffer[i] = pcm[frame_size*st->channels-ENCODER_DELAY_COMPENSATION*st->channels+i];
        } else {
            ec_enc_done(&enc);
        }
        } else {
            ec_enc_done(&enc);
        }
index 37d4370..1f061db 100644 (file)
@@ -42,6 +42,7 @@
 struct OpusEncoder {
        CELTEncoder *celt_enc;
        void        *silk_enc;
 struct OpusEncoder {
        CELTEncoder *celt_enc;
        void        *silk_enc;
+       int          channels;
 
     int          mode;
        int          bandwidth;
 
     int          mode;
        int          bandwidth;