/// <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 partial as wave. /// </summary> /// <param name="inFilename">The in filename.</param> /// <param name="outFilename">The out filename.</param> /// <param name="start">The start position in seconds.</param> /// <param name="length">The length in seconds.</param> /// <param name="offset">The offset position in seconds.</param> /// <param name="gain">The gain.</param> /// <param name="bpm">The BPM.</param> /// <param name="targetBpm">The target BPM.</param> public static void SavePartialAsWave(string inFilename, string outFilename, double start, double length, double offset = 0, float gain = 0, decimal bpm = 0, decimal targetBpm = 0) { // DebugHelper.WriteLine("Saving portion of track as wave with offset - " + inFilename); var audioStream = new Sample { Filename = inFilename, Description = inFilename, Gain = gain, Bpm = bpm }; AudioStreamHelper.LoadAudio(audioStream); if (targetBpm != 0) { if (bpm == 0) { bpm = BpmHelper.GetBpmFromLoopLength(length); } var percentChange = BpmHelper.GetAdjustedBpmPercentChange(bpm, targetBpm) / 100; AudioStreamHelper.SetTempoToMatchBpm(audioStream.ChannelId, bpm, targetBpm); length = length * (double)(1 + percentChange); } const BASSEncode flags = BASSEncode.BASS_ENCODE_PCM; BassEnc.BASS_Encode_Start(audioStream.ChannelId, outFilename, flags, null, IntPtr.Zero); var startByte = Bass.BASS_ChannelSeconds2Bytes(audioStream.ChannelId, start); var endByte = Bass.BASS_ChannelSeconds2Bytes(audioStream.ChannelId, start + length); if (offset == 0 || offset == start) { TransferBytes(audioStream.ChannelId, startByte, endByte); } else { startByte = Bass.BASS_ChannelSeconds2Bytes(audioStream.ChannelId, offset); TransferBytes(audioStream.ChannelId, startByte, endByte); startByte = Bass.BASS_ChannelSeconds2Bytes(audioStream.ChannelId, start); endByte = Bass.BASS_ChannelSeconds2Bytes(audioStream.ChannelId, offset); TransferBytes(audioStream.ChannelId, startByte, endByte); } BassEnc.BASS_Encode_Stop(audioStream.ChannelId); Bass.BASS_StreamFree(audioStream.ChannelId); AudioStreamHelper.UnloadAudio(audioStream); }