Skip to content

Commit 150baea

Browse files
authored
Modernized collection initialization syntax (#3)
* Modernized collection initialization syntax * Sealed a few classes Those were (presumably) not intended to be inherited
1 parent 998002a commit 150baea

File tree

9 files changed

+119
-118
lines changed

9 files changed

+119
-118
lines changed

Samples/SoundFlow.SimplePlayer/ComponentTests.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,11 +323,12 @@ private static void TestMultiChannelChorusModifier()
323323
var multiChorus = new MultiChannelChorusModifier(
324324
wetMix: 0.6f,
325325
maxDelay: 44100 / 20, // Example max delay
326-
channelParameters: new[] // Example parameters for stereo (2-channel)
327-
{
326+
channelParameters:
327+
// Example parameters for stereo (2-channel)
328+
[
328329
(depth: 2f, rate: 0.8f, feedback: 0.6f),
329330
(depth: 2.5f, rate: 1.1f, feedback: 0.65f)
330-
});
331+
]);
331332
oscillator.AddModifier(multiChorus);
332333
PlayComponentForDuration(oscillator, 5);
333334
}

Samples/SoundFlow.SimplePlayer/EqualizerPresets.cs

Lines changed: 91 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -6,187 +6,187 @@ public static class EqualizerPresets
66
{
77
public static Dictionary<string, List<EqualizerBand>> GetAllPresets()
88
{
9-
return new Dictionary<string, List<EqualizerBand>>
9+
return new()
1010
{
11-
{ "Default", DefaultEq() },
12-
{ "Metal", MetalEq() },
13-
{ "HipHop", HipHopEq() },
14-
{ "Acoustic", AcousticEq() },
15-
{ "Jazz", JazzEq() },
16-
{ "Classical", ClassicalEq() },
17-
{ "Vocal Boost", VocalBoostEq() },
18-
{ "Bass Boost", BassBoostEq() },
19-
{ "Pop", PopEq() },
20-
{ "Rock", RockEq() },
21-
{ "Party", PartyEq() },
22-
{ "Rap", RapEq() },
23-
{ "Live", LiveEq() },
24-
{ "Large Hall", LargeHallEq() },
25-
{ "JPop", JPopEq() },
26-
{ "EDM", EdmEq() },
27-
{ "Podcast", PodcastEq() },
28-
{ "Nightcore", NightcoreEq() }
11+
["Default"] = DefaultEq(),
12+
["Metal"] = MetalEq(),
13+
["HipHop"] = HipHopEq(),
14+
["Acoustic"] = AcousticEq(),
15+
["Jazz"] = JazzEq(),
16+
["Classical"] = ClassicalEq(),
17+
["Vocal Boost"] = VocalBoostEq(),
18+
["Bass Boost"] = BassBoostEq(),
19+
["Pop"] = PopEq(),
20+
["Rock"] = RockEq(),
21+
["Party"] = PartyEq(),
22+
["Rap"] = RapEq(),
23+
["Live"] = LiveEq(),
24+
["Large Hall"] = LargeHallEq(),
25+
["JPop"] = JPopEq(),
26+
["EDM"] = EdmEq(),
27+
["Podcast"] = PodcastEq(),
28+
["Nightcore"] = NightcoreEq(),
2929
};
3030
}
3131

32-
public static List<EqualizerBand> DefaultEq() => new()
33-
{
32+
public static List<EqualizerBand> DefaultEq() =>
33+
[
3434
new(FilterType.Peaking, 1000, 6, 1.4f),
3535
new(FilterType.LowShelf, 250, -10, 0.7f),
3636
new(FilterType.HighShelf, 5000, 3, 0.7f),
3737
new(FilterType.BandPass, 2000, 0, 3.0f),
3838
new(FilterType.Notch, 500, 0, 2.0f),
3939
new(FilterType.LowPass, 150, 0, 0.7f),
40-
new(FilterType.HighPass, 10000, 0, 0.7f)
41-
};
40+
new(FilterType.HighPass, 10000, 0, 0.7f),
41+
];
4242

43-
public static List<EqualizerBand> MetalEq() => new()
44-
{
43+
public static List<EqualizerBand> MetalEq() =>
44+
[
4545
new(FilterType.Peaking, 80, 9, 2.0f),
4646
new(FilterType.Peaking, 250, 3, 1.4f),
4747
new(FilterType.Peaking, 500, -3, 1.4f),
4848
new(FilterType.Peaking, 1000, -2, 1.4f),
4949
new(FilterType.Peaking, 4000, 4, 1.4f),
5050
new(FilterType.Peaking, 8000, 6, 1.4f),
51-
new(FilterType.HighShelf, 12000, 4, 0.7f)
52-
};
51+
new(FilterType.HighShelf, 12000, 4, 0.7f),
52+
];
5353

54-
public static List<EqualizerBand> HipHopEq() => new()
55-
{
54+
public static List<EqualizerBand> HipHopEq() =>
55+
[
5656
new(FilterType.LowShelf, 80, 6, 0.7f),
5757
new(FilterType.Peaking, 100, 4, 1.4f),
5858
new(FilterType.Peaking, 300, -2, 1.4f),
5959
new(FilterType.Peaking, 1000, 1, 1.4f),
6060
new(FilterType.Peaking, 3000, 2, 1.4f),
61-
new(FilterType.HighShelf, 8000, 3, 0.7f)
62-
};
61+
new(FilterType.HighShelf, 8000, 3, 0.7f),
62+
];
6363

64-
public static List<EqualizerBand> AcousticEq() => new()
65-
{
64+
public static List<EqualizerBand> AcousticEq() =>
65+
[
6666
new(FilterType.HighPass, 80, 0, 0.7f),
6767
new(FilterType.Peaking, 200, -2, 1.4f),
6868
new(FilterType.Peaking, 3000, 2, 1.4f),
6969
new(FilterType.Peaking, 5000, 3, 1.4f),
70-
new(FilterType.HighShelf, 10000, 2, 0.7f)
71-
};
70+
new(FilterType.HighShelf, 10000, 2, 0.7f),
71+
];
7272

73-
public static List<EqualizerBand> JazzEq() => new()
74-
{
73+
public static List<EqualizerBand> JazzEq() =>
74+
[
7575
new(FilterType.Peaking, 60, 2, 1.4f),
7676
new(FilterType.Peaking, 400, -2, 1.4f),
7777
new(FilterType.Peaking, 1000, 1, 1.4f),
7878
new(FilterType.Peaking, 5000, 2, 1.4f),
79-
new(FilterType.HighShelf, 12000, 1, 0.7f)
80-
};
79+
new(FilterType.HighShelf, 12000, 1, 0.7f),
80+
];
8181

82-
public static List<EqualizerBand> ClassicalEq() => new()
83-
{
82+
public static List<EqualizerBand> ClassicalEq() =>
83+
[
8484
new(FilterType.HighPass, 40, 0, 0.7f),
8585
new(FilterType.Peaking, 250, -1, 1.4f),
8686
new(FilterType.Peaking, 4000, 1, 2.0f),
87-
new(FilterType.HighShelf, 10000, 1, 0.7f)
88-
};
87+
new(FilterType.HighShelf, 10000, 1, 0.7f),
88+
];
8989

90-
public static List<EqualizerBand> VocalBoostEq() => new()
91-
{
90+
public static List<EqualizerBand> VocalBoostEq() =>
91+
[
9292
new(FilterType.HighPass, 100, 0, 0.7f),
9393
new(FilterType.Peaking, 250, -2, 1.4f),
9494
new(FilterType.Peaking, 3000, 3, 1.4f),
9595
new(FilterType.Peaking, 5000, 2, 1.4f),
96-
new(FilterType.HighShelf, 10000, 1, 0.7f)
97-
};
96+
new(FilterType.HighShelf, 10000, 1, 0.7f),
97+
];
9898

99-
public static List<EqualizerBand> BassBoostEq() => new()
100-
{
99+
public static List<EqualizerBand> BassBoostEq() =>
100+
[
101101
new(FilterType.LowShelf, 100, 6, 0.7f),
102-
new(FilterType.Peaking, 300, -3, 1.4f)
103-
};
102+
new(FilterType.Peaking, 300, -3, 1.4f),
103+
];
104104

105-
public static List<EqualizerBand> PopEq() => new()
106-
{
105+
public static List<EqualizerBand> PopEq() =>
106+
[
107107
new(FilterType.Peaking, 100, 3, 1.4f),
108108
new(FilterType.Peaking, 300, -2, 1.4f),
109109
new(FilterType.Peaking, 1000, 1, 1.4f),
110110
new(FilterType.Peaking, 3000, 2, 1.4f),
111111
new(FilterType.Peaking, 8000, 2, 1.4f),
112-
new(FilterType.HighShelf, 12000, 1, 0.7f)
113-
};
112+
new(FilterType.HighShelf, 12000, 1, 0.7f),
113+
];
114114

115-
public static List<EqualizerBand> RockEq() => new()
116-
{
115+
public static List<EqualizerBand> RockEq() =>
116+
[
117117
new(FilterType.Peaking, 80, 4, 2.0f),
118118
new(FilterType.Peaking, 500, -2, 1.4f),
119119
new(FilterType.Peaking, 1000, -1, 1.4f),
120120
new(FilterType.Peaking, 4000, 3, 1.4f),
121-
new(FilterType.Peaking, 8000, 2, 1.4f)
122-
};
121+
new(FilterType.Peaking, 8000, 2, 1.4f),
122+
];
123123

124-
public static List<EqualizerBand> PartyEq() => new()
125-
{
124+
public static List<EqualizerBand> PartyEq() =>
125+
[
126126
new(FilterType.LowShelf, 100, 5, 0.7f),
127127
new(FilterType.Peaking, 300, -2, 1.4f),
128128
new(FilterType.Peaking, 4000, 2, 1.4f),
129-
new(FilterType.HighShelf, 10000, 4, 0.7f)
130-
};
129+
new(FilterType.HighShelf, 10000, 4, 0.7f),
130+
];
131131

132-
public static List<EqualizerBand> RapEq() => new()
133-
{
132+
public static List<EqualizerBand> RapEq() =>
133+
[
134134
new(FilterType.LowShelf, 80, 7, 0.7f),
135135
new(FilterType.Peaking, 100, 3, 1.4f),
136136
new(FilterType.Peaking, 300, -3, 1.4f),
137137
new(FilterType.Peaking, 3000, 3, 1.4f),
138-
new(FilterType.HighShelf, 8000, 2, 0.7f)
139-
};
138+
new(FilterType.HighShelf, 8000, 2, 0.7f),
139+
];
140140

141-
public static List<EqualizerBand> LiveEq() => new()
142-
{
141+
public static List<EqualizerBand> LiveEq() =>
142+
[
143143
new(FilterType.HighPass, 60, 0, 0.7f),
144144
new(FilterType.Peaking, 250, -3, 1.4f),
145145
new(FilterType.Peaking, 4000, 2, 1.4f),
146-
new(FilterType.Peaking, 8000, -2, 1.4f)
147-
};
146+
new(FilterType.Peaking, 8000, -2, 1.4f),
147+
];
148148

149-
public static List<EqualizerBand> LargeHallEq() => new()
150-
{
149+
public static List<EqualizerBand> LargeHallEq() =>
150+
[
151151
new(FilterType.HighPass, 50, 0, 0.7f),
152152
new(FilterType.Peaking, 200, -4, 1.4f),
153153
new(FilterType.Peaking, 4000, 2, 1.4f),
154-
new(FilterType.Peaking, 8000, -1, 1.4f)
155-
};
154+
new(FilterType.Peaking, 8000, -1, 1.4f),
155+
];
156156

157-
public static List<EqualizerBand> JPopEq() => new()
158-
{
157+
public static List<EqualizerBand> JPopEq() =>
158+
[
159159
new(FilterType.Peaking, 100, 2, 1.4f),
160160
new(FilterType.Peaking, 300, -2, 1.4f),
161161
new(FilterType.Peaking, 1000, 1, 1.4f),
162162
new(FilterType.Peaking, 3000, 3, 1.4f),
163163
new(FilterType.Peaking, 6000, 2, 2.0f),
164-
new(FilterType.HighShelf, 12000, 2, 0.7f)
165-
};
164+
new(FilterType.HighShelf, 12000, 2, 0.7f),
165+
];
166166

167-
public static List<EqualizerBand> EdmEq() => new()
168-
{
167+
public static List<EqualizerBand> EdmEq() =>
168+
[
169169
new(FilterType.LowShelf, 60, 4, 0.7f),
170170
new(FilterType.Peaking, 100, 3, 1.4f),
171171
new(FilterType.Peaking, 300, -2, 1.4f),
172172
new(FilterType.Peaking, 5000, 2, 2.0f),
173-
new(FilterType.HighShelf, 10000, 3, 0.7f)
174-
};
173+
new(FilterType.HighShelf, 10000, 3, 0.7f),
174+
];
175175

176-
public static List<EqualizerBand> PodcastEq() => new()
177-
{
176+
public static List<EqualizerBand> PodcastEq() =>
177+
[
178178
new(FilterType.HighPass, 100, 0, 0.7f),
179179
new(FilterType.Peaking, 250, -3, 1.4f),
180180
new(FilterType.Peaking, 4000, 2, 1.4f),
181-
new(FilterType.Peaking, 8000, -2, 1.4f)
182-
};
181+
new(FilterType.Peaking, 8000, -2, 1.4f),
182+
];
183183

184-
public static List<EqualizerBand> NightcoreEq() => new()
185-
{
184+
public static List<EqualizerBand> NightcoreEq() =>
185+
[
186186
new(FilterType.Peaking, 100, 2, 1.4f),
187187
new(FilterType.Peaking, 300, -2, 1.4f),
188188
new(FilterType.Peaking, 3000, 3, 1.4f),
189189
new(FilterType.Peaking, 6000, 2, 2.0f),
190-
new(FilterType.HighShelf, 10000, 2, 0.7f)
191-
};
190+
new(FilterType.HighShelf, 10000, 2, 0.7f),
191+
];
192192
}

Samples/SoundFlow.SimplePlayer/Program.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,18 +218,18 @@ private static void PlayAudioFromFile()
218218
{
219219
Console.WriteLine("Surround sound requested but player is not a SurroundPlayer.");
220220
}
221-
}, new List<SoundModifier>
222-
{
221+
},
222+
[
223223
new AlgorithmicReverbModifier
224224
{
225225
RoomSize = 0.9f,
226226
Damp = 0.3f,
227227
Width = 0.75f,
228228
Wet = 0.65f,
229229
PreDelay = 35f,
230-
Mix = 0.6f
230+
Mix = 0.6f,
231231
}
232-
});
232+
]);
233233
}
234234

235235
private static void PlayAudioFromWeb()
@@ -374,7 +374,7 @@ private static void PlayAudioWithNoiseReduction()
374374
noiseFrames: 50
375375
);
376376

377-
PlayAudio(new StreamDataProvider(new FileStream(noisyFilePath, FileMode.Open, FileAccess.Read)), modifiers: new List<SoundModifier> { noiseReductionModifier });
377+
PlayAudio(new StreamDataProvider(new FileStream(noisyFilePath, FileMode.Open, FileAccess.Read)), modifiers: [noiseReductionModifier]);
378378
}
379379

380380
private static void PlayAudioWithEqualizer()
@@ -411,7 +411,7 @@ private static void PlayAudioWithEqualizer()
411411
}
412412
Console.WriteLine();
413413

414-
PlayAudio(new StreamDataProvider(new FileStream(filePath, FileMode.Open, FileAccess.Read)), modifiers: new List<SoundModifier> { parametricEqualizer });
414+
PlayAudio(new StreamDataProvider(new FileStream(filePath, FileMode.Open, FileAccess.Read)), modifiers: [parametricEqualizer]);
415415
}
416416

417417
private static void SaveWaveformAsText(string filePath, int width, int height, List<float> waveform)

Src/Abstracts/SoundComponent.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ public abstract class SoundComponent
1515
private static readonly ArrayPool<float> BufferPool = ArrayPool<float>.Shared;
1616

1717
// Connection state
18-
private readonly List<SoundComponent> _inputs = new();
19-
private readonly List<SoundComponent> _outputs = new();
18+
private readonly List<SoundComponent> _inputs = [];
19+
private readonly List<SoundComponent> _outputs = [];
2020
private readonly object _connectionsLock = new();
2121

2222
// Processing state
23-
private readonly List<SoundModifier> _modifiers = new();
24-
private readonly List<AudioAnalyzer> _analyzers = new();
23+
private readonly List<SoundModifier> _modifiers = [];
24+
private readonly List<AudioAnalyzer> _analyzers = [];
2525
private float _pan;
2626
private bool _solo;
2727
private float _volume = 1f;

Src/Components/SurroundPlayer.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace SoundFlow.Components;
1010
/// <summary>
1111
/// A sound player that simulates surround sound with support for different speaker configurations and advanced panning methods.
1212
/// </summary>
13-
public class SurroundPlayer : SoundComponent, ISoundPlayer
13+
public sealed class SurroundPlayer : SoundComponent, ISoundPlayer
1414
{
1515
private readonly LowPassModifier _lowPassFilter = new(120f);
1616
private readonly ISoundDataProvider _dataProvider;
@@ -177,7 +177,7 @@ public SurroundConfiguration SurroundConfig
177177
}
178178

179179
// Surround sound parameters (predefined configurations)
180-
private readonly Dictionary<SpeakerConfiguration, SurroundConfiguration> _predefinedConfigurations = new();
180+
private readonly Dictionary<SpeakerConfiguration, SurroundConfiguration> _predefinedConfigurations = [];
181181

182182
private float[] _delayLines = [];
183183
private int[] _delayIndices = [];
@@ -647,7 +647,7 @@ public void SetLoopPoints(int startSample, int endSample = -1)
647647
/// <param name="volumes">The volumes for each speaker.</param>
648648
/// <param name="delays">The delays for each speaker.</param>
649649
/// <param name="speakerPositions">The positions of each speaker.</param>
650-
public class SurroundConfiguration(string name, float[] volumes, float[] delays, Vector2[] speakerPositions)
650+
public sealed class SurroundConfiguration(string name, float[] volumes, float[] delays, Vector2[] speakerPositions)
651651
{
652652
/// <summary>
653653
/// The name of the configuration.

0 commit comments

Comments
 (0)