52 lines
2.2 KiB
GDScript3
52 lines
2.2 KiB
GDScript3
extends Control
|
|
|
|
|
|
# Declare member variables here. Examples:
|
|
# var a = 2
|
|
# var b = "text"
|
|
|
|
var spectrum_play
|
|
var spectrum_record
|
|
var recorder
|
|
var recording
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready():
|
|
$MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer/VideoPlayer.set_stream(load(OS.get_user_data_dir()+"/converted.webm"))
|
|
var idx = AudioServer.get_bus_index("Record")
|
|
recorder = AudioServer.get_bus_effect(idx, 0)
|
|
spectrum_play = AudioServer.get_bus_effect_instance(0,0)
|
|
spectrum_record = AudioServer.get_bus_effect_instance(1,1)
|
|
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
func _process(delta):
|
|
var magnitude: float = spectrum_play.get_magnitude_for_frequency_range(0,11050.0).length()
|
|
var energy = clamp((60 + linear2db(magnitude)) / 60, 0, 1)
|
|
$MarginContainer/VBoxContainer/HBoxContainer3/VBoxContainer/HBoxContainer/PlaybackMeter.value = energy * 100
|
|
magnitude = spectrum_record.get_magnitude_for_frequency_range(0,11050.0).length()
|
|
energy = clamp((60 + linear2db(magnitude)) / 60, 0, 1)
|
|
$MarginContainer/VBoxContainer/HBoxContainer3/VBoxContainer/HBoxContainer2/RecordMeter.value = energy * 100
|
|
|
|
func _on_RecButton_pressed():
|
|
if recorder.is_recording_active():
|
|
$MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer/VideoPlayer.stop()
|
|
recording = recorder.get_recording()
|
|
$MarginContainer/VBoxContainer/HBoxContainer3/VBoxContainer/PlayButton.disabled = false
|
|
recorder.set_recording_active(false)
|
|
$MarginContainer/VBoxContainer/HBoxContainer3/VBoxContainer/RecordButton.text = "Record"
|
|
$MarginContainer/VBoxContainer/HBoxContainer3/VBoxContainer/Status.text = ""
|
|
else:
|
|
$MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer/VideoPlayer.play()
|
|
$MarginContainer/VBoxContainer/HBoxContainer3/VBoxContainer/PlayButton.disabled = true
|
|
recorder.set_recording_active(true)
|
|
$MarginContainer/VBoxContainer/HBoxContainer3/VBoxContainer/RecordButton.text = "Stop"
|
|
$MarginContainer/VBoxContainer/HBoxContainer3/VBoxContainer/Status.text = "Recording..."
|
|
|
|
|
|
func _on_PlayButton_pressed():
|
|
var data = recording.get_data()
|
|
$AudioStreamPlayer.stream = recording
|
|
$MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer/VideoPlayer.play()
|
|
$AudioStreamPlayer.play()
|