public static double GetAdjustedAudioLength(double length, decimal sourceBpm, decimal targetBpm) { var sourceLoopLength = BpmHelper.GetDefaultLoopLength(sourceBpm); var repeatsPerLoop = Math.Round(sourceLoopLength / length, 0); return(GetDefaultLoopLength(targetBpm) / repeatsPerLoop); }
/// <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> /// Does an audio stream power down effect asynchronously /// </summary> /// <param name="audioStream">The audio stream.</param> private static void PowerDownAsync(AudioStream audioStream) { if (audioStream == null || !audioStream.IsAudioLoaded()) { return; } var freq = audioStream.DefaultSampleRate; var interval = (int)(BpmHelper.GetDefaultLoopLength(audioStream.Bpm) * 1000) / 128; // set the volume slide //lock (Lock) { Bass.BASS_ChannelSlideAttribute(audioStream.ChannelId, BASSAttribute.BASS_ATTRIB_VOL, 0F, interval * 8); Thread.Sleep(1); } var percentValue = 0.70; while (freq > 100) { percentValue = percentValue / 1.2; interval = (int)(interval * 0.9D); freq = (int)(audioStream.DefaultSampleRate * percentValue); if (freq <= 100 || audioStream.ChannelId == int.MinValue) { continue; } //lock (Lock) { Bass.BASS_ChannelSlideAttribute(audioStream.ChannelId, BASSAttribute.BASS_ATTRIB_FREQ, freq, interval); Thread.Sleep(1); } Thread.Sleep(interval); } Pause(audioStream); if (!audioStream.IsAudioLoaded()) { return; } //lock (Lock) { Bass.BASS_ChannelSetAttribute(audioStream.ChannelId, BASSAttribute.BASS_ATTRIB_FREQ, audioStream.DefaultSampleRate); Thread.Sleep(1); } SetVolume(audioStream, 100M); }