- Home /
How do I profile a C DSP plugin function called from OnAudioFilterRead?
I have a procedural audio synthesis algorithm in C that I integrated to unity. It generates sound samples values in order to fill the audio buffer in OnAudioFilterRead.
I would like to profile my C function to see how much cpu ressources it uses. My problem is that neither my function nor OnAudioFilterRead show up in Unity Pro profiler. Also if I try to invoke the profiler from my script using Profiler.BeginSample() like this:
void OnAudioFilterRead (float[] data, int channels)
{
Profiler.BeginSample("myFunction");
//my Code that fills an audio buffer
Profiler.EndSample ();
}
I get the following runtime error:
" ArgumentException: BeginSampleOnly can only be called from the main thread. Constructors and field initializers will be executed from the loading thread when loading a scene. Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function. UnityEngine.Profiler.BeginSample (System.String name) PlayerController.OnAudioFilterRead (System.Single[] data, Int32 channels) (at Assets/Scripts/PlayerController.cs:96) "
How can I profile my C plugin function called from OnAudioFilterRead?
Your answer
![](https://koobas.hobune.stream/wayback/20220613143032im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Unity plugin folder 0 Answers
How to access USB on Linux 1 Answer
editor script memory leak 1 Answer
Profiler.BeginSample() performance - does it affect it while not profiling? 1 Answer
Can I create plugins for Unity > Flash exported games? 0 Answers