Skip to content

Commit cf1fcf7

Browse files
Added spectrum output
1 parent 2a1cebf commit cf1fcf7

File tree

4 files changed

+94
-2
lines changed

4 files changed

+94
-2
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<UserControl
2+
x:Class="VBAudioRouter.Controls.SpectrumNodeControl"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:local="using:VBAudioRouter"
6+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
7+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:controls="using:VBAudioRouter.Controls"
8+
mc:Ignorable="d"
9+
xmlns:visualizer="using:AudioVisualizer">
10+
11+
<Grid Background="#3F3F3F" RequestedTheme="Dark">
12+
<Grid.ColumnDefinitions>
13+
<ColumnDefinition Width="15" />
14+
<ColumnDefinition Width="*" />
15+
<ColumnDefinition Width="15" />
16+
</Grid.ColumnDefinitions>
17+
<StackPanel Grid.Column="0">
18+
<controls:ConnectorControl x:Name="IngoingConnectorInternal" Margin="0,5,0,5" IsOutgoing="False">
19+
<controls:ConnectorControl.RenderTransform>
20+
<CompositeTransform TranslateX="-18" />
21+
</controls:ConnectorControl.RenderTransform>
22+
</controls:ConnectorControl>
23+
</StackPanel>
24+
<StackPanel Grid.Column="1">
25+
<visualizer:SpectrumVisualizer Width="400" Height="200" x:Name="SpectrumVisualizer" UnlitElement="Transparent" />
26+
</StackPanel>
27+
</Grid>
28+
</UserControl>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
Imports AudioVisualizer
2+
Imports VBAudioRouter.AudioGraphControl
3+
Imports Windows.Devices.Enumeration
4+
Imports Windows.Media.Audio
5+
Imports Windows.Media.Devices
6+
7+
Namespace Controls
8+
9+
Public NotInheritable Class SpectrumNodeControl
10+
Inherits UserControl
11+
Implements IAudioNodeControl
12+
13+
#Region "Identity"
14+
15+
Public ReadOnly Property NodeType As NodeTypeEnum Implements IAudioNodeControl.NodeType
16+
Get
17+
Return NodeTypeEnum.Output
18+
End Get
19+
End Property
20+
Public Property Canvas As Canvas Implements IAudioNodeControl.Canvas
21+
Public ReadOnly Property BaseAudioNode As IAudioNode Implements IAudioNodeControl.BaseAudioNode
22+
Public ReadOnly Property OutgoingConnector As ConnectorControl = Nothing Implements IAudioNodeControl.OutgoingConnector
23+
#End Region
24+
25+
Public Async Function Initialize(graph As AudioGraph) As Task Implements IAudioNodeControl.Initialize
26+
_BaseAudioNode = graph.CreateSubmixNode()
27+
28+
' https://github.com/clarkezone/audiovisualizer/blob/47938f7cf592daedd705c125b1e218f93d0bbc4b/samples/VisualizationPlayer/AudioNodePage.xaml.cs#L64
29+
Dim _source As PlaybackSource = PlaybackSource.CreateFromAudioNode(BaseAudioNode)
30+
Dim _converter As New SourceConverter()
31+
_converter.Source = _source.Source
32+
_converter.MinFrequency = 110.0F ' Note A2
33+
_converter.MaxFrequency = 3520.0F ' Note A7
34+
_converter.FrequencyCount = 12 * 5 * 5 ' 5 octaves, 5 bars per note
35+
_converter.FrequencyScale = ScaleType.Logarithmic
36+
_converter.SpectrumRiseTime = TimeSpan.FromMilliseconds(20)
37+
_converter.SpectrumFallTime = TimeSpan.FromMilliseconds(200)
38+
_converter.RmsRiseTime = TimeSpan.FromMilliseconds(20) ' Use RMS To gate noise, fast rise slow fall
39+
_converter.RmsFallTime = TimeSpan.FromMilliseconds(500)
40+
_converter.ChannelCount = 1
41+
SpectrumVisualizer.Source = _converter
42+
End Function
43+
44+
Public Sub OnStateChanged(state As GraphState) Implements IAudioNodeControl.OnStateChanged : End Sub
45+
End Class
46+
47+
End Namespace

VBAudioRouter/MainPage.xaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
<MenuFlyoutItem Text="File" Tag="FileInputNodeControl" Click="MenuFlyoutItem_Click" />
3232
<MenuFlyoutItem Text="TTS" Tag="TextToSpeechInputNodeControl" Click="MenuFlyoutItem_Click" />
3333
</MenuFlyoutSubItem>
34+
<MenuFlyoutSeparator />
3435
<MenuFlyoutSubItem Text="Effects">
3536
<MenuFlyoutItem Text="Equalizer" Tag="EQNodeControl" Click="MenuFlyoutItem_Click" />
3637
<MenuFlyoutItem Text="Reverb" Tag="ReverbNodeControl" Click="MenuFlyoutItem_Click" />
@@ -40,12 +41,18 @@
4041
<MenuFlyoutSubItem Text="Transforms">
4142
<MenuFlyoutItem Text="Gain" Tag="GainNodeControl" Click="MenuFlyoutItem_Click" />
4243
</MenuFlyoutSubItem>
44+
<MenuFlyoutSeparator />
45+
<MenuFlyoutSubItem Text="Output">
46+
<MenuFlyoutItem Text="Device" IsEnabled="False" />
47+
<MenuFlyoutItem Text="File" IsEnabled="False" />
48+
<MenuFlyoutItem Text="Spectrum" Tag="SpectrumNodeControl" Click="MenuFlyoutItem_Click" />
49+
</MenuFlyoutSubItem>
4350
</MenuFlyout>
4451
</Grid.ContextFlyout>
4552
<controls1:NodeControl Title="Output" TitleBrush="{StaticResource NodeTitleBarColor}" VerticalAlignment="Top" HorizontalAlignment="Left">
4653
<controls1:OutputNodeControl Canvas="{x:Bind ConnectionCanvas}" x:Name="DefaultOutputNode" />
4754
</controls1:NodeControl>
48-
</Grid>
55+
</Grid>
4956
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="10" CornerRadius="5" Background="{StaticResource MenuBackground}">
5057
<AppBarButton x:Name="PlayButton" Icon="Play" Foreground="{StaticResource PositiveColor}" LabelPosition="Collapsed" />
5158
<AppBarButton x:Name="StopButton" Icon="Stop" Foreground="{StaticResource NegativeColor}" IsEnabled="False" LabelPosition="Collapsed" />

VBAudioRouter/VBAudioRouter.vbproj

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@
150150
<Compile Include="Controls\EchoNodeControl.xaml.vb">
151151
<DependentUpon>EchoNodeControl.xaml</DependentUpon>
152152
</Compile>
153+
<Compile Include="Controls\SpectrumNodeControl.xaml.vb">
154+
<DependentUpon>SpectrumNodeControl.xaml</DependentUpon>
155+
</Compile>
153156
<Compile Include="Controls\TextToSpeechInputNodeControl.xaml.vb">
154157
<DependentUpon>TextToSpeechInputNodeControl.xaml</DependentUpon>
155158
</Compile>
@@ -267,6 +270,10 @@
267270
<Generator>MSBuild:Compile</Generator>
268271
<SubType>Designer</SubType>
269272
</Page>
273+
<Page Include="Controls\SpectrumNodeControl.xaml">
274+
<Generator>MSBuild:Compile</Generator>
275+
<SubType>Designer</SubType>
276+
</Page>
270277
<Page Include="Controls\TextToSpeechInputNodeControl.xaml">
271278
<Generator>MSBuild:Compile</Generator>
272279
<SubType>Designer</SubType>
@@ -342,7 +349,10 @@
342349
<Version>7.1.1</Version>
343350
</PackageReference>
344351
<PackageReference Include="Microsoft.UI.Xaml">
345-
<Version>2.7.0</Version>
352+
<Version>2.8.0-prerelease.210927001</Version>
353+
</PackageReference>
354+
<PackageReference Include="UWPAudioVisualizer">
355+
<Version>1.0.38</Version>
346356
</PackageReference>
347357
</ItemGroup>
348358
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' ">

0 commit comments

Comments
 (0)