private void StartConversion ()
{
m_btn_Add.Enabled = false;
m_btn_Browse.Enabled = false;
m_btn_Start.Enabled = false;
m_btnReset.Enabled = false;
m_btnDelete.Enabled = false;
m_cb_channel.Enabled = false;
m_cb_sampleRate.Enabled = false;
IWavFormatConverter audioConverter = new WavFormatConverter ( true );
int samplingRate = int.Parse ( m_cb_sampleRate.SelectedItem.ToString () );
int channels = m_cb_channel.SelectedIndex + 1;
int bitDepth = 16;
string outputDirectory = m_txt_Browse.Text;
string convertedFilePath = null;
bool flag = false;
if (!Directory.Exists ( outputDirectory )) return;
int listPositionIndex = 0;
while (m_lb_addFiles.Items.Count > listPositionIndex && listPositionIndex < 50)
{
string filePath = (string)m_lb_addFiles.Items[listPositionIndex];
//MessageBox.Show ( filePath );
try
{
if (Path.GetExtension ( filePath ) == ".wav")
{
convertedFilePath = audioConverter.ConvertSampleRate ( filePath, outputDirectory, channels, samplingRate, bitDepth );
}
else if (Path.GetExtension ( filePath ) == ".mp3")
{
convertedFilePath = audioConverter.UnCompressMp3File ( filePath, outputDirectory, channels, samplingRate, bitDepth );
}
// rename converted file to appropriate name
string newFilePath = Path.Combine ( outputDirectory,
Path.GetFileNameWithoutExtension ( filePath ) ) + ".wav";
//MessageBox.Show ( newFilePath );
if (File.Exists ( newFilePath ))
{
if (MessageBox.Show ( "File: " + Path.GetFileName ( newFilePath ) + " already exists. Do you want to overwrite it?", "Warning", MessageBoxButtons.YesNo ) == DialogResult.Yes)
{
File.Delete ( newFilePath );
File.Move ( convertedFilePath, newFilePath );
}
}
else
{
File.Move ( convertedFilePath, newFilePath );
}
m_lb_addFiles.Items.RemoveAt ( 0 );
}
catch (System.Exception ex)
{
flag = true;
MessageBox.Show ( ex.ToString () );
listPositionIndex++;
}
}
if (flag == false)
{
MessageBox.Show("Files have been converted");
}
else
MessageBox.Show("Some files have not been converted properly");
m_btn_Add.Enabled = true;
m_btn_Start.Enabled = false;
m_btnDelete.Enabled = false;
m_btn_Browse.Enabled = true;
m_btnReset.Enabled = true;
m_cb_channel.Enabled = true;
m_cb_sampleRate.Enabled = true;
}