I’m trying to convert a Unity AudioClip to an FMOD.Sound and I followed that post:
http://52.88.2.202/questions/question/load-an-audioclip-as-fmod-sound
I have a single FMODSystem object that I use to create various sounds and play them:
FMOD.RESULT result;
FMOD.Factory.System_Create(ref fmodSystem);
result = fmodSystem.init(4, FMOD.INITFLAG.NORMAL, System.IntPtr.Zero);
And I have this method here for converting AudioClips into FMOD.Sounds:
private FMOD.Sound ConvertAudioClip(AudioClip clip){
float[] samples = new float[clip.samples * clip.channels];
clip.GetData(samples, 0);
uint lenbytes = (uint)(clip.samples * clip.channels * sizeof(float));
FMOD.CREATESOUNDEXINFO soundinfo = new FMOD.CREATESOUNDEXINFO();
soundinfo.length = lenbytes;
soundinfo.format = FMOD.SOUND_FORMAT.PCMFLOAT;
soundinfo.defaultfrequency = clip.frequency;
soundinfo.numchannels = clip.channels;
FMOD.RESULT result;
FMOD.Sound sound = new FMOD.Sound();
result = fmodSystem.createSound("", FMOD.MODE.OPENUSER, ref soundinfo, ref sound);
Debug.Log(result);
System.IntPtr ptr1 = System.IntPtr.Zero, ptr2 = System.IntPtr.Zero;
uint len1 = (uint)0, len2 = (uint)0;
result = sound.@lock(0, lenbytes, ref ptr1, ref ptr2, ref len1, ref len2);
Marshal.Copy(samples, 0, ptr1, (int)(len1 / sizeof(float)));
if (len2 > 0)
{
Marshal.Copy(samples, (int)(len1 / sizeof(float)), ptr2, (int)(len2 / sizeof(float)));
}
result = sound.unlock(ptr1, ptr2, len1, len2);
result = sound.setMode(FMOD.MODE.LOOP_NORMAL);
return sound;
}
However, when I log the result from creating the sound I get an ERR_INVALID_PARAM error. What could be causing this ?
Thanks!