I have a question about the GetVisualizationData function in the MediaPlayer class. This function returns two 256 float arrays. One representing the frequency and one for Samples of the Wave.
Here is an example of an attempt to scan the frequencies of an entire song.
bool bScanning = true;
TimeSpan total_span = TimeSpan.Zero;
MediaPlayer.Stop();
while (bScanning)
{
// Get visualization data for this frame.
MediaPlayer.GetVisualizationData(frequencies, samples);
// Using the output window to watch frequency buffer
// (using 5 as the index for lookup into frequency range).
System.Diagnostics.Debug.Write(frequencies[5]);
System.Diagnostics.Debug.Write(" ");
// add 26 milliseconds. I have heard that a frame in an MPEG-1 file lasts for 26ms.
total_span += delta;
// I have to resume the song in order to get the frequency data,
// If I don't I get zeros in the frequency buffer.
MediaPlayer.Resume();
// Advance song forward one frame.
MediaPlayer.PlayPosition = total_span;
// Pause the song right away so that we are still in the frame
// for the next GetVisualizationData() call.
MediaPlayer.Pause();
// Break out if the song is done scanning.
if (MediaPlayer.PlayPosition >= song.Duration)
bScanning = false;
}
I am currently using 26 milliseconds to skip a head every time I want to read the frequencies. I do this because I heard that a frame in an MPEG-1 file lasts for 26ms. If 26 milliseconds is the correct time that a single frame of an mp3 lasts, then if I use a 13 millisecond delta shouldn't I start getting duplicate frequencies in my output window, since I will be sampling the frequency buffer twice per mp3 frame? I checked this, and this is not the case. I end up getting different frequencies when I sample with 13 milliseconds instead of 26 milliseconds. My end goal is to be able to sample the frequencies for every single frame (or step) of a song. Does anybody know a way that this can be done?