Hello,
I am a bit lost on how exactly FMOD can receive information taken from an AudioClip in Unity, and how this can be used to eventually create a Programmer Sound.
I’ve followed the general advice here: How to create programmer sound from AUDIOCLIP
But I’m still not sure what to put as the SoundRequirements parameters in the attached image.
Also attached is the full script I’m attempting to use based off the above post.
Thank you!
AudioClipTest.txt (7.9 KB)
Hi,
Thank you for adding the full script.
I have updated your code with some more comments explaining what is going on in a bit more detail.
PlayClipInFmod
public void PlayClipInFmod(AudioClip audioclip)
{
UnityEngine.Debug.Log("PlayClipinFmod " + audioclip.name);
// Get the sample data from the clip and assign in to an array
float[] audioclip_data = new float[audioclip.samples * audioclip.channels];
audioclip.GetData(audioclip_data, 0);
// We no longer require the 'key' parameter as it was used to access the FMOD audio table.
// string key = audioclip.name;
// We are getting the information out of the Unity Audio clip passed into the function
SoundRequirements sound_requirements = new SoundRequirements(
// The name of the clip we are playing, makes it easier to identify when in code
audioclip.name,
// Parameters required to create sound exit info: https://fmod.com/docs/2.02/api/core-api-system.html#fmod_createsoundexinfo
audioclip.samples,
audioclip.channels,
FMOD.SOUND_FORMAT.PCMFLOAT,
audioclip.frequency,
// The sample data that will be copied into the sound when we create it
audioclip_data);
//
// Renamed this for clarity.
var audioClipInstance = FMODUnity.RuntimeManager.CreateInstance(EventName);
// Instead of passing in the key we will pass in the sound requirements that we have created.
GCHandle stringHandle = GCHandle.Alloc(sound_requirements);
audioClipInstance.setUserData(GCHandle.ToIntPtr(stringHandle));
// The callback to make the create the sound and assign it to the instance
audioClipInstance.setCallback(dialogueCallback);
// Play the sound
audioClipInstance.start();
// Release the memory, however if you would like to access parameters or other functions of the instane,
// you don't have to release it now.
audioClipInstance.release();
}
I have also uploaded the edited script.
AudioClipTest.txt (7.4 KB)
Hope this helps!
1 Like