godotengine / godotengine/godot
AudioEffectCapture Produces Distorted Output on 44.1 kHz Input Systems
- Dominant language
- C++
- Stars
- 117k
- Forks
- 26.8k
- PR merge metrics
- PR metrics pending
Description
### 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](https://github.com/user-attachments/files/18747747/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
Contributor guide
Research direction
Start with the AudioStreamMicrophone and AudioEffectCapture path described in the reproduction, comparing behavior at 44.1 kHz and 48 kHz. Reproduce the capture, inspect the frames returned by get_buffer(), and verify the saved WAV has correct timing and playback without distortion on both sample rates.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- audio-video-rtc
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100