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

AudioEffectCapture Produces Distorted Output on 44.1 kHz Input Systems #102701

Open
JBlank19 opened this issue Feb 11, 2025 · 8 comments
Open

AudioEffectCapture Produces Distorted Output on 44.1 kHz Input Systems #102701

JBlank19 opened this issue Feb 11, 2025 · 8 comments

Comments

@JBlank19
Copy link

JBlank19 commented Feb 11, 2025

Tested versions

  • Reproducible in 4.2.stable, 4.4.beta3

System information

Windows 10 - 44100 kHz Input Audio

Issue description

I have a bus layout with 3 buses, Master, Muted, Record. Record has a AudioEffectCapture in it and trasfers its audio into Muted which is indeed muted. Then I have an AudioStreamPlayer with an AudioStreamMicrophone.

I press an action (via the input map) to activate and deactivate (play or not play) the Stream in AudioStreamMicrophone. Then, via code I get the buffer like this:

while _recording:
    var start_time = Time.get_ticks_msec()
        
    # Get new frames from the capture.
    var chunk = _effect_capture.get_buffer(_effect_capture.get_frames_available())
    if chunk.size() > 0:
        _accumulated_frames.append_array(chunk)

I then save the audio (_accumulated_frames) into a .wav file at the sample rate AudioServer.get_mix_rate(). In systems with 48 kHz input audio this works perfectly. In systems with 44.1 kHz input audio the .wav originated from _accumulated_frames sounds like the audio file attached.

debug_acc_frames.zip

On systems with a 48 kHz input audio rate, the generated .wav file plays back correctly and my posterior speech to text scripts work correctly.
On systems with a 44.1 kHz input audio rate, the resulting .wav file sounds distorted and my posterior speech to text scripts break, see the attached audio file.

Steps to reproduce

  1. Set up an AudioStreamMicrophone routed to a bus containing AudioEffectCapture.
  2. Capture audio frames using _effect_capture.get_buffer().
  3. Save the recorded audio as a .wav file using AudioServer.get_mix_rate() for the sample rate.
  4. Test on a system with 44.1 kHz input audio and listen to the resulting .wav file, it will be stuttery and in slow motion.

Minimal reproduction project (MRP)

See above

@JBlank19
Copy link
Author

As asked by @Ughuuu I will mention him and @fire

@akien-mga
Copy link
Member

akien-mga commented Feb 11, 2025

4.2.stable is fairly old - can you also reproduce this issue in 4.3.stable and 4.4.beta3?
(The bug is plausible and I don't particularly have a recent fix in mind that may have solved it, but it's always useful to test the latest builds to make sure we don't start chasing a bug that no longer exists.)

@JBlank19
Copy link
Author

Here is a MWP for 4.4.beta3, again the bus layout has 3 buses set up like this:

Image

The scene looks like this:

Image

Image

And the script is here

CaptureScript.txt

Resulting audio is broken for 44.1 kHz systems:

debug_acc_frames_44beta3.zip

Hopefully this is useful!

@Calinou
Copy link
Member

Calinou commented Feb 11, 2025

Is the 44.1 kHz setup using surround sound? In this case, I suggest testing #92532 locally (see Testing pull requests).

Typically, I'd also suggest adjusting the capture rate to match the output audio rate, however, Godot already defaults to 44100 Hz output by default, so that's probably not the cause.

However, recent changes were made to AudioStreamGenerator to allow it to automatically adjust itself to the input/output mix rate: #102691

@JBlank19
Copy link
Author

@Calinou how do I build for this #92532 version? I downloaded the Windows editor artifact and managed to open the project, however I cannot build as there's no templates.

@Calinou
Copy link
Member

Calinou commented Feb 11, 2025

I downloaded the Windows editor artifact and managed to open the project, however I cannot build as there's no templates.

You can run the project from the editor and it should reproduce the issue, unless you were only able to reproduce the issue in an exported project beforehand.

You can also run the project from the project manager with the Run button if you don't want the editor to be running at the same time.

@JBlank19
Copy link
Author

JBlank19 commented Feb 11, 2025

I downloaded the Windows editor artifact and managed to open the project, however I cannot build as there's no templates.

You can run the project from the editor and it should reproduce the issue, unless you were only able to reproduce the issue in an exported project beforehand.

You can also run the project from the project manager with the Run button if you don't want the editor to be running at the same time.

The problem is that I'm not the one having the issue, but one of my "testers" so yes, I've only tested the bug in build. I'll make them run this version in editor and tell you.

@JBlank19
Copy link
Author

JBlank19 commented Feb 11, 2025

@Calinou #92532 fixes the issue, both in editor and with Run from the project manager.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: For team assessment
Development

No branches or pull requests

3 participants