Thought for the Dazed

I've had to give up that Distance Learning course as I was having trouble seeing the teacher.

Flickr
www.flickr.com
RobMiles' items Go to RobMiles' photostream
Twitter
C# Yellow Book

Search entire site
« Amazing Picture | Main | Buy My Book (please) »
Sunday
May182008

Cheesy Music

I'm doing a session at Dev Days next week in their Geek Night slot. It is on XNA, and so I thought I'd have a play with "Hot Salad Death with Cheese" and get it running on the Zune.

Took 30 minutes.

Took another 20 to make the game play a random music track and display a spectrum analyzer as the music plays. Great stuff. I'm really looking forward to the talk now..

2503158864

Hot salad death with music and cheese.

Reader Comments (4)

Hi Rob,

I'm really curious about the spectrum analyser. Is that something which you coded in XNA yourself, or is it an inbuilt function of the Zune which you can now access in XNA 3.0?
May 19, 2008 | Unregistered CommenterBurkey
I cannot tell a lie. It is actually very easy to do. I just lifted some sample code from the help documentation and slapped it into my game. Which is why it was so quick.

The XNA 3.0 API gives you all you need to do this, I've pulled this text from the help documentation:

public static void GetVisualizationData (
float[] frequencies,
float[] samples
)


Parameters

frequencies

Array of 256 floats that receives frequency data. Frequency data is a normalized array over the frequency bands from 20Hz to 20KHz, on a logarithmic scale. Each value in the array is a float value from 0.0f to 1.0f, and is the logarithmic scaled power level for that frequency band. See Remarks below.

samples

Array of 256 floats that receives sample data. Sample data is an array of 256 floats in the range -1.0f to 1.0f, which approximate the wave form of the sound.

Remarks

Visualization data can be used to create visualizers, which are graphical representations of sound. For example, a simple visualizer might be an equalizer spectrum display that shows the current power level for each frequency band.

The frequency data is an array of 256 float values. Each element corresponds to a frequency band, ranging from 20Hz (frequencies[0]) to 20KHz (frequencies[255]). In the array, the distribution of bands from 20Hz to 20KHz is logarithmic, not linear. This means that elements at the lower end of the spectrum represent a smaller frequency range than those at the upper end of the spectrum.

Each value in the frequency array is a normalized float value from 0.0f to 1.0f, and is the logarithmic scaled power level for that frequency band.

May 19, 2008 | Registered CommenterRob
Awesome! Sounds like it'd now be possible to make music games (eg. rhythm action games). Just what I've been hoping for :)
May 19, 2008 | Unregistered CommenterBurkey
Thats super simple. Beats the soundObject command we have in Flash. I presumeyou have a soundObject command in C# so music based games can be of the varying varieties ?
May 22, 2008 | Unregistered CommenterJDog

PostPost a New Comment

Enter your information below to add a new comment.
Author Email (optional):
Author URL (optional):
Post:
 
All HTML will be escaped. Hyperlinks will be created for URLs automatically.