-
I suspect that all classes inheriting from While this might not be a bug, intuitively, disabling a My public class ReplayGainComponent : SoundComponent
{
public float Gain { get; set; } = 1.0f; // Default gain
public override string Name { get; set; } = "Replay Gain";
protected override void GenerateAudio(Span<float> buffer)
{
// Multiply each sample by the gain factor
for (int i = 0; i < buffer.Length; i++)
{
buffer[i] *= Gain;
}
}
} Playback Service Setup: private void InitializeNewTrack(string audioFilePath, double startingSeconds, double replayGain)
{
var fileStream = File.OpenRead(audioFilePath);
var dataProvider = new StreamDataProvider(fileStream);
_soundPlayer = new SoundPlayer(dataProvider)
{
Volume = _volume,
};
Mixer.Master.AddComponent(SetSoundComponent(_soundPlayer));
if (startingSeconds >= 0)
{
Seek(startingSeconds);
}
_soundPlayer.PlaybackEnded += OnPlaybackCompleted;
SoundEffectConfig.ReplayGainComponent.Gain = (float)replayGain;
_progressTimer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(500) };
_progressTimer.Tick += OnProgressTimerTick;
}
private ReplayGainComponent SetSoundComponent(SoundPlayer soundPlayer)
{
SoundEffectConfig.ReplayGainComponent.ConnectInput(soundPlayer);
return SoundEffectConfig.ReplayGainComponent;
} View Binding: <StackPanel IsEnabled="True">
<TextBlock Text="Replay Gain" />
<CheckBox IsChecked="{Binding SoundEffectConfig.ReplayGainComponent.Enabled}" />
</StackPanel> Issue: Questions:
Any guidance would be greatly appreciated! 🙏 Note: Translated from the original Chinese description for clarity. |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments
-
Follow-up Comment: Updated Code: public class ReplayGainModifier : SoundModifier
{
public float Gain { get; set; } = 1.0f; // Default gain
public override string Name { get; set; } = "Replay Gain";
public override float ProcessSample(float sample, int channel)
{
return sample * Gain;
}
} Updated Playback Service: private void InitializeNewTrack(string audioFilePath, double startingSeconds, double replayGain)
{
var fileStream = File.OpenRead(audioFilePath);
var dataProvider = new StreamDataProvider(fileStream);
_soundPlayer = new SoundPlayer(dataProvider)
{
Volume = _volume,
};
SoundEffectConfig.ReplayGainModifier.Gain = (float)replayGain;
_soundPlayer.AddModifier(SoundEffectConfig.ReplayGainModifier);
Mixer.Master.AddComponent(_soundPlayer);
if (startingSeconds >= 0)
{
Seek(startingSeconds);
}
_soundPlayer.PlaybackEnded += OnPlaybackCompleted;
_progressTimer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(500) };
_progressTimer.Tick += OnProgressTimerTick;
} Questions:
Thanks again for your insights! 🙌 Note: Follow-up translation added for context. |
Beta Was this translation helpful? Give feedback.
-
They don't. every component is independent from the others in the graph. This only happens if you set
Short answer: yes.
They aren't shared, look at the example below.
I tested this using multiple players simultaneously and found that enabling or disabling one player does not impact the others, as demonstrated in the example below:
If the issue still persists, I would suggest trying the library from source. |
Beta Was this translation helpful? Give feedback.
-
Thank you for your previous help. I think I might have identified the cause of the playback stopping. It occurred because I used
I referred to the documentation, which shows:
The example uses I tried two alternative approaches. In both cases, setting Approach 1:
Approach 2:
However, this introduced a new issue: even when modifying the audio samples (e.g.,
I tried setting I’m unsure how to resolve this, but thankfully You mentioned using the source code directly—thanks! If other issues arise, I’ll try that, but not yet due to my laziness. (^-^) |
Beta Was this translation helpful? Give feedback.
-
Sorry for the late response. The issue arises from a misunderstanding of the roles. The You need to do this
The full reproducible example
As I mentioned previously, the recommended approach for buffer modifications, such as gain adjustments, is to implement them as a |
Beta Was this translation helpful? Give feedback.
-
Thank you for your response. I believe I now understand how to use them correctly. qwq |
Beta Was this translation helpful? Give feedback.
Sorry for the late response. The issue arises from a misunderstanding of the roles. The
SoundPlayer
is actually the component that provides the data, serving as the input, whereas theReplayGainComponent
takes the buffer fromSoundPlayer
as its input and applies modifications to it.You need to do this