filoe / cscore

An advanced audio library, written in C#. Provides tons of features. From playing/recording audio to decoding/encoding audio streams/files to processing audio data in realtime (e.g. applying custom effects during playback, create visualizations,...). The possibilities are nearly unlimited.
Other
2.15k stars 451 forks source link

SoundInSource.DataAvailable fires 3 or 4 times and then is never raised again #396

Closed GingerLoaf closed 4 years ago

GingerLoaf commented 4 years ago

After several days of CSCore working just fine, I had my USB ports go out and had to reboot my machine. After the reboot, only one specific app refuses to fire SoundInSource.DataAvailable more than 3 or 4 times.

I know what you're thinking... "This sounds like a hardware issue". I would normally agree, except that when I copy code from the project with issues into a new vanilla project and run it using the same exact input source, it fires SoundInSource.DataAvailable on time, consistently. In other words, using the same hardware in a different app works perfectly. I have verified that nothing is stopping the input source after it is started, and the debugger even reports that my input is in the recording state

Is there some sort of cache that CSCore uses that I can clear to refresh it? I have to wonder if there is some persistent state that CSCore relies on that failed to get a proper cleanup when my machine had issues. If so, it would really help to know where this is and clean it up

This is a Unity App, using C#. Build settings are set as: Scripting Runtime Version: ".NET 4.x Equivelant" Scripting Backend: "Mono" Api Compatibility Level: ".NET 4.x"

Tested with versions: CSCore.dll 1.1.6044.26128 CSCore.dll 1.2.1.2

Machine Info: Operating System: Windows 10 Pro 64-bit (10.0, Build 18363) (18362.19h1_release.190318-1202) Processor: Intel(R) Core(TM) i7-6950X CPU @ 3.00GHz (20 CPUs), ~3.0GHz Memory: 32768MB RAM

filoe commented 4 years ago

I'm sorry, but there is no persisted state. Hard to tell whats the problem :-( Never used in unity sandbox. Maybe this causes a problem or unity has some kind of persistent state?

GingerLoaf commented 4 years ago

No worries! I am very glad to know that there is no persistent state. I will continue to work with this to find the problem, I just wanted to reach out in case there was any way to get help. I appreciate your timely response!

filoe commented 4 years ago

I'll close this for now. If I can help you any further, let me know.

GingerLoaf commented 4 years ago

@filoe I am so terribly sorry for wasting your time! I feel really bad that this ended up being an issue in my software. Thought I am still baffled about why the behavior changed and the code did not, I have figured this out. I subscribed to the ISoundIn.Stopped event and discovered that it can carry an exception along with it. It turns out that Stopped was being fired after a few chunks of audio were processed, and it was carrying with it an out of bounds exception.

The reason I came here in the first place (which is very last resort for me) is because I seemed to be getting undesirable behavior with no output from the CSCore system... I just needed to get the exception from the stopped event and print it to Unity's console and now I will never miss any odd behavior again.

Hope this might help someone else in the future. As formerly stated, I sincerely apologize for wasting your time :(. You responded super fast though and were nice about it and I appreciate that from you. Thanks!