diff options
Diffstat (limited to 'apps/recorder/recording.c')
-rw-r--r-- | apps/recorder/recording.c | 127 |
1 files changed, 79 insertions, 48 deletions
diff --git a/apps/recorder/recording.c b/apps/recorder/recording.c index f7ceb508d5..17ed1052cb 100644 --- a/apps/recorder/recording.c +++ b/apps/recorder/recording.c | |||
@@ -70,11 +70,20 @@ | |||
70 | #include "radio.h" | 70 | #include "radio.h" |
71 | #ifdef HAVE_RECORDING | 71 | #ifdef HAVE_RECORDING |
72 | 72 | ||
73 | static bool in_screen = false; | 73 | /* recording screen status flags */ |
74 | 74 | enum rec_status_flags | |
75 | { | ||
76 | RCSTAT_IN_RECSCREEN = 0x00000001, | ||
77 | RCSTAT_BEEN_IN_USB_MODE = 0x00000002, | ||
78 | RCSTAT_CREATED_DIRECTORY = 0x00000004, | ||
79 | RCSTAT_HAVE_RECORDED = 0x00000008, | ||
80 | }; | ||
81 | |||
82 | static int rec_status = 0; | ||
83 | |||
75 | bool in_recording_screen(void) | 84 | bool in_recording_screen(void) |
76 | { | 85 | { |
77 | return in_screen; | 86 | return (rec_status & RCSTAT_IN_RECSCREEN) != 0; |
78 | } | 87 | } |
79 | 88 | ||
80 | #define PM_HEIGHT ((LCD_HEIGHT >= 72) ? 2 : 1) | 89 | #define PM_HEIGHT ((LCD_HEIGHT >= 72) ? 2 : 1) |
@@ -92,13 +101,13 @@ static bool remote_display_on = true; | |||
92 | #endif | 101 | #endif |
93 | 102 | ||
94 | /** File name creation **/ | 103 | /** File name creation **/ |
95 | #if CONFIG_CODEC == SWCODEC | 104 | #if CONFIG_RTC == 0 |
96 | |||
97 | #ifdef IF_CNFN_NUM | ||
98 | /* current file number to assist in creating unique numbered filenames | 105 | /* current file number to assist in creating unique numbered filenames |
99 | without actually having to create the file on disk */ | 106 | without actually having to create the file on disk */ |
100 | static int file_number = -1; | 107 | static int file_number = -1; |
101 | #endif /* IF_CNFN_NUM */ | 108 | #endif /* CONFIG_RTC */ |
109 | |||
110 | #if CONFIG_CODEC == SWCODEC | ||
102 | 111 | ||
103 | #define REC_FILE_ENDING(rec_format) \ | 112 | #define REC_FILE_ENDING(rec_format) \ |
104 | (audio_formats[rec_format_afmt[rec_format]].ext_list) | 113 | (audio_formats[rec_format_afmt[rec_format]].ext_list) |
@@ -511,16 +520,26 @@ char *rec_create_filename(char *buffer) | |||
511 | snprintf(ext, sizeof(ext), ".%s", | 520 | snprintf(ext, sizeof(ext), ".%s", |
512 | REC_FILE_ENDING(global_settings.rec_format)); | 521 | REC_FILE_ENDING(global_settings.rec_format)); |
513 | 522 | ||
514 | #if CONFIG_RTC | 523 | #if CONFIG_RTC == 0 |
524 | return create_numbered_filename(buffer, buffer, "rec_", ext, 4, | ||
525 | &file_number); | ||
526 | #else | ||
515 | /* We'll wait at least up to the start of the next second so no duplicate | 527 | /* We'll wait at least up to the start of the next second so no duplicate |
516 | names are created */ | 528 | names are created */ |
517 | return create_datetime_filename(buffer, buffer, "R", ext, true); | 529 | return create_datetime_filename(buffer, buffer, "R", ext, true); |
518 | #else | ||
519 | return create_numbered_filename(buffer, buffer, "rec_", ext, 4 | ||
520 | IF_CNFN_NUM_(, &file_number)); | ||
521 | #endif | 530 | #endif |
522 | } | 531 | } |
523 | 532 | ||
533 | #if CONFIG_RTC == 0 | ||
534 | /* Hit disk to get a starting filename for the type */ | ||
535 | void rec_init_filename(void) | ||
536 | { | ||
537 | file_number = -1; | ||
538 | rec_create_filename(path_buffer); | ||
539 | file_number--; | ||
540 | } | ||
541 | #endif | ||
542 | |||
524 | int rec_create_directory(void) | 543 | int rec_create_directory(void) |
525 | { | 544 | { |
526 | int rc; | 545 | int rc; |
@@ -594,7 +613,6 @@ void rec_record(void) | |||
594 | #if CONFIG_CODEC != SWCODEC | 613 | #if CONFIG_CODEC != SWCODEC |
595 | talk_buffer_steal(); /* we use the mp3 buffer */ | 614 | talk_buffer_steal(); /* we use the mp3 buffer */ |
596 | #endif | 615 | #endif |
597 | IF_CNFN_NUM_(file_number = -1;) /* Hit disk for number */ | ||
598 | audio_record(rec_create_filename(path_buffer)); | 616 | audio_record(rec_create_filename(path_buffer)); |
599 | } | 617 | } |
600 | 618 | ||
@@ -617,12 +635,15 @@ static void trigger_listener(int trigger_status) | |||
617 | switch (trigger_status) | 635 | switch (trigger_status) |
618 | { | 636 | { |
619 | case TRIG_GO: | 637 | case TRIG_GO: |
620 | if((audio_status() & AUDIO_STATUS_RECORD) != AUDIO_STATUS_RECORD) | 638 | if(!(audio_status() & AUDIO_STATUS_RECORD)) |
621 | { | 639 | { |
640 | rec_status |= RCSTAT_HAVE_RECORDED; | ||
622 | rec_record(); | 641 | rec_record(); |
642 | #if CONFIG_CODEC != SWCODEC | ||
623 | /* give control to mpeg thread so that it can start | 643 | /* give control to mpeg thread so that it can start |
624 | recording */ | 644 | recording */ |
625 | yield(); yield(); yield(); | 645 | yield(); yield(); yield(); |
646 | #endif | ||
626 | } | 647 | } |
627 | 648 | ||
628 | /* if we're already recording this is a retrigger */ | 649 | /* if we're already recording this is a retrigger */ |
@@ -648,11 +669,7 @@ static void trigger_listener(int trigger_status) | |||
648 | switch(global_settings.rec_trigger_type) | 669 | switch(global_settings.rec_trigger_type) |
649 | { | 670 | { |
650 | case 0: /* Stop */ | 671 | case 0: /* Stop */ |
651 | #if CONFIG_CODEC == SWCODEC | ||
652 | audio_stop_recording(); | 672 | audio_stop_recording(); |
653 | #else | ||
654 | audio_stop(); | ||
655 | #endif | ||
656 | break; | 673 | break; |
657 | 674 | ||
658 | case 1: /* Pause */ | 675 | case 1: /* Pause */ |
@@ -686,11 +703,9 @@ bool recording_screen(bool no_source) | |||
686 | char buf2[32]; | 703 | char buf2[32]; |
687 | int w, h; | 704 | int w, h; |
688 | int update_countdown = 1; | 705 | int update_countdown = 1; |
689 | bool have_recorded = false; | ||
690 | unsigned int seconds; | 706 | unsigned int seconds; |
691 | int hours, minutes; | 707 | int hours, minutes; |
692 | char filename[13]; | 708 | char filename[13]; |
693 | bool been_in_usb_mode = false; | ||
694 | int last_audio_stat = -1; | 709 | int last_audio_stat = -1; |
695 | int audio_stat; | 710 | int audio_stat; |
696 | #if CONFIG_CODEC == SWCODEC | 711 | #if CONFIG_CODEC == SWCODEC |
@@ -733,7 +748,7 @@ bool recording_screen(bool no_source) | |||
733 | 748 | ||
734 | struct audio_recording_options rec_options; | 749 | struct audio_recording_options rec_options; |
735 | 750 | ||
736 | in_screen = true; | 751 | rec_status = RCSTAT_IN_RECSCREEN; |
737 | cursor = 0; | 752 | cursor = 0; |
738 | #if (CONFIG_LED == LED_REAL) && !defined(SIMULATOR) | 753 | #if (CONFIG_LED == LED_REAL) && !defined(SIMULATOR) |
739 | ata_set_led_enabled(false); | 754 | ata_set_led_enabled(false); |
@@ -761,6 +776,15 @@ bool recording_screen(bool no_source) | |||
761 | rec_set_recording_options(&rec_options); | 776 | rec_set_recording_options(&rec_options); |
762 | 777 | ||
763 | set_gain(); | 778 | set_gain(); |
779 | |||
780 | if(rec_create_directory() > 0) | ||
781 | rec_status |= RCSTAT_CREATED_DIRECTORY; | ||
782 | |||
783 | #if CONFIG_RTC == 0 | ||
784 | /* Create new filename for recording start */ | ||
785 | rec_init_filename(); | ||
786 | #endif | ||
787 | |||
764 | settings_apply_trigger(); | 788 | settings_apply_trigger(); |
765 | 789 | ||
766 | #ifdef HAVE_AGC | 790 | #ifdef HAVE_AGC |
@@ -788,9 +812,7 @@ bool recording_screen(bool no_source) | |||
788 | filename_offset[i] = ((screens[i].height >= 80) ? 1 : 0); | 812 | filename_offset[i] = ((screens[i].height >= 80) ? 1 : 0); |
789 | pm_y[i] = 8 + h * (2 + filename_offset[i]); | 813 | pm_y[i] = 8 + h * (2 + filename_offset[i]); |
790 | } | 814 | } |
791 | 815 | ||
792 | if(rec_create_directory() > 0) | ||
793 | have_recorded = true; | ||
794 | #ifdef HAVE_REMOTE_LCD | 816 | #ifdef HAVE_REMOTE_LCD |
795 | if (!remote_display_on) | 817 | if (!remote_display_on) |
796 | { | 818 | { |
@@ -859,9 +881,9 @@ bool recording_screen(bool no_source) | |||
859 | 881 | ||
860 | if (last_audio_stat != audio_stat) | 882 | if (last_audio_stat != audio_stat) |
861 | { | 883 | { |
862 | if (audio_stat == AUDIO_STATUS_RECORD) | 884 | if (audio_stat & AUDIO_STATUS_RECORD) |
863 | { | 885 | { |
864 | have_recorded = true; | 886 | rec_status |= RCSTAT_HAVE_RECORDED; |
865 | } | 887 | } |
866 | last_audio_stat = audio_stat; | 888 | last_audio_stat = audio_stat; |
867 | } | 889 | } |
@@ -926,7 +948,7 @@ bool recording_screen(bool no_source) | |||
926 | (peak_meter_trigger_status() != TRIG_OFF)) | 948 | (peak_meter_trigger_status() != TRIG_OFF)) |
927 | { | 949 | { |
928 | /* manual recording */ | 950 | /* manual recording */ |
929 | have_recorded = true; | 951 | rec_status |= RCSTAT_HAVE_RECORDED; |
930 | rec_record(); | 952 | rec_record(); |
931 | last_seconds = 0; | 953 | last_seconds = 0; |
932 | if (global_settings.talk_menu) | 954 | if (global_settings.talk_menu) |
@@ -1119,7 +1141,11 @@ bool recording_screen(bool no_source) | |||
1119 | break; | 1141 | break; |
1120 | 1142 | ||
1121 | case ACTION_STD_MENU: | 1143 | case ACTION_STD_MENU: |
1144 | #if CONFIG_CODEC == SWCODEC | ||
1145 | if(!(audio_stat & AUDIO_STATUS_RECORD)) | ||
1146 | #else | ||
1122 | if(audio_stat != AUDIO_STATUS_RECORD) | 1147 | if(audio_stat != AUDIO_STATUS_RECORD) |
1148 | #endif | ||
1123 | { | 1149 | { |
1124 | #ifdef HAVE_FMRADIO_REC | 1150 | #ifdef HAVE_FMRADIO_REC |
1125 | const int prev_rec_source = global_settings.rec_source; | 1151 | const int prev_rec_source = global_settings.rec_source; |
@@ -1132,7 +1158,7 @@ bool recording_screen(bool no_source) | |||
1132 | if (recording_menu(no_source)) | 1158 | if (recording_menu(no_source)) |
1133 | { | 1159 | { |
1134 | done = true; | 1160 | done = true; |
1135 | been_in_usb_mode = true; | 1161 | rec_status |= RCSTAT_BEEN_IN_USB_MODE; |
1136 | #ifdef HAVE_FMRADIO_REC | 1162 | #ifdef HAVE_FMRADIO_REC |
1137 | radio_status = FMRADIO_OFF; | 1163 | radio_status = FMRADIO_OFF; |
1138 | #endif | 1164 | #endif |
@@ -1152,11 +1178,18 @@ bool recording_screen(bool no_source) | |||
1152 | audio_close_recording(); | 1178 | audio_close_recording(); |
1153 | audio_init_recording(0); | 1179 | audio_init_recording(0); |
1154 | #endif | 1180 | #endif |
1181 | |||
1155 | rec_init_recording_options(&rec_options); | 1182 | rec_init_recording_options(&rec_options); |
1156 | rec_set_recording_options(&rec_options); | 1183 | rec_set_recording_options(&rec_options); |
1157 | 1184 | ||
1158 | if(rec_create_directory() > 0) | 1185 | if(rec_create_directory() > 0) |
1159 | have_recorded = true; | 1186 | rec_status |= RCSTAT_CREATED_DIRECTORY; |
1187 | |||
1188 | #if CONFIG_CODEC == SWCODEC && CONFIG_RTC == 0 | ||
1189 | /* If format changed, a new number is required */ | ||
1190 | rec_init_filename(); | ||
1191 | #endif | ||
1192 | |||
1160 | #ifdef HAVE_AGC | 1193 | #ifdef HAVE_AGC |
1161 | if (global_settings.rec_source == AUDIO_SRC_MIC) { | 1194 | if (global_settings.rec_source == AUDIO_SRC_MIC) { |
1162 | agc_preset = global_settings.rec_agc_preset_mic; | 1195 | agc_preset = global_settings.rec_agc_preset_mic; |
@@ -1192,7 +1225,7 @@ bool recording_screen(bool no_source) | |||
1192 | #endif | 1225 | #endif |
1193 | if (f2_rec_screen()) | 1226 | if (f2_rec_screen()) |
1194 | { | 1227 | { |
1195 | have_recorded = true; | 1228 | rec_status |= RCSTAT_HAVE_RECORDED; |
1196 | done = true; | 1229 | done = true; |
1197 | } | 1230 | } |
1198 | else | 1231 | else |
@@ -1208,31 +1241,28 @@ bool recording_screen(bool no_source) | |||
1208 | } | 1241 | } |
1209 | else | 1242 | else |
1210 | { | 1243 | { |
1211 | if(audio_stat != AUDIO_STATUS_RECORD) | ||
1212 | { | ||
1213 | #if (CONFIG_LED == LED_REAL) | 1244 | #if (CONFIG_LED == LED_REAL) |
1214 | /* led is restored at begin of loop / end of function */ | 1245 | /* led is restored at begin of loop / end of function */ |
1215 | led(false); | 1246 | led(false); |
1216 | #endif | 1247 | #endif |
1217 | if (f3_rec_screen()) | 1248 | if (f3_rec_screen()) |
1218 | { | 1249 | { |
1219 | have_recorded = true; | 1250 | rec_status |= RCSTAT_HAVE_RECORDED; |
1220 | done = true; | 1251 | done = true; |
1221 | } | ||
1222 | else | ||
1223 | update_countdown = 1; /* Update immediately */ | ||
1224 | } | 1252 | } |
1253 | else | ||
1254 | update_countdown = 1; /* Update immediately */ | ||
1225 | } | 1255 | } |
1226 | break; | 1256 | break; |
1227 | #endif /* CONFIG_KEYPAD == RECORDER_PAD */ | 1257 | #endif /* CONFIG_KEYPAD == RECORDER_PAD */ |
1228 | 1258 | ||
1229 | case SYS_USB_CONNECTED: | 1259 | case SYS_USB_CONNECTED: |
1230 | /* Only accept USB connection when not recording */ | 1260 | /* Only accept USB connection when not recording */ |
1231 | if(audio_stat != AUDIO_STATUS_RECORD) | 1261 | if(!(audio_stat & AUDIO_STATUS_RECORD)) |
1232 | { | 1262 | { |
1233 | default_event_handler(SYS_USB_CONNECTED); | 1263 | default_event_handler(SYS_USB_CONNECTED); |
1234 | done = true; | 1264 | done = true; |
1235 | been_in_usb_mode = true; | 1265 | rec_status |= RCSTAT_BEEN_IN_USB_MODE; |
1236 | #ifdef HAVE_FMRADIO_REC | 1266 | #ifdef HAVE_FMRADIO_REC |
1237 | radio_status = FMRADIO_OFF; | 1267 | radio_status = FMRADIO_OFF; |
1238 | #endif | 1268 | #endif |
@@ -1467,12 +1497,11 @@ bool recording_screen(bool no_source) | |||
1467 | { | 1497 | { |
1468 | switch (global_settings.rec_source) | 1498 | switch (global_settings.rec_source) |
1469 | { | 1499 | { |
1470 | #if defined(HAVE_LINE_REC) || defined(HAVE_FMRADIO_REC) | ||
1471 | HAVE_LINE_REC_(case AUDIO_SRC_LINEIN:) | 1500 | HAVE_LINE_REC_(case AUDIO_SRC_LINEIN:) |
1472 | HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO:) | 1501 | HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO:) |
1473 | line[i] = 5; | 1502 | line[i] = 5; |
1474 | break; | 1503 | break; |
1475 | #endif | 1504 | |
1476 | case AUDIO_SRC_MIC: | 1505 | case AUDIO_SRC_MIC: |
1477 | line[i] = 4; | 1506 | line[i] = 4; |
1478 | break; | 1507 | break; |
@@ -1678,7 +1707,7 @@ bool recording_screen(bool no_source) | |||
1678 | break; | 1707 | break; |
1679 | } | 1708 | } |
1680 | } | 1709 | } |
1681 | 1710 | ||
1682 | #if CONFIG_CODEC == SWCODEC | 1711 | #if CONFIG_CODEC == SWCODEC |
1683 | audio_stop_recording(); | 1712 | audio_stop_recording(); |
1684 | audio_close_recording(); | 1713 | audio_close_recording(); |
@@ -1704,13 +1733,15 @@ bool recording_screen(bool no_source) | |||
1704 | peak_meter_trigger(false); | 1733 | peak_meter_trigger(false); |
1705 | peak_meter_set_trigger_listener(NULL); | 1734 | peak_meter_set_trigger_listener(NULL); |
1706 | 1735 | ||
1707 | in_screen = false; | 1736 | rec_status &= ~RCSTAT_IN_RECSCREEN; |
1708 | sound_settings_apply(); | 1737 | sound_settings_apply(); |
1709 | 1738 | ||
1710 | FOR_NB_SCREENS(i) | 1739 | FOR_NB_SCREENS(i) |
1711 | screens[i].setfont(FONT_UI); | 1740 | screens[i].setfont(FONT_UI); |
1712 | 1741 | ||
1713 | if (have_recorded) | 1742 | /* if the directory was created or recording happened, make sure the |
1743 | browser is updated */ | ||
1744 | if (rec_status & (RCSTAT_CREATED_DIRECTORY | RCSTAT_HAVE_RECORDED)) | ||
1714 | reload_directory(); | 1745 | reload_directory(); |
1715 | 1746 | ||
1716 | #if (CONFIG_LED == LED_REAL) && !defined(SIMULATOR) | 1747 | #if (CONFIG_LED == LED_REAL) && !defined(SIMULATOR) |
@@ -1719,7 +1750,7 @@ bool recording_screen(bool no_source) | |||
1719 | 1750 | ||
1720 | settings_save(); | 1751 | settings_save(); |
1721 | 1752 | ||
1722 | return been_in_usb_mode; | 1753 | return (rec_status & RCSTAT_BEEN_IN_USB_MODE) != 0; |
1723 | } /* recording_screen */ | 1754 | } /* recording_screen */ |
1724 | 1755 | ||
1725 | #if CONFIG_KEYPAD == RECORDER_PAD | 1756 | #if CONFIG_KEYPAD == RECORDER_PAD |