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"
56 #include "statusbar.h"
58 #include "sound_menu.h"
59 #include "timefuncs.h"
69 #if (CONFIG_STORAGE & STORAGE_ATA) && (CONFIG_LED == LED_REAL) \
70 && !defined(SIMULATOR)
74 #include "screen_access.h"
77 #include "sound_menu.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 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 strncpy(buffer
, str(LANG_RECORDING_FILENAME
), buffer_len
);
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 static const unsigned char *byte_units
[] = {
1040 ID2P(LANG_KILOBYTE
),
1041 ID2P(LANG_MEGABYTE
),
1045 struct audio_recording_options rec_options
;
1046 rec_status
= RCSTAT_IN_RECSCREEN
;
1048 #if (CONFIG_STORAGE & STORAGE_ATA) && (CONFIG_LED == LED_REAL) \
1049 && !defined(SIMULATOR)
1050 ata_set_led_enabled(false);
1053 #if CONFIG_CODEC == SWCODEC
1054 /* recording_menu gets messed up: so prevent manus talking */
1056 /* audio_init_recording stops anything playing when it takes the audio
1059 /* Yes, we use the D/A for monitoring */
1060 peak_meter_enabled
= true;
1061 peak_meter_playback(true);
1065 peak_meter_get_peakhold(&peak_l
, &peak_r
);
1068 pm_reset_clipcount();
1069 pm_activate_clipcount(false);
1070 settings_apply_trigger();
1073 agc_preset_str
[0] = str(LANG_OFF
);
1074 agc_preset_str
[1] = str(LANG_AGC_SAFETY
);
1075 agc_preset_str
[2] = str(LANG_AGC_LIVE
);
1076 agc_preset_str
[3] = str(LANG_AGC_DJSET
);
1077 agc_preset_str
[4] = str(LANG_AGC_MEDIUM
);
1078 agc_preset_str
[5] = str(LANG_AGC_VOICE
);
1079 #endif /* HAVE_AGC */
1081 #if CONFIG_CODEC == SWCODEC
1082 audio_close_recording();
1084 audio_init_recording(0);
1085 sound_set_volume(global_settings
.volume
);
1088 /* Create new filename for recording start */
1089 rec_init_filename();
1092 /* viewport init and calculations that only needs to be done once */
1094 recbars
|= VP_SB_IGNORE_SETTING(i
);
1095 oldbars
= viewportmanager_set_statusbar(recbars
);
1099 /* top vp, 4 lines, force sys font if total screen < 6 lines
1100 NOTE: one could limit the list to 1 line and get away with 5 lines */
1102 viewport_set_defaults(v
, i
);
1103 if (viewport_get_nb_lines(v
) < 4)
1105 /* compact needs 4 lines total */
1106 v
->font
= FONT_SYSFIXED
;
1107 compact_view
[i
] = false;
1111 if (viewport_get_nb_lines(v
) < (4+2)) /*top=4,list=2*/
1112 compact_view
[i
] = true;
1114 compact_view
[i
] = false;
1116 v
->height
= (font_get(v
->font
)->height
)*(compact_view
[i
] ? 3 : 4);
1118 /* list section, rest of the screen */
1120 viewport_set_defaults(v
, i
);
1121 v
->font
= vp_top
[i
].font
;
1122 v
->y
= vp_top
[i
].y
+ vp_top
[i
].height
;
1123 v
->height
= screens
[i
].lcdheight
- v
->y
; /* the rest */
1124 screens
[i
].set_viewport(&vp_top
[i
]); /* req for next calls */
1126 screens
[i
].getstringsize("W", &w
, &h
);
1127 pm_y
[i
] = font_get(vp_top
[i
].font
)->height
* 2;
1128 trig_ypos
[i
] = font_get(vp_top
[i
].font
)->height
* 3;
1130 trig_ypos
[i
] -= (font_get(vp_top
[i
].font
)->height
)/2;
1133 /* init the bottom list */
1134 gui_synclist_init(&lists
, reclist_get_name
, NULL
, false, 1, vp_list
);
1135 gui_synclist_set_title(&lists
, NULL
, Icon_NOICON
);
1137 /* start of the loop: we stay in this loop until user quits recscreen */
1142 /* request to re-init stuff, done after settings screen */
1144 #ifdef HAVE_FMRADIO_REC
1145 /* If input changes away from FM Radio,
1146 radio will remain off when recording screen closes. */
1147 if (global_settings
.rec_source
!= prev_rec_source
1148 && prev_rec_source
== AUDIO_SRC_FMRADIO
)
1149 radio_status
= FMRADIO_OFF
;
1150 prev_rec_source
= global_settings
.rec_source
;
1156 if(global_settings
.peak_meter_clipcounter
)
1159 screens
[i
].getstringsize(str(LANG_PM_CLIPCOUNT
),
1160 &clipwidth
, &h
); /* h is same */
1161 pm_x
[i
] = clipwidth
+1;
1163 if(global_settings
.rec_trigger_mode
== TRIG_MODE_OFF
)
1164 pm_h
[i
] = font_get(vp_top
[i
].font
)->height
* 2;
1166 pm_h
[i
] = font_get(vp_top
[i
].font
)->height
;
1169 trig_width
[i
] = vp_top
[i
].width
- pm_x
[i
];
1172 #if CONFIG_CODEC == SWCODEC
1173 audio_close_recording();
1174 audio_init_recording(0);
1177 rec_init_recording_options(&rec_options
);
1178 rec_set_recording_options(&rec_options
);
1180 if(rec_create_directory() < 0)
1186 #if CONFIG_CODEC == SWCODEC && CONFIG_RTC == 0
1187 /* If format changed, a new number is required */
1188 rec_init_filename();
1193 if (global_settings
.rec_source
== AUDIO_SRC_MIC
) {
1194 agc_preset
= global_settings
.rec_agc_preset_mic
;
1195 agc_maxgain
= global_settings
.rec_agc_maxgain_mic
;
1200 agc_preset
= global_settings
.rec_agc_preset_line
;
1201 agc_maxgain
= global_settings
.rec_agc_maxgain_line
;
1203 #endif /* HAVE_AGC */
1206 update_countdown
= 0; /* Update immediately */
1208 /* populate translation table for list id -> enum */
1209 #ifdef HAVE_SPDIF_REC
1210 if(global_settings
.rec_source
== AUDIO_SRC_SPDIF
)
1212 listid_to_enum
[0] = ITEM_VOLUME_D
;
1213 #if CONFIG_CODEC == SWCODEC
1214 listid_to_enum
[1] = ITEM_SAMPLERATE_D
;
1215 listid_to_enum
[2] = ITEM_FILENAME_D
;
1217 listid_to_enum
[1] = ITEM_FILENAME_D
;
1220 gui_synclist_set_nb_items(&lists
, ITEM_COUNT_D
); /* spdif */
1224 if(HAVE_MIC_REC_((global_settings
.rec_source
== AUDIO_SRC_MIC
) || )
1225 (global_settings
.rec_channels
== 1))
1227 listid_to_enum
[0] = ITEM_VOLUME_M
;
1228 listid_to_enum
[1] = ITEM_GAIN_M
;
1230 listid_to_enum
[2] = ITEM_AGC_MODE_M
;
1231 listid_to_enum
[3] = ITEM_AGC_MAXDB_M
;
1232 listid_to_enum
[4] = ITEM_FILENAME_M
;
1234 listid_to_enum
[2] = ITEM_FILENAME_M
;
1236 gui_synclist_set_nb_items(&lists
, ITEM_COUNT_M
); /* mono */
1240 listid_to_enum
[0] = ITEM_VOLUME
;
1241 listid_to_enum
[1] = ITEM_GAIN
;
1242 listid_to_enum
[2] = ITEM_GAIN_L
;
1243 listid_to_enum
[3] = ITEM_GAIN_R
;
1245 listid_to_enum
[4] = ITEM_AGC_MODE
;
1246 listid_to_enum
[5] = ITEM_AGC_MAXDB
;
1247 listid_to_enum
[6] = ITEM_FILENAME
;
1249 listid_to_enum
[4] = ITEM_FILENAME
;
1251 gui_synclist_set_nb_items(&lists
, ITEM_COUNT
); /* stereo */
1254 gui_synclist_draw(&lists
);
1255 } /* if(done < 0) */
1257 audio_stat
= audio_status();
1259 #if (CONFIG_LED == LED_REAL)
1262 * Flash the LED while waiting to record. Turn it on while
1265 if(audio_stat
& AUDIO_STATUS_RECORD
)
1267 if (audio_stat
& AUDIO_STATUS_PAUSE
)
1269 if (--led_countdown
<= 0)
1271 led_state
= !led_state
;
1278 /* trigger is on in status TRIG_READY (no check needed) */
1284 int trig_stat
= peak_meter_trigger_status();
1286 * other trigger stati than trig_off and trig_steady
1287 * already imply that we are recording.
1289 if (trig_stat
== TRIG_STEADY
)
1291 if (--led_countdown
<= 0)
1293 led_state
= !led_state
;
1300 /* trigger is on in status TRIG_READY (no check needed) */
1304 #endif /* CONFIG_LED */
1306 /* Wait for a button a while (HZ/10) drawing the peak meter */
1307 button
= peak_meter_draw_get_btn(CONTEXT_RECSCREEN
,
1309 screen_update
, vp_top
);
1310 if (last_audio_stat
!= audio_stat
)
1312 if (audio_stat
& AUDIO_STATUS_RECORD
)
1314 rec_status
|= RCSTAT_HAVE_RECORDED
;
1316 last_audio_stat
= audio_stat
;
1320 if (recording_start_automatic
)
1322 /* simulate a button press */
1323 button
= ACTION_REC_PAUSE
;
1324 recording_start_automatic
= false;
1327 /* let list handle the button */
1328 gui_synclist_do_button(&lists
, &button
, LIST_WRAP_UNLESS_HELD
);
1333 case ACTION_SETTINGS_INC
:
1334 case ACTION_SETTINGS_INCREPEAT
:
1335 switch (listid_to_enum
[gui_synclist_get_sel_pos(&lists
)])
1338 global_settings
.volume
++;
1343 if(global_settings
.rec_source
== AUDIO_SRC_MIC
)
1345 if(global_settings
.rec_mic_gain
<
1346 sound_max(SOUND_MIC_GAIN
))
1347 global_settings
.rec_mic_gain
++;
1352 if(global_settings
.rec_left_gain
<
1353 sound_max(SOUND_LEFT_GAIN
))
1354 global_settings
.rec_left_gain
++;
1355 if(global_settings
.rec_right_gain
<
1356 sound_max(SOUND_RIGHT_GAIN
))
1357 global_settings
.rec_right_gain
++;
1361 if(global_settings
.rec_left_gain
<
1362 sound_max(SOUND_LEFT_GAIN
))
1363 global_settings
.rec_left_gain
++;
1366 if(global_settings
.rec_right_gain
<
1367 sound_max(SOUND_RIGHT_GAIN
))
1368 global_settings
.rec_right_gain
++;
1372 agc_preset
= MIN(agc_preset
+ 1, AGC_MODE_SIZE
);
1373 agc_enable
= (agc_preset
!= 0);
1375 if (global_settings
.rec_source
== AUDIO_SRC_MIC
) {
1376 global_settings
.rec_agc_preset_mic
= agc_preset
;
1377 agc_maxgain
= global_settings
.rec_agc_maxgain_mic
;
1381 global_settings
.rec_agc_preset_line
= agc_preset
;
1382 agc_maxgain
= global_settings
.rec_agc_maxgain_line
;
1385 case ITEM_AGC_MAXDB
:
1387 if (global_settings
.rec_source
== AUDIO_SRC_MIC
)
1389 agc_maxgain
= MIN(agc_maxgain
+ 1,
1390 sound_max(SOUND_MIC_GAIN
));
1391 global_settings
.rec_agc_maxgain_mic
= agc_maxgain
;
1396 agc_maxgain
= MIN(agc_maxgain
+ 1,
1397 sound_max(SOUND_LEFT_GAIN
));
1398 global_settings
.rec_agc_maxgain_line
= agc_maxgain
;
1401 #endif /* HAVE_AGC */
1404 update_countdown
= 0; /* Update immediately */
1406 case ACTION_SETTINGS_DEC
:
1407 case ACTION_SETTINGS_DECREPEAT
:
1408 switch (listid_to_enum
[gui_synclist_get_sel_pos(&lists
)])
1411 global_settings
.volume
--;
1416 if(global_settings
.rec_source
== AUDIO_SRC_MIC
)
1418 if(global_settings
.rec_mic_gain
>
1419 sound_min(SOUND_MIC_GAIN
))
1420 global_settings
.rec_mic_gain
--;
1425 if(global_settings
.rec_left_gain
>
1426 sound_min(SOUND_LEFT_GAIN
))
1427 global_settings
.rec_left_gain
--;
1428 if(global_settings
.rec_right_gain
>
1429 sound_min(SOUND_RIGHT_GAIN
))
1430 global_settings
.rec_right_gain
--;
1434 if(global_settings
.rec_left_gain
>
1435 sound_min(SOUND_LEFT_GAIN
))
1436 global_settings
.rec_left_gain
--;
1439 if(global_settings
.rec_right_gain
>
1440 sound_min(SOUND_RIGHT_GAIN
))
1441 global_settings
.rec_right_gain
--;
1445 agc_preset
= MAX(agc_preset
- 1, 0);
1446 agc_enable
= (agc_preset
!= 0);
1448 if (global_settings
.rec_source
== AUDIO_SRC_MIC
) {
1449 global_settings
.rec_agc_preset_mic
= agc_preset
;
1450 agc_maxgain
= global_settings
.rec_agc_maxgain_mic
;
1454 global_settings
.rec_agc_preset_line
= agc_preset
;
1455 agc_maxgain
= global_settings
.rec_agc_maxgain_line
;
1458 case ITEM_AGC_MAXDB
:
1460 if (global_settings
.rec_source
== AUDIO_SRC_MIC
)
1462 agc_maxgain
= MAX(agc_maxgain
- 1,
1463 sound_min(SOUND_MIC_GAIN
));
1464 global_settings
.rec_agc_maxgain_mic
= agc_maxgain
;
1468 agc_maxgain
= MAX(agc_maxgain
- 1,
1469 sound_min(SOUND_LEFT_GAIN
));
1470 global_settings
.rec_agc_maxgain_line
= agc_maxgain
;
1473 #endif /* HAVE_AGC */
1476 update_countdown
= 0; /* Update immediately */
1478 case ACTION_STD_CANCEL
:
1479 /* turn off the trigger */
1480 peak_meter_trigger(false);
1481 peak_meter_set_trigger_listener(NULL
);
1483 if(audio_stat
& AUDIO_STATUS_RECORD
)
1485 rec_command(RECORDING_CMD_STOP
);
1489 #if CONFIG_CODEC != SWCODEC
1490 peak_meter_playback(true);
1491 peak_meter_enabled
= false;
1495 update_countdown
= 0; /* Update immediately */
1497 #ifdef HAVE_REMOTE_LCD
1498 case ACTION_REC_LCD
:
1499 /* this feature exists for some h1x0/h3x0 targets that suffer
1500 from noise caused by remote LCD updates
1501 NOTE 1: this will leave the list on the remote
1502 NOTE 2: to be replaced by a global LCD_off() routine */
1503 if(remote_display_on
)
1505 /* switch to single screen, leave message on remote */
1507 screens
[1].clear_viewport();
1508 screens
[1].puts(0, 0, str(LANG_REMOTE_LCD_OFF
));
1509 screens
[1].puts(0, 1, str(LANG_REMOTE_LCD_ON
));
1510 screens
[1].update_viewport();
1514 /* remote switched on again */
1516 screen_update
= NB_SCREENS
;
1518 remote_display_on
= !remote_display_on
; /* toggle */
1519 update_countdown
= 0; /* Update immediately */
1522 case ACTION_REC_PAUSE
:
1523 case ACTION_REC_NEWFILE
:
1524 /* Only act if the mpeg is stopped */
1525 if(!(audio_stat
& AUDIO_STATUS_RECORD
))
1527 /* is this manual or triggered recording? */
1528 if ((global_settings
.rec_trigger_mode
== TRIG_MODE_OFF
) ||
1529 (peak_meter_trigger_status() != TRIG_OFF
))
1531 /* manual recording */
1532 rec_status
|= RCSTAT_HAVE_RECORDED
;
1533 rec_command(RECORDING_CMD_START
);
1535 if (global_settings
.talk_menu
)
1537 /* no voice possible here, but a beep */
1538 audio_beep(HZ
/2); /* longer beep on start */
1541 /* this is triggered recording */
1544 /* we don't start recording now, but enable the
1545 trigger and let the callback function
1546 trigger_listener control when the recording starts */
1547 peak_meter_trigger(true);
1548 peak_meter_set_trigger_listener(&trigger_listener
);
1553 /*if new file button pressed, start new file */
1554 if (button
== ACTION_REC_NEWFILE
)
1556 rec_command(RECORDING_CMD_START_NEWFILE
);
1560 /* if pause button pressed, pause or resume */
1562 if(audio_stat
& AUDIO_STATUS_PAUSE
)
1564 rec_command(RECORDING_CMD_RESUME
);
1565 if (global_settings
.talk_menu
)
1567 /* no voice possible here, but a beep */
1568 audio_beep(HZ
/4); /* short beep on resume */
1573 rec_command(RECORDING_CMD_PAUSE
);
1577 update_countdown
= 0; /* Update immediately */
1579 case ACTION_STD_MENU
:
1580 #if CONFIG_CODEC == SWCODEC
1581 if(!(audio_stat
& AUDIO_STATUS_RECORD
))
1583 if(audio_stat
!= AUDIO_STATUS_RECORD
)
1586 #if (CONFIG_LED == LED_REAL)
1587 /* led is restored at begin of loop / end of function */
1590 viewportmanager_set_statusbar(oldbars
);
1591 if (recording_menu(no_source
))
1594 rec_status
|= RCSTAT_BEEN_IN_USB_MODE
;
1595 #ifdef HAVE_FMRADIO_REC
1596 radio_status
= FMRADIO_OFF
;
1602 /* the init is now done at the beginning of the loop */
1604 viewportmanager_set_statusbar(recbars
);
1608 #if CONFIG_KEYPAD == RECORDER_PAD
1610 if(audio_stat
!= AUDIO_STATUS_RECORD
)
1612 #if (CONFIG_LED == LED_REAL)
1613 /* led is restored at begin of loop / end of function */
1616 viewportmanager_set_statusbar(oldbars
);
1617 if (f2_rec_screen())
1619 rec_status
|= RCSTAT_HAVE_RECORDED
;
1623 update_countdown
= 0; /* Update immediately */
1624 viewportmanager_set_statusbar(recbars
);
1629 if(audio_stat
& AUDIO_STATUS_RECORD
)
1631 rec_command(RECORDING_CMD_START_NEWFILE
);
1636 #if (CONFIG_LED == LED_REAL)
1637 /* led is restored at begin of loop / end of function */
1640 viewportmanager_set_statusbar(oldbars
);
1641 if (f3_rec_screen())
1643 rec_status
|= RCSTAT_HAVE_RECORDED
;
1647 update_countdown
= 0; /* Update immediately */
1648 viewportmanager_set_statusbar(recbars
);
1651 #endif /* CONFIG_KEYPAD == RECORDER_PAD */
1653 case SYS_USB_CONNECTED
:
1654 /* Only accept USB connection when not recording */
1655 if(!(audio_stat
& AUDIO_STATUS_RECORD
))
1658 screens
[i
].set_viewport(NULL
);
1659 default_event_handler(SYS_USB_CONNECTED
);
1661 rec_status
|= RCSTAT_BEEN_IN_USB_MODE
;
1662 #ifdef HAVE_FMRADIO_REC
1663 radio_status
= FMRADIO_OFF
;
1667 } /*switch(button)*/
1670 peak_read
= !peak_read
;
1671 if (peak_read
) { /* every 2nd run of loop */
1673 peak_valid
= read_peak_levels(&peak_l
, &peak_r
, &balance
);
1676 /* Handle AGC every 200ms when enabled and peak data is valid */
1677 if (peak_read
&& agc_enable
&& peak_valid
)
1678 auto_gain_control(&peak_l
, &peak_r
, &balance
);
1681 seconds
= audio_recorded_time() / HZ
;
1683 /* start of vp_top drawing */
1684 if(update_countdown
-- == 0 || seconds
> last_seconds
)
1686 unsigned int dseconds
, dhours
, dminutes
;
1687 unsigned long num_recorded_bytes
, dsize
, dmb
;
1692 screens
[i
].set_viewport(&vp_top
[i
]);
1693 screens
[i
].clear_viewport();
1695 update_countdown
= 5;
1696 last_seconds
= seconds
;
1698 dseconds
= rec_timesplit_seconds();
1699 dsize
= rec_sizesplit_bytes();
1700 num_recorded_bytes
= audio_num_recorded_bytes();
1702 #if CONFIG_CODEC == SWCODEC
1703 if ((audio_stat
& AUDIO_STATUS_WARNING
)
1704 && (warning_counter
++ % WARNING_PERIOD
) < WARNING_PERIOD
/2)
1706 /* Switch back and forth displaying warning on first available
1707 line to ensure visibility - the motion should also help
1709 /* Don't use language string unless agreed upon to make this
1710 method permanent - could do something in the statusbar */
1711 snprintf(buf
, sizeof(buf
), "Warning: %08X",
1712 pcm_rec_get_warnings());
1715 #endif /* CONFIG_CODEC == SWCODEC */
1716 if ((global_settings
.rec_sizesplit
) &&
1717 (global_settings
.rec_split_method
))
1719 dmb
= dsize
/1024/1024;
1720 snprintf(buf
, sizeof(buf
), "%s %dMB",
1721 str(LANG_SPLIT_SIZE
), dmb
);
1725 hours
= seconds
/ 3600;
1726 minutes
= (seconds
- (hours
* 3600)) / 60;
1727 snprintf(buf
, sizeof(buf
), "%s %02d:%02d:%02d",
1728 str(LANG_RECORDING_TIME
),
1729 hours
, minutes
, seconds
%60);
1732 FOR_NB_ACTIVE_SCREENS(i
)
1733 screens
[i
].puts(0, 0, buf
);
1735 if(audio_stat
& AUDIO_STATUS_PRERECORD
)
1737 snprintf(buf
, sizeof(buf
), "%s...",
1738 str(LANG_RECORD_PRERECORD
));
1742 /* Display the split interval if the record timesplit
1744 if ((global_settings
.rec_timesplit
) &&
1745 !(global_settings
.rec_split_method
))
1747 /* Display the record timesplit interval rather
1748 than the file size if the record timer is active */
1749 dhours
= dseconds
/ 3600;
1750 dminutes
= (dseconds
- (dhours
* 3600)) / 60;
1751 snprintf(buf
, sizeof(buf
), "%s %02d:%02d",
1752 str(LANG_RECORDING_TIMESPLIT_REC
),
1757 output_dyn_value(buf2
, sizeof buf2
,
1760 snprintf(buf
, sizeof(buf
), "%s %s",
1761 str(LANG_RECORDING_SIZE
), buf2
);
1765 FOR_NB_ACTIVE_SCREENS(i
)
1766 screens
[i
].puts(0, 1, buf
);
1768 /* We will do file splitting regardless, either at the end of
1769 a split interval, or when the filesize approaches the 2GB
1770 FAT file size (compatibility) limit. */
1771 if ((audio_stat
&& !(global_settings
.rec_split_method
)
1772 && global_settings
.rec_timesplit
&& (seconds
>= dseconds
))
1773 || (audio_stat
&& global_settings
.rec_split_method
1774 && global_settings
.rec_sizesplit
1775 && (num_recorded_bytes
>= dsize
))
1776 || (num_recorded_bytes
>= MAX_FILE_SIZE
))
1778 if (!(global_settings
.rec_split_type
)
1779 || (num_recorded_bytes
>= MAX_FILE_SIZE
))
1781 rec_command(RECORDING_CMD_START_NEWFILE
);
1786 peak_meter_trigger(false);
1787 peak_meter_set_trigger_listener(NULL
);
1788 if( global_settings
.rec_split_type
== 1)
1789 rec_command(RECORDING_CMD_STOP
);
1791 rec_command(RECORDING_CMD_STOP_SHUTDOWN
);
1793 update_countdown
= 0;
1796 /* draw the clipcounter just in front of the peakmeter */
1797 if(global_settings
.peak_meter_clipcounter
)
1800 snprintf(clpstr
, 32, "%4d", pm_get_clipcount());
1801 FOR_NB_ACTIVE_SCREENS(i
)
1803 if(!compact_view
[i
])
1804 screens
[i
].puts(0, 2,str(LANG_PM_CLIPCOUNT
));
1805 screens
[i
].puts(0, compact_view
[i
] ? 2 : 3, clpstr
);
1813 /* draw the trigger status */
1814 if (peak_meter_trigger_status() != TRIG_OFF
)
1816 peak_meter_draw_trig(pm_x
, trig_ypos
, trig_width
,
1818 FOR_NB_ACTIVE_SCREENS(i
)
1819 screens
[i
].update_viewport_rect(pm_x
[i
], trig_ypos
[i
],
1820 trig_width
[i
] + 2, TRIG_HEIGHT
);
1825 if (global_settings
.rec_source
== AUDIO_SRC_MIC
)
1827 if(agc_maxgain
< (global_settings
.rec_mic_gain
))
1828 change_recording_gain(false, true, true);
1833 if(agc_maxgain
< (global_settings
.rec_left_gain
))
1834 change_recording_gain(false, true, false);
1835 if(agc_maxgain
< (global_settings
.rec_right_gain
))
1836 change_recording_gain(false, false, true);
1838 #endif /* HAVE_AGC */
1840 #if CONFIG_CODEC == SWCODEC
1841 #ifdef HAVE_SPDIF_REC
1842 if((global_settings
.rec_source
== AUDIO_SRC_SPDIF
) &&
1843 (prev_sample_rate
!= pcm_rec_sample_rate()))
1845 /* spdif samplerate changed */
1846 prev_sample_rate
= pcm_rec_sample_rate();
1854 /* update_list is set whenever content changes */
1855 update_list
= false;
1856 gui_synclist_draw(&lists
);
1859 /* draw peakmeter again (check if this can be removed) */
1860 FOR_NB_ACTIVE_SCREENS(i
)
1862 screens
[i
].set_viewport(&vp_top
[i
]);
1863 peak_meter_screen(&screens
[i
], pm_x
[i
], pm_y
[i
], pm_h
[i
]);
1864 screens
[i
].update();
1866 } /* display update every second */
1868 if(audio_stat
& AUDIO_STATUS_ERROR
)
1872 } /* end while(!done) */
1874 audio_stat
= audio_status();
1875 if (audio_stat
& AUDIO_STATUS_ERROR
)
1877 splash(0, str(LANG_DISK_FULL
));
1880 screens
[i
].update();
1882 #if CONFIG_CODEC == SWCODEC
1883 /* stop recording - some players like H10 freeze otherwise
1884 TO DO: find out why it freezes and fix properly */
1885 rec_command(RECORDING_CMD_STOP
);
1886 audio_close_recording();
1889 audio_error_clear();
1893 if (action_userabort(TIMEOUT_NOBLOCK
))
1900 #if CONFIG_CODEC == SWCODEC
1901 rec_command(RECORDING_CMD_STOP
);
1902 audio_close_recording();
1904 #ifdef HAVE_FMRADIO_REC
1905 if (radio_status
!= FMRADIO_OFF
)
1906 /* Restore radio playback - radio_status should be unchanged if started
1907 through fm radio screen (barring usb connect) */
1908 rec_set_source(AUDIO_SRC_FMRADIO
, (radio_status
& FMRADIO_PAUSED
) ?
1909 SRCF_FMRADIO_PAUSED
: SRCF_FMRADIO_PLAYING
);
1912 /* Go back to playback mode */
1913 rec_set_source(AUDIO_SRC_PLAYBACK
, SRCF_PLAYBACK
);
1915 /* restore talking */
1916 talk_disable(false);
1917 #else /* !SWCODEC */
1918 audio_init_playback();
1919 #endif /* CONFIG_CODEC == SWCODEC */
1921 /* make sure the trigger is really turned off */
1922 peak_meter_trigger(false);
1923 peak_meter_set_trigger_listener(NULL
);
1925 rec_status
&= ~RCSTAT_IN_RECSCREEN
;
1926 sound_settings_apply();
1928 viewportmanager_set_statusbar(oldbars
);
1930 screens
[i
].setfont(FONT_UI
);
1932 /* if the directory was created or recording happened, make sure the
1933 browser is updated */
1934 if (rec_status
& (RCSTAT_CREATED_DIRECTORY
| RCSTAT_HAVE_RECORDED
))
1937 #if (CONFIG_STORAGE & STORAGE_ATA) && (CONFIG_LED == LED_REAL) \
1938 && !defined(SIMULATOR)
1939 ata_set_led_enabled(true);
1944 return (rec_status
& RCSTAT_BEEN_IN_USB_MODE
) != 0;
1945 } /* recording_screen */
1947 #if CONFIG_KEYPAD == RECORDER_PAD
1948 static bool f2_rec_screen(void)
1950 static const char* const freq_str
[6] =
1965 struct audio_recording_options rec_options
;
1969 screens
[i
].setfont(FONT_SYSFIXED
);
1970 screens
[i
].getstringsize("A",&w
,&h
);
1974 const char* ptr
=NULL
;
1978 screens
[i
].clear_display();
1980 /* Recording quality */
1981 screens
[i
].putsxy(0, LCD_HEIGHT
/2 - h
*2,
1982 str(LANG_SYSFONT_RECORDING_QUALITY
));
1985 snprintf(buf
, sizeof(buf
), "%d", global_settings
.rec_quality
);
1988 screens
[i
].putsxy(0, LCD_HEIGHT
/2-h
, buf
);
1989 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_FastBackward
],
1990 LCD_WIDTH
/2 - 16, LCD_HEIGHT
/2 - 4, 7, 8);
1994 snprintf(buf
, sizeof buf
, "%s:", str(LANG_SYSFONT_RECORDING_FREQUENCY
));
1995 ptr
= freq_str
[global_settings
.rec_frequency
];
1998 screens
[i
].getstringsize(buf
,&w
,&h
);
1999 screens
[i
].putsxy((LCD_WIDTH
-w
)/2, LCD_HEIGHT
- h
*2, buf
);
2000 screens
[i
].getstringsize(ptr
, &w
, &h
);
2001 screens
[i
].putsxy((LCD_WIDTH
-w
)/2, LCD_HEIGHT
- h
, ptr
);
2002 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_DownArrow
],
2003 LCD_WIDTH
/2 - 3, LCD_HEIGHT
- h
*3, 7, 8);
2007 switch ( global_settings
.rec_channels
) {
2009 ptr
= str(LANG_SYSFONT_CHANNEL_STEREO
);
2013 ptr
= str(LANG_SYSFONT_CHANNEL_MONO
);
2019 screens
[i
].getstringsize(str(LANG_SYSFONT_CHANNELS
), &w
, &h
);
2020 screens
[i
].putsxy(LCD_WIDTH
- w
, LCD_HEIGHT
/2 - h
*2,
2021 str(LANG_SYSFONT_CHANNELS
));
2022 screens
[i
].getstringsize(str(LANG_SYSFONT_MODE
), &w
, &h
);
2023 screens
[i
].putsxy(LCD_WIDTH
- w
, LCD_HEIGHT
/2 - h
,
2024 str(LANG_SYSFONT_MODE
));
2025 screens
[i
].getstringsize(ptr
, &w
, &h
);
2026 screens
[i
].putsxy(LCD_WIDTH
- w
, LCD_HEIGHT
/2, ptr
);
2027 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_FastForward
],
2028 LCD_WIDTH
/2 + 8, LCD_HEIGHT
/2 - 4, 7, 8);
2030 screens
[i
].update();
2033 button
= button_get(true);
2036 case BUTTON_F2
| BUTTON_LEFT
:
2037 global_settings
.rec_quality
++;
2038 if(global_settings
.rec_quality
> 7)
2039 global_settings
.rec_quality
= 0;
2044 case BUTTON_F2
| BUTTON_DOWN
:
2045 global_settings
.rec_frequency
++;
2046 if(global_settings
.rec_frequency
> 5)
2047 global_settings
.rec_frequency
= 0;
2052 case BUTTON_F2
| BUTTON_RIGHT
:
2053 global_settings
.rec_channels
++;
2054 if(global_settings
.rec_channels
> 1)
2055 global_settings
.rec_channels
= 0;
2059 case BUTTON_F2
| BUTTON_REL
:
2065 case BUTTON_F2
| BUTTON_REPEAT
:
2070 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
2076 rec_init_recording_options(&rec_options
);
2077 rec_set_recording_options(&rec_options
);
2083 screens
[i
].setfont(FONT_UI
);
2088 static bool f3_rec_screen(void)
2096 str(LANG_SYSFONT_RECORDING_SRC_MIC
),
2097 str(LANG_SYSFONT_LINE_IN
),
2098 str(LANG_SYSFONT_RECORDING_SRC_DIGITAL
)
2100 struct audio_recording_options rec_options
;
2104 screens
[i
].setfont(FONT_SYSFIXED
);
2105 screens
[i
].getstringsize("A",&w
,&h
);
2110 ptr
= src_str
[global_settings
.rec_source
];
2113 screens
[i
].clear_display();
2115 /* Recording source */
2116 screens
[i
].putsxy(0, LCD_HEIGHT
/2 - h
*2,
2117 str(LANG_SYSFONT_RECORDING_SOURCE
));
2119 screens
[i
].getstringsize(ptr
, &w
, &h
);
2120 screens
[i
].putsxy(0, LCD_HEIGHT
/2-h
, ptr
);
2121 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_FastBackward
],
2122 LCD_WIDTH
/2 - 16, LCD_HEIGHT
/2 - 4, 7, 8);
2126 ptr
= str(LANG_SYSFONT_RECORD_TRIGGER
);
2129 screens
[i
].getstringsize(ptr
,&w
,&h
);
2130 screens
[i
].putsxy((LCD_WIDTH
-w
)/2, LCD_HEIGHT
- h
*2, ptr
);
2131 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_DownArrow
],
2132 LCD_WIDTH
/2 - 3, LCD_HEIGHT
- h
*3, 7, 8);
2134 screens
[i
].update();
2137 button
= button_get(true);
2140 case BUTTON_F3
| BUTTON_DOWN
:
2143 settings_apply_trigger();
2149 case BUTTON_F3
| BUTTON_LEFT
:
2150 global_settings
.rec_source
++;
2151 if(global_settings
.rec_source
> AUDIO_SRC_MAX
)
2152 global_settings
.rec_source
= 0;
2156 case BUTTON_F3
| BUTTON_REL
:
2162 case BUTTON_F3
| BUTTON_REPEAT
:
2167 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
2173 rec_init_recording_options(&rec_options
);
2174 rec_set_recording_options(&rec_options
);
2180 screens
[i
].setfont(FONT_UI
);
2184 #endif /* CONFIG_KEYPAD == RECORDER_PAD */
2186 #if CONFIG_CODEC == SWCODEC
2187 void audio_beep(int duration
)
2194 /* stubs for recording sim */
2195 void audio_init_recording(unsigned int buffer_offset
)
2197 buffer_offset
= buffer_offset
;
2200 void audio_close_recording(void)
2204 unsigned long pcm_rec_get_warnings(void)
2209 unsigned long pcm_rec_sample_rate(void)
2214 unsigned long audio_recorded_time(void)
2219 unsigned long audio_num_recorded_bytes(void)
2221 return 5 * 1024 * 1024;
2224 void rec_set_source(int source
, unsigned flags
)
2230 void audio_set_recording_options(struct audio_recording_options
*options
)
2235 void audio_set_recording_gain(int left
, int right
, int type
)
2242 void audio_record(const char *filename
)
2244 filename
= filename
;
2247 void audio_new_file(const char *filename
)
2249 filename
= filename
;
2252 void audio_stop_recording(void)
2256 void audio_pause_recording(void)
2260 void audio_resume_recording(void)
2264 #endif /* #ifdef SIMULATOR */
2265 #endif /* #ifdef CONFIG_CODEC == SWCODEC */
2267 #endif /* HAVE_RECORDING */