File tree Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ extends Node
33
44const SAMPLE_HZ = 44100
55const MIN_HZ = 110
6- const MAX_HZ = 440
6+ const MAX_HZ = 880
77
88var frac : float
99var player = AudioStreamPlayer .new ()
@@ -13,7 +13,7 @@ var _playback: AudioStreamGeneratorPlayback
1313func _fill_buffer (pulse_hz ):
1414 var increment = pulse_hz / SAMPLE_HZ
1515 for i in range (_playback .get_frames_available ()):
16- _playback .push_frame (Vector2 .ONE * sin (_phase * TAU ))
16+ _playback .push_frame (Vector2 .ONE * triangle (_phase ))
1717 _phase = fmod (_phase + increment , 1.0 )
1818
1919func _process (delta ):
@@ -26,3 +26,7 @@ func _init():
2626 player .stream .mix_rate = SAMPLE_HZ
2727 _playback = player .get_stream_playback ()
2828 player .play ()
29+
30+ func triangle (x ):
31+ """Generate a triangle wave from the given phase."""
32+ return 2 / PI * asin (sin (PI * x ))
You can’t perform that action at this time.
0 commit comments