summaryrefslogtreecommitdiff
path: root/apps/recorder
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2006-08-28 22:38:41 +0000
committerMichael Sevakis <jethead71@rockbox.org>2006-08-28 22:38:41 +0000
commit4fc717a4c19a1fe0349977d7b9c86561c5a5cf2d (patch)
treeeb6113c7491072f7b5136e24775737764e2cdede /apps/recorder
parent65c2c58b3aa26164bd919665e4d710efa2fa7c79 (diff)
downloadrockbox-4fc717a4c19a1fe0349977d7b9c86561c5a5cf2d.tar.gz
rockbox-4fc717a4c19a1fe0349977d7b9c86561c5a5cf2d.zip
Added FS#2939 Encoder Codec Interface + Codecs by Antonius Hellmann with additional FM Recording support and my modifications
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@10789 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/recorder')
-rw-r--r--apps/recorder/radio.c380
-rw-r--r--apps/recorder/radio.h12
-rw-r--r--apps/recorder/recording.c578
-rw-r--r--apps/recorder/recording.h27
4 files changed, 652 insertions, 345 deletions
diff --git a/apps/recorder/radio.c b/apps/recorder/radio.c
index c292909b33..208e7b67fa 100644
--- a/apps/recorder/radio.c
+++ b/apps/recorder/radio.c
@@ -24,7 +24,6 @@
24#include "mas.h" 24#include "mas.h"
25#include "settings.h" 25#include "settings.h"
26#include "button.h" 26#include "button.h"
27#include "fmradio.h"
28#include "status.h" 27#include "status.h"
29#include "kernel.h" 28#include "kernel.h"
30#include "mpeg.h" 29#include "mpeg.h"
@@ -63,17 +62,6 @@
63 62
64#ifdef CONFIG_TUNER 63#ifdef CONFIG_TUNER
65 64
66#if CONFIG_CODEC == SWCODEC
67#ifdef HAVE_UDA1380
68#include "uda1380.h"
69#endif
70#ifdef HAVE_TLV320
71#include "tlv320.h"
72#endif
73
74#include "pcm_record.h"
75#endif
76
77#if CONFIG_KEYPAD == RECORDER_PAD 65#if CONFIG_KEYPAD == RECORDER_PAD
78#define FM_MENU BUTTON_F1 66#define FM_MENU BUTTON_F1
79#define FM_PRESET BUTTON_F2 67#define FM_PRESET BUTTON_F2
@@ -165,6 +153,7 @@ static int curr_freq;
165static int radio_mode = RADIO_SCAN_MODE; 153static int radio_mode = RADIO_SCAN_MODE;
166 154
167static int radio_status = FMRADIO_OFF; 155static int radio_status = FMRADIO_OFF;
156static bool in_screen = false;
168 157
169#define MAX_PRESETS 64 158#define MAX_PRESETS 64
170static bool presets_loaded = false, presets_changed = false; 159static bool presets_loaded = false, presets_changed = false;
@@ -239,22 +228,87 @@ int get_radio_status(void)
239 return radio_status; 228 return radio_status;
240} 229}
241 230
231bool in_radio_screen(void)
232{
233 return in_screen;
234}
235
236/* secret flag for starting paused - prevents unmute */
237#define FMRADIO_START_PAUSED 0x8000
238void radio_start(void)
239{
240 bool start_paused;
241 int mute_timeout;
242
243 if(radio_status == FMRADIO_PLAYING)
244 return;
245
246 start_paused = radio_status & FMRADIO_START_PAUSED;
247 /* clear flag before any yielding */
248 radio_status &= ~FMRADIO_START_PAUSED;
249
250 if(radio_status == FMRADIO_OFF)
251 radio_power(true);
252
253 curr_freq = global_settings.last_frequency * FREQ_STEP + MIN_FREQ;
254
255 radio_set(RADIO_SLEEP, 0); /* wake up the tuner */
256 radio_set(RADIO_FREQUENCY, curr_freq);
257
258 if(radio_status == FMRADIO_OFF)
259 {
260 radio_set(RADIO_IF_MEASUREMENT, 0);
261 radio_set(RADIO_SENSITIVITY, 0);
262 radio_set(RADIO_FORCE_MONO, global_settings.fm_force_mono);
263 mute_timeout = current_tick + 1*HZ;
264 }
265 else
266 {
267 /* paused */
268 mute_timeout = current_tick + 2*HZ;
269 }
270
271 while(!radio_get(RADIO_STEREO) && !radio_get(RADIO_TUNED))
272 {
273 if(TIME_AFTER(current_tick, mute_timeout))
274 break;
275 yield();
276 }
277
278 /* keep radio from sounding initially */
279 if(!start_paused)
280 radio_set(RADIO_MUTE, 0);
281
282 radio_status = FMRADIO_PLAYING;
283} /* radio_start */
284
285void radio_pause(void)
286{
287 if(radio_status == FMRADIO_PAUSED)
288 return;
289
290 if(radio_status == FMRADIO_OFF)
291 {
292 radio_status |= FMRADIO_START_PAUSED;
293 radio_start();
294 }
295
296 radio_set(RADIO_MUTE, 1);
297 radio_set(RADIO_SLEEP, 1);
298
299 radio_status = FMRADIO_PAUSED;
300} /* radio_pause */
301
242void radio_stop(void) 302void radio_stop(void)
243{ 303{
304 if(radio_status == FMRADIO_OFF)
305 return;
306
244 radio_set(RADIO_MUTE, 1); 307 radio_set(RADIO_MUTE, 1);
245 radio_set(RADIO_SLEEP, 1); /* low power mode, if available */ 308 radio_set(RADIO_SLEEP, 1); /* low power mode, if available */
246 radio_status = FMRADIO_OFF; 309 radio_status = FMRADIO_OFF;
247 radio_power(false); /* status update, power off if avail. */ 310 radio_power(false); /* status update, power off if avail. */
248 311} /* radio_stop */
249#ifndef SIMULATOR /* SIMULATOR. Catch FMRADIO_OFF status for the sim. */
250#if CONFIG_CODEC == SWCODEC
251#ifdef HAVE_TLV320
252 tlv320_set_monitor(false);
253#endif
254 pcm_rec_mux(0); /* Line In */
255#endif
256#endif /* SIMULATOR */
257}
258 312
259bool radio_hardware_present(void) 313bool radio_hardware_present(void)
260{ 314{
@@ -297,18 +351,16 @@ static int find_closest_preset(int freq)
297 return i; 351 return i;
298 if(diff < 0) 352 if(diff < 0)
299 diff = -diff; 353 diff = -diff;
300 if(diff < min_diff) 354 if(diff < min_diff)
301 { 355 {
302 preset = i; 356 preset = i;
303 min_diff = diff; 357 min_diff = diff;
304 } 358 }
305 } 359 }
306 360
307 return preset; 361 return preset;
308} 362}
309 363
310
311
312static void remember_frequency(void) 364static void remember_frequency(void)
313{ 365{
314 global_settings.last_frequency = (curr_freq - MIN_FREQ) / FREQ_STEP; 366 global_settings.last_frequency = (curr_freq - MIN_FREQ) / FREQ_STEP;
@@ -366,13 +418,15 @@ bool radio_screen(void)
366#endif 418#endif
367 bool keep_playing = false; 419 bool keep_playing = false;
368 bool statusbar = global_settings.statusbar; 420 bool statusbar = global_settings.statusbar;
369 int mute_timeout = current_tick;
370 int button_timeout = current_tick + (2*HZ); 421 int button_timeout = current_tick + (2*HZ);
371#ifdef HAS_BUTTONBAR 422#ifdef HAS_BUTTONBAR
372 struct gui_buttonbar buttonbar; 423 struct gui_buttonbar buttonbar;
373 gui_buttonbar_init(&buttonbar); 424 gui_buttonbar_init(&buttonbar);
374 gui_buttonbar_set_display(&buttonbar, &(screens[SCREEN_MAIN]) ); 425 gui_buttonbar_set_display(&buttonbar, &(screens[SCREEN_MAIN]) );
375#endif 426#endif
427 /* change status to "in screen" */
428 in_screen = true;
429
376 /* always display status bar in radio screen for now */ 430 /* always display status bar in radio screen for now */
377 global_settings.statusbar = true; 431 global_settings.statusbar = true;
378 FOR_NB_SCREENS(i) 432 FOR_NB_SCREENS(i)
@@ -396,80 +450,44 @@ bool radio_screen(void)
396 } 450 }
397 451
398#ifndef SIMULATOR 452#ifndef SIMULATOR
453 if(radio_status == FMRADIO_OFF)
454 audio_stop();
455
399#if CONFIG_CODEC != SWCODEC 456#if CONFIG_CODEC != SWCODEC
400 if(rec_create_directory() > 0) 457 if(rec_create_directory() > 0)
401 have_recorded = true; 458 have_recorded = true;
402#endif
403 459
404 if(radio_status == FMRADIO_PLAYING_OUT)
405 radio_status = FMRADIO_PLAYING;
406 else if(radio_status == FMRADIO_PAUSED_OUT)
407 radio_status = FMRADIO_PAUSED;
408
409 if(radio_status == FMRADIO_OFF)
410 audio_stop();
411
412#if CONFIG_CODEC != SWCODEC
413 audio_init_recording(talk_get_bufsize()); 460 audio_init_recording(talk_get_bufsize());
414 461
415 sound_settings_apply(); 462 sound_settings_apply();
416 /* Yes, we use the D/A for monitoring */ 463 /* Yes, we use the D/A for monitoring */
417 peak_meter_playback(true); 464 peak_meter_playback(true);
418
419 peak_meter_enabled = true;
420 465
421 if (global_settings.rec_prerecord_time) 466 peak_meter_enabled = true;
422 talk_buffer_steal(); /* will use the mp3 buffer */
423 467
424 audio_set_recording_options(global_settings.rec_frequency, 468 rec_set_recording_options(global_settings.rec_frequency,
425 global_settings.rec_quality, 469 global_settings.rec_quality,
426 1, /* Line In */ 470 AUDIO_SRC_LINEIN, 0,
427 global_settings.rec_channels, 471 global_settings.rec_channels,
428 global_settings.rec_editable, 472 global_settings.rec_editable,
429 global_settings.rec_prerecord_time); 473 global_settings.rec_prerecord_time);
430 474
431 475 audio_set_recording_gain(sound_default(SOUND_LEFT_GAIN),
432#else 476 sound_default(SOUND_RIGHT_GAIN), AUDIO_GAIN_LINEIN);
433 peak_meter_enabled = false;
434 477
435#ifdef HAVE_UDA1380 478#endif /* CONFIG_CODEC != SWCODEC */
436 uda1380_enable_recording(false); 479#endif /* ndef SIMULATOR */
437 uda1380_set_monitor(true);
438#elif defined(HAVE_TLV320)
439 //tlv320_enable_recording(false);
440 tlv320_set_recvol(23, 23, AUDIO_GAIN_LINEIN); /* 0dB */
441 tlv320_set_monitor(true);
442#endif
443 480
444 /* Set the input multiplexer to FM */ 481 /* turn on radio */
445 pcm_rec_mux(1); 482#if CONFIG_CODEC == SWCODEC
446#endif 483 rec_set_source(AUDIO_SRC_FMRADIO, (radio_status == FMRADIO_PAUSED) ?
447 audio_set_recording_gain(sound_default(SOUND_LEFT_GAIN), 484 SRCF_FMRADIO_PAUSED : SRCF_FMRADIO_PLAYING);
448 sound_default(SOUND_RIGHT_GAIN), AUDIO_GAIN_LINEIN); 485#else
486 if (radio_status == FMRADIO_OFF)
487 radio_start();
449#endif 488#endif
450 489
451 curr_freq = global_settings.last_frequency * FREQ_STEP + MIN_FREQ; 490 /* I hate this thing with vehement passion (jhMikeS): */
452
453 if(radio_status == FMRADIO_OFF)
454 {
455 radio_power(true);
456 radio_set(RADIO_SLEEP, 0); /* wake up the tuner */
457 radio_set(RADIO_FREQUENCY, curr_freq);
458 radio_set(RADIO_IF_MEASUREMENT, 0);
459 radio_set(RADIO_SENSITIVITY, 0);
460 radio_set(RADIO_FORCE_MONO, global_settings.fm_force_mono);
461 mute_timeout = current_tick + (1*HZ);
462 while( !radio_get(RADIO_STEREO)
463 &&!radio_get(RADIO_TUNED) )
464 {
465 if(TIME_AFTER(current_tick, mute_timeout))
466 break;
467 yield();
468 }
469 radio_set(RADIO_MUTE, 0);
470 radio_status = FMRADIO_PLAYING;
471 }
472
473 if(num_presets == 0 && yesno_pop(str(LANG_FM_FIRST_AUTOSCAN))) 491 if(num_presets == 0 && yesno_pop(str(LANG_FM_FIRST_AUTOSCAN)))
474 scan_presets(); 492 scan_presets();
475 493
@@ -478,8 +496,8 @@ bool radio_screen(void)
478 radio_mode = RADIO_PRESET_MODE; 496 radio_mode = RADIO_PRESET_MODE;
479 497
480#ifdef HAS_BUTTONBAR 498#ifdef HAS_BUTTONBAR
481 gui_buttonbar_set(&buttonbar, str(LANG_BUTTONBAR_MENU), str(LANG_FM_BUTTONBAR_PRESETS), 499 gui_buttonbar_set(&buttonbar, str(LANG_BUTTONBAR_MENU),
482 str(LANG_FM_BUTTONBAR_RECORD)); 500 str(LANG_FM_BUTTONBAR_PRESETS), str(LANG_FM_BUTTONBAR_RECORD));
483#endif 501#endif
484 502
485 cpu_idle_mode(true); 503 cpu_idle_mode(true);
@@ -535,7 +553,7 @@ bool radio_screen(void)
535 if (lastbutton != FM_STOP_PRE) 553 if (lastbutton != FM_STOP_PRE)
536 break; 554 break;
537#endif 555#endif
538#ifndef SIMULATOR 556#if CONFIG_CODEC != SWCODEC && !defined(SIMULATOR)
539 if(audio_status() == AUDIO_STATUS_RECORD) 557 if(audio_status() == AUDIO_STATUS_RECORD)
540 { 558 {
541 audio_stop(); 559 audio_stop();
@@ -548,7 +566,7 @@ bool radio_screen(void)
548 { 566 {
549 if(yesno_pop(str(LANG_FM_SAVE_CHANGES))) 567 if(yesno_pop(str(LANG_FM_SAVE_CHANGES)))
550 { 568 {
551 if(filepreset[0] == '\0') 569 if(filepreset[0] == '\0')
552 save_preset_list(); 570 save_preset_list();
553 else 571 else
554 radio_save_presets(); 572 radio_save_presets();
@@ -577,14 +595,13 @@ bool radio_screen(void)
577#ifndef SIMULATOR 595#ifndef SIMULATOR
578 if(audio_status() == AUDIO_STATUS_RECORD) 596 if(audio_status() == AUDIO_STATUS_RECORD)
579 { 597 {
580 audio_new_file(rec_create_filename(buf)); 598 rec_new_file();
581 update_screen = true; 599 update_screen = true;
582 } 600 }
583 else 601 else
584 { 602 {
585 have_recorded = true; 603 have_recorded = true;
586 talk_buffer_steal(); /* we use the mp3 buffer */ 604 rec_record();
587 audio_record(rec_create_filename(buf));
588 update_screen = true; 605 update_screen = true;
589 } 606 }
590#endif 607#endif
@@ -604,7 +621,7 @@ bool radio_screen(void)
604 ) 621 )
605 break; 622 break;
606#endif 623#endif
607#ifndef SIMULATOR 624#if CONFIG_CODEC != SWCODEC && !defined(SIMULATOR)
608 if(audio_status() == AUDIO_STATUS_RECORD) 625 if(audio_status() == AUDIO_STATUS_RECORD)
609 audio_stop(); 626 audio_stop();
610#endif 627#endif
@@ -615,7 +632,7 @@ bool radio_screen(void)
615 { 632 {
616 if(yesno_pop(str(LANG_FM_SAVE_CHANGES))) 633 if(yesno_pop(str(LANG_FM_SAVE_CHANGES)))
617 { 634 {
618 if(filepreset[0] == '\0') 635 if(filepreset[0] == '\0')
619 save_preset_list(); 636 save_preset_list();
620 else 637 else
621 radio_save_presets(); 638 radio_save_presets();
@@ -734,27 +751,11 @@ bool radio_screen(void)
734 ) 751 )
735 break; 752 break;
736#endif 753#endif
737 if(radio_status != FMRADIO_PLAYING) 754 if (radio_status == FMRADIO_PLAYING)
738 { 755 radio_pause();
739 radio_set(RADIO_SLEEP, 0);
740 radio_set(RADIO_FREQUENCY, curr_freq);
741 mute_timeout = current_tick + (2*HZ);
742 while( !radio_get(RADIO_STEREO)
743 &&!radio_get(RADIO_TUNED) )
744 {
745 if(TIME_AFTER(current_tick, mute_timeout))
746 break;
747 yield();
748 }
749 radio_set(RADIO_MUTE, 0);
750 radio_status = FMRADIO_PLAYING;
751 }
752 else 756 else
753 { 757 radio_start();
754 radio_set(RADIO_MUTE, 1); 758
755 radio_set(RADIO_SLEEP, 1);
756 radio_status = FMRADIO_PAUSED;
757 }
758 update_screen = true; 759 update_screen = true;
759 break; 760 break;
760#endif 761#endif
@@ -917,13 +918,17 @@ bool radio_screen(void)
917 if(TIME_AFTER(current_tick, timeout)) 918 if(TIME_AFTER(current_tick, timeout))
918 { 919 {
919 timeout = current_tick + HZ; 920 timeout = current_tick + HZ;
920 921
921 stereo = radio_get(RADIO_STEREO) && 922 /* keep "mono" from always being displayed when paused */
922 !global_settings.fm_force_mono; 923 if (radio_status != FMRADIO_PAUSED)
923 if(stereo != last_stereo_status)
924 { 924 {
925 update_screen = true; 925 stereo = radio_get(RADIO_STEREO) &&
926 last_stereo_status = stereo; 926 !global_settings.fm_force_mono;
927 if(stereo != last_stereo_status)
928 {
929 update_screen = true;
930 last_stereo_status = stereo;
931 }
927 } 932 }
928 } 933 }
929 934
@@ -952,9 +957,6 @@ bool radio_screen(void)
952 FOR_NB_SCREENS(i) 957 FOR_NB_SCREENS(i)
953 screens[i].puts_scroll(0, top_of_screen + 1, buf); 958 screens[i].puts_scroll(0, top_of_screen + 1, buf);
954 959
955 strcat(buf, stereo?str(LANG_CHANNEL_STEREO):
956 str(LANG_CHANNEL_MONO));
957
958 snprintf(buf, 128, stereo?str(LANG_CHANNEL_STEREO): 960 snprintf(buf, 128, stereo?str(LANG_CHANNEL_STEREO):
959 str(LANG_CHANNEL_MONO)); 961 str(LANG_CHANNEL_MONO));
960 FOR_NB_SCREENS(i) 962 FOR_NB_SCREENS(i)
@@ -1005,9 +1007,9 @@ bool radio_screen(void)
1005 done = true; 1007 done = true;
1006 } 1008 }
1007 if (TIME_AFTER(current_tick, button_timeout)) 1009 if (TIME_AFTER(current_tick, button_timeout))
1008 { 1010 {
1009 cpu_idle_mode(true); 1011 cpu_idle_mode(true);
1010 } 1012 }
1011 } /*while(!done)*/ 1013 } /*while(!done)*/
1012 1014
1013#ifndef SIMULATOR 1015#ifndef SIMULATOR
@@ -1033,28 +1035,26 @@ bool radio_screen(void)
1033 1035
1034 sound_settings_apply(); 1036 sound_settings_apply();
1035#endif /* SIMULATOR */ 1037#endif /* SIMULATOR */
1038
1036 if(keep_playing) 1039 if(keep_playing)
1037 { 1040 {
1038/* Catch FMRADIO_PLAYING_OUT status for the sim. */ 1041/* Catch FMRADIO_PLAYING status for the sim. */
1039#ifndef SIMULATOR 1042#ifndef SIMULATOR
1040#if CONFIG_CODEC != SWCODEC 1043#if CONFIG_CODEC != SWCODEC
1041 /* Enable the Left and right A/D Converter */ 1044 /* Enable the Left and right A/D Converter */
1042 audio_set_recording_gain(sound_default(SOUND_LEFT_GAIN), 1045 audio_set_recording_gain(sound_default(SOUND_LEFT_GAIN),
1043 sound_default(SOUND_RIGHT_GAIN), AUDIO_GAIN_LINEIN); 1046 sound_default(SOUND_RIGHT_GAIN),
1047 AUDIO_GAIN_LINEIN);
1044 mas_codec_writereg(6, 0x4000); 1048 mas_codec_writereg(6, 0x4000);
1045#endif 1049#endif
1046#endif 1050#endif
1047 if(radio_status == FMRADIO_PAUSED)
1048 radio_status = FMRADIO_PAUSED_OUT;
1049 else
1050 radio_status = FMRADIO_PLAYING_OUT;
1051
1052 } 1051 }
1053 else 1052 else
1054 { 1053 {
1055 radio_stop();
1056#if CONFIG_CODEC == SWCODEC 1054#if CONFIG_CODEC == SWCODEC
1057 peak_meter_enabled = true; 1055 rec_set_source(AUDIO_SRC_PLAYBACK, SRCF_PLAYBACK);
1056#else
1057 radio_stop();
1058#endif 1058#endif
1059 } 1059 }
1060 1060
@@ -1062,9 +1062,11 @@ bool radio_screen(void)
1062 1062
1063 /* restore status bar settings */ 1063 /* restore status bar settings */
1064 global_settings.statusbar = statusbar; 1064 global_settings.statusbar = statusbar;
1065
1066 in_screen = false;
1065 1067
1066 return have_recorded; 1068 return have_recorded;
1067} 1069} /* radio_screen */
1068 1070
1069void radio_save_presets(void) 1071void radio_save_presets(void)
1070{ 1072{
@@ -1106,16 +1108,16 @@ void radio_load_presets(char *filename)
1106 1108
1107/* No Preset in configuration. */ 1109/* No Preset in configuration. */
1108 if(filename[0] == '\0') 1110 if(filename[0] == '\0')
1109 { 1111 {
1110 filepreset[0] = '\0'; 1112 filepreset[0] = '\0';
1111 return; 1113 return;
1112 } 1114 }
1113/* Temporary preset, loaded until player shuts down. */ 1115/* Temporary preset, loaded until player shuts down. */
1114 else if(filename[0] == '/') 1116 else if(filename[0] == '/')
1115 strncpy(filepreset, filename, sizeof(filepreset)); 1117 strncpy(filepreset, filename, sizeof(filepreset));
1116/* Preset from default directory. */ 1118/* Preset from default directory. */
1117 else 1119 else
1118 snprintf(filepreset, sizeof(filepreset), "%s/%s.fmr", 1120 snprintf(filepreset, sizeof(filepreset), "%s/%s.fmr",
1119 FMPRESET_PATH, filename); 1121 FMPRESET_PATH, filename);
1120 1122
1121 fd = open(filepreset, O_RDONLY); 1123 fd = open(filepreset, O_RDONLY);
@@ -1466,30 +1468,6 @@ bool handle_radio_presets(void)
1466 return reload_dir; 1468 return reload_dir;
1467} 1469}
1468 1470
1469#ifndef SIMULATOR
1470#if CONFIG_CODEC != SWCODEC
1471static bool fm_recording_settings(void)
1472{
1473 bool ret;
1474
1475 ret = recording_menu(true);
1476 if(!ret)
1477 {
1478 if (global_settings.rec_prerecord_time)
1479 talk_buffer_steal(); /* will use the mp3 buffer */
1480
1481 audio_set_recording_options(global_settings.rec_frequency,
1482 global_settings.rec_quality,
1483 1, /* Line In */
1484 global_settings.rec_channels,
1485 global_settings.rec_editable,
1486 global_settings.rec_prerecord_time);
1487 }
1488 return ret;
1489}
1490#endif
1491#endif
1492
1493char monomode_menu_string[32]; 1471char monomode_menu_string[32];
1494 1472
1495static void create_monomode_menu(void) 1473static void create_monomode_menu(void)
@@ -1628,6 +1606,55 @@ int radio_menu_cb(int key, int m)
1628 return key; 1606 return key;
1629} 1607}
1630 1608
1609#ifndef SIMULATOR
1610#if defined(HAVE_FMRADIO_IN) || CONFIG_CODEC != SWCODEC
1611static bool fm_recording_screen(void)
1612{
1613 bool ret;
1614
1615#ifdef HAVE_FMRADIO_IN
1616 /* switch recording source to FMRADIO for the duration */
1617 int rec_source = global_settings.rec_source;
1618 global_settings.rec_source = AUDIO_SRC_FMRADIO;
1619
1620 /* clearing queue seems to cure a spontaneous abort during record */
1621 while (button_get(false) != BUTTON_NONE);
1622#endif
1623
1624 ret = recording_screen(true);
1625
1626#ifdef HAVE_FMRADIO_IN
1627 /* safe to reset as changing sources is prohibited here */
1628 global_settings.rec_source = rec_source;
1629#endif
1630
1631 return ret;
1632}
1633
1634static bool fm_recording_settings(void)
1635{
1636 bool ret = recording_menu(true);
1637
1638 if (!ret)
1639 {
1640 rec_set_recording_options(global_settings.rec_frequency,
1641 global_settings.rec_quality,
1642#if CONFIG_CODEC == SWCODEC
1643 AUDIO_SRC_FMRADIO, SRCF_FMRADIO_PLAYING,
1644#else
1645 AUDIO_SRC_LINEIN, 0,
1646#endif
1647 global_settings.rec_channels,
1648 global_settings.rec_editable,
1649 global_settings.rec_prerecord_time);
1650 }
1651
1652 return ret;
1653}
1654#endif
1655#endif /* SIMULATOR */
1656
1657
1631/* main menu of the radio screen */ 1658/* main menu of the radio screen */
1632bool radio_menu(void) 1659bool radio_menu(void)
1633{ 1660{
@@ -1637,24 +1664,27 @@ bool radio_menu(void)
1637 static const struct menu_item items[] = { 1664 static const struct menu_item items[] = {
1638/* Add functions not accessible via buttons */ 1665/* Add functions not accessible via buttons */
1639#ifndef FM_PRESET 1666#ifndef FM_PRESET
1640 { ID2P(LANG_FM_BUTTONBAR_PRESETS), handle_radio_presets }, 1667 { ID2P(LANG_FM_BUTTONBAR_PRESETS), handle_radio_presets },
1641#endif 1668#endif
1642#ifndef FM_PRESET_ADD 1669#ifndef FM_PRESET_ADD
1643 { ID2P(LANG_FM_ADD_PRESET) , radio_add_preset }, 1670 { ID2P(LANG_FM_ADD_PRESET) , radio_add_preset },
1644#endif 1671#endif
1645 { ID2P(LANG_FM_PRESET_LOAD) , load_preset_list }, 1672 { ID2P(LANG_FM_PRESET_LOAD) , load_preset_list },
1646 { ID2P(LANG_FM_PRESET_SAVE) , save_preset_list }, 1673 { ID2P(LANG_FM_PRESET_SAVE) , save_preset_list },
1647 { ID2P(LANG_FM_PRESET_CLEAR) , clear_preset_list }, 1674 { ID2P(LANG_FM_PRESET_CLEAR) , clear_preset_list },
1648 1675
1649 { monomode_menu_string , toggle_mono_mode }, 1676 { monomode_menu_string , toggle_mono_mode },
1650#ifndef FM_MODE 1677#ifndef FM_MODE
1651 { radiomode_menu_string , toggle_radio_mode }, 1678 { radiomode_menu_string , toggle_radio_mode },
1679#endif
1680 { ID2P(LANG_SOUND_SETTINGS) , sound_menu },
1681#ifndef SIMULATOR
1682#if defined(HAVE_FMRADIO_IN) || CONFIG_CODEC != SWCODEC
1683 { ID2P(LANG_RECORDING_MENU) , fm_recording_screen },
1684 { ID2P(LANG_RECORDING_SETTINGS) , fm_recording_settings },
1652#endif 1685#endif
1653 { ID2P(LANG_SOUND_SETTINGS) , sound_menu },
1654#if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
1655 { ID2P(LANG_RECORDING_SETTINGS) , fm_recording_settings},
1656#endif 1686#endif
1657 { ID2P(LANG_FM_SCAN_PRESETS) , scan_presets }, 1687 { ID2P(LANG_FM_SCAN_PRESETS) , scan_presets },
1658 }; 1688 };
1659 1689
1660 create_monomode_menu(); 1690 create_monomode_menu();
diff --git a/apps/recorder/radio.h b/apps/recorder/radio.h
index 86ce04c4b9..fdf446dc0a 100644
--- a/apps/recorder/radio.h
+++ b/apps/recorder/radio.h
@@ -20,19 +20,19 @@
20#define RADIO_H 20#define RADIO_H
21#define FMPRESET_PATH ROCKBOX_DIR "/fmpresets" 21#define FMPRESET_PATH ROCKBOX_DIR "/fmpresets"
22 22
23#define FMRADIO_OFF 0 23#ifndef FMRADIO_H
24#define FMRADIO_PLAYING 1 24#include "fmradio.h"
25#define FMRADIO_PLAYING_OUT 2 25#endif
26#define FMRADIO_PAUSED 3
27#define FMRADIO_PAUSED_OUT 4
28 26
29#ifdef CONFIG_TUNER 27#ifdef CONFIG_TUNER
30void radio_load_presets(char *filename); 28void radio_load_presets(char *filename);
31void radio_init(void); 29void radio_init(void);
32bool radio_screen(void); 30bool radio_screen(void);
31void radio_start(void);
32void radio_pause(void);
33void radio_stop(void); 33void radio_stop(void);
34bool radio_hardware_present(void); 34bool radio_hardware_present(void);
35int get_radio_status(void); 35bool in_radio_screen(void);
36 36
37#define MAX_FMPRESET_LEN 27 37#define MAX_FMPRESET_LEN 27
38 38
diff --git a/apps/recorder/recording.c b/apps/recorder/recording.c
index e6b06d56dc..080cafcf2f 100644
--- a/apps/recorder/recording.c
+++ b/apps/recorder/recording.c
@@ -24,12 +24,14 @@
24#include <stdlib.h> 24#include <stdlib.h>
25 25
26#include "system.h" 26#include "system.h"
27#include "power.h"
27#include "lcd.h" 28#include "lcd.h"
28#include "led.h" 29#include "led.h"
29#include "mpeg.h" 30#include "mpeg.h"
30#include "audio.h" 31#include "audio.h"
31#if CONFIG_CODEC == SWCODEC 32#if CONFIG_CODEC == SWCODEC
32#include "pcm_record.h" 33#include "pcm_record.h"
34#include "playback.h"
33#endif 35#endif
34#ifdef HAVE_UDA1380 36#ifdef HAVE_UDA1380
35#include "uda1380.h" 37#include "uda1380.h"
@@ -37,7 +39,7 @@
37#ifdef HAVE_TLV320 39#ifdef HAVE_TLV320
38#include "tlv320.h" 40#include "tlv320.h"
39#endif 41#endif
40 42#include "recording.h"
41#include "mp3_playback.h" 43#include "mp3_playback.h"
42#include "mas.h" 44#include "mas.h"
43#include "button.h" 45#include "button.h"
@@ -66,6 +68,7 @@
66#include "splash.h" 68#include "splash.h"
67#include "screen_access.h" 69#include "screen_access.h"
68#include "action.h" 70#include "action.h"
71#include "radio.h"
69#ifdef HAVE_RECORDING 72#ifdef HAVE_RECORDING
70 73
71#define PM_HEIGHT ((LCD_HEIGHT >= 72) ? 2 : 1) 74#define PM_HEIGHT ((LCD_HEIGHT >= 72) ? 2 : 1)
@@ -73,21 +76,6 @@
73bool f2_rec_screen(void); 76bool f2_rec_screen(void);
74bool f3_rec_screen(void); 77bool f3_rec_screen(void);
75 78
76#define SOURCE_MIC 0
77#define SOURCE_LINE 1
78#ifdef HAVE_SPDIF_IN
79#define SOURCE_SPDIF 2
80#define MAX_SOURCE SOURCE_SPDIF
81#else
82#define MAX_SOURCE SOURCE_LINE
83#endif
84
85#if CONFIG_CODEC == SWCODEC
86#define REC_FILE_ENDING ".wav"
87#else
88#define REC_FILE_ENDING ".mp3"
89#endif
90
91#define MAX_FILE_SIZE 0x7F800000 /* 2 GB - 4 MB */ 79#define MAX_FILE_SIZE 0x7F800000 /* 2 GB - 4 MB */
92 80
93int screen_update = NB_SCREENS; 81int screen_update = NB_SCREENS;
@@ -102,6 +90,19 @@ const char* const freq_str[6] =
102 "16kHz" 90 "16kHz"
103}; 91};
104 92
93#if CONFIG_CODEC == SWCODEC
94#define REC_ENCODER_ID(q) \
95 rec_quality_info_afmt[q]
96#define REC_QUALITY_LABEL(q) \
97 (audio_formats[REC_ENCODER_ID(q)].label)
98#define REC_FILE_ENDING(q) \
99 (audio_formats[REC_ENCODER_ID(q)].ext)
100#else
101/* default record file extension for HWCODEC */
102#define REC_QUALITY_LABEL(q) "MP3"
103#define REC_FILE_ENDING(q) ".mp3"
104#endif
105
105#ifdef HAVE_AGC 106#ifdef HAVE_AGC
106/* Timing counters: 107/* Timing counters:
107 * peak_time is incremented every 0.2s, every 2nd run of record screen loop. 108 * peak_time is incremented every 0.2s, every 2nd run of record screen loop.
@@ -161,13 +162,14 @@ static short agc_maxgain;
161 162
162static void set_gain(void) 163static void set_gain(void)
163{ 164{
164 if(global_settings.rec_source == SOURCE_MIC) 165 if(global_settings.rec_source == AUDIO_SRC_MIC)
165 { 166 {
166 audio_set_recording_gain(global_settings.rec_mic_gain, 167 audio_set_recording_gain(global_settings.rec_mic_gain,
167 0, AUDIO_GAIN_MIC); 168 0, AUDIO_GAIN_MIC);
168 } 169 }
169 else 170 else
170 { 171 {
172 /* AUDIO_SRC_LINEIN, AUDIO_SRC_SPDIF, AUDIO_SRC_FMRADIO */
171 audio_set_recording_gain(global_settings.rec_left_gain, 173 audio_set_recording_gain(global_settings.rec_left_gain,
172 global_settings.rec_right_gain, 174 global_settings.rec_right_gain,
173 AUDIO_GAIN_LINEIN); 175 AUDIO_GAIN_LINEIN);
@@ -217,12 +219,16 @@ bool agc_gain_is_max(bool left, bool right)
217 if (agc_preset == 0) 219 if (agc_preset == 0)
218 return false; 220 return false;
219 221
220 if (global_settings.rec_source == SOURCE_LINE) 222 switch (global_settings.rec_source)
221 { 223 {
224 case AUDIO_SRC_LINEIN:
225#ifdef HAVE_FMRADIO_IN
226 case AUDIO_SRC_FMRADIO:
227#endif
222 gain_current_l = global_settings.rec_left_gain; 228 gain_current_l = global_settings.rec_left_gain;
223 gain_current_r = global_settings.rec_right_gain; 229 gain_current_r = global_settings.rec_right_gain;
224 } else 230 break;
225 { 231 default:
226 gain_current_l = global_settings.rec_mic_gain; 232 gain_current_l = global_settings.rec_mic_gain;
227 gain_current_r = global_settings.rec_mic_gain; 233 gain_current_r = global_settings.rec_mic_gain;
228 } 234 }
@@ -235,13 +241,16 @@ void change_recording_gain(bool increment, bool left, bool right)
235{ 241{
236 int factor = (increment ? 1 : -1); 242 int factor = (increment ? 1 : -1);
237 243
238 if (global_settings.rec_source == SOURCE_LINE) 244 switch (global_settings.rec_source)
239 { 245 {
246 case AUDIO_SRC_LINEIN:
247#ifdef HAVE_FMRADIO_IN
248 case AUDIO_SRC_FMRADIO:
249#endif
240 if(left) global_settings.rec_left_gain += factor; 250 if(left) global_settings.rec_left_gain += factor;
241 if (right) global_settings.rec_right_gain += factor; 251 if (right) global_settings.rec_right_gain += factor;
242 } 252 break;
243 else 253 default:
244 {
245 global_settings.rec_mic_gain += factor; 254 global_settings.rec_mic_gain += factor;
246 } 255 }
247} 256}
@@ -443,12 +452,15 @@ void adjust_cursor(void)
443#ifdef HAVE_AGC 452#ifdef HAVE_AGC
444 switch(global_settings.rec_source) 453 switch(global_settings.rec_source)
445 { 454 {
446 case SOURCE_MIC: 455 case AUDIO_SRC_MIC:
447 if(cursor == 2) 456 if(cursor == 2)
448 cursor = 4; 457 cursor = 4;
449 else if(cursor == 3) 458 else if(cursor == 3)
450 cursor = 1; 459 cursor = 1;
451 case SOURCE_LINE: 460 case AUDIO_SRC_LINEIN:
461#ifdef HAVE_FMRADIO_IN
462 case AUDIO_SRC_FMRADIO:
463#endif
452 max_cursor = 5; 464 max_cursor = 5;
453 break; 465 break;
454 default: 466 default:
@@ -458,10 +470,13 @@ void adjust_cursor(void)
458#else 470#else
459 switch(global_settings.rec_source) 471 switch(global_settings.rec_source)
460 { 472 {
461 case SOURCE_MIC: 473 case AUDIO_SRC_MIC:
462 max_cursor = 1; 474 max_cursor = 1;
463 break; 475 break;
464 case SOURCE_LINE: 476 case AUDIO_SRC_LINEIN:
477#ifdef HAVE_FMRADIO_IN
478 case AUDIO_SRC_FMRADIO:
479#endif
465 max_cursor = 3; 480 max_cursor = 3;
466 break; 481 break;
467 default: 482 default:
@@ -481,10 +496,13 @@ char *rec_create_filename(char *buffer)
481 else 496 else
482 strncpy(buffer, rec_base_directory, MAX_PATH); 497 strncpy(buffer, rec_base_directory, MAX_PATH);
483 498
499
484#ifdef CONFIG_RTC 500#ifdef CONFIG_RTC
485 create_datetime_filename(buffer, buffer, "R", REC_FILE_ENDING); 501 create_datetime_filename(buffer, buffer, "R",
502 REC_FILE_ENDING(global_settings.rec_quality));
486#else 503#else
487 create_numbered_filename(buffer, buffer, "rec_", REC_FILE_ENDING, 4); 504 create_numbered_filename(buffer, buffer, "rec_",
505 REC_FILE_ENDING(global_settings.rec_quality), 4);
488#endif 506#endif
489 return buffer; 507 return buffer;
490} 508}
@@ -515,8 +533,190 @@ int rec_create_directory(void)
515 return 0; 533 return 0;
516} 534}
517 535
536#if CONFIG_CODEC == SWCODEC && !defined(SIMULATOR)
537/**
538 * Selects an audio source for recording or playback
539 * powers/unpowers related devices.
540 * Here because it calls app code and used only for HAVE_RECORDING atm.
541 * Would like it in pcm_record.c.
542 */
543#if defined(HAVE_UDA1380)
544#define ac_disable_recording uda1380_disable_recording
545#define ac_enable_recording uda1380_enable_recording
546#define ac_set_monitor uda1380_set_monitor
547#elif defined(HAVE_TLV320)
548#define ac_disable_recording tlv320_disable_recording
549#define ac_enable_recording tlv320_enable_recording
550#define ac_set_monitor tlv320_set_monitor
551#endif
552
553void rec_set_source(int source, int flags)
554{
555 /* Prevent pops from unneeded switching */
556 static int last_source = AUDIO_SRC_PLAYBACK;
557#ifdef HAVE_TLV320
558 static bool last_recording = false;
559#endif
560
561 bool recording = flags & SRCF_RECORDING;
562 /* Default to peakmeter record. */
563 bool pm_playback = false;
564 bool pm_enabled = true;
565
566 /** Do power up/down of associated device(s) **/
567
568#ifdef HAVE_SPDIF_IN
569 if ((source == AUDIO_SRC_SPDIF) != (source == last_source))
570 cpu_boost(source == AUDIO_SRC_SPDIF);
571
572#ifdef HAVE_SPDIF_POWER
573 /* Check if S/PDIF output power should be switched off or on. NOTE: assumes
574 both optical in and out is controlled by the same power source, which is
575 the case on H1x0. */
576 spdif_power_enable((source == AUDIO_SRC_SPDIF) ||
577 global_settings.spdif_enable);
578#endif
579#endif
580
581#ifdef CONFIG_TUNER
582 /* Switch radio off or on per source and flags. */
583 if (source != AUDIO_SRC_FMRADIO)
584 radio_stop();
585 else if (flags & SRCF_FMRADIO_PAUSED)
586 radio_pause();
587 else
588 radio_start();
589#endif
590
591 switch (source)
592 {
593 default: /* playback - no recording */
594 pm_playback = true;
595 if (source == last_source)
596 break;
597 ac_disable_recording();
598 ac_set_monitor(false);
599 pcm_rec_mux(0); /* line in */
600 break;
601
602 case AUDIO_SRC_MIC: /* recording only */
603 if (source == last_source)
604 break;
605 ac_enable_recording(true); /* source mic */
606 pcm_rec_mux(0); /* line in */
607 break;
608
609 case AUDIO_SRC_LINEIN: /* recording only */
610 if (source == last_source)
611 break;
612 pcm_rec_mux(0); /* line in */
613 ac_enable_recording(false); /* source line */
614 break;
615
616#ifdef HAVE_SPDIF_IN
617 case AUDIO_SRC_SPDIF: /* recording only */
618 if (recording)
619 {
620 /* This was originally done in audio_set_recording_options only */
621#ifdef HAVE_SPDIF_POWER
622 EBU1CONFIG = global_settings.spdif_enable ? (1 << 2) : 0;
623 /* Input source is EBUin1, Feed-through monitoring if desired */
624#else
625 EBU1CONFIG = (1 << 2);
626 /* Input source is EBUin1, Feed-through monitoring */
627#endif
628 }
629
630 if (source != last_source)
631 uda1380_disable_recording();
632 break;
633#endif /* HAVE_SPDIF_IN */
634
635#ifdef HAVE_FMRADIO_IN
636 case AUDIO_SRC_FMRADIO:
637 if (!recording)
638 {
639 audio_set_recording_gain(sound_default(SOUND_LEFT_GAIN),
640 sound_default(SOUND_RIGHT_GAIN), AUDIO_GAIN_LINEIN);
641 pm_playback = true;
642 pm_enabled = false;
643 }
644
645 pcm_rec_mux(1); /* fm radio */
646
647#ifdef HAVE_UDA1380
648 if (source == last_source)
649 break;
650 /* I2S recording and playback */
651 uda1380_enable_recording(false); /* source line */
652 uda1380_set_monitor(true);
653#endif
654#ifdef HAVE_TLV320
655 /* I2S recording and analog playback */
656 if (source == last_source && recording == last_recording)
657 break;
658
659 last_recording = recording;
660
661 if (recording)
662 tlv320_enable_recording(false); /* source line */
663 else
664 {
665 tlv320_disable_recording();
666 tlv320_set_monitor(true); /* analog bypass */
667 }
668#endif
669 break;
670/* #elif defined(CONFIG_TUNER) */
671/* Have radio but cannot record it */
672/* case AUDIO_SRC_FMRADIO: */
673/* break; */
674#endif /* HAVE_FMRADIO_IN */
675 } /* end switch */
676
677 peak_meter_playback(pm_playback);
678 peak_meter_enabled = pm_enabled;
679
680 last_source = source;
681} /* rec_set_source */
682#endif /* CONFIG_CODEC == SWCODEC && !defined(SIMULATOR) */
683
684/* steal the mp3 buffer then actually set options */
685void rec_set_recording_options(int frequency, int quality,
686 int source, int source_flags,
687 int channel_mode, bool editable,
688 int prerecord_time)
689{
690#if CONFIG_CODEC != SWCODEC
691 if (global_settings.rec_prerecord_time)
692#endif
693 talk_buffer_steal(); /* will use the mp3 buffer */
694
695#if CONFIG_CODEC == SWCODEC
696 rec_set_source(source, source_flags | SRCF_RECORDING);
697#else
698 (void)source_flags;
699#endif
700
701 audio_set_recording_options(frequency, quality, source,
702 channel_mode, editable, prerecord_time);
703}
704
518static char path_buffer[MAX_PATH]; 705static char path_buffer[MAX_PATH];
519 706
707/* steals mp3 buffer, creates unique filename and starts recording */
708void rec_record(void)
709{
710 talk_buffer_steal(); /* we use the mp3 buffer */
711 audio_record(rec_create_filename(path_buffer));
712}
713
714/* creates unique filename and starts recording */
715void rec_new_file(void)
716{
717 audio_new_file(rec_create_filename(path_buffer));
718}
719
520/* used in trigger_listerner and recording_screen */ 720/* used in trigger_listerner and recording_screen */
521static unsigned int last_seconds = 0; 721static unsigned int last_seconds = 0;
522 722
@@ -533,16 +733,16 @@ static void trigger_listener(int trigger_status)
533 if((audio_status() & AUDIO_STATUS_RECORD) != AUDIO_STATUS_RECORD) 733 if((audio_status() & AUDIO_STATUS_RECORD) != AUDIO_STATUS_RECORD)
534 { 734 {
535 talk_buffer_steal(); /* we use the mp3 buffer */ 735 talk_buffer_steal(); /* we use the mp3 buffer */
536 audio_record(rec_create_filename(path_buffer)); 736 rec_record();
537 737 /* give control to mpeg thread so that it can start
538 /* give control to mpeg thread so that it can start recording*/ 738 recording */
539 yield(); yield(); yield(); 739 yield(); yield(); yield();
540 } 740 }
541 741
542 /* if we're already recording this is a retrigger */ 742 /* if we're already recording this is a retrigger */
543 else 743 else
544 { 744 {
545 audio_new_file(rec_create_filename(path_buffer)); 745 rec_new_file();
546 /* tell recording_screen to reset the time */ 746 /* tell recording_screen to reset the time */
547 last_seconds = 0; 747 last_seconds = 0;
548 } 748 }
@@ -563,10 +763,9 @@ static void trigger_listener(int trigger_status)
563 } 763 }
564} 764}
565 765
566bool recording_screen(void) 766bool recording_screen(bool no_source)
567{ 767{
568 long button; 768 long button;
569 long lastbutton = BUTTON_NONE;
570 bool done = false; 769 bool done = false;
571 char buf[32]; 770 char buf[32];
572 char buf2[32]; 771 char buf2[32];
@@ -575,11 +774,19 @@ bool recording_screen(void)
575 bool have_recorded = false; 774 bool have_recorded = false;
576 unsigned int seconds; 775 unsigned int seconds;
577 int hours, minutes; 776 int hours, minutes;
578 char path_buffer[MAX_PATH];
579 char filename[13]; 777 char filename[13];
580 bool been_in_usb_mode = false; 778 bool been_in_usb_mode = false;
581 int last_audio_stat = -1; 779 int last_audio_stat = -1;
582 int audio_stat; 780 int audio_stat;
781#ifdef HAVE_FMRADIO_IN
782 /* Radio is left on if:
783 * 1) Is was on at the start and the initial source is FM Radio
784 * 2) 1) and the source was never changed to something else
785 */
786 int radio_status = (global_settings.rec_source != AUDIO_SRC_FMRADIO) ?
787 FMRADIO_OFF : get_radio_status();
788#endif
789 int talk_menu = global_settings.talk_menu;
583#if CONFIG_LED == LED_REAL 790#if CONFIG_LED == LED_REAL
584 bool led_state = false; 791 bool led_state = false;
585 int led_countdown = 2; 792 int led_countdown = 2;
@@ -608,6 +815,18 @@ bool recording_screen(void)
608 ata_set_led_enabled(false); 815 ata_set_led_enabled(false);
609#endif 816#endif
610 817
818#if CONFIG_CODEC == SWCODEC
819 audio_stop();
820 voice_stop();
821 /* recording_menu gets messed up: so reset talk_menu */
822 talk_menu = global_settings.talk_menu;
823 global_settings.talk_menu = 0;
824#else
825 /* Yes, we use the D/A for monitoring */
826 peak_meter_enabled = true;
827 peak_meter_playback(true);
828#endif
829
611#ifndef SIMULATOR 830#ifndef SIMULATOR
612 audio_init_recording(talk_get_bufsize()); 831 audio_init_recording(talk_get_bufsize());
613#else 832#else
@@ -616,44 +835,19 @@ bool recording_screen(void)
616 835
617 sound_set_volume(global_settings.volume); 836 sound_set_volume(global_settings.volume);
618 837
619#if CONFIG_CODEC == SWCODEC
620 audio_stop();
621 /* Set peak meter to recording mode */
622 peak_meter_playback(false);
623
624#if defined(HAVE_SPDIF_IN) && !defined(SIMULATOR)
625 if (global_settings.rec_source == SOURCE_SPDIF)
626 cpu_boost(true);
627#endif
628
629#else
630 /* Yes, we use the D/A for monitoring */
631 peak_meter_playback(true);
632#endif
633 peak_meter_enabled = true;
634#ifdef HAVE_AGC 838#ifdef HAVE_AGC
635 peak_meter_get_peakhold(&peak_l, &peak_r); 839 peak_meter_get_peakhold(&peak_l, &peak_r);
636#endif 840#endif
637 841
638#if CONFIG_CODEC != SWCODEC 842 rec_set_recording_options(global_settings.rec_frequency,
639 if (global_settings.rec_prerecord_time) 843 global_settings.rec_quality,
640#endif 844 global_settings.rec_source,
641 talk_buffer_steal(); /* will use the mp3 buffer */ 845 0,
642 846 global_settings.rec_channels,
643#if defined(HAVE_SPDIF_POWER) && !defined(SIMULATOR) 847 global_settings.rec_editable,
644 /* Tell recording whether we want S/PDIF power enabled at all times */ 848 global_settings.rec_prerecord_time);
645 audio_set_spdif_power_setting(global_settings.spdif_enable);
646#endif
647
648 audio_set_recording_options(global_settings.rec_frequency,
649 global_settings.rec_quality,
650 global_settings.rec_source,
651 global_settings.rec_channels,
652 global_settings.rec_editable,
653 global_settings.rec_prerecord_time);
654 849
655 set_gain(); 850 set_gain();
656
657 settings_apply_trigger(); 851 settings_apply_trigger();
658 852
659#ifdef HAVE_AGC 853#ifdef HAVE_AGC
@@ -663,7 +857,7 @@ bool recording_screen(void)
663 agc_preset_str[3] = str(LANG_AGC_DJSET); 857 agc_preset_str[3] = str(LANG_AGC_DJSET);
664 agc_preset_str[4] = str(LANG_AGC_MEDIUM); 858 agc_preset_str[4] = str(LANG_AGC_MEDIUM);
665 agc_preset_str[5] = str(LANG_AGC_VOICE); 859 agc_preset_str[5] = str(LANG_AGC_VOICE);
666 if (global_settings.rec_source == SOURCE_MIC) { 860 if (global_settings.rec_source == AUDIO_SRC_MIC) {
667 agc_preset = global_settings.rec_agc_preset_mic; 861 agc_preset = global_settings.rec_agc_preset_mic;
668 agc_maxgain = global_settings.rec_agc_maxgain_mic; 862 agc_maxgain = global_settings.rec_agc_maxgain_mic;
669 } 863 }
@@ -697,11 +891,7 @@ bool recording_screen(void)
697 891
698 while(!done) 892 while(!done)
699 { 893 {
700#if CONFIG_CODEC == SWCODEC
701 audio_stat = pcm_rec_status();
702#else
703 audio_stat = audio_status(); 894 audio_stat = audio_status();
704#endif
705 895
706#if CONFIG_LED == LED_REAL 896#if CONFIG_LED == LED_REAL
707 897
@@ -794,8 +984,8 @@ bool recording_screen(void)
794 } 984 }
795 else 985 else
796 { 986 {
797 peak_meter_playback(true);
798#if CONFIG_CODEC != SWCODEC 987#if CONFIG_CODEC != SWCODEC
988 peak_meter_playback(true);
799 peak_meter_enabled = false; 989 peak_meter_enabled = false;
800#endif 990#endif
801 done = true; 991 done = true;
@@ -815,14 +1005,13 @@ bool recording_screen(void)
815 /* manual recording */ 1005 /* manual recording */
816 have_recorded = true; 1006 have_recorded = true;
817 talk_buffer_steal(); /* we use the mp3 buffer */ 1007 talk_buffer_steal(); /* we use the mp3 buffer */
818 audio_record(rec_create_filename(path_buffer)); 1008 rec_record();
819 last_seconds = 0; 1009 last_seconds = 0;
820 if (global_settings.talk_menu) 1010 if (talk_menu)
821 { /* no voice possible here, but a beep */ 1011 { /* no voice possible here, but a beep */
822 audio_beep(HZ/2); /* longer beep on start */ 1012 audio_beep(HZ/2); /* longer beep on start */
823 } 1013 }
824 } 1014 }
825
826 /* this is triggered recording */ 1015 /* this is triggered recording */
827 else 1016 else
828 { 1017 {
@@ -838,7 +1027,7 @@ bool recording_screen(void)
838 /*if new file button pressed, start new file */ 1027 /*if new file button pressed, start new file */
839 if (button == ACTION_REC_NEWFILE) 1028 if (button == ACTION_REC_NEWFILE)
840 { 1029 {
841 audio_new_file(rec_create_filename(path_buffer)); 1030 rec_new_file();
842 last_seconds = 0; 1031 last_seconds = 0;
843 } 1032 }
844 else 1033 else
@@ -847,7 +1036,7 @@ bool recording_screen(void)
847 if(audio_stat & AUDIO_STATUS_PAUSE) 1036 if(audio_stat & AUDIO_STATUS_PAUSE)
848 { 1037 {
849 audio_resume_recording(); 1038 audio_resume_recording();
850 if (global_settings.talk_menu) 1039 if (talk_menu)
851 { /* no voice possible here, but a beep */ 1040 { /* no voice possible here, but a beep */
852 audio_beep(HZ/4); /* short beep on resume */ 1041 audio_beep(HZ/4); /* short beep on resume */
853 } 1042 }
@@ -883,7 +1072,7 @@ bool recording_screen(void)
883 sound_set_volume(global_settings.volume); 1072 sound_set_volume(global_settings.volume);
884 break; 1073 break;
885 case 1: 1074 case 1:
886 if(global_settings.rec_source == SOURCE_MIC) 1075 if(global_settings.rec_source == AUDIO_SRC_MIC)
887 { 1076 {
888 if(global_settings.rec_mic_gain < 1077 if(global_settings.rec_mic_gain <
889 sound_max(SOUND_MIC_GAIN)) 1078 sound_max(SOUND_MIC_GAIN))
@@ -913,7 +1102,7 @@ bool recording_screen(void)
913 case 4: 1102 case 4:
914 agc_preset = MIN(agc_preset + 1, AGC_MODE_SIZE); 1103 agc_preset = MIN(agc_preset + 1, AGC_MODE_SIZE);
915 agc_enable = (agc_preset != 0); 1104 agc_enable = (agc_preset != 0);
916 if (global_settings.rec_source == SOURCE_MIC) { 1105 if (global_settings.rec_source == AUDIO_SRC_MIC) {
917 global_settings.rec_agc_preset_mic = agc_preset; 1106 global_settings.rec_agc_preset_mic = agc_preset;
918 agc_maxgain = global_settings.rec_agc_maxgain_mic; 1107 agc_maxgain = global_settings.rec_agc_maxgain_mic;
919 } else { 1108 } else {
@@ -922,7 +1111,7 @@ bool recording_screen(void)
922 } 1111 }
923 break; 1112 break;
924 case 5: 1113 case 5:
925 if (global_settings.rec_source == SOURCE_MIC) 1114 if (global_settings.rec_source == AUDIO_SRC_MIC)
926 { 1115 {
927 agc_maxgain = MIN(agc_maxgain + 1, 1116 agc_maxgain = MIN(agc_maxgain + 1,
928 sound_max(SOUND_MIC_GAIN)); 1117 sound_max(SOUND_MIC_GAIN));
@@ -951,7 +1140,7 @@ bool recording_screen(void)
951 sound_set_volume(global_settings.volume); 1140 sound_set_volume(global_settings.volume);
952 break; 1141 break;
953 case 1: 1142 case 1:
954 if(global_settings.rec_source == SOURCE_MIC) 1143 if(global_settings.rec_source == AUDIO_SRC_MIC)
955 { 1144 {
956 if(global_settings.rec_mic_gain > 1145 if(global_settings.rec_mic_gain >
957 sound_min(SOUND_MIC_GAIN)) 1146 sound_min(SOUND_MIC_GAIN))
@@ -981,7 +1170,7 @@ bool recording_screen(void)
981 case 4: 1170 case 4:
982 agc_preset = MAX(agc_preset - 1, 0); 1171 agc_preset = MAX(agc_preset - 1, 0);
983 agc_enable = (agc_preset != 0); 1172 agc_enable = (agc_preset != 0);
984 if (global_settings.rec_source == SOURCE_MIC) { 1173 if (global_settings.rec_source == AUDIO_SRC_MIC) {
985 global_settings.rec_agc_preset_mic = agc_preset; 1174 global_settings.rec_agc_preset_mic = agc_preset;
986 agc_maxgain = global_settings.rec_agc_maxgain_mic; 1175 agc_maxgain = global_settings.rec_agc_maxgain_mic;
987 } else { 1176 } else {
@@ -990,7 +1179,7 @@ bool recording_screen(void)
990 } 1179 }
991 break; 1180 break;
992 case 5: 1181 case 5:
993 if (global_settings.rec_source == SOURCE_MIC) 1182 if (global_settings.rec_source == AUDIO_SRC_MIC)
994 { 1183 {
995 agc_maxgain = MAX(agc_maxgain - 1, 1184 agc_maxgain = MAX(agc_maxgain - 1,
996 sound_min(SOUND_MIC_GAIN)); 1185 sound_min(SOUND_MIC_GAIN));
@@ -1012,49 +1201,73 @@ bool recording_screen(void)
1012 case ACTION_STD_MENU: 1201 case ACTION_STD_MENU:
1013 if(audio_stat != AUDIO_STATUS_RECORD) 1202 if(audio_stat != AUDIO_STATUS_RECORD)
1014 { 1203 {
1204#ifdef HAVE_FMRADIO_IN
1205 const int prev_rec_source = global_settings.rec_source;
1206#endif
1207
1015#if CONFIG_LED == LED_REAL 1208#if CONFIG_LED == LED_REAL
1016 /* led is restored at begin of loop / end of function */ 1209 /* led is restored at begin of loop / end of function */
1017 led(false); 1210 led(false);
1018#endif 1211#endif
1019 if (recording_menu(false)) 1212 if (recording_menu(no_source))
1020 { 1213 {
1021 return SYS_USB_CONNECTED; 1214 done = true;
1215 been_in_usb_mode = true;
1216#ifdef HAVE_FMRADIO_IN
1217 radio_status = FMRADIO_OFF;
1218#endif
1022 } 1219 }
1023 settings_save(); 1220 else
1221 {
1222 settings_save();
1223
1224#ifdef HAVE_FMRADIO_IN
1225 /* If input changes away from FM Radio, radio will
1226 remain off when recording screen closes. */
1227 if (global_settings.rec_source != prev_rec_source
1228 && prev_rec_source == AUDIO_SRC_FMRADIO)
1229 radio_status = FMRADIO_OFF;
1230#endif
1024 1231
1025#if CONFIG_CODEC != SWCODEC 1232#if CONFIG_CODEC == SWCODEC
1026 if (global_settings.rec_prerecord_time) 1233 /* reinit after submenu exit */
1234 audio_close_recording();
1235 audio_init_recording(talk_get_bufsize());
1027#endif 1236#endif
1028 talk_buffer_steal(); /* will use the mp3 buffer */ 1237 rec_set_recording_options(
1029 1238 global_settings.rec_frequency,
1030 audio_set_recording_options(global_settings.rec_frequency, 1239 global_settings.rec_quality,
1031 global_settings.rec_quality, 1240 global_settings.rec_source,
1032 global_settings.rec_source, 1241 0,
1033 global_settings.rec_channels, 1242 global_settings.rec_channels,
1034 global_settings.rec_editable, 1243 global_settings.rec_editable,
1035 global_settings.rec_prerecord_time); 1244 global_settings.rec_prerecord_time);
1245
1036#ifdef HAVE_AGC 1246#ifdef HAVE_AGC
1037 if (global_settings.rec_source == SOURCE_MIC) { 1247 if (global_settings.rec_source == AUDIO_SRC_MIC) {
1038 agc_preset = global_settings.rec_agc_preset_mic; 1248 agc_preset = global_settings.rec_agc_preset_mic;
1039 agc_maxgain = global_settings.rec_agc_maxgain_mic; 1249 agc_maxgain = global_settings.rec_agc_maxgain_mic;
1040 } 1250 }
1041 else { 1251 else {
1042 agc_preset = global_settings.rec_agc_preset_line; 1252 agc_preset = global_settings.rec_agc_preset_line;
1043 agc_maxgain = global_settings.rec_agc_maxgain_line; 1253 agc_maxgain = global_settings.rec_agc_maxgain_line;
1044 } 1254 }
1045#endif 1255#endif
1046 1256
1047 adjust_cursor(); 1257 adjust_cursor();
1048 set_gain(); 1258 set_gain();
1049 update_countdown = 1; /* Update immediately */ 1259 update_countdown = 1; /* Update immediately */
1050 1260
1051 FOR_NB_SCREENS(i) 1261 FOR_NB_SCREENS(i)
1052 { 1262 {
1053 screens[i].setfont(FONT_SYSFIXED); 1263 screens[i].setfont(FONT_SYSFIXED);
1054 screens[i].setmargins(global_settings.invert_cursor ? 0 : w, 8); 1264 screens[i].setmargins(
1265 global_settings.invert_cursor ? 0 : w, 8);
1266 }
1055 } 1267 }
1056 } 1268 }
1057 break; 1269 break;
1270
1058#if CONFIG_KEYPAD == RECORDER_PAD 1271#if CONFIG_KEYPAD == RECORDER_PAD
1059 case ACTION_REC_F2: 1272 case ACTION_REC_F2:
1060 if(audio_stat != AUDIO_STATUS_RECORD) 1273 if(audio_stat != AUDIO_STATUS_RECORD)
@@ -1076,7 +1289,7 @@ bool recording_screen(void)
1076 case ACTION_REC_F3: 1289 case ACTION_REC_F3:
1077 if(audio_stat & AUDIO_STATUS_RECORD) 1290 if(audio_stat & AUDIO_STATUS_RECORD)
1078 { 1291 {
1079 audio_new_file(rec_create_filename(path_buffer)); 1292 rec_new_file();
1080 last_seconds = 0; 1293 last_seconds = 0;
1081 } 1294 }
1082 else 1295 else
@@ -1097,7 +1310,7 @@ bool recording_screen(void)
1097 } 1310 }
1098 } 1311 }
1099 break; 1312 break;
1100#endif 1313#endif /* CONFIG_KEYPAD == RECORDER_PAD */
1101 1314
1102 case SYS_USB_CONNECTED: 1315 case SYS_USB_CONNECTED:
1103 /* Only accept USB connection when not recording */ 1316 /* Only accept USB connection when not recording */
@@ -1106,6 +1319,9 @@ bool recording_screen(void)
1106 default_event_handler(SYS_USB_CONNECTED); 1319 default_event_handler(SYS_USB_CONNECTED);
1107 done = true; 1320 done = true;
1108 been_in_usb_mode = true; 1321 been_in_usb_mode = true;
1322#ifdef HAVE_FMRADIO_IN
1323 radio_status = FMRADIO_OFF;
1324#endif
1109 } 1325 }
1110 break; 1326 break;
1111 1327
@@ -1113,8 +1329,6 @@ bool recording_screen(void)
1113 default_event_handler(button); 1329 default_event_handler(button);
1114 break; 1330 break;
1115 } 1331 }
1116 if (button != BUTTON_NONE)
1117 lastbutton = button;
1118 1332
1119#ifdef HAVE_AGC 1333#ifdef HAVE_AGC
1120 peak_read = !peak_read; 1334 peak_read = !peak_read;
@@ -1230,7 +1444,7 @@ bool recording_screen(void)
1230 if (!(global_settings.rec_split_type) 1444 if (!(global_settings.rec_split_type)
1231 || (num_recorded_bytes >= MAX_FILE_SIZE)) 1445 || (num_recorded_bytes >= MAX_FILE_SIZE))
1232 { 1446 {
1233 audio_new_file(rec_create_filename(path_buffer)); 1447 rec_new_file();
1234 last_seconds = 0; 1448 last_seconds = 0;
1235 } 1449 }
1236 else 1450 else
@@ -1259,8 +1473,9 @@ bool recording_screen(void)
1259 screens[i].puts(0, filename_offset[i] + PM_HEIGHT + 2, buf); 1473 screens[i].puts(0, filename_offset[i] + PM_HEIGHT + 2, buf);
1260 } 1474 }
1261 1475
1262 if(global_settings.rec_source == SOURCE_MIC) 1476 if(global_settings.rec_source == AUDIO_SRC_MIC)
1263 { 1477 {
1478 /* Draw MIC recording gain */
1264 snprintf(buf, 32, "%s:%s", str(LANG_SYSFONT_RECORDING_GAIN), 1479 snprintf(buf, 32, "%s:%s", str(LANG_SYSFONT_RECORDING_GAIN),
1265 fmt_gain(SOUND_MIC_GAIN, 1480 fmt_gain(SOUND_MIC_GAIN,
1266 global_settings.rec_mic_gain, 1481 global_settings.rec_mic_gain,
@@ -1278,8 +1493,13 @@ bool recording_screen(void)
1278 PM_HEIGHT + 3, buf); 1493 PM_HEIGHT + 3, buf);
1279 } 1494 }
1280 } 1495 }
1281 else if(global_settings.rec_source == SOURCE_LINE) 1496 else if(global_settings.rec_source == AUDIO_SRC_LINEIN
1497#ifdef HAVE_FMRADIO_IN
1498 || global_settings.rec_source == AUDIO_SRC_FMRADIO
1499#endif
1500 )
1282 { 1501 {
1502 /* Draw LINE or FMRADIO recording gain */
1283 snprintf(buf, 32, "%s:%s", 1503 snprintf(buf, 32, "%s:%s",
1284 str(LANG_SYSFONT_RECORDING_LEFT), 1504 str(LANG_SYSFONT_RECORDING_LEFT),
1285 fmt_gain(SOUND_LEFT_GAIN, 1505 fmt_gain(SOUND_LEFT_GAIN,
@@ -1319,14 +1539,23 @@ bool recording_screen(void)
1319 1539
1320 FOR_NB_SCREENS(i) 1540 FOR_NB_SCREENS(i)
1321 { 1541 {
1322 if (global_settings.rec_source == SOURCE_LINE) 1542 switch (global_settings.rec_source)
1543 {
1544 case AUDIO_SRC_LINEIN:
1545#ifdef HAVE_FMRADIO_IN
1546 case AUDIO_SRC_FMRADIO:
1547#endif
1323 line[i] = 5; 1548 line[i] = 5;
1324 else if (global_settings.rec_source == SOURCE_MIC) 1549 break;
1550 case AUDIO_SRC_MIC:
1325 line[i] = 4; 1551 line[i] = 4;
1552 break;
1326#ifdef HAVE_SPDIF_IN 1553#ifdef HAVE_SPDIF_IN
1327 else if (global_settings.rec_source == SOURCE_SPDIF) 1554 case AUDIO_SRC_SPDIF:
1328 line[i] = 3; 1555 line[i] = 3;
1556 break;
1329#endif 1557#endif
1558 } /* end switch */
1330#ifdef HAVE_AGC 1559#ifdef HAVE_AGC
1331 if (screens[i].height < h * (2 + filename_offset[i] + PM_HEIGHT + line[i])) 1560 if (screens[i].height < h * (2 + filename_offset[i] + PM_HEIGHT + line[i]))
1332 { 1561 {
@@ -1358,7 +1587,7 @@ bool recording_screen(void)
1358 snprintf(buf, 32, "%s: %s", 1587 snprintf(buf, 32, "%s: %s",
1359 str(LANG_RECORDING_AGC_PRESET), 1588 str(LANG_RECORDING_AGC_PRESET),
1360 agc_preset_str[agc_preset]); 1589 agc_preset_str[agc_preset]);
1361 else if (global_settings.rec_source == SOURCE_MIC) 1590 else if (global_settings.rec_source == AUDIO_SRC_MIC)
1362 snprintf(buf, 32, "%s: %s%s", 1591 snprintf(buf, 32, "%s: %s%s",
1363 str(LANG_RECORDING_AGC_PRESET), 1592 str(LANG_RECORDING_AGC_PRESET),
1364 agc_preset_str[agc_preset], 1593 agc_preset_str[agc_preset],
@@ -1382,8 +1611,12 @@ bool recording_screen(void)
1382 screens[i].puts_style_offset(0, filename_offset[i] + 1611 screens[i].puts_style_offset(0, filename_offset[i] +
1383 PM_HEIGHT + line[i], buf, STYLE_INVERT,0); 1612 PM_HEIGHT + line[i], buf, STYLE_INVERT,0);
1384 } 1613 }
1385 else if ((global_settings.rec_source == SOURCE_MIC) 1614 else if (global_settings.rec_source == AUDIO_SRC_MIC
1386 || (global_settings.rec_source == SOURCE_LINE)) 1615 || global_settings.rec_source == AUDIO_SRC_LINEIN
1616#ifdef HAVE_FMRADIO_IN
1617 || global_settings.rec_source == AUDIO_SRC_FMRADIO
1618#endif
1619 )
1387 { 1620 {
1388 for(i = 0; i < screen_update; i++) { 1621 for(i = 0; i < screen_update; i++) {
1389 if (display_agc[i]) { 1622 if (display_agc[i]) {
@@ -1393,7 +1626,7 @@ bool recording_screen(void)
1393 } 1626 }
1394 } 1627 }
1395 1628
1396 if (global_settings.rec_source == SOURCE_MIC) 1629 if (global_settings.rec_source == AUDIO_SRC_MIC)
1397 { 1630 {
1398 if(agc_maxgain < (global_settings.rec_mic_gain)) 1631 if(agc_maxgain < (global_settings.rec_mic_gain))
1399 change_recording_gain(false, true, true); 1632 change_recording_gain(false, true, true);
@@ -1418,7 +1651,7 @@ bool recording_screen(void)
1418 filename_offset[i] + 1651 filename_offset[i] +
1419 PM_HEIGHT + 3, true); 1652 PM_HEIGHT + 3, true);
1420 1653
1421 if(global_settings.rec_source != SOURCE_MIC) 1654 if(global_settings.rec_source != AUDIO_SRC_MIC)
1422 { 1655 {
1423 for(i = 0; i < screen_update; i++) 1656 for(i = 0; i < screen_update; i++)
1424 screen_put_cursorxy(&screens[i], 0, 1657 screen_put_cursorxy(&screens[i], 0,
@@ -1456,14 +1689,14 @@ bool recording_screen(void)
1456 } 1689 }
1457/* Can't measure S/PDIF sample rate on Archos yet */ 1690/* Can't measure S/PDIF sample rate on Archos yet */
1458#if (CONFIG_CODEC != MAS3587F) && defined(HAVE_SPDIF_IN) && !defined(SIMULATOR) 1691#if (CONFIG_CODEC != MAS3587F) && defined(HAVE_SPDIF_IN) && !defined(SIMULATOR)
1459 if (global_settings.rec_source == SOURCE_SPDIF) 1692 if (global_settings.rec_source == AUDIO_SRC_SPDIF)
1460 snprintf(spdif_sfreq, 8, "%dHz", audio_get_spdif_sample_rate()); 1693 snprintf(spdif_sfreq, 8, "%dHz", audio_get_spdif_sample_rate());
1461#else 1694#else
1462 (void)spdif_sfreq; 1695 (void)spdif_sfreq;
1463#endif 1696#endif
1464 snprintf(buf, 32, "%s %s", 1697 snprintf(buf, 32, "%s %s",
1465#if (CONFIG_CODEC != MAS3587F) && defined(HAVE_SPDIF_IN) && !defined(SIMULATOR) 1698#if (CONFIG_CODEC != MAS3587F) && defined(HAVE_SPDIF_IN) && !defined(SIMULATOR)
1466 global_settings.rec_source == SOURCE_SPDIF ? 1699 global_settings.rec_source == AUDIO_SRC_SPDIF ?
1467 spdif_sfreq : 1700 spdif_sfreq :
1468#endif 1701#endif
1469 freq_str[global_settings.rec_frequency], 1702 freq_str[global_settings.rec_frequency],
@@ -1473,8 +1706,8 @@ bool recording_screen(void)
1473 1706
1474 for(i = 0; i < screen_update; i++) { 1707 for(i = 0; i < screen_update; i++) {
1475#ifdef HAVE_AGC 1708#ifdef HAVE_AGC
1476 if ((global_settings.rec_source == SOURCE_MIC) 1709 if ((global_settings.rec_source == AUDIO_SRC_MIC)
1477 || (global_settings.rec_source == SOURCE_LINE)) 1710 || (global_settings.rec_source == AUDIO_SRC_LINEIN))
1478 screens[i].puts(0, filename_offset[i] + PM_HEIGHT + line[i] + 1, buf); 1711 screens[i].puts(0, filename_offset[i] + PM_HEIGHT + line[i] + 1, buf);
1479 else 1712 else
1480#endif 1713#endif
@@ -1484,6 +1717,14 @@ bool recording_screen(void)
1484#ifdef HAVE_AGC 1717#ifdef HAVE_AGC
1485 hist_time++; 1718 hist_time++;
1486#endif 1719#endif
1720
1721#if CONFIG_CODEC == SWCODEC
1722 snprintf(buf, 32, "%s",
1723 REC_QUALITY_LABEL(global_settings.rec_quality));
1724 for(i = 0; i < screen_update; i++)
1725 screens[i].puts(0, filename_offset[i] + PM_HEIGHT + 6, buf);
1726#endif
1727
1487 for(i = 0; i < screen_update; i++) 1728 for(i = 0; i < screen_update; i++)
1488 { 1729 {
1489 gui_statusbar_draw(&(statusbars.statusbars[i]), true); 1730 gui_statusbar_draw(&(statusbars.statusbars[i]), true);
@@ -1506,7 +1747,7 @@ bool recording_screen(void)
1506 { 1747 {
1507 done = true; 1748 done = true;
1508 } 1749 }
1509 } 1750 } /* end while(!done) */
1510 1751
1511 1752
1512#if CONFIG_CODEC == SWCODEC 1753#if CONFIG_CODEC == SWCODEC
@@ -1531,18 +1772,26 @@ bool recording_screen(void)
1531 } 1772 }
1532 } 1773 }
1533 1774
1534#if CONFIG_CODEC == SWCODEC 1775#if CONFIG_CODEC == SWCODEC
1535 audio_stop_recording(); 1776 audio_stop_recording();
1536 audio_close_recording(); 1777 audio_close_recording();
1537 1778
1538#if defined(HAVE_SPDIF_IN) && !defined(SIMULATOR) 1779#ifdef HAVE_FMRADIO_IN
1539 if (global_settings.rec_source == SOURCE_SPDIF) 1780 if (radio_status != FMRADIO_OFF)
1540 cpu_boost(false); 1781 /* Restore radio playback - radio_status should be unchanged if started
1782 through fm radio screen (barring usb connect) */
1783 rec_set_source(AUDIO_SRC_FMRADIO, (radio_status & FMRADIO_PAUSED) ?
1784 SRCF_FMRADIO_PAUSED : SRCF_FMRADIO_PLAYING);
1785 else
1541#endif 1786#endif
1787 /* Go back to playback mode */
1788 rec_set_source(AUDIO_SRC_PLAYBACK, SRCF_PLAYBACK);
1542 1789
1543#else 1790 /* restore talk_menu setting */
1791 global_settings.talk_menu = talk_menu;
1792#else /* !SWCODEC */
1544 audio_init_playback(); 1793 audio_init_playback();
1545#endif 1794#endif /* CONFIG_CODEC == SWCODEC */
1546 1795
1547 /* make sure the trigger is really turned off */ 1796 /* make sure the trigger is really turned off */
1548 peak_meter_trigger(false); 1797 peak_meter_trigger(false);
@@ -1560,7 +1809,7 @@ bool recording_screen(void)
1560 ata_set_led_enabled(true); 1809 ata_set_led_enabled(true);
1561#endif 1810#endif
1562 return been_in_usb_mode; 1811 return been_in_usb_mode;
1563} 1812} /* recording_screen */
1564 1813
1565#if CONFIG_KEYPAD == RECORDER_PAD 1814#if CONFIG_KEYPAD == RECORDER_PAD
1566bool f2_rec_screen(void) 1815bool f2_rec_screen(void)
@@ -1680,15 +1929,13 @@ bool f2_rec_screen(void)
1680 } 1929 }
1681 } 1930 }
1682 1931
1683 if (global_settings.rec_prerecord_time) 1932 rec_set_recording_options(global_settings.rec_frequency,
1684 talk_buffer_steal(); /* will use the mp3 buffer */ 1933 global_settings.rec_quality,
1685 1934 global_settings.rec_source,
1686 audio_set_recording_options(global_settings.rec_frequency, 1935 0,
1687 global_settings.rec_quality, 1936 global_settings.rec_channels,
1688 global_settings.rec_source, 1937 global_settings.rec_editable,
1689 global_settings.rec_channels, 1938 global_settings.rec_prerecord_time);
1690 global_settings.rec_editable,
1691 global_settings.rec_prerecord_time);
1692 1939
1693 set_gain(); 1940 set_gain();
1694 1941
@@ -1760,7 +2007,7 @@ bool f3_rec_screen(void)
1760 case BUTTON_LEFT: 2007 case BUTTON_LEFT:
1761 case BUTTON_F3 | BUTTON_LEFT: 2008 case BUTTON_F3 | BUTTON_LEFT:
1762 global_settings.rec_source++; 2009 global_settings.rec_source++;
1763 if(global_settings.rec_source > MAX_SOURCE) 2010 if(global_settings.rec_source > AUDIO_SRC_MAX)
1764 global_settings.rec_source = 0; 2011 global_settings.rec_source = 0;
1765 used = true; 2012 used = true;
1766 break; 2013 break;
@@ -1782,16 +2029,13 @@ bool f3_rec_screen(void)
1782 } 2029 }
1783 } 2030 }
1784 2031
1785 if (global_settings.rec_prerecord_time) 2032 rec_set_recording_options(global_settings.rec_frequency,
1786 talk_buffer_steal(); /* will use the mp3 buffer */ 2033 global_settings.rec_quality,
1787 2034 global_settings.rec_source,
1788 audio_set_recording_options(global_settings.rec_frequency, 2035 0,
1789 global_settings.rec_quality, 2036 global_settings.rec_channels,
1790 global_settings.rec_source, 2037 global_settings.rec_editable,
1791 global_settings.rec_channels, 2038 global_settings.rec_prerecord_time);
1792 global_settings.rec_editable,
1793 global_settings.rec_prerecord_time);
1794
1795 2039
1796 set_gain(); 2040 set_gain();
1797 2041
@@ -1801,7 +2045,7 @@ bool f3_rec_screen(void)
1801 2045
1802 return false; 2046 return false;
1803} 2047}
1804#endif /* #ifdef RECORDER_PAD */ 2048#endif /* CONFIG_KEYPAD == RECORDER_PAD */
1805 2049
1806#if CONFIG_CODEC == SWCODEC 2050#if CONFIG_CODEC == SWCODEC
1807void audio_beep(int duration) 2051void audio_beep(int duration)
@@ -1831,6 +2075,14 @@ unsigned long audio_num_recorded_bytes(void)
1831 return 5 * 1024 * 1024; 2075 return 5 * 1024 * 1024;
1832} 2076}
1833 2077
2078#if CONFIG_CODEC == SWCODEC
2079void rec_set_source(int source, int flags)
2080{
2081 source = source;
2082 flags = flags;
2083}
2084#endif
2085
1834void audio_set_recording_options(int frequency, int quality, 2086void audio_set_recording_options(int frequency, int quality,
1835 int source, int channel_mode, 2087 int source, int channel_mode,
1836 bool editable, int prerecord_time) 2088 bool editable, int prerecord_time)
diff --git a/apps/recorder/recording.h b/apps/recorder/recording.h
index 384b34f5bf..aa216e757f 100644
--- a/apps/recorder/recording.h
+++ b/apps/recorder/recording.h
@@ -19,8 +19,33 @@
19#ifndef RECORDING_H 19#ifndef RECORDING_H
20#define RECORDING_H 20#define RECORDING_H
21 21
22bool recording_screen(void); 22bool recording_screen(bool no_source);
23char *rec_create_filename(char *buf); 23char *rec_create_filename(char *buf);
24int rec_create_directory(void); 24int rec_create_directory(void);
25 25
26#if CONFIG_CODEC == SWCODEC
27/* selects an audio source for recording or playback */
28#define SRCF_PLAYBACK 0x0000 /* default */
29#define SRCF_RECORDING 0x1000
30#ifdef CONFIG_TUNER
31/* for AUDIO_SRC_FMRADIO */
32#define SRCF_FMRADIO_PLAYING 0x0000 /* default */
33#define SRCF_FMRADIO_PAUSED 0x2000
34#endif
35void rec_set_source(int source, int flags);
36#endif /* CONFIG_CODEC == SW_CODEC */
37
38/* steals mp3 buffer, sets source and then options */
39/* SRCF_RECORDING is implied */
40void rec_set_recording_options(int frequency, int quality,
41 int source, int source_flags,
42 int channel_mode, bool editable,
43 int prerecord_time);
44
45/* steals mp3 buffer, creates unique filename and starts recording */
46void rec_record(void);
47
48/* creates unique filename and starts recording */
49void rec_new_file(void);
50
26#endif 51#endif