Click here to Skip to main content
Click here to Skip to main content
Articles » Multimedia » DirectX » General » Downloads
 
Add your own
alternative version

Interactive 3D Spectrum Analyzer Visualization for Windows Media Player

, 17 May 2009 CPOL
Interactive 3D Spectrum Analyzer for Windows Media Player using DirectX 9 and some light GPGPU.
///////////////////////////////////////////////////////////////////////////////
//  Copyright (c) 2009 Carlo McWhirter. All Rights Reserved.	
//  Copyright (c) 2009 Hyteq Systems. All Rights Reserved.	
//  
//  http://www.hyteq.com
//
//	Hyteq Systems Educational License
//
//  This file is part of WM3DSpectrum, also known as 3D Spectrum Analyzer for
//  Windows Media Player. This file, the project that this file is part of, and
//  the resulting compiled program files are intended to be used for educational
//  purposes only. Use of this file or this project for any non-educational or
//  non-observatory purpose is strictly prohibited without the express written 
//  consent of all of the copyright holders listed above.
//
//  This file may only be modified and later redistributed by one or more of the
//  copyright holders listed above. Suggestions for bug fixes, enhancements,
//  and other modifications must be sent directly to one of the copyright holders.
//  
//  This file may be modified without being redistributed by any recipient of 
//  this file provided the modifications are NOT intentionaly or unintentionaly 
//  directed toward malicious or illegal purposes, but, instead, toward educational
//  purposes only.
//
//	THIS SOFTWARE IS PROVIDED 'AS-IS', WITHOUT ANY EXPRESS OR IMPLIED
//  WARRANTY. IN NO EVENT WILL THE AUTHORS BE HELD LIABLE FOR ANY DAMAGES
//  ARISING FROM THE USE OF THIS SOFTWARE.
//
//  This notice may not be removed from this file or altered in any manner.
//
///////////////////////////////////////////////////////////////////////////////

#pragma once

#include "windows.h"
#include "effects.h"
#include <d3d9.h>
#include <d3dx9.h>
#include <dxerr9.h>
#include <vector>

// Friendly macros to assist with COM/DirectX related nuisances
#define ReleaseCOM(x) { if(x){ x->Release();x = 0; } }

#if defined(DEBUG) | defined(_DEBUG)
	#ifndef CHECK
	#define CHECK(x)                                   \
	{                                                  \
		HRESULT hr = x;                                \
		if(FAILED(hr))                                 \
		{                                              \
			DXTrace(__FILE__, __LINE__, hr, #x, TRUE); \
		}                                              \
	}
	#endif
#else
	#ifndef CHECK
	#define CHECK(x) x;
	#endif
#endif 

// preset values
enum {
    PRESET_ROSE_GARDEN = 0,
    PRESET_CITY_LIGHTS,
	PRESET_ROSE_GARDEN_POINTS,
	PRESET_CITY_LIGHTS_POINTS,
    PRESET_ROSE_GARDEN_SMOOTH,
    PRESET_CITY_LIGHTS_SMOOTH,
	PRESET_ROSE_GARDEN_POINTS_SMOOTH,
	PRESET_CITY_LIGHTS_POINTS_SMOOTH,
    PRESET_COUNT
};

// Forward declare some essential interfaces.
interface IRenderable;
interface IInterpolateFreq;

// Render context structure used to pass information along the
// rendering hiearchy.
typedef struct _RENDER_CONTEXT
{
	bool		bIsWindowed;
	bool		bHasNewData;
	HWND		hWnd;
	HDC			hDC;
	LPRECT		lpRect;
	LONG		preset;
	TimedLevel*	pLevel;
	D3DXMATRIX	ViewMtx;
	D3DXMATRIX	ProjMtx;
	IDirect3D9*					d3d;
	D3DPRESENT_PARAMETERS		d3dPP;
	IDirect3DDevice9*			d3dDevice;
	std::vector<IRenderable*>	vecRenderables;
	IInterpolateFreq*			Interpolator;
} RENDERCONTEXT, *LPRENDERCONTEXT;

// IInterpolateFreq is an interface used by classes that interpolate frequencies
interface IInterpolateFreq
{
public:
	// Prepare the interpolation
	virtual void PrepareInterpolation( TimedLevel* pLevel ) = 0;

	// Get the amplitudes as an interpolated color value.
	virtual void GetAplitudesAtIndex( int index, float* fAudioAsColorL, float* fAudioAsColorR ) = 0;
};

// IRenderable is an interface used to render actual content to the screen.
interface IRenderable
{
public:
	virtual void Intitialize(LPRENDERCONTEXT context) = 0;
	virtual void Destroy(LPRENDERCONTEXT context) = 0;
	virtual void Prerender(LPRENDERCONTEXT context) = 0;
	virtual void Render(LPRENDERCONTEXT context) = 0;
	virtual void LostDevice(LPRENDERCONTEXT context) = 0;
	virtual void ResetDevice(LPRENDERCONTEXT context) = 0;
	virtual bool CanRenderWindowed() = 0;
	virtual bool CanRenderNonWindowed() = 0;
};

// IRenderer is an interface used to organize rendering for either windowed or non windowed mode.
interface IRenderer
{
public:
	virtual void Intialize(LPRENDERCONTEXT context) = 0;
	virtual void Destroy(LPRENDERCONTEXT context) = 0;
	virtual void Render(LPRENDERCONTEXT context) = 0;
	virtual bool IsInitialized() = 0;
	virtual bool InitializationFailed() = 0;
	virtual HRESULT OnWindowMessage(LPRENDERCONTEXT context, UINT msg, WPARAM WParam, LPARAM LParam, LRESULT *plResultParam ) = 0;
};

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Carlo McWhirter
Software Developer (Senior) Hyteq Systems
United States United States
I have been programming in C/C++ for over 10 years now, and I've programmed in C# since the .NET 1.0 beta was released. I know a lot of other languages, but I find very few languages to be as capable as the C family of languages.
 
I've worked for a few large corporations, but my favorite job was when I worked for ATS (Automation Tooling Systems) as a Control Systems Engineer. Programming PLCs taught me about the core of computing and the currently under-utilized power of concurrent state machines. Programming real-time computer systems for vision guided robotics and multi-axis motion control is just fun.
 
My personal interest are computation for finance, aritificial intelligence, physics, electronics engineering, embedded systems, motion control, and of course Music/Audio.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150123.1 | Last Updated 17 May 2009
Article Copyright 2009 by Carlo McWhirter
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid