diff options
author | Jacob Lee <jacob@unabridgedsoftware.com> | 2021-10-27 22:24:23 -0400 |
---|---|---|
committer | Jacob Lee <jacob@unabridgedsoftware.com> | 2021-10-27 22:24:23 -0400 |
commit | 7bd9dd418ac6215094feb87087fcb59499c3aa69 (patch) | |
tree | 8dd0f98083f5d37e3ffd9d6c0a3d37cf8ae0d2d4 /klangfarb/main.gd | |
parent | fc2da03a2a385d9beac72246799a9ee5241f9859 (diff) |
Fix pitch in rust code and limit to 3 second duration
Diffstat (limited to 'klangfarb/main.gd')
-rw-r--r-- | klangfarb/main.gd | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/klangfarb/main.gd b/klangfarb/main.gd index 62137bc..d88d431 100644 --- a/klangfarb/main.gd +++ b/klangfarb/main.gd @@ -1,4 +1,3 @@ -tool extends AudioStreamPlayer var playback: AudioStreamPlayback = null @@ -6,28 +5,33 @@ var MonoBuffer = preload("res://MonoBuffer.gdns") var buffer = MonoBuffer.new() var samples = buffer.frames var sample_count = samples.size() +var current_count = 0 - -func _create_generator() -> void: - stream = AudioStreamGenerator.new() - stream.mix_rate = 8000.0 # Setting mix rate is only possible before play(). - playback = get_stream_playback() +#func _create_generator() -> void: +# stream = AudioStreamGenerator.new() +# stream.mix_rate = 44100.0 # Setting mix rate is only possible before play(). +# playback = get_stream_playback() func _fill_buffer() -> void: var to_fill = playback.get_frames_available() - while to_fill > 0: - var sample_index = to_fill % 512 + + while to_fill > 0 && current_count != sample_count: + var sample_index = current_count playback.push_frame(Vector2.ONE * samples[sample_index]) # Audio frames are stereo. # _phase = fmod(_phase + frequency() / GDawConfig.sample_rate, 1.0) # _update_state() to_fill -= 1 + current_count += 1 -func _process(delta): - _fill_buffer() +func _process(_delta): + if current_count < sample_count: + _fill_buffer() + else: + self.stop() func _ready() -> void: - _create_generator() - print(sample_count) + self.stream.mix_rate = 44100.0 + playback = self.get_stream_playback() _fill_buffer() self.play() # _update_envelope() |