Comments (5)
After looking into this more I have realized that WasapiOut is stopping not WasapiCapture. Is this intended?
from cscore.
The problem is that the event does not get fired on the ui thread. Accessing UI Elements from other threads is not allowed. In order to ensure that all components are getting released correctly, the exception gets catched and populated by the Stopped Event of the WasapiOut class. The correct solution for this problem is to use the InvokeAsync Method of any UI Element. It is not recommend to use the sync Invoke Method since it could cause deadlocks or performance critical operations.
from cscore.
Thanks! That did it. For sake of documentation I updated the code from above with your suggestion using InvokeAsync to change the label to the PeakValue every 100ms. Works great.
public partial class MainWindow : Window
{
private WasapiCapture wasapiCapture;
private WasapiOut wasapiOut;
private SoundInSource wasapiCaptureSource;
private ISampleSource sampleSource;
private PeakMeter peakMeter;
private IWaveSource waveSource;
public MainWindow()
{
InitializeComponent();
wasapiCapture = new WasapiCapture();
wasapiCapture.Initialize();
wasapiCaptureSource = new SoundInSource(wasapiCapture);
sampleSource = wasapiCaptureSource.ToSampleSource();
peakMeter = new PeakMeter(sampleSource);
peakMeter.Interval = 100;
peakMeter.PeakCalculated += peakMeter_PeakCalculated;
waveSource = peakMeter.ToWaveSource();
wasapiCapture.Start();
wasapiOut = new WasapiOut();
wasapiOut.Initialize(waveSource);
Thread.Sleep(100);
wasapiOut.Play();
}
void peakMeter_PeakCalculated(object sender, PeakEventArgs e)
{
Action peakAction = () => lbltest.Content = e.PeakValue.ToString();
Dispatcher.InvokeAsync(peakAction);
}
}
from cscore.
Is this the same issue? I am trying to toggle the reverb mix with a button click and it stops WasapiOut also. I tried to add a InvokeAsync to the click method and it works sometimes and other times it stops WasapiOut. Any ideas? Here is my code.
public partial class MainWindow : Window
{
private WasapiCapture wasapiCapture;
private WasapiOut wasapiOut;
private SoundInSource wasapiCaptureSource;
private readonly DmoWavesReverbEffect reverbEffect;
private ISampleSource sampleSource;
private PeakMeter peakMeter;
private IWaveSource waveSource;
public MainWindow()
{
InitializeComponent();
wasapiCapture = new WasapiCapture();
wasapiCapture.Initialize();
wasapiCaptureSource = new SoundInSource(wasapiCapture);
sampleSource = wasapiCaptureSource.ToSampleSource();
peakMeter = new PeakMeter(sampleSource);
peakMeter.Interval = 100;
peakMeter.PeakCalculated += peakMeter_PeakCalculated;
waveSource = peakMeter.ToWaveSource();
reverbEffect = new DmoWavesReverbEffect(waveSource);
wasapiCapture.Start();
wasapiOut = new WasapiOut();
wasapiOut.Initialize(reverbEffect);
Thread.Sleep(100);
wasapiOut.Play();
}
void peakMeter_PeakCalculated(object sender, PeakEventArgs e)
{
Action peakAction = () => lbltest.Content = e.PeakValue.ToString();
Dispatcher.InvokeAsync(peakAction);
}
private void TestButton_Click(object sender, RoutedEventArgs e)
{
Action reverbAction = () =>
{
if (reverbEffect.ReverbMix == 0f)
{
reverbEffect.ReverbMix = -96;
}
else if (reverbEffect.ReverbMix == -96f)
{
reverbEffect.ReverbMix = 0;
}
};
Dispatcher.InvokeAsync(reverbAction);
}
}
from cscore.
This was a bug which got fixed a few days ago with commit 31bf8cd.
Since the TestButton_Click EventHandler runs on the GUI Thread, it is not necessary to invoke anything.
from cscore.
Related Issues (20)
- 'System.InvalidCastException' occurred in CSCore. Unable to cast object of type 'NAudio.CoreAudioApi.Interfaces.MMDeviceEnumeratorComObject' to type 'MMDeviceEnumeratorObject'. HOT 4
- Is it possible to process audio based on LUFS scale? HOT 1
- In SpectrumBase.cs ,why " _maxFftIndex = _fftSize / 2 - 1 " ? HOT 4
- Convert a MemoryStream to IAudioSource? HOT 5
- microphone audio as input to another microphone? HOT 1
- Recording on WasapiCapture,a lot of noise. HOT 4
- Duplicate values in AudioSubTypes
- CSCORE AudioClient initializing problem or problem elsewhere? HOT 2
- Which license is intended?
- [Question] peak sound HOT 3
- [Question] Any plans to update it to .NET core/5-6 versions?
- [Question] Getting playback position with WriteableBufferingSource ? HOT 1
- PropertyStore constains not all keys
- Clear WriteableBufferingSource?
- How to prevent WasapiOut to change Device when soundouput changes
- Doesn't build HOT 2
- Is it possible to play audio using RTP Payload?
- Real-time processing left and right channel
- Supported Still? HOT 1
- [QUESTION] Is it possible to run on a Linux server with .Net 8?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cscore.