5
\$\begingroup\$

I am trying to implement a method which should be called each 10ms with a precision not less than 0.1ms (better 0.05ms). This method is very complex and it is generating sound samples which are placed to float[] buffer to be played with OnAudioFilterRead function.

I have tried both Coroutines and InvokeRepeating - both are bad, because they can call the method with period from 7ms to 13ms which is not acceptable.

The only idea I have is another Task with while() cycle checking the Time.realtimeSinceStartup permanently. But I feel like this is a bad idea.

Can you help me? Thanks.

\$\endgroup\$
  • \$\begingroup\$ If you use an empty object and put float[] buffer generation in fixedupdate? And then generate the exact amount of data relative to Time.fixedDeltaTime? \$\endgroup\$ – dnk drone.vs.drones Nov 27 '17 at 12:22
1
\$\begingroup\$

Yes, You can use multi-threading which is not recommended in many cases but it can be used if threads are managed correctly and made sure that Unity API is being called from main thread only.

Read more about pros and cons of using multi-threading:

Why Should I Use Threads Instead Of Coroutines?

Hope this helps :)

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.