Skip to content

Commit

Permalink
(#96) Allow upconverting to a different sample rate
Browse files Browse the repository at this point in the history
  • Loading branch information
libertyernie committed May 22, 2024
1 parent 5fb75fc commit c926a69
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion LoopingAudioConverter.Conversion/Converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public static async Task ConvertFileAsync(
env.UpdateStatus(filename_no_ext, "Applying effects");
w = await effectEngine.ApplyEffectsAsync(w,
channels: o.Channels ?? w.Channels,
rate: o.SampleRate ?? w.SampleRate,
rate: o.SampleRate,
db: o.AmplifydB ?? 0M,
amplitude: o.AmplifyRatio ?? 1M,
pitch_semitones: o.PitchSemitones ?? 0,
Expand Down
12 changes: 5 additions & 7 deletions LoopingAudioConverter.FFmpeg/FFmpegEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,10 @@ IEnumerable<string> getArgs() {
/// <param name="tempo_ratio">Tempo ratio (if 1, this effect will not be applied)</param>
/// <param name="force">If true, always return a new PCM16Audio object</param>
/// <returns>A new PCM16Audio object if one or more effects are applied; the same PCM16Audio object if no effects are applied.</returns>
public async Task<PCM16Audio> ApplyEffectsAsync(PCM16Audio lwav, int channels = int.MaxValue, decimal db = 0, decimal amplitude = 1, int rate = int.MaxValue, double pitch_semitones = 0, double tempo_ratio = 1, bool force = false) {
// This is where I wish I had F# list comprehensions

public async Task<PCM16Audio> ApplyEffectsAsync(PCM16Audio lwav, int? channels = null, decimal db = 0, decimal amplitude = 1, int? rate = null, double pitch_semitones = 0, double tempo_ratio = 1, bool force = false) {
IEnumerable<string> getParameters() {
if (channels != lwav.Channels)
yield return $"-ac {channels}";
if (channels is int ch && ch != lwav.Channels)
yield return $"-ac {ch}";

IEnumerable<string> getFilters() {
if (db != 0)
Expand All @@ -167,8 +165,8 @@ IEnumerable<string> getFilters() {
if (tempo != 1) {
yield return $"atempo={tempo}";
}
if (newrate > rate) {
yield return $"aresample={rate}";
if (rate is int rr && newrate != rr) {
yield return $"aresample={rr}";
}
}

Expand Down

0 comments on commit c926a69

Please sign in to comment.