Opened 3 years ago

Last modified 2 years ago

#9397 open enhancement

Allow any ADPCM block size to support XAudio2

Reported by: Thomas Cashman Owned by: zane
Priority: normal Component: undetermined
Version: unspecified Keywords:
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Summary of the bug:
Related to https://trac.ffmpeg.org/ticket/6585 and https://github.com/MonoGame/MonoGame/issues/5662

Microsoft measures the size of a block in samples for XAudio2 (https://msdn.microsoft.com/de-de/library/windows/desktop/ee415711(v=vs.85).aspx).

From Github thread:
FFMPEG forces the block size to be a power of 2 which appears to generate invalid samples per block. A block size of 70 would be needed to generate a valid 128 samples per block.

How to reproduce:

% ffmpeg.exe -y -i sample.ogg -vn -c:a adpcm_ms -block_size 70 -b:a 128000 -ar 36000 -f:a wav -strict experimental result.wav
ffmpeg version 4.4
Downloaded from https://github.com/BtbN/FFmpeg-Builds/releases

Change History (2)

comment:1 by zane, 2 years ago

Owner: set to zane
Status: newopen

I suspect the fix is a simple matter of relaxing the check.

Could you please comment out this block at libavcodec/adpcmenc.c:92 and see if the generated file works?

    if (avctx->codec->id != AV_CODEC_ID_ADPCM_IMA_AMV &&
        (s->block_size & (s->block_size - 1))) {
        av_log(avctx, AV_LOG_ERROR, "block size must be power of 2\n");
        return AVERROR(EINVAL);
    }

in reply to:  1 comment:2 by squarebananas, 2 years ago

Replying to zane:

Could you please comment out this block at libavcodec/adpcmenc.c:92 and see if the generated file works?

I can confirm this change works.

I've just commented out the block, built FFmpeg with MSYS2, used that to create an ADPCM audio file with a block size of 70 and then successfully played that through XAudio2 (via a monogame project).

Note: See TracTickets for help on using tickets.