-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9acce6b
commit 5b910af
Showing
8 changed files
with
226 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
extends Object | ||
|
||
const BASE_58_ALPHABET := "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz" | ||
|
||
|
||
static func b58decode(v: String) -> StreamPeerBuffer: | ||
# Base 58 is a number expressed in the base-58 numeral system. | ||
# When encoding data, big-endian is used and leading zeros are encoded as leading `1`s. | ||
|
||
var original_length := v.length() | ||
v = v.lstrip(BASE_58_ALPHABET[0]) | ||
var zeros := original_length - v.length() | ||
|
||
var buffer := PoolByteArray() | ||
buffer.resize(v.length()) # Won't be as long as base 58 string since the buffer is 256-based. | ||
buffer.fill(0) | ||
|
||
var length := 0 | ||
for c in v: | ||
var carry := BASE_58_ALPHABET.find(c) | ||
if carry == -1: | ||
return null | ||
var i := 0 | ||
while carry != 0 or i < length: | ||
var pos := buffer.size() - 1 - i | ||
carry += 58 * buffer[pos] | ||
buffer[pos] = carry % 256 | ||
carry /= 256 | ||
i += 1 | ||
length = i | ||
|
||
var result := StreamPeerBuffer.new() | ||
for _i in zeros: | ||
result.put_8(0) | ||
result.put_data(buffer.subarray(buffer.size() - length, -1)) | ||
result.seek(0) | ||
|
||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,14 +8,14 @@ msgid "" | |
msgstr "" | ||
"Project-Id-Version: gdfxr 1.0\n" | ||
"Report-Msgid-Bugs-To: [email protected]\n" | ||
"POT-Creation-Date: 2022-09-20 14:01+0800\n" | ||
"POT-Creation-Date: 2022-12-04 13:45+0800\n" | ||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" | ||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" | ||
"Language-Team: LANGUAGE <[email protected]>\n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=utf-8\n" | ||
"Content-Transfer-Encoding: 8bit\n" | ||
"Generated-By: Babel 2.10.3\n" | ||
"Generated-By: Babel 2.11.0\n" | ||
|
||
#: addons/gdfxr/editor/Editor.gd | ||
msgid "Save As..." | ||
|
@@ -29,6 +29,10 @@ msgstr "" | |
msgid "Paste" | ||
msgstr "" | ||
|
||
#: addons/gdfxr/editor/Editor.gd | ||
msgid "Paste from jsfxr" | ||
msgstr "" | ||
|
||
#: addons/gdfxr/editor/Editor.gd | ||
msgid "Recently Generated" | ||
msgstr "" | ||
|
@@ -109,6 +113,10 @@ msgstr "" | |
msgid "None" | ||
msgstr "" | ||
|
||
#: addons/gdfxr/editor/Editor.gd | ||
msgid "Clipboard does not contain code copied from jsfxr." | ||
msgstr "" | ||
|
||
#: addons/gdfxr/editor/Editor.tscn | ||
msgid "New" | ||
msgstr "" | ||
|
@@ -245,7 +253,3 @@ msgstr "" | |
msgid "Waveform" | ||
msgstr "" | ||
|
||
#: addons/gdfxr/editor/ParamSlider.tscn | ||
msgid "Hold Ctrl to snap to 0.01 increments." | ||
msgstr "" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,8 +7,8 @@ msgid "" | |
msgstr "" | ||
"Project-Id-Version: gdfxr 1.0\n" | ||
"Report-Msgid-Bugs-To: [email protected]\n" | ||
"POT-Creation-Date: 2022-09-20 14:01+0800\n" | ||
"PO-Revision-Date: 2022-09-20 14:01+0800\n" | ||
"POT-Creation-Date: 2022-12-04 13:45+0800\n" | ||
"PO-Revision-Date: 2022-12-04 13:45+0800\n" | ||
"Last-Translator: Haoyu Qiu <[email protected]>\n" | ||
"Language-Team: \n" | ||
"Language: zh_CN\n" | ||
|
@@ -17,7 +17,7 @@ msgstr "" | |
"Content-Transfer-Encoding: 8bit\n" | ||
"Plural-Forms: nplurals=1; plural=0;\n" | ||
"Generated-By: Babel 2.9.1\n" | ||
"X-Generator: Poedit 3.1\n" | ||
"X-Generator: Poedit 3.2.1\n" | ||
|
||
#: addons/gdfxr/editor/Editor.gd | ||
msgid "Save As..." | ||
|
@@ -31,6 +31,10 @@ msgstr "复制" | |
msgid "Paste" | ||
msgstr "粘贴" | ||
|
||
#: addons/gdfxr/editor/Editor.gd | ||
msgid "Paste from jsfxr" | ||
msgstr "从 jsfxr 粘贴" | ||
|
||
#: addons/gdfxr/editor/Editor.gd | ||
msgid "Recently Generated" | ||
msgstr "最近生成" | ||
|
@@ -117,6 +121,10 @@ msgstr "" | |
msgid "None" | ||
msgstr "无" | ||
|
||
#: addons/gdfxr/editor/Editor.gd | ||
msgid "Clipboard does not contain code copied from jsfxr." | ||
msgstr "剪贴板中没有从 jsfxr 复制的代码。" | ||
|
||
#: addons/gdfxr/editor/Editor.tscn | ||
msgid "New" | ||
msgstr "新建" | ||
|
@@ -253,6 +261,5 @@ msgstr "高通变频" | |
msgid "Waveform" | ||
msgstr "波形" | ||
|
||
#: addons/gdfxr/editor/ParamSlider.tscn | ||
msgid "Hold Ctrl to snap to 0.01 increments." | ||
msgstr "按住 Ctrl 吸附到 0.01 增量。" | ||
#~ msgid "Hold Ctrl to snap to 0.01 increments." | ||
#~ msgstr "按住 Ctrl 吸附到 0.01 增量。" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
extends Container | ||
|
||
# These two classes are for runtime generation. | ||
const SFXRConfig = preload("res://addons/gdfxr/SFXRConfig.gd") | ||
const SFXRGenerator = preload("res://addons/gdfxr/SFXRGenerator.gd") | ||
|
||
onready var audio_player: AudioStreamPlayer = $AudioPlayer | ||
onready var adhoc_audio_player: AudioStreamPlayer = $AdhocAudioPlayer | ||
|
||
|
||
func _on_Play_pressed() -> void: | ||
audio_player.play() | ||
|
||
|
||
func _on_PlayFile_pressed() -> void: | ||
adhoc_audio_player.stream = preload("res://example/example.sfxr") | ||
adhoc_audio_player.play() | ||
|
||
|
||
func _on_Generate_pressed() -> void: | ||
var config := SFXRConfig.new() | ||
|
||
# Fill the fields manually | ||
# config.p_base_freq = 0.5 | ||
|
||
# Load from .sfxr file | ||
# config.load("res://example/example.sfxr") | ||
|
||
# Load from jsfxr base58 string | ||
config.load_from_base58("34T6PkmKkNTf3aUynCpV3oetaq6ecj9Grh9W7tiTbccVYK8FxNKBbfBFXJCLzk8QTy4d7fbiCfY2gXDaiengXbENjdLWt5jZBtcz8QmSCXjHCSuooDCWp4SrT") | ||
|
||
# generate_audio_stream() might freeze a bit when generating long sounds. | ||
# It's recommended to pre-generate the sound effects in editor. | ||
# If you do want to generate the sound effects on the fly, you might want | ||
# to generate and cache the sound effects at the start of your game. | ||
var generator := SFXRGenerator.new() | ||
adhoc_audio_player.stream = generator.generate_audio_stream(config) | ||
adhoc_audio_player.play() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,74 @@ | ||
[gd_scene load_steps=2 format=2] | ||
|
||
[ext_resource path="res://example/example.sfxr" type="AudioStream" id=1] | ||
|
||
[node name="Example" type="CenterContainer"] | ||
anchor_right = 1.0 | ||
anchor_bottom = 1.0 | ||
__meta__ = { | ||
"_edit_use_anchors_": false | ||
} | ||
|
||
[node name="Button" type="Button" parent="."] | ||
margin_left = 448.0 | ||
margin_top = 284.0 | ||
margin_right = 576.0 | ||
margin_bottom = 316.0 | ||
[gd_scene load_steps=3 format=2] | ||
|
||
[ext_resource path="res://example/Example.gd" type="Script" id=1] | ||
[ext_resource path="res://example/example.sfxr" type="AudioStream" id=2] | ||
|
||
[node name="Example" type="GridContainer"] | ||
anchor_left = 0.5 | ||
anchor_top = 0.5 | ||
anchor_right = 0.5 | ||
anchor_bottom = 0.5 | ||
grow_horizontal = 2 | ||
grow_vertical = 2 | ||
custom_constants/vseparation = 32 | ||
custom_constants/hseparation = 32 | ||
columns = 2 | ||
script = ExtResource( 1 ) | ||
|
||
[node name="AudioPlayer" type="AudioStreamPlayer" parent="."] | ||
stream = ExtResource( 2 ) | ||
|
||
[node name="AdhocAudioPlayer" type="AudioStreamPlayer" parent="."] | ||
|
||
[node name="Play" type="Button" parent="."] | ||
margin_right = 141.0 | ||
margin_bottom = 32.0 | ||
rect_min_size = Vector2( 128, 32 ) | ||
size_flags_vertical = 4 | ||
text = "Play" | ||
|
||
[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."] | ||
stream = ExtResource( 1 ) | ||
[node name="Label" type="Label" parent="."] | ||
margin_left = 173.0 | ||
margin_right = 473.0 | ||
margin_bottom = 31.0 | ||
rect_min_size = Vector2( 300, 0 ) | ||
text = "A .sfxr file can be used as regular audio files like .wav, .ogg, and .mp3." | ||
autowrap = true | ||
|
||
[node name="PlayFile" type="Button" parent="."] | ||
margin_top = 64.0 | ||
margin_right = 141.0 | ||
margin_bottom = 96.0 | ||
rect_min_size = Vector2( 128, 32 ) | ||
size_flags_vertical = 4 | ||
text = "Load .sfxr File" | ||
|
||
[node name="Label2" type="Label" parent="."] | ||
margin_left = 173.0 | ||
margin_top = 64.0 | ||
margin_right = 473.0 | ||
margin_bottom = 95.0 | ||
rect_min_size = Vector2( 300, 0 ) | ||
text = "A .sfxr file is a AudioStreamSample resource that can be loaded with load() or preload()." | ||
autowrap = true | ||
|
||
[node name="Generate" type="Button" parent="."] | ||
margin_top = 144.0 | ||
margin_right = 141.0 | ||
margin_bottom = 176.0 | ||
rect_min_size = Vector2( 128, 32 ) | ||
size_flags_vertical = 4 | ||
text = "Runtime Generation" | ||
|
||
[node name="Label3" type="Label" parent="."] | ||
margin_left = 173.0 | ||
margin_top = 128.0 | ||
margin_right = 473.0 | ||
margin_bottom = 193.0 | ||
rect_min_size = Vector2( 300, 0 ) | ||
text = "You can generate the sound effect at runtime. However, due to performance constraints with GDScript, your game might freeze when generating long sounds." | ||
autowrap = true | ||
|
||
[connection signal="pressed" from="Button" to="AudioStreamPlayer" method="play"] | ||
[connection signal="pressed" from="Play" to="." method="_on_Play_pressed"] | ||
[connection signal="pressed" from="PlayFile" to="." method="_on_PlayFile_pressed"] | ||
[connection signal="pressed" from="Generate" to="." method="_on_Generate_pressed"] |