+
Skip to content

Opus 1.4 Corrupted audio while encode of 128 channels #397

@NickolayGerasimenko

Description

@NickolayGerasimenko

Environment

Opus 1.4 (commit: 82ac57d)
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;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载