keijiro / Lasp

Low-latency Audio Signal Processing plugin for Unity
The Unlicense
1.57k stars 121 forks source link

Unplugged audio interface requires restart #61

Open atesija opened 1 year ago

atesija commented 1 year ago

I had a show where I accidentally unplugged my audio interface and the only way to get audio again was by restarting my program. Is there a way to reset the audio input programmatically?

Reproduction steps: 1: Run a program using Lasp 2: Unplug your audio interface (I use a Focusrite Scarlet 2i2) 3: Plug it back in (expecting it all to keep working but instead it won't pick up audio again unless I restart the program)

The error I see when doing this in editor:

InStream error (Streaming)
0x00007ff7dc3b368d (Unity) StackWalker::GetCurrentCallstack
0x00007ff7dc3ba369 (Unity) StackWalker::ShowCallstack
0x00007ff7dd32b683 (Unity) GetStacktrace
0x00007ff7dd9c947d (Unity) DebugStringToFile
0x00007ff7db59abd2 (Unity) DebugLogHandler_CUSTOM_Internal_Log
0x000002d78b119e23 (Mono JIT Code) (wrapper managed-to-native) UnityEngine.DebugLogHandler:Internal_Log (UnityEngine.LogType,UnityEngine.LogOption,string,UnityEngine.Object)
0x000002d78b119d5b (Mono JIT Code) UnityEngine.DebugLogHandler:LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[])
0x000002d78b119ae0 (Mono JIT Code) UnityEngine.Logger:Log (UnityEngine.LogType,object)
0x000002d78b1199a8 (Mono JIT Code) UnityEngine.Debug:LogWarning (object)
0x000002d78b11969b (Mono JIT Code) [InputDeviceHandle.cs:313] Lasp.InputDeviceHandle:OnErrorInStream (SoundIO.InStreamData&,SoundIO.Error) 
0x000002d787f56c2b (Mono JIT Code) (wrapper native-to-managed) Lasp.InputDeviceHandle:OnErrorInStream (SoundIO.InStreamData&,SoundIO.Error)
0x000000005eab69f4 (soundio) soundio_ring_buffer_clear
0x000000005eab365c (soundio) soundio_version_patch
0x00007ffd2e567614 (KERNEL32) BaseThreadInitThunk
0x00007ffd2ee626a1 (ntdll) RtlUserThreadStart
keijiro commented 1 year ago

How about destroying/recreating related objects after device reconnection?

atesija commented 1 year ago

I tried recreating both the Spectrum Analyzer and an Audio Level Tracker but they seem frozen, like no audio is recognized. I made sure they used the same Device ID, channel, and other settings. I also tried resetting the scene by loading it fresh and that didn't work either. It feels like the audio stream that is read from breaks and can't be repaired.

(This isn't a big issue, I can always try to make sure the interface stays plugged in or try a different one if it's only happening with mine)