diff --git a/Sample.h b/Sample.h index 30a2d60ef..df7e8db65 100644 --- a/Sample.h +++ b/Sample.h @@ -95,12 +95,15 @@ class Sample } - /** Resets the phase (the playhead) to the start position, which will be 0 unless set to another value with setStart(); - */ + /** + * Resets the phase (the playhead) to the start position, which will be 0 unless set to another value with setStart(); + * Also unpauses playback if it's paused. + */ inline void start() { phase_fractional = startpos_fractional; + if(paused) setPaused(false); } @@ -114,6 +117,20 @@ class Sample start(); } + /** Puts playback of the sample on pause or unpauses it. + * When paused, "next()" does not advance position and returns 0. + * @param to_pause whether to pause or unpause, default true + */ + inline + void setPaused(bool to_pause = true) + { + paused = to_pause; + } + + /** Checks whether playback is paused. */ + inline + bool isPaused() { return paused; } + /** Sets the end position in samples from the beginning of the sound. @param end position in samples. @@ -164,6 +181,8 @@ class Sample inline int8_t next() { // 4us + if (paused) return 0; + if (phase_fractional>endpos_fractional){ if (looping) { phase_fractional = startpos_fractional + (phase_fractional - endpos_fractional); @@ -192,7 +211,7 @@ class Sample */ inline boolean isPlaying(){ - return phase_fractional