summaryrefslogtreecommitdiff
path: root/apps/recorder/recording.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/recorder/recording.c')
-rw-r--r--apps/recorder/recording.c238
1 files changed, 189 insertions, 49 deletions
diff --git a/apps/recorder/recording.c b/apps/recorder/recording.c
index 8b52b7cac2..2c8e473c11 100644
--- a/apps/recorder/recording.c
+++ b/apps/recorder/recording.c
@@ -219,7 +219,6 @@ static char path_buffer[MAX_PATH];
219 * overflow every 13 years 8-) 219 * overflow every 13 years 8-)
220 */ 220 */
221static long peak_time = 0; 221static long peak_time = 0;
222static long hist_time = 0;
223 222
224static short peak_valid_mem[4]; 223static short peak_valid_mem[4];
225#define BAL_MEM_SIZE 24 224#define BAL_MEM_SIZE 24
@@ -269,6 +268,38 @@ static short agc_baltime = 0;
269/* AGC maximum gain */ 268/* AGC maximum gain */
270static short agc_maxgain; 269static short agc_maxgain;
271#endif /* HAVE_AGC */ 270#endif /* HAVE_AGC */
271#if defined(HAVE_AGC) || defined(HAVE_RECORDING_HISTOGRAM)
272static long hist_time = 0;
273#endif /* HAVE_AGC or HAVE_RECORDING_HISTOGRAM */
274/* Histogram data */
275/* TO DO: move some of this stuff inside the recording function? */
276#ifdef HAVE_RECORDING_HISTOGRAM
277static int hist_l = 0;
278static int hist_r = 0;
279#define HIST_Y (hist_pos_y+hist_size_h-1)
280#define HIST_W (LCD_WIDTH / 2 - 4)
281#if LCD_DEPTH > 1
282#ifdef HAVE_LCD_COLOR
283#define LCD_BAL_L LCD_RGBPACK(0, 0, 255)
284#define LCD_BAL_R LCD_RGBPACK(204, 0, 0)
285#define LCD_HIST_OVER LCD_RGBPACK(204, 0, 0)
286#define LCD_HIST_HI LCD_RGBPACK(255, 204, 0)
287#define LCD_HIST_OK LCD_RGBPACK(51, 153, 0)
288#else /* HAVE_LCD_COLOR */
289#define LCD_BATT_OK LCD_BLACK
290#define LCD_BATT_LO LCD_DARKGRAY
291#define LCD_DISK_OK LCD_BLACK
292#define LCD_DISK_LO LCD_DARKGRAY
293#define LCD_HIST_OVER LCD_BLACK
294#define LCD_HIST_OK LCD_DARKGRAY
295#define LCD_BAL LCD_DARKGRAY
296#endif /* HAVE_LCD_COLOR */
297#else /* LCD_DEPTH > 1 */
298#define LCD_HIST_OVER LCD_DEFAULT_FG
299#define LCD_HIST_OK LCD_DEFAULT_FG
300#define LCD_BAL LCD_DEFAULT_FG
301#endif /* LCD_DEPTH > 1 */
302#endif /* HAVE_RECORDING_HISTOGRAM */
272 303
273static void set_gain(void) 304static void set_gain(void)
274{ 305{
@@ -317,6 +348,13 @@ static bool read_peak_levels(int *peak_l, int *peak_r, int *balance)
317 *balance += balance_mem[i]; 348 *balance += balance_mem[i];
318 *balance = *balance / BAL_MEM_SIZE; 349 *balance = *balance / BAL_MEM_SIZE;
319 350
351#ifdef HAVE_RECORDING_HISTOGRAM
352 if (*peak_l > hist_l)
353 hist_l = *peak_l;
354 if (*peak_r > hist_r)
355 hist_r = *peak_r;
356#endif
357
320 return true; 358 return true;
321} 359}
322 360
@@ -1015,7 +1053,6 @@ bool recording_screen(bool no_source)
1015#endif 1053#endif
1016#ifdef HAVE_AGC 1054#ifdef HAVE_AGC
1017 bool peak_read = false; 1055 bool peak_read = false;
1018 bool peak_valid = false;
1019 int peak_l, peak_r; 1056 int peak_l, peak_r;
1020 int balance = 0; 1057 int balance = 0;
1021#endif 1058#endif
@@ -1025,9 +1062,21 @@ bool recording_screen(bool no_source)
1025 int pm_h[NB_SCREENS]; /* peakmeter height */ 1062 int pm_h[NB_SCREENS]; /* peakmeter height */
1026 int trig_ypos[NB_SCREENS]; /* trigger bar y pos */ 1063 int trig_ypos[NB_SCREENS]; /* trigger bar y pos */
1027 int trig_width[NB_SCREENS]; /* trigger bar width */ 1064 int trig_width[NB_SCREENS]; /* trigger bar width */
1065 int top_height_req[NB_SCREENS]; /* required height for top half */
1028 bool compact_view[NB_SCREENS]; /* tweak layout tiny screens / big fonts */ 1066 bool compact_view[NB_SCREENS]; /* tweak layout tiny screens / big fonts */
1029
1030 struct gui_synclist lists; /* the list in the bottom vp */ 1067 struct gui_synclist lists; /* the list in the bottom vp */
1068#if defined(HAVE_AGC) || defined(HAVE_RECORDING_HISTOGRAM)
1069 bool peak_valid = false;
1070#endif
1071#if defined(HAVE_RECORDING_HISTOGRAM)
1072 unsigned short hist_pos_y = 0;
1073 unsigned short hist_size_h = 0;
1074 int history_pos = 0;
1075 short hist_time_interval = 1; /* 1, 2, 4, 8 */
1076 unsigned char history_l[HIST_W];
1077 unsigned char history_r[HIST_W];
1078 const char hist_level_marks[6] = { 29, 26, 23, 17, 9, 2};
1079#endif
1031#ifdef HAVE_FMRADIO_REC 1080#ifdef HAVE_FMRADIO_REC
1032 int prev_rec_source = global_settings.rec_source; /* detect source change */ 1081 int prev_rec_source = global_settings.rec_source; /* detect source change */
1033#endif 1082#endif
@@ -1084,49 +1133,6 @@ bool recording_screen(bool no_source)
1084 rec_init_filename(); 1133 rec_init_filename();
1085#endif 1134#endif
1086 1135
1087 /* viewport init and calculations that only needs to be done once */
1088 FOR_NB_SCREENS(i)
1089 {
1090 struct viewport *v;
1091 /* top vp, 4 lines, force sys font if total screen < 6 lines
1092 NOTE: one could limit the list to 1 line and get away with 5 lines */
1093 v = &vp_top[i];
1094 viewport_set_defaults(v, i);
1095 if (viewport_get_nb_lines(v) < 4)
1096 {
1097 /* compact needs 4 lines total */
1098 v->font = FONT_SYSFIXED;
1099 compact_view[i] = false;
1100 }
1101 else
1102 {
1103 if (viewport_get_nb_lines(v) < (4+2)) /*top=4,list=2*/
1104 compact_view[i] = true;
1105 else
1106 compact_view[i] = false;
1107 }
1108 vp_list[i] = *v; /* get a copy now so it can be sized more easily */
1109 v->height = (font_get(v->font)->height)*(compact_view[i] ? 3 : 4);
1110
1111 /* list section, rest of the screen */
1112 vp_list[i].y += vp_top[i].height;
1113 vp_list[i].height -= vp_top[i].height;
1114 screens[i].set_viewport(&vp_top[i]); /* req for next calls */
1115
1116 screens[i].getstringsize("W", &w, &h);
1117 pm_y[i] = font_get(vp_top[i].font)->height * 2;
1118 trig_ypos[i] = font_get(vp_top[i].font)->height * 3;
1119 if(compact_view[i])
1120 trig_ypos[i] -= (font_get(vp_top[i].font)->height)/2;
1121 }
1122
1123 /* init the bottom list */
1124 gui_synclist_init(&lists, reclist_get_name, NULL, false, 1, vp_list);
1125 gui_synclist_set_title(&lists, NULL, Icon_NOICON);
1126
1127
1128 send_event(GUI_EVENT_ACTIONUPDATE, (void*)1); /* force a redraw */
1129
1130 /* start of the loop: we stay in this loop until user quits recscreen */ 1136 /* start of the loop: we stay in this loop until user quits recscreen */
1131 while(done <= 0) 1137 while(done <= 0)
1132 { 1138 {
@@ -1143,6 +1149,65 @@ bool recording_screen(bool no_source)
1143 prev_rec_source = global_settings.rec_source; 1149 prev_rec_source = global_settings.rec_source;
1144#endif 1150#endif
1145 1151
1152 /* viewport init and calculations that only needs to be done once */
1153 FOR_NB_SCREENS(i)
1154 {
1155 struct viewport *v;
1156 /* top vp, 4 lines, force sys font if total screen < 6 lines
1157 NOTE: one could limit the list to 1 line and get away with 5 lines */
1158 top_height_req[i] = 4;
1159#if defined(HAVE_RECORDING_HISTOGRAM)
1160 if((global_settings.rec_histogram_interval) && (!i))
1161 top_height_req[i] += 1; /* use one line for histogram */
1162 hist_time_interval = 1 << global_settings.rec_histogram_interval;
1163#endif
1164 v = &vp_top[i];
1165 viewport_set_defaults(v, i);
1166 if (viewport_get_nb_lines(v) < top_height_req[i])
1167 {
1168 /* compact needs 4 lines total */
1169 v->font = FONT_SYSFIXED;
1170 compact_view[i] = false;
1171 }
1172 else
1173 {
1174 /*top=4,list=2*/
1175 if (viewport_get_nb_lines(v) < (top_height_req[i]+2))
1176 compact_view[i] = true;
1177 else
1178 compact_view[i] = false;
1179 }
1180 vp_list[i] = *v; /* get a copy now so it can be sized more easily */
1181 v->height = (font_get(v->font)->height)*(compact_view[i] ? 3 :
1182 top_height_req[i]);
1183
1184 /* list section, rest of the screen */
1185 vp_list[i].y += vp_top[i].height;
1186 vp_list[i].height -= vp_top[i].height;
1187 screens[i].set_viewport(&vp_top[i]); /* req for next calls */
1188
1189 screens[i].getstringsize("W", &w, &h);
1190 pm_y[i] = font_get(vp_top[i].font)->height * 2;
1191 trig_ypos[i] = font_get(vp_top[i].font)->height * 3;
1192 if(compact_view[i])
1193 trig_ypos[i] -= (font_get(vp_top[i].font)->height)/2;
1194 }
1195
1196 /* init the bottom list */
1197 gui_synclist_init(&lists, reclist_get_name, NULL, false, 1, vp_list);
1198 gui_synclist_set_title(&lists, NULL, Icon_NOICON);
1199
1200 send_event(GUI_EVENT_ACTIONUPDATE, (void*)1); /* force a redraw */
1201
1202#if defined(HAVE_RECORDING_HISTOGRAM)
1203 history_pos = 0;
1204 hist_pos_y = (compact_view[0] ? 3 : 4) * (font_get(vp_top[0].font)->height)
1205 + 1;
1206 hist_size_h = font_get(vp_top[0].font)->height - 2;
1207 memset(history_l, 0, sizeof(unsigned char)*HIST_W);
1208 memset(history_r, 0, sizeof(unsigned char)*HIST_W);
1209#endif
1210
1146 FOR_NB_SCREENS(i) 1211 FOR_NB_SCREENS(i)
1147 { 1212 {
1148 pm_x[i] = 0; 1213 pm_x[i] = 0;
@@ -1673,12 +1738,11 @@ bool recording_screen(bool no_source)
1673 unsigned int dseconds, dhours, dminutes; 1738 unsigned int dseconds, dhours, dminutes;
1674 unsigned long num_recorded_bytes, dsize, dmb; 1739 unsigned long num_recorded_bytes, dsize, dmb;
1675 1740
1676
1677 FOR_NB_SCREENS(i) 1741 FOR_NB_SCREENS(i)
1678 { 1742 {
1679 screens[i].set_viewport(&vp_top[i]); 1743 screens[i].set_viewport(&vp_top[i]);
1680 screens[i].clear_viewport(); 1744 screens[i].clear_viewport();
1681 } 1745 }
1682 update_countdown = 5; 1746 update_countdown = 5;
1683 last_seconds = seconds; 1747 last_seconds = seconds;
1684 1748
@@ -1796,6 +1860,83 @@ bool recording_screen(bool no_source)
1796 } 1860 }
1797 } 1861 }
1798 1862
1863#ifdef HAVE_RECORDING_HISTOGRAM
1864 if(global_settings.rec_histogram_interval)
1865 {
1866 if (peak_valid && !(hist_time % hist_time_interval) && hist_l)
1867 {
1868 history_l[history_pos] = hist_l * hist_size_h / 32767;
1869 history_r[history_pos] = hist_r * hist_size_h / 32767;
1870 history_pos = (history_pos + 1) % HIST_W;
1871 history_l[history_pos] = history_r[history_pos] = 0;
1872 history_l[(history_pos + 1) % HIST_W] = 0;
1873 history_r[(history_pos + 1) % HIST_W] = 0;
1874 hist_l = 0;
1875 hist_r = 0;
1876 }
1877 lcd_set_drawmode(DRMODE_SOLID);
1878 lcd_drawrect(0, hist_pos_y - 1,
1879 HIST_W + 2, hist_size_h + 1);
1880 lcd_drawrect(HIST_W + 6, hist_pos_y - 1,
1881 HIST_W + 2, hist_size_h + 1);
1882 lcd_set_drawmode(DRMODE_FG);
1883#ifdef HAVE_LCD_COLOR
1884 for (i = 0; i < HIST_W; i++)
1885 {
1886 if (history_l[i])
1887 {
1888 if (history_l[i] == hist_size_h)
1889 lcd_set_foreground(LCD_HIST_OVER);
1890 else if (history_l[i] > hist_level_marks[1])
1891 lcd_set_foreground(LCD_HIST_HI);
1892 else
1893 lcd_set_foreground(LCD_HIST_OK);
1894 lcd_vline(1 + i, HIST_Y-1, HIST_Y - history_l[i]);
1895 }
1896 if (history_r[i])
1897 {
1898 if (history_r[i] == hist_size_h)
1899 lcd_set_foreground(LCD_HIST_OVER);
1900 else if (history_r[i] > hist_level_marks[1])
1901 lcd_set_foreground(LCD_HIST_HI);
1902 else
1903 lcd_set_foreground(LCD_HIST_OK);
1904 lcd_vline(HIST_W+7 + i, HIST_Y-1, HIST_Y - history_r[i]);
1905 }
1906 }
1907#else
1908 for (i = 0; i < HIST_W; i++)
1909 {
1910 if (history_l[i])
1911 {
1912 if (history_l[i] == hist_size_h)
1913 lcd_set_foreground(LCD_HIST_OVER);
1914 else
1915 lcd_set_foreground(LCD_HIST_OK);
1916 lcd_vline(1 + i, HIST_Y-1, HIST_Y - history_l[i]);
1917 }
1918 if (history_r[i])
1919 {
1920 if (history_r[i] == hist_size_h)
1921 lcd_set_foreground(LCD_HIST_OVER);
1922 else
1923 lcd_set_foreground(LCD_HIST_OK);
1924 lcd_vline(HIST_W+7 + i, HIST_Y-1, HIST_Y - history_r[i]);
1925 }
1926 }
1927#endif /* HAVE_LCD_COLOR */
1928 lcd_set_foreground(
1929#ifdef HAVE_LCD_COLOR
1930 global_settings.fg_color);
1931#else
1932 LCD_DEFAULT_FG);
1933#endif
1934 for (i = 0; i < 6; i++)
1935 lcd_hline(HIST_W + 3, HIST_W + 4,
1936 HIST_Y - hist_level_marks[i]);
1937 }
1938#endif /* HAVE_RECORDING_HISTOGRAM */
1939
1799#ifdef HAVE_AGC 1940#ifdef HAVE_AGC
1800 hist_time++; 1941 hist_time++;
1801#endif 1942#endif
@@ -1922,7 +2063,6 @@ rec_abort:
1922 2063
1923 FOR_NB_SCREENS(i) 2064 FOR_NB_SCREENS(i)
1924 screens[i].setfont(FONT_UI); 2065 screens[i].setfont(FONT_UI);
1925
1926 2066
1927 /* if the directory was created or recording happened, make sure the 2067 /* if the directory was created or recording happened, make sure the
1928 browser is updated */ 2068 browser is updated */