From 282a0a07c3fd37f86d81952ae565f94f71748a8f Mon Sep 17 00:00:00 2001 From: Julian Todd Date: Sat, 14 Dec 2024 20:11:59 +0000 Subject: [PATCH] stereo slip commit --- example/radiomqtt/member.gd | 6 ++++- example/radiomqtt/member.tscn | 6 ++++- example/radiomqtt/radiomqtt.gd | 41 ++++++++++++++++++++++++++++---- example/radiomqtt/radiomqtt.tscn | 10 ++++++-- 4 files changed, 54 insertions(+), 9 deletions(-) diff --git a/example/radiomqtt/member.gd b/example/radiomqtt/member.gd index debbfd4..cb0bdb5 100644 --- a/example/radiomqtt/member.gd +++ b/example/radiomqtt/member.gd @@ -169,7 +169,11 @@ func _process(delta): else: while audiostreamgeneratorplayback.get_frames_available() > audiosamplesize: - if len(audiopacketsbuffer) != 0: + if resampledpacketsbuffer != null and len(resampledpacketsbuffer) != 0: + var resampledaudiochunk = resampledpacketsbuffer.pop_front() + var audiochunk = audiostreamopuschunked.resample_chunk(resampledaudiochunk) + audiostreamgeneratorplayback.push_buffer(audiochunk) + elif len(audiopacketsbuffer) != 0: audiostreamgeneratorplayback.push_buffer(audiopacketsbuffer.pop_front()) elif len(opuspacketsbuffer) != 0: const fec = 0 diff --git a/example/radiomqtt/member.tscn b/example/radiomqtt/member.tscn index 8833c9e..01129d8 100644 --- a/example/radiomqtt/member.tscn +++ b/example/radiomqtt/member.tscn @@ -1,8 +1,11 @@ -[gd_scene load_steps=5 format=3 uid="uid://c1ibcb1toyerh"] +[gd_scene load_steps=6 format=3 uid="uid://c1ibcb1toyerh"] [ext_resource type="Script" path="res://radiomqtt/member.gd" id="1_o3hks"] [ext_resource type="Texture2D" uid="uid://cvyjsyigutxbh" path="res://icon.png" id="2_atirx"] +[sub_resource type="AudioStreamGenerator" id="AudioStreamGenerator_t0bqw"] +resource_local_to_scene = true + [sub_resource type="Shader" id="Shader_022wp"] code = "// NOTE: Shader automatically converted from Godot Engine 4.3.beta's CanvasItemMaterial. @@ -35,6 +38,7 @@ color = Color(0.423529, 0, 0.423529, 1) script = ExtResource("1_o3hks") [node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."] +stream = SubResource("AudioStreamGenerator_t0bqw") bus = &"SpeechBus" [node name="Label" type="Label" parent="."] diff --git a/example/radiomqtt/radiomqtt.gd b/example/radiomqtt/radiomqtt.gd index d21bb46..885aabd 100644 --- a/example/radiomqtt/radiomqtt.gd +++ b/example/radiomqtt/radiomqtt.gd @@ -106,6 +106,8 @@ func _ready(): SelfMember.audiobufferregulationtime = 3600.0 + + func rechunkrecordedchunks(orgsamples, newsamplesize): assert (newsamplesize > 0) var res = [ ] @@ -291,6 +293,8 @@ func _input(event): func _process(_delta): + #Dmicrophonestreamplayback.mix() + var talking = $HBoxBigButtons/VBoxPTT/PTT.button_pressed if talking: $VBoxPlayback/HBoxPlaycount/GridContainer/TimeSecs.text = "%.1f" % ((Time.get_ticks_msec() - talkingstarttime)*0.001) @@ -394,6 +398,33 @@ func endtalking(): $MQTTnetwork.transportaudiopacketjson({"framecount":len(recordedsamples)}) print("Talked for ", (Time.get_ticks_msec() - talkingstarttime)*0.001, " seconds") + + +func duplicatewithslippage(audiopackets, lframeslip): + var frameslip = abs(lframeslip) + var bleftside = (lframeslip >= 0) + var slippedaudiopackets = [ ] + for i in range(1, len(audiopackets)): + var prevpacket = audiopackets[i-1] + var packet = audiopackets[i] + var dpacket = packet.duplicate() + var n = len(packet) + if bleftside: + for j in range(n): + if j < frameslip: + dpacket[j].x = prevpacket[n - frameslip + j].x + else: + dpacket[j].x = packet[j - frameslip].x + else: + for j in range(n): + if j < frameslip: + dpacket[j].y = prevpacket[n - frameslip + j].y + else: + dpacket[j].y = packet[j - frameslip].y + slippedaudiopackets.push_back(dpacket) + return slippedaudiopackets + + func _on_play_pressed(): if audioeffectpitchshift != null: var speedup = $VBoxPlayback/HBoxStream/StreamSpeedup.value @@ -408,11 +439,11 @@ func _on_play_pressed(): SelfMember.opuspacketsbuffer = recordedopuspackets.duplicate() elif recordedresampledpackets != null: SelfMember.processheaderpacket(h) - SelfMember.resampledpacketsbuffer = recordedresampledpackets.duplicate() - var resampledaudiochunk_blank = PackedVector2Array() - resampledaudiochunk_blank.resize(h["opusframesize"]) - for i in range(5): - SelfMember.audiostreamopuschunked.resample_chunk(resampledaudiochunk_blank) + var stereoframeslip = $VBoxPlayback/HBoxStream/StereoFrameSlip.value + if stereoframeslip == 0: + SelfMember.resampledpacketsbuffer = recordedresampledpackets.duplicate() + else: + SelfMember.resampledpacketsbuffer = duplicatewithslippage(recordedresampledpackets, stereoframeslip) elif recordedsamples and SelfMember.audiostreamgeneratorplayback != null: SelfMember.audiosamplesize = audiosamplesize diff --git a/example/radiomqtt/radiomqtt.tscn b/example/radiomqtt/radiomqtt.tscn index df8cc9c..7413c3d 100644 --- a/example/radiomqtt/radiomqtt.tscn +++ b/example/radiomqtt/radiomqtt.tscn @@ -526,7 +526,7 @@ text = "Play" [node name="LabelSamplerate" type="Label" parent="VBoxPlayback/HBoxStream"] layout_mode = 2 -text = "sample rate" +text = "sample" [node name="OutSampleRate" type="SpinBox" parent="VBoxPlayback/HBoxStream"] custom_minimum_size = Vector2(95, 0) @@ -539,7 +539,7 @@ suffix = "Hz" [node name="LabelMixrate" type="Label" parent="VBoxPlayback/HBoxStream"] layout_mode = 2 -text = "mix rate" +text = "mix" [node name="MixRate" type="SpinBox" parent="VBoxPlayback/HBoxStream"] custom_minimum_size = Vector2(95, 0) @@ -564,6 +564,12 @@ max_value = 3.0 step = 0.1 value = 1.0 +[node name="StereoFrameSlip" type="SpinBox" parent="VBoxPlayback/HBoxStream"] +layout_mode = 2 +tooltip_text = "stereo frame slip" +min_value = -900.0 +max_value = 900.0 + [node name="HSeparator5" type="HSeparator" parent="."] custom_minimum_size = Vector2(0, 20) layout_mode = 2