Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions FFTStreamHandlerFields.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using FrooxEngine;
using Elements.Assets;
using CSCore.DSP;
using Elements.Core;

namespace Resonance;

Expand Down Expand Up @@ -32,4 +31,4 @@ public partial class FFTStreamHandler(UserAudioStream<StereoSample> stream, FFTS
public const string BINSIZE_VARIABLE = "fft_bin_size";
public const string NORMALIZED_VARIABLE = "fft_data_normalized";
public static readonly float[] BAND_RANGES = { 20, 60, 250, 500, 2000, 4000, 6000, 20000 };
}
}
41 changes: 33 additions & 8 deletions Resonance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,36 @@ public static void OnAwake_Postfix(UserAudioStream<StereoSample> __instance)
return;


__instance.RunSynchronously(() => {
__instance.RunSynchronously(() =>
{
int index = __instance.TargetDeviceIndex ?? -1;

int sampleRate = index > 0 ? __instance.AudioSystem.AudioInputs[index].SampleRate : __instance.AudioSystem.DefaultAudioInput.SampleRate;


//44100;
int sampleRate;

// Check if we're using SDL. Either non-Windows platform or ForceSDLAudio launch argument
// Filter out Steam Voice as a special case. Unless it's the only and Default option somehow.
Type? audioInputType = __instance.AudioSystem.AudioInputCount > 1 ?
__instance.AudioSystem.AudioInputs.First(ain => ain.DeviceID != "SteamVoice").GetType() :
__instance.AudioSystem.DefaultAudioInput.GetType();

if (audioInputType.Name != "SDLRecordingDevice")
{
sampleRate = index > 0 ? __instance.AudioSystem.AudioInputs[index].SampleRate : __instance.AudioSystem.DefaultAudioInput.SampleRate;
}
else
{
// We need to cast AudioInput to SDLRecordingDevice to get Format.spec.Freq and set sampleRate.
Resonance.Msg("AudioInput is actually SDLRecordingDevice on Linux. Casting and getting sample rate...");

var selectedInput = index > 0 ? __instance.AudioSystem.AudioInputs[index] : __instance.AudioSystem.DefaultAudioInput;

ValueTuple<SDL3.SDL.AudioSpec, int> sdlRecordingDevice_Format =
(ValueTuple<SDL3.SDL.AudioSpec, int>)audioInputType.GetProperty("Format").GetValue(selectedInput);

sampleRate = sdlRecordingDevice_Format.Item1.Freq;
}

FFTStreamSettings settings =
new
(
Expand All @@ -52,7 +77,7 @@ public static void OnAwake_Postfix(UserAudioStream<StereoSample> __instance)
AutoGain,
Quantize_Bins
);


FFTStreamHandler streamHandler = new(__instance, settings);
streamHandler.Setup();
Expand All @@ -64,7 +89,7 @@ public static void OnAwake_Postfix(UserAudioStream<StereoSample> __instance)
{
audioStream.BufferSize.Value = 12000;
audioStream.MinimumBufferDelay.Value = 0.05f;
}
}

__instance.Destroyed += FFTStreamHandler.Destroy;
});
Expand All @@ -77,9 +102,9 @@ public static void OnNewAudioData_Postfix(UserAudioStream<StereoSample> __instan
var world = __instance.World;
if (world.Focus != World.WorldFocus.Focused || __instance.LocalUser.IsSilenced || (ContactsDialog.RecordingVoiceMessage && ___lastDeviceIndex == __instance.AudioSystem.DefaultAudioInputIndex))
return;

if (FFTStreamHandler.FFTDict.TryGetValue(__instance, out FFTStreamHandler handler))
handler.UpdateFFTData(buffer);
}
}
}
}
27 changes: 15 additions & 12 deletions Resonance.csproj
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<TargetFramework>net9</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>preview</LangVersion>
<Version>1.0.3</Version>
<LangVersion>latest</LangVersion>
<Version>1.0.4</Version>
<AssemblyVersion>$(Version)</AssemblyVersion>
<Authors>Cyro</Authors>
<Product>Resonance FFT</Product>
<Description>Realtime networked FFT support for Resonite</Description>
<Copyright>Copyright (c) 2023 Riley Fields</Copyright>
</PropertyGroup>

<!--This will test for the default Steam installation paths for Resonite on Windows and Linux.-->
<PropertyGroup Condition="'$(ResonitePath)'==''">
<ResonitePath Condition="Exists('C:\Program Files (x86)\Steam\steamapps\common\Resonite\')">C:\Program Files (x86)\Steam\steamapps\common\Resonite\</ResonitePath>
<ResonitePath Condition="'$(OS)' == 'Windows_NT' and Exists('C:\Program Files (x86)\Steam\steamapps\common\Resonite\')">C:\Program Files (x86)\Steam\steamapps\common\Resonite\</ResonitePath>
<ResonitePath Condition="'$(OS)' != 'Windows_NT' and Exists('$(HOME)/.local/share/Steam/steamapps/common/Resonite/')">$(HOME)/.local/share/Steam/steamapps/common/Resonite/</ResonitePath>
<!--If neither path above exists, you can define your custom Resonite install directory here -->
<ResonitePath Condition="'$(ResonitePath)'==''">/Custom/Resonite/Install/Path</ResonitePath>
</PropertyGroup>

<ItemGroup>
Expand All @@ -27,25 +31,24 @@
<HintPath Condition="Exists('$(ResonitePath)Libraries\0Harmony.dll')">$(ResonitePath)Libraries\0Harmony.dll</HintPath>
</Reference>
<Reference Include="FrooxEngine">
<HintPath>$(ResonitePath)Resonite_Data\Managed\FrooxEngine.dll</HintPath>
<HintPath>$(ResonitePath)FrooxEngine.dll</HintPath>
</Reference>
<Reference Include="Elements.Core">
<HintPath>$(ResonitePath)Resonite_Data\Managed\Elements.Core.dll</HintPath>
<HintPath>$(ResonitePath)Elements.Core.dll</HintPath>
</Reference>
<Reference Include="Elements.Assets">
<HintPath>$(ResonitePath)Resonite_Data\Managed\Elements.Assets.dll</HintPath>
<HintPath>$(ResonitePath)Elements.Assets.dll</HintPath>
</Reference>
<Reference Include="CSCore">
<HintPath>$(ResonitePath)Resonite_Data\Managed\CSCore.dll</HintPath>
<HintPath>$(ResonitePath)CSCore.dll</HintPath>
</Reference>
<Reference Include="SDL3">
<HintPath>$(ResonitePath)SDL3-CS.dll</HintPath>
</Reference>
</ItemGroup>

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<!--Copy SourceFiles="$(OutDir)$(TargetFileName)" DestinationFolder="$(ResonitePath)rml_mods" ContinueOnError="true" /-->
<Copy SourceFiles="$(OutDir)$(TargetFileName)" DestinationFolder="$(OutDir)Result" ContinueOnError="true" />
</Target>

<ItemGroup>
<PackageReference Include="System.Memory" Version="4.5.5" />
</ItemGroup>
</Project>