ref: 10a34a5dd66ff45538ac3843eab7802d260e160f
parent: bb43b8b69d3e06ec2609a6040513952cb472d742
author: Jean-Marc Valin <[email protected]>
date: Wed Dec 19 19:23:01 EST 2012
Making multistream variable duration work for both the float and int API
--- a/src/opus_encoder.c
+++ b/src/opus_encoder.c
@@ -665,11 +665,36 @@
return best_state;
}
+void downmix_float(const void *_x, float *sub, int subframe, int i, int C)
+{
+ const float *x;
+ int c, j;
+ x = (const float *)_x;
+ for (j=0;j<subframe;j++)
+ sub[j] = x[(subframe*i+j)*C];
+ for (c=1;c<C;c++)
+ for (j=0;j<subframe;j++)
+ sub[j] += x[(subframe*i+j)*C+c];
+}
+
+void downmix_int(const void *_x, float *sub, int subframe, int i, int C)
+{
+ const opus_int16 *x;
+ int c, j;
+ x = (const opus_int16 *)_x;
+ for (j=0;j<subframe;j++)
+ sub[j] = x[(subframe*i+j)*C];
+ for (c=1;c<C;c++)
+ for (j=0;j<subframe;j++)
+ sub[j] += x[(subframe*i+j)*C+c];
+}
+
int optimize_framesize(const opus_val16 *x, int len, int C, opus_int32 Fs,
- int bitrate, opus_val16 tonality, opus_val32 *mem, int buffering)
+ int bitrate, opus_val16 tonality, opus_val32 *mem, int buffering,
+ downmix_func downmix)
{
int N;
- int i, c;
+ int i;
float e[MAX_DYNAMIC_FRAMESIZE+4];
float e_1[MAX_DYNAMIC_FRAMESIZE+3];
float memx;
@@ -700,8 +725,6 @@
}
N=IMIN(len/subframe, MAX_DYNAMIC_FRAMESIZE);
memx = x[0];
- for (c=1;c<C;c++)
- memx += x[c];
for (i=0;i<N;i++)
{
float tmp;
@@ -709,13 +732,10 @@
int j;
tmp=EPSILON;
+ downmix(x, sub, subframe, i, C);
+ if (i==0)
+ memx = sub[0];
for (j=0;j<subframe;j++)
- sub[j] = x[(subframe*i+j)*C];
- for (c=1;c<C;c++)
- for (j=0;j<subframe;j++)
- sub[j] += x[(subframe*i+j)*C+c];
-
- for (j=0;j<subframe;j++)
{
tmpx = sub[j];
tmp += (tmpx-memx)*(tmpx-memx);
@@ -806,7 +826,7 @@
int LM = 3;
#ifndef FIXED_POINT
LM = optimize_framesize(pcm, frame_size, st->channels, st->Fs, st->bitrate_bps,
- st->analysis.prev_tonality, st->subframe_mem, delay_compensation);
+ st->analysis.prev_tonality, st->subframe_mem, delay_compensation, downmix_float);
#endif
while ((st->Fs/400<<LM)>frame_size)
LM--;
@@ -1167,6 +1187,7 @@
RESTORE_STACK;
return ret;
}
+#ifndef FIXED_POINT
/* Perform analysis for 40-60 ms frames */
if (perform_analysis && frame_size > st->Fs/50)
{
@@ -1175,7 +1196,7 @@
tonality_analysis(&st->analysis, &analysis_info, celt_enc, pcm+i*(st->Fs/100)*st->channels, 480, st->channels, lsb_depth);
st->voice_ratio = (int)floor(.5+100*(1-analysis_info.music_prob));
}
-
+#endif
curr_bandwidth = st->bandwidth;
/* Chooses the appropriate mode for speech
--- a/src/opus_multistream_encoder.c
+++ b/src/opus_multistream_encoder.c
@@ -185,6 +185,9 @@
unsigned char *data,
opus_int32 max_data_bytes,
int lsb_depth
+#ifndef FIXED_POINT
+ , downmix_func downmix
+#endif
)
{
opus_int32 Fs;
@@ -221,7 +224,7 @@
delay_compensation -= Fs/400;
#ifndef FIXED_POINT
LM = optimize_framesize(pcm, frame_size, channels, Fs, st->bitrate_bps,
- 0.f, st->subframe_mem, delay_compensation);
+ 0.f, st->subframe_mem, delay_compensation, downmix);
#endif
while ((Fs/400<<LM)>frame_size)
LM--;
@@ -410,7 +413,7 @@
)
{
return opus_multistream_encode_native(st, opus_copy_channel_in_float,
- pcm, frame_size, data, max_data_bytes, 24);
+ pcm, frame_size, data, max_data_bytes, 24, downmix_float);
}
int opus_multistream_encode(
@@ -422,7 +425,7 @@
)
{
return opus_multistream_encode_native(st, opus_copy_channel_in_short,
- pcm, frame_size, data, max_data_bytes, 16);
+ pcm, frame_size, data, max_data_bytes, 16, downmix_int);
}
#endif
--- a/src/opus_private.h
+++ b/src/opus_private.h
@@ -81,8 +81,13 @@
#define OPUS_SET_FORCE_MODE_REQUEST 11002
#define OPUS_SET_FORCE_MODE(x) OPUS_SET_FORCE_MODE_REQUEST, __opus_check_int(x)
+typedef void (*downmix_func)(const void *, float *, int, int, int);
+void downmix_float(const void *_x, float *sub, int subframe, int i, int C);
+void downmix_int(const void *_x, float *sub, int subframe, int i, int C);
+
int optimize_framesize(const opus_val16 *x, int len, int C, opus_int32 Fs,
- int bitrate, opus_val16 tonality, opus_val32 *mem, int buffering);
+ int bitrate, opus_val16 tonality, opus_val32 *mem, int buffering,
+ void (*downmix)(const void *, float *, int, int, int));
int encode_size(int size, unsigned char *data);