Exemple #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            string output_fullpass;
            //folder dialog
            string output_foldername = "";
            FolderBrowserDialog fdb  = new FolderBrowserDialog();

            fdb.Description         = "出力フォルダを選択してください";
            fdb.RootFolder          = Environment.SpecialFolder.Desktop;
            fdb.ShowNewFolderButton = true;
            if (fdb.ShowDialog(this) == DialogResult.OK)
            {
                output_foldername = fdb.SelectedPath;
            }

            if (textBox3.Text == "")
            {
                MessageBox.Show("出力ファイル名を入力してね", "注意", MessageBoxButtons.YesNo);
            }
            else
            {
                axWindowsMediaPlayer1.URL = "";
                output_fullpass           = output_foldername + "\\" + textBox3.Text + ".wav";
                WaveFile.Save(output_fullpass, makeStereo(wavdata), fs);
                axWindowsMediaPlayer1.URL = output_fullpass;
            }
        }
        /// <summary>
        /// Utility method to generate wav files
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="sampleRate"></param>
        /// <param name="bitsPerSample"></param>
        /// <param name="samples"></param>
        public static bool CreateWavFile(string filePath, int sampleRate, short bitsPerSample, List <double> samples)
        {
            try
            {
                WaveFile waveFile    = new WaveFile(sampleRate, bitsPerSample, 1);
                double[] sampleArray = new double[samples.Count];
                samples.CopyTo(sampleArray);

                waveFile.AddSamples(sampleArray);
                waveFile.Save(filePath);
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }