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 "pcm_record.h"
44 #include "recording.h"
45 #include "mp3_playback.h"
55 #include "peakmeter.h"
57 #include "sound_menu.h"
58 #include "timefuncs.h"
68 #if (CONFIG_STORAGE & STORAGE_ATA) && (CONFIG_LED == LED_REAL) \
69 && !defined(SIMULATOR)
73 #include "screen_access.h"
79 #include "appevents.h"
82 /* This array holds the record timer interval lengths, in seconds */
83 static const unsigned long rec_timer_seconds
[] =
97 10L*60*60, /* 10:00 */
98 12L*60*60, /* 12:00 */
99 18L*60*60, /* 18:00 */
100 24L*60*60 /* 24:00 */
103 static unsigned int rec_timesplit_seconds(void)
105 return rec_timer_seconds
[global_settings
.rec_timesplit
];
108 /* This array holds the record size interval lengths, in bytes */
109 static const unsigned long rec_size_bytes
[] =
112 5*1024*1024, /* 5MB */
113 10*1024*1024, /* 10MB */
114 15*1024*1024, /* 15MB */
115 32*1024*1024, /* 32MB */
116 64*1024*1024, /* 64MB */
117 75*1024*1024, /* 75MB */
118 100*1024*1024, /* 100MB */
119 128*1024*1024, /* 128MB */
120 256*1024*1024, /* 256MB */
121 512*1024*1024, /* 512MB */
122 650*1024*1024, /* 650MB */
123 700*1024*1024, /* 700MB */
124 1024*1024*1024, /* 1GB */
125 1536*1024*1024, /* 1.5GB */
126 1792*1024*1024, /* 1.75GB */
129 static unsigned long rec_sizesplit_bytes(void)
131 return rec_size_bytes
[global_settings
.rec_sizesplit
];
134 void settings_apply_trigger(void)
136 int start_thres
, stop_thres
;
137 if (global_settings
.peak_meter_dbfs
)
139 start_thres
= global_settings
.rec_start_thres_db
- 1;
140 stop_thres
= global_settings
.rec_stop_thres_db
- 1;
144 start_thres
= global_settings
.rec_start_thres_linear
;
145 stop_thres
= global_settings
.rec_stop_thres_linear
;
148 peak_meter_define_trigger(
150 global_settings
.rec_start_duration
*HZ
,
151 MIN(global_settings
.rec_start_duration
*HZ
/ 2, 2*HZ
),
153 global_settings
.rec_stop_postrec
*HZ
,
154 global_settings
.rec_stop_gap
*HZ
157 /* recording screen status flags */
158 enum rec_status_flags
160 RCSTAT_IN_RECSCREEN
= 0x00000001,
161 RCSTAT_BEEN_IN_USB_MODE
= 0x00000002,
162 RCSTAT_CREATED_DIRECTORY
= 0x00000004,
163 RCSTAT_HAVE_RECORDED
= 0x00000008,
166 static int rec_status
= 0;
168 bool in_recording_screen(void)
170 return (rec_status
& RCSTAT_IN_RECSCREEN
) != 0;
173 #if CONFIG_KEYPAD == RECORDER_PAD
174 static bool f2_rec_screen(void);
175 static bool f3_rec_screen(void);
178 #define MAX_FILE_SIZE 0x7F800000 /* 2 GB - 4 MB */
180 #ifndef HAVE_REMOTE_LCD
181 static const int screen_update
= NB_SCREENS
;
183 static int screen_update
= NB_SCREENS
;
184 static bool remote_display_on
= true;
187 /* as we have the ability to disable the remote, we need an alternative loop */
188 #define FOR_NB_ACTIVE_SCREENS(i) for(i = 0; i < screen_update; i++)
190 static bool update_list
= false; /* (GIU) list needs updating */
192 /** File name creation **/
194 /* current file number to assist in creating unique numbered filenames
195 without actually having to create the file on disk */
196 static int file_number
= -1;
197 #endif /* CONFIG_RTC */
199 #if CONFIG_CODEC == SWCODEC
201 #define REC_FILE_ENDING(rec_format) \
202 (audio_formats[rec_format_afmt[rec_format]].ext_list)
204 #else /* CONFIG_CODEC != SWCODEC */
206 /* default record file extension for HWCODEC */
207 #define REC_FILE_ENDING(rec_format) \
208 (audio_formats[AFMT_MPA_L3].ext_list)
210 #endif /* CONFIG_CODEC == SWCODEC */
212 /* path for current file */
213 static char path_buffer
[MAX_PATH
];
215 /** Automatic Gain Control (AGC) **/
218 * peak_time is incremented every 0.2s, every 2nd run of record screen loop.
219 * hist_time is incremented every 0.5s, display update.
220 * peak_time is the counter of the peak hold read and agc process,
221 * overflow every 13 years 8-)
223 static long peak_time
= 0;
224 static long hist_time
= 0;
226 static short peak_valid_mem
[4];
227 #define BAL_MEM_SIZE 24
228 static short balance_mem
[BAL_MEM_SIZE
];
230 /* Automatic Gain Control */
231 #define AGC_MODE_SIZE 5
232 #define AGC_SAFETY_MODE 0
234 static const char* agc_preset_str
[] =
235 { "Off", "S", "L", "D", "M", "V" };
242 #define AGC_CLIP 32766
243 #define AGC_PEAK 29883 /* fast gain reduction threshold -0.8dB */
244 #define AGC_HIGH 27254 /* accelerated gain reduction threshold -1.6dB */
245 #define AGC_IMG 823 /* threshold for balance control -32dB */
246 /* autogain high level thresholds (-3dB, -7dB, -4dB, -5dB, -5dB) */
247 static const short agc_th_hi
[AGC_MODE_SIZE
] =
248 { 23197, 14637, 21156, 18428, 18426 };
249 /* autogain low level thresholds (-14dB, -11dB, -6dB, -7dB, -8dB) */
250 static const short agc_th_lo
[AGC_MODE_SIZE
] =
251 { 6538, 9235, 16422, 14636, 13045 };
252 /* autogain threshold times [1/5s] or [200ms] */
253 static const short agc_tdrop
[AGC_MODE_SIZE
] =
254 { 900, 225, 150, 60, 8 };
255 static const short agc_trise
[AGC_MODE_SIZE
] =
256 { 9000, 750, 400, 150, 20 };
257 static const short agc_tbal
[AGC_MODE_SIZE
] =
258 { 4500, 500, 300, 100, 15 };
260 static bool agc_enable
= true;
261 static short agc_preset
;
263 static int agc_left
= 0;
264 static int agc_right
= 0;
265 /* AGC time since high target volume was exceeded */
266 static short agc_droptime
= 0;
267 /* AGC time since volume fallen below low target */
268 static short agc_risetime
= 0;
269 /* AGC balance time exceeding +/- 0.7dB */
270 static short agc_baltime
= 0;
271 /* AGC maximum gain */
272 static short agc_maxgain
;
273 #endif /* HAVE_AGC */
275 static void set_gain(void)
278 if(global_settings
.rec_source
== AUDIO_SRC_MIC
)
280 audio_set_recording_gain(global_settings
.rec_mic_gain
,
286 /* AUDIO_SRC_LINEIN, AUDIO_SRC_FMRADIO, AUDIO_SRC_SPDIF */
287 audio_set_recording_gain(global_settings
.rec_left_gain
,
288 global_settings
.rec_right_gain
,
291 /* reset the clipping indicators */
292 peak_meter_set_clip_hold(global_settings
.peak_meter_clip_hold
);
297 /* Read peak meter values & calculate balance.
298 * Returns validity of peak values.
299 * Used for automatic gain control and history diagram.
301 static bool read_peak_levels(int *peak_l
, int *peak_r
, int *balance
)
303 peak_meter_get_peakhold(peak_l
, peak_r
);
304 peak_valid_mem
[peak_time
% 3] = *peak_l
;
305 if (((peak_valid_mem
[0] == peak_valid_mem
[1]) &&
306 (peak_valid_mem
[1] == peak_valid_mem
[2])) &&
307 ((*peak_l
< 32767) || storage_disk_is_active()))
310 if (*peak_r
> *peak_l
)
311 balance_mem
[peak_time
% BAL_MEM_SIZE
] = (*peak_l
?
312 MIN((10000 * *peak_r
) / *peak_l
- 10000, 15118) : 15118);
314 balance_mem
[peak_time
% BAL_MEM_SIZE
] = (*peak_r
?
315 MAX(10000 - (10000 * *peak_l
) / *peak_r
, -15118) : -15118);
318 for (i
= 0; i
< BAL_MEM_SIZE
; i
++)
319 *balance
+= balance_mem
[i
];
320 *balance
= *balance
/ BAL_MEM_SIZE
;
325 /* AGC helper function to check if maximum gain is reached */
326 static bool agc_gain_is_max(bool left
, bool right
)
328 /* range -128...+108 [0.5dB] */
329 short gain_current_l
;
330 short gain_current_r
;
335 switch (global_settings
.rec_source
)
337 #if defined(HAVE_LINE_REC) || defined(HAVE_FMRADIO_REC)
338 HAVE_LINE_REC_(case AUDIO_SRC_LINEIN
:)
339 HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO
:)
340 gain_current_l
= global_settings
.rec_left_gain
;
341 gain_current_r
= global_settings
.rec_right_gain
;
343 #endif /* LINE, FMRADIO */
344 #if defined(HAVE_MIC_REC)
347 gain_current_l
= global_settings
.rec_mic_gain
;
348 gain_current_r
= global_settings
.rec_mic_gain
;
352 return ((left
&& (gain_current_l
>= agc_maxgain
)) ||
353 (right
&& (gain_current_r
>= agc_maxgain
)));
356 static void change_recording_gain(bool increment
, bool left
, bool right
)
358 int factor
= (increment
? 1 : -1);
360 switch (global_settings
.rec_source
)
362 #if defined(HAVE_LINE_REC) || defined(HAVE_FMRADIO_REC)
363 HAVE_LINE_REC_(case AUDIO_SRC_LINEIN
:)
364 HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO
:)
365 if (left
) global_settings
.rec_left_gain
+= factor
;
366 if (right
) global_settings
.rec_right_gain
+= factor
;
368 #endif /* LINE, FMRADIO */
369 #if defined(HAVE_MIC_REC)
371 global_settings
.rec_mic_gain
+= factor
;
377 * Handle automatic gain control (AGC).
378 * Change recording gain if peak_x levels are above or below
379 * target volume for specified timeouts.
381 static void auto_gain_control(int *peak_l
, int *peak_r
, int *balance
)
387 if (*peak_l
> agc_left
)
390 agc_left
-= (agc_left
- *peak_l
+ 3) >> 2;
391 if (*peak_r
> agc_right
)
394 agc_right
-= (agc_right
- *peak_r
+ 3) >> 2;
395 agc_mono
= (agc_left
+ agc_right
) / 2;
397 agc_mode
= abs(agc_preset
) - 1;
403 if (agc_mode
!= AGC_SAFETY_MODE
) {
404 /* Automatic balance control - only if not in safety mode */
405 if ((agc_left
> AGC_IMG
) && (agc_right
> AGC_IMG
))
410 agc_baltime
-= !(peak_time
% 4); /* 0.47 - 0.75dB */
411 else if (*balance
> -4125)
412 agc_baltime
--; /* 0.75 - 3.00dB */
413 else if (*balance
> -7579)
414 agc_baltime
-= 2; /* 3.00 - 4.90dB */
416 agc_baltime
-= !(peak_time
% 8); /* 4.90 - inf dB */
418 agc_baltime
-= (peak_time
% 2);
420 else if (*balance
> 556)
423 agc_baltime
+= !(peak_time
% 4);
424 else if (*balance
< 4125)
426 else if (*balance
< 7579)
429 agc_baltime
+= !(peak_time
% 8);
431 agc_baltime
+= (peak_time
% 2);
434 if ((*balance
* agc_baltime
) < 0)
437 agc_baltime
-= peak_time
% 2;
439 agc_baltime
+= peak_time
% 2;
442 increment
= ((agc_risetime
/ 2) > agc_droptime
);
444 if (agc_baltime
< -agc_tbal
[agc_mode
])
446 if (!increment
|| !agc_gain_is_max(!increment
, increment
)) {
447 change_recording_gain(increment
, !increment
, increment
);
452 else if (agc_baltime
> +agc_tbal
[agc_mode
])
454 if (!increment
|| !agc_gain_is_max(increment
, !increment
)) {
455 change_recording_gain(increment
, increment
, !increment
);
461 else if (!(hist_time
% 4))
470 /* Automatic gain control */
471 if ((agc_left
> agc_th_hi
[agc_mode
]) || (agc_right
> agc_th_hi
[agc_mode
]))
473 if ((agc_left
> AGC_CLIP
) || (agc_right
> AGC_CLIP
))
474 agc_droptime
+= agc_tdrop
[agc_mode
] /
475 (global_settings
.rec_agc_cliptime
+ 1);
476 if (agc_left
> AGC_HIGH
) {
479 if (agc_left
> AGC_PEAK
)
482 if (agc_right
> AGC_HIGH
) {
485 if (agc_right
> AGC_PEAK
)
488 if (agc_mono
> agc_th_hi
[agc_mode
])
491 agc_droptime
+= !(peak_time
% 2);
493 if (agc_droptime
>= agc_tdrop
[agc_mode
])
495 change_recording_gain(false, true, true);
500 agc_risetime
= MAX(agc_risetime
- 1, 0);
502 else if (agc_mono
< agc_th_lo
[agc_mode
])
504 if (agc_mono
< (agc_th_lo
[agc_mode
] / 8))
505 agc_risetime
+= !(peak_time
% 5);
506 else if (agc_mono
< (agc_th_lo
[agc_mode
] / 2))
511 if (agc_risetime
>= agc_trise
[agc_mode
]) {
512 if ((agc_mode
!= AGC_SAFETY_MODE
) &&
513 (!agc_gain_is_max(true, true))) {
514 change_recording_gain(true, true, true);
520 agc_droptime
= MAX(agc_droptime
- 1, 0);
522 else if (!(peak_time
% 6)) /* on target level every 1.2 sec */
524 agc_risetime
= MAX(agc_risetime
- 1, 0);
525 agc_droptime
= MAX(agc_droptime
- 1, 0);
528 #endif /* HAVE_AGC */
530 static const char* const fmtstr
[] =
532 "%c%d %s", /* no decimals */
533 "%c%d.%d %s ", /* 1 decimal */
534 "%c%d.%02d %s " /* 2 decimals */
537 static char *fmt_gain(int snd
, int val
, char *str
, int len
)
543 val
= sound_val2phys(snd
, val
);
549 numdec
= sound_numdecimals(snd
);
550 unit
= sound_unit(snd
);
554 i
= val
/ (10*numdec
);
555 d
= val
% (10*numdec
);
556 snprintf(str
, len
, fmtstr
[numdec
], sign
, i
, d
, unit
);
559 snprintf(str
, len
, fmtstr
[numdec
], sign
, val
, unit
);
564 /* the list below must match enum audio_sources in audio.h */
565 static const char* const prestr
[] =
567 HAVE_MIC_IN_([AUDIO_SRC_MIC
] = "R_MIC_",)
568 HAVE_LINE_REC_([AUDIO_SRC_LINEIN
] = "R_LINE_",)
569 HAVE_SPDIF_IN_([AUDIO_SRC_SPDIF
] = "R_SPDIF_",)
570 HAVE_FMRADIO_REC_([AUDIO_SRC_FMRADIO
] = "R_FM_",)
573 char *rec_create_filename(char *buffer
)
576 const char *pref
= "R_";
578 /* Directory existence and writeablility should have already been
579 * verified - do not pass NULL pointers to pcmrec */
581 if((unsigned)global_settings
.rec_source
< AUDIO_NUM_SOURCES
)
583 pref
= prestr
[global_settings
.rec_source
];
586 strcpy(buffer
, global_settings
.rec_directory
);
588 snprintf(ext
, sizeof(ext
), ".%s",
589 REC_FILE_ENDING(global_settings
.rec_format
));
592 return create_numbered_filename(buffer
, buffer
, pref
, ext
, 4,
595 /* We'll wait at least up to the start of the next second so no duplicate
597 return create_datetime_filename(buffer
, buffer
, pref
, ext
, true);
602 /* Hit disk to get a starting filename for the type */
603 static void rec_init_filename(void)
606 rec_create_filename(path_buffer
);
611 int rec_create_directory(void)
614 const char * const folder
= global_settings
.rec_directory
;
616 if (strcmp(folder
, "/") && !dir_exists(folder
))
622 while (action_userabort(HZ
) == false)
625 str(LANG_REC_DIR_NOT_WRITABLE
),
626 str(LANG_OFF_ABORT
));
631 rec_status
|= RCSTAT_CREATED_DIRECTORY
;
639 void rec_init_recording_options(struct audio_recording_options
*options
)
641 options
->rec_source
= global_settings
.rec_source
;
642 options
->rec_frequency
= global_settings
.rec_frequency
;
643 options
->rec_channels
= global_settings
.rec_channels
;
644 options
->rec_prerecord_time
= global_settings
.rec_prerecord_time
;
645 #if CONFIG_CODEC == SWCODEC
646 options
->rec_mono_mode
= global_settings
.rec_mono_mode
;
647 options
->rec_source_flags
= 0;
648 options
->enc_config
.rec_format
= global_settings
.rec_format
;
649 global_to_encoder_config(&options
->enc_config
);
651 options
->rec_quality
= global_settings
.rec_quality
;
652 options
->rec_editable
= global_settings
.rec_editable
;
656 #if CONFIG_CODEC == SWCODEC && !defined (SIMULATOR)
657 void rec_set_source(int source
, unsigned flags
)
659 /* Set audio input source, power up/down devices */
660 audio_set_input_source(source
, flags
);
662 /* Set peakmeters for recording or reset to playback */
663 peak_meter_playback((flags
& SRCF_RECORDING
) == 0);
664 peak_meter_enabled
= true;
666 #endif /* CONFIG_CODEC == SWCODEC && !defined (SIMULATOR) */
668 void rec_set_recording_options(struct audio_recording_options
*options
)
670 #if CONFIG_CODEC != SWCODEC
671 if (global_settings
.rec_prerecord_time
)
673 talk_buffer_steal(); /* will use the mp3 buffer */
675 #else /* == SWCODEC */
676 rec_set_source(options
->rec_source
,
677 options
->rec_source_flags
| SRCF_RECORDING
);
678 #endif /* CONFIG_CODEC != SWCODEC */
680 audio_set_recording_options(options
);
683 void rec_command(enum recording_command cmd
)
687 case RECORDING_CMD_STOP_SHUTDOWN
:
688 pm_activate_clipcount(false);
689 audio_stop_recording();
690 #if CONFIG_CODEC == SWCODEC
691 audio_close_recording();
695 case RECORDING_CMD_STOP
:
696 pm_activate_clipcount(false);
697 audio_stop_recording();
699 case RECORDING_CMD_START
:
700 /* steal mp3 buffer, create unique filename and start recording */
701 pm_reset_clipcount();
702 pm_activate_clipcount(true);
703 #if CONFIG_CODEC != SWCODEC
704 talk_buffer_steal(); /* we use the mp3 buffer */
706 audio_record(rec_create_filename(path_buffer
));
708 case RECORDING_CMD_START_NEWFILE
:
709 /* create unique filename and start recording*/
710 pm_reset_clipcount();
711 pm_activate_clipcount(true); /* just to be sure */
712 audio_new_file(rec_create_filename(path_buffer
));
714 case RECORDING_CMD_PAUSE
:
715 pm_activate_clipcount(false);
716 audio_pause_recording();
718 case RECORDING_CMD_RESUME
:
719 pm_activate_clipcount(true);
720 audio_resume_recording();
726 /* used in trigger_listerner and recording_screen */
727 static unsigned int last_seconds
= 0;
730 * Callback function so that the peak meter code can send an event
731 * to this application. This function can be passed to
732 * peak_meter_set_trigger_listener in order to activate the trigger.
734 static void trigger_listener(int trigger_status
)
736 switch (trigger_status
)
739 if(!(audio_status() & AUDIO_STATUS_RECORD
))
741 rec_status
|= RCSTAT_HAVE_RECORDED
;
742 rec_command(RECORDING_CMD_START
);
743 #if CONFIG_CODEC != SWCODEC
744 /* give control to mpeg thread so that it can start
746 yield(); yield(); yield();
750 /* if we're already recording this is a retrigger */
753 if((audio_status() & AUDIO_STATUS_PAUSE
) &&
754 (global_settings
.rec_trigger_type
== TRIG_TYPE_PAUSE
))
756 rec_command(RECORDING_CMD_RESUME
);
758 /* New file on trig start*/
759 else if (global_settings
.rec_trigger_type
!= TRIG_TYPE_NEW_FILE
)
761 rec_command(RECORDING_CMD_START_NEWFILE
);
762 /* tell recording_screen to reset the time */
768 /* A _change_ to TRIG_READY means the current recording has stopped */
770 if(audio_status() & AUDIO_STATUS_RECORD
)
772 switch(global_settings
.rec_trigger_type
)
774 case TRIG_TYPE_STOP
: /* Stop */
775 rec_command(RECORDING_CMD_STOP
);
778 case TRIG_TYPE_PAUSE
: /* Pause */
779 rec_command(RECORDING_CMD_PAUSE
);
782 case TRIG_TYPE_NEW_FILE
: /* New file on trig stop*/
783 rec_command(RECORDING_CMD_START_NEWFILE
);
784 /* tell recording_screen to reset the time */
788 case 3: /* Stop and shutdown */
789 rec_command(RECORDING_CMD_STOP_SHUTDOWN
);
793 if (global_settings
.rec_trigger_mode
!= TRIG_MODE_REARM
)
795 peak_meter_set_trigger_listener(NULL
);
796 peak_meter_trigger(false);
803 /* Stuff for drawing the screen */
805 enum rec_list_items_stereo
{
821 enum rec_list_items_mono
{
826 ITEM_AGC_MAXDB_M
= 5,
835 #ifdef HAVE_SPDIF_REC
836 enum rec_list_items_spdif
{
838 #if CONFIG_CODEC == SWCODEC
839 ITEM_SAMPLERATE_D
= 6,
849 static int listid_to_enum
[ITEM_COUNT
];
851 static const char* reclist_get_name(int selected_item
, void * data
,
852 char * buffer
, size_t buffer_len
)
858 data
= data
; /* not used */
859 if(selected_item
>= ITEM_COUNT
)
862 switch (listid_to_enum
[selected_item
])
865 snprintf(buffer
, buffer_len
, "%s: %s", str(LANG_VOLUME
),
866 fmt_gain(SOUND_VOLUME
,
867 global_settings
.volume
,
868 buf2
, sizeof(buf2
)));
872 if(global_settings
.rec_source
== AUDIO_SRC_MIC
)
874 /* Draw MIC recording gain */
875 snprintf(buffer
, buffer_len
, "%s: %s", str(LANG_GAIN
),
876 fmt_gain(SOUND_MIC_GAIN
,
877 global_settings
.rec_mic_gain
,
878 buf2
, sizeof(buf2
)));
883 int avg_gain
= (global_settings
.rec_left_gain
+
884 global_settings
.rec_right_gain
) / 2;
885 snprintf(buffer
, buffer_len
, "%s: %s", str(LANG_GAIN
),
886 fmt_gain(SOUND_LEFT_GAIN
,
888 buf2
, sizeof(buf2
)));
892 snprintf(buffer
, buffer_len
, "%s: %s",
894 fmt_gain(SOUND_LEFT_GAIN
,
895 global_settings
.rec_left_gain
,
896 buf2
, sizeof(buf2
)));
899 snprintf(buffer
, buffer_len
, "%s: %s",
900 str(LANG_GAIN_RIGHT
),
901 fmt_gain(SOUND_RIGHT_GAIN
,
902 global_settings
.rec_right_gain
,
903 buf2
, sizeof(buf2
)));
907 snprintf(buffer
, buffer_len
, "%s: %s",
908 str(LANG_RECORDING_AGC_PRESET
),
909 agc_preset_str
[agc_preset
]);
913 snprintf(buffer
, buffer_len
, "%s: %s",
914 str(LANG_RECORDING_AGC_MAXGAIN
),
915 fmt_gain(SOUND_LEFT_GAIN
,
916 agc_maxgain
, buf2
, sizeof(buf2
)));
918 else if (global_settings
.rec_source
== AUDIO_SRC_MIC
)
919 snprintf(buffer
, buffer_len
, "%s: %s (%s)",
920 str(LANG_RECORDING_AGC_MAXGAIN
),
921 fmt_gain(SOUND_MIC_GAIN
,
922 agc_maxgain
, buf2
, sizeof(buf2
)),
923 fmt_gain(SOUND_MIC_GAIN
,
924 agc_maxgain
- global_settings
.rec_mic_gain
,
925 buf3
, sizeof(buf3
)));
928 snprintf(buffer
, buffer_len
, "%s: %s (%s)",
929 str(LANG_RECORDING_AGC_MAXGAIN
),
930 fmt_gain(SOUND_LEFT_GAIN
,
931 agc_maxgain
, buf2
, sizeof(buf2
)),
932 fmt_gain(SOUND_LEFT_GAIN
,
934 (global_settings
.rec_left_gain
+
935 global_settings
.rec_right_gain
)/2,
936 buf3
, sizeof(buf3
)));
939 #if CONFIG_CODEC == SWCODEC
940 #ifdef HAVE_SPDIF_REC
941 case ITEM_SAMPLERATE_D
:
942 snprintf(buffer
, buffer_len
, "%s: %d",
943 str(LANG_RECORDING_FREQUENCY
),
944 pcm_rec_sample_rate());
950 if(audio_status() & AUDIO_STATUS_RECORD
)
952 size_t tot_len
= strlen(path_buffer
) +
953 strlen(str(LANG_RECORDING_FILENAME
)) + 1;
954 if(tot_len
> buffer_len
)
956 snprintf(buffer
, buffer_len
, "%s %s",
957 str(LANG_RECORDING_FILENAME
),
958 path_buffer
+ tot_len
- buffer_len
);
962 snprintf(buffer
, buffer_len
, "%s %s",
963 str(LANG_RECORDING_FILENAME
), path_buffer
);
968 return str(LANG_RECORDING_FILENAME
);
979 bool recording_start_automatic
= false;
981 bool recording_screen(bool no_source
)
984 int done
= -1; /* negative to re-init, positive to quit, zero to run */
985 char buf
[32]; /* for preparing strings */
986 char buf2
[32]; /* for preparing strings */
987 int w
, h
; /* character width/height */
988 int update_countdown
= 0; /* refresh counter */
989 unsigned int seconds
;
991 int audio_stat
= 0; /* status of the audio system */
992 int last_audio_stat
= -1; /* previous status so we can act on changes */
993 struct viewport vp_list
[NB_SCREENS
], vp_top
[NB_SCREENS
]; /* the viewports */
995 #if CONFIG_CODEC == SWCODEC
996 int warning_counter
= 0;
997 #define WARNING_PERIOD 7
1000 #if CONFIG_CODEC == SWCODEC
1001 #ifdef HAVE_SPDIF_REC
1002 unsigned long prev_sample_rate
= 0;
1006 #ifdef HAVE_FMRADIO_REC
1007 /* Radio is left on if:
1008 * 1) Is was on at the start and the initial source is FM Radio
1009 * 2) 1) and the source was never changed to something else
1011 int radio_status
= (global_settings
.rec_source
!= AUDIO_SRC_FMRADIO
) ?
1012 FMRADIO_OFF
: get_radio_status();
1014 #if (CONFIG_LED == LED_REAL)
1015 bool led_state
= false;
1016 int led_countdown
= 2;
1019 bool peak_read
= false;
1020 bool peak_valid
= false;
1024 int oldbars
, recbars
= VP_SB_ALLSCREENS
;
1026 int pm_x
[NB_SCREENS
]; /* peakmeter (and trigger bar) x pos */
1027 int pm_y
[NB_SCREENS
]; /* peakmeter y pos */
1028 int pm_h
[NB_SCREENS
]; /* peakmeter height */
1029 int trig_ypos
[NB_SCREENS
]; /* trigger bar y pos */
1030 int trig_width
[NB_SCREENS
]; /* trigger bar width */
1031 bool compact_view
[NB_SCREENS
]; /* tweak layout tiny screens / big fonts */
1033 struct gui_synclist lists
; /* the list in the bottom vp */
1034 #ifdef HAVE_FMRADIO_REC
1035 int prev_rec_source
= global_settings
.rec_source
; /* detect source change */
1038 struct audio_recording_options rec_options
;
1039 rec_status
= RCSTAT_IN_RECSCREEN
;
1041 #if (CONFIG_STORAGE & STORAGE_ATA) && (CONFIG_LED == LED_REAL) \
1042 && !defined(SIMULATOR)
1043 ata_set_led_enabled(false);
1046 #if CONFIG_CODEC == SWCODEC
1047 /* recording_menu gets messed up: so prevent manus talking */
1049 /* audio_init_recording stops anything playing when it takes the audio
1052 /* Yes, we use the D/A for monitoring */
1053 peak_meter_enabled
= true;
1054 peak_meter_playback(true);
1058 peak_meter_get_peakhold(&peak_l
, &peak_r
);
1061 pm_reset_clipcount();
1062 pm_activate_clipcount(false);
1063 settings_apply_trigger();
1066 agc_preset_str
[0] = str(LANG_OFF
);
1067 agc_preset_str
[1] = str(LANG_AGC_SAFETY
);
1068 agc_preset_str
[2] = str(LANG_AGC_LIVE
);
1069 agc_preset_str
[3] = str(LANG_AGC_DJSET
);
1070 agc_preset_str
[4] = str(LANG_AGC_MEDIUM
);
1071 agc_preset_str
[5] = str(LANG_AGC_VOICE
);
1072 #endif /* HAVE_AGC */
1074 #if CONFIG_CODEC == SWCODEC
1075 audio_close_recording();
1077 audio_init_recording(0);
1078 sound_set_volume(global_settings
.volume
);
1081 /* Create new filename for recording start */
1082 rec_init_filename();
1085 /* viewport init and calculations that only needs to be done once */
1087 recbars
|= VP_SB_IGNORE_SETTING(i
);
1088 oldbars
= viewportmanager_set_statusbar(recbars
);
1092 /* top vp, 4 lines, force sys font if total screen < 6 lines
1093 NOTE: one could limit the list to 1 line and get away with 5 lines */
1095 viewport_set_defaults(v
, i
);
1096 if (viewport_get_nb_lines(v
) < 4)
1098 /* compact needs 4 lines total */
1099 v
->font
= FONT_SYSFIXED
;
1100 compact_view
[i
] = false;
1104 if (viewport_get_nb_lines(v
) < (4+2)) /*top=4,list=2*/
1105 compact_view
[i
] = true;
1107 compact_view
[i
] = false;
1109 vp_list
[i
] = *v
; /* get a copy now so it can be sized more easily */
1110 v
->height
= (font_get(v
->font
)->height
)*(compact_view
[i
] ? 3 : 4);
1112 /* list section, rest of the screen */
1113 vp_list
[i
].y
+= vp_top
[i
].height
;
1114 vp_list
[i
].height
-= vp_top
[i
].height
;
1115 screens
[i
].set_viewport(&vp_top
[i
]); /* req for next calls */
1117 screens
[i
].getstringsize("W", &w
, &h
);
1118 pm_y
[i
] = font_get(vp_top
[i
].font
)->height
* 2;
1119 trig_ypos
[i
] = font_get(vp_top
[i
].font
)->height
* 3;
1121 trig_ypos
[i
] -= (font_get(vp_top
[i
].font
)->height
)/2;
1124 /* init the bottom list */
1125 gui_synclist_init(&lists
, reclist_get_name
, NULL
, false, 1, vp_list
);
1126 gui_synclist_set_title(&lists
, NULL
, Icon_NOICON
);
1128 /* start of the loop: we stay in this loop until user quits recscreen */
1133 /* request to re-init stuff, done after settings screen */
1135 #ifdef HAVE_FMRADIO_REC
1136 /* If input changes away from FM Radio,
1137 radio will remain off when recording screen closes. */
1138 if (global_settings
.rec_source
!= prev_rec_source
1139 && prev_rec_source
== AUDIO_SRC_FMRADIO
)
1140 radio_status
= FMRADIO_OFF
;
1141 prev_rec_source
= global_settings
.rec_source
;
1147 if(global_settings
.peak_meter_clipcounter
)
1150 screens
[i
].getstringsize(str(LANG_PM_CLIPCOUNT
),
1151 &clipwidth
, &h
); /* h is same */
1152 pm_x
[i
] = clipwidth
+1;
1154 if(global_settings
.rec_trigger_mode
== TRIG_MODE_OFF
)
1155 pm_h
[i
] = font_get(vp_top
[i
].font
)->height
* 2;
1157 pm_h
[i
] = font_get(vp_top
[i
].font
)->height
;
1160 trig_width
[i
] = vp_top
[i
].width
- pm_x
[i
];
1163 #if CONFIG_CODEC == SWCODEC
1164 audio_close_recording();
1165 audio_init_recording(0);
1168 rec_init_recording_options(&rec_options
);
1169 rec_set_recording_options(&rec_options
);
1171 if(rec_create_directory() < 0)
1177 #if CONFIG_CODEC == SWCODEC && CONFIG_RTC == 0
1178 /* If format changed, a new number is required */
1179 rec_init_filename();
1184 if (global_settings
.rec_source
== AUDIO_SRC_MIC
) {
1185 agc_preset
= global_settings
.rec_agc_preset_mic
;
1186 agc_maxgain
= global_settings
.rec_agc_maxgain_mic
;
1191 agc_preset
= global_settings
.rec_agc_preset_line
;
1192 agc_maxgain
= global_settings
.rec_agc_maxgain_line
;
1194 #endif /* HAVE_AGC */
1197 update_countdown
= 0; /* Update immediately */
1199 /* populate translation table for list id -> enum */
1200 #ifdef HAVE_SPDIF_REC
1201 if(global_settings
.rec_source
== AUDIO_SRC_SPDIF
)
1203 listid_to_enum
[0] = ITEM_VOLUME_D
;
1204 #if CONFIG_CODEC == SWCODEC
1205 listid_to_enum
[1] = ITEM_SAMPLERATE_D
;
1206 listid_to_enum
[2] = ITEM_FILENAME_D
;
1208 listid_to_enum
[1] = ITEM_FILENAME_D
;
1211 gui_synclist_set_nb_items(&lists
, ITEM_COUNT_D
); /* spdif */
1215 if(HAVE_MIC_REC_((global_settings
.rec_source
== AUDIO_SRC_MIC
) || )
1216 (global_settings
.rec_channels
== 1))
1218 listid_to_enum
[0] = ITEM_VOLUME_M
;
1219 listid_to_enum
[1] = ITEM_GAIN_M
;
1221 listid_to_enum
[2] = ITEM_AGC_MODE_M
;
1222 listid_to_enum
[3] = ITEM_AGC_MAXDB_M
;
1223 listid_to_enum
[4] = ITEM_FILENAME_M
;
1225 listid_to_enum
[2] = ITEM_FILENAME_M
;
1227 gui_synclist_set_nb_items(&lists
, ITEM_COUNT_M
); /* mono */
1231 listid_to_enum
[0] = ITEM_VOLUME
;
1232 listid_to_enum
[1] = ITEM_GAIN
;
1233 listid_to_enum
[2] = ITEM_GAIN_L
;
1234 listid_to_enum
[3] = ITEM_GAIN_R
;
1236 listid_to_enum
[4] = ITEM_AGC_MODE
;
1237 listid_to_enum
[5] = ITEM_AGC_MAXDB
;
1238 listid_to_enum
[6] = ITEM_FILENAME
;
1240 listid_to_enum
[4] = ITEM_FILENAME
;
1242 gui_synclist_set_nb_items(&lists
, ITEM_COUNT
); /* stereo */
1245 gui_synclist_draw(&lists
);
1246 } /* if(done < 0) */
1248 audio_stat
= audio_status();
1250 #if (CONFIG_LED == LED_REAL)
1253 * Flash the LED while waiting to record. Turn it on while
1256 if(audio_stat
& AUDIO_STATUS_RECORD
)
1258 if (audio_stat
& AUDIO_STATUS_PAUSE
)
1260 if (--led_countdown
<= 0)
1262 led_state
= !led_state
;
1269 /* trigger is on in status TRIG_READY (no check needed) */
1275 int trig_stat
= peak_meter_trigger_status();
1277 * other trigger stati than trig_off and trig_steady
1278 * already imply that we are recording.
1280 if (trig_stat
== TRIG_STEADY
)
1282 if (--led_countdown
<= 0)
1284 led_state
= !led_state
;
1291 /* trigger is on in status TRIG_READY (no check needed) */
1295 #endif /* CONFIG_LED */
1297 /* Wait for a button a while (HZ/10) drawing the peak meter */
1298 button
= peak_meter_draw_get_btn(CONTEXT_RECSCREEN
,
1300 screen_update
, vp_top
);
1301 if (last_audio_stat
!= audio_stat
)
1303 if (audio_stat
& AUDIO_STATUS_RECORD
)
1305 rec_status
|= RCSTAT_HAVE_RECORDED
;
1307 last_audio_stat
= audio_stat
;
1311 if (recording_start_automatic
)
1313 /* simulate a button press */
1314 button
= ACTION_REC_PAUSE
;
1315 recording_start_automatic
= false;
1318 /* let list handle the button */
1319 gui_synclist_do_button(&lists
, &button
, LIST_WRAP_UNLESS_HELD
);
1324 case ACTION_SETTINGS_INC
:
1325 case ACTION_SETTINGS_INCREPEAT
:
1326 switch (listid_to_enum
[gui_synclist_get_sel_pos(&lists
)])
1329 global_settings
.volume
++;
1334 if(global_settings
.rec_source
== AUDIO_SRC_MIC
)
1336 if(global_settings
.rec_mic_gain
<
1337 sound_max(SOUND_MIC_GAIN
))
1338 global_settings
.rec_mic_gain
++;
1343 if(global_settings
.rec_left_gain
<
1344 sound_max(SOUND_LEFT_GAIN
))
1345 global_settings
.rec_left_gain
++;
1346 if(global_settings
.rec_right_gain
<
1347 sound_max(SOUND_RIGHT_GAIN
))
1348 global_settings
.rec_right_gain
++;
1352 if(global_settings
.rec_left_gain
<
1353 sound_max(SOUND_LEFT_GAIN
))
1354 global_settings
.rec_left_gain
++;
1357 if(global_settings
.rec_right_gain
<
1358 sound_max(SOUND_RIGHT_GAIN
))
1359 global_settings
.rec_right_gain
++;
1363 agc_preset
= MIN(agc_preset
+ 1, AGC_MODE_SIZE
);
1364 agc_enable
= (agc_preset
!= 0);
1366 if (global_settings
.rec_source
== AUDIO_SRC_MIC
) {
1367 global_settings
.rec_agc_preset_mic
= agc_preset
;
1368 agc_maxgain
= global_settings
.rec_agc_maxgain_mic
;
1372 global_settings
.rec_agc_preset_line
= agc_preset
;
1373 agc_maxgain
= global_settings
.rec_agc_maxgain_line
;
1376 case ITEM_AGC_MAXDB
:
1378 if (global_settings
.rec_source
== AUDIO_SRC_MIC
)
1380 agc_maxgain
= MIN(agc_maxgain
+ 1,
1381 sound_max(SOUND_MIC_GAIN
));
1382 global_settings
.rec_agc_maxgain_mic
= agc_maxgain
;
1387 agc_maxgain
= MIN(agc_maxgain
+ 1,
1388 sound_max(SOUND_LEFT_GAIN
));
1389 global_settings
.rec_agc_maxgain_line
= agc_maxgain
;
1392 #endif /* HAVE_AGC */
1395 update_countdown
= 0; /* Update immediately */
1397 case ACTION_SETTINGS_DEC
:
1398 case ACTION_SETTINGS_DECREPEAT
:
1399 switch (listid_to_enum
[gui_synclist_get_sel_pos(&lists
)])
1402 global_settings
.volume
--;
1407 if(global_settings
.rec_source
== AUDIO_SRC_MIC
)
1409 if(global_settings
.rec_mic_gain
>
1410 sound_min(SOUND_MIC_GAIN
))
1411 global_settings
.rec_mic_gain
--;
1416 if(global_settings
.rec_left_gain
>
1417 sound_min(SOUND_LEFT_GAIN
))
1418 global_settings
.rec_left_gain
--;
1419 if(global_settings
.rec_right_gain
>
1420 sound_min(SOUND_RIGHT_GAIN
))
1421 global_settings
.rec_right_gain
--;
1425 if(global_settings
.rec_left_gain
>
1426 sound_min(SOUND_LEFT_GAIN
))
1427 global_settings
.rec_left_gain
--;
1430 if(global_settings
.rec_right_gain
>
1431 sound_min(SOUND_RIGHT_GAIN
))
1432 global_settings
.rec_right_gain
--;
1436 agc_preset
= MAX(agc_preset
- 1, 0);
1437 agc_enable
= (agc_preset
!= 0);
1439 if (global_settings
.rec_source
== AUDIO_SRC_MIC
) {
1440 global_settings
.rec_agc_preset_mic
= agc_preset
;
1441 agc_maxgain
= global_settings
.rec_agc_maxgain_mic
;
1445 global_settings
.rec_agc_preset_line
= agc_preset
;
1446 agc_maxgain
= global_settings
.rec_agc_maxgain_line
;
1449 case ITEM_AGC_MAXDB
:
1451 if (global_settings
.rec_source
== AUDIO_SRC_MIC
)
1453 agc_maxgain
= MAX(agc_maxgain
- 1,
1454 sound_min(SOUND_MIC_GAIN
));
1455 global_settings
.rec_agc_maxgain_mic
= agc_maxgain
;
1459 agc_maxgain
= MAX(agc_maxgain
- 1,
1460 sound_min(SOUND_LEFT_GAIN
));
1461 global_settings
.rec_agc_maxgain_line
= agc_maxgain
;
1464 #endif /* HAVE_AGC */
1467 update_countdown
= 0; /* Update immediately */
1469 case ACTION_STD_CANCEL
:
1470 /* turn off the trigger */
1471 peak_meter_trigger(false);
1472 peak_meter_set_trigger_listener(NULL
);
1474 if(audio_stat
& AUDIO_STATUS_RECORD
)
1476 rec_command(RECORDING_CMD_STOP
);
1480 #if CONFIG_CODEC != SWCODEC
1481 peak_meter_playback(true);
1482 peak_meter_enabled
= false;
1486 update_countdown
= 0; /* Update immediately */
1488 #ifdef HAVE_REMOTE_LCD
1489 case ACTION_REC_LCD
:
1490 /* this feature exists for some h1x0/h3x0 targets that suffer
1491 from noise caused by remote LCD updates
1492 NOTE 1: this will leave the list on the remote
1493 NOTE 2: to be replaced by a global LCD_off() routine */
1494 if(remote_display_on
)
1496 /* switch to single screen, leave message on remote */
1498 screens
[1].clear_viewport();
1499 screens
[1].puts(0, 0, str(LANG_REMOTE_LCD_OFF
));
1500 screens
[1].puts(0, 1, str(LANG_REMOTE_LCD_ON
));
1501 screens
[1].update_viewport();
1505 /* remote switched on again */
1507 screen_update
= NB_SCREENS
;
1509 remote_display_on
= !remote_display_on
; /* toggle */
1510 update_countdown
= 0; /* Update immediately */
1513 case ACTION_REC_NEWFILE
:
1514 /* start recording or start a new file */
1515 if(audio_stat
& AUDIO_STATUS_RECORD
)
1517 rec_command(RECORDING_CMD_START_NEWFILE
);
1522 /* is this manual or triggered recording? */
1523 if ((global_settings
.rec_trigger_mode
== TRIG_MODE_OFF
) ||
1524 (peak_meter_trigger_status() != TRIG_OFF
))
1526 /* manual recording */
1527 rec_status
|= RCSTAT_HAVE_RECORDED
;
1528 rec_command(RECORDING_CMD_START
);
1530 if (global_settings
.talk_menu
)
1532 /* no voice possible here, but a beep */
1533 audio_beep(HZ
/2); /* longer beep on start */
1536 /* this is triggered recording */
1539 /* we don't start recording now, but enable the
1540 trigger and let the callback function
1541 trigger_listener control when the recording starts */
1542 peak_meter_trigger(true);
1543 peak_meter_set_trigger_listener(&trigger_listener
);
1546 update_countdown
= 0; /* Update immediately */
1548 case ACTION_REC_PAUSE
:
1549 /* Only act if a recording is ongoing (paused or not) */
1550 if(audio_stat
& AUDIO_STATUS_RECORD
)
1552 /* if pause button pressed, pause or resume */
1553 if(audio_stat
& AUDIO_STATUS_PAUSE
)
1555 rec_command(RECORDING_CMD_RESUME
);
1556 if (global_settings
.talk_menu
)
1558 /* no voice possible here, but a beep */
1559 audio_beep(HZ
/4); /* short beep on resume */
1564 rec_command(RECORDING_CMD_PAUSE
);
1567 update_countdown
= 0; /* Update immediately */
1569 case ACTION_STD_MENU
:
1570 #if CONFIG_CODEC == SWCODEC
1571 if(!(audio_stat
& AUDIO_STATUS_RECORD
))
1573 if(audio_stat
!= AUDIO_STATUS_RECORD
)
1576 #if (CONFIG_LED == LED_REAL)
1577 /* led is restored at begin of loop / end of function */
1580 viewportmanager_set_statusbar(oldbars
);
1581 if (recording_menu(no_source
))
1584 rec_status
|= RCSTAT_BEEN_IN_USB_MODE
;
1585 #ifdef HAVE_FMRADIO_REC
1586 radio_status
= FMRADIO_OFF
;
1592 /* the init is now done at the beginning of the loop */
1594 viewportmanager_set_statusbar(recbars
);
1598 #if CONFIG_KEYPAD == RECORDER_PAD
1600 if(audio_stat
!= AUDIO_STATUS_RECORD
)
1602 #if (CONFIG_LED == LED_REAL)
1603 /* led is restored at begin of loop / end of function */
1606 viewportmanager_set_statusbar(oldbars
);
1607 if (f2_rec_screen())
1609 rec_status
|= RCSTAT_HAVE_RECORDED
;
1613 update_countdown
= 0; /* Update immediately */
1614 viewportmanager_set_statusbar(recbars
);
1619 if(audio_stat
& AUDIO_STATUS_RECORD
)
1621 rec_command(RECORDING_CMD_START_NEWFILE
);
1626 #if (CONFIG_LED == LED_REAL)
1627 /* led is restored at begin of loop / end of function */
1630 viewportmanager_set_statusbar(oldbars
);
1631 if (f3_rec_screen())
1633 rec_status
|= RCSTAT_HAVE_RECORDED
;
1637 update_countdown
= 0; /* Update immediately */
1638 viewportmanager_set_statusbar(recbars
);
1641 #endif /* CONFIG_KEYPAD == RECORDER_PAD */
1643 case SYS_USB_CONNECTED
:
1644 /* Only accept USB connection when not recording */
1645 if(!(audio_stat
& AUDIO_STATUS_RECORD
))
1648 screens
[i
].set_viewport(NULL
);
1649 default_event_handler(SYS_USB_CONNECTED
);
1651 rec_status
|= RCSTAT_BEEN_IN_USB_MODE
;
1652 #ifdef HAVE_FMRADIO_REC
1653 radio_status
= FMRADIO_OFF
;
1657 } /*switch(button)*/
1660 peak_read
= !peak_read
;
1661 if (peak_read
) { /* every 2nd run of loop */
1663 peak_valid
= read_peak_levels(&peak_l
, &peak_r
, &balance
);
1666 /* Handle AGC every 200ms when enabled and peak data is valid */
1667 if (peak_read
&& agc_enable
&& peak_valid
)
1668 auto_gain_control(&peak_l
, &peak_r
, &balance
);
1671 seconds
= audio_recorded_time() / HZ
;
1673 /* start of vp_top drawing */
1674 if(update_countdown
-- == 0 || seconds
> last_seconds
)
1676 unsigned int dseconds
, dhours
, dminutes
;
1677 unsigned long num_recorded_bytes
, dsize
, dmb
;
1682 screens
[i
].set_viewport(&vp_top
[i
]);
1683 screens
[i
].clear_viewport();
1685 update_countdown
= 5;
1686 last_seconds
= seconds
;
1688 dseconds
= rec_timesplit_seconds();
1689 dsize
= rec_sizesplit_bytes();
1690 num_recorded_bytes
= audio_num_recorded_bytes();
1692 #if CONFIG_CODEC == SWCODEC
1693 if ((audio_stat
& AUDIO_STATUS_WARNING
)
1694 && (warning_counter
++ % WARNING_PERIOD
) < WARNING_PERIOD
/2)
1696 /* Switch back and forth displaying warning on first available
1697 line to ensure visibility - the motion should also help
1699 /* Don't use language string unless agreed upon to make this
1700 method permanent - could do something in the statusbar */
1701 snprintf(buf
, sizeof(buf
), "Warning: %08X",
1702 pcm_rec_get_warnings());
1705 #endif /* CONFIG_CODEC == SWCODEC */
1706 if ((global_settings
.rec_sizesplit
) &&
1707 (global_settings
.rec_split_method
))
1709 dmb
= dsize
/1024/1024;
1710 snprintf(buf
, sizeof(buf
), "%s %dMB",
1711 str(LANG_SPLIT_SIZE
), dmb
);
1715 hours
= seconds
/ 3600;
1716 minutes
= (seconds
- (hours
* 3600)) / 60;
1717 snprintf(buf
, sizeof(buf
), "%s %02d:%02d:%02d",
1718 str(LANG_RECORDING_TIME
),
1719 hours
, minutes
, seconds
%60);
1722 FOR_NB_ACTIVE_SCREENS(i
)
1723 screens
[i
].puts(0, 0, buf
);
1725 if(audio_stat
& AUDIO_STATUS_PRERECORD
)
1727 snprintf(buf
, sizeof(buf
), "%s...",
1728 str(LANG_RECORD_PRERECORD
));
1732 /* Display the split interval if the record timesplit
1734 if ((global_settings
.rec_timesplit
) &&
1735 !(global_settings
.rec_split_method
))
1737 /* Display the record timesplit interval rather
1738 than the file size if the record timer is active */
1739 dhours
= dseconds
/ 3600;
1740 dminutes
= (dseconds
- (dhours
* 3600)) / 60;
1741 snprintf(buf
, sizeof(buf
), "%s %02d:%02d",
1742 str(LANG_RECORDING_TIMESPLIT_REC
),
1747 output_dyn_value(buf2
, sizeof buf2
,
1750 snprintf(buf
, sizeof(buf
), "%s %s",
1751 str(LANG_RECORDING_SIZE
), buf2
);
1755 FOR_NB_ACTIVE_SCREENS(i
)
1756 screens
[i
].puts(0, 1, buf
);
1758 /* We will do file splitting regardless, either at the end of
1759 a split interval, or when the filesize approaches the 2GB
1760 FAT file size (compatibility) limit. */
1761 if ((audio_stat
&& !(global_settings
.rec_split_method
)
1762 && global_settings
.rec_timesplit
&& (seconds
>= dseconds
))
1763 || (audio_stat
&& global_settings
.rec_split_method
1764 && global_settings
.rec_sizesplit
1765 && (num_recorded_bytes
>= dsize
))
1766 || (num_recorded_bytes
>= MAX_FILE_SIZE
))
1768 if (!(global_settings
.rec_split_type
)
1769 || (num_recorded_bytes
>= MAX_FILE_SIZE
))
1771 rec_command(RECORDING_CMD_START_NEWFILE
);
1776 peak_meter_trigger(false);
1777 peak_meter_set_trigger_listener(NULL
);
1778 if( global_settings
.rec_split_type
== 1)
1779 rec_command(RECORDING_CMD_STOP
);
1781 rec_command(RECORDING_CMD_STOP_SHUTDOWN
);
1783 update_countdown
= 0;
1786 /* draw the clipcounter just in front of the peakmeter */
1787 if(global_settings
.peak_meter_clipcounter
)
1790 snprintf(clpstr
, 32, "%4d", pm_get_clipcount());
1791 FOR_NB_ACTIVE_SCREENS(i
)
1793 if(!compact_view
[i
])
1794 screens
[i
].puts(0, 2,str(LANG_PM_CLIPCOUNT
));
1795 screens
[i
].puts(0, compact_view
[i
] ? 2 : 3, clpstr
);
1803 /* draw the trigger status */
1804 if (peak_meter_trigger_status() != TRIG_OFF
)
1806 peak_meter_draw_trig(pm_x
, trig_ypos
, trig_width
,
1808 FOR_NB_ACTIVE_SCREENS(i
)
1809 screens
[i
].update_viewport_rect(pm_x
[i
], trig_ypos
[i
],
1810 trig_width
[i
] + 2, TRIG_HEIGHT
);
1815 if (global_settings
.rec_source
== AUDIO_SRC_MIC
)
1817 if(agc_maxgain
< (global_settings
.rec_mic_gain
))
1818 change_recording_gain(false, true, true);
1823 if(agc_maxgain
< (global_settings
.rec_left_gain
))
1824 change_recording_gain(false, true, false);
1825 if(agc_maxgain
< (global_settings
.rec_right_gain
))
1826 change_recording_gain(false, false, true);
1828 #endif /* HAVE_AGC */
1830 #if CONFIG_CODEC == SWCODEC
1831 #ifdef HAVE_SPDIF_REC
1832 if((global_settings
.rec_source
== AUDIO_SRC_SPDIF
) &&
1833 (prev_sample_rate
!= pcm_rec_sample_rate()))
1835 /* spdif samplerate changed */
1836 prev_sample_rate
= pcm_rec_sample_rate();
1844 /* update_list is set whenever content changes */
1845 update_list
= false;
1846 gui_synclist_draw(&lists
);
1849 /* draw peakmeter again (check if this can be removed) */
1850 FOR_NB_ACTIVE_SCREENS(i
)
1852 screens
[i
].set_viewport(&vp_top
[i
]);
1853 peak_meter_screen(&screens
[i
], pm_x
[i
], pm_y
[i
], pm_h
[i
]);
1854 screens
[i
].update();
1856 } /* display update every second */
1858 if(audio_stat
& AUDIO_STATUS_ERROR
)
1862 } /* end while(!done) */
1864 audio_stat
= audio_status();
1865 if (audio_stat
& AUDIO_STATUS_ERROR
)
1867 splash(0, str(LANG_DISK_FULL
));
1870 screens
[i
].update();
1872 #if CONFIG_CODEC == SWCODEC
1873 /* stop recording - some players like H10 freeze otherwise
1874 TO DO: find out why it freezes and fix properly */
1875 rec_command(RECORDING_CMD_STOP
);
1876 audio_close_recording();
1879 audio_error_clear();
1883 if (action_userabort(TIMEOUT_NOBLOCK
))
1890 #if CONFIG_CODEC == SWCODEC
1891 rec_command(RECORDING_CMD_STOP
);
1892 audio_close_recording();
1894 #ifdef HAVE_FMRADIO_REC
1895 if (radio_status
!= FMRADIO_OFF
)
1896 /* Restore radio playback - radio_status should be unchanged if started
1897 through fm radio screen (barring usb connect) */
1898 rec_set_source(AUDIO_SRC_FMRADIO
, (radio_status
& FMRADIO_PAUSED
) ?
1899 SRCF_FMRADIO_PAUSED
: SRCF_FMRADIO_PLAYING
);
1902 /* Go back to playback mode */
1903 rec_set_source(AUDIO_SRC_PLAYBACK
, SRCF_PLAYBACK
);
1905 /* restore talking */
1906 talk_disable(false);
1907 #else /* !SWCODEC */
1908 audio_init_playback();
1909 #endif /* CONFIG_CODEC == SWCODEC */
1911 /* make sure the trigger is really turned off */
1912 peak_meter_trigger(false);
1913 peak_meter_set_trigger_listener(NULL
);
1915 rec_status
&= ~RCSTAT_IN_RECSCREEN
;
1916 sound_settings_apply();
1919 screens
[i
].setfont(FONT_UI
);
1921 viewportmanager_set_statusbar(oldbars
);
1922 send_event(GUI_EVENT_REFRESH
, NULL
);
1924 /* if the directory was created or recording happened, make sure the
1925 browser is updated */
1926 if (rec_status
& (RCSTAT_CREATED_DIRECTORY
| RCSTAT_HAVE_RECORDED
))
1929 #if (CONFIG_STORAGE & STORAGE_ATA) && (CONFIG_LED == LED_REAL) \
1930 && !defined(SIMULATOR)
1931 ata_set_led_enabled(true);
1936 return (rec_status
& RCSTAT_BEEN_IN_USB_MODE
) != 0;
1937 } /* recording_screen */
1939 #if CONFIG_KEYPAD == RECORDER_PAD
1940 static bool f2_rec_screen(void)
1942 static const char* const freq_str
[6] =
1957 struct audio_recording_options rec_options
;
1961 screens
[i
].setfont(FONT_SYSFIXED
);
1962 screens
[i
].getstringsize("A",&w
,&h
);
1970 screens
[i
].clear_display();
1972 /* Recording quality */
1973 screens
[i
].putsxy(0, LCD_HEIGHT
/2 - h
*2,
1974 str(LANG_SYSFONT_RECORDING_QUALITY
));
1977 snprintf(buf
, sizeof(buf
), "%d", global_settings
.rec_quality
);
1980 screens
[i
].putsxy(0, LCD_HEIGHT
/2-h
, buf
);
1981 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_FastBackward
],
1982 LCD_WIDTH
/2 - 16, LCD_HEIGHT
/2 - 4, 7, 8);
1986 snprintf(buf
, sizeof buf
, "%s:", str(LANG_SYSFONT_RECORDING_FREQUENCY
));
1987 ptr
= freq_str
[global_settings
.rec_frequency
];
1990 screens
[i
].getstringsize(buf
,&w
,&h
);
1991 screens
[i
].putsxy((LCD_WIDTH
-w
)/2, LCD_HEIGHT
- h
*2, buf
);
1992 screens
[i
].getstringsize(ptr
, &w
, &h
);
1993 screens
[i
].putsxy((LCD_WIDTH
-w
)/2, LCD_HEIGHT
- h
, ptr
);
1994 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_DownArrow
],
1995 LCD_WIDTH
/2 - 3, LCD_HEIGHT
- h
*3, 7, 8);
1999 switch ( global_settings
.rec_channels
) {
2001 ptr
= str(LANG_SYSFONT_CHANNEL_STEREO
);
2005 ptr
= str(LANG_SYSFONT_CHANNEL_MONO
);
2011 screens
[i
].getstringsize(str(LANG_SYSFONT_CHANNELS
), &w
, &h
);
2012 screens
[i
].putsxy(LCD_WIDTH
- w
, LCD_HEIGHT
/2 - h
*2,
2013 str(LANG_SYSFONT_CHANNELS
));
2014 screens
[i
].getstringsize(str(LANG_SYSFONT_MODE
), &w
, &h
);
2015 screens
[i
].putsxy(LCD_WIDTH
- w
, LCD_HEIGHT
/2 - h
,
2016 str(LANG_SYSFONT_MODE
));
2017 screens
[i
].getstringsize(ptr
, &w
, &h
);
2018 screens
[i
].putsxy(LCD_WIDTH
- w
, LCD_HEIGHT
/2, ptr
);
2019 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_FastForward
],
2020 LCD_WIDTH
/2 + 8, LCD_HEIGHT
/2 - 4, 7, 8);
2022 screens
[i
].update();
2025 button
= button_get(true);
2028 case BUTTON_F2
| BUTTON_LEFT
:
2029 global_settings
.rec_quality
++;
2030 if(global_settings
.rec_quality
> 7)
2031 global_settings
.rec_quality
= 0;
2036 case BUTTON_F2
| BUTTON_DOWN
:
2037 global_settings
.rec_frequency
++;
2038 if(global_settings
.rec_frequency
> 5)
2039 global_settings
.rec_frequency
= 0;
2044 case BUTTON_F2
| BUTTON_RIGHT
:
2045 global_settings
.rec_channels
++;
2046 if(global_settings
.rec_channels
> 1)
2047 global_settings
.rec_channels
= 0;
2051 case BUTTON_F2
| BUTTON_REL
:
2057 case BUTTON_F2
| BUTTON_REPEAT
:
2062 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
2068 rec_init_recording_options(&rec_options
);
2069 rec_set_recording_options(&rec_options
);
2075 screens
[i
].setfont(FONT_UI
);
2080 static bool f3_rec_screen(void)
2086 const char *src_str
[] =
2088 str(LANG_SYSFONT_RECORDING_SRC_MIC
),
2089 str(LANG_SYSFONT_LINE_IN
),
2090 str(LANG_SYSFONT_RECORDING_SRC_DIGITAL
)
2092 struct audio_recording_options rec_options
;
2096 screens
[i
].setfont(FONT_SYSFIXED
);
2097 screens
[i
].getstringsize("A",&w
,&h
);
2101 const char* ptr
= src_str
[global_settings
.rec_source
];
2104 screens
[i
].clear_display();
2106 /* Recording source */
2107 screens
[i
].putsxy(0, LCD_HEIGHT
/2 - h
*2,
2108 str(LANG_SYSFONT_RECORDING_SOURCE
));
2110 screens
[i
].getstringsize(ptr
, &w
, &h
);
2111 screens
[i
].putsxy(0, LCD_HEIGHT
/2-h
, ptr
);
2112 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_FastBackward
],
2113 LCD_WIDTH
/2 - 16, LCD_HEIGHT
/2 - 4, 7, 8);
2117 ptr
= str(LANG_SYSFONT_RECORD_TRIGGER
);
2120 screens
[i
].getstringsize(ptr
,&w
,&h
);
2121 screens
[i
].putsxy((LCD_WIDTH
-w
)/2, LCD_HEIGHT
- h
*2, ptr
);
2122 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_DownArrow
],
2123 LCD_WIDTH
/2 - 3, LCD_HEIGHT
- h
*3, 7, 8);
2125 screens
[i
].update();
2128 button
= button_get(true);
2131 case BUTTON_F3
| BUTTON_DOWN
:
2134 settings_apply_trigger();
2140 case BUTTON_F3
| BUTTON_LEFT
:
2141 global_settings
.rec_source
++;
2142 if(global_settings
.rec_source
> AUDIO_SRC_MAX
)
2143 global_settings
.rec_source
= 0;
2147 case BUTTON_F3
| BUTTON_REL
:
2153 case BUTTON_F3
| BUTTON_REPEAT
:
2158 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
2164 rec_init_recording_options(&rec_options
);
2165 rec_set_recording_options(&rec_options
);
2171 screens
[i
].setfont(FONT_UI
);
2175 #endif /* CONFIG_KEYPAD == RECORDER_PAD */
2177 #if CONFIG_CODEC == SWCODEC
2178 void audio_beep(int duration
)
2185 /* stubs for recording sim */
2186 void audio_init_recording(unsigned int buffer_offset
)
2188 buffer_offset
= buffer_offset
;
2191 void audio_close_recording(void)
2195 unsigned long pcm_rec_get_warnings(void)
2200 unsigned long pcm_rec_sample_rate(void)
2205 unsigned long audio_recorded_time(void)
2210 unsigned long audio_num_recorded_bytes(void)
2212 return 5 * 1024 * 1024;
2215 void rec_set_source(int source
, unsigned flags
)
2221 void audio_set_recording_options(struct audio_recording_options
*options
)
2226 void audio_set_recording_gain(int left
, int right
, int type
)
2233 void audio_record(const char *filename
)
2235 filename
= filename
;
2238 void audio_new_file(const char *filename
)
2240 filename
= filename
;
2243 void audio_stop_recording(void)
2247 void audio_pause_recording(void)
2251 void audio_resume_recording(void)
2255 #endif /* #ifdef SIMULATOR */
2256 #endif /* #ifdef CONFIG_CODEC == SWCODEC */
2258 #endif /* HAVE_RECORDING */