Trouble playing data segments through Programmer Instrument

Hi Jeff,
I managed to get it working a while ago through some experimentation and it seems to do the trick!
I wont paste the full code but this is the PCM reader callback I ended up with and I ended up only initializing the sound once during the programmer instrument creation callback.

    FMOD.RESULT PcmReadCallback(IntPtr sound, IntPtr data, uint datalen) {
        if(!isReady || outputBuffer == null || readerPosition>outputBuffer.Length) return FMOD.RESULT.OK;

        byte[] modifiedData = new byte[datalen];

        for (int i=0; i<datalen; ++i)
        {
            // Start with silence
            modifiedData[i] = 0;
 
            // Check for any buffer data
            if (bufferCount > 0)
            {
                // Copy data from reader position
                modifiedData[i] = outputBuffer[readerPosition];

                // Loop reader index
                readerPosition = (readerPosition + 1) % outputBufferSize;
                bufferCount--;
            }
        }

        Marshal.Copy(modifiedData, 0, data, (int)datalen);

        return FMOD.RESULT.OK;
    }
1 Like