xiph / xiph/opus

Opus 1.4 Corrupted audio while encode of 128 channels

Open
#397 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
3.3k
Forks
808
PR merge metrics
No merged PRs in 30d

Description

Environment

Opus 1.4 (commit: 82ac57d9f1aa)
OS: Win/MacOS

Repro steps

I have very simple encoder as below,
I try to encode 128 channels where I have sine wave on every channel,
I set total bitrate as 64kbps * 128 = 8192kbps

So I instantiate Encoder as follows:

Encoder encoder(8192, 48000, 128);

Actual result:

Audio corrupted on last channels, up to total loss of audio in last channel.

Issue can be reproduced on any number of channels depending on set total bitrate.

Expected result:

Audio should be of good quality in every channel if set total bitrate as 64kbps * channels

Results on different bitrates:

total bitrate 8192kbps - no audio on 128th channel at all:

Image

total bitrate 16384kbps - it's 128kbps per channel, still 128th channel is corrupted:

Image
Workaround:

Only after setting total bitrate to 20480kbps audio looks fine.

Image
Encoder::Encoder(int bitrateKbps, int sampleRate, int numChannels)
{
    int error = 0;
    msEncoder_ = opus_multistream_encoder_create(sampleRate, numChannels, numChannels, 0, kChannelMapping.data(), OPUS_APPLICATION_AUDIO, &error);

    if (error != OPUS_OK)
        throw std::logic_error(std::string("Failed to create opus mulistream encoder, error: ") + opus_strerror(error));

    opus_multistream_encoder_ctl(msEncoder_, OPUS_SET_BITRATE(bitrateKbps * 1000));
    opus_multistream_encoder_ctl(msEncoder_, OPUS_SET_VBR(0));
    opus_multistream_encoder_ctl(msEncoder_, OPUS_SET_PACKET_LOSS_PERC(5));
    opus_multistream_encoder_ctl(msEncoder_, OPUS_SET_COMPLEXITY(5));
    opus_multistream_encoder_ctl(msEncoder_, OPUS_SET_BANDWIDTH(OPUS_AUTO));
}

Encoder::~Encoder()
{
    opus_multistream_encoder_destroy(msEncoder_);
}

bool Encoder::encode(const float* inBuf, int numInputSamples, unsigned char *outBuf, int outBufCapacity, int& encBytes)
{
    encBytes = opus_multistream_encode_float(msEncoder_, inBuf, numInputSamples, outBuf, outBufCapacity);

    if (encBytes < 0)
    {
        return false;
    }

    return true;
}

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the 128-channel case using opus_multistream_encoder_create and opus_multistream_encode_float with the reported bitrate values, comparing the final channels in the decoded output. Trace how multistream bitrate allocation behaves as channel count and total bitrate change; the issue is done when the reported bitrate produces intact audio across all channels or the supported limitation is clearly established.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
audio-video-rtc
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.