diff --git a/scenes/main.gd b/scenes/main.gd index 877901d..4b345be 100644 --- a/scenes/main.gd +++ b/scenes/main.gd @@ -75,8 +75,6 @@ func _make_tone(freq_hz: float, length: float, sample_rate: int, amplitude: int func _on_wav_button_pressed() -> void: var data: Array[int] = [] - var loc_phase := 0.0 - var increment = pulse_hz / sample_hz var _use_test_data := false var amp := 100 @@ -106,8 +104,23 @@ func _on_wav_button_pressed() -> void: wav.data = data print("Writing WAV with ", data.size(), " length") - wav.save_to_wav("/tmp/foo.wav") - + var proposed_fname := "morse-" + Time.get_datetime_string_from_system(true) + ".wav" + match OS.get_name(): + ["Linux", "macOS", "Windows"]: + wav.save_to_wav("/tmp/foo.wav") + "Android": + print("Whaaat") + "Web": + print("download") + # we either write our own wave header method or we use a temporary file + # FIXME: find out if we have our own temp / if our filename needs to be random + var tmp_file := "/tmp/morse.wav" + wav.save_to_wav(tmp_file) + # var wav_file := FileAccess.open(tmp_file, FileAccess.READ) + var wav_data := FileAccess.get_file_as_bytes(tmp_file) + JavaScriptBridge.download_buffer(wav_data, proposed_fname, "audio/vnd.wave") + var platform: + print("Saving not supported on platform " + platform) func _on_reset_button_pressed() -> void: MorseState.reset()