Debugging sampler issues

It seems that on some of our imps a sampler we had running is no longer running. Do they eventually time out? Any suggestions on how to debug this issue when it’s intermittent.


Here is the code I’m using if that helps.

class SampleManager {
static SAMPLE_HZ = 50;

_buffer = blob(100);

constructor() {
    hardware.sampler.configure(hardware.pinH, SAMPLE_HZ, [_buffer], function(buffer, length){ _processSamples(buffer, length); }.bindenv(this));

function _processSamples(buffer, length) {
    if (length > 0) {
        for (local i = 0; i < SAMPLE_HZ; ++i) {
            local sample = buffer.readn('s');


You only have a single buffer queued, which means if your callback takes longer than 1/50th of a second to run, you’ll overrun.

It’s worth printing the buffer length in your callback (especially if it’s not full) - if there’s an overrun then you’ll see that here.

Thanks. So if an over-run occurs do you need to stop and start the sampler?

I’m pretty sure that’s what happens.