Skip to content

Comments

Added events when fade-in/fade-out are complete#1136

Open
SMSapereAude wants to merge 1 commit intonaudio:masterfrom
SMSapereAude:sample-provider-events
Open

Added events when fade-in/fade-out are complete#1136
SMSapereAude wants to merge 1 commit intonaudio:masterfrom
SMSapereAude:sample-provider-events

Conversation

@SMSapereAude
Copy link

According to FadeInOutSampleProvider docs:

The FadeInOutSampleProvider is a very basic fade provider, and you may want additional features like:

  • automatically fading out when you reach the end of the source
  • automatically stopping at the end of a fade out
  • cross-fading into another input.

These two events might be helpful for implementing such features.
It's also a contribution from our project, for the NAudio community ;)

@SMSapereAude SMSapereAude force-pushed the sample-provider-events branch from b229424 to 5b1b837 Compare March 15, 2024 01:28
@SMSapereAude
Copy link
Author

@markheath Hi, could you please take a look at this PR?

Copy link

@trolleycrash trolleycrash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The final contribution to make this PR complete would be to demonstrate how it's used in FadeInOutDemo

Comment on lines +123 to 126
FadeOutComplete?.Invoke(this, EventArgs.Empty);

// clear out the end
ClearBuffer(buffer, sample + offset, sourceSamplesRead - sample);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like the event should be fired after the buffer is cleared for the following reasons:

  1. Consistent State: When the event handler executes, the audio sample buffer will be in its final state with zeroed samples at the end.
  2. Error Handling: If clearing the buffer were to somehow fail, we wouldn't want to falsely signal completion.
  3. Logical Flow: The event signals the completion of the entire fade-out process, which includes the buffer clearing step.

Copy link

@fsa-SM fsa-SM Sep 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. If event handler execution takes longer time than buffer content can keep NAudio busy (tens of milliseconds), then NAudio will have stutter effect. Will be fixed with next PR.

@markheath
Copy link
Contributor

my main concern with raising events from IWaveProviders/ISampleProviders is that depending on what playback implementation you are using you might be on a background thread/thread managed by the audio device itself, in which case you need to be quite careful about what you do in the handler to avoid causing deadlocks or trying to update the UI from the wrong thread.

@fsa-SM
Copy link

fsa-SM commented Sep 7, 2025

Hi, sorry for long time of absence (devices which were used to access my account were unfortunately seized.)
This pull request can be closed as I don't have means to push changes related to requested changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants