1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 by Linus Nielsen Feltzing
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
30 #include "powermgmt.h"
35 #if CONFIG_CODEC == SWCODEC
38 #include "enc_config.h"
39 #if defined(HAVE_SPDIF_IN) || defined(HAVE_SPDIF_OUT)
42 #endif /* CONFIG_CODEC == SWCODEC */
43 #include "recording.h"
44 #include "mp3_playback.h"
54 #include "peakmeter.h"
55 #include "statusbar.h"
57 #include "sound_menu.h"
58 #include "timefuncs.h"
69 #include "screen_access.h"
72 #include "sound_menu.h"
77 /* This array holds the record timer interval lengths, in seconds */
78 static const unsigned long rec_timer_seconds
[] =
92 10L*60*60, /* 10:00 */
93 12L*60*60, /* 12:00 */
94 18L*60*60, /* 18:00 */
98 static unsigned int rec_timesplit_seconds(void)
100 return rec_timer_seconds
[global_settings
.rec_timesplit
];
103 /* This array holds the record size interval lengths, in bytes */
104 static const unsigned long rec_size_bytes
[] =
107 5*1024*1024, /* 5MB */
108 10*1024*1024, /* 10MB */
109 15*1024*1024, /* 15MB */
110 32*1024*1024, /* 32MB */
111 64*1024*1024, /* 64MB */
112 75*1024*1024, /* 75MB */
113 100*1024*1024, /* 100MB */
114 128*1024*1024, /* 128MB */
115 256*1024*1024, /* 256MB */
116 512*1024*1024, /* 512MB */
117 650*1024*1024, /* 650MB */
118 700*1024*1024, /* 700MB */
119 1024*1024*1024, /* 1GB */
120 1536*1024*1024, /* 1.5GB */
121 1792*1024*1024, /* 1.75GB */
124 static unsigned long rec_sizesplit_bytes(void)
126 return rec_size_bytes
[global_settings
.rec_sizesplit
];
129 void settings_apply_trigger(void)
131 int start_thres
, stop_thres
;
132 if (global_settings
.peak_meter_dbfs
)
134 start_thres
= global_settings
.rec_start_thres_db
- 1;
135 stop_thres
= global_settings
.rec_stop_thres_db
- 1;
139 start_thres
= global_settings
.rec_start_thres_linear
;
140 stop_thres
= global_settings
.rec_stop_thres_linear
;
143 peak_meter_define_trigger(
145 global_settings
.rec_start_duration
*HZ
,
146 MIN(global_settings
.rec_start_duration
*HZ
/ 2, 2*HZ
),
148 global_settings
.rec_stop_postrec
*HZ
,
149 global_settings
.rec_stop_gap
*HZ
152 /* recording screen status flags */
153 enum rec_status_flags
155 RCSTAT_IN_RECSCREEN
= 0x00000001,
156 RCSTAT_BEEN_IN_USB_MODE
= 0x00000002,
157 RCSTAT_CREATED_DIRECTORY
= 0x00000004,
158 RCSTAT_HAVE_RECORDED
= 0x00000008,
161 static int rec_status
= 0;
163 bool in_recording_screen(void)
165 return (rec_status
& RCSTAT_IN_RECSCREEN
) != 0;
168 #if CONFIG_KEYPAD == RECORDER_PAD
169 static bool f2_rec_screen(void);
170 static bool f3_rec_screen(void);
173 #define MAX_FILE_SIZE 0x7F800000 /* 2 GB - 4 MB */
175 #ifndef HAVE_REMOTE_LCD
176 static const int screen_update
= NB_SCREENS
;
178 static int screen_update
= NB_SCREENS
;
179 static bool remote_display_on
= true;
182 /* as we have the ability to disable the remote, we need an alternative loop */
183 #define FOR_NB_ACTIVE_SCREENS(i) for(i = 0; i < screen_update; i++)
185 static bool update_list
= false; /* (GIU) list needs updating */
187 /** File name creation **/
189 /* current file number to assist in creating unique numbered filenames
190 without actually having to create the file on disk */
191 static int file_number
= -1;
192 #endif /* CONFIG_RTC */
194 #if CONFIG_CODEC == SWCODEC
196 #define REC_FILE_ENDING(rec_format) \
197 (audio_formats[rec_format_afmt[rec_format]].ext_list)
199 #else /* CONFIG_CODEC != SWCODEC */
201 /* default record file extension for HWCODEC */
202 #define REC_FILE_ENDING(rec_format) \
203 (audio_formats[AFMT_MPA_L3].ext_list)
205 #endif /* CONFIG_CODEC == SWCODEC */
207 /* path for current file */
208 static char path_buffer
[MAX_PATH
];
210 /** Automatic Gain Control (AGC) **/
213 * peak_time is incremented every 0.2s, every 2nd run of record screen loop.
214 * hist_time is incremented every 0.5s, display update.
215 * peak_time is the counter of the peak hold read and agc process,
216 * overflow every 13 years 8-)
218 static long peak_time
= 0;
219 static long hist_time
= 0;
221 static short peak_valid_mem
[4];
222 #define BAL_MEM_SIZE 24
223 static short balance_mem
[BAL_MEM_SIZE
];
225 /* Automatic Gain Control */
226 #define AGC_MODE_SIZE 5
227 #define AGC_SAFETY_MODE 0
229 static const char* agc_preset_str
[] =
230 { "Off", "S", "L", "D", "M", "V" };
237 #define AGC_CLIP 32766
238 #define AGC_PEAK 29883 /* fast gain reduction threshold -0.8dB */
239 #define AGC_HIGH 27254 /* accelerated gain reduction threshold -1.6dB */
240 #define AGC_IMG 823 /* threshold for balance control -32dB */
241 /* autogain high level thresholds (-3dB, -7dB, -4dB, -5dB, -5dB) */
242 static const short agc_th_hi
[AGC_MODE_SIZE
] =
243 { 23197, 14637, 21156, 18428, 18426 };
244 /* autogain low level thresholds (-14dB, -11dB, -6dB, -7dB, -8dB) */
245 static const short agc_th_lo
[AGC_MODE_SIZE
] =
246 { 6538, 9235, 16422, 14636, 13045 };
247 /* autogain threshold times [1/5s] or [200ms] */
248 static const short agc_tdrop
[AGC_MODE_SIZE
] =
249 { 900, 225, 150, 60, 8 };
250 static const short agc_trise
[AGC_MODE_SIZE
] =
251 { 9000, 750, 400, 150, 20 };
252 static const short agc_tbal
[AGC_MODE_SIZE
] =
253 { 4500, 500, 300, 100, 15 };
255 static bool agc_enable
= true;
256 static short agc_preset
;
258 static int agc_left
= 0;
259 static int agc_right
= 0;
260 /* AGC time since high target volume was exceeded */
261 static short agc_droptime
= 0;
262 /* AGC time since volume fallen below low target */
263 static short agc_risetime
= 0;
264 /* AGC balance time exceeding +/- 0.7dB */
265 static short agc_baltime
= 0;
266 /* AGC maximum gain */
267 static short agc_maxgain
;
268 #endif /* HAVE_AGC */
270 static void set_gain(void)
272 if(global_settings
.rec_source
== AUDIO_SRC_MIC
)
274 audio_set_recording_gain(global_settings
.rec_mic_gain
,
279 /* AUDIO_SRC_LINEIN, AUDIO_SRC_FMRADIO, AUDIO_SRC_SPDIF */
280 audio_set_recording_gain(global_settings
.rec_left_gain
,
281 global_settings
.rec_right_gain
,
284 /* reset the clipping indicators */
285 peak_meter_set_clip_hold(global_settings
.peak_meter_clip_hold
);
290 /* Read peak meter values & calculate balance.
291 * Returns validity of peak values.
292 * Used for automatic gain control and history diagram.
294 static bool read_peak_levels(int *peak_l
, int *peak_r
, int *balance
)
296 peak_meter_get_peakhold(peak_l
, peak_r
);
297 peak_valid_mem
[peak_time
% 3] = *peak_l
;
298 if (((peak_valid_mem
[0] == peak_valid_mem
[1]) &&
299 (peak_valid_mem
[1] == peak_valid_mem
[2])) &&
300 ((*peak_l
< 32767) || ata_disk_is_active()))
303 if (*peak_r
> *peak_l
)
304 balance_mem
[peak_time
% BAL_MEM_SIZE
] = (*peak_l
?
305 MIN((10000 * *peak_r
) / *peak_l
- 10000, 15118) : 15118);
307 balance_mem
[peak_time
% BAL_MEM_SIZE
] = (*peak_r
?
308 MAX(10000 - (10000 * *peak_l
) / *peak_r
, -15118) : -15118);
311 for (i
= 0; i
< BAL_MEM_SIZE
; i
++)
312 *balance
+= balance_mem
[i
];
313 *balance
= *balance
/ BAL_MEM_SIZE
;
318 /* AGC helper function to check if maximum gain is reached */
319 static bool agc_gain_is_max(bool left
, bool right
)
321 /* range -128...+108 [0.5dB] */
322 short gain_current_l
;
323 short gain_current_r
;
328 switch (global_settings
.rec_source
)
330 HAVE_LINE_REC_(case AUDIO_SRC_LINEIN
:)
331 HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO
:)
332 gain_current_l
= global_settings
.rec_left_gain
;
333 gain_current_r
= global_settings
.rec_right_gain
;
337 gain_current_l
= global_settings
.rec_mic_gain
;
338 gain_current_r
= global_settings
.rec_mic_gain
;
341 return ((left
&& (gain_current_l
>= agc_maxgain
)) ||
342 (right
&& (gain_current_r
>= agc_maxgain
)));
345 static void change_recording_gain(bool increment
, bool left
, bool right
)
347 int factor
= (increment
? 1 : -1);
349 switch (global_settings
.rec_source
)
351 HAVE_LINE_REC_(case AUDIO_SRC_LINEIN
:)
352 HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO
:)
353 if (left
) global_settings
.rec_left_gain
+= factor
;
354 if (right
) global_settings
.rec_right_gain
+= factor
;
357 global_settings
.rec_mic_gain
+= factor
;
362 * Handle automatic gain control (AGC).
363 * Change recording gain if peak_x levels are above or below
364 * target volume for specified timeouts.
366 static void auto_gain_control(int *peak_l
, int *peak_r
, int *balance
)
372 if (*peak_l
> agc_left
)
375 agc_left
-= (agc_left
- *peak_l
+ 3) >> 2;
376 if (*peak_r
> agc_right
)
379 agc_right
-= (agc_right
- *peak_r
+ 3) >> 2;
380 agc_mono
= (agc_left
+ agc_right
) / 2;
382 agc_mode
= abs(agc_preset
) - 1;
388 if (agc_mode
!= AGC_SAFETY_MODE
) {
389 /* Automatic balance control - only if not in safety mode */
390 if ((agc_left
> AGC_IMG
) && (agc_right
> AGC_IMG
))
395 agc_baltime
-= !(peak_time
% 4); /* 0.47 - 0.75dB */
396 else if (*balance
> -4125)
397 agc_baltime
--; /* 0.75 - 3.00dB */
398 else if (*balance
> -7579)
399 agc_baltime
-= 2; /* 3.00 - 4.90dB */
401 agc_baltime
-= !(peak_time
% 8); /* 4.90 - inf dB */
403 agc_baltime
-= (peak_time
% 2);
405 else if (*balance
> 556)
408 agc_baltime
+= !(peak_time
% 4);
409 else if (*balance
< 4125)
411 else if (*balance
< 7579)
414 agc_baltime
+= !(peak_time
% 8);
416 agc_baltime
+= (peak_time
% 2);
419 if ((*balance
* agc_baltime
) < 0)
422 agc_baltime
-= peak_time
% 2;
424 agc_baltime
+= peak_time
% 2;
427 increment
= ((agc_risetime
/ 2) > agc_droptime
);
429 if (agc_baltime
< -agc_tbal
[agc_mode
])
431 if (!increment
|| !agc_gain_is_max(!increment
, increment
)) {
432 change_recording_gain(increment
, !increment
, increment
);
437 else if (agc_baltime
> +agc_tbal
[agc_mode
])
439 if (!increment
|| !agc_gain_is_max(increment
, !increment
)) {
440 change_recording_gain(increment
, increment
, !increment
);
446 else if (!(hist_time
% 4))
455 /* Automatic gain control */
456 if ((agc_left
> agc_th_hi
[agc_mode
]) || (agc_right
> agc_th_hi
[agc_mode
]))
458 if ((agc_left
> AGC_CLIP
) || (agc_right
> AGC_CLIP
))
459 agc_droptime
+= agc_tdrop
[agc_mode
] /
460 (global_settings
.rec_agc_cliptime
+ 1);
461 if (agc_left
> AGC_HIGH
) {
464 if (agc_left
> AGC_PEAK
)
467 if (agc_right
> AGC_HIGH
) {
470 if (agc_right
> AGC_PEAK
)
473 if (agc_mono
> agc_th_hi
[agc_mode
])
476 agc_droptime
+= !(peak_time
% 2);
478 if (agc_droptime
>= agc_tdrop
[agc_mode
])
480 change_recording_gain(false, true, true);
485 agc_risetime
= MAX(agc_risetime
- 1, 0);
487 else if (agc_mono
< agc_th_lo
[agc_mode
])
489 if (agc_mono
< (agc_th_lo
[agc_mode
] / 8))
490 agc_risetime
+= !(peak_time
% 5);
491 else if (agc_mono
< (agc_th_lo
[agc_mode
] / 2))
496 if (agc_risetime
>= agc_trise
[agc_mode
]) {
497 if ((agc_mode
!= AGC_SAFETY_MODE
) &&
498 (!agc_gain_is_max(true, true))) {
499 change_recording_gain(true, true, true);
505 agc_droptime
= MAX(agc_droptime
- 1, 0);
507 else if (!(peak_time
% 6)) /* on target level every 1.2 sec */
509 agc_risetime
= MAX(agc_risetime
- 1, 0);
510 agc_droptime
= MAX(agc_droptime
- 1, 0);
513 #endif /* HAVE_AGC */
515 static const char* const fmtstr
[] =
517 "%c%d %s", /* no decimals */
518 "%c%d.%d %s ", /* 1 decimal */
519 "%c%d.%02d %s " /* 2 decimals */
522 static char *fmt_gain(int snd
, int val
, char *str
, int len
)
528 val
= sound_val2phys(snd
, val
);
534 numdec
= sound_numdecimals(snd
);
535 unit
= sound_unit(snd
);
539 i
= val
/ (10*numdec
);
540 d
= val
% (10*numdec
);
541 snprintf(str
, len
, fmtstr
[numdec
], sign
, i
, d
, unit
);
544 snprintf(str
, len
, fmtstr
[numdec
], sign
, val
, unit
);
549 /* the list below must match enum audio_sources in audio.h */
550 static const char* const prestr
[] =
552 HAVE_MIC_IN_([AUDIO_SRC_MIC
] = "R_MIC_",)
553 HAVE_LINE_REC_([AUDIO_SRC_LINEIN
] = "R_LINE_",)
554 HAVE_SPDIF_IN_([AUDIO_SRC_SPDIF
] = "R_SPDIF_",)
555 HAVE_FMRADIO_REC_([AUDIO_SRC_FMRADIO
] = "R_FM_",)
558 char *rec_create_filename(char *buffer
)
561 const char *pref
= "R_";
563 /* Directory existence and writeablility should have already been
564 * verified - do not pass NULL pointers to pcmrec */
566 if((unsigned)global_settings
.rec_source
< AUDIO_NUM_SOURCES
)
568 pref
= prestr
[global_settings
.rec_source
];
571 strcpy(buffer
, global_settings
.rec_directory
);
573 snprintf(ext
, sizeof(ext
), ".%s",
574 REC_FILE_ENDING(global_settings
.rec_format
));
577 return create_numbered_filename(buffer
, buffer
, pref
, ext
, 4,
580 /* We'll wait at least up to the start of the next second so no duplicate
582 return create_datetime_filename(buffer
, buffer
, pref
, ext
, true);
587 /* Hit disk to get a starting filename for the type */
588 static void rec_init_filename(void)
591 rec_create_filename(path_buffer
);
596 int rec_create_directory(void)
599 const char * const folder
= global_settings
.rec_directory
;
601 if (strcmp(folder
, "/") && !dir_exists(folder
))
607 while (action_userabort(HZ
) == false)
609 gui_syncsplash(0, "%s %s",
610 str(LANG_REC_DIR_NOT_WRITABLE
),
611 str(LANG_OFF_ABORT
));
616 rec_status
|= RCSTAT_CREATED_DIRECTORY
;
624 void rec_init_recording_options(struct audio_recording_options
*options
)
626 options
->rec_source
= global_settings
.rec_source
;
627 options
->rec_frequency
= global_settings
.rec_frequency
;
628 options
->rec_channels
= global_settings
.rec_channels
;
629 options
->rec_prerecord_time
= global_settings
.rec_prerecord_time
;
630 #if CONFIG_CODEC == SWCODEC
631 options
->rec_source_flags
= 0;
632 options
->enc_config
.rec_format
= global_settings
.rec_format
;
633 global_to_encoder_config(&options
->enc_config
);
635 options
->rec_quality
= global_settings
.rec_quality
;
636 options
->rec_editable
= global_settings
.rec_editable
;
640 #if CONFIG_CODEC == SWCODEC && !defined (SIMULATOR)
641 void rec_set_source(int source
, unsigned flags
)
643 /* Set audio input source, power up/down devices */
644 audio_set_input_source(source
, flags
);
646 /* Set peakmeters for recording or reset to playback */
647 peak_meter_playback((flags
& SRCF_RECORDING
) == 0);
648 peak_meter_enabled
= true;
650 #endif /* CONFIG_CODEC == SWCODEC && !defined (SIMULATOR) */
652 void rec_set_recording_options(struct audio_recording_options
*options
)
654 #if CONFIG_CODEC != SWCODEC
655 if (global_settings
.rec_prerecord_time
)
657 talk_buffer_steal(); /* will use the mp3 buffer */
659 #else /* == SWCODEC */
660 rec_set_source(options
->rec_source
,
661 options
->rec_source_flags
| SRCF_RECORDING
);
662 #endif /* CONFIG_CODEC != SWCODEC */
664 audio_set_recording_options(options
);
667 void rec_command(enum recording_command cmd
)
671 case RECORDING_CMD_STOP_SHUTDOWN
:
672 pm_activate_clipcount(false);
673 audio_stop_recording();
674 #if CONFIG_CODEC == SWCODEC
675 audio_close_recording();
679 case RECORDING_CMD_STOP
:
680 pm_activate_clipcount(false);
681 audio_stop_recording();
683 case RECORDING_CMD_START
:
684 /* steal mp3 buffer, create unique filename and start recording */
685 pm_reset_clipcount();
686 pm_activate_clipcount(true);
687 #if CONFIG_CODEC != SWCODEC
688 talk_buffer_steal(); /* we use the mp3 buffer */
690 audio_record(rec_create_filename(path_buffer
));
692 case RECORDING_CMD_START_NEWFILE
:
693 /* create unique filename and start recording*/
694 pm_reset_clipcount();
695 pm_activate_clipcount(true); /* just to be sure */
696 audio_new_file(rec_create_filename(path_buffer
));
698 case RECORDING_CMD_PAUSE
:
699 pm_activate_clipcount(false);
700 audio_pause_recording();
702 case RECORDING_CMD_RESUME
:
703 pm_activate_clipcount(true);
704 audio_resume_recording();
710 /* used in trigger_listerner and recording_screen */
711 static unsigned int last_seconds
= 0;
714 * Callback function so that the peak meter code can send an event
715 * to this application. This function can be passed to
716 * peak_meter_set_trigger_listener in order to activate the trigger.
718 static void trigger_listener(int trigger_status
)
720 switch (trigger_status
)
723 if(!(audio_status() & AUDIO_STATUS_RECORD
))
725 rec_status
|= RCSTAT_HAVE_RECORDED
;
726 rec_command(RECORDING_CMD_START
);
727 #if CONFIG_CODEC != SWCODEC
728 /* give control to mpeg thread so that it can start
730 yield(); yield(); yield();
734 /* if we're already recording this is a retrigger */
737 if((audio_status() & AUDIO_STATUS_PAUSE
) &&
738 (global_settings
.rec_trigger_type
== TRIG_TYPE_PAUSE
))
740 rec_command(RECORDING_CMD_RESUME
);
742 /* New file on trig start*/
743 else if (global_settings
.rec_trigger_type
!= TRIG_TYPE_NEW_FILE
)
745 rec_command(RECORDING_CMD_START_NEWFILE
);
746 /* tell recording_screen to reset the time */
752 /* A _change_ to TRIG_READY means the current recording has stopped */
754 if(audio_status() & AUDIO_STATUS_RECORD
)
756 switch(global_settings
.rec_trigger_type
)
758 case TRIG_TYPE_STOP
: /* Stop */
759 rec_command(RECORDING_CMD_STOP
);
762 case TRIG_TYPE_PAUSE
: /* Pause */
763 rec_command(RECORDING_CMD_PAUSE
);
766 case TRIG_TYPE_NEW_FILE
: /* New file on trig stop*/
767 rec_command(RECORDING_CMD_START_NEWFILE
);
768 /* tell recording_screen to reset the time */
772 case 3: /* Stop and shutdown */
773 rec_command(RECORDING_CMD_STOP_SHUTDOWN
);
777 if (global_settings
.rec_trigger_mode
!= TRIG_MODE_REARM
)
779 peak_meter_set_trigger_listener(NULL
);
780 peak_meter_trigger(false);
787 /* Stuff for drawing the screen */
789 enum rec_list_items_stereo
{
805 enum rec_list_items_mono
{
810 ITEM_AGC_MAXDB_M
= 5,
819 static int listid_to_enum
[ITEM_COUNT
];
821 static char * reclist_get_name(int selected_item
, void * data
,
822 char * buffer
, size_t buffer_len
)
828 data
= data
; /* not used */
829 if(selected_item
>= ITEM_COUNT
)
832 switch (listid_to_enum
[selected_item
])
835 snprintf(buffer
, buffer_len
, "%s: %s", str(LANG_VOLUME
),
836 fmt_gain(SOUND_VOLUME
,
837 global_settings
.volume
,
838 buf2
, sizeof(buf2
)));
841 if(global_settings
.rec_source
== AUDIO_SRC_MIC
)
843 /* Draw MIC recording gain */
844 snprintf(buffer
, buffer_len
, "%s: %s", str(LANG_GAIN
),
845 fmt_gain(SOUND_MIC_GAIN
,
846 global_settings
.rec_mic_gain
,
847 buf2
, sizeof(buf2
)));
851 int avg_gain
= (global_settings
.rec_left_gain
+
852 global_settings
.rec_right_gain
) / 2;
853 snprintf(buffer
, buffer_len
, "%s: %s", str(LANG_GAIN
),
854 fmt_gain(SOUND_LEFT_GAIN
,
856 buf2
, sizeof(buf2
)));
860 snprintf(buffer
, buffer_len
, "%s: %s",
862 fmt_gain(SOUND_LEFT_GAIN
,
863 global_settings
.rec_left_gain
,
864 buf2
, sizeof(buf2
)));
867 snprintf(buffer
, buffer_len
, "%s: %s",
868 str(LANG_GAIN_RIGHT
),
869 fmt_gain(SOUND_RIGHT_GAIN
,
870 global_settings
.rec_right_gain
,
871 buf2
, sizeof(buf2
)));
875 snprintf(buffer
, buffer_len
, "%s: %s",
876 str(LANG_RECORDING_AGC_PRESET
),
877 agc_preset_str
[agc_preset
]);
881 snprintf(buffer
, buffer_len
, "%s: %s",
882 str(LANG_RECORDING_AGC_MAXGAIN
),
883 fmt_gain(SOUND_LEFT_GAIN
,
884 agc_maxgain
, buf2
, sizeof(buf2
)));
885 else if (global_settings
.rec_source
== AUDIO_SRC_MIC
)
886 snprintf(buffer
, buffer_len
, "%s: %s (%s)",
887 str(LANG_RECORDING_AGC_MAXGAIN
),
888 fmt_gain(SOUND_MIC_GAIN
,
889 agc_maxgain
, buf2
, sizeof(buf2
)),
890 fmt_gain(SOUND_MIC_GAIN
,
891 agc_maxgain
- global_settings
.rec_mic_gain
,
892 buf3
, sizeof(buf3
)));
894 snprintf(buffer
, buffer_len
, "%s: %s (%s)",
895 str(LANG_RECORDING_AGC_MAXGAIN
),
896 fmt_gain(SOUND_LEFT_GAIN
,
897 agc_maxgain
, buf2
, sizeof(buf2
)),
898 fmt_gain(SOUND_LEFT_GAIN
,
900 (global_settings
.rec_left_gain
+
901 global_settings
.rec_right_gain
)/2,
902 buf3
, sizeof(buf3
)));
907 if(audio_status() & AUDIO_STATUS_RECORD
)
909 size_t tot_len
= strlen(path_buffer
) +
910 strlen(str(LANG_RECORDING_FILENAME
)) + 1;
911 if(tot_len
> buffer_len
)
913 snprintf(buffer
, buffer_len
, "%s %s",
914 str(LANG_RECORDING_FILENAME
),
915 path_buffer
+ tot_len
- buffer_len
);
919 snprintf(buffer
, buffer_len
, "%s %s",
920 str(LANG_RECORDING_FILENAME
), path_buffer
);
925 strncpy(buffer
, str(LANG_RECORDING_FILENAME
), buffer_len
);
936 bool recording_start_automatic
= false;
938 bool recording_screen(bool no_source
)
941 int done
= -1; /* negative to re-init, positive to quit, zero to run */
942 char buf
[32]; /* for preparing strings */
943 char buf2
[32]; /* for preparing strings */
944 int w
, h
; /* character width/height */
945 int update_countdown
= 1; /* refresh counter */
946 unsigned int seconds
;
948 int audio_stat
= 0; /* status of the audio system */
949 int last_audio_stat
= -1; /* previous status so we can act on changes */
950 struct viewport vp_list
[NB_SCREENS
], vp_top
[NB_SCREENS
]; /* the viewports */
952 #if CONFIG_CODEC == SWCODEC
953 int warning_counter
= 0;
954 #define WARNING_PERIOD 7
957 #ifdef HAVE_FMRADIO_REC
958 /* Radio is left on if:
959 * 1) Is was on at the start and the initial source is FM Radio
960 * 2) 1) and the source was never changed to something else
962 int radio_status
= (global_settings
.rec_source
!= AUDIO_SRC_FMRADIO
) ?
963 FMRADIO_OFF
: get_radio_status();
965 #if (CONFIG_LED == LED_REAL)
966 bool led_state
= false;
967 int led_countdown
= 2;
970 bool peak_read
= false;
971 bool peak_valid
= false;
976 int pm_x
[NB_SCREENS
]; /* peakmeter (and trigger bar) x pos */
977 int pm_y
[NB_SCREENS
]; /* peakmeter y pos */
978 int pm_h
[NB_SCREENS
]; /* peakmeter height */
979 int trig_ypos
[NB_SCREENS
]; /* trigger bar y pos */
980 int trig_width
[NB_SCREENS
]; /* trigger bar width */
981 bool compact_view
[NB_SCREENS
]; /* tweak layout tiny screens / big fonts */
983 struct gui_synclist lists
; /* the list in the bottom vp */
984 #ifdef HAVE_FMRADIO_REC
985 int prev_rec_source
= global_settings
.rec_source
; /* detect source change */
989 bool statusbar
= global_settings
.statusbar
;
990 global_status
.statusbar_forced
= statusbar
?0:1;
991 global_settings
.statusbar
= true;
992 gui_syncstatusbar_draw(&statusbars
,true);
995 static const unsigned char *byte_units
[] = {
1002 struct audio_recording_options rec_options
;
1003 rec_status
= RCSTAT_IN_RECSCREEN
;
1005 #if (CONFIG_LED == LED_REAL) && !defined(SIMULATOR)
1006 ata_set_led_enabled(false);
1009 #if CONFIG_CODEC == SWCODEC
1010 /* recording_menu gets messed up: so prevent manus talking */
1012 /* audio_init_recording stops anything playing when it takes the audio
1015 /* Yes, we use the D/A for monitoring */
1016 peak_meter_enabled
= true;
1017 peak_meter_playback(true);
1021 peak_meter_get_peakhold(&peak_l
, &peak_r
);
1024 pm_reset_clipcount();
1025 pm_activate_clipcount(false);
1026 settings_apply_trigger();
1029 agc_preset_str
[0] = str(LANG_OFF
);
1030 agc_preset_str
[1] = str(LANG_AGC_SAFETY
);
1031 agc_preset_str
[2] = str(LANG_AGC_LIVE
);
1032 agc_preset_str
[3] = str(LANG_AGC_DJSET
);
1033 agc_preset_str
[4] = str(LANG_AGC_MEDIUM
);
1034 agc_preset_str
[5] = str(LANG_AGC_VOICE
);
1035 #endif /* HAVE_AGC */
1037 #if CONFIG_CODEC == SWCODEC
1038 audio_close_recording();
1040 audio_init_recording(0);
1041 sound_set_volume(global_settings
.volume
);
1044 /* Create new filename for recording start */
1045 rec_init_filename();
1048 /* viewport init and calculations that only needs to be done once */
1052 /* top vp, 4 lines, force sys font if total screen < 6 lines
1053 NOTE: one could limit the list to 1 line and get away with 5 lines */
1055 viewport_set_defaults(v
, i
); /*already takes care of statusbar*/
1056 if (viewport_get_nb_lines(v
) < 4)
1058 /* compact needs 4 lines total */
1059 v
->font
= FONT_SYSFIXED
;
1060 compact_view
[i
] = false;
1064 if (viewport_get_nb_lines(v
) < (4+2)) /*top=4,list=2*/
1065 compact_view
[i
] = true;
1067 compact_view
[i
] = false;
1069 v
->height
= (font_get(v
->font
)->height
)*(compact_view
[i
] ? 3 : 4);
1071 /* list section, rest of the screen */
1073 viewport_set_defaults(v
, i
);
1074 v
->font
= vp_top
[i
].font
;
1075 v
->y
= vp_top
[i
].y
+ vp_top
[i
].height
;
1076 v
->height
= screens
[i
].lcdheight
- v
->y
; /* the rest */
1077 screens
[i
].set_viewport(&vp_top
[i
]); /* req for next calls */
1079 screens
[i
].getstringsize("W", &w
, &h
);
1080 pm_y
[i
] = font_get(vp_top
[i
].font
)->height
* 2;
1081 trig_ypos
[i
] = font_get(vp_top
[i
].font
)->height
* 3;
1083 trig_ypos
[i
] -= (font_get(vp_top
[i
].font
)->height
)/2;
1086 /* init the bottom list */
1087 gui_synclist_init(&lists
, reclist_get_name
, NULL
, false, 1, vp_list
);
1088 gui_synclist_set_title(&lists
, NULL
, Icon_NOICON
);
1090 /* start of the loop: we stay in this loop until user quits recscreen */
1095 /* request to re-init stuff, done after settings screen */
1097 #ifdef HAVE_FMRADIO_REC
1098 /* If input changes away from FM Radio,
1099 radio will remain off when recording screen closes. */
1100 if (global_settings
.rec_source
!= prev_rec_source
1101 && prev_rec_source
== AUDIO_SRC_FMRADIO
)
1102 radio_status
= FMRADIO_OFF
;
1103 prev_rec_source
= global_settings
.rec_source
;
1109 if(global_settings
.peak_meter_clipcounter
)
1112 screens
[i
].getstringsize(str(LANG_PM_CLIPCOUNT
),
1113 &clipwidth
, &h
); /* h is same */
1114 pm_x
[i
] = clipwidth
+1;
1116 if(global_settings
.rec_trigger_mode
== TRIG_MODE_OFF
)
1117 pm_h
[i
] = font_get(vp_top
[i
].font
)->height
* 2;
1119 pm_h
[i
] = font_get(vp_top
[i
].font
)->height
;
1122 trig_width
[i
] = vp_top
[i
].width
- pm_x
[i
];
1123 screens
[i
].clear_display();
1124 screens
[i
].update();
1127 #if CONFIG_CODEC == SWCODEC
1128 audio_close_recording();
1129 audio_init_recording(0);
1132 rec_init_recording_options(&rec_options
);
1133 rec_set_recording_options(&rec_options
);
1135 if(rec_create_directory() < 0)
1141 #if CONFIG_CODEC == SWCODEC && CONFIG_RTC == 0
1142 /* If format changed, a new number is required */
1143 rec_init_filename();
1147 if (global_settings
.rec_source
== AUDIO_SRC_MIC
) {
1148 agc_preset
= global_settings
.rec_agc_preset_mic
;
1149 agc_maxgain
= global_settings
.rec_agc_maxgain_mic
;
1152 agc_preset
= global_settings
.rec_agc_preset_line
;
1153 agc_maxgain
= global_settings
.rec_agc_maxgain_line
;
1158 update_countdown
= 1; /* Update immediately */
1160 /* populate translation table for list id -> enum */
1161 if(global_settings
.rec_source
== AUDIO_SRC_MIC
)
1163 listid_to_enum
[0] = ITEM_VOLUME_M
;
1164 listid_to_enum
[1] = ITEM_GAIN_M
;
1166 listid_to_enum
[2] = ITEM_AGC_MODE_M
;
1167 listid_to_enum
[3] = ITEM_AGC_MAXDB_M
;
1168 listid_to_enum
[4] = ITEM_FILENAME_M
;
1170 listid_to_enum
[2] = ITEM_FILENAME_M
;
1175 listid_to_enum
[0] = ITEM_VOLUME
;
1176 listid_to_enum
[1] = ITEM_GAIN
;
1177 listid_to_enum
[2] = ITEM_GAIN_L
;
1178 listid_to_enum
[3] = ITEM_GAIN_R
;
1180 listid_to_enum
[4] = ITEM_AGC_MODE
;
1181 listid_to_enum
[5] = ITEM_AGC_MAXDB
;
1182 listid_to_enum
[6] = ITEM_FILENAME
;
1184 listid_to_enum
[4] = ITEM_FILENAME
;
1188 if(global_settings
.rec_source
== AUDIO_SRC_MIC
)
1189 gui_synclist_set_nb_items(&lists
, ITEM_COUNT_M
); /* mono */
1191 gui_synclist_set_nb_items(&lists
, ITEM_COUNT
); /* stereo */
1192 gui_synclist_draw(&lists
);
1193 } /* if(done < 0) */
1195 audio_stat
= audio_status();
1197 #if (CONFIG_LED == LED_REAL)
1200 * Flash the LED while waiting to record. Turn it on while
1203 if(audio_stat
& AUDIO_STATUS_RECORD
)
1205 if (audio_stat
& AUDIO_STATUS_PAUSE
)
1207 if (--led_countdown
<= 0)
1209 led_state
= !led_state
;
1216 /* trigger is on in status TRIG_READY (no check needed) */
1222 int trig_stat
= peak_meter_trigger_status();
1224 * other trigger stati than trig_off and trig_steady
1225 * already imply that we are recording.
1227 if (trig_stat
== TRIG_STEADY
)
1229 if (--led_countdown
<= 0)
1231 led_state
= !led_state
;
1238 /* trigger is on in status TRIG_READY (no check needed) */
1242 #endif /* CONFIG_LED */
1244 /* first set current vp - stays like this for drawing that follows */
1246 screens
[i
].set_viewport(&vp_top
[i
]);
1248 /* Wait for a button a while (HZ/10) drawing the peak meter */
1249 button
= peak_meter_draw_get_btn(CONTEXT_RECSCREEN
,
1253 if (last_audio_stat
!= audio_stat
)
1255 if (audio_stat
& AUDIO_STATUS_RECORD
)
1257 rec_status
|= RCSTAT_HAVE_RECORDED
;
1259 last_audio_stat
= audio_stat
;
1263 if (recording_start_automatic
)
1265 /* simulate a button press */
1266 button
= ACTION_REC_PAUSE
;
1267 recording_start_automatic
= false;
1270 /* let list handle the button */
1271 gui_synclist_do_button(&lists
, &button
, LIST_WRAP_UNLESS_HELD
);
1273 /* list code changes active viewport - change it back */
1275 screens
[i
].set_viewport(&vp_top
[i
]);
1279 case ACTION_SETTINGS_INC
:
1280 case ACTION_SETTINGS_INCREPEAT
:
1281 switch (listid_to_enum
[gui_synclist_get_sel_pos(&lists
)])
1284 global_settings
.volume
++;
1288 if(global_settings
.rec_source
== AUDIO_SRC_MIC
)
1290 if(global_settings
.rec_mic_gain
<
1291 sound_max(SOUND_MIC_GAIN
))
1292 global_settings
.rec_mic_gain
++;
1296 if(global_settings
.rec_left_gain
<
1297 sound_max(SOUND_LEFT_GAIN
))
1298 global_settings
.rec_left_gain
++;
1299 if(global_settings
.rec_right_gain
<
1300 sound_max(SOUND_RIGHT_GAIN
))
1301 global_settings
.rec_right_gain
++;
1305 if(global_settings
.rec_left_gain
<
1306 sound_max(SOUND_LEFT_GAIN
))
1307 global_settings
.rec_left_gain
++;
1310 if(global_settings
.rec_right_gain
<
1311 sound_max(SOUND_RIGHT_GAIN
))
1312 global_settings
.rec_right_gain
++;
1316 agc_preset
= MIN(agc_preset
+ 1, AGC_MODE_SIZE
);
1317 agc_enable
= (agc_preset
!= 0);
1318 if (global_settings
.rec_source
== AUDIO_SRC_MIC
) {
1319 global_settings
.rec_agc_preset_mic
= agc_preset
;
1320 agc_maxgain
= global_settings
.rec_agc_maxgain_mic
;
1322 global_settings
.rec_agc_preset_line
= agc_preset
;
1323 agc_maxgain
= global_settings
.rec_agc_maxgain_line
;
1326 case ITEM_AGC_MAXDB
:
1327 if (global_settings
.rec_source
== AUDIO_SRC_MIC
)
1329 agc_maxgain
= MIN(agc_maxgain
+ 1,
1330 sound_max(SOUND_MIC_GAIN
));
1331 global_settings
.rec_agc_maxgain_mic
= agc_maxgain
;
1335 agc_maxgain
= MIN(agc_maxgain
+ 1,
1336 sound_max(SOUND_LEFT_GAIN
));
1337 global_settings
.rec_agc_maxgain_line
= agc_maxgain
;
1340 #endif /* HAVE_AGC */
1343 update_countdown
= 1; /* Update immediately */
1345 case ACTION_SETTINGS_DEC
:
1346 case ACTION_SETTINGS_DECREPEAT
:
1347 switch (listid_to_enum
[gui_synclist_get_sel_pos(&lists
)])
1350 global_settings
.volume
--;
1354 if(global_settings
.rec_source
== AUDIO_SRC_MIC
)
1356 if(global_settings
.rec_mic_gain
>
1357 sound_min(SOUND_MIC_GAIN
))
1358 global_settings
.rec_mic_gain
--;
1362 if(global_settings
.rec_left_gain
>
1363 sound_min(SOUND_LEFT_GAIN
))
1364 global_settings
.rec_left_gain
--;
1365 if(global_settings
.rec_right_gain
>
1366 sound_min(SOUND_RIGHT_GAIN
))
1367 global_settings
.rec_right_gain
--;
1371 if(global_settings
.rec_left_gain
>
1372 sound_min(SOUND_LEFT_GAIN
))
1373 global_settings
.rec_left_gain
--;
1376 if(global_settings
.rec_right_gain
>
1377 sound_min(SOUND_RIGHT_GAIN
))
1378 global_settings
.rec_right_gain
--;
1382 agc_preset
= MAX(agc_preset
- 1, 0);
1383 agc_enable
= (agc_preset
!= 0);
1384 if (global_settings
.rec_source
== AUDIO_SRC_MIC
) {
1385 global_settings
.rec_agc_preset_mic
= agc_preset
;
1386 agc_maxgain
= global_settings
.rec_agc_maxgain_mic
;
1388 global_settings
.rec_agc_preset_line
= agc_preset
;
1389 agc_maxgain
= global_settings
.rec_agc_maxgain_line
;
1392 case ITEM_AGC_MAXDB
:
1393 if (global_settings
.rec_source
== AUDIO_SRC_MIC
)
1395 agc_maxgain
= MAX(agc_maxgain
- 1,
1396 sound_min(SOUND_MIC_GAIN
));
1397 global_settings
.rec_agc_maxgain_mic
= agc_maxgain
;
1401 agc_maxgain
= MAX(agc_maxgain
- 1,
1402 sound_min(SOUND_LEFT_GAIN
));
1403 global_settings
.rec_agc_maxgain_line
= agc_maxgain
;
1406 #endif /* HAVE_AGC */
1409 update_countdown
= 1; /* Update immediately */
1411 case ACTION_STD_CANCEL
:
1412 /* turn off the trigger */
1413 peak_meter_trigger(false);
1414 peak_meter_set_trigger_listener(NULL
);
1416 if(audio_stat
& AUDIO_STATUS_RECORD
)
1418 rec_command(RECORDING_CMD_STOP
);
1422 #if CONFIG_CODEC != SWCODEC
1423 peak_meter_playback(true);
1424 peak_meter_enabled
= false;
1428 update_countdown
= 1; /* Update immediately */
1430 #ifdef HAVE_REMOTE_LCD
1431 case ACTION_REC_LCD
:
1432 /* this feature exists for some h1x0/h3x0 targets that suffer
1433 from noise caused by remote LCD updates
1434 NOTE 1: this will leave the list on the remote
1435 NOTE 2: to be replaced by a global LCD_off() routine */
1436 if(remote_display_on
)
1438 /* switch to single screen and put up a splash on the main.
1439 On the remote we put a two line message */
1441 screens
[1].clear_viewport();
1442 screens
[1].puts(0, 0, str(LANG_REMOTE_LCD_OFF
));
1443 screens
[1].puts(0, 1, str(LANG_REMOTE_LCD_ON
));
1444 screens
[1].update_viewport();
1445 gui_splash(&screens
[0], 0, str(LANG_REMOTE_LCD_OFF
));
1449 /* remote switched on again */
1451 screen_update
= NB_SCREENS
;
1453 remote_display_on
= !remote_display_on
; /* toggle */
1454 update_countdown
= 1; /* Update immediately */
1457 case ACTION_REC_PAUSE
:
1458 case ACTION_REC_NEWFILE
:
1459 /* Only act if the mpeg is stopped */
1460 if(!(audio_stat
& AUDIO_STATUS_RECORD
))
1462 /* is this manual or triggered recording? */
1463 if ((global_settings
.rec_trigger_mode
== TRIG_MODE_OFF
) ||
1464 (peak_meter_trigger_status() != TRIG_OFF
))
1466 /* manual recording */
1467 rec_status
|= RCSTAT_HAVE_RECORDED
;
1468 rec_command(RECORDING_CMD_START
);
1470 if (global_settings
.talk_menu
)
1472 /* no voice possible here, but a beep */
1473 audio_beep(HZ
/2); /* longer beep on start */
1476 /* this is triggered recording */
1479 /* we don't start recording now, but enable the
1480 trigger and let the callback function
1481 trigger_listener control when the recording starts */
1482 peak_meter_trigger(true);
1483 peak_meter_set_trigger_listener(&trigger_listener
);
1488 /*if new file button pressed, start new file */
1489 if (button
== ACTION_REC_NEWFILE
)
1491 rec_command(RECORDING_CMD_START_NEWFILE
);
1495 /* if pause button pressed, pause or resume */
1497 if(audio_stat
& AUDIO_STATUS_PAUSE
)
1499 rec_command(RECORDING_CMD_RESUME
);
1500 if (global_settings
.talk_menu
)
1502 /* no voice possible here, but a beep */
1503 audio_beep(HZ
/4); /* short beep on resume */
1508 rec_command(RECORDING_CMD_PAUSE
);
1512 update_countdown
= 1; /* Update immediately */
1514 case ACTION_STD_MENU
:
1515 #if CONFIG_CODEC == SWCODEC
1516 if(!(audio_stat
& AUDIO_STATUS_RECORD
))
1518 if(audio_stat
!= AUDIO_STATUS_RECORD
)
1521 #if (CONFIG_LED == LED_REAL)
1522 /* led is restored at begin of loop / end of function */
1525 if (recording_menu(no_source
))
1528 rec_status
|= RCSTAT_BEEN_IN_USB_MODE
;
1529 #ifdef HAVE_FMRADIO_REC
1530 radio_status
= FMRADIO_OFF
;
1536 /* the init is now done at the beginning of the loop */
1541 #if CONFIG_KEYPAD == RECORDER_PAD
1543 if(audio_stat
!= AUDIO_STATUS_RECORD
)
1545 #if (CONFIG_LED == LED_REAL)
1546 /* led is restored at begin of loop / end of function */
1549 if (f2_rec_screen())
1551 rec_status
|= RCSTAT_HAVE_RECORDED
;
1555 update_countdown
= 1; /* Update immediately */
1560 if(audio_stat
& AUDIO_STATUS_RECORD
)
1562 rec_command(RECORDING_CMD_START_NEWFILE
);
1567 #if (CONFIG_LED == LED_REAL)
1568 /* led is restored at begin of loop / end of function */
1571 if (f3_rec_screen())
1573 rec_status
|= RCSTAT_HAVE_RECORDED
;
1577 update_countdown
= 1; /* Update immediately */
1580 #endif /* CONFIG_KEYPAD == RECORDER_PAD */
1582 case SYS_USB_CONNECTED
:
1583 /* Only accept USB connection when not recording */
1584 if(!(audio_stat
& AUDIO_STATUS_RECORD
))
1587 screens
[i
].set_viewport(NULL
);
1588 default_event_handler(SYS_USB_CONNECTED
);
1590 rec_status
|= RCSTAT_BEEN_IN_USB_MODE
;
1591 #ifdef HAVE_FMRADIO_REC
1592 radio_status
= FMRADIO_OFF
;
1596 } /*switch(button)*/
1599 peak_read
= !peak_read
;
1600 if (peak_read
) { /* every 2nd run of loop */
1602 peak_valid
= read_peak_levels(&peak_l
, &peak_r
, &balance
);
1605 /* Handle AGC every 200ms when enabled and peak data is valid */
1606 if (peak_read
&& agc_enable
&& peak_valid
)
1607 auto_gain_control(&peak_l
, &peak_r
, &balance
);
1610 seconds
= audio_recorded_time() / HZ
;
1612 /* start of vp_top drawing */
1613 if(update_countdown
-- == 0 || seconds
> last_seconds
)
1615 unsigned int dseconds
, dhours
, dminutes
;
1616 unsigned long num_recorded_bytes
, dsize
, dmb
;
1618 /* we assume vp_top is the current viewport! */
1619 FOR_NB_ACTIVE_SCREENS(i
)
1620 screens
[i
].clear_viewport();
1622 update_countdown
= 5;
1623 last_seconds
= seconds
;
1625 dseconds
= rec_timesplit_seconds();
1626 dsize
= rec_sizesplit_bytes();
1627 num_recorded_bytes
= audio_num_recorded_bytes();
1629 #if CONFIG_CODEC == SWCODEC
1630 if ((audio_stat
& AUDIO_STATUS_WARNING
)
1631 && (warning_counter
++ % WARNING_PERIOD
) < WARNING_PERIOD
/2)
1633 /* Switch back and forth displaying warning on first available
1634 line to ensure visibility - the motion should also help
1636 /* Don't use language string unless agreed upon to make this
1637 method permanent - could do something in the statusbar */
1638 snprintf(buf
, sizeof(buf
), "Warning: %08X",
1639 pcm_rec_get_warnings());
1642 #endif /* CONFIG_CODEC == SWCODEC */
1643 if ((global_settings
.rec_sizesplit
) &&
1644 (global_settings
.rec_split_method
))
1646 dmb
= dsize
/1024/1024;
1647 snprintf(buf
, sizeof(buf
), "%s %dMB",
1648 str(LANG_SPLIT_SIZE
), dmb
);
1652 hours
= seconds
/ 3600;
1653 minutes
= (seconds
- (hours
* 3600)) / 60;
1654 snprintf(buf
, sizeof(buf
), "%s %02d:%02d:%02d",
1655 str(LANG_RECORDING_TIME
),
1656 hours
, minutes
, seconds
%60);
1659 FOR_NB_ACTIVE_SCREENS(i
)
1660 screens
[i
].puts(0, 0, buf
);
1662 if(audio_stat
& AUDIO_STATUS_PRERECORD
)
1664 snprintf(buf
, sizeof(buf
), "%s...",
1665 str(LANG_RECORD_PRERECORD
));
1669 /* Display the split interval if the record timesplit
1671 if ((global_settings
.rec_timesplit
) &&
1672 !(global_settings
.rec_split_method
))
1674 /* Display the record timesplit interval rather
1675 than the file size if the record timer is active */
1676 dhours
= dseconds
/ 3600;
1677 dminutes
= (dseconds
- (dhours
* 3600)) / 60;
1678 snprintf(buf
, sizeof(buf
), "%s %02d:%02d",
1679 str(LANG_RECORDING_TIMESPLIT_REC
),
1684 output_dyn_value(buf2
, sizeof buf2
,
1687 snprintf(buf
, sizeof(buf
), "%s %s",
1688 str(LANG_RECORDING_SIZE
), buf2
);
1692 FOR_NB_ACTIVE_SCREENS(i
)
1693 screens
[i
].puts(0, 1, buf
);
1695 /* We will do file splitting regardless, either at the end of
1696 a split interval, or when the filesize approaches the 2GB
1697 FAT file size (compatibility) limit. */
1698 if ((audio_stat
&& !(global_settings
.rec_split_method
)
1699 && global_settings
.rec_timesplit
&& (seconds
>= dseconds
))
1700 || (audio_stat
&& global_settings
.rec_split_method
1701 && global_settings
.rec_sizesplit
1702 && (num_recorded_bytes
>= dsize
))
1703 || (num_recorded_bytes
>= MAX_FILE_SIZE
))
1705 if (!(global_settings
.rec_split_type
)
1706 || (num_recorded_bytes
>= MAX_FILE_SIZE
))
1708 rec_command(RECORDING_CMD_START_NEWFILE
);
1713 peak_meter_trigger(false);
1714 peak_meter_set_trigger_listener(NULL
);
1715 if( global_settings
.rec_split_type
== 1)
1716 rec_command(RECORDING_CMD_STOP
);
1718 rec_command(RECORDING_CMD_STOP_SHUTDOWN
);
1720 update_countdown
= 1;
1723 /* draw the clipcounter just in front of the peakmeter */
1724 if(global_settings
.peak_meter_clipcounter
)
1727 snprintf(clpstr
, 32, "%4d", pm_get_clipcount());
1728 FOR_NB_ACTIVE_SCREENS(i
)
1730 if(!compact_view
[i
])
1731 screens
[i
].puts(0, 2,str(LANG_PM_CLIPCOUNT
));
1732 screens
[i
].puts(0, compact_view
[i
] ? 2 : 3, clpstr
);
1740 /* draw the trigger status */
1741 if (peak_meter_trigger_status() != TRIG_OFF
)
1743 peak_meter_draw_trig(pm_x
, trig_ypos
, trig_width
,
1745 FOR_NB_ACTIVE_SCREENS(i
)
1746 screens
[i
].update_viewport_rect(pm_x
[i
], trig_ypos
[i
],
1747 trig_width
[i
] + 2, TRIG_HEIGHT
);
1751 if (global_settings
.rec_source
== AUDIO_SRC_MIC
)
1753 if(agc_maxgain
< (global_settings
.rec_mic_gain
))
1754 change_recording_gain(false, true, true);
1758 if(agc_maxgain
< (global_settings
.rec_left_gain
))
1759 change_recording_gain(false, true, false);
1760 if(agc_maxgain
< (global_settings
.rec_right_gain
))
1761 change_recording_gain(false, false, true);
1763 #endif /* HAVE_AGC */
1767 /* update_list is set whenever content changes */
1768 update_list
= false;
1769 gui_synclist_draw(&lists
);
1772 /* draw peakmeter again (check if this can be removed) */
1773 FOR_NB_ACTIVE_SCREENS(i
)
1775 screens
[i
].set_viewport(NULL
);
1776 gui_statusbar_draw(&(statusbars
.statusbars
[i
]), true);
1777 screens
[i
].set_viewport(&vp_top
[i
]);
1778 peak_meter_screen(&screens
[i
], pm_x
[i
], pm_y
[i
], pm_h
[i
]);
1779 screens
[i
].update();
1781 } /* display update every second */
1783 if(audio_stat
& AUDIO_STATUS_ERROR
)
1787 } /* end while(!done) */
1789 audio_stat
= audio_status();
1790 if (audio_stat
& AUDIO_STATUS_ERROR
)
1792 gui_syncsplash(0, str(LANG_DISK_FULL
));
1793 gui_syncstatusbar_draw(&statusbars
, true);
1796 screens
[i
].update();
1798 #if CONFIG_CODEC == SWCODEC
1799 /* stop recording - some players like H10 freeze otherwise
1800 TO DO: find out why it freezes and fix properly */
1801 rec_command(RECORDING_CMD_STOP
);
1802 audio_close_recording();
1805 audio_error_clear();
1809 if (action_userabort(TIMEOUT_NOBLOCK
))
1816 #if CONFIG_CODEC == SWCODEC
1817 rec_command(RECORDING_CMD_STOP
);
1818 audio_close_recording();
1820 #ifdef HAVE_FMRADIO_REC
1821 if (radio_status
!= FMRADIO_OFF
)
1822 /* Restore radio playback - radio_status should be unchanged if started
1823 through fm radio screen (barring usb connect) */
1824 rec_set_source(AUDIO_SRC_FMRADIO
, (radio_status
& FMRADIO_PAUSED
) ?
1825 SRCF_FMRADIO_PAUSED
: SRCF_FMRADIO_PLAYING
);
1828 /* Go back to playback mode */
1829 rec_set_source(AUDIO_SRC_PLAYBACK
, SRCF_PLAYBACK
);
1831 /* restore talking */
1832 talk_disable(false);
1833 #else /* !SWCODEC */
1834 audio_init_playback();
1835 #endif /* CONFIG_CODEC == SWCODEC */
1837 /* make sure the trigger is really turned off */
1838 peak_meter_trigger(false);
1839 peak_meter_set_trigger_listener(NULL
);
1841 rec_status
&= ~RCSTAT_IN_RECSCREEN
;
1842 sound_settings_apply();
1845 screens
[i
].setfont(FONT_UI
);
1847 /* if the directory was created or recording happened, make sure the
1848 browser is updated */
1849 if (rec_status
& (RCSTAT_CREATED_DIRECTORY
| RCSTAT_HAVE_RECORDED
))
1852 #if (CONFIG_LED == LED_REAL) && !defined(SIMULATOR)
1853 ata_set_led_enabled(true);
1857 global_settings
.statusbar
= statusbar
;
1858 global_status
.statusbar_forced
= 0;
1863 return (rec_status
& RCSTAT_BEEN_IN_USB_MODE
) != 0;
1864 } /* recording_screen */
1866 #if CONFIG_KEYPAD == RECORDER_PAD
1867 static bool f2_rec_screen(void)
1869 static const char* const freq_str
[6] =
1884 struct audio_recording_options rec_options
;
1888 screens
[i
].setfont(FONT_SYSFIXED
);
1889 screens
[i
].getstringsize("A",&w
,&h
);
1893 const char* ptr
=NULL
;
1897 screens
[i
].clear_display();
1899 /* Recording quality */
1900 screens
[i
].putsxy(0, LCD_HEIGHT
/2 - h
*2,
1901 str(LANG_SYSFONT_RECORDING_QUALITY
));
1904 snprintf(buf
, sizeof(buf
), "%d", global_settings
.rec_quality
);
1907 screens
[i
].putsxy(0, LCD_HEIGHT
/2-h
, buf
);
1908 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_FastBackward
],
1909 LCD_WIDTH
/2 - 16, LCD_HEIGHT
/2 - 4, 7, 8);
1913 snprintf(buf
, sizeof buf
, "%s:", str(LANG_SYSFONT_RECORDING_FREQUENCY
));
1914 ptr
= freq_str
[global_settings
.rec_frequency
];
1917 screens
[i
].getstringsize(buf
,&w
,&h
);
1918 screens
[i
].putsxy((LCD_WIDTH
-w
)/2, LCD_HEIGHT
- h
*2, buf
);
1919 screens
[i
].getstringsize(ptr
, &w
, &h
);
1920 screens
[i
].putsxy((LCD_WIDTH
-w
)/2, LCD_HEIGHT
- h
, ptr
);
1921 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_DownArrow
],
1922 LCD_WIDTH
/2 - 3, LCD_HEIGHT
- h
*3, 7, 8);
1926 switch ( global_settings
.rec_channels
) {
1928 ptr
= str(LANG_SYSFONT_CHANNEL_STEREO
);
1932 ptr
= str(LANG_SYSFONT_CHANNEL_MONO
);
1938 screens
[i
].getstringsize(str(LANG_SYSFONT_CHANNELS
), &w
, &h
);
1939 screens
[i
].putsxy(LCD_WIDTH
- w
, LCD_HEIGHT
/2 - h
*2,
1940 str(LANG_SYSFONT_CHANNELS
));
1941 screens
[i
].getstringsize(str(LANG_SYSFONT_MODE
), &w
, &h
);
1942 screens
[i
].putsxy(LCD_WIDTH
- w
, LCD_HEIGHT
/2 - h
,
1943 str(LANG_SYSFONT_MODE
));
1944 screens
[i
].getstringsize(ptr
, &w
, &h
);
1945 screens
[i
].putsxy(LCD_WIDTH
- w
, LCD_HEIGHT
/2, ptr
);
1946 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_FastForward
],
1947 LCD_WIDTH
/2 + 8, LCD_HEIGHT
/2 - 4, 7, 8);
1949 screens
[i
].update();
1952 button
= button_get(true);
1955 case BUTTON_F2
| BUTTON_LEFT
:
1956 global_settings
.rec_quality
++;
1957 if(global_settings
.rec_quality
> 7)
1958 global_settings
.rec_quality
= 0;
1963 case BUTTON_F2
| BUTTON_DOWN
:
1964 global_settings
.rec_frequency
++;
1965 if(global_settings
.rec_frequency
> 5)
1966 global_settings
.rec_frequency
= 0;
1971 case BUTTON_F2
| BUTTON_RIGHT
:
1972 global_settings
.rec_channels
++;
1973 if(global_settings
.rec_channels
> 1)
1974 global_settings
.rec_channels
= 0;
1978 case BUTTON_F2
| BUTTON_REL
:
1984 case BUTTON_F2
| BUTTON_REPEAT
:
1989 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
1995 rec_init_recording_options(&rec_options
);
1996 rec_set_recording_options(&rec_options
);
2002 screens
[i
].setfont(FONT_UI
);
2007 static bool f3_rec_screen(void)
2015 str(LANG_SYSFONT_RECORDING_SRC_MIC
),
2016 str(LANG_SYSFONT_LINE_IN
),
2017 str(LANG_SYSFONT_RECORDING_SRC_DIGITAL
)
2019 struct audio_recording_options rec_options
;
2023 screens
[i
].setfont(FONT_SYSFIXED
);
2024 screens
[i
].getstringsize("A",&w
,&h
);
2029 ptr
= src_str
[global_settings
.rec_source
];
2032 screens
[i
].clear_display();
2034 /* Recording source */
2035 screens
[i
].putsxy(0, LCD_HEIGHT
/2 - h
*2,
2036 str(LANG_SYSFONT_RECORDING_SOURCE
));
2038 screens
[i
].getstringsize(ptr
, &w
, &h
);
2039 screens
[i
].putsxy(0, LCD_HEIGHT
/2-h
, ptr
);
2040 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_FastBackward
],
2041 LCD_WIDTH
/2 - 16, LCD_HEIGHT
/2 - 4, 7, 8);
2045 ptr
= str(LANG_SYSFONT_RECORD_TRIGGER
);
2048 screens
[i
].getstringsize(ptr
,&w
,&h
);
2049 screens
[i
].putsxy((LCD_WIDTH
-w
)/2, LCD_HEIGHT
- h
*2, ptr
);
2050 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_DownArrow
],
2051 LCD_WIDTH
/2 - 3, LCD_HEIGHT
- h
*3, 7, 8);
2053 screens
[i
].update();
2056 button
= button_get(true);
2059 case BUTTON_F3
| BUTTON_DOWN
:
2062 settings_apply_trigger();
2068 case BUTTON_F3
| BUTTON_LEFT
:
2069 global_settings
.rec_source
++;
2070 if(global_settings
.rec_source
> AUDIO_SRC_MAX
)
2071 global_settings
.rec_source
= 0;
2075 case BUTTON_F3
| BUTTON_REL
:
2081 case BUTTON_F3
| BUTTON_REPEAT
:
2086 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
2092 rec_init_recording_options(&rec_options
);
2093 rec_set_recording_options(&rec_options
);
2099 screens
[i
].setfont(FONT_UI
);
2103 #endif /* CONFIG_KEYPAD == RECORDER_PAD */
2105 #if CONFIG_CODEC == SWCODEC
2106 void audio_beep(int duration
)
2113 /* stubs for recording sim */
2114 void audio_init_recording(unsigned int buffer_offset
)
2116 buffer_offset
= buffer_offset
;
2119 void audio_close_recording(void)
2123 unsigned long pcm_rec_get_warnings(void)
2128 unsigned long audio_recorded_time(void)
2133 unsigned long audio_num_recorded_bytes(void)
2135 return 5 * 1024 * 1024;
2138 void rec_set_source(int source
, unsigned flags
)
2144 void audio_set_recording_options(struct audio_recording_options
*options
)
2149 void audio_set_recording_gain(int left
, int right
, int type
)
2156 void audio_record(const char *filename
)
2158 filename
= filename
;
2161 void audio_new_file(const char *filename
)
2163 filename
= filename
;
2166 void audio_stop_recording(void)
2170 void audio_pause_recording(void)
2174 void audio_resume_recording(void)
2178 #endif /* #ifdef SIMULATOR */
2179 #endif /* #ifdef CONFIG_CODEC == SWCODEC */
2181 #endif /* HAVE_RECORDING */