# playSound returns ERR\_INVALID\_POSITION for user created stream.

**URL:** https://qa.fmod.com/t/playsound-returns-err-invalid-position-for-user-created-stream/12678
**Category:** Unity
**Created:** [September 4, 2016, 6:20am UTC](https://qa.fmod.com/t/playsound-returns-err-invalid-position-for-user-created-stream/12678 "2016-09-04T06:20:59Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![r618](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/r618/32/36_2.png) [@r618](https://qa.fmod.com/u/r618)
#### Post date: [September 4, 2016, 6:20am UTC](https://qa.fmod.com/t/playsound-returns-err-invalid-position-for-user-created-stream/12678/1 "2016-09-04T06:20:59Z")

</div>

Hi,

I’m trying to replicate `user_created_sound` low level cpp sample in Unity, but getting error from %subj%.  
I have

`...`  
`FMOD.CREATESOUNDEXINFO exinfo = new FMOD.CREATESOUNDEXINFO();`  
`exinfo.numchannels = 2;`  
`exinfo.defaultfrequency = 44100;`  
`exinfo.decodebuffersize = 44100;`  
`exinfo.length = (uint)( exinfo.defaultfrequency * exinfo.numchannels * 2 * 5 ); // 2 == sizeof(short) or Int16 or two bytes per sample in channel`  
`exinfo.format = FMOD.SOUND_FORMAT.PCM16;`  
`exinfo.pcmreadcallback = this.pcmreadcallback;`  
`exinfo.pcmsetposcallback = this.pcmsetposcallback;`

`result = system.createSound( "", FMOD.MODE.OPENUSER | FMOD.MODE.CREATESTREAM, ref exinfo, out sound);`  
`// here result == FMOD.RESULT.OK`

`result = system.playSound(sound, null, false, out channel);`  
`// here result == FMOD.RESULT.ERR_INVALID_POSITION`  
`...`

Both callbacks defined as specified by respective delegate get called from/by `createSound` with proper parameters… , but playSound always fails with seeking error ( no callbacks, obviously, are called afterwards ); is this an overlook in the c# wrapper / unity plugin, or am I doing something very stupid ?

Thanks!

---

<div class="post-metadata">

### Author: ![nick1](https://avatars.discourse-cdn.com/v4/letter/n/47e85d/32.png) [@nick1](https://qa.fmod.com/u/nick1)
#### Post date: [September 5, 2016, 2:25am UTC](https://qa.fmod.com/t/playsound-returns-err-invalid-position-for-user-created-stream/12678/2 "2016-09-05T02:25:41Z")

</div>

> [@](#):
>
> Hi,
> 
> I’m trying to replicate `user_created_sound` low level cpp sample in Unity, but getting error from %subj%.  
> I have
> 
> `...`  
> `FMOD.CREATESOUNDEXINFO exinfo = new FMOD.CREATESOUNDEXINFO();`  
> `exinfo.numchannels = 2;`  
> `exinfo.defaultfrequency = 44100;`  
> `exinfo.decodebuffersize = 44100;`  
> `exinfo.length = (uint)( exinfo.defaultfrequency * exinfo.numchannels * 2 * 5 ); // 2 == sizeof(short) or Int16 or two bytes per sample in channel`  
> `exinfo.format = FMOD.SOUND_FORMAT.PCM16;`  
> `exinfo.pcmreadcallback = this.pcmreadcallback;`  
> `exinfo.pcmsetposcallback = this.pcmsetposcallback;`
> 
> `result = system.createSound( "", FMOD.MODE.OPENUSER | FMOD.MODE.CREATESTREAM, ref exinfo, out sound);`  
> `// here result == FMOD.RESULT.OK`
> 
> `result = system.playSound(sound, null, false, out channel);`  
> `// here result == FMOD.RESULT.ERR_INVALID_POSITION `  
> `...`
> 
> Both callbacks defined as specified by respective delegate get called from/by `createSound` with proper parameters… , but playSound always fails with seeking error ( no callbacks, obviously, are called afterwards ); is this an overlook in the c# wrapper / unity plugin, or am I doing something very stupid ?
> 
> Thanks!

See [http://www.fmod.org/documentation/#content/generated/engine\_new\_unity/script\_example\_timeline.html](http://www.fmod.org/documentation/#content/generated/engine_new_unity/script_example_timeline.html) for example of using C# callbacks and avoiding GC issues. Please update with the content of the callbacks if you’re still having issues.

---

<div class="post-metadata">

### Author: ![r618](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/r618/32/36_2.png) [@r618](https://qa.fmod.com/u/r618)
#### Post date: [September 5, 2016, 4:05am UTC](https://qa.fmod.com/t/playsound-returns-err-invalid-position-for-user-created-stream/12678/3 "2016-09-05T04:05:07Z")

</div>

Thanks, but still the same result / the callbacks are (for testing) empty, just returning immediately:

`[AOT.MonoPInvokeCallback(typeof(FMOD.SOUND_PCMREADCALLBACK))]`  
`FMOD.RESULT PCMReadCallback(System.IntPtr soundraw, System.IntPtr data, uint datalen) {`  
`return FMOD.RESULT.OK;`  
`}`

`[AOT.MonoPInvokeCallback(typeof(FMOD.SOUND_PCMSETPOSCALLBACK))]`  
`FMOD.RESULT PCMSetPosCallback(System.IntPtr soundraw, int subsound, uint position, FMOD.TIMEUNIT postype)`  
`{`  
`return FMOD.RESULT.OK;`  
`}`

`FMOD.SOUND_PCMREADCALLBACK pcmreadcallback;`  
`FMOD.SOUND_PCMSETPOSCALLBACK pcmsetposcallback;`

`void Start() {`  
`this.pcmreadcallback = new FMOD.SOUND_PCMREADCALLBACK(PCMReadCallback);`  
`this.pcmsetposcallback = new FMOD.SOUND_PCMSETPOSCALLBACK(PCMSetPosCallback);`

`FMOD.CREATESOUNDEXINFO exinfo = new FMOD.CREATESOUNDEXINFO();`  
`...`  
`}`

both of them are called by `createSound`, but `playSound` still returns ERR\_INVALID\_POSITION

( empty read callback just for testing, when it has its body:

`float t1 = 0, t2 = 0; // time`  
`float v1 = 0, v2 = 0; // velocity`

`[AOT.MonoPInvokeCallback(typeof(FMOD.SOUND_PCMREADCALLBACK))]`  
`FMOD.RESULT PCMReadCallback(System.IntPtr soundraw, System.IntPtr data, uint datalen)`  
`{`  
`for (int count = 0; count < (datalen >> 2); count++) // >>2 = 16bit stereo (4 bytes per sample)`  
`{`  
`System.Runtime.InteropServices.Marshal.WriteInt16(data, 0, (short)(Mathf.Sin(t1) * 32767f));`  
`System.Runtime.InteropServices.Marshal.WriteInt16(data, 1, (short)(Mathf.Sin(t2) * 32767f));`

`t1 += 0.01f + v1;`  
`t2 += 0.0142f + v2;`  
`v1 += (float)(Mathf.Sin(t1) * 0.002f);`  
`v2 += (float)(Mathf.Sin(t2) * 0.002f);`  
`}`

`return FMOD.RESULT.OK;`  
`}`

the result is still the same )

---

<div class="post-metadata">

### Author: ![r618](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/r618/32/36_2.png) [@r618](https://qa.fmod.com/u/r618)
#### Post date: [September 5, 2016, 4:07am UTC](https://qa.fmod.com/t/playsound-returns-err-invalid-position-for-user-created-stream/12678/4 "2016-09-05T04:07:08Z")

</div>

( sorry about the formatting, apparently it isn’t recognized in the comment / )

---

<div class="post-metadata">

### Author: ![nick1](https://avatars.discourse-cdn.com/v4/letter/n/47e85d/32.png) [@nick1](https://qa.fmod.com/u/nick1)
#### Post date: [September 5, 2016, 5:28am UTC](https://qa.fmod.com/t/playsound-returns-err-invalid-position-for-user-created-stream/12678/5 "2016-09-05T05:28:29Z")

</div>

There’s a bug in the C# API wrapper. The fix will be released in 1.08.11.

You can see the fix here:

> <https://github.com/fmod/UnityIntegration/commit/12849c22cab51af82c1b21ba6b3e624c81447307>

---

<div class="post-metadata">

### Author: ![r618](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/r618/32/36_2.png) [@r618](https://qa.fmod.com/u/r618)
#### Post date: [September 5, 2016, 5:56am UTC](https://qa.fmod.com/t/playsound-returns-err-invalid-position-for-user-created-stream/12678/6 "2016-09-05T05:56:48Z")

</div>

> [@](#):
>
> There’s a bug in the C# API wrapper. The fix will be released in 1.08.11.
> 
> You can see the fix here:  
> [Fix marshalling of CREATESOUNDEXINFO · fmod/fmod-for-unity@12849c2 · GitHub](https://github.com/fmod/UnityIntegration/commit/12849c22cab51af82c1b21ba6b3e624c81447307)

Thanks for the info and link !
