From 5279d60e0afb13b39efdcd21585baa251d0133a6 Mon Sep 17 00:00:00 2001 From: Sebastian Leonhardt Date: Sat, 1 Oct 2016 22:58:50 +0200 Subject: [PATCH] Midi Player: fix premature stopping of audio buffer playback Change-Id: I3794e8d8837722442b25e2b48db1b5b3c3c2dc51 --- apps/plugins/midi/midiplay.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/apps/plugins/midi/midiplay.c b/apps/plugins/midi/midiplay.c index 6df1578bb3..344efd317e 100644 --- a/apps/plugins/midi/midiplay.c +++ b/apps/plugins/midi/midiplay.c @@ -323,6 +323,7 @@ long bpm IBSS_ATTR; int32_t gmbuf[BUF_SIZE*NBUF]; static unsigned int samples_in_buf; +bool midi_end = false; bool quit = false; bool swap = false; bool lastswap = true; @@ -341,6 +342,10 @@ static inline void synthbuf(void) #else outptr = gmbuf; #endif + if (midi_end) { + samples_in_buf = 0; + return; + } /* synth samples for as many whole ticks as we can fit in the buffer */ for (; i >= number_of_samples; i -= number_of_samples) @@ -353,7 +358,7 @@ static inline void synthbuf(void) rb->yield(); #endif if (tick() == 0) - quit = true; + midi_end = true; /* no more midi data to play */ } /* how many samples did we write to the buffer? */ @@ -379,6 +384,10 @@ static void get_more(const void** start, size_t* size) #else *start = gmbuf; #endif + if (samples_in_buf==0) { + *start = NULL; + quit = true; /* this was the last buffer to play */ + } } static int midimain(const void * filename)