MediaPlayerVisuals Sample

Description
This sample is a collection of Windows Media Player visualizations which use Direct3D, along with a supporting common framework class which enables developers to easily create their own Direct3D visualizations.



Path
Source: DX90SDK\Samples\C++\Direct3D\MediaPlayerVisuals
Plug-in: DX90SDK\Samples\C++\Direct3D\Bin\MediaPlayerVisuals.dll


Requirements
Execution of the plug-in requires Windows Media Player 9 Series.
Compilation of the source code requires the Windows Media 9 Series SDK.

Each of these components is available as a free download from the Windows Media Player website:
http://www.microsoft.com/windows/windowsmedia


User's Guide
To run the plug-in:
  1. Open Windows Media Player 9 Series
  2. Click the "View" menu option, select "Visualizations->Options..."
  3. Click the "Add..." button and browse to the compiled "MediaPlayerVisuals.dll" file.
  4. "Microsoft Direct3D" should now be on your list of installed visualizations. Close the options dialog to return to the application window.
  5. To set one of the Direct3D presets as the active visualization, click "View->Visualizations->Microsoft Direct3D" from the menu and select the desired preset.
To compile the source code:
  1. Locate the directory search path settings inside your build environment. For Visual Studio 6: "Tools->Options->Directories" For Visual Studio.NET: "Tools->Options->Projects->VC++ Directories"
  2. Add the Windows Media 9 Series SDK include directory to the include directories search path (commonly "C:\WMSDK\WMPSDK9\include")


Programming Notes
The majority of files in the project were generated by the Windows Media Player Plug-in Wizard and have not been modified. The files of interest are:

D3DVisualizaton.cpp DirectX common framework class. This class is a modified version of the D3DApplication class shared by the rest of the SDK samples, and acts as an interpreter between the Windows Media Player interface and the common Direct3D application model.
MediaPlayerVisuals.cpp This file was generated by the Windows Media Player Plug-in Wizard to implement an example visualization, but has been modified to make the appropriate calls into the CD3DVisualization interface.
Bars.cpp Implementation of the Bars visualization. This class is derived from CD3DVisualization and illustrates how to create a simple Direct3D visualization, including support for a property dialog.
SpectrumWheel.cpp Implementation of the Spectrum Wheel visualization. This class is an example of a more advanced Direct3D visualization.

Windows Media Player visualizations are implemented as a collection of presets enclosed within a single effect; the effect implements the IWMPEffects interface to communicate with the Player application, and several of the member functions accept an argument to indicate which preset the call is intended for. This sample assigns a separate CD3DVisualization derived class for each preset, but you could easily share rendering code across several presets and simply adjust rendering parameters depending on which one is selected. See the Windows Media 9 Series SDK documentation for more information about the IWMPEffects interface.

The CD3DVisualization class handles the mapping between the IWMPEffects interface and the CD3DApplication sample framework, so a custom visualization can be created by overriding the same CD3DApplication functions as used throughout the samples. The member functions unique to visualizations are:
GetTitle Returns the display name.
GetPropSheetPage Retrieves the property sheet page header which defines the configuration dialog.
GetCapabilities Indicates whether the visualization supports full- screen rendering and/or a configuration dialog
MediaInfo Sends channel count, sample rate, and display title information about the currently playing media.

Each time the Player application prompts the visualization to render, per-channel frequency and waveform information is sent to allow the visualization to respond to the music. This information is accessible from the "m_pAudioLevels" member variable inside the CD3DVisualization class.

This sample makes use of common DirectX code (consisting of helper functions, etc.) that is shared with other samples on the DirectX SDK. All common headers and source code can be found in the following directory: (SDK Directory)\Samples\C++\Common


Bars Visualization
The Bars visualization implements very simple rendering and configuration functionalily. Upon construction, the class loads the bar width and spacing options from the registry. These values are used inside RestoreDeviceObjects() to determine how many bars will be drawn, and therefore how many vertices and indices are required. These vertices are filled during every call to FrameMove() based on the current state of the audio stream.

User-configurable options are handled through a property page; the collection of pages for all the presets in the visualization are displayed when the user opens the properties dialog through Player menu. GetPropSheetPage() retrieves the PROPSHEETPAGE structure which contains the dialog resource and dialog procedure callback. DialogProc() (and the StaticDialogProc() helper function) implement this dialog procedure to handle user input. These configurable values are pushed to the registry when the visualization is destroyed.

Bars Visualization
Properties Dialog
 



Spectrum Wheel Visualization
The Spectrum Wheel visualization shows a more interesting use of Direct3D. The wheel represents the sound frequency much the same as the bar graph, except wrapped around a center point. Cells further from the center represent higher volume at the given frequency.

The visualization is implemented as a simplified particle system, where cells are emitted based on audio levels. Each particle spot is shared by two cells, and if both cells are falling when that spot is signaled to fire, the bottom-most cell will be recycled and fired again. For visual effect, falling cells are stretched and the alpha value is faded.

Spectrum Wheel Visualization
 




Copyright (c) Microsoft Corporation. All rights reserved.