# BufferPlayerNode assertion upon using .start(when)

**URL:** <https://discourse.libcinder.org/t/bufferplayernode-assertion-upon-using-start-when/841>\
**Category:** Uncategorized\
**Created:** [August 28, 2017, 2:05am UTC](https://discourse.libcinder.org/t/bufferplayernode-assertion-upon-using-start-when/841 "2017-08-28T02:05:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Callum](https://avatars.discourse-cdn.com/v4/letter/c/5f8ce5/32.png) [@Callum](https://discourse.libcinder.org/u/Callum)\
**Post date:** [August 28, 2017, 2:05am UTC](https://discourse.libcinder.org/t/bufferplayernode-assertion-upon-using-start-when/841/1 "2017-08-28T02:05:32Z")

</div>

Hi,

## Problem

I am having difficulties playing audio starting at a specific time using [BufferPlayerNode](https://libcinder.org/docs/classcinder_1_1audio_1_1_buffer_player_node.html) and the .start(when) method.

## Diagnosis

At runtime, an assertion is triggered in another thread:

```auto
Assertion failed: (frameOffset + numFrames <= this->getNumFrames()), function copyOffset, file /Users/callumhoward/codeoncanvas/Cinder.git/include/cinder/audio/Buffer.h, line 155.

```

The `frameOffset` variable in the assertion frame appears like it may be uninitialised as it is a very large value: `frameOffset	size_t	18446744073709442560`

## Steps to reproduce

I have come up with a simple way to reproduce this problem:  
Start with the BufferPlayerApp sample code found [here](https://github.com/cinder/Cinder/blob/e39a8f62fa75897d7640d99cee8ddf7e6777ffbd/samples/_audio/BufferPlayer/src/BufferPlayerApp.cpp#L82), and change line 82 from

```auto
	mBufferPlayerNode->start();

```

to add a time to start from: 0.0.

```auto
	mBufferPlayerNode->start(0.0);

```

expected behaviour should be identical to before the change.

I have searched the forums and github issues, but nothing seems to come up. I must be misunderstanding how it should be used.

I am on release 0.9.1 on macOS 10.12.6 using Xcode 8.3.3

---

<div class="post-metadata">

**Author:** ![lithium](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/lithium/32/38_2.png) [@lithium](https://discourse.libcinder.org/u/lithium)\
**Post date:** [August 28, 2017, 10:20am UTC](https://discourse.libcinder.org/t/bufferplayernode-assertion-upon-using-start-when/841/2 "2017-08-28T10:20:14Z")

</div>

Looking at the cinder source, the `when` appears not to be a time offset into the `BufferNode`, but a delay after which to start playing. I agree that calling `start(0.0)` should probably fall back to just calling `start()` (or maybe be renamed to `startIn (float secondsFromNow)`), but this explains why you’re seeing what you’re seeing.

@rich.e is the man you want to speak to, though.

---

<div class="post-metadata">

**Author:** ![Callum](https://avatars.discourse-cdn.com/v4/letter/c/5f8ce5/32.png) [@Callum](https://discourse.libcinder.org/u/Callum)\
**Post date:** [August 29, 2017, 1:41pm UTC](https://discourse.libcinder.org/t/bufferplayernode-assertion-upon-using-start-when/841/3 "2017-08-29T13:41:29Z")

</div>

Thanks for clearing that up. I’ll use `start()` and then call `seekToTime()`.

---

<div class="post-metadata">

**Author:** ![rich.e](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/rich.e/32/1025_2.png) [@rich.e](https://discourse.libcinder.org/u/rich.e)\
**Post date:** [September 5, 2017, 8:35pm UTC](https://discourse.libcinder.org/t/bufferplayernode-assertion-upon-using-start-when/841/4 "2017-09-05T20:35:30Z")

</div>

Yes the double argument to `start()` and `enable()` methods represent an offset into the audio graph’s notion of time, it has nothing to do with the sample being played. This was an idea borrowed from the Web Audio api, although I don’t think it is an optional argument there (can’t remember). We could perhaps rename it to `startAt( when )`, but I sort of like having less methods and in this case I think the in line docs should get you on the right track (and please let me know if there is a way to word this better). I will look into making sure that assertion doesn’t fire, though, I imagine that if you specify any time that is in the ‘past’ (for the audio thread), then it will just start / enable immediately.

Also, although highly unlikely it’s best to do the seek before starting playback. Since they are atomic operations happening on different threads there is a small chance that the audio thread will play its first buffer from the beginning as it won’t have received the seek call yet.

cheers,  
Rich

---

<div class="post-metadata">

**Author:** ![Callum](https://avatars.discourse-cdn.com/v4/letter/c/5f8ce5/32.png) [@Callum](https://discourse.libcinder.org/u/Callum)\
**Post date:** [September 5, 2017, 11:51pm UTC](https://discourse.libcinder.org/t/bufferplayernode-assertion-upon-using-start-when/841/5 "2017-09-05T23:51:15Z")

</div>

Thanks, I’ll do that.

---

<div class="post-metadata">

**Author:** ![rich.e](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/rich.e/32/1025_2.png) [@rich.e](https://discourse.libcinder.org/u/rich.e)\
**Post date:** [September 19, 2017, 9:17pm UTC](https://discourse.libcinder.org/t/bufferplayernode-assertion-upon-using-start-when/841/6 "2017-09-19T21:17:56Z")

</div>

As an update, I’ve added a guard ([here](https://github.com/richardeakin/Cinder/commit/1ff75551e7e886cfabae126ad9266b1ae02d581b)) so a `when` time in the past just gets scheduled next processing block. It is part of this PR: [https://github.com/cinder/Cinder/pull/1899](https://github.com/cinder/Cinder/pull/1899)

Thanks for reporting, and making it easy to reproduce!

cheers,  
Rich
