Added events when fade-in/fade-out are complete#1136
Added events when fade-in/fade-out are complete#1136SMSapereAude wants to merge 1 commit intonaudio:masterfrom
Conversation
b229424 to
5b1b837
Compare
|
@markheath Hi, could you please take a look at this PR? |
trolleycrash
left a comment
There was a problem hiding this comment.
The final contribution to make this PR complete would be to demonstrate how it's used in FadeInOutDemo
| FadeOutComplete?.Invoke(this, EventArgs.Empty); | ||
|
|
||
| // clear out the end | ||
| ClearBuffer(buffer, sample + offset, sourceSamplesRead - sample); |
There was a problem hiding this comment.
I feel like the event should be fired after the buffer is cleared for the following reasons:
- Consistent State: When the event handler executes, the audio sample buffer will be in its final state with zeroed samples at the end.
- Error Handling: If clearing the buffer were to somehow fail, we wouldn't want to falsely signal completion.
- Logical Flow: The event signals the completion of the entire fade-out process, which includes the buffer clearing step.
There was a problem hiding this comment.
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.
|
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. |
|
Hi, sorry for long time of absence (devices which were used to access my account were unfortunately seized.) |
According to
FadeInOutSampleProviderdocs:These two events might be helpful for implementing such features.
It's also a contribution from our project, for the NAudio community ;)