How To Convert MP3 Files To WAV Files
There may be some times when you need to convert an MP3 file back to bog standard PCM wave audio format, like, for example in a sound editing program. If you want todo
this, then
all you have todo
is use the Xaudio SDK. By the way, I said that the Xaudio SDK was free. Well, it's not.
By default, when you tell the XAudioPlayer to play, it plays the music through your soundcard. However, instead of using the standard soundcard output module, you can instruct the player to use a different output module, like the one that outputs to a file.
To set the output module to the file writer thing, youdo
something like this:
XaudioPlayer.SetOutputModule(0);
0, in this case is the ID for the "Output To File" output module.
Usually the default OutputModule ID is -1 or value XA_DECODER_OUTPUT_AUTOSELECT, which means that the player automatically sets the output module to whatever it thinks best.
Ok, the next thing todo
is to say what file you want to write to. Todo
this, you tell the output module what file to open. Like this:
XaudioPlayer.OutputOpen('e:/stuff.wav');
This will output the raw PCM data to a file called "e:/stuff.wav". However if you really want a proper WAVE file, with a wave header section at the front you need tospecify it, like this: 'wav:e:/stuff.wav'
Also, if youdo
n't want the decoder to take all your processing time as it writes your file, you should set its priority level to 2, instead of the default 4:
XAudioPlayer.Priority := 2;
Now, all you have todo
is open the input file, like so:
if OpenFileDialog.Execute then
begin
XaudioPlayer.InputOpen(OpenFileDialog.FileName);
end
The player should start playing straight away. However instead of playing through your soundcard, it plays to your harddrive. If you have the equalizer switched on, well this will effect the saved file. In fact, if you have some sort of trackbar to set the position of the music, you could "remix" the music as it gets saved to the file, though it probably will not sound too good. Trust me, I've tried.