From 2e457523c19e51bdccef8901ac6fa5cf0f6ce003 Mon Sep 17 00:00:00 2001 From: Paul Melnikov Date: Wed, 10 Jun 2026 10:39:41 +0000 Subject: [PATCH 1/2] Add pause functionality to Sample --- Sample.h | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) 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 Date: Wed, 22 Jul 2026 14:21:37 +0200 Subject: [PATCH 2/2] Update Sample.h --- Sample.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sample.h b/Sample.h index 1d8d353ca..c13da6726 100644 --- a/Sample.h +++ b/Sample.h @@ -129,7 +129,7 @@ class Sample /** Checks whether playback is paused. */ inline - bool isPaused() { return paused; } + bool isPaused() const { return paused; } /** Sets the end position in samples from the beginning of the sound.