Hello! I’ve used FMOD previous for monogame, and I’m porting the project over to Unity. I’m using a .wav file as an instrument in the game. It’s the same file that I used and worked in the monogame project.
Load Type : Decompress on Load
Preload Audio Data : True (would prefer not, but for testing).
Compression format: PCM
I made sure to initialize fmod first;
FMODUnity.RuntimeManager.CoreSystem.init(32, FMOD.INITFLAGS.NORMAL, (IntPtr)0);
I’ve converted an audioclip to FMOD.Sound using this code. This probably where I mess up. It’s a bit low level for me too be honest!
unityClip.GetData(samples, 0);
byte[] byteArray = new byte[samples.Length * sizeof(float)];
System.Buffer.BlockCopy(samples, 0, byteArray, 0, byteArray.Length);
uint lenbytes = (uint)(unityClip.samples * unityClip.channels * sizeof(float));
CREATESOUNDEXINFO soundinfo = new CREATESOUNDEXINFO();
soundinfo.cbsize = Marshal.SizeOf(typeof(CREATESOUNDEXINFO));
soundinfo.length = lenbytes;
//soundinfo.format = SOUND_FORMAT.BITSTREAM;
soundinfo.format = SOUND_FORMAT.PCMFLOAT;
soundinfo.defaultfrequency = unityClip.frequency;
soundinfo.numchannels = unityClip.channels;
RESULT result;
FMOD.Sound sound;
//doesn't work
//result = RuntimeManager.CoreSystem.createSound(byteArray, FMOD.MODE.OPENMEMORY | FMOD.MODE.CREATESAMPLE, ref soundinfo, out sound);
//I'm not sure where to actually pass the float array
result = RuntimeManager.CoreSystem.createSound(unityClip.name, FMOD.MODE.OPENUSER | FMOD.MODE.CREATESAMPLE, ref soundinfo, out sound);
if (result != FMOD.RESULT.OK)
Debug.LogError($"error creating sound {result}" );
else
Debug.Log($"converted sound {result} : sound");
I then try to play this sound as followed;
{
sound = FmodSound.LoadSound(instrumentPlayer.audioClip);
RuntimeManager.CoreSystem.createChannelGroup(" test", out channelGroup);
channelGroup.setVolumeRamp(false);
channelGroup.setVolume(1);
}
// Update is called once per frame
void Update()
{
Keyboard keyboard = playerInput.GetDevice<Keyboard>();
if (keyboard == null) return;
if (keyboard.dKey.wasPressedThisFrame)
{
RuntimeManager.CoreSystem.playSound( sound, channelGroup, false, out FMOD.Channel fmodChannel);
fmodChannel.setVolume(1);
fmodChannel.setVolumeRamp(false);
//instrumentPlayer.instrument.Play(Note.C3);
}
}
I can see a channel is created, but the volume remains at -80.
I’m sure I’m just forgetting a very basic thing, help is appreciated!