Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.xiph.org/xiph/opus.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarcin Gorzel <gorzel@google.com>2018-08-30 15:15:21 +0300
committerFelicia Lim <flim@google.com>2018-08-31 19:32:49 +0300
commitc2a6ac4e341f7224ef8e30ad4e1eee79a516e069 (patch)
treeab2aeb73d59a646a34817f84108a52894f7bc334 /src
parent38fca4a203a6759f2c90b86c84c4db087982ca81 (diff)
Apply equal bit allocation to ambisonic channels
Fixes issue #95 on GitHub. Signed-off-by: Felicia Lim <flim@google.com>
Diffstat (limited to 'src')
-rw-r--r--src/opus_multistream_encoder.c57
1 files changed, 6 insertions, 51 deletions
diff --git a/src/opus_multistream_encoder.c b/src/opus_multistream_encoder.c
index 6cc1f432..9cb9bf34 100644
--- a/src/opus_multistream_encoder.c
+++ b/src/opus_multistream_encoder.c
@@ -742,20 +742,9 @@ static void ambisonics_rate_allocation(
{
int i;
opus_int32 total_rate;
- opus_int32 directional_rate;
- opus_int32 nondirectional_rate;
- opus_int32 leftover_bits;
-
- /* Each nondirectional channel gets (rate_ratio_num / rate_ratio_den) times
- * as many bits as all other ambisonics channels.
- */
- const int rate_ratio_num = 4;
- const int rate_ratio_den = 3;
+ opus_int32 per_stream_rate;
+
const int nb_channels = st->layout.nb_streams + st->layout.nb_coupled_streams;
- /* The omnidirectional ambisonics and non-diegetic stereo channels */
- const int nb_nondirectional_channels = st->layout.nb_coupled_streams * 2 + 1;
- /* The remaining ambisonics channels */
- const int nb_directional_channels = nb_channels - nb_nondirectional_channels;
if (st->bitrate_bps==OPUS_AUTO)
{
@@ -769,46 +758,12 @@ static void ambisonics_rate_allocation(
total_rate = st->bitrate_bps;
}
- /* Let y be the directional rate, m be the num of nondirectional channels
- * m = (s + 1)
- * and let p, q be integers such that the nondirectional rate is
- * m_rate = (p / q) * y
- * Also let T be the total bitrate to allocate. Then
- * T = (n - m) * y + m * m_rate
- * Solving for y,
- * y = (q * T) / (m * (p - q) + n * q)
- */
- directional_rate =
- total_rate * rate_ratio_den
- / (nb_nondirectional_channels * (rate_ratio_num - rate_ratio_den)
- + nb_channels * rate_ratio_den);
-
- /* Calculate the nondirectional rate.
- * m_rate = y * (p / q)
- */
- nondirectional_rate = directional_rate * rate_ratio_num / rate_ratio_den;
-
- /* Calculate the leftover from truncation error.
- * leftover = T - y * (n - m) - m_rate * m
- * Place leftover bits in omnidirectional channel.
- */
- leftover_bits = total_rate
- - directional_rate * nb_directional_channels
- - nondirectional_rate * nb_nondirectional_channels;
-
- /* Calculate rates for each channel */
+ /* Allocate equal number of bits to Ambisonic (uncoupled) and non-diegetic
+ * (coupled) streams */
+ per_stream_rate = total_rate / st->layout.nb_streams;
for (i = 0; i < st->layout.nb_streams; i++)
{
- if (i < st->layout.nb_coupled_streams)
- {
- rate[i] = nondirectional_rate * 2;
- } else if (i == st->layout.nb_coupled_streams)
- {
- rate[i] = nondirectional_rate + leftover_bits;
- } else
- {
- rate[i] = directional_rate;
- }
+ rate[i] = per_stream_rate;
}
}