- Home /
How does one apply a filter to an audioClip instead of the realtime using OnAudioFilterRead?
I have experience with audio, but almost none with unity. I am making a granular sampler that will analize the sounds looking for the next zero crossing that has the most similar transient to the current starting point.
For this I want to make an initial analysis through the whole sample. The OnAudioFilterRead window of 512 samples is too short even for any kind of granular sampling. In this analysis, the program will choose, let's say 1024 possible starting points throughout the sample (a short sample) and find an array of loop endpoints that will loop seamlesly, looking for zero crossings and then maybe using mean square difference or something simpler.
So my question is, how can I get this sample and iterate through the whole array of floats of it's buffer? Albeit it may be expensive, it should be ok for short samples; and want to make different experiments in this context anyways.
Answer by Bunny83 · Nov 22, 2016 at 09:23 PM
It's not quite clear what you actually mean by "apply the filter", but if you just want access to the samples of an AudioClip, just have a look at the documentation. There you will find the method GetData which can read a block of samples (or the whole clip depending on your array size). Keep in mind that the AudioClip must be "readable". So compressed audioclips can't be read unless they are imported as "decompress on load". All this is explained in the docs.
Your answer