- Home /
Procedural native audio synthesis with OnAudioFilterRead
I'm trying to use the Unity3.5 audio buffer access to integrate a synthesis engine in C to produce audio.
When I try to do it in the most efficient way, i.e. passing the audio buffer pointer, I get crashes in what looks like FMOD memory management.
Maybe I'm not allowed to pass arrays by reference like that, since the (hoped for) memory pinning seems to invoke some runtime code that is not allowed in the audio thread or so? I only have shaky knowledge about the Mono C# to C interface, p/invoke, marshaling, and all that.
the C# audio filter script on the (empty) audio source:
 [DllImport ("synth-lib")]
 private static extern void synth (IntPtr self, int nsamp, float[] data, int channels);
     
 void OnAudioFilterRead (float[] data, int channels)  {
         synth(impl_, data.Length, data, channels); 
 }
the C code prototype:
  void synth (mysynth_t *self, int nsamp, float *data, int channels); 
the crash log:
 Thread 0:  Dispatch queue: com.apple.main-thread
 4   libmono.0.dylib                   0x02845278 mono_handle_native_sigsegv + 327
 5   libSystem.B.dylib                 0x93c6505b _sigtramp + 43
 6   ???                               0xffffffff 0 + 4294967295
 7   fmod_editor.dylib                 0x02ac904e 0x2ac7000 + 8270
 8   fmod_editor.dylib                 0x02b2b249 FMOD::SystemI::getMemoryUsedImpl(FMOD::MemoryTracker*) + 2181
 9   fmod_editor.dylib                 0x02b28db1 FMOD::System::lockDSP() + 39
 10  com.unity3d.UnityEditor3.x        0x006514a7 AudioManager::ProcessScheduledSources() + 23
 11  com.unity3d.UnityEditor3.x        0x00659ea3 AudioManager::Update() + 51
 
 Thread 16 Crashed:
 0   libSystem.B.dylib                 0x93c6c0ee __semwait_signal_nocancel + 10
 6   libmono.0.dylib                   0x027be019 mono_sigsegv_signal_handler + 498
 7   libSystem.B.dylib                 0x93c6505b _sigtramp + 43
 8   ???                               0xffffffff 0 + 4294967295
 9   libmono.0.dylib                   0x02986483 g_log + 41
 10  libmono.0.dylib                   0x028d5946 mono_array_to_lparray + 164
 11  ???                               0x08bd400c 0 + 146620428
 12  ???                               0x38641a78 0 + 946084472
 13  ???                               0x3864161f 0 + 946083359
 14  ???                               0x3864193e 0 + 946084158
 15  libmono.0.dylib                   0x027c5140 mono_jit_runtime_invoke + 1149
 16  libmono.0.dylib                   0x0290d170 mono_runtime_invoke + 133
 17  com.unity3d.UnityEditor3.x        0x00678933 AudioCustomFilter::readCallback(FMOD_DSP_STATE*, float*, float*, unsigned int, int, int) + 291
 18  fmod_editor.dylib                 0x02b0483b FMOD::DSPConnection::getInput(FMOD::DSP**) + 18131
Did you ever solve this issue? Although not working with procedural audio, we are seeing a large number of crashes at various points in our game to do with unity re-gaining focus on iOS devices, all the crash logs seem to call that get$$anonymous$$emoryUsedImpl method right before they then abort and die.
Been trying to solve this for a few days now and we're getting nowhere.
Answer by drudiverse · Dec 10, 2014 at 11:48 PM
Have to pass the onaudiofilterread function a float array of same length as audiobuffer settings.
See reference for example of the loop that has to be in the function, i dont think that above code would work on it. it's a tricky code it needs just 1-2 loops and if functions.
Your answer
 
 
             Follow this Question
Related Questions
Game created that Users can add own music? 1 Answer
Can you fix my code? (Audio for doors) 2 Answers
OnAudioFilterRead issues on Android? 1 Answer
Making sounds wait for each other to finish 2 Answers
Sprinting Audio Problem 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
               
 
			 
                