Getting samples from programmer sound

Hello.

I’m using Programmer Instrument to apply effects to player voices. Is there a callback that gets called after the effect is applied to get the processed samples? I need this so that I can reuse the data for playback elsewhere.
In my case, it’s a radio. The player speaks into local chat, and I want the audio from local chat to go straight to the radio with all the effects applied to local chat.
The final samples should not be mixed together, that is, I need the ability to get samples of each programmer sound separately.

[AOT.MonoPInvokeCallback(typeof(EVENT_CALLBACK))]
private static RESULT ProgrammerSoundEventCallback(EVENT_CALLBACK_TYPE type, IntPtr instancePtr, IntPtr parameterPtr)
{
    EventInstance instance = new EventInstance(instancePtr);

    instance.getUserData(out IntPtr stringPtr);

    GCHandle stringHandle = GCHandle.FromIntPtr(stringPtr);
    SoundWrapper soundWrapper = stringHandle.Target as SoundWrapper;
    switch (type)
    {
        case EVENT_CALLBACK_TYPE.CREATE_PROGRAMMER_SOUND:
            {
                PROGRAMMER_SOUND_PROPERTIES parameter = (PROGRAMMER_SOUND_PROPERTIES)Marshal.PtrToStructure(parameterPtr, typeof(PROGRAMMER_SOUND_PROPERTIES));
                parameter.sound = soundWrapper.Sound.handle;

                Marshal.StructureToPtr(parameter, parameterPtr, false);
                break;
            }
        case EVENT_CALLBACK_TYPE.DESTROYED:
            {
                stringHandle.Free();
                break;
            }
    }

    return RESULT.OK;
}

Hi,

Based on what you’ve explained, I suspect the easiest way to get access to the samples after effects are applied would be to create your own DSP with a read callback, and add it to the channel the effects are on after the effects. Using the read callback, you can intercept the incoming audio buffer and pass it out of the callback using the DSP’s user data.

Our DSP Capture script provides an example of how to do this with a DSP on the master channel; in your case, you’ll likely need to drill down to your event’s channel group and potentially to the relevant channel as well so you can add the DSP to it.

Hello.

Thanks you for reply.
I managed to get samples. I will need to convert the resulting samples to FMOD.Sound, what do you recommend for this: lock/unlock or pcmreadcallback? Before this I used lock/unlock, but not with DSP callback.

I’d recommend using pcmreadcallback in this case, and if possible in most cases.

By default, the FMOD Studio mixer is set up to process audio asynchronously to the main thread. pcmreadcallbackis fired from the mixer, so using it ensures that the sample data you provide is synced with the mixer’s update period.

Lock/unlock are driven by your main thread’s update period, which may differ from the mixer - as a result, you’ll likely need to implement safeguards to ensure that you don’t call lock/unlock more than once in a single mixer period, or accidentally provide the same block of sample data twice, etc.

1 Like