Charles Petzold on writing books, reading books, and exercising the internal UTM

Recent Entries
< PreviousBrowse the ArchivesNext >
Subscribe to the RSS Feed

Spinning a Record Like a DJ in Windows 8

April 2, 2013
New York, N.Y.

Windows 8 has some exceptionally powerful facilities for working with sound, and in the latest installment of the DirectX Factor column in MSDN Magazine I show how to display a file picker that allows you to select an MP3 or WMA file from your Windows 8 Music Library, display cover art as well as album and artist information, load and decode the file using the Media Foundation APIs, and shovel the resultant audio buffers into XAudio2 voices to play back the file.

This may seem like a rather roundabout way to do something that the Windows 8 MediaElement does for you, but having access to the actual audio buffers allows for some interesting techniques. The downloadable DeeJay program creates a disk that looks like an old-fashioned vinyl record with a "needle" pointing to the current location:

You can adjust the playback speed (forward or reverse) using a Slider on the application bar, or you can use your fingers to spin the record manually like a DJ. The DeeJay program uses the one-finger Manipulation events with inertia for the touch interface, so you can give it a good flick and watch it spin crazily and then slow down.

Check it out. The program is pretty cool whether you're interesting in the particular programming techniques or not.


The first paragraph in the article under the "Media Foundation Streaming" section: *That's* why I think I'll struggle getting to grips with working in C++ - how on earth are beginners supposed to know which libraries to pull in?

I understand that there's a similar problem with managed code, i.e. you have to know to pull in various assemblies, but a) they're named a bit more sensibly and b) any dependencies can be resolved at runtime, i.e. they don't have to be linked at compile time.

Or am I just being a .NET scaredy-cat?

— Mike G, Tue, 2 Apr 2013 08:31:46 -0400

No question that C++ is more difficult than C# in *many* respects. However, much of this stuff is documented. For example, check out the page for the MFStartup function:

Down at the bottom you'll see you'll see the header file and library required for this function. (You don't have to worry about the DLL because that's included with Windows 8.) Put the header file in pch.h (the "precompiled header" header), so it get compiled just once.

Adding a reference to the library is a little messier: In Visual Studio, right-click the project name, and select Properties. (Or select Properties from the Project menu.) You'll get an extensive dialog. On the left, select Linker and Input. What you want to do is add the library to the Additional Dependencies field at the top. HOWEVER, you probably want to add the same libraries for all the configurations (Debug and Release) and all the platforms (x86 [aka Win32], x64, and ARM). First use the Configuration dropdown at the top to select All Configurations. Use the Platform dropdown to select All Platforms. Then click the Additional Dependencies field. A dropdown arrow appears. Click that, and select Edit. A box comes up to which you can add the additional libraries you require, one to a line.

Believe me, it becomes easier with time. — Charles

Is Microsoft not using #pragma comment lib to link libraries automatically when you include the header?

It's a shame if they're not using that .

— Ajs, Tue, 2 Apr 2013 15:17:48 -0400

I've always had to specify the libraries explicitly.

When doing DirectX coding, that the *least* of the difficulties. — Charles

Recent Entries
< PreviousBrowse the ArchivesNext >
Subscribe to the RSS Feed

(c) Copyright Charles Petzold