summaryrefslogtreecommitdiff
path: root/shared-module/audiomp3/MP3Decoder.h
diff options
context:
space:
mode:
authorJeff Epler <jepler@gmail.com>2020-05-11 08:51:41 -0500
committerJeff Epler <jepler@gmail.com>2020-07-15 09:26:47 -0500
commitbdab6c12d4332523fdbd8967c1233b3708f4883e (patch)
tree61b05eb15531e184553dd3eac75762ab99a7b64e /shared-module/audiomp3/MP3Decoder.h
parent742aa740f651c72a5991250d9ac898492e99389d (diff)
MP3Decoder: take advantage of background callback
Before this, the mp3 file would be read into the in-memory buffer only when new samples were actually needed. This meant that the time to read mp3 content always counted against the ~22ms audio buffer length. Now, when there's at least 1 full disk block of free space in the input buffer, we can request that the buffer be filled _after_ returning from audiomp3_mp3file_get_buffer and actually filling the DMA pointers. In this way, the time taken for reading MP3 data from flash/SD is less likely to cause an underrun of audio DMA. The existing calls to fill the inbuf remain, but in most cases during streaming these become no-ops because the buffer will be over half full.
Diffstat (limited to 'shared-module/audiomp3/MP3Decoder.h')
-rw-r--r--shared-module/audiomp3/MP3Decoder.h2
1 files changed, 2 insertions, 0 deletions
diff --git a/shared-module/audiomp3/MP3Decoder.h b/shared-module/audiomp3/MP3Decoder.h
index 9ee1d0949..f91f102a2 100644
--- a/shared-module/audiomp3/MP3Decoder.h
+++ b/shared-module/audiomp3/MP3Decoder.h
@@ -28,6 +28,7 @@
#ifndef MICROPY_INCLUDED_SHARED_MODULE_AUDIOIO_MP3FILE_H
#define MICROPY_INCLUDED_SHARED_MODULE_AUDIOIO_MP3FILE_H
+#include "supervisor/background_callback.h"
#include "extmod/vfs_fat.h"
#include "py/obj.h"
@@ -36,6 +37,7 @@
typedef struct {
mp_obj_base_t base;
struct _MP3DecInfo *decoder;
+ background_callback_t inbuf_fill_cb;
uint8_t* inbuf;
uint32_t inbuf_length;
uint32_t inbuf_offset;