summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/pcmbuf.c19
-rw-r--r--firmware/pcm_playback.c6
2 files changed, 11 insertions, 14 deletions
diff --git a/apps/pcmbuf.c b/apps/pcmbuf.c
index 66dd47eb3d..2d75185f62 100644
--- a/apps/pcmbuf.c
+++ b/apps/pcmbuf.c
@@ -46,8 +46,8 @@
46static long pcmbuf_size = 0; /* Size of the PCM buffer. */ 46static long pcmbuf_size = 0; /* Size of the PCM buffer. */
47static char *audiobuffer; 47static char *audiobuffer;
48static long audiobuffer_pos; /* Current audio buffer write index. */ 48static long audiobuffer_pos; /* Current audio buffer write index. */
49long audiobuffer_free; /* Amount of bytes left in the buffer. */ 49long audiobuffer_free IDATA_ATTR; /* Amount of bytes left in the buffer. */
50static long audiobuffer_fillpos; /* Amount audiobuffer_pos will be increased. */ 50static long audiobuffer_fillpos; /* Amount audiobuffer_pos will be increased.*/
51static char *guardbuf; 51static char *guardbuf;
52 52
53static void (*pcmbuf_event_handler)(void); 53static void (*pcmbuf_event_handler)(void);
@@ -81,11 +81,11 @@ struct pcmbufdesc
81 int size; 81 int size;
82 /* Call this when the buffer has been played */ 82 /* Call this when the buffer has been played */
83 void (*callback)(void); 83 void (*callback)(void);
84} pcmbuffers[NUM_PCM_BUFFERS]; 84} pcmbuffers[NUM_PCM_BUFFERS] IDATA_ATTR;
85 85
86volatile int pcmbuf_read_index; 86volatile int pcmbuf_read_index;
87volatile int pcmbuf_write_index; 87volatile int pcmbuf_write_index;
88int pcmbuf_unplayed_bytes; 88int pcmbuf_unplayed_bytes IDATA_ATTR;
89int pcmbuf_mix_used_bytes; 89int pcmbuf_mix_used_bytes;
90int pcmbuf_watermark; 90int pcmbuf_watermark;
91void (*pcmbuf_watermark_event)(int bytes_left); 91void (*pcmbuf_watermark_event)(int bytes_left);
@@ -121,6 +121,7 @@ int pcmbuf_num_used_buffers(void)
121 return (pcmbuf_write_index - pcmbuf_read_index) & NUM_PCM_BUFFERS_MASK; 121 return (pcmbuf_write_index - pcmbuf_read_index) & NUM_PCM_BUFFERS_MASK;
122} 122}
123 123
124static void pcmbuf_callback(unsigned char** start, long* size) ICODE_ATTR;
124static void pcmbuf_callback(unsigned char** start, long* size) 125static void pcmbuf_callback(unsigned char** start, long* size)
125{ 126{
126 struct pcmbufdesc *desc = &pcmbuffers[pcmbuf_read_index]; 127 struct pcmbufdesc *desc = &pcmbuffers[pcmbuf_read_index];
@@ -206,14 +207,10 @@ void pcmbuf_add_event(void (*event_handler)(void))
206 207
207unsigned int pcmbuf_get_latency(void) 208unsigned int pcmbuf_get_latency(void)
208{ 209{
209 int latency; 210 int latency = (pcmbuf_unplayed_bytes + pcm_get_bytes_waiting())
211 * 1000 / 4 / 44100;
210 212
211 latency = (pcmbuf_unplayed_bytes + pcm_get_bytes_waiting()) 213 return latency<0?0:latency;
212 * 1000 / 4 / 44100;
213 if (latency < 0)
214 latency = 0;
215
216 return latency;
217} 214}
218 215
219bool pcmbuf_is_lowdata(void) 216bool pcmbuf_is_lowdata(void)
diff --git a/firmware/pcm_playback.c b/firmware/pcm_playback.c
index fe71fa3862..36c6ab6a75 100644
--- a/firmware/pcm_playback.c
+++ b/firmware/pcm_playback.c
@@ -59,8 +59,8 @@ static bool pcm_playing;
59static bool pcm_paused; 59static bool pcm_paused;
60static int pcm_freq = 0x6; /* 44.1 is default */ 60static int pcm_freq = 0x6; /* 44.1 is default */
61 61
62static unsigned char *next_start; 62static unsigned char *next_start IDATA_ATTR;
63static long next_size; 63static long next_size IDATA_ATTR;
64 64
65/* Set up the DMA transfer that kicks in when the audio FIFO gets empty */ 65/* Set up the DMA transfer that kicks in when the audio FIFO gets empty */
66static void dma_start(const void *addr, long size) 66static void dma_start(const void *addr, long size)
@@ -193,7 +193,7 @@ void pcm_set_frequency(unsigned int frequency)
193} 193}
194 194
195/* the registered callback function to ask for more mp3 data */ 195/* the registered callback function to ask for more mp3 data */
196static void (*callback_for_more)(unsigned char**, long*) = NULL; 196static void (*callback_for_more)(unsigned char**, long*) IDATA_ATTR = NULL;
197 197
198void pcm_play_data(void (*get_more)(unsigned char** start, long* size)) 198void pcm_play_data(void (*get_more)(unsigned char** start, long* size))
199{ 199{