I am currently developing an audio visualizer using C#/Asp.net/JavaScript for a website. To ensure that my animations move smoothly in sync with the music, I have decided to preprocess the MP3 file within the code backend. I plan to write the values and frequencies to a text file, which will then be read by JavaScript to adjust the animation accordingly. My goal is to create a bar visualization similar to this example: example. I need numerical values to determine the height of the bars, which should change as the music plays.
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NAudio;
using System.IO;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
MP3toWAV(MapPath("~/Music/UctfnI6yUPM.mp3"), MapPath("~/Music/UctfnI6yUPM.wav"));
Strip(MapPath("~/Music/UctfnI6yUPM.wav"));
}
public void MP3toWAV(string file,string output)
{
using (NAudio.Wave.Mp3FileReader reader = new NAudio.Wave.Mp3FileReader(file))
{
NAudio.Wave.WaveFileWriter.CreateWaveFile(output, reader);
}
}
public void Strip(string path)
{
NAudio.Wave.WaveChannel32 wave = new NAudio.Wave.WaveChannel32(new NAudio.Wave.WaveFileReader(path));
byte[] buffer = new byte[8192];
int read = 0;
StreamWriter writer = new StreamWriter(MapPath("~/Result.txt"));
while (wave.Position < wave.Length)
{
read = wave.Read(buffer, 0, 8192);
for (int i = 0; i < read / 4; i++)
{
writer.Write(BitConverter.ToSingle(buffer, i * 4));
}
}
}
}
A portion of the output can be viewed on pastebin:output link. Unfortunately, I was unable to copy the entire file due to its large size (~90mb). I am uncertain about how to utilize this data and if it's the appropriate data for the task at hand. I have dedicated the last few days to researching this topic, including reviewing Mark Heath's article on autotune and exploring the BandedSpectrumAnalyzer project. While I derived some inspiration from these sources, I found the BandedSpectrumAnalyzer project quite perplexing. Any guidance would be greatly appreciated!