diff options
author | Jeffrey Goode <jeffg7@gmail.com> | 2009-11-09 06:53:22 +0000 |
---|---|---|
committer | Jeffrey Goode <jeffg7@gmail.com> | 2009-11-09 06:53:22 +0000 |
commit | 73c4791da0018c1fbe366cf21836d1d719f7e9a0 (patch) | |
tree | d993c24666f7864be06ced737396019b6a040c7c | |
parent | 6008c29e5e18a6978690685f2c0d645bc1ab92f9 (diff) | |
download | rockbox-73c4791da0018c1fbe366cf21836d1d719f7e9a0.tar.gz rockbox-73c4791da0018c1fbe366cf21836d1d719f7e9a0.zip |
pcmbuf: eliminate add_chunk as a separate function
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23582 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | apps/pcmbuf.c | 58 |
1 files changed, 30 insertions, 28 deletions
diff --git a/apps/pcmbuf.c b/apps/pcmbuf.c index 6cbd4556b6..a39a69a21c 100644 --- a/apps/pcmbuf.c +++ b/apps/pcmbuf.c | |||
@@ -184,10 +184,27 @@ static bool show_desc(char *caller) | |||
184 | 184 | ||
185 | /* Commit PCM data */ | 185 | /* Commit PCM data */ |
186 | 186 | ||
187 | /* This is really just part of commit_chunk, but is easier to keep | 187 | /** |
188 | * in a separate function for the moment */ | 188 | * Commit samples waiting to the pcm buffer. |
189 | static inline void pcmbuf_add_chunk(void) | 189 | */ |
190 | static void commit_chunk(void) | ||
190 | { | 191 | { |
192 | if (!pcmbuffer_fillpos) | ||
193 | return; | ||
194 | |||
195 | /* Never use the last buffer descriptor */ | ||
196 | while (write_chunk == write_end_chunk) { | ||
197 | /* If this happens, something is being stupid */ | ||
198 | if (!pcm_is_playing()) { | ||
199 | logf("commit_chunk error"); | ||
200 | pcmbuf_play_start(); | ||
201 | } | ||
202 | /* Let approximately one chunk of data playback */ | ||
203 | sleep(HZ*PCMBUF_TARGET_CHUNK/(NATIVE_FREQUENCY*4)); | ||
204 | } | ||
205 | |||
206 | /* commit the chunk */ | ||
207 | |||
191 | register size_t size = pcmbuffer_fillpos; | 208 | register size_t size = pcmbuffer_fillpos; |
192 | /* Grab the next description to write, and change the write pointer */ | 209 | /* Grab the next description to write, and change the write pointer */ |
193 | register struct chunkdesc *pcmbuf_current = write_chunk; | 210 | register struct chunkdesc *pcmbuf_current = write_chunk; |
@@ -198,9 +215,13 @@ static inline void pcmbuf_add_chunk(void) | |||
198 | pcmbuf_current->end_of_track = end_of_track; | 215 | pcmbuf_current->end_of_track = end_of_track; |
199 | pcmbuf_current->link = NULL; | 216 | pcmbuf_current->link = NULL; |
200 | end_of_track = false; /* This is single use only */ | 217 | end_of_track = false; /* This is single use only */ |
201 | if (read_chunk != NULL) { | 218 | |
219 | if (read_chunk != NULL) | ||
220 | { | ||
202 | if (flush_pcmbuf) | 221 | if (flush_pcmbuf) |
203 | { | 222 | { |
223 | /* flush! discard all data after the currently playing chunk, | ||
224 | and make the current chunk play next */ | ||
204 | write_end_chunk->link = read_chunk->link; | 225 | write_end_chunk->link = read_chunk->link; |
205 | read_chunk->link = pcmbuf_current; | 226 | read_chunk->link = pcmbuf_current; |
206 | while (write_end_chunk->link) | 227 | while (write_end_chunk->link) |
@@ -213,10 +234,13 @@ static inline void pcmbuf_add_chunk(void) | |||
213 | /* If there is already a read buffer setup, add to it */ | 234 | /* If there is already a read buffer setup, add to it */ |
214 | else | 235 | else |
215 | read_end_chunk->link = pcmbuf_current; | 236 | read_end_chunk->link = pcmbuf_current; |
216 | } else { | 237 | } |
238 | else | ||
239 | { | ||
217 | /* Otherwise create the buffer */ | 240 | /* Otherwise create the buffer */ |
218 | read_chunk = pcmbuf_current; | 241 | read_chunk = pcmbuf_current; |
219 | } | 242 | } |
243 | |||
220 | /* This is now the last buffer to read */ | 244 | /* This is now the last buffer to read */ |
221 | read_end_chunk = pcmbuf_current; | 245 | read_end_chunk = pcmbuf_current; |
222 | 246 | ||
@@ -228,29 +252,7 @@ static inline void pcmbuf_add_chunk(void) | |||
228 | pcmbuffer_pos -= pcmbuf_size; | 252 | pcmbuffer_pos -= pcmbuf_size; |
229 | 253 | ||
230 | pcmbuffer_fillpos = 0; | 254 | pcmbuffer_fillpos = 0; |
231 | DISPLAY_DESC("add_chunk"); | 255 | DISPLAY_DESC("commit_chunk"); |
232 | } | ||
233 | |||
234 | /** | ||
235 | * Commit samples waiting to the pcm buffer. | ||
236 | */ | ||
237 | static bool commit_chunk(void) | ||
238 | { | ||
239 | if (pcmbuffer_fillpos) { | ||
240 | /* Never use the last buffer descriptor */ | ||
241 | while (write_chunk == write_end_chunk) { | ||
242 | /* If this happens, something is being stupid */ | ||
243 | if (!pcm_is_playing()) { | ||
244 | logf("commit_chunk error"); | ||
245 | pcmbuf_play_start(); | ||
246 | } | ||
247 | /* Let approximately one chunk of data playback */ | ||
248 | sleep(HZ*PCMBUF_TARGET_CHUNK/(NATIVE_FREQUENCY*4)); | ||
249 | } | ||
250 | pcmbuf_add_chunk(); | ||
251 | return true; | ||
252 | } | ||
253 | return false; | ||
254 | } | 256 | } |
255 | 257 | ||
256 | #ifdef HAVE_PRIORITY_SCHEDULING | 258 | #ifdef HAVE_PRIORITY_SCHEDULING |