So, I'm working on some audio generation stuff, and I have problems generating low notes. C4 anda round works fine, but down at C2 (65.41 hertz), I get wierd audio.
I took the Audio Generator Demo and played around with that to see if it would work there. Turns out I get the same issue. I tried playing a sequence of notes (C2,D2,D#2,F2, G2) to see if it sounds normal or not, but nope.
I have no idea what's going on here. My sample rate is 22050.
Here's my slightly modified code from the Audio Generation Demo:
var sample_hz = 22050.0 # Keep the number of samples to mix low, GDScript is not super fast.
var pulse_hz = 65.41
var phase = 0.0
var playback: AudioStreamPlayback = null # Actual playback stream, assigned in _ready().
var notes = [
var note = 0
var t = 0
var increment = pulse_hz / sample_hz
var to_fill = playback.get_frames_available()
while to_fill > 0:
playback.push_frame(Vector2.ONE * sin(phase * TAU)) # Audio frames are stereo.
phase = fmod(phase + increment, 1.0)
to_fill -= 1
t += _delta
if t > 1:
t = 0
if note > notes.size() - 1:
note = 0
pulse_hz = notes[note]
$Player.stream.mix_rate = sample_hz # Setting mix rate is only possible before play().
playback = $Player.get_stream_playback()
_fill_buffer() # Prefill, do before play() to avoid delay.