Coder Social home page Coder Social logo

Strange distortion when decoding about opus HOT 6 CLOSED

hraban avatar hraban commented on July 20, 2024
Strange distortion when decoding

from opus.

Comments (6)

brandonsturgeon avatar brandonsturgeon commented on July 20, 2024 1

Fixed it!

I was creating a new instance of the decoder every time I needed to use it.

Creating just one of them and re-using it for subsequent packets works flawlessly 👍

from opus.

hraban avatar hraban commented on July 20, 2024

Hi Brandon, I think you forgot to attach the spectograms.

My first step for debugging this would be to compare the raw opus data extracted by your node and go programs: if they're equal, then the problem lies with decoding the packets. If they're not, then it's in the extraction of opus data from that proprietary stream.

I'd output them using something very easy to compare, e.g. a text file with one line of hex encoded binary data per line. If there is any diff, this makes it easy to identify where the issue is, hopefully.

If you've done that and the opus data is the same, I'd check one more thing: are you actually receiving raw opus packets, or are you receiving a OGG/Opus stream? (see the README for more details on this).

If you've done all that and you're sure it's raw opus data coming in and they're exactly the same between nodejs and go, I'd have another close look at the initialisation of the decoder: are all the parameters passed exactly right? Are you extracting the resulting PCM data correctly? Are you handling the mono vs stereo case correctly? (NB that libopus returns a single channel as a single array, which might not fit your PCM device API).

For context: this wrapper is extremely thin. It doesn't do any allocation or data handling of the actual audio: it's a direct, zerocopy passthrough to libopus. If the Node.JS lib you're using does some smarter handling of the data, there's another avenue for bugs to creep in when switching to this lib.

Good luck 🙂

from opus.

hraban avatar hraban commented on July 20, 2024

I'm closing this until further update indicates that it is specifically an issue with this library.

from opus.

brandonsturgeon avatar brandonsturgeon commented on July 20, 2024

Thanks for the very helpful reply!

After a great deal more debugging, I didn't get any further.

The data was the exact same going into the decoder in my Go project as in my Node project.

I also tried another Go Opus library but got the same result - so it's clearly not a problem specifically with this library.

Still, the mystery remains 🤦‍♂️

from opus.

hraban avatar hraban commented on July 20, 2024

@brandonsturgeon what was the node library you were using?

from opus.

brandonsturgeon avatar brandonsturgeon commented on July 20, 2024

We're using Discord's Opus library: https://github.com/discordjs/opus

Comparing your call to libopus:

	n := int(C.opus_decode(
		dec.p,
		(*C.uchar)(&data[0]),
		C.opus_int32(len(data)),
		(*C.opus_int16)(&pcm[0]),
		C.int(cap(pcm)/dec.channels),
		0))

To discordjs':

	int decodedSamples = opus_decode(
		this->decoder,
		compressedData,
		compressedDataLength,
		&(this->outPcm[0]),
		MAX_FRAME_SIZE,
		/* decode_fec */ 0
	);

They're practically identical, so... I have no idea.

To my eyes, the only difference is the second-to-last parameter.
You use the size of the input buffer. They use MAX_FRAME_SIZE, which I believe is:

#define MAX_FRAME_SIZE 6 * 960

I actually tried modifying your opus to use 6 * 960 in that parameter and found zero difference in the output. Still garbled.

from opus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.