Hi,
I’m trying to load online sounds to Programmer Sounds.
I have 2 questions:
-
If I load 6 files into 6 programmer sounds, each one in one track, will it play in sync?
-
How can I add the name of the Programmer Sound and direct the loaded sound to this specific Programmer Sound?
This code allow me to load the audio file from the internet, but not to specify to which programmer sound name in the Event:
static FMOD.RESULT DialogueEventCallback(FMOD.Studio.EVENT_CALLBACK_TYPE type, IntPtr instancePtr, IntPtr parameterPtr)
{
// Recreate the event instance C# object
FMOD.Studio.EventInstance instance = new FMOD.Studio.EventInstance(instancePtr);
// Retrieve the user data
IntPtr stringPtr;
instance.getUserData(out stringPtr);
// Get the string object
GCHandle stringHandle = GCHandle.FromIntPtr(stringPtr);
String key = stringHandle.Target as String;
Debug.Log("Event = " + type);
switch (type)
{
case FMOD.Studio.EVENT_CALLBACK_TYPE.CREATE_PROGRAMMER_SOUND:
{
var parameter = (FMOD.Studio.PROGRAMMER_SOUND_PROPERTIES)Marshal.PtrToStructure(parameterPtr, typeof(FMOD.Studio.PROGRAMMER_SOUND_PROPERTIES));
FMOD.Sound dialogueSound;
var soundResult = FMODUnity.RuntimeManager.CoreSystem.createSound(key, FMOD.MODE.DEFAULT, out dialogueSound);
if (soundResult == FMOD.RESULT.OK)
{
parameter.sound = dialogueSound.handle;
Marshal.StructureToPtr(parameter, parameterPtr, false);
}
}
break;
case FMOD.Studio.EVENT_CALLBACK_TYPE.DESTROY_PROGRAMMER_SOUND:
{
var parameter = (FMOD.Studio.PROGRAMMER_SOUND_PROPERTIES)Marshal.PtrToStructure(parameterPtr, typeof(FMOD.Studio.PROGRAMMER_SOUND_PROPERTIES));
var sound = new FMOD.Sound(parameter.sound);
sound.release();
}
break;
case FMOD.Studio.EVENT_CALLBACK_TYPE.DESTROYED:
stringHandle.Free();
break;
}
return FMOD.RESULT.OK;
}
I’ve checked the getName but really don’t know how to link the sound to the programmer instrument.
I even created 6 events with one programmer instrument each.
Then created one Event with each one of these Event Instruments.
I loaded this script, but I got only one sound running and going directly to the master output. I couldn’t control anything on the track level (that I have full of parameters to control pan, volume, etc).
Anyway… nothing worked properly. What should I do here?
Here’s the full code:
using System;
using System.Collections.Generic;
using UnityEngine;
using System.Runtime.InteropServices;
class ProgrammerSounds : MonoBehaviour
{
FMOD.Studio.EVENT_CALLBACK dialogueCallback;
[FMODUnity.EventRef]
public string MyProgrammerEvent;
void Start()
{
dialogueCallback = new FMOD.Studio.EVENT_CALLBACK(DialogueEventCallback);
}
void PlayDialogue(string key)
{
var dialogueInstance = FMODUnity.RuntimeManager.CreateInstance(MyProgrammerEvent);
GCHandle stringHandle = GCHandle.Alloc(key, GCHandleType.Pinned);
dialogueInstance.setUserData(GCHandle.ToIntPtr(stringHandle));
dialogueInstance.setCallback(dialogueCallback);
dialogueInstance.start();
dialogueInstance.release();
}
[AOT.MonoPInvokeCallback(typeof(FMOD.Studio.EVENT_CALLBACK))]
static FMOD.RESULT DialogueEventCallback(FMOD.Studio.EVENT_CALLBACK_TYPE type, IntPtr instancePtr, IntPtr parameterPtr)
{
FMOD.Studio.EventInstance instance = new FMOD.Studio.EventInstance(instancePtr);
IntPtr stringPtr;
instance.getUserData(out stringPtr);
GCHandle stringHandle = GCHandle.FromIntPtr(stringPtr);
String key = stringHandle.Target as String;
switch (type)
{
case FMOD.Studio.EVENT_CALLBACK_TYPE.CREATE_PROGRAMMER_SOUND:
{
var parameter = (FMOD.Studio.PROGRAMMER_SOUND_PROPERTIES)Marshal.PtrToStructure(parameterPtr, typeof(FMOD.Studio.PROGRAMMER_SOUND_PROPERTIES));
FMOD.Sound dialogueSound;
var soundResult = FMODUnity.RuntimeManager.CoreSystem.createSound(key, FMOD.MODE.DEFAULT, out dialogueSound);
if (soundResult == FMOD.RESULT.OK)
{
parameter.sound = dialogueSound.handle;
Marshal.StructureToPtr(parameter, parameterPtr, false);
}
}
break;
case FMOD.Studio.EVENT_CALLBACK_TYPE.DESTROY_PROGRAMMER_SOUND:
{
var parameter = (FMOD.Studio.PROGRAMMER_SOUND_PROPERTIES)Marshal.PtrToStructure(parameterPtr, typeof(FMOD.Studio.PROGRAMMER_SOUND_PROPERTIES));
var sound = new FMOD.Sound(parameter.sound);
sound.release();
}
break;
case FMOD.Studio.EVENT_CALLBACK_TYPE.DESTROYED:
stringHandle.Free();
break;
}
return FMOD.RESULT.OK;
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Q))
{
PlayDialogue("http://www.mysite/myaudio.mp3");
}
if (Input.GetKeyDown(KeyCode.W))
{
PlayDialogue("c:/myaudio.wav");
}
}
}