Skip to content

Audio artefacts #1142

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Uriopass opened this issue Feb 19, 2021 · 10 comments
Closed

Audio artefacts #1142

Uriopass opened this issue Feb 19, 2021 · 10 comments
Labels
C-bug Category: This is a bug.

Comments

@Uriopass
Copy link
Contributor

Uriopass commented Feb 19, 2021

This is the official issue for the audio artefacts I had in #1129
I tried to reproduce the problem, however I hit an incredibly weird bug.

When compiling this snippet alone

use rodio::Source;

fn main() {
    let (a, b) = rodio::OutputStream::try_default().unwrap();
    let buf = std::fs::read("music1.ogg").ok().unwrap();

    let s = rodio::Decoder::new(std::io::Cursor::new(buf)).unwrap();
    b.play_raw(s.convert_samples()).unwrap();
    loop {}
}

everything works fine and the music sounds good.

However when I compile the exact same main with the exact same audio file in my big project with lots of dependencies, there are hugs artefacts which look like this in audacity: Top is what is output and bottom is expected.
image

I tried deleting the target folder and rebuilding and I still got the artefacts.

Then I found that by removing theses directives about optimizing in my workspace Cargo.toml

[profile.dev.build-override]
opt-level = 1

[profile.dev.package."*"]
opt-level = 2

[profile.dev.package.common]
opt-level = 2

[profile.dev.package.egregoria]
opt-level = 0

[profile.dev.package.map_model]
opt-level = 0

[profile.dev.package.native_app] # <- main binary
opt-level = 0

[profile.dev.package.imgui-inspect]
opt-level = 1

[profile.dev.package.imgui-inspect-derive]
opt-level = 1

the audio artefacts were gone !

However, when reenabling

[profile.dev.package."*"]
opt-level = 2

the artefacts came back.

So I started removing dependencies, and I found that, basically, enabling optimizations on rodio using cg_clif gave thoses artefacts..

You can find a repo to reproduce here.
https://github.com/Uriopass/cranelift_bug

EDIT:
Now that I think about it, you still have to dive a bit further, it's not like there's no dependencies. I'll try on cpal examples.

@bjorn3 bjorn3 added the C-bug Category: This is a bug. label Feb 19, 2021
@bjorn3
Copy link
Member

bjorn3 commented Feb 19, 2021

So I started removing dependencies, and I found that, basically, enabling optimizations on rodio using cg_clif gave thoses artefacts.

Thanks for the investigation! This must be a miscompilation caused by one of the optimizations then. I will see if I can narrow down which optimization is responsible.

@bjorn3
Copy link
Member

bjorn3 commented Feb 19, 2021

By the way, which license is the repro?

@Uriopass
Copy link
Contributor Author

Interestingly, when I use a simple sin wave as a source, I get normal sounding results! I wonder if it comes from the vorbis decoder, I'll try the mp3 decoder.

@Uriopass
Copy link
Contributor Author

Added the Unlicense LICENCE :-)

@bjorn3
Copy link
Member

bjorn3 commented Feb 19, 2021

Thanks. I won't have to worry about adding a test derived from it to cg_clif then.

@Uriopass
Copy link
Contributor Author

I confirm that using the mp3 decoder gives normal result. It probably comes from the vorbis decoder used by rodio: lewton.
https://github.com/RustAudio/lewton

@Uriopass
Copy link
Contributor Author

Uriopass commented Feb 19, 2021

Adding

[profile.dev.package.lewton]
opt-level = 0

does solve the artefacts issues
and

[profile.dev.package.lewton]
opt-level = 1

still gives artefacts.

Also, generating a sin wave ogg file gives normal result (maybe it compresses well and does not go through a miscompiled zone ?)

@bjorn3
Copy link
Member

bjorn3 commented Feb 19, 2021

I am able to reproduce the issue. Disabling my stack2reg optimization fixes it. I already kind of suspected this to be the culprit, as I wrote it with absolutely zero knowledge about how to write this kind of optimization. I will see if I can fix it and otherwise I will just disable it completely.

@bjorn3
Copy link
Member

bjorn3 commented Feb 19, 2021

Disabling just the the dead store removal of that optimization fixes it too.

@bjorn3
Copy link
Member

bjorn3 commented Feb 20, 2021

I have disabled stack2reg. Maybe I will try to fix it in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

2 participants