How do I set the AudioServer mix rate?

Godot Version

4.2

Question

I found
AudioServer.get_mix_rate()
and it tells me the mix rate is set to 48000, but I don’t see a setter. I found

AudioStreamWAV.get_mix_rate()
AudioStreamWAV.set_mix_rate()

so I was able to set that to what I want, which is 44100 Hz.

But still the wav files produced with
AudioStreamWAV.save_to_wav()
are 48000 Hz.

I went to the Project Settings page, and the audio driver mix rate is set to 44100.
I checked it again with
ProjectSettings.get_setting_with_override ("audio/driver/mix_rate")
and it’s 44100

var recording = AudioStreamWAV.new()
recording.set_mix_rate(44100)
print("Confirming AudioStreamWAV mix rate:")
print(recording.get_mix_rate())
print("Project settings audio mix rate incl any overrides:")
print(ProjectSettings.get_setting_with_override ("audio/driver/mix_rate"))
print("Checking AudioServer")
print(AudioServer.get_mix_rate())
Confirming AudioStreamWAV mix rate:
44100
Project settings audio mix rate incl any overrides:
44100
Checking AudioServer 
48000

The ProjectSettings page says I can use an override.cfg file in my project root directory. So I would just need to know how to access the mix rate setting.

I tried
AudioServer.set_mix_rate(44100)
and I got

Static function "set_mix_rate()" not found in base "GDScriptNativeClass".

I tried
AudioServer.mix_rate = 44100
and I got
Cannot find member "mix_rate" in base "AudioServer"
Seems like there would be a way … maybe a workaround?

Thanks in advance for any help or suggestions.

Could be hardware specific, do you have Windows 10 or 11?
I couldn’t find anything in the C++ sources that it is hardcoded, only on Android 44.1k


on MacOs all values are 44100

Confirming AudioStreamWAV mix rate:
44100
Project settings audio mix rate incl any overrides:
44100
Checking AudioServer
44100

recording.save_to_wav("res://test.wav")
also 44,1 kHz

Thank you!

I ran into similar issue. In my case, I wanted to get a mono recording to send it to some third-party API, and my observation was as follows:

  • Project’s settings and Windows audio settings has no effect on the result recording.
  • Settings “mix-rate” and “stereo” properties before calling “save_to_wav” doesn’t resample the recorded audio data and the saved .wav file will be destorted.
    In my case, I had to do the resampling (changing stereo to mono) my self:
	if recording.stereo and recording.format == AudioStreamWAV.FORMAT_16_BITS:
		var data :  PackedByteArray = recording.data
		var newData := PackedByteArray()
		newData.resize(data.size() / 2)
		for i in range(0, data.size(), 4):
			var left := data.decode_u16(i)
			var right := data.decode_u16(i + 2)
			newData.encode_u16(i / 2, (left + right) / 2)
		recording.data = newData
		recording.set_stereo(false)