System.createSound from raw byte array fails with ERR_INTERNAL

Hi,

I’m trying to create a sound from a byte array like this:

FMOD.Sound mySound;

CREATESOUNDEXINFO exInfo = new CREATESOUNDEXINFO()
{
	defaultfrequency = soundData.Frequency,
	numchannels = soundData.Channels,
	format = soundData.Format,                    
	length = (uint)soundData.Data.Length,
	cbsize = System.Runtime.InteropServices.Marshal.SizeOf(typeof(CREATESOUNDEXINFO))
};

FMOD.RESULT result = coreSystem.createSound(soundData.Data, FMOD.MODE.OPENRAW | FMOD.MODE.CREATESAMPLE , ref exInfo, out mySound);
UnityEngine.Debug.Log(result);

but createSound fails with ERR_INTERNAL.
The byte array and all other data (frequency, format) have been previously extracted like this:

uint byteCount = 0;
sound.getLength(out byteCount, TIMEUNIT.PCMBYTES);

IntPtr ptr1;
IntPtr ptr2;
uint len1;
uint len2;

sound.@lock(0, byteCount, out ptr1, out ptr2, out len1, out len2);

byte[] myData = new byte[len1];

FMOD.SOUND_TYPE type;
FMOD.SOUND_FORMAT format;
int channels;
int bits;
float frequency;
int priority;

sound.getFormat(out type, out format, out channels, out bits);
sound.getDefaults(out frequency, out priority);

Marshal.Copy(ptr1, myData, 0, (int)len1);

sound.unlock(ptr1, ptr2, len1, len2);

sound.release();

Any ideas on what could be causing that error (I’m using C#, Unity 2019.2.8f1 and FMOD Unity Integration 2.00.05)?
Thanks in advance!

I figured it out myself. Both FMOD.MODE.OPENMEMORY and FMOD.MODE.OPENRAW are required.

   FMOD.RESULT result = coreSystem.createSound(soundData.Data, FMOD.MODE.OPENMEMORY | FMOD.MODE.OPENRAW | FMOD.MODE.CREATESAMPLE, ref exInfo, out mySound);
1 Like