xiph / opus-tools

A set of tools to encode, inspect, and decode audio in the Opus format.
https://opus-codec.org/
Other
212 stars 78 forks source link

opus_custom_decode() can't decode the custom stream while set sample rate less 24K #79

Closed sam131208 closed 1 year ago

sam131208 commented 1 year ago

The following code is a bat file to convert .wav to an Opus stream.

for %%s in (music\*.wav) do ( 
    if %%~zs neq 0 (
        opusenc --bitrate 128 --vbr --music --comp 0 --framesize 10 --downmix-mono --discard-comments --discard-pictures %%s    %%~ns.ops
        opusdec --rate 16000 %%~ns.ops %%~ns.pcm
        del %%~ns.ops /q
        opus_demo  -e audio 16000 1 -cvbr -framesize 10 -max_payload 160 -complexity 0 -forcemono %%~ns.pcm %%~ns.ops
        del %%~ns.pcm /q
    )
)

If you use opus_decode() decoding, it works fine, return frame size = 160. When I decode with opus_custom_decode(), an error value is returned, return frame size = 40.

mark4o commented 1 year ago

opus_demo -e produces a file in a special format intended only to be read by opus_demo -d. The file is not an Opus file and it contains more than just the raw packet data.

opus_custom_decode() does not take an Opus packet like opus_decode(); it takes a frame using the custom CELT mode that was specified on initialization of the custom decoder. In an Opus packet the mode information is part of the packet data.

sam131208 commented 1 year ago

@mark4o Thanks for your reply. Is there an encoding/decoding tool for custom CELT mode here? Sometimes, opus cannot be used due to less RAM.

mark4o commented 1 year ago

In the opus repository there is a test utility opus_custom_demo. It performs opus_custom_encode() followed by opus_custom_decode(), so that you can check the resulting audio quality. This project (opus-tools) is a collection of utilities for use with standard Opus files and has no connection to Opus Custom.