summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rw-r--r--apps/playback.c95
1 files changed, 49 insertions, 46 deletions
diff --git a/apps/playback.c b/apps/playback.c
index d0b2882204..96db31f1c8 100644
--- a/apps/playback.c
+++ b/apps/playback.c
@@ -161,14 +161,59 @@ static bool v1first = false;
161static void mp3_set_elapsed(struct mp3entry* id3); 161static void mp3_set_elapsed(struct mp3entry* id3);
162int mp3_get_file_pos(void); 162int mp3_get_file_pos(void);
163 163
164/* Simulator stubs. */
164#ifdef SIMULATOR 165#ifdef SIMULATOR
165bool audiobuffer_insert_sim(char *buf, size_t length) 166bool audiobuffer_insert(char *buf, size_t length)
166{ 167{
167 (void)buf; 168 (void)buf;
168 (void)length; 169 (void)length;
169 170
170 return true; 171 return true;
171} 172}
173
174unsigned int audiobuffer_get_latency()
175{
176 return 0;
177}
178
179void pcm_play_stop(void)
180{
181}
182
183bool pcm_is_playing(void)
184{
185 return false;
186}
187
188bool pcm_is_lowdata(void)
189{
190 return false;
191}
192
193bool pcm_crossfade_start(void)
194{
195 return false;
196}
197
198void pcm_set_boost_mode(bool state)
199{
200 (void)state;
201}
202
203bool pcm_is_crossfade_enabled(void)
204{
205 return false;
206}
207
208void pcm_play_pause(bool state)
209{
210 (void)state;
211}
212
213int ata_sleep(void)
214{
215 return 0;
216}
172#endif 217#endif
173 218
174void* get_codec_memory_callback(size_t *size) 219void* get_codec_memory_callback(size_t *size)
@@ -181,11 +226,8 @@ void codec_set_elapsed_callback(unsigned int value)
181{ 226{
182 unsigned int latency; 227 unsigned int latency;
183 228
184#ifndef SIMULATOR
185 latency = audiobuffer_get_latency(); 229 latency = audiobuffer_get_latency();
186#else 230
187 latency = 0;
188#endif
189 if (value < latency) { 231 if (value < latency) {
190 cur_ti->id3.elapsed = 0; 232 cur_ti->id3.elapsed = 0;
191 } else if (value - latency > cur_ti->id3.elapsed 233 } else if (value - latency > cur_ti->id3.elapsed
@@ -328,9 +370,7 @@ bool codec_seek_buffer_callback(off_t newpos)
328 if (difference >= 0) { 370 if (difference >= 0) {
329 logf("seek: +%d", difference); 371 logf("seek: +%d", difference);
330 codec_advance_buffer_callback(difference); 372 codec_advance_buffer_callback(difference);
331#ifndef SIMULATOR
332 pcm_play_stop(); 373 pcm_play_stop();
333#endif
334 return true; 374 return true;
335 } 375 }
336 376
@@ -351,9 +391,7 @@ bool codec_seek_buffer_callback(off_t newpos)
351 if (buf_ridx < 0) 391 if (buf_ridx < 0)
352 buf_ridx = codecbuflen + buf_ridx; 392 buf_ridx = codecbuflen + buf_ridx;
353 ci.curpos -= difference; 393 ci.curpos -= difference;
354#ifndef SIMULATOR
355 pcm_play_stop(); 394 pcm_play_stop();
356#endif
357 395
358 return true; 396 return true;
359} 397}
@@ -381,13 +419,11 @@ void codec_configure_callback(int setting, void *value)
381void yield_codecs(void) 419void yield_codecs(void)
382{ 420{
383 yield(); 421 yield();
384#ifndef SIMULATOR
385 if (!pcm_is_playing()) 422 if (!pcm_is_playing())
386 sleep(5); 423 sleep(5);
387 while (pcm_is_lowdata() && !ci.stop_codec && 424 while (pcm_is_lowdata() && !ci.stop_codec &&
388 playing && queue_empty(&audio_queue)) 425 playing && queue_empty(&audio_queue))
389 yield(); 426 yield();
390#endif
391} 427}
392 428
393void audio_fill_file_buffer(void) 429void audio_fill_file_buffer(void)
@@ -723,14 +759,10 @@ void audio_play_start(int offset)
723 buf_ridx = 0; 759 buf_ridx = 0;
724 buf_widx = 0; 760 buf_widx = 0;
725 codecbufused = 0; 761 codecbufused = 0;
726#ifndef SIMULATOR
727 pcm_set_boost_mode(true); 762 pcm_set_boost_mode(true);
728#endif
729 audio_insert_tracks(offset, true, 0); 763 audio_insert_tracks(offset, true, 0);
730#ifndef SIMULATOR
731 pcm_set_boost_mode(false); 764 pcm_set_boost_mode(false);
732 ata_sleep(); 765 ata_sleep();
733#endif
734} 766}
735 767
736void audio_clear_track_entries(void) 768void audio_clear_track_entries(void)
@@ -752,11 +784,9 @@ void audio_check_buffer(void)
752 int cur_idx; 784 int cur_idx;
753 785
754 /* Fill buffer as full as possible for cross-fader. */ 786 /* Fill buffer as full as possible for cross-fader. */
755#ifndef SIMULATOR
756 if (pcm_is_crossfade_enabled() && cur_ti->id3.length > 0 787 if (pcm_is_crossfade_enabled() && cur_ti->id3.length > 0
757 && cur_ti->id3.length - cur_ti->id3.elapsed < 20000 && playing) 788 && cur_ti->id3.length - cur_ti->id3.elapsed < 20000 && playing)
758 pcm_set_boost_mode(true); 789 pcm_set_boost_mode(true);
759#endif
760 790
761 /* Start buffer filling as necessary. */ 791 /* Start buffer filling as necessary. */
762 if (codecbufused > conf_watermark || !queue_empty(&audio_queue) 792 if (codecbufused > conf_watermark || !queue_empty(&audio_queue)
@@ -764,9 +794,7 @@ void audio_check_buffer(void)
764 return ; 794 return ;
765 795
766 filling = true; 796 filling = true;
767#ifndef SIMULATOR
768 pcm_set_boost_mode(true); 797 pcm_set_boost_mode(true);
769#endif
770 798
771 fill_bytesleft = codecbuflen - codecbufused; 799 fill_bytesleft = codecbuflen - codecbufused;
772 800
@@ -803,11 +831,9 @@ void audio_check_buffer(void)
803 if (tracks[track_widx].filerem == 0) 831 if (tracks[track_widx].filerem == 0)
804 audio_insert_tracks(0, false, 1); 832 audio_insert_tracks(0, false, 1);
805 833
806#ifndef SIMULATOR
807 pcm_set_boost_mode(false); 834 pcm_set_boost_mode(false);
808 if (playing) 835 if (playing)
809 ata_sleep(); 836 ata_sleep();
810#endif
811 filling = false; 837 filling = false;
812} 838}
813 839
@@ -822,11 +848,10 @@ void audio_update_trackinfo(void)
822 codecbufused -= cur_ti->codecsize; 848 codecbufused -= cur_ti->codecsize;
823 if (buf_ridx >= codecbuflen) 849 if (buf_ridx >= codecbuflen)
824 buf_ridx -= codecbuflen; 850 buf_ridx -= codecbuflen;
825#ifndef SIMULATOR 851
826 pcm_crossfade_start(); 852 pcm_crossfade_start();
827 if (!filling) 853 if (!filling)
828 pcm_set_boost_mode(false); 854 pcm_set_boost_mode(false);
829#endif
830 } else { 855 } else {
831 buf_ridx -= ci.curpos + cur_ti->codecsize; 856 buf_ridx -= ci.curpos + cur_ti->codecsize;
832 codecbufused += ci.curpos + cur_ti->codecsize; 857 codecbufused += ci.curpos + cur_ti->codecsize;
@@ -959,18 +984,14 @@ void audio_thread(void)
959 ci.stop_codec = true; 984 ci.stop_codec = true;
960 ci.reload_codec = false; 985 ci.reload_codec = false;
961 ci.seek_time = 0; 986 ci.seek_time = 0;
962#ifndef SIMULATOR
963 pcm_play_stop(); 987 pcm_play_stop();
964#endif
965 audio_play_start((int)ev.data); 988 audio_play_start((int)ev.data);
966 break ; 989 break ;
967 990
968 case AUDIO_STOP: 991 case AUDIO_STOP:
969 paused = false; 992 paused = false;
970#ifndef SIMULATOR
971 pcm_play_stop(); 993 pcm_play_stop();
972 pcm_play_pause(true); 994 pcm_play_pause(true);
973#endif
974 break ; 995 break ;
975 996
976 case AUDIO_PAUSE: 997 case AUDIO_PAUSE:
@@ -1111,9 +1132,7 @@ void audio_play(int offset)
1111{ 1132{
1112 logf("audio_play"); 1133 logf("audio_play");
1113 ci.stop_codec = true; 1134 ci.stop_codec = true;
1114#ifndef SIMULATOR
1115 pcm_play_pause(true); 1135 pcm_play_pause(true);
1116#endif
1117 paused = false; 1136 paused = false;
1118 playing = true; 1137 playing = true;
1119 queue_post(&audio_queue, AUDIO_PLAY, (void *)offset); 1138 queue_post(&audio_queue, AUDIO_PLAY, (void *)offset);
@@ -1130,17 +1149,13 @@ void audio_stop(void)
1130 current_fd = -1; 1149 current_fd = -1;
1131 } 1150 }
1132 queue_post(&audio_queue, AUDIO_STOP, 0); 1151 queue_post(&audio_queue, AUDIO_STOP, 0);
1133#ifndef SIMULATOR
1134 pcm_play_pause(true); 1152 pcm_play_pause(true);
1135#endif
1136} 1153}
1137 1154
1138void audio_pause(void) 1155void audio_pause(void)
1139{ 1156{
1140 logf("audio_pause"); 1157 logf("audio_pause");
1141#ifndef SIMULATOR
1142 pcm_play_pause(false); 1158 pcm_play_pause(false);
1143#endif
1144 paused = true; 1159 paused = true;
1145 //queue_post(&audio_queue, AUDIO_PAUSE, 0); 1160 //queue_post(&audio_queue, AUDIO_PAUSE, 0);
1146} 1161}
@@ -1148,9 +1163,7 @@ void audio_pause(void)
1148void audio_resume(void) 1163void audio_resume(void)
1149{ 1164{
1150 logf("audio_resume"); 1165 logf("audio_resume");
1151#ifndef SIMULATOR
1152 pcm_play_pause(true); 1166 pcm_play_pause(true);
1153#endif
1154 paused = false; 1167 paused = false;
1155 //queue_post(&audio_queue, AUDIO_RESUME, 0); 1168 //queue_post(&audio_queue, AUDIO_RESUME, 0);
1156} 1169}
@@ -1167,11 +1180,10 @@ void audio_next(void)
1167 playlist_next(1); 1180 playlist_next(1);
1168 queue_post(&audio_queue, AUDIO_PLAY, 0); 1181 queue_post(&audio_queue, AUDIO_PLAY, 0);
1169 } 1182 }
1170#ifndef SIMULATOR 1183
1171 else if (!pcm_crossfade_start()) { 1184 else if (!pcm_crossfade_start()) {
1172 pcm_play_stop(); 1185 pcm_play_stop();
1173 } 1186 }
1174#endif
1175} 1187}
1176 1188
1177void audio_prev(void) 1189void audio_prev(void)
@@ -1179,9 +1191,7 @@ void audio_prev(void)
1179 logf("audio_prev"); 1191 logf("audio_prev");
1180 new_track = -1; 1192 new_track = -1;
1181 ci.reload_codec = true; 1193 ci.reload_codec = true;
1182#ifndef SIMULATOR
1183 pcm_play_stop(); 1194 pcm_play_stop();
1184#endif
1185 1195
1186 if (filling) { 1196 if (filling) {
1187 ci.stop_codec = true; 1197 ci.stop_codec = true;
@@ -1377,11 +1387,7 @@ void audio_init(void)
1377 1387
1378 /* Initialize codec api. */ 1388 /* Initialize codec api. */
1379 ci.read_filebuf = codec_filebuf_callback; 1389 ci.read_filebuf = codec_filebuf_callback;
1380#ifndef SIMULATOR
1381 ci.audiobuffer_insert = audiobuffer_insert; 1390 ci.audiobuffer_insert = audiobuffer_insert;
1382#else
1383 ci.audiobuffer_insert = audiobuffer_insert_sim;
1384#endif
1385 ci.get_codec_memory = get_codec_memory_callback; 1391 ci.get_codec_memory = get_codec_memory_callback;
1386 ci.request_buffer = codec_request_buffer_callback; 1392 ci.request_buffer = codec_request_buffer_callback;
1387 ci.advance_buffer = codec_advance_buffer_callback; 1393 ci.advance_buffer = codec_advance_buffer_callback;
@@ -1399,9 +1405,6 @@ void audio_init(void)
1399 codec_thread_name); 1405 codec_thread_name);
1400 create_thread(audio_thread, audio_stack, sizeof(audio_stack), 1406 create_thread(audio_thread, audio_stack, sizeof(audio_stack),
1401 audio_thread_name); 1407 audio_thread_name);
1402#ifndef SIMULATOR
1403 audio_is_initialized = true;
1404#endif
1405} 1408}
1406 1409
1407 1410