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)
277 if(global_settings
.rec_source
== AUDIO_SRC_MIC
)
279 audio_set_recording_gain(global_settings
.rec_mic_gain
,
284 /* AUDIO_SRC_LINEIN, AUDIO_SRC_FMRADIO, AUDIO_SRC_SPDIF */
285 audio_set_recording_gain(global_settings
.rec_left_gain
,
286 global_settings
.rec_right_gain
,
289 /* reset the clipping indicators */
290 peak_meter_set_clip_hold(global_settings
.peak_meter_clip_hold
);
295 /* Read peak meter values & calculate balance.
296 * Returns validity of peak values.
297 * Used for automatic gain control and history diagram.
299 static bool read_peak_levels(int *peak_l
, int *peak_r
, int *balance
)
301 peak_meter_get_peakhold(peak_l
, peak_r
);
302 peak_valid_mem
[peak_time
% 3] = *peak_l
;
303 if (((peak_valid_mem
[0] == peak_valid_mem
[1]) &&
304 (peak_valid_mem
[1] == peak_valid_mem
[2])) &&
305 ((*peak_l
< 32767) || storage_disk_is_active()))
308 if (*peak_r
> *peak_l
)
309 balance_mem
[peak_time
% BAL_MEM_SIZE
] = (*peak_l
?
310 MIN((10000 * *peak_r
) / *peak_l
- 10000, 15118) : 15118);
312 balance_mem
[peak_time
% BAL_MEM_SIZE
] = (*peak_r
?
313 MAX(10000 - (10000 * *peak_l
) / *peak_r
, -15118) : -15118);
316 for (i
= 0; i
< BAL_MEM_SIZE
; i
++)
317 *balance
+= balance_mem
[i
];
318 *balance
= *balance
/ BAL_MEM_SIZE
;
323 /* AGC helper function to check if maximum gain is reached */
324 static bool agc_gain_is_max(bool left
, bool right
)
326 /* range -128...+108 [0.5dB] */
327 short gain_current_l
;
328 short gain_current_r
;
333 switch (global_settings
.rec_source
)
335 HAVE_LINE_REC_(case AUDIO_SRC_LINEIN
:)
336 HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO
:)
337 gain_current_l
= global_settings
.rec_left_gain
;
338 gain_current_r
= global_settings
.rec_right_gain
;
342 gain_current_l
= global_settings
.rec_mic_gain
;
343 gain_current_r
= global_settings
.rec_mic_gain
;
346 return ((left
&& (gain_current_l
>= agc_maxgain
)) ||
347 (right
&& (gain_current_r
>= agc_maxgain
)));
350 static void change_recording_gain(bool increment
, bool left
, bool right
)
352 int factor
= (increment
? 1 : -1);
354 switch (global_settings
.rec_source
)
356 HAVE_LINE_REC_(case AUDIO_SRC_LINEIN
:)
357 HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO
:)
358 if (left
) global_settings
.rec_left_gain
+= factor
;
359 if (right
) global_settings
.rec_right_gain
+= factor
;
362 global_settings
.rec_mic_gain
+= factor
;
367 * Handle automatic gain control (AGC).
368 * Change recording gain if peak_x levels are above or below
369 * target volume for specified timeouts.
371 static void auto_gain_control(int *peak_l
, int *peak_r
, int *balance
)
377 if (*peak_l
> agc_left
)
380 agc_left
-= (agc_left
- *peak_l
+ 3) >> 2;
381 if (*peak_r
> agc_right
)
384 agc_right
-= (agc_right
- *peak_r
+ 3) >> 2;
385 agc_mono
= (agc_left
+ agc_right
) / 2;
387 agc_mode
= abs(agc_preset
) - 1;
393 if (agc_mode
!= AGC_SAFETY_MODE
) {
394 /* Automatic balance control - only if not in safety mode */
395 if ((agc_left
> AGC_IMG
) && (agc_right
> AGC_IMG
))
400 agc_baltime
-= !(peak_time
% 4); /* 0.47 - 0.75dB */
401 else if (*balance
> -4125)
402 agc_baltime
--; /* 0.75 - 3.00dB */
403 else if (*balance
> -7579)
404 agc_baltime
-= 2; /* 3.00 - 4.90dB */
406 agc_baltime
-= !(peak_time
% 8); /* 4.90 - inf dB */
408 agc_baltime
-= (peak_time
% 2);
410 else if (*balance
> 556)
413 agc_baltime
+= !(peak_time
% 4);
414 else if (*balance
< 4125)
416 else if (*balance
< 7579)
419 agc_baltime
+= !(peak_time
% 8);
421 agc_baltime
+= (peak_time
% 2);
424 if ((*balance
* agc_baltime
) < 0)
427 agc_baltime
-= peak_time
% 2;
429 agc_baltime
+= peak_time
% 2;
432 increment
= ((agc_risetime
/ 2) > agc_droptime
);
434 if (agc_baltime
< -agc_tbal
[agc_mode
])
436 if (!increment
|| !agc_gain_is_max(!increment
, increment
)) {
437 change_recording_gain(increment
, !increment
, increment
);
442 else if (agc_baltime
> +agc_tbal
[agc_mode
])
444 if (!increment
|| !agc_gain_is_max(increment
, !increment
)) {
445 change_recording_gain(increment
, increment
, !increment
);
451 else if (!(hist_time
% 4))
460 /* Automatic gain control */
461 if ((agc_left
> agc_th_hi
[agc_mode
]) || (agc_right
> agc_th_hi
[agc_mode
]))
463 if ((agc_left
> AGC_CLIP
) || (agc_right
> AGC_CLIP
))
464 agc_droptime
+= agc_tdrop
[agc_mode
] /
465 (global_settings
.rec_agc_cliptime
+ 1);
466 if (agc_left
> AGC_HIGH
) {
469 if (agc_left
> AGC_PEAK
)
472 if (agc_right
> AGC_HIGH
) {
475 if (agc_right
> AGC_PEAK
)
478 if (agc_mono
> agc_th_hi
[agc_mode
])
481 agc_droptime
+= !(peak_time
% 2);
483 if (agc_droptime
>= agc_tdrop
[agc_mode
])
485 change_recording_gain(false, true, true);
490 agc_risetime
= MAX(agc_risetime
- 1, 0);
492 else if (agc_mono
< agc_th_lo
[agc_mode
])
494 if (agc_mono
< (agc_th_lo
[agc_mode
] / 8))
495 agc_risetime
+= !(peak_time
% 5);
496 else if (agc_mono
< (agc_th_lo
[agc_mode
] / 2))
501 if (agc_risetime
>= agc_trise
[agc_mode
]) {
502 if ((agc_mode
!= AGC_SAFETY_MODE
) &&
503 (!agc_gain_is_max(true, true))) {
504 change_recording_gain(true, true, true);
510 agc_droptime
= MAX(agc_droptime
- 1, 0);
512 else if (!(peak_time
% 6)) /* on target level every 1.2 sec */
514 agc_risetime
= MAX(agc_risetime
- 1, 0);
515 agc_droptime
= MAX(agc_droptime
- 1, 0);
518 #endif /* HAVE_AGC */
520 static const char* const fmtstr
[] =
522 "%c%d %s", /* no decimals */
523 "%c%d.%d %s ", /* 1 decimal */
524 "%c%d.%02d %s " /* 2 decimals */
527 static char *fmt_gain(int snd
, int val
, char *str
, int len
)
533 val
= sound_val2phys(snd
, val
);
539 numdec
= sound_numdecimals(snd
);
540 unit
= sound_unit(snd
);
544 i
= val
/ (10*numdec
);
545 d
= val
% (10*numdec
);
546 snprintf(str
, len
, fmtstr
[numdec
], sign
, i
, d
, unit
);
549 snprintf(str
, len
, fmtstr
[numdec
], sign
, val
, unit
);
554 /* the list below must match enum audio_sources in audio.h */
555 static const char* const prestr
[] =
557 HAVE_MIC_IN_([AUDIO_SRC_MIC
] = "R_MIC_",)
558 HAVE_LINE_REC_([AUDIO_SRC_LINEIN
] = "R_LINE_",)
559 HAVE_SPDIF_IN_([AUDIO_SRC_SPDIF
] = "R_SPDIF_",)
560 HAVE_FMRADIO_REC_([AUDIO_SRC_FMRADIO
] = "R_FM_",)
563 char *rec_create_filename(char *buffer
)
566 const char *pref
= "R_";
568 /* Directory existence and writeablility should have already been
569 * verified - do not pass NULL pointers to pcmrec */
571 if((unsigned)global_settings
.rec_source
< AUDIO_NUM_SOURCES
)
573 pref
= prestr
[global_settings
.rec_source
];
576 strcpy(buffer
, global_settings
.rec_directory
);
578 snprintf(ext
, sizeof(ext
), ".%s",
579 REC_FILE_ENDING(global_settings
.rec_format
));
582 return create_numbered_filename(buffer
, buffer
, pref
, ext
, 4,
585 /* We'll wait at least up to the start of the next second so no duplicate
587 return create_datetime_filename(buffer
, buffer
, pref
, ext
, true);
592 /* Hit disk to get a starting filename for the type */
593 static void rec_init_filename(void)
596 rec_create_filename(path_buffer
);
601 int rec_create_directory(void)
604 const char * const folder
= global_settings
.rec_directory
;
606 if (strcmp(folder
, "/") && !dir_exists(folder
))
612 while (action_userabort(HZ
) == false)
615 str(LANG_REC_DIR_NOT_WRITABLE
),
616 str(LANG_OFF_ABORT
));
621 rec_status
|= RCSTAT_CREATED_DIRECTORY
;
629 void rec_init_recording_options(struct audio_recording_options
*options
)
631 options
->rec_source
= global_settings
.rec_source
;
632 options
->rec_frequency
= global_settings
.rec_frequency
;
633 options
->rec_channels
= global_settings
.rec_channels
;
634 options
->rec_prerecord_time
= global_settings
.rec_prerecord_time
;
635 #if CONFIG_CODEC == SWCODEC
636 options
->rec_mono_mode
= global_settings
.rec_mono_mode
;
637 options
->rec_source_flags
= 0;
638 options
->enc_config
.rec_format
= global_settings
.rec_format
;
639 global_to_encoder_config(&options
->enc_config
);
641 options
->rec_quality
= global_settings
.rec_quality
;
642 options
->rec_editable
= global_settings
.rec_editable
;
646 #if CONFIG_CODEC == SWCODEC && !defined (SIMULATOR)
647 void rec_set_source(int source
, unsigned flags
)
649 /* Set audio input source, power up/down devices */
650 audio_set_input_source(source
, flags
);
652 /* Set peakmeters for recording or reset to playback */
653 peak_meter_playback((flags
& SRCF_RECORDING
) == 0);
654 peak_meter_enabled
= true;
656 #endif /* CONFIG_CODEC == SWCODEC && !defined (SIMULATOR) */
658 void rec_set_recording_options(struct audio_recording_options
*options
)
660 #if CONFIG_CODEC != SWCODEC
661 if (global_settings
.rec_prerecord_time
)
663 talk_buffer_steal(); /* will use the mp3 buffer */
665 #else /* == SWCODEC */
666 rec_set_source(options
->rec_source
,
667 options
->rec_source_flags
| SRCF_RECORDING
);
668 #endif /* CONFIG_CODEC != SWCODEC */
670 audio_set_recording_options(options
);
673 void rec_command(enum recording_command cmd
)
677 case RECORDING_CMD_STOP_SHUTDOWN
:
678 pm_activate_clipcount(false);
679 audio_stop_recording();
680 #if CONFIG_CODEC == SWCODEC
681 audio_close_recording();
685 case RECORDING_CMD_STOP
:
686 pm_activate_clipcount(false);
687 audio_stop_recording();
689 case RECORDING_CMD_START
:
690 /* steal mp3 buffer, create unique filename and start recording */
691 pm_reset_clipcount();
692 pm_activate_clipcount(true);
693 #if CONFIG_CODEC != SWCODEC
694 talk_buffer_steal(); /* we use the mp3 buffer */
696 audio_record(rec_create_filename(path_buffer
));
698 case RECORDING_CMD_START_NEWFILE
:
699 /* create unique filename and start recording*/
700 pm_reset_clipcount();
701 pm_activate_clipcount(true); /* just to be sure */
702 audio_new_file(rec_create_filename(path_buffer
));
704 case RECORDING_CMD_PAUSE
:
705 pm_activate_clipcount(false);
706 audio_pause_recording();
708 case RECORDING_CMD_RESUME
:
709 pm_activate_clipcount(true);
710 audio_resume_recording();
716 /* used in trigger_listerner and recording_screen */
717 static unsigned int last_seconds
= 0;
720 * Callback function so that the peak meter code can send an event
721 * to this application. This function can be passed to
722 * peak_meter_set_trigger_listener in order to activate the trigger.
724 static void trigger_listener(int trigger_status
)
726 switch (trigger_status
)
729 if(!(audio_status() & AUDIO_STATUS_RECORD
))
731 rec_status
|= RCSTAT_HAVE_RECORDED
;
732 rec_command(RECORDING_CMD_START
);
733 #if CONFIG_CODEC != SWCODEC
734 /* give control to mpeg thread so that it can start
736 yield(); yield(); yield();
740 /* if we're already recording this is a retrigger */
743 if((audio_status() & AUDIO_STATUS_PAUSE
) &&
744 (global_settings
.rec_trigger_type
== TRIG_TYPE_PAUSE
))
746 rec_command(RECORDING_CMD_RESUME
);
748 /* New file on trig start*/
749 else if (global_settings
.rec_trigger_type
!= TRIG_TYPE_NEW_FILE
)
751 rec_command(RECORDING_CMD_START_NEWFILE
);
752 /* tell recording_screen to reset the time */
758 /* A _change_ to TRIG_READY means the current recording has stopped */
760 if(audio_status() & AUDIO_STATUS_RECORD
)
762 switch(global_settings
.rec_trigger_type
)
764 case TRIG_TYPE_STOP
: /* Stop */
765 rec_command(RECORDING_CMD_STOP
);
768 case TRIG_TYPE_PAUSE
: /* Pause */
769 rec_command(RECORDING_CMD_PAUSE
);
772 case TRIG_TYPE_NEW_FILE
: /* New file on trig stop*/
773 rec_command(RECORDING_CMD_START_NEWFILE
);
774 /* tell recording_screen to reset the time */
778 case 3: /* Stop and shutdown */
779 rec_command(RECORDING_CMD_STOP_SHUTDOWN
);
783 if (global_settings
.rec_trigger_mode
!= TRIG_MODE_REARM
)
785 peak_meter_set_trigger_listener(NULL
);
786 peak_meter_trigger(false);
793 /* Stuff for drawing the screen */
795 enum rec_list_items_stereo
{
811 enum rec_list_items_mono
{
816 ITEM_AGC_MAXDB_M
= 5,
825 #ifdef HAVE_SPDIF_REC
826 enum rec_list_items_spdif
{
828 #if CONFIG_CODEC == SWCODEC
829 ITEM_SAMPLERATE_D
= 6,
839 static int listid_to_enum
[ITEM_COUNT
];
841 static char * reclist_get_name(int selected_item
, void * data
,
842 char * buffer
, size_t buffer_len
)
848 data
= data
; /* not used */
849 if(selected_item
>= ITEM_COUNT
)
852 switch (listid_to_enum
[selected_item
])
855 snprintf(buffer
, buffer_len
, "%s: %s", str(LANG_VOLUME
),
856 fmt_gain(SOUND_VOLUME
,
857 global_settings
.volume
,
858 buf2
, sizeof(buf2
)));
861 if(global_settings
.rec_source
== AUDIO_SRC_MIC
)
863 /* Draw MIC recording gain */
864 snprintf(buffer
, buffer_len
, "%s: %s", str(LANG_GAIN
),
865 fmt_gain(SOUND_MIC_GAIN
,
866 global_settings
.rec_mic_gain
,
867 buf2
, sizeof(buf2
)));
871 int avg_gain
= (global_settings
.rec_left_gain
+
872 global_settings
.rec_right_gain
) / 2;
873 snprintf(buffer
, buffer_len
, "%s: %s", str(LANG_GAIN
),
874 fmt_gain(SOUND_LEFT_GAIN
,
876 buf2
, sizeof(buf2
)));
880 snprintf(buffer
, buffer_len
, "%s: %s",
882 fmt_gain(SOUND_LEFT_GAIN
,
883 global_settings
.rec_left_gain
,
884 buf2
, sizeof(buf2
)));
887 snprintf(buffer
, buffer_len
, "%s: %s",
888 str(LANG_GAIN_RIGHT
),
889 fmt_gain(SOUND_RIGHT_GAIN
,
890 global_settings
.rec_right_gain
,
891 buf2
, sizeof(buf2
)));
895 snprintf(buffer
, buffer_len
, "%s: %s",
896 str(LANG_RECORDING_AGC_PRESET
),
897 agc_preset_str
[agc_preset
]);
901 snprintf(buffer
, buffer_len
, "%s: %s",
902 str(LANG_RECORDING_AGC_MAXGAIN
),
903 fmt_gain(SOUND_LEFT_GAIN
,
904 agc_maxgain
, buf2
, sizeof(buf2
)));
905 else if (global_settings
.rec_source
== AUDIO_SRC_MIC
)
906 snprintf(buffer
, buffer_len
, "%s: %s (%s)",
907 str(LANG_RECORDING_AGC_MAXGAIN
),
908 fmt_gain(SOUND_MIC_GAIN
,
909 agc_maxgain
, buf2
, sizeof(buf2
)),
910 fmt_gain(SOUND_MIC_GAIN
,
911 agc_maxgain
- global_settings
.rec_mic_gain
,
912 buf3
, sizeof(buf3
)));
914 snprintf(buffer
, buffer_len
, "%s: %s (%s)",
915 str(LANG_RECORDING_AGC_MAXGAIN
),
916 fmt_gain(SOUND_LEFT_GAIN
,
917 agc_maxgain
, buf2
, sizeof(buf2
)),
918 fmt_gain(SOUND_LEFT_GAIN
,
920 (global_settings
.rec_left_gain
+
921 global_settings
.rec_right_gain
)/2,
922 buf3
, sizeof(buf3
)));
925 #if CONFIG_CODEC == SWCODEC
926 #ifdef HAVE_SPDIF_REC
927 case ITEM_SAMPLERATE_D
:
928 snprintf(buffer
, buffer_len
, "%s: %d",
929 str(LANG_RECORDING_FREQUENCY
),
930 pcm_rec_sample_rate());
936 if(audio_status() & AUDIO_STATUS_RECORD
)
938 size_t tot_len
= strlen(path_buffer
) +
939 strlen(str(LANG_RECORDING_FILENAME
)) + 1;
940 if(tot_len
> buffer_len
)
942 snprintf(buffer
, buffer_len
, "%s %s",
943 str(LANG_RECORDING_FILENAME
),
944 path_buffer
+ tot_len
- buffer_len
);
948 snprintf(buffer
, buffer_len
, "%s %s",
949 str(LANG_RECORDING_FILENAME
), path_buffer
);
954 strncpy(buffer
, str(LANG_RECORDING_FILENAME
), buffer_len
);
965 bool recording_start_automatic
= false;
967 bool recording_screen(bool no_source
)
970 int done
= -1; /* negative to re-init, positive to quit, zero to run */
971 char buf
[32]; /* for preparing strings */
972 char buf2
[32]; /* for preparing strings */
973 int w
, h
; /* character width/height */
974 int update_countdown
= 0; /* refresh counter */
975 unsigned int seconds
;
977 int audio_stat
= 0; /* status of the audio system */
978 int last_audio_stat
= -1; /* previous status so we can act on changes */
979 struct viewport vp_list
[NB_SCREENS
], vp_top
[NB_SCREENS
]; /* the viewports */
981 #if CONFIG_CODEC == SWCODEC
982 int warning_counter
= 0;
983 #define WARNING_PERIOD 7
986 #if CONFIG_CODEC == SWCODEC
987 #ifdef HAVE_SPDIF_REC
988 unsigned long prev_sample_rate
= 0;
992 #ifdef HAVE_FMRADIO_REC
993 /* Radio is left on if:
994 * 1) Is was on at the start and the initial source is FM Radio
995 * 2) 1) and the source was never changed to something else
997 int radio_status
= (global_settings
.rec_source
!= AUDIO_SRC_FMRADIO
) ?
998 FMRADIO_OFF
: get_radio_status();
1000 #if (CONFIG_LED == LED_REAL)
1001 bool led_state
= false;
1002 int led_countdown
= 2;
1005 bool peak_read
= false;
1006 bool peak_valid
= false;
1011 int pm_x
[NB_SCREENS
]; /* peakmeter (and trigger bar) x pos */
1012 int pm_y
[NB_SCREENS
]; /* peakmeter y pos */
1013 int pm_h
[NB_SCREENS
]; /* peakmeter height */
1014 int trig_ypos
[NB_SCREENS
]; /* trigger bar y pos */
1015 int trig_width
[NB_SCREENS
]; /* trigger bar width */
1016 bool compact_view
[NB_SCREENS
]; /* tweak layout tiny screens / big fonts */
1018 struct gui_synclist lists
; /* the list in the bottom vp */
1019 #ifdef HAVE_FMRADIO_REC
1020 int prev_rec_source
= global_settings
.rec_source
; /* detect source change */
1024 bool statusbar
= global_settings
.statusbar
;
1025 global_status
.statusbar_forced
= statusbar
?0:1;
1026 global_settings
.statusbar
= true;
1027 gui_syncstatusbar_draw(&statusbars
,true);
1030 static const unsigned char *byte_units
[] = {
1032 ID2P(LANG_KILOBYTE
),
1033 ID2P(LANG_MEGABYTE
),
1037 struct audio_recording_options rec_options
;
1038 rec_status
= RCSTAT_IN_RECSCREEN
;
1040 #if (CONFIG_STORAGE & STORAGE_ATA) && (CONFIG_LED == LED_REAL) \
1041 && !defined(SIMULATOR)
1042 ata_set_led_enabled(false);
1045 #if CONFIG_CODEC == SWCODEC
1046 /* recording_menu gets messed up: so prevent manus talking */
1048 /* audio_init_recording stops anything playing when it takes the audio
1051 /* Yes, we use the D/A for monitoring */
1052 peak_meter_enabled
= true;
1053 peak_meter_playback(true);
1057 peak_meter_get_peakhold(&peak_l
, &peak_r
);
1060 pm_reset_clipcount();
1061 pm_activate_clipcount(false);
1062 settings_apply_trigger();
1065 agc_preset_str
[0] = str(LANG_OFF
);
1066 agc_preset_str
[1] = str(LANG_AGC_SAFETY
);
1067 agc_preset_str
[2] = str(LANG_AGC_LIVE
);
1068 agc_preset_str
[3] = str(LANG_AGC_DJSET
);
1069 agc_preset_str
[4] = str(LANG_AGC_MEDIUM
);
1070 agc_preset_str
[5] = str(LANG_AGC_VOICE
);
1071 #endif /* HAVE_AGC */
1073 #if CONFIG_CODEC == SWCODEC
1074 audio_close_recording();
1076 audio_init_recording(0);
1077 sound_set_volume(global_settings
.volume
);
1080 /* Create new filename for recording start */
1081 rec_init_filename();
1084 /* viewport init and calculations that only needs to be done once */
1088 /* top vp, 4 lines, force sys font if total screen < 6 lines
1089 NOTE: one could limit the list to 1 line and get away with 5 lines */
1091 viewport_set_defaults(v
, i
); /*already takes care of statusbar*/
1092 if (viewport_get_nb_lines(v
) < 4)
1094 /* compact needs 4 lines total */
1095 v
->font
= FONT_SYSFIXED
;
1096 compact_view
[i
] = false;
1100 if (viewport_get_nb_lines(v
) < (4+2)) /*top=4,list=2*/
1101 compact_view
[i
] = true;
1103 compact_view
[i
] = false;
1105 v
->height
= (font_get(v
->font
)->height
)*(compact_view
[i
] ? 3 : 4);
1107 /* list section, rest of the screen */
1109 viewport_set_defaults(v
, i
);
1110 v
->font
= vp_top
[i
].font
;
1111 v
->y
= vp_top
[i
].y
+ vp_top
[i
].height
;
1112 v
->height
= screens
[i
].lcdheight
- v
->y
; /* the rest */
1113 screens
[i
].set_viewport(&vp_top
[i
]); /* req for next calls */
1115 screens
[i
].getstringsize("W", &w
, &h
);
1116 pm_y
[i
] = font_get(vp_top
[i
].font
)->height
* 2;
1117 trig_ypos
[i
] = font_get(vp_top
[i
].font
)->height
* 3;
1119 trig_ypos
[i
] -= (font_get(vp_top
[i
].font
)->height
)/2;
1122 /* init the bottom list */
1123 gui_synclist_init(&lists
, reclist_get_name
, NULL
, false, 1, vp_list
);
1124 gui_synclist_set_title(&lists
, NULL
, Icon_NOICON
);
1126 /* start of the loop: we stay in this loop until user quits recscreen */
1131 /* request to re-init stuff, done after settings screen */
1133 #ifdef HAVE_FMRADIO_REC
1134 /* If input changes away from FM Radio,
1135 radio will remain off when recording screen closes. */
1136 if (global_settings
.rec_source
!= prev_rec_source
1137 && prev_rec_source
== AUDIO_SRC_FMRADIO
)
1138 radio_status
= FMRADIO_OFF
;
1139 prev_rec_source
= global_settings
.rec_source
;
1145 if(global_settings
.peak_meter_clipcounter
)
1148 screens
[i
].getstringsize(str(LANG_PM_CLIPCOUNT
),
1149 &clipwidth
, &h
); /* h is same */
1150 pm_x
[i
] = clipwidth
+1;
1152 if(global_settings
.rec_trigger_mode
== TRIG_MODE_OFF
)
1153 pm_h
[i
] = font_get(vp_top
[i
].font
)->height
* 2;
1155 pm_h
[i
] = font_get(vp_top
[i
].font
)->height
;
1158 trig_width
[i
] = vp_top
[i
].width
- pm_x
[i
];
1159 screens
[i
].clear_display();
1160 screens
[i
].update();
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();
1183 if (global_settings
.rec_source
== AUDIO_SRC_MIC
) {
1184 agc_preset
= global_settings
.rec_agc_preset_mic
;
1185 agc_maxgain
= global_settings
.rec_agc_maxgain_mic
;
1188 agc_preset
= global_settings
.rec_agc_preset_line
;
1189 agc_maxgain
= global_settings
.rec_agc_maxgain_line
;
1194 update_countdown
= 0; /* Update immediately */
1196 /* populate translation table for list id -> enum */
1197 #ifdef HAVE_SPDIF_REC
1198 if(global_settings
.rec_source
== AUDIO_SRC_SPDIF
)
1200 listid_to_enum
[0] = ITEM_VOLUME_D
;
1201 #if CONFIG_CODEC == SWCODEC
1202 listid_to_enum
[1] = ITEM_SAMPLERATE_D
;
1203 listid_to_enum
[2] = ITEM_FILENAME_D
;
1205 listid_to_enum
[1] = ITEM_FILENAME_D
;
1208 gui_synclist_set_nb_items(&lists
, ITEM_COUNT_D
); /* spdif */
1212 if((global_settings
.rec_source
== AUDIO_SRC_MIC
) ||
1213 (global_settings
.rec_channels
== 1))
1215 listid_to_enum
[0] = ITEM_VOLUME_M
;
1216 listid_to_enum
[1] = ITEM_GAIN_M
;
1218 listid_to_enum
[2] = ITEM_AGC_MODE_M
;
1219 listid_to_enum
[3] = ITEM_AGC_MAXDB_M
;
1220 listid_to_enum
[4] = ITEM_FILENAME_M
;
1222 listid_to_enum
[2] = ITEM_FILENAME_M
;
1224 gui_synclist_set_nb_items(&lists
, ITEM_COUNT_M
); /* mono */
1228 listid_to_enum
[0] = ITEM_VOLUME
;
1229 listid_to_enum
[1] = ITEM_GAIN
;
1230 listid_to_enum
[2] = ITEM_GAIN_L
;
1231 listid_to_enum
[3] = ITEM_GAIN_R
;
1233 listid_to_enum
[4] = ITEM_AGC_MODE
;
1234 listid_to_enum
[5] = ITEM_AGC_MAXDB
;
1235 listid_to_enum
[6] = ITEM_FILENAME
;
1237 listid_to_enum
[4] = ITEM_FILENAME
;
1239 gui_synclist_set_nb_items(&lists
, ITEM_COUNT
); /* stereo */
1242 gui_synclist_draw(&lists
);
1243 } /* if(done < 0) */
1245 audio_stat
= audio_status();
1247 #if (CONFIG_LED == LED_REAL)
1250 * Flash the LED while waiting to record. Turn it on while
1253 if(audio_stat
& AUDIO_STATUS_RECORD
)
1255 if (audio_stat
& AUDIO_STATUS_PAUSE
)
1257 if (--led_countdown
<= 0)
1259 led_state
= !led_state
;
1266 /* trigger is on in status TRIG_READY (no check needed) */
1272 int trig_stat
= peak_meter_trigger_status();
1274 * other trigger stati than trig_off and trig_steady
1275 * already imply that we are recording.
1277 if (trig_stat
== TRIG_STEADY
)
1279 if (--led_countdown
<= 0)
1281 led_state
= !led_state
;
1288 /* trigger is on in status TRIG_READY (no check needed) */
1292 #endif /* CONFIG_LED */
1294 /* first set current vp - stays like this for drawing that follows */
1296 screens
[i
].set_viewport(&vp_top
[i
]);
1298 /* Wait for a button a while (HZ/10) drawing the peak meter */
1299 button
= peak_meter_draw_get_btn(CONTEXT_RECSCREEN
,
1303 if (last_audio_stat
!= audio_stat
)
1305 if (audio_stat
& AUDIO_STATUS_RECORD
)
1307 rec_status
|= RCSTAT_HAVE_RECORDED
;
1309 last_audio_stat
= audio_stat
;
1313 if (recording_start_automatic
)
1315 /* simulate a button press */
1316 button
= ACTION_REC_PAUSE
;
1317 recording_start_automatic
= false;
1320 /* let list handle the button */
1321 gui_synclist_do_button(&lists
, &button
, LIST_WRAP_UNLESS_HELD
);
1323 /* list code changes active viewport - change it back */
1325 screens
[i
].set_viewport(&vp_top
[i
]);
1329 case ACTION_SETTINGS_INC
:
1330 case ACTION_SETTINGS_INCREPEAT
:
1331 switch (listid_to_enum
[gui_synclist_get_sel_pos(&lists
)])
1334 global_settings
.volume
++;
1338 if(global_settings
.rec_source
== AUDIO_SRC_MIC
)
1340 if(global_settings
.rec_mic_gain
<
1341 sound_max(SOUND_MIC_GAIN
))
1342 global_settings
.rec_mic_gain
++;
1346 if(global_settings
.rec_left_gain
<
1347 sound_max(SOUND_LEFT_GAIN
))
1348 global_settings
.rec_left_gain
++;
1349 if(global_settings
.rec_right_gain
<
1350 sound_max(SOUND_RIGHT_GAIN
))
1351 global_settings
.rec_right_gain
++;
1355 if(global_settings
.rec_left_gain
<
1356 sound_max(SOUND_LEFT_GAIN
))
1357 global_settings
.rec_left_gain
++;
1360 if(global_settings
.rec_right_gain
<
1361 sound_max(SOUND_RIGHT_GAIN
))
1362 global_settings
.rec_right_gain
++;
1366 agc_preset
= MIN(agc_preset
+ 1, AGC_MODE_SIZE
);
1367 agc_enable
= (agc_preset
!= 0);
1368 if (global_settings
.rec_source
== AUDIO_SRC_MIC
) {
1369 global_settings
.rec_agc_preset_mic
= agc_preset
;
1370 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
:
1377 if (global_settings
.rec_source
== AUDIO_SRC_MIC
)
1379 agc_maxgain
= MIN(agc_maxgain
+ 1,
1380 sound_max(SOUND_MIC_GAIN
));
1381 global_settings
.rec_agc_maxgain_mic
= agc_maxgain
;
1385 agc_maxgain
= MIN(agc_maxgain
+ 1,
1386 sound_max(SOUND_LEFT_GAIN
));
1387 global_settings
.rec_agc_maxgain_line
= agc_maxgain
;
1390 #endif /* HAVE_AGC */
1393 update_countdown
= 0; /* Update immediately */
1395 case ACTION_SETTINGS_DEC
:
1396 case ACTION_SETTINGS_DECREPEAT
:
1397 switch (listid_to_enum
[gui_synclist_get_sel_pos(&lists
)])
1400 global_settings
.volume
--;
1404 if(global_settings
.rec_source
== AUDIO_SRC_MIC
)
1406 if(global_settings
.rec_mic_gain
>
1407 sound_min(SOUND_MIC_GAIN
))
1408 global_settings
.rec_mic_gain
--;
1412 if(global_settings
.rec_left_gain
>
1413 sound_min(SOUND_LEFT_GAIN
))
1414 global_settings
.rec_left_gain
--;
1415 if(global_settings
.rec_right_gain
>
1416 sound_min(SOUND_RIGHT_GAIN
))
1417 global_settings
.rec_right_gain
--;
1421 if(global_settings
.rec_left_gain
>
1422 sound_min(SOUND_LEFT_GAIN
))
1423 global_settings
.rec_left_gain
--;
1426 if(global_settings
.rec_right_gain
>
1427 sound_min(SOUND_RIGHT_GAIN
))
1428 global_settings
.rec_right_gain
--;
1432 agc_preset
= MAX(agc_preset
- 1, 0);
1433 agc_enable
= (agc_preset
!= 0);
1434 if (global_settings
.rec_source
== AUDIO_SRC_MIC
) {
1435 global_settings
.rec_agc_preset_mic
= agc_preset
;
1436 agc_maxgain
= global_settings
.rec_agc_maxgain_mic
;
1438 global_settings
.rec_agc_preset_line
= agc_preset
;
1439 agc_maxgain
= global_settings
.rec_agc_maxgain_line
;
1442 case ITEM_AGC_MAXDB
:
1443 if (global_settings
.rec_source
== AUDIO_SRC_MIC
)
1445 agc_maxgain
= MAX(agc_maxgain
- 1,
1446 sound_min(SOUND_MIC_GAIN
));
1447 global_settings
.rec_agc_maxgain_mic
= agc_maxgain
;
1451 agc_maxgain
= MAX(agc_maxgain
- 1,
1452 sound_min(SOUND_LEFT_GAIN
));
1453 global_settings
.rec_agc_maxgain_line
= agc_maxgain
;
1456 #endif /* HAVE_AGC */
1459 update_countdown
= 0; /* Update immediately */
1461 case ACTION_STD_CANCEL
:
1462 /* turn off the trigger */
1463 peak_meter_trigger(false);
1464 peak_meter_set_trigger_listener(NULL
);
1466 if(audio_stat
& AUDIO_STATUS_RECORD
)
1468 rec_command(RECORDING_CMD_STOP
);
1472 #if CONFIG_CODEC != SWCODEC
1473 peak_meter_playback(true);
1474 peak_meter_enabled
= false;
1478 update_countdown
= 0; /* Update immediately */
1480 #ifdef HAVE_REMOTE_LCD
1481 case ACTION_REC_LCD
:
1482 /* this feature exists for some h1x0/h3x0 targets that suffer
1483 from noise caused by remote LCD updates
1484 NOTE 1: this will leave the list on the remote
1485 NOTE 2: to be replaced by a global LCD_off() routine */
1486 if(remote_display_on
)
1488 /* switch to single screen, leave message on remote */
1490 screens
[1].clear_viewport();
1491 screens
[1].puts(0, 0, str(LANG_REMOTE_LCD_OFF
));
1492 screens
[1].puts(0, 1, str(LANG_REMOTE_LCD_ON
));
1493 screens
[1].update_viewport();
1497 /* remote switched on again */
1499 screen_update
= NB_SCREENS
;
1501 remote_display_on
= !remote_display_on
; /* toggle */
1502 update_countdown
= 0; /* Update immediately */
1505 case ACTION_REC_PAUSE
:
1506 case ACTION_REC_NEWFILE
:
1507 /* Only act if the mpeg is stopped */
1508 if(!(audio_stat
& AUDIO_STATUS_RECORD
))
1510 /* is this manual or triggered recording? */
1511 if ((global_settings
.rec_trigger_mode
== TRIG_MODE_OFF
) ||
1512 (peak_meter_trigger_status() != TRIG_OFF
))
1514 /* manual recording */
1515 rec_status
|= RCSTAT_HAVE_RECORDED
;
1516 rec_command(RECORDING_CMD_START
);
1518 if (global_settings
.talk_menu
)
1520 /* no voice possible here, but a beep */
1521 audio_beep(HZ
/2); /* longer beep on start */
1524 /* this is triggered recording */
1527 /* we don't start recording now, but enable the
1528 trigger and let the callback function
1529 trigger_listener control when the recording starts */
1530 peak_meter_trigger(true);
1531 peak_meter_set_trigger_listener(&trigger_listener
);
1536 /*if new file button pressed, start new file */
1537 if (button
== ACTION_REC_NEWFILE
)
1539 rec_command(RECORDING_CMD_START_NEWFILE
);
1543 /* if pause button pressed, pause or resume */
1545 if(audio_stat
& AUDIO_STATUS_PAUSE
)
1547 rec_command(RECORDING_CMD_RESUME
);
1548 if (global_settings
.talk_menu
)
1550 /* no voice possible here, but a beep */
1551 audio_beep(HZ
/4); /* short beep on resume */
1556 rec_command(RECORDING_CMD_PAUSE
);
1560 update_countdown
= 0; /* Update immediately */
1562 case ACTION_STD_MENU
:
1563 #if CONFIG_CODEC == SWCODEC
1564 if(!(audio_stat
& AUDIO_STATUS_RECORD
))
1566 if(audio_stat
!= AUDIO_STATUS_RECORD
)
1569 #if (CONFIG_LED == LED_REAL)
1570 /* led is restored at begin of loop / end of function */
1573 if (recording_menu(no_source
))
1576 rec_status
|= RCSTAT_BEEN_IN_USB_MODE
;
1577 #ifdef HAVE_FMRADIO_REC
1578 radio_status
= FMRADIO_OFF
;
1584 /* the init is now done at the beginning of the loop */
1589 #if CONFIG_KEYPAD == RECORDER_PAD
1591 if(audio_stat
!= AUDIO_STATUS_RECORD
)
1593 #if (CONFIG_LED == LED_REAL)
1594 /* led is restored at begin of loop / end of function */
1597 if (f2_rec_screen())
1599 rec_status
|= RCSTAT_HAVE_RECORDED
;
1603 update_countdown
= 0; /* Update immediately */
1608 if(audio_stat
& AUDIO_STATUS_RECORD
)
1610 rec_command(RECORDING_CMD_START_NEWFILE
);
1615 #if (CONFIG_LED == LED_REAL)
1616 /* led is restored at begin of loop / end of function */
1619 if (f3_rec_screen())
1621 rec_status
|= RCSTAT_HAVE_RECORDED
;
1625 update_countdown
= 0; /* Update immediately */
1628 #endif /* CONFIG_KEYPAD == RECORDER_PAD */
1630 case SYS_USB_CONNECTED
:
1631 /* Only accept USB connection when not recording */
1632 if(!(audio_stat
& AUDIO_STATUS_RECORD
))
1635 screens
[i
].set_viewport(NULL
);
1636 default_event_handler(SYS_USB_CONNECTED
);
1638 rec_status
|= RCSTAT_BEEN_IN_USB_MODE
;
1639 #ifdef HAVE_FMRADIO_REC
1640 radio_status
= FMRADIO_OFF
;
1644 } /*switch(button)*/
1647 peak_read
= !peak_read
;
1648 if (peak_read
) { /* every 2nd run of loop */
1650 peak_valid
= read_peak_levels(&peak_l
, &peak_r
, &balance
);
1653 /* Handle AGC every 200ms when enabled and peak data is valid */
1654 if (peak_read
&& agc_enable
&& peak_valid
)
1655 auto_gain_control(&peak_l
, &peak_r
, &balance
);
1658 seconds
= audio_recorded_time() / HZ
;
1660 /* start of vp_top drawing */
1661 if(update_countdown
-- == 0 || seconds
> last_seconds
)
1663 unsigned int dseconds
, dhours
, dminutes
;
1664 unsigned long num_recorded_bytes
, dsize
, dmb
;
1666 /* we assume vp_top is the current viewport! */
1667 FOR_NB_ACTIVE_SCREENS(i
)
1668 screens
[i
].clear_viewport();
1670 update_countdown
= 5;
1671 last_seconds
= seconds
;
1673 dseconds
= rec_timesplit_seconds();
1674 dsize
= rec_sizesplit_bytes();
1675 num_recorded_bytes
= audio_num_recorded_bytes();
1677 #if CONFIG_CODEC == SWCODEC
1678 if ((audio_stat
& AUDIO_STATUS_WARNING
)
1679 && (warning_counter
++ % WARNING_PERIOD
) < WARNING_PERIOD
/2)
1681 /* Switch back and forth displaying warning on first available
1682 line to ensure visibility - the motion should also help
1684 /* Don't use language string unless agreed upon to make this
1685 method permanent - could do something in the statusbar */
1686 snprintf(buf
, sizeof(buf
), "Warning: %08X",
1687 pcm_rec_get_warnings());
1690 #endif /* CONFIG_CODEC == SWCODEC */
1691 if ((global_settings
.rec_sizesplit
) &&
1692 (global_settings
.rec_split_method
))
1694 dmb
= dsize
/1024/1024;
1695 snprintf(buf
, sizeof(buf
), "%s %dMB",
1696 str(LANG_SPLIT_SIZE
), dmb
);
1700 hours
= seconds
/ 3600;
1701 minutes
= (seconds
- (hours
* 3600)) / 60;
1702 snprintf(buf
, sizeof(buf
), "%s %02d:%02d:%02d",
1703 str(LANG_RECORDING_TIME
),
1704 hours
, minutes
, seconds
%60);
1707 FOR_NB_ACTIVE_SCREENS(i
)
1708 screens
[i
].puts(0, 0, buf
);
1710 if(audio_stat
& AUDIO_STATUS_PRERECORD
)
1712 snprintf(buf
, sizeof(buf
), "%s...",
1713 str(LANG_RECORD_PRERECORD
));
1717 /* Display the split interval if the record timesplit
1719 if ((global_settings
.rec_timesplit
) &&
1720 !(global_settings
.rec_split_method
))
1722 /* Display the record timesplit interval rather
1723 than the file size if the record timer is active */
1724 dhours
= dseconds
/ 3600;
1725 dminutes
= (dseconds
- (dhours
* 3600)) / 60;
1726 snprintf(buf
, sizeof(buf
), "%s %02d:%02d",
1727 str(LANG_RECORDING_TIMESPLIT_REC
),
1732 output_dyn_value(buf2
, sizeof buf2
,
1735 snprintf(buf
, sizeof(buf
), "%s %s",
1736 str(LANG_RECORDING_SIZE
), buf2
);
1740 FOR_NB_ACTIVE_SCREENS(i
)
1741 screens
[i
].puts(0, 1, buf
);
1743 /* We will do file splitting regardless, either at the end of
1744 a split interval, or when the filesize approaches the 2GB
1745 FAT file size (compatibility) limit. */
1746 if ((audio_stat
&& !(global_settings
.rec_split_method
)
1747 && global_settings
.rec_timesplit
&& (seconds
>= dseconds
))
1748 || (audio_stat
&& global_settings
.rec_split_method
1749 && global_settings
.rec_sizesplit
1750 && (num_recorded_bytes
>= dsize
))
1751 || (num_recorded_bytes
>= MAX_FILE_SIZE
))
1753 if (!(global_settings
.rec_split_type
)
1754 || (num_recorded_bytes
>= MAX_FILE_SIZE
))
1756 rec_command(RECORDING_CMD_START_NEWFILE
);
1761 peak_meter_trigger(false);
1762 peak_meter_set_trigger_listener(NULL
);
1763 if( global_settings
.rec_split_type
== 1)
1764 rec_command(RECORDING_CMD_STOP
);
1766 rec_command(RECORDING_CMD_STOP_SHUTDOWN
);
1768 update_countdown
= 0;
1771 /* draw the clipcounter just in front of the peakmeter */
1772 if(global_settings
.peak_meter_clipcounter
)
1775 snprintf(clpstr
, 32, "%4d", pm_get_clipcount());
1776 FOR_NB_ACTIVE_SCREENS(i
)
1778 if(!compact_view
[i
])
1779 screens
[i
].puts(0, 2,str(LANG_PM_CLIPCOUNT
));
1780 screens
[i
].puts(0, compact_view
[i
] ? 2 : 3, clpstr
);
1788 /* draw the trigger status */
1789 if (peak_meter_trigger_status() != TRIG_OFF
)
1791 peak_meter_draw_trig(pm_x
, trig_ypos
, trig_width
,
1793 FOR_NB_ACTIVE_SCREENS(i
)
1794 screens
[i
].update_viewport_rect(pm_x
[i
], trig_ypos
[i
],
1795 trig_width
[i
] + 2, TRIG_HEIGHT
);
1799 if (global_settings
.rec_source
== AUDIO_SRC_MIC
)
1801 if(agc_maxgain
< (global_settings
.rec_mic_gain
))
1802 change_recording_gain(false, true, true);
1806 if(agc_maxgain
< (global_settings
.rec_left_gain
))
1807 change_recording_gain(false, true, false);
1808 if(agc_maxgain
< (global_settings
.rec_right_gain
))
1809 change_recording_gain(false, false, true);
1811 #endif /* HAVE_AGC */
1813 #if CONFIG_CODEC == SWCODEC
1814 #ifdef HAVE_SPDIF_REC
1815 if((global_settings
.rec_source
== AUDIO_SRC_SPDIF
) &&
1816 (prev_sample_rate
!= pcm_rec_sample_rate()))
1818 /* spdif samplerate changed */
1819 prev_sample_rate
= pcm_rec_sample_rate();
1827 /* update_list is set whenever content changes */
1828 update_list
= false;
1829 gui_synclist_draw(&lists
);
1832 /* draw peakmeter again (check if this can be removed) */
1833 FOR_NB_ACTIVE_SCREENS(i
)
1835 screens
[i
].set_viewport(NULL
);
1836 gui_statusbar_draw(&(statusbars
.statusbars
[i
]), true);
1837 screens
[i
].set_viewport(&vp_top
[i
]);
1838 peak_meter_screen(&screens
[i
], pm_x
[i
], pm_y
[i
], pm_h
[i
]);
1839 screens
[i
].update();
1841 } /* display update every second */
1843 if(audio_stat
& AUDIO_STATUS_ERROR
)
1847 } /* end while(!done) */
1849 audio_stat
= audio_status();
1850 if (audio_stat
& AUDIO_STATUS_ERROR
)
1852 splash(0, str(LANG_DISK_FULL
));
1853 gui_syncstatusbar_draw(&statusbars
, true);
1856 screens
[i
].update();
1858 #if CONFIG_CODEC == SWCODEC
1859 /* stop recording - some players like H10 freeze otherwise
1860 TO DO: find out why it freezes and fix properly */
1861 rec_command(RECORDING_CMD_STOP
);
1862 audio_close_recording();
1865 audio_error_clear();
1869 if (action_userabort(TIMEOUT_NOBLOCK
))
1876 #if CONFIG_CODEC == SWCODEC
1877 rec_command(RECORDING_CMD_STOP
);
1878 audio_close_recording();
1880 #ifdef HAVE_FMRADIO_REC
1881 if (radio_status
!= FMRADIO_OFF
)
1882 /* Restore radio playback - radio_status should be unchanged if started
1883 through fm radio screen (barring usb connect) */
1884 rec_set_source(AUDIO_SRC_FMRADIO
, (radio_status
& FMRADIO_PAUSED
) ?
1885 SRCF_FMRADIO_PAUSED
: SRCF_FMRADIO_PLAYING
);
1888 /* Go back to playback mode */
1889 rec_set_source(AUDIO_SRC_PLAYBACK
, SRCF_PLAYBACK
);
1891 /* restore talking */
1892 talk_disable(false);
1893 #else /* !SWCODEC */
1894 audio_init_playback();
1895 #endif /* CONFIG_CODEC == SWCODEC */
1897 /* make sure the trigger is really turned off */
1898 peak_meter_trigger(false);
1899 peak_meter_set_trigger_listener(NULL
);
1901 rec_status
&= ~RCSTAT_IN_RECSCREEN
;
1902 sound_settings_apply();
1905 screens
[i
].setfont(FONT_UI
);
1907 /* if the directory was created or recording happened, make sure the
1908 browser is updated */
1909 if (rec_status
& (RCSTAT_CREATED_DIRECTORY
| RCSTAT_HAVE_RECORDED
))
1912 #if (CONFIG_STORAGE & STORAGE_ATA) && (CONFIG_LED == LED_REAL) \
1913 && !defined(SIMULATOR)
1914 ata_set_led_enabled(true);
1918 global_settings
.statusbar
= statusbar
;
1919 global_status
.statusbar_forced
= 0;
1924 return (rec_status
& RCSTAT_BEEN_IN_USB_MODE
) != 0;
1925 } /* recording_screen */
1927 #if CONFIG_KEYPAD == RECORDER_PAD
1928 static bool f2_rec_screen(void)
1930 static const char* const freq_str
[6] =
1945 struct audio_recording_options rec_options
;
1949 screens
[i
].setfont(FONT_SYSFIXED
);
1950 screens
[i
].getstringsize("A",&w
,&h
);
1954 const char* ptr
=NULL
;
1958 screens
[i
].clear_display();
1960 /* Recording quality */
1961 screens
[i
].putsxy(0, LCD_HEIGHT
/2 - h
*2,
1962 str(LANG_SYSFONT_RECORDING_QUALITY
));
1965 snprintf(buf
, sizeof(buf
), "%d", global_settings
.rec_quality
);
1968 screens
[i
].putsxy(0, LCD_HEIGHT
/2-h
, buf
);
1969 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_FastBackward
],
1970 LCD_WIDTH
/2 - 16, LCD_HEIGHT
/2 - 4, 7, 8);
1974 snprintf(buf
, sizeof buf
, "%s:", str(LANG_SYSFONT_RECORDING_FREQUENCY
));
1975 ptr
= freq_str
[global_settings
.rec_frequency
];
1978 screens
[i
].getstringsize(buf
,&w
,&h
);
1979 screens
[i
].putsxy((LCD_WIDTH
-w
)/2, LCD_HEIGHT
- h
*2, buf
);
1980 screens
[i
].getstringsize(ptr
, &w
, &h
);
1981 screens
[i
].putsxy((LCD_WIDTH
-w
)/2, LCD_HEIGHT
- h
, ptr
);
1982 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_DownArrow
],
1983 LCD_WIDTH
/2 - 3, LCD_HEIGHT
- h
*3, 7, 8);
1987 switch ( global_settings
.rec_channels
) {
1989 ptr
= str(LANG_SYSFONT_CHANNEL_STEREO
);
1993 ptr
= str(LANG_SYSFONT_CHANNEL_MONO
);
1999 screens
[i
].getstringsize(str(LANG_SYSFONT_CHANNELS
), &w
, &h
);
2000 screens
[i
].putsxy(LCD_WIDTH
- w
, LCD_HEIGHT
/2 - h
*2,
2001 str(LANG_SYSFONT_CHANNELS
));
2002 screens
[i
].getstringsize(str(LANG_SYSFONT_MODE
), &w
, &h
);
2003 screens
[i
].putsxy(LCD_WIDTH
- w
, LCD_HEIGHT
/2 - h
,
2004 str(LANG_SYSFONT_MODE
));
2005 screens
[i
].getstringsize(ptr
, &w
, &h
);
2006 screens
[i
].putsxy(LCD_WIDTH
- w
, LCD_HEIGHT
/2, ptr
);
2007 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_FastForward
],
2008 LCD_WIDTH
/2 + 8, LCD_HEIGHT
/2 - 4, 7, 8);
2010 screens
[i
].update();
2013 button
= button_get(true);
2016 case BUTTON_F2
| BUTTON_LEFT
:
2017 global_settings
.rec_quality
++;
2018 if(global_settings
.rec_quality
> 7)
2019 global_settings
.rec_quality
= 0;
2024 case BUTTON_F2
| BUTTON_DOWN
:
2025 global_settings
.rec_frequency
++;
2026 if(global_settings
.rec_frequency
> 5)
2027 global_settings
.rec_frequency
= 0;
2032 case BUTTON_F2
| BUTTON_RIGHT
:
2033 global_settings
.rec_channels
++;
2034 if(global_settings
.rec_channels
> 1)
2035 global_settings
.rec_channels
= 0;
2039 case BUTTON_F2
| BUTTON_REL
:
2045 case BUTTON_F2
| BUTTON_REPEAT
:
2050 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
2056 rec_init_recording_options(&rec_options
);
2057 rec_set_recording_options(&rec_options
);
2063 screens
[i
].setfont(FONT_UI
);
2068 static bool f3_rec_screen(void)
2076 str(LANG_SYSFONT_RECORDING_SRC_MIC
),
2077 str(LANG_SYSFONT_LINE_IN
),
2078 str(LANG_SYSFONT_RECORDING_SRC_DIGITAL
)
2080 struct audio_recording_options rec_options
;
2084 screens
[i
].setfont(FONT_SYSFIXED
);
2085 screens
[i
].getstringsize("A",&w
,&h
);
2090 ptr
= src_str
[global_settings
.rec_source
];
2093 screens
[i
].clear_display();
2095 /* Recording source */
2096 screens
[i
].putsxy(0, LCD_HEIGHT
/2 - h
*2,
2097 str(LANG_SYSFONT_RECORDING_SOURCE
));
2099 screens
[i
].getstringsize(ptr
, &w
, &h
);
2100 screens
[i
].putsxy(0, LCD_HEIGHT
/2-h
, ptr
);
2101 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_FastBackward
],
2102 LCD_WIDTH
/2 - 16, LCD_HEIGHT
/2 - 4, 7, 8);
2106 ptr
= str(LANG_SYSFONT_RECORD_TRIGGER
);
2109 screens
[i
].getstringsize(ptr
,&w
,&h
);
2110 screens
[i
].putsxy((LCD_WIDTH
-w
)/2, LCD_HEIGHT
- h
*2, ptr
);
2111 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_DownArrow
],
2112 LCD_WIDTH
/2 - 3, LCD_HEIGHT
- h
*3, 7, 8);
2114 screens
[i
].update();
2117 button
= button_get(true);
2120 case BUTTON_F3
| BUTTON_DOWN
:
2123 settings_apply_trigger();
2129 case BUTTON_F3
| BUTTON_LEFT
:
2130 global_settings
.rec_source
++;
2131 if(global_settings
.rec_source
> AUDIO_SRC_MAX
)
2132 global_settings
.rec_source
= 0;
2136 case BUTTON_F3
| BUTTON_REL
:
2142 case BUTTON_F3
| BUTTON_REPEAT
:
2147 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
2153 rec_init_recording_options(&rec_options
);
2154 rec_set_recording_options(&rec_options
);
2160 screens
[i
].setfont(FONT_UI
);
2164 #endif /* CONFIG_KEYPAD == RECORDER_PAD */
2166 #if CONFIG_CODEC == SWCODEC
2167 void audio_beep(int duration
)
2174 /* stubs for recording sim */
2175 void audio_init_recording(unsigned int buffer_offset
)
2177 buffer_offset
= buffer_offset
;
2180 void audio_close_recording(void)
2184 unsigned long pcm_rec_get_warnings(void)
2189 unsigned long pcm_rec_sample_rate(void)
2194 unsigned long audio_recorded_time(void)
2199 unsigned long audio_num_recorded_bytes(void)
2201 return 5 * 1024 * 1024;
2204 void rec_set_source(int source
, unsigned flags
)
2210 void audio_set_recording_options(struct audio_recording_options
*options
)
2215 void audio_set_recording_gain(int left
, int right
, int type
)
2222 void audio_record(const char *filename
)
2224 filename
= filename
;
2227 void audio_new_file(const char *filename
)
2229 filename
= filename
;
2232 void audio_stop_recording(void)
2236 void audio_pause_recording(void)
2240 void audio_resume_recording(void)
2244 #endif /* #ifdef SIMULATOR */
2245 #endif /* #ifdef CONFIG_CODEC == SWCODEC */
2247 #endif /* HAVE_RECORDING */