# Trouble playing data segments through Programmer Instrument

**URL:** <https://qa.fmod.com/t/trouble-playing-data-segments-through-programmer-instrument/18568>\
**Category:** Unity\
**Tags:** csharp\
**Created:** [March 23, 2022, 10:43pm UTC](https://qa.fmod.com/t/trouble-playing-data-segments-through-programmer-instrument/18568 "2022-03-23T22:43:19Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![Bryles](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/bryles/32/3356_2.png) [@Bryles](https://qa.fmod.com/u/Bryles)\
**Post date:** [April 3, 2022, 6:30pm UTC](https://qa.fmod.com/t/trouble-playing-data-segments-through-programmer-instrument/18568/3 "2022-04-03T18:30:33Z")

</div>

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.

```auto
    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;
    }

```

---

_[View the full topic](https://qa.fmod.com/t/trouble-playing-data-segments-through-programmer-instrument/18568)._
