Example #1
0
        private void ConvertAudio(string audioFilePath, double rate)
        {
            // Convert .mp3 file to .wav
            Codec.MP3ToWave(audioFilePath + ".mp3", audioFilePath + ".wav");

            // Change either the tempo or the rate of the .wav
            string[] args = new string[] { audioFilePath + ".wav", audioFilePath + rate * 100 + ".wav" };
            float    rateDeltaInProcent = ((float)rate * 100) - 100;
            bool     keepPitch          = cbxPitch.Checked;

            AudioStrech.Start(args, rateDeltaInProcent, keepPitch);

            // Convert .wav file to .mp3
            try
            {
                Codec.WaveToMP3(audioFilePath + rate * 100 + ".wav", audioFilePath + rate * 100 + ".mp3");
            }
            catch (Exception e)
            {
                MessageBox.Show("Could not convert the modified .wav file to the .mp3 file.", "Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            // Remove the .wav files
            File.Delete(audioFilePath + ".wav");
            File.Delete(audioFilePath + rate * 100 + ".wav");
        }
Example #2
0
        private void btnStartConversion(object sender, EventArgs e)
        {
            OsuFileConverter converter = new OsuFileConverter();

            btnStart.Text    = "Loading...";
            btnStart.Enabled = false;

            if (ValidateInputs())
            {
                // For every file
                for (int i = 0; i < osuFilePaths.Length; i++)
                {
                    // For every convert
                    foreach (var rate in rates)
                    {
                        string audioFilePath;

                        // Convert the .osu file
                        string audioFileName = converter.Start(osuFilePaths[i], osuFileNames[i], tbxAudio.Text, rate, cbxOffset.Checked);

                        // Reset start button
                        btnStart.Text    = "Start Conversion";
                        btnStart.Enabled = true;

                        if (audioFileName == "error")
                        {
                            MessageBox.Show("Could not read the .osu file correctly.", "Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                        else if (audioFileName == "fileError")
                        {
                            return;
                        }
                        else
                        {
                            DirectoryInfo songDir = Directory.GetParent(osuFilePaths[i]);
                            audioFilePath = Path.Combine(songDir.FullName, audioFileName);
                            audioFilePath = audioFilePath.Substring(0, audioFilePath.Length - 4);
                        }

                        if (cbxAudio.Checked == true)
                        {
                            if (!File.Exists(audioFilePath + ".mp3"))
                            {
                                MessageBox.Show("Could not find the audio file.", "Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return;
                            }

                            // Convert .mp3 file to .wav
                            Codec.MP3ToWave(audioFilePath + ".mp3", audioFilePath + ".wav");

                            // Change the tempo of the .wav
                            string[] args = new string[] { audioFilePath + ".wav", audioFilePath + rate * 100 + ".wav" };
                            float    rateDeltaInProcent = ((float)rate * 100) - 100;
                            bool     keepPitch          = cbxPitch.Checked;
                            AudioStrech.Start(args, rateDeltaInProcent, keepPitch);

                            // Convert .wav file to .mp3
                            Codec.WaveToMP3(audioFilePath + rate * 100 + ".wav", audioFilePath + rate * 100 + ".mp3");

                            // Remove the .wav files
                            File.Delete(audioFilePath + ".wav");
                            File.Delete(audioFilePath + rate * 100 + ".wav");
                        }
                    }
                }

                DialogResult exit = MessageBox.Show("Convertions successful! Do you want to exit the application?", "Success", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                if (exit == DialogResult.Yes)
                {
                    Application.Exit();
                }
            }

            // Reset start button
            btnStart.Text    = "Start Conversion";
            btnStart.Enabled = true;
        }