Skip to content

Commit

Permalink
Restrict audio sample rate settings to allowed values (#1116)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mbucari committed Jan 16, 2025
1 parent 65c64c4 commit 13aad1a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
14 changes: 12 additions & 2 deletions Source/AppScaffolding/LibationScaffolding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ public static void RunPostConfigMigrations(Configuration config)

Migrations.migrate_to_v6_6_9(config);
Migrations.migrate_to_v11_5_0(config);
}
Migrations.migrate_to_v11_6_5(config);
}

/// <summary>Initialize logging. Wire-up events. Run after migration</summary>
public static void RunPostMigrationScaffolding(Variety variety, Configuration config)
Expand Down Expand Up @@ -413,7 +414,16 @@ class FilterState_6_6_9
public List<string> Filters { get; set; } = new();
}

public static void migrate_to_v11_5_0(Configuration config)
public static void migrate_to_v11_6_5(Configuration config)
{
//Settings migration for unsupported sample rates (#1116)
if (config.MaxSampleRate < AAXClean.SampleRate.Hz_8000)
config.MaxSampleRate = AAXClean.SampleRate.Hz_8000;
else if (config.MaxSampleRate > AAXClean.SampleRate.Hz_48000)
config.MaxSampleRate = AAXClean.SampleRate.Hz_48000;
}

public static void migrate_to_v11_5_0(Configuration config)
{
// Read file, but convert old format to new (with Name field) as necessary.
if (!File.Exists(QuickFilters.JsonFile))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ public class AudioSettingsVM : ViewModelBase
public NAudio.Lame.EncoderQuality SelectedEncoderQuality { get; set; }

public AvaloniaList<EnumDiaplay<SampleRate>> SampleRates { get; }
= new(Enum.GetValues<SampleRate>().Select(v => new EnumDiaplay<SampleRate>(v, $"{(int)v} Hz")));
= new(Enum.GetValues<SampleRate>()
.Where(r => r >= SampleRate.Hz_8000 && r <= SampleRate.Hz_48000)
.Select(v => new EnumDiaplay<SampleRate>(v, $"{(int)v} Hz")));

public AvaloniaList<NAudio.Lame.EncoderQuality> EncoderQualities { get; }
= new(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ private void Load_AudioSettings(Configuration config)

maxSampleRateCb.Items.AddRange(
Enum.GetValues<AAXClean.SampleRate>()
.Where(r => r >= AAXClean.SampleRate.Hz_8000 && r <= AAXClean.SampleRate.Hz_48000)
.Select(v => new EnumDiaplay<AAXClean.SampleRate>(v, $"{(int)v} Hz"))
.ToArray());

Expand Down

0 comments on commit 13aad1a

Please sign in to comment.