Merge 8e4ad94569
into 3173b21368
This commit is contained in:
commit
f3097d1db5
6 changed files with 152 additions and 147 deletions
|
@ -29,13 +29,13 @@ var blink = false
|
|||
var blinkTick = 0
|
||||
|
||||
#Audio Listener
|
||||
|
||||
var currentMicrophone = null
|
||||
var playa:AudioStreamPlayer
|
||||
|
||||
var speaking = false
|
||||
var spectrum
|
||||
var volume = 0
|
||||
var volumeSensitivity = 0.0
|
||||
var experimentalMicLoudness = false
|
||||
|
||||
var volumeLimit = 0.0
|
||||
var senseLimit = 0.0
|
||||
|
@ -44,8 +44,6 @@ var senseLimit = 0.0
|
|||
signal startSpeaking
|
||||
signal stopSpeaking
|
||||
|
||||
var micResetTime = 180
|
||||
|
||||
var updatePusherNode = null
|
||||
|
||||
var rand = RandomNumberGenerator.new()
|
||||
|
@ -56,39 +54,31 @@ func _ready():
|
|||
if !Saving.settings.has("useStreamDeck"):
|
||||
Saving.settings["useStreamDeck"] = false
|
||||
|
||||
if Saving.settings.has("secondsToMicReset"):
|
||||
Global.micResetTime = Saving.settings["secondsToMicReset"]
|
||||
if Saving.settings.has("experimentalMicLoudness"):
|
||||
Global.experimentalMicLoudness = Saving.settings["experimentalMicLoudness"]
|
||||
else:
|
||||
Saving.settings["secondsToMicReset"] = 180
|
||||
Saving.settings["experimentalMicLoudness"] = false
|
||||
|
||||
createMicrophone()
|
||||
|
||||
func createMicrophone():
|
||||
var playa = AudioStreamPlayer.new()
|
||||
var mic = AudioStreamMicrophone.new()
|
||||
playa.stream = mic
|
||||
playa.autoplay = true
|
||||
if playa != null:
|
||||
remove_child(playa)
|
||||
playa.free()
|
||||
playa = AudioStreamPlayer.new()
|
||||
playa.bus = "MIC"
|
||||
playa.stream = AudioStreamMicrophone.new()
|
||||
add_child(playa)
|
||||
currentMicrophone = playa
|
||||
await get_tree().create_timer(micResetTime).timeout
|
||||
if currentMicrophone != playa:
|
||||
return
|
||||
deleteAllMics()
|
||||
currentMicrophone = null
|
||||
await get_tree().create_timer(0.25).timeout
|
||||
createMicrophone()
|
||||
|
||||
func deleteAllMics():
|
||||
for child in get_children():
|
||||
child.queue_free()
|
||||
await get_tree().create_timer(0.25).timeout # apparently it works to fix WASAPI "Initialize failed with error 0xffffffff88890002" and "init_input_device" errors
|
||||
playa.play()
|
||||
|
||||
|
||||
func _process(delta):
|
||||
animationTick += 1
|
||||
|
||||
volume = spectrum.get_magnitude_for_frequency_range(20, 20000).length()
|
||||
if currentMicrophone != null:
|
||||
volume = (AudioServer.get_bus_peak_volume_left_db(1, 0) + AudioServer.get_bus_peak_volume_right_db(1, 0)) / 1600.0 + 0.25 if experimentalMicLoudness else spectrum.get_magnitude_for_frequency_range(20, 20000).length()
|
||||
|
||||
if playa != null:
|
||||
volumeSensitivity = lerp(volumeSensitivity,0.0,delta*2)
|
||||
|
||||
if volume>volumeLimit:
|
||||
|
|
|
@ -50,13 +50,13 @@ var settings = {
|
|||
"bounce":250,
|
||||
"gravity":1000,
|
||||
"maxFPS":60,
|
||||
"secondsToMicReset":180,
|
||||
"backgroundColor":var_to_str(Color(0.0,0.0,0.0,0.0)),
|
||||
"filtering":false,
|
||||
"costumeKeys":["1","2","3","4","5","6","7","8","9","0"],
|
||||
"blinkSpeed":1.0,
|
||||
"blinkChance":200,
|
||||
"bounceOnCostumeChange":false,
|
||||
"experimentalMicLoudness":false
|
||||
}
|
||||
|
||||
var settingsPath = "user://settings.pngtp"
|
||||
|
|
|
@ -23,6 +23,7 @@ config/icon="res://icon.png"
|
|||
[audio]
|
||||
|
||||
driver/enable_input=true
|
||||
buses/channel_disable_time=0.0
|
||||
|
||||
[autoload]
|
||||
|
||||
|
|
|
@ -7,17 +7,9 @@ func _ready():
|
|||
|
||||
|
||||
func _on_button_pressed():
|
||||
|
||||
if !get_parent().get_parent().get_parent().visible:
|
||||
return
|
||||
|
||||
AudioServer.input_device = micName
|
||||
Global.deleteAllMics()
|
||||
Global.currentMicrophone = null
|
||||
|
||||
get_parent().get_parent().get_parent().visible = false
|
||||
|
||||
await get_tree().create_timer(1.0).timeout
|
||||
Global.createMicrophone()
|
||||
|
||||
|
||||
get_parent().get_parent().get_parent().visible = false
|
||||
|
|
|
@ -38,6 +38,8 @@ func setvalues():
|
|||
label.text = "costume " + str(tag) + " key: \"" + Global.main.costumeKeys[tag-1] + "\""
|
||||
tag += 1
|
||||
|
||||
$experimentalMicLoudness/checkmark.button_pressed = Global.experimentalMicLoudness
|
||||
|
||||
func _on_color_picker_button_color_changed(color):
|
||||
get_viewport().transparent_bg = false
|
||||
RenderingServer.set_default_clear_color(color)
|
||||
|
@ -191,6 +193,11 @@ func _on_costume_check_toggled(button_pressed):
|
|||
Saving.settings["bounceOnCostumeChange"] = button_pressed
|
||||
|
||||
|
||||
func _on_experimental_mic_loudness_toggle(checked):
|
||||
Global.experimentalMicLoudness = checked
|
||||
Saving.settings["experimentalMicLoudness"] = checked
|
||||
|
||||
|
||||
func _process(delta):
|
||||
var g = to_local(get_global_mouse_position())
|
||||
if g.x < 0 or g.y < 0 or g.x > $NinePatchRect.size.x or g.y > $NinePatchRect.size.y:
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue