summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Marc Valin <jmvalin@jmvalin.ca>2015-12-06 10:50:15 -0500
committerJean-Marc Valin <jmvalin@jmvalin.ca>2015-12-23 16:18:01 -0500
commit95320afb8af84103be19c97ca26c32b679e6bcff (patch)
treed497766f3989d534241e367f37c2554fd3dc3ab1
parentb92e148143c0a08488ed89496665900b8c7f976f (diff)
downloadopus-95320afb8af84103be19c97ca26c32b679e6bcff.tar.gz
Work in progress -- doesn't work
-rw-r--r--celt/celt_encoder.c31
-rw-r--r--celt/quant_bands.c2
-rw-r--r--src/opus_encoder.c9
3 files changed, 33 insertions, 9 deletions
diff --git a/celt/celt_encoder.c b/celt/celt_encoder.c
index e33b9906..5b0e1dba 100644
--- a/celt/celt_encoder.c
+++ b/celt/celt_encoder.c
@@ -1345,6 +1345,7 @@ int celt_encode_with_ec(CELTEncoder * OPUS_RESTRICT st, const opus_val16 * pcm,
opus_int32 total_boost;
opus_int32 balance;
opus_int32 tell;
+ opus_int32 tell0;
int prefilter_tapset=0;
int pf_on;
int anti_collapse_rsv;
@@ -1402,10 +1403,10 @@ int celt_encode_with_ec(CELTEncoder * OPUS_RESTRICT st, const opus_val16 * pcm,
if (enc==NULL)
{
- tell=1;
+ tell0=tell=1;
nbFilledBytes=0;
} else {
- tell=ec_tell(enc);
+ tell0=tell=ec_tell(enc);
nbFilledBytes=(tell+4)>>3;
}
@@ -1543,7 +1544,7 @@ int celt_encode_with_ec(CELTEncoder * OPUS_RESTRICT st, const opus_val16 * pcm,
} while (++c<CC);
-
+ printf("%d ", ec_tell_frac(enc));
/* Find pitch period and gain */
{
int enabled;
@@ -1774,13 +1775,16 @@ int celt_encode_with_ec(CELTEncoder * OPUS_RESTRICT st, const opus_val16 * pcm,
tf_select=0;
}
+ printf("%d ", ec_tell_frac(enc));
ALLOC(error, C*nbEBands, opus_val16);
quant_coarse_energy(mode, start, end, effEnd, bandLogE,
oldBandE, total_bits, error, enc,
C, LM, nbAvailableBytes, st->force_intra,
&st->delayedIntra, st->complexity >= 4, st->loss_rate, st->lfe);
+ printf("%d ", ec_tell_frac(enc));
tf_encode(start, end, isTransient, tf_res, LM, tf_select, enc);
+ printf("%d ", ec_tell_frac(enc));
if (ec_tell(enc)+4<=total_bits)
{
@@ -1821,6 +1825,7 @@ int celt_encode_with_ec(CELTEncoder * OPUS_RESTRICT st, const opus_val16 * pcm,
}
ALLOC(offsets, nbEBands, int);
+ printf("%d ", ec_tell_frac(enc));
maxDepth = dynalloc_analysis(bandLogE, bandLogE2, nbEBands, start, end, C, offsets,
st->lsb_depth, mode->logN, isTransient, st->vbr, st->constrained_vbr,
@@ -1882,6 +1887,7 @@ int celt_encode_with_ec(CELTEncoder * OPUS_RESTRICT st, const opus_val16 * pcm,
intensity_thresholds, intensity_histeresis, 21, st->intensity);
st->intensity = IMIN(end,IMAX(start, st->intensity));
}
+ printf("%d ", ec_tell_frac(enc));
alloc_trim = 5;
if (tell+(6<<BITRES) <= total_bits - total_boost)
@@ -1899,6 +1905,7 @@ int celt_encode_with_ec(CELTEncoder * OPUS_RESTRICT st, const opus_val16 * pcm,
tell = ec_tell_frac(enc);
}
+ printf("%d ", ec_tell_frac(enc));
/* Variable bitrate */
if (vbr_rate>0)
{
@@ -1912,17 +1919,26 @@ int celt_encode_with_ec(CELTEncoder * OPUS_RESTRICT st, const opus_val16 * pcm,
/* Don't attempt to use more than 510 kb/s, even for frames smaller than 20 ms.
The CELT allocator will just not be able to use more than that anyway. */
nbCompressedBytes = IMIN(nbCompressedBytes,1275>>(3-LM));
- base_target = vbr_rate - ((40*C+20)<<BITRES);
+ if (start == 0)
+ {
+ base_target = vbr_rate - ((40*C+20)<<BITRES);
+ } else {
+ base_target = vbr_rate - (tell0<<BITRES) - ((10*C+5)<<BITRES);
+ }
if (st->constrained_vbr)
base_target += (st->vbr_offset>>lm_diff);
- target = compute_vbr(mode, &st->analysis, base_target, LM, equiv_rate,
+ if (start == 0)
+ {
+ target = compute_vbr(mode, &st->analysis, base_target, LM, equiv_rate,
st->lastCodedBands, C, st->intensity, st->constrained_vbr,
st->stereo_saving, tot_boost, tf_estimate, pitch_change, maxDepth,
st->variable_duration, st->lfe, st->energy_mask!=NULL, surround_masking,
temporal_vbr);
-
+ } else {
+ target = base_target;
+ }
/* The current offset is removed from the target and the space used
so far is added*/
target=target+tell;
@@ -2024,7 +2040,9 @@ int celt_encode_with_ec(CELTEncoder * OPUS_RESTRICT st, const opus_val16 * pcm,
else
st->lastCodedBands = codedBands;
+ printf("%d ", ec_tell_frac(enc));
quant_fine_energy(mode, start, end, oldBandE, error, fine_quant, enc, C);
+ printf("%d ", ec_tell_frac(enc));
/* Residual quantisation */
ALLOC(collapse_masks, C*nbEBands, unsigned char);
@@ -2032,6 +2050,7 @@ int celt_encode_with_ec(CELTEncoder * OPUS_RESTRICT st, const opus_val16 * pcm,
bandE, pulses, shortBlocks, st->spread_decision,
dual_stereo, st->intensity, tf_res, nbCompressedBytes*(8<<BITRES)-anti_collapse_rsv,
balance, enc, LM, codedBands, &st->rng, st->arch);
+ printf("%d\n", ec_tell_frac(enc));
if (anti_collapse_rsv > 0)
{
diff --git a/celt/quant_bands.c b/celt/quant_bands.c
index 95076e0a..9cf48f66 100644
--- a/celt/quant_bands.c
+++ b/celt/quant_bands.c
@@ -281,7 +281,7 @@ void quant_coarse_energy(const CELTMode *m, int start, int end, int effEnd,
tell = ec_tell(enc);
if (tell+3 > budget)
two_pass = intra = 0;
-
+ //printf("budget: %d %d\n", tell, budget);
max_decay = QCONST16(16.f,DB_SHIFT);
if (end-start>10)
{
diff --git a/src/opus_encoder.c b/src/opus_encoder.c
index dcceccf5..6913e564 100644
--- a/src/opus_encoder.c
+++ b/src/opus_encoder.c
@@ -1499,9 +1499,11 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_
st->silk_mode.bitRate += ( total_bitRate - st->silk_mode.bitRate ) * 3 / 5;
}
/* Don't let SILK use more than 80% */
- if( st->silk_mode.bitRate > total_bitRate * 4/5 ) {
- st->silk_mode.bitRate = total_bitRate * 4/5;
+ if( st->silk_mode.bitRate > total_bitRate * 9/10 ) {
+ st->silk_mode.bitRate = total_bitRate * 9/10;
}
+ //printf("%d\n", st->silk_mode.bitRate);
+ st->silk_mode.bitRate = 11000;
if (!st->energy_masking)
{
/* Increasingly attenuate high band when it gets allocated fewer bits */
@@ -1720,6 +1722,9 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_
len += st->mode == MODE_HYBRID ? 3 : 1;
if( st->use_vbr ) {
nb_compr_bytes = len + bytes_target - (st->silk_mode.bitRate * frame_size) / (8 * st->Fs);
+ celt_encoder_ctl(celt_enc, OPUS_SET_BITRATE(st->bitrate_bps));
+ nb_compr_bytes = max_data_bytes-1-redundancy_bytes;
+ celt_encoder_ctl(celt_enc, OPUS_SET_VBR(1));
} else {
/* check if SILK used up too much */
nb_compr_bytes = len > bytes_target ? len : bytes_target;