Skip to content

A UWP audio visualization component that provides a stream analyzer and XAML visualization controls for displaying VU and spectrum meters powered by Win2D

License

Notifications You must be signed in to change notification settings

clarkezone/audiovisualizer

Repository files navigation

Build status

Build status

Target Branch Status Recommended Nuget packages version
Current Release master Build status NuGet

Introduction

Image

The AudioAnalyzer UWP extension DLL contains a MF component and companion XAML controls that can provide realtime audio analysis information for visualization and other purposes. The library contains prebuilt controls implementing VU meters, a spectrum analyzer as well as a control that has a custom draw capability. This project is a continuation of the work here and originally here.

To play with a demo app the shows the controls in action, grab this app from the Windows Store.

What's new

You can now analyze media files without playing them.

Version 1.0.8

AudioSourceReader class has been added that enables reading audio frames from media file, decompress them if needed and pass on to AudioAnalyzer or use them on their own without the need to play media file. Both video and audio files are supported as long as appropriate codecs are installed.

Version 1.0.7

(click image to play video)

  • You can now insert analyzer both into MediaPlayer and AudioGraph pipeline
  • AudioAnalyzer itself is exposed so you can use it to generate data on audio frames from file as an example
  • There is a new data source SourceConverter that helps reshaping the visualization data and applying physics (combine channels, convert spectrum to logarithmic scale, apply rise and fall times)
  • There are 4 customizable built-in controls to display visualization
    • AnalogVUMeter mimics an analog VU meter with a scale and dial and takes input from RMS
    • DiscreteVUBar is a stacked bar of elements that lit up based on RMS and Peak data
    • SpectrumVisualizer is a multicolumn stacked bar of elements that take input from the spectrum data
    • CustomVisualizer is a Win2D custom draw control that allows to draw the visualization frame by frame

To learn more browse the documentation

Getting started

Installing the library

Download and install the AudioAnalyzer nuget package. Note this will also add a reference to Win2D to your project.

Install-Package UWPAudioVisualizer

for convenient use add namespace statement to your C# code as:

using AudioVisualizer;

add namespace statement and built in controls to your XAML code as:

<Page
    x:Class="App4.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:visualizer="using:AudioVisualizer"
    mc:Ignorable="d">

    <Grid>
        <StackPanel>
            <visualizer:DiscreteVUBar />
            <visualizer:CustomVisualizer />
        </StackPanel>
    </Grid>
</Page>

Initializing the source

First you need to create the analyzer object, that implements IVisualizationSource interface which is basis to retrieve audio data.

To create visualization source you need to create PlaybackSource, you can create this from MediaPlayer or from AudioNode or MediaPlayer. With AudioNode the source will be available immediately however for MediaPlayer it will be created only when MediaPlayer will open source and start playing. When opening a new file a new source will be created - this means that if you use PlaybackSource with MediaPlayer you will need to monitor the SourceChanged event and assign the new source to the controls you are using.

partial class VisualizationPage : Page
{
    MediaPlayer _player;
    AudioVisualizer.PlaybackSource _source;

    public VisualizationPage()
    {
        _player = new MediaPlayer();
        _source = new PlaybackSource.CreateFromMediaPlayer(_player);
        _source.SourceChanged += Playback_SourceChanged;
	}

	private void Playback_SourceChanged(object sender, IVisualizationSource source)
    {
		vuMeter.Source = source;
		spectrumDisplay.Source = source;
		playPositionDisplay.Source = source;
    }

	private void Page_Loaded(object sender, RoutedEventArgs e)
    {
		vuMeter.Source = _source.VisualizationSource;
		spectrumDisplay.Source = _source.VisualizationSource;
		playPositionDisplay.Source = _source.VisualizationSource;
    }

}

Getting the data

Once you have a properly initialized IVisualizationSource you get the visualization data by calling GetData(). This method will return VisualizationDataFrame for the current audio being played or null if the current state of stream is stopped or if the analyzer is catching up processing for example due to seek operation. All controls have a source property, once you assign the source to the controls, they will pull and display data automatically.

Reading the file

Please see AudioSourceReader for the sample.

About

A UWP audio visualization component that provides a stream analyzer and XAML visualization controls for displaying VU and spectrum meters powered by Win2D

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •