From 5b86523b4888c4f226ea81f5e5b5bc84022982d3 Mon Sep 17 00:00:00 2001 From: Martyn Date: Wed, 23 Sep 2020 23:09:49 +0200 Subject: [PATCH] Tech demo - record voice whilst playing video --- godot/MicRecord.tscn | 9 ++ godot/PlayVideoRecordAudio.gd | 51 ++++++++++ godot/PlayVideoRecordAudio.tscn | 173 ++++++++++++++++++++++++++++++++ godot/default_env.tres | 16 ++- godot/main_menu.gd | 4 + godot/main_menu.tscn | 88 ++++++++++------ 6 files changed, 309 insertions(+), 32 deletions(-) create mode 100644 godot/PlayVideoRecordAudio.gd create mode 100644 godot/PlayVideoRecordAudio.tscn diff --git a/godot/MicRecord.tscn b/godot/MicRecord.tscn index dfb3054..ceeb144 100644 --- a/godot/MicRecord.tscn +++ b/godot/MicRecord.tscn @@ -37,6 +37,9 @@ margin_top = 100.0 margin_right = 240.0 margin_bottom = 140.0 text = "Record" +__meta__ = { +"_edit_use_anchors_": false +} [node name="SaveButton" type="Button" parent="."] margin_left = 120.0 @@ -61,6 +64,9 @@ margin_right = 420.0 margin_bottom = 140.0 disabled = true text = "Play" +__meta__ = { +"_edit_use_anchors_": false +} [node name="PlayMusic" type="Button" parent="."] margin_left = 120.0 @@ -68,6 +74,9 @@ margin_top = 260.0 margin_right = 240.0 margin_bottom = 300.0 text = "Play Music" +__meta__ = { +"_edit_use_anchors_": false +} [node name="Status" type="Label" parent="."] margin_left = 120.0 diff --git a/godot/PlayVideoRecordAudio.gd b/godot/PlayVideoRecordAudio.gd new file mode 100644 index 0000000..410e857 --- /dev/null +++ b/godot/PlayVideoRecordAudio.gd @@ -0,0 +1,51 @@ +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() diff --git a/godot/PlayVideoRecordAudio.tscn b/godot/PlayVideoRecordAudio.tscn new file mode 100644 index 0000000..8443f18 --- /dev/null +++ b/godot/PlayVideoRecordAudio.tscn @@ -0,0 +1,173 @@ +[gd_scene load_steps=5 format=2] + +[ext_resource path="res://main_menu.gd" type="Script" id=2] +[ext_resource path="res://PlayVideoRecordAudio.gd" type="Script" id=3] +[ext_resource path="res://UI/src/meter.png" type="Texture" id=4] + +[sub_resource type="AudioStreamMicrophone" id=1] + +[node name="Control" type="Control"] +anchor_right = 1.0 +anchor_bottom = 1.0 +margin_right = -6.10352e-05 +rect_pivot_offset = Vector2( -138.227, 18.34 ) +script = ExtResource( 3 ) +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="MarginContainer" type="MarginContainer" parent="."] +anchor_right = 1.0 +anchor_bottom = 1.0 +margin_left = 5.0 +margin_top = 5.0 +margin_right = -5.0 +margin_bottom = -5.0 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer"] +margin_right = 1013.0 +margin_bottom = 590.0 + +[node name="HBoxContainer2" type="HBoxContainer" parent="MarginContainer/VBoxContainer"] +margin_right = 1013.0 +margin_bottom = 20.0 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer/VBoxContainer/HBoxContainer2"] +margin_right = 989.0 +margin_bottom = 20.0 +size_flags_horizontal = 3 + +[node name="RichTextLabel" type="RichTextLabel" parent="MarginContainer/VBoxContainer/HBoxContainer2/VBoxContainer"] +margin_right = 989.0 +margin_bottom = 15.0 +size_flags_horizontal = 3 +bbcode_enabled = true +bbcode_text = "[center]SANG YOA <3 OUT!!![/center]" +text = "SANG YOA <3 OUT!!!" +fit_content_height = true +scroll_active = false + +[node name="Quit" type="Button" parent="MarginContainer/VBoxContainer/HBoxContainer2"] +margin_left = 993.0 +margin_right = 1013.0 +margin_bottom = 20.0 +text = "X" +script = ExtResource( 2 ) + +[node name="HBoxContainer" type="HBoxContainer" parent="MarginContainer/VBoxContainer"] +margin_top = 24.0 +margin_right = 1013.0 +margin_bottom = 305.0 +size_flags_horizontal = 3 +size_flags_vertical = 3 +alignment = 1 + +[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer/VBoxContainer/HBoxContainer"] +margin_right = 1013.0 +margin_bottom = 281.0 +size_flags_horizontal = 3 +size_flags_vertical = 3 +alignment = 1 + +[node name="VideoPlayer" type="VideoPlayer" parent="MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer"] +margin_right = 1013.0 +margin_bottom = 281.0 +size_flags_horizontal = 3 +size_flags_vertical = 3 + +[node name="HBoxContainer3" type="HBoxContainer" parent="MarginContainer/VBoxContainer"] +margin_top = 309.0 +margin_right = 1013.0 +margin_bottom = 590.0 +size_flags_horizontal = 3 +size_flags_vertical = 3 +alignment = 1 + +[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer/VBoxContainer/HBoxContainer3"] +margin_right = 1013.0 +margin_bottom = 281.0 +size_flags_horizontal = 3 +size_flags_vertical = 3 +alignment = 1 + +[node name="RecordButton" type="Button" parent="MarginContainer/VBoxContainer/HBoxContainer3/VBoxContainer"] +margin_top = 89.0 +margin_right = 1013.0 +margin_bottom = 109.0 +text = "Record" + +[node name="PlayButton" type="Button" parent="MarginContainer/VBoxContainer/HBoxContainer3/VBoxContainer"] +margin_top = 113.0 +margin_right = 1013.0 +margin_bottom = 133.0 +disabled = true +text = "Play" + +[node name="Status" type="RichTextLabel" parent="MarginContainer/VBoxContainer/HBoxContainer3/VBoxContainer"] +margin_top = 137.0 +margin_right = 1013.0 +margin_bottom = 152.0 +fit_content_height = true + +[node name="HBoxContainer" type="HBoxContainer" parent="MarginContainer/VBoxContainer/HBoxContainer3/VBoxContainer"] +margin_top = 156.0 +margin_right = 1013.0 +margin_bottom = 172.0 + +[node name="Playbacklabel" type="RichTextLabel" parent="MarginContainer/VBoxContainer/HBoxContainer3/VBoxContainer/HBoxContainer"] +margin_right = 110.0 +margin_bottom = 15.0 +rect_min_size = Vector2( 110, 0 ) +size_flags_vertical = 0 +visible_characters = 28 +text = "Playback meter : " +fit_content_height = true +scroll_active = false + +[node name="PlaybackMeter" type="TextureProgress" parent="MarginContainer/VBoxContainer/HBoxContainer3/VBoxContainer/HBoxContainer"] +margin_left = 114.0 +margin_right = 1013.0 +margin_bottom = 16.0 +rect_min_size = Vector2( 0, 16 ) +size_flags_horizontal = 3 +size_flags_vertical = 0 +texture_progress = ExtResource( 4 ) +nine_patch_stretch = true + +[node name="HBoxContainer2" type="HBoxContainer" parent="MarginContainer/VBoxContainer/HBoxContainer3/VBoxContainer"] +margin_top = 176.0 +margin_right = 1013.0 +margin_bottom = 192.0 + +[node name="Recordlabel" type="RichTextLabel" parent="MarginContainer/VBoxContainer/HBoxContainer3/VBoxContainer/HBoxContainer2"] +margin_right = 110.0 +margin_bottom = 16.0 +rect_min_size = Vector2( 110, 0 ) +text = "Record meter :" +fit_content_height = true + +[node name="RecordMeter" type="TextureProgress" parent="MarginContainer/VBoxContainer/HBoxContainer3/VBoxContainer/HBoxContainer2"] +margin_left = 114.0 +margin_right = 1013.0 +margin_bottom = 16.0 +rect_min_size = Vector2( 0, 16 ) +size_flags_horizontal = 3 +size_flags_vertical = 0 +texture_progress = ExtResource( 4 ) +nine_patch_stretch = true + +[node name="AudioStreamRecorder" type="AudioStreamPlayer" parent="."] +stream = SubResource( 1 ) +autoplay = true +bus = "Record" + +[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."] +[connection signal="pressed" from="MarginContainer/VBoxContainer/HBoxContainer2/Quit" to="MarginContainer/VBoxContainer/HBoxContainer2/Quit" method="_on_Quit_pressed"] +[connection signal="pressed" from="MarginContainer/VBoxContainer/HBoxContainer3/VBoxContainer/RecordButton" to="." method="_on_RecButton_pressed"] +[connection signal="pressed" from="MarginContainer/VBoxContainer/HBoxContainer3/VBoxContainer/PlayButton" to="." method="_on_PlayButton_pressed"] diff --git a/godot/default_env.tres b/godot/default_env.tres index 6715205..63922b4 100644 --- a/godot/default_env.tres +++ b/godot/default_env.tres @@ -1,14 +1,24 @@ -[gd_resource type="AudioBusLayout" load_steps=2 format=2] +[gd_resource type="AudioBusLayout" load_steps=4 format=2] -[sub_resource type="AudioEffectRecord" id=1] +[sub_resource type="AudioEffectSpectrumAnalyzer" id=1] +resource_name = "SpectrumAnalyzer" + +[sub_resource type="AudioEffectRecord" id=4] resource_name = "Record" +[sub_resource type="AudioEffectSpectrumAnalyzer" id=3] +resource_name = "SpectrumAnalyzer" + [resource] +bus/0/effect/0/effect = SubResource( 1 ) +bus/0/effect/0/enabled = true bus/1/name = "Record" bus/1/solo = false bus/1/mute = true bus/1/bypass_fx = false bus/1/volume_db = 0.0 bus/1/send = "Master" -bus/1/effect/0/effect = SubResource( 1 ) +bus/1/effect/0/effect = SubResource( 4 ) bus/1/effect/0/enabled = true +bus/1/effect/1/effect = SubResource( 3 ) +bus/1/effect/1/enabled = true diff --git a/godot/main_menu.gd b/godot/main_menu.gd index e743cfb..c33d270 100644 --- a/godot/main_menu.gd +++ b/godot/main_menu.gd @@ -25,3 +25,7 @@ func _on_Button_pressed(): func _on_MicTest_pressed(): get_tree().change_scene("res://MicRecord.tscn") + + +func _on_DownloadPlayVid2_pressed(): + get_tree().change_scene("res://PlayVideoRecordAudio.tscn") diff --git a/godot/main_menu.tscn b/godot/main_menu.tscn index fffa381..8848512 100644 --- a/godot/main_menu.tscn +++ b/godot/main_menu.tscn @@ -10,25 +10,36 @@ __meta__ = { "_edit_use_anchors_": false } -[node name="HBoxContainer" type="HBoxContainer" parent="."] +[node name="MarginContainer" type="MarginContainer" parent="."] anchor_right = 1.0 -anchor_bottom = 0.033 -margin_bottom = 0.200001 -alignment = 1 +anchor_bottom = 1.0 +margin_left = 5.0 +margin_top = 5.0 +margin_right = -5.0 +margin_bottom = -5.0 __meta__ = { "_edit_use_anchors_": false } -[node name="VBoxContainer" type="VBoxContainer" parent="HBoxContainer"] -margin_right = 1000.0 +[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer"] +margin_right = 1014.0 +margin_bottom = 590.0 + +[node name="HBoxContainer2" type="HBoxContainer" parent="MarginContainer/VBoxContainer"] +margin_right = 1014.0 +margin_bottom = 20.0 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer/VBoxContainer/HBoxContainer2"] +margin_right = 990.0 margin_bottom = 20.0 size_flags_horizontal = 3 -alignment = 1 -[node name="RichTextLabel" type="RichTextLabel" parent="HBoxContainer/VBoxContainer"] -margin_top = 2.0 -margin_right = 1000.0 -margin_bottom = 17.0 +[node name="RichTextLabel" type="RichTextLabel" parent="MarginContainer/VBoxContainer/HBoxContainer2/VBoxContainer"] +margin_right = 990.0 +margin_bottom = 15.0 size_flags_horizontal = 3 bbcode_enabled = true bbcode_text = "[center]MAIN MENU[/center]" @@ -36,32 +47,51 @@ text = "MAIN MENU" fit_content_height = true scroll_active = false -[node name="Quit" type="Button" parent="HBoxContainer"] -margin_left = 1004.0 -margin_right = 1024.0 +[node name="Quit" type="Button" parent="MarginContainer/VBoxContainer/HBoxContainer2"] +margin_left = 994.0 +margin_right = 1014.0 margin_bottom = 20.0 text = "X" script = ExtResource( 1 ) -[node name="GridContainer" type="GridContainer" parent="."] -anchor_right = 1.0 -anchor_bottom = 0.815 -margin_top = 50.0 -margin_bottom = -3.05176e-05 +[node name="GridContainer" type="GridContainer" parent="MarginContainer/VBoxContainer"] +margin_top = 24.0 +margin_right = 1014.0 +margin_bottom = 111.0 __meta__ = { "_edit_use_anchors_": false } -[node name="DownloadPlayVid" type="Button" parent="GridContainer"] -margin_right = 109.0 -margin_bottom = 20.0 +[node name="RichTextLabel2" type="RichTextLabel" parent="MarginContainer/VBoxContainer/GridContainer"] +margin_right = 1014.0 +margin_bottom = 15.0 +size_flags_horizontal = 3 +bbcode_enabled = true +bbcode_text = "Complete Test Scenarios in order, 2 depends on 1 having worked..." +text = "Complete Test Scenarios in order, 2 depends on 1 having worked..." +fit_content_height = true +scroll_active = false + +[node name="DownloadPlayVid" type="Button" parent="MarginContainer/VBoxContainer/GridContainer"] +margin_top = 19.0 +margin_right = 1014.0 +margin_bottom = 39.0 +size_flags_horizontal = 3 text = "Test scenario 1" -[node name="MicTest" type="Button" parent="GridContainer"] -margin_top = 24.0 -margin_right = 109.0 -margin_bottom = 44.0 +[node name="DownloadPlayVid2" type="Button" parent="MarginContainer/VBoxContainer/GridContainer"] +margin_top = 43.0 +margin_right = 1014.0 +margin_bottom = 63.0 +size_flags_horizontal = 3 +text = "Test scenario 2" + +[node name="MicTest" type="Button" parent="MarginContainer/VBoxContainer/GridContainer"] +margin_top = 67.0 +margin_right = 1014.0 +margin_bottom = 87.0 text = "Mic Test" -[connection signal="pressed" from="HBoxContainer/Quit" to="HBoxContainer/Quit" method="_on_Quit_pressed"] -[connection signal="pressed" from="GridContainer/DownloadPlayVid" to="." method="_on_Button_pressed"] -[connection signal="pressed" from="GridContainer/MicTest" to="." method="_on_MicTest_pressed"] +[connection signal="pressed" from="MarginContainer/VBoxContainer/HBoxContainer2/Quit" to="MarginContainer/VBoxContainer/HBoxContainer2/Quit" method="_on_Quit_pressed"] +[connection signal="pressed" from="MarginContainer/VBoxContainer/GridContainer/DownloadPlayVid" to="." method="_on_Button_pressed"] +[connection signal="pressed" from="MarginContainer/VBoxContainer/GridContainer/DownloadPlayVid2" to="." method="_on_DownloadPlayVid2_pressed"] +[connection signal="pressed" from="MarginContainer/VBoxContainer/GridContainer/MicTest" to="." method="_on_MicTest_pressed"]