private static void SaveSample(AudioStream sample)
 {
     if (!File.Exists(sample.Filename))
     {
         AudioExportHelper.SaveAsWave(sample.AudioData.Data, sample.Filename);
     }
 }
        /// <summary>
        ///     Saves a shortened version the specified sample as a mono wave in the Scratch folder and launches Scratch
        /// </summary>
        /// <param name="sample">The sample.</param>
        public static void LaunchShort(Sample sample)
        {
            if (_applicationFolder == "")
            {
                return;
            }

            SilenceHelper.GenerateSilenceAudioFile(GetSilenceFilename());
            SaveSample(sample);

            var bpm         = BpmHelper.GetBpmFromLoopLength(sample.LengthSeconds);
            var loopLength  = BpmHelper.GetDefaultLoopLength(bpm);
            var shortLength = loopLength / 8;

            if (shortLength > sample.LengthSeconds)
            {
                shortLength = sample.LengthSeconds;
            }

            var gain            = GetGain(sample.Filename);
            var scratchFilePath = Path.Combine(_applicationFolder, ScratchFile);

            AudioExportHelper.SaveAsMonoWave(sample.Filename, scratchFilePath, shortLength, gain);

            var scratchExePath = Path.Combine(_applicationFolder, ScratchExe);

            Process.Start(scratchExePath);
        }
        /// <summary>
        ///     Saves the specified sample as a mono wave in the Scratch folder and launches Scratch
        /// </summary>
        /// <param name="sample">The sample.</param>
        public static void Launch(Sample sample)
        {
            if (_applicationFolder == "")
            {
                return;
            }
            if (sample == null)
            {
                return;
            }

            SilenceHelper.GenerateSilenceAudioFile(GetSilenceFilename());
            SaveSample(sample);

            var gain = GetGain(sample.Filename);

            var scratchFilePath = Path.Combine(_applicationFolder, ScratchFile);

            AudioExportHelper.SaveAsMonoWave(sample.Filename, scratchFilePath, gain);


            var scratchExePath = Path.Combine(_applicationFolder, ScratchExe);

            Process.Start(scratchExePath);
        }
        /// <summary>
        ///     Generates an audio file of silence.
        /// </summary>
        /// <param name="filename">The filename.</param>
        public static void GenerateSilenceAudioFile(string filename)
        {
            if (File.Exists(filename))
            {
                return;
            }

            var audioData = Resources.silence_mp3.ToArray();

            AudioExportHelper.SaveAsMonoWave(audioData, filename);
        }