Skip to content
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

Audio distortion and artifact issues with Rune playback #151

Closed
puff-dayo opened this issue Dec 2, 2024 · 6 comments
Closed

Audio distortion and artifact issues with Rune playback #151

puff-dayo opened this issue Dec 2, 2024 · 6 comments
Labels
C - bug Something isn't working S - confirmed The issue has been confirmed by our team T - help wanted Extra attention is needed

Comments

@puff-dayo
Copy link

Describe the bug

I've noticed subtle audio distortions and artifacts when playing music through both my computer's built-in speakers and headphones. The audio sounds consistently hoarse with a persistent hum and intermittent popping sounds. So I switched to Windows's built-in media player for testing, then I noticed different sound quality.

Here is the frequency spectrum comparison between the original A(frequency=1760Hz, sample_rate = 44.1kHz) sine wave audio file and the recorded output file from Rune using an internal recording tool. I've attached both the test file and the recorded output for reference.

(Upper: Internally recorded Rune audio playback. Lower: Program-generated sine wave audio)

To Reproduce
Steps to reproduce the behavior:

  1. Simply play any sound.

Desktop

  • OS: Windows 11 21H2 22000.2538
  • Audio device: Headphones&Speakers (Realtek Audio) @ 2 channels, 24-bit, 48000Hz.
  • Version: Rune-v0.0.0-alpha.19-1d84138-windows

sound_files.zip

@puff-dayo
Copy link
Author

The same issue can also be reproduced on one of my Linux PCs.

Desktop

  • OS: Ubuntu 24.04 (Linux 6.8)
  • Audio device: Headphones&Speakers ALSA (Intel HDA) @ 2 channels, 32-bit, 48000Hz
  • Version: Rune-v0.0.0-alpha.20-linux-amd64

@Losses
Copy link
Owner

Losses commented Dec 2, 2024

image

Reproduced, investigating the issue, a little bit headache about this...

@Losses Losses added C - bug Something isn't working T - help wanted Extra attention is needed S - confirmed The issue has been confirmed by our team labels Dec 2, 2024
@XMLHexagram
Copy link
Collaborator

The same on macOS

The record of Rune output:
CleanShot 2024-12-02 at 21 07 22@2x

The record of Apple Music output:
CleanShot 2024-12-02 at 21 08 13@2x

@Losses
Copy link
Owner

Losses commented Dec 3, 2024

This is improved in: 2077859

I think it could be optimized further, but more effort to dig the issue is necessary. We are still trying.

Cheers.

@Losses
Copy link
Owner

Losses commented Dec 3, 2024

We have conducted a thorough investigation and identified the core problem. It was determined that an incorrect API was used during audio visualization, which resulted in directly taking a sample from the buffer and causing sample loss. This led to imperfections in audio playback.

To address this, we have made modifications to the Rodio API, allowing us to extract data directly from the audio stream without compromising the audio decoding results. After implementing these changes, the issue of sample loss has been resolved, as confirmed by various spectrum analyses.

However, when playing a sine wave and extracting its spectrum, you may still notice artifacts. This is due to the underlying audio processing mechanisms of the entire tech stack. Specifically, there is a 0.05681818182% discrepancy between the output frequency and the original audio frequency. This issue may stem from inherent digital system limitations or parameter rounding during processing.

We are continuing to investigate this matter and hope that our current findings provide you with a better understanding of the situation.

@Losses
Copy link
Owner

Losses commented Dec 3, 2024

In our continued investigation into the artifacts observed during sine wave audio playback, we have identified several complex contributing factors. To eliminate potential software-related influences, we controlled all external parameters:

  • We generated an audio file with a sample rate of 44100Hz, consisting of a 1000Hz mono sine wave.
  • Using OBS for recording, we set the recording parameters to 44100Hz as well to avoid resampling issues.
  • During the recording process, both the audio player's volume and the system volume were set to 100%.

This resulted in a clean, smooth spectrum, indicating that there are no inherent development errors within Rune affecting audio quality.

image

We observed that Rodio's resampling design has flaws, particularly when downsampling from 48000Hz to 44100Hz, resulting in suboptimal signal quality.

image

If we subtract Rodio's decoded output from the Ground Truth signal, the flaws in the resampling parameters become evident.

image

This issue is documented in the official repository's issue section.

RustAudio/rodio#647

We will continue to monitor upstream developments and apply updates promptly to ensure the best listening experience.

@Losses Losses closed this as completed Dec 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C - bug Something isn't working S - confirmed The issue has been confirmed by our team T - help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants