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"
34 #if CONFIG_CODEC == SWCODEC
36 #include "enc_config.h"
37 #if defined(HAVE_SPDIF_IN) || defined(HAVE_SPDIF_OUT)
40 #endif /* CONFIG_CODEC == SWCODEC */
41 #include "pcm_record.h"
42 #include "recording.h"
43 #include "mp3_playback.h"
53 #include "peakmeter.h"
55 #include "sound_menu.h"
56 #include "timefuncs.h"
66 #if (CONFIG_STORAGE & STORAGE_ATA) && (CONFIG_LED == LED_REAL) \
67 && !defined(SIMULATOR)
71 #include "screen_access.h"
77 #include "appevents.h"
80 /* This array holds the record timer interval lengths, in seconds */
81 static const unsigned long rec_timer_seconds
[] =
95 10L*60*60, /* 10:00 */
96 12L*60*60, /* 12:00 */
97 18L*60*60, /* 18:00 */
101 static unsigned int rec_timesplit_seconds(void)
103 return rec_timer_seconds
[global_settings
.rec_timesplit
];
106 /* This array holds the record size interval lengths, in bytes */
107 static const unsigned long rec_size_bytes
[] =
110 5*1024*1024, /* 5MB */
111 10*1024*1024, /* 10MB */
112 15*1024*1024, /* 15MB */
113 32*1024*1024, /* 32MB */
114 64*1024*1024, /* 64MB */
115 75*1024*1024, /* 75MB */
116 100*1024*1024, /* 100MB */
117 128*1024*1024, /* 128MB */
118 256*1024*1024, /* 256MB */
119 512*1024*1024, /* 512MB */
120 650*1024*1024, /* 650MB */
121 700*1024*1024, /* 700MB */
122 1024*1024*1024, /* 1GB */
123 1536*1024*1024, /* 1.5GB */
124 1792*1024*1024, /* 1.75GB */
127 static unsigned long rec_sizesplit_bytes(void)
129 return rec_size_bytes
[global_settings
.rec_sizesplit
];
132 void settings_apply_trigger(void)
134 int start_thres
, stop_thres
;
135 if (global_settings
.peak_meter_dbfs
)
137 start_thres
= global_settings
.rec_start_thres_db
- 1;
138 stop_thres
= global_settings
.rec_stop_thres_db
- 1;
142 start_thres
= global_settings
.rec_start_thres_linear
;
143 stop_thres
= global_settings
.rec_stop_thres_linear
;
146 peak_meter_define_trigger(
148 global_settings
.rec_start_duration
*HZ
,
149 MIN(global_settings
.rec_start_duration
*HZ
/ 2, 2*HZ
),
151 global_settings
.rec_stop_postrec
*HZ
,
152 global_settings
.rec_stop_gap
*HZ
155 /* recording screen status flags */
156 enum rec_status_flags
158 RCSTAT_IN_RECSCREEN
= 0x00000001,
159 RCSTAT_BEEN_IN_USB_MODE
= 0x00000002,
160 RCSTAT_CREATED_DIRECTORY
= 0x00000004,
161 RCSTAT_HAVE_RECORDED
= 0x00000008,
164 static int rec_status
= 0;
166 bool in_recording_screen(void)
168 return (rec_status
& RCSTAT_IN_RECSCREEN
) != 0;
171 #if CONFIG_KEYPAD == RECORDER_PAD
172 static bool f2_rec_screen(void);
173 static bool f3_rec_screen(void);
176 #define MAX_FILE_SIZE 0x7F800000 /* 2 GB - 4 MB */
178 #ifndef HAVE_REMOTE_LCD
179 static const int screen_update
= NB_SCREENS
;
181 static int screen_update
= NB_SCREENS
;
182 static bool remote_display_on
= true;
185 /* as we have the ability to disable the remote, we need an alternative loop */
186 #define FOR_NB_ACTIVE_SCREENS(i) for(i = 0; i < screen_update; i++)
188 static bool update_list
= false; /* (GIU) list needs updating */
190 /** File name creation **/
192 /* current file number to assist in creating unique numbered filenames
193 without actually having to create the file on disk */
194 static int file_number
= -1;
195 #endif /* CONFIG_RTC */
197 #if CONFIG_CODEC == SWCODEC
199 #define REC_FILE_ENDING(rec_format) \
200 (audio_formats[rec_format_afmt[rec_format]].ext_list)
202 #else /* CONFIG_CODEC != SWCODEC */
204 /* default record file extension for HWCODEC */
205 #define REC_FILE_ENDING(rec_format) \
206 (audio_formats[AFMT_MPA_L3].ext_list)
208 #endif /* CONFIG_CODEC == SWCODEC */
210 /* path for current file */
211 static char path_buffer
[MAX_PATH
];
213 /** Automatic Gain Control (AGC) **/
216 * peak_time is incremented every 0.2s, every 2nd run of record screen loop.
217 * hist_time is incremented every 0.5s, display update.
218 * peak_time is the counter of the peak hold read and agc process,
219 * overflow every 13 years 8-)
221 static long peak_time
= 0;
223 static short peak_valid_mem
[4];
224 #define BAL_MEM_SIZE 24
225 static short balance_mem
[BAL_MEM_SIZE
];
227 /* Automatic Gain Control */
228 #define AGC_MODE_SIZE 5
229 #define AGC_SAFETY_MODE 0
231 static const char* agc_preset_str
[] =
232 { "Off", "S", "L", "D", "M", "V" };
239 #define AGC_CLIP 32766
240 #define AGC_PEAK 29883 /* fast gain reduction threshold -0.8dB */
241 #define AGC_HIGH 27254 /* accelerated gain reduction threshold -1.6dB */
242 #define AGC_IMG 823 /* threshold for balance control -32dB */
243 /* autogain high level thresholds (-3dB, -7dB, -4dB, -5dB, -5dB) */
244 static const short agc_th_hi
[AGC_MODE_SIZE
] =
245 { 23197, 14637, 21156, 18428, 18426 };
246 /* autogain low level thresholds (-14dB, -11dB, -6dB, -7dB, -8dB) */
247 static const short agc_th_lo
[AGC_MODE_SIZE
] =
248 { 6538, 9235, 16422, 14636, 13045 };
249 /* autogain threshold times [1/5s] or [200ms] */
250 static const short agc_tdrop
[AGC_MODE_SIZE
] =
251 { 900, 225, 150, 60, 8 };
252 static const short agc_trise
[AGC_MODE_SIZE
] =
253 { 9000, 750, 400, 150, 20 };
254 static const short agc_tbal
[AGC_MODE_SIZE
] =
255 { 4500, 500, 300, 100, 15 };
257 static bool agc_enable
= true;
258 static short agc_preset
;
260 static int agc_left
= 0;
261 static int agc_right
= 0;
262 /* AGC time since high target volume was exceeded */
263 static short agc_droptime
= 0;
264 /* AGC time since volume fallen below low target */
265 static short agc_risetime
= 0;
266 /* AGC balance time exceeding +/- 0.7dB */
267 static short agc_baltime
= 0;
268 /* AGC maximum gain */
269 static short agc_maxgain
;
270 #endif /* HAVE_AGC */
271 #if defined(HAVE_AGC) || defined(HAVE_RECORDING_HISTOGRAM)
272 static long hist_time
= 0;
273 #endif /* HAVE_AGC or HAVE_RECORDING_HISTOGRAM */
275 /* TO DO: move some of this stuff inside the recording function? */
276 #ifdef HAVE_RECORDING_HISTOGRAM
277 static int hist_l
= 0;
278 static int hist_r
= 0;
279 #define HIST_BUF_SIZE (LCD_WIDTH)
280 #define HIST_Y (hist_pos_y+hist_size_h-1)
281 #define HIST_W (LCD_WIDTH / 2 - 4)
283 #ifdef HAVE_LCD_COLOR
284 #define LCD_BAL_L LCD_RGBPACK(0, 0, 255)
285 #define LCD_BAL_R LCD_RGBPACK(204, 0, 0)
286 #define LCD_HIST_OVER LCD_RGBPACK(204, 0, 0)
287 #define LCD_HIST_HI LCD_RGBPACK(255, 204, 0)
288 #define LCD_HIST_OK LCD_RGBPACK(51, 153, 0)
289 #else /* HAVE_LCD_COLOR */
290 #define LCD_BATT_OK LCD_BLACK
291 #define LCD_BATT_LO LCD_DARKGRAY
292 #define LCD_DISK_OK LCD_BLACK
293 #define LCD_DISK_LO LCD_DARKGRAY
294 #define LCD_HIST_OVER LCD_BLACK
295 #define LCD_HIST_OK LCD_DARKGRAY
296 #define LCD_BAL LCD_DARKGRAY
297 #endif /* HAVE_LCD_COLOR */
298 #else /* LCD_DEPTH > 1 */
299 #define LCD_HIST_OVER LCD_DEFAULT_FG
300 #define LCD_HIST_OK LCD_DEFAULT_FG
301 #define LCD_BAL LCD_DEFAULT_FG
302 #endif /* LCD_DEPTH > 1 */
303 #endif /* HAVE_RECORDING_HISTOGRAM */
305 static void set_gain(void)
308 if(global_settings
.rec_source
== AUDIO_SRC_MIC
)
310 audio_set_recording_gain(global_settings
.rec_mic_gain
,
316 /* AUDIO_SRC_LINEIN, AUDIO_SRC_FMRADIO, AUDIO_SRC_SPDIF */
317 audio_set_recording_gain(global_settings
.rec_left_gain
,
318 global_settings
.rec_right_gain
,
321 /* reset the clipping indicators */
322 peak_meter_set_clip_hold(global_settings
.peak_meter_clip_hold
);
327 /* Read peak meter values & calculate balance.
328 * Returns validity of peak values.
329 * Used for automatic gain control and history diagram.
331 static bool read_peak_levels(int *peak_l
, int *peak_r
, int *balance
)
333 peak_meter_get_peakhold(peak_l
, peak_r
);
334 peak_valid_mem
[peak_time
% 3] = *peak_l
;
335 if (((peak_valid_mem
[0] == peak_valid_mem
[1]) &&
336 (peak_valid_mem
[1] == peak_valid_mem
[2])) &&
337 ((*peak_l
< 32767) || storage_disk_is_active()))
340 if (*peak_r
> *peak_l
)
341 balance_mem
[peak_time
% BAL_MEM_SIZE
] = (*peak_l
?
342 MIN((10000 * *peak_r
) / *peak_l
- 10000, 15118) : 15118);
344 balance_mem
[peak_time
% BAL_MEM_SIZE
] = (*peak_r
?
345 MAX(10000 - (10000 * *peak_l
) / *peak_r
, -15118) : -15118);
348 for (i
= 0; i
< BAL_MEM_SIZE
; i
++)
349 *balance
+= balance_mem
[i
];
350 *balance
= *balance
/ BAL_MEM_SIZE
;
352 #ifdef HAVE_RECORDING_HISTOGRAM
353 if (*peak_l
> hist_l
)
355 if (*peak_r
> hist_r
)
362 /* AGC helper function to check if maximum gain is reached */
363 static bool agc_gain_is_max(bool left
, bool right
)
365 /* range -128...+108 [0.5dB] */
366 short gain_current_l
;
367 short gain_current_r
;
372 switch (global_settings
.rec_source
)
374 #if defined(HAVE_LINE_REC) || defined(HAVE_FMRADIO_REC)
375 HAVE_LINE_REC_(case AUDIO_SRC_LINEIN
:)
376 HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO
:)
377 gain_current_l
= global_settings
.rec_left_gain
;
378 gain_current_r
= global_settings
.rec_right_gain
;
380 #endif /* LINE, FMRADIO */
381 #if defined(HAVE_MIC_REC)
384 gain_current_l
= global_settings
.rec_mic_gain
;
385 gain_current_r
= global_settings
.rec_mic_gain
;
389 return ((left
&& (gain_current_l
>= agc_maxgain
)) ||
390 (right
&& (gain_current_r
>= agc_maxgain
)));
393 static void change_recording_gain(bool increment
, bool left
, bool right
)
395 int factor
= (increment
? 1 : -1);
397 switch (global_settings
.rec_source
)
399 #if defined(HAVE_LINE_REC) || defined(HAVE_FMRADIO_REC)
400 HAVE_LINE_REC_(case AUDIO_SRC_LINEIN
:)
401 HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO
:)
402 if (left
) global_settings
.rec_left_gain
+= factor
;
403 if (right
) global_settings
.rec_right_gain
+= factor
;
405 #endif /* LINE, FMRADIO */
406 #if defined(HAVE_MIC_REC)
408 global_settings
.rec_mic_gain
+= factor
;
414 * Handle automatic gain control (AGC).
415 * Change recording gain if peak_x levels are above or below
416 * target volume for specified timeouts.
418 static void auto_gain_control(int *peak_l
, int *peak_r
, int *balance
)
424 if (*peak_l
> agc_left
)
427 agc_left
-= (agc_left
- *peak_l
+ 3) >> 2;
428 if (*peak_r
> agc_right
)
431 agc_right
-= (agc_right
- *peak_r
+ 3) >> 2;
432 agc_mono
= (agc_left
+ agc_right
) / 2;
434 agc_mode
= abs(agc_preset
) - 1;
440 if (agc_mode
!= AGC_SAFETY_MODE
) {
441 /* Automatic balance control - only if not in safety mode */
442 if ((agc_left
> AGC_IMG
) && (agc_right
> AGC_IMG
))
447 agc_baltime
-= !(peak_time
% 4); /* 0.47 - 0.75dB */
448 else if (*balance
> -4125)
449 agc_baltime
--; /* 0.75 - 3.00dB */
450 else if (*balance
> -7579)
451 agc_baltime
-= 2; /* 3.00 - 4.90dB */
453 agc_baltime
-= !(peak_time
% 8); /* 4.90 - inf dB */
455 agc_baltime
-= (peak_time
% 2);
457 else if (*balance
> 556)
460 agc_baltime
+= !(peak_time
% 4);
461 else if (*balance
< 4125)
463 else if (*balance
< 7579)
466 agc_baltime
+= !(peak_time
% 8);
468 agc_baltime
+= (peak_time
% 2);
471 if ((*balance
* agc_baltime
) < 0)
474 agc_baltime
-= peak_time
% 2;
476 agc_baltime
+= peak_time
% 2;
479 increment
= ((agc_risetime
/ 2) > agc_droptime
);
481 if (agc_baltime
< -agc_tbal
[agc_mode
])
483 if (!increment
|| !agc_gain_is_max(!increment
, increment
)) {
484 change_recording_gain(increment
, !increment
, increment
);
489 else if (agc_baltime
> +agc_tbal
[agc_mode
])
491 if (!increment
|| !agc_gain_is_max(increment
, !increment
)) {
492 change_recording_gain(increment
, increment
, !increment
);
498 else if (!(hist_time
% 4))
507 /* Automatic gain control */
508 if ((agc_left
> agc_th_hi
[agc_mode
]) || (agc_right
> agc_th_hi
[agc_mode
]))
510 if ((agc_left
> AGC_CLIP
) || (agc_right
> AGC_CLIP
))
511 agc_droptime
+= agc_tdrop
[agc_mode
] /
512 (global_settings
.rec_agc_cliptime
+ 1);
513 if (agc_left
> AGC_HIGH
) {
516 if (agc_left
> AGC_PEAK
)
519 if (agc_right
> AGC_HIGH
) {
522 if (agc_right
> AGC_PEAK
)
525 if (agc_mono
> agc_th_hi
[agc_mode
])
528 agc_droptime
+= !(peak_time
% 2);
530 if (agc_droptime
>= agc_tdrop
[agc_mode
])
532 change_recording_gain(false, true, true);
537 agc_risetime
= MAX(agc_risetime
- 1, 0);
539 else if (agc_mono
< agc_th_lo
[agc_mode
])
541 if (agc_mono
< (agc_th_lo
[agc_mode
] / 8))
542 agc_risetime
+= !(peak_time
% 5);
543 else if (agc_mono
< (agc_th_lo
[agc_mode
] / 2))
548 if (agc_risetime
>= agc_trise
[agc_mode
]) {
549 if ((agc_mode
!= AGC_SAFETY_MODE
) &&
550 (!agc_gain_is_max(true, true))) {
551 change_recording_gain(true, true, true);
557 agc_droptime
= MAX(agc_droptime
- 1, 0);
559 else if (!(peak_time
% 6)) /* on target level every 1.2 sec */
561 agc_risetime
= MAX(agc_risetime
- 1, 0);
562 agc_droptime
= MAX(agc_droptime
- 1, 0);
565 #endif /* HAVE_AGC */
567 static const char* const fmtstr
[] =
569 "%c%d %s", /* no decimals */
570 "%c%d.%d %s ", /* 1 decimal */
571 "%c%d.%02d %s " /* 2 decimals */
574 static char *fmt_gain(int snd
, int val
, char *str
, int len
)
580 val
= sound_val2phys(snd
, val
);
586 numdec
= sound_numdecimals(snd
);
587 unit
= sound_unit(snd
);
591 i
= val
/ (10*numdec
);
592 d
= val
% (10*numdec
);
593 snprintf(str
, len
, fmtstr
[numdec
], sign
, i
, d
, unit
);
596 snprintf(str
, len
, fmtstr
[numdec
], sign
, val
, unit
);
601 /* the list below must match enum audio_sources in audio.h */
602 static const char* const prestr
[] =
604 HAVE_MIC_IN_([AUDIO_SRC_MIC
] = "R_MIC_",)
605 HAVE_LINE_REC_([AUDIO_SRC_LINEIN
] = "R_LINE_",)
606 HAVE_SPDIF_IN_([AUDIO_SRC_SPDIF
] = "R_SPDIF_",)
607 HAVE_FMRADIO_REC_([AUDIO_SRC_FMRADIO
] = "R_FM_",)
610 char *rec_create_filename(char *buffer
)
613 const char *pref
= "R_";
615 /* Directory existence and writeablility should have already been
616 * verified - do not pass NULL pointers to pcmrec */
618 if((unsigned)global_settings
.rec_source
< AUDIO_NUM_SOURCES
)
620 pref
= prestr
[global_settings
.rec_source
];
623 strcpy(buffer
, global_settings
.rec_directory
);
625 snprintf(ext
, sizeof(ext
), ".%s",
626 REC_FILE_ENDING(global_settings
.rec_format
));
629 return create_numbered_filename(buffer
, buffer
, pref
, ext
, 4,
632 /* We'll wait at least up to the start of the next second so no duplicate
634 return create_datetime_filename(buffer
, buffer
, pref
, ext
, true);
639 /* Hit disk to get a starting filename for the type */
640 static void rec_init_filename(void)
643 rec_create_filename(path_buffer
);
648 int rec_create_directory(void)
651 const char * const folder
= global_settings
.rec_directory
;
653 if (strcmp(folder
, "/") && !dir_exists(folder
))
659 while (action_userabort(HZ
) == false)
662 str(LANG_REC_DIR_NOT_WRITABLE
),
663 str(LANG_OFF_ABORT
));
668 rec_status
|= RCSTAT_CREATED_DIRECTORY
;
676 void rec_init_recording_options(struct audio_recording_options
*options
)
678 options
->rec_source
= global_settings
.rec_source
;
679 options
->rec_frequency
= global_settings
.rec_frequency
;
680 options
->rec_channels
= global_settings
.rec_channels
;
681 options
->rec_prerecord_time
= global_settings
.rec_prerecord_time
;
682 #if CONFIG_CODEC == SWCODEC
683 options
->rec_mono_mode
= global_settings
.rec_mono_mode
;
684 options
->rec_source_flags
= 0;
685 options
->enc_config
.rec_format
= global_settings
.rec_format
;
686 global_to_encoder_config(&options
->enc_config
);
688 options
->rec_quality
= global_settings
.rec_quality
;
689 options
->rec_editable
= global_settings
.rec_editable
;
693 #if CONFIG_CODEC == SWCODEC && !defined (SIMULATOR)
694 void rec_set_source(int source
, unsigned flags
)
696 /* Set audio input source, power up/down devices */
697 audio_set_input_source(source
, flags
);
699 /* Set peakmeters for recording or reset to playback */
700 peak_meter_playback((flags
& SRCF_RECORDING
) == 0);
701 peak_meter_enable(true);
703 #endif /* CONFIG_CODEC == SWCODEC && !defined (SIMULATOR) */
705 void rec_set_recording_options(struct audio_recording_options
*options
)
707 #if CONFIG_CODEC != SWCODEC
708 if (global_settings
.rec_prerecord_time
)
710 talk_buffer_steal(); /* will use the mp3 buffer */
712 #else /* == SWCODEC */
713 rec_set_source(options
->rec_source
,
714 options
->rec_source_flags
| SRCF_RECORDING
);
715 #endif /* CONFIG_CODEC != SWCODEC */
717 audio_set_recording_options(options
);
720 void rec_command(enum recording_command cmd
)
724 case RECORDING_CMD_STOP_SHUTDOWN
:
725 pm_activate_clipcount(false);
726 audio_stop_recording();
727 #if CONFIG_CODEC == SWCODEC
728 audio_close_recording();
732 case RECORDING_CMD_STOP
:
733 pm_activate_clipcount(false);
734 audio_stop_recording();
736 case RECORDING_CMD_START
:
737 /* steal mp3 buffer, create unique filename and start recording */
738 pm_reset_clipcount();
739 pm_activate_clipcount(true);
740 #if CONFIG_CODEC != SWCODEC
741 talk_buffer_steal(); /* we use the mp3 buffer */
743 audio_record(rec_create_filename(path_buffer
));
745 case RECORDING_CMD_START_NEWFILE
:
746 /* create unique filename and start recording*/
747 pm_reset_clipcount();
748 pm_activate_clipcount(true); /* just to be sure */
749 audio_new_file(rec_create_filename(path_buffer
));
751 case RECORDING_CMD_PAUSE
:
752 pm_activate_clipcount(false);
753 audio_pause_recording();
755 case RECORDING_CMD_RESUME
:
756 pm_activate_clipcount(true);
757 audio_resume_recording();
763 /* used in trigger_listerner and recording_screen */
764 static unsigned int last_seconds
= 0;
767 * Callback function so that the peak meter code can send an event
768 * to this application. This function can be passed to
769 * peak_meter_set_trigger_listener in order to activate the trigger.
771 static void trigger_listener(int trigger_status
)
773 switch (trigger_status
)
776 if(!(audio_status() & AUDIO_STATUS_RECORD
))
778 rec_status
|= RCSTAT_HAVE_RECORDED
;
779 rec_command(RECORDING_CMD_START
);
780 #if CONFIG_CODEC != SWCODEC
781 /* give control to mpeg thread so that it can start
783 yield(); yield(); yield();
787 /* if we're already recording this is a retrigger */
790 if((audio_status() & AUDIO_STATUS_PAUSE
) &&
791 (global_settings
.rec_trigger_type
== TRIG_TYPE_PAUSE
))
793 rec_command(RECORDING_CMD_RESUME
);
795 /* New file on trig start*/
796 else if (global_settings
.rec_trigger_type
!= TRIG_TYPE_NEW_FILE
)
798 rec_command(RECORDING_CMD_START_NEWFILE
);
799 /* tell recording_screen to reset the time */
805 /* A _change_ to TRIG_READY means the current recording has stopped */
807 if(audio_status() & AUDIO_STATUS_RECORD
)
809 switch(global_settings
.rec_trigger_type
)
811 case TRIG_TYPE_STOP
: /* Stop */
812 rec_command(RECORDING_CMD_STOP
);
815 case TRIG_TYPE_PAUSE
: /* Pause */
816 rec_command(RECORDING_CMD_PAUSE
);
819 case TRIG_TYPE_NEW_FILE
: /* New file on trig stop*/
820 rec_command(RECORDING_CMD_START_NEWFILE
);
821 /* tell recording_screen to reset the time */
825 case 3: /* Stop and shutdown */
826 rec_command(RECORDING_CMD_STOP_SHUTDOWN
);
830 if (global_settings
.rec_trigger_mode
!= TRIG_MODE_REARM
)
832 peak_meter_set_trigger_listener(NULL
);
833 peak_meter_trigger(false);
840 /* Stuff for drawing the screen */
842 enum rec_list_items_stereo
{
858 enum rec_list_items_mono
{
863 ITEM_AGC_MAXDB_M
= 5,
872 #ifdef HAVE_SPDIF_REC
873 enum rec_list_items_spdif
{
875 #if CONFIG_CODEC == SWCODEC
876 ITEM_SAMPLERATE_D
= 6,
886 static int listid_to_enum
[ITEM_COUNT
];
888 static const char* reclist_get_name(int selected_item
, void * data
,
889 char * buffer
, size_t buffer_len
)
895 data
= data
; /* not used */
896 if(selected_item
>= ITEM_COUNT
)
899 switch (listid_to_enum
[selected_item
])
902 snprintf(buffer
, buffer_len
, "%s: %s", str(LANG_VOLUME
),
903 fmt_gain(SOUND_VOLUME
,
904 global_settings
.volume
,
905 buf2
, sizeof(buf2
)));
909 if(global_settings
.rec_source
== AUDIO_SRC_MIC
)
911 /* Draw MIC recording gain */
912 snprintf(buffer
, buffer_len
, "%s: %s", str(LANG_GAIN
),
913 fmt_gain(SOUND_MIC_GAIN
,
914 global_settings
.rec_mic_gain
,
915 buf2
, sizeof(buf2
)));
920 int avg_gain
= (global_settings
.rec_left_gain
+
921 global_settings
.rec_right_gain
) / 2;
922 snprintf(buffer
, buffer_len
, "%s: %s", str(LANG_GAIN
),
923 fmt_gain(SOUND_LEFT_GAIN
,
925 buf2
, sizeof(buf2
)));
929 snprintf(buffer
, buffer_len
, "%s: %s",
931 fmt_gain(SOUND_LEFT_GAIN
,
932 global_settings
.rec_left_gain
,
933 buf2
, sizeof(buf2
)));
936 snprintf(buffer
, buffer_len
, "%s: %s",
937 str(LANG_GAIN_RIGHT
),
938 fmt_gain(SOUND_RIGHT_GAIN
,
939 global_settings
.rec_right_gain
,
940 buf2
, sizeof(buf2
)));
944 snprintf(buffer
, buffer_len
, "%s: %s",
945 str(LANG_RECORDING_AGC_PRESET
),
946 agc_preset_str
[agc_preset
]);
950 snprintf(buffer
, buffer_len
, "%s: %s",
951 str(LANG_RECORDING_AGC_MAXGAIN
),
952 fmt_gain(SOUND_LEFT_GAIN
,
953 agc_maxgain
, buf2
, sizeof(buf2
)));
955 else if (global_settings
.rec_source
== AUDIO_SRC_MIC
)
956 snprintf(buffer
, buffer_len
, "%s: %s (%s)",
957 str(LANG_RECORDING_AGC_MAXGAIN
),
958 fmt_gain(SOUND_MIC_GAIN
,
959 agc_maxgain
, buf2
, sizeof(buf2
)),
960 fmt_gain(SOUND_MIC_GAIN
,
961 agc_maxgain
- global_settings
.rec_mic_gain
,
962 buf3
, sizeof(buf3
)));
965 snprintf(buffer
, buffer_len
, "%s: %s (%s)",
966 str(LANG_RECORDING_AGC_MAXGAIN
),
967 fmt_gain(SOUND_LEFT_GAIN
,
968 agc_maxgain
, buf2
, sizeof(buf2
)),
969 fmt_gain(SOUND_LEFT_GAIN
,
971 (global_settings
.rec_left_gain
+
972 global_settings
.rec_right_gain
)/2,
973 buf3
, sizeof(buf3
)));
976 #if CONFIG_CODEC == SWCODEC
977 #ifdef HAVE_SPDIF_REC
978 case ITEM_SAMPLERATE_D
:
979 snprintf(buffer
, buffer_len
, "%s: %lu",
980 str(LANG_RECORDING_FREQUENCY
),
981 pcm_rec_sample_rate());
987 if(audio_status() & AUDIO_STATUS_RECORD
)
989 size_t tot_len
= strlen(path_buffer
) +
990 strlen(str(LANG_RECORDING_FILENAME
)) + 1;
991 if(tot_len
> buffer_len
)
993 snprintf(buffer
, buffer_len
, "%s %s",
994 str(LANG_RECORDING_FILENAME
),
995 path_buffer
+ tot_len
- buffer_len
);
999 snprintf(buffer
, buffer_len
, "%s %s",
1000 str(LANG_RECORDING_FILENAME
), path_buffer
);
1005 return str(LANG_RECORDING_FILENAME
);
1016 bool recording_start_automatic
= false;
1018 bool recording_screen(bool no_source
)
1021 int done
= -1; /* negative to re-init, positive to quit, zero to run */
1022 char buf
[32]; /* for preparing strings */
1023 char buf2
[32]; /* for preparing strings */
1024 int w
, h
; /* character width/height */
1025 int update_countdown
= 0; /* refresh counter */
1026 unsigned int seconds
;
1028 int audio_stat
= 0; /* status of the audio system */
1029 int last_audio_stat
= -1; /* previous status so we can act on changes */
1030 struct viewport vp_list
[NB_SCREENS
], vp_top
[NB_SCREENS
]; /* the viewports */
1032 #if CONFIG_CODEC == SWCODEC
1033 int warning_counter
= 0;
1034 #define WARNING_PERIOD 7
1037 #if CONFIG_CODEC == SWCODEC
1038 #ifdef HAVE_SPDIF_REC
1039 unsigned long prev_sample_rate
= 0;
1043 #ifdef HAVE_FMRADIO_REC
1044 /* Radio is left on if:
1045 * 1) Is was on at the start and the initial source is FM Radio
1046 * 2) 1) and the source was never changed to something else
1048 int radio_status
= (global_settings
.rec_source
!= AUDIO_SRC_FMRADIO
) ?
1049 FMRADIO_OFF
: get_radio_status();
1051 #if (CONFIG_LED == LED_REAL)
1052 bool led_state
= false;
1053 int led_countdown
= 2;
1056 bool peak_read
= false;
1061 int pm_x
[NB_SCREENS
]; /* peakmeter (and trigger bar) x pos */
1062 int pm_y
[NB_SCREENS
]; /* peakmeter y pos */
1063 int pm_h
[NB_SCREENS
]; /* peakmeter height */
1064 int trig_ypos
[NB_SCREENS
]; /* trigger bar y pos */
1065 int trig_width
[NB_SCREENS
]; /* trigger bar width */
1066 int top_height_req
[NB_SCREENS
]; /* required height for top half */
1067 /* tweak layout tiny screens / big fonts */
1068 bool compact_view
[NB_SCREENS
] = { false };
1069 struct gui_synclist lists
; /* the list in the bottom vp */
1070 #if defined(HAVE_AGC) || defined(HAVE_RECORDING_HISTOGRAM)
1071 bool peak_valid
= false;
1073 #if defined(HAVE_RECORDING_HISTOGRAM)
1075 unsigned short hist_pos_y
= 0;
1076 unsigned short hist_size_h
= 0;
1077 int history_pos
= 0;
1078 short hist_time_interval
= 1; /* 1, 2, 4, 8 */
1079 unsigned char history_l
[HIST_BUF_SIZE
];
1080 unsigned char history_r
[HIST_BUF_SIZE
];
1081 const char hist_level_marks
[6] = { 29, 26, 23, 17, 9, 2};
1083 #ifdef HAVE_FMRADIO_REC
1084 int prev_rec_source
= global_settings
.rec_source
; /* detect source change */
1087 struct audio_recording_options rec_options
;
1088 rec_status
= RCSTAT_IN_RECSCREEN
;
1090 #if (CONFIG_STORAGE & STORAGE_ATA) && (CONFIG_LED == LED_REAL) \
1091 && !defined(SIMULATOR)
1092 ata_set_led_enabled(false);
1095 #if CONFIG_CODEC == SWCODEC
1096 /* recording_menu gets messed up: so prevent manus talking */
1098 /* audio_init_recording stops anything playing when it takes the audio
1101 /* Yes, we use the D/A for monitoring */
1102 peak_meter_enable(true);
1103 peak_meter_playback(true);
1107 peak_meter_get_peakhold(&peak_l
, &peak_r
);
1110 pm_reset_clipcount();
1111 pm_activate_clipcount(false);
1112 settings_apply_trigger();
1115 agc_preset_str
[0] = str(LANG_OFF
);
1116 agc_preset_str
[1] = str(LANG_AGC_SAFETY
);
1117 agc_preset_str
[2] = str(LANG_AGC_LIVE
);
1118 agc_preset_str
[3] = str(LANG_AGC_DJSET
);
1119 agc_preset_str
[4] = str(LANG_AGC_MEDIUM
);
1120 agc_preset_str
[5] = str(LANG_AGC_VOICE
);
1121 #endif /* HAVE_AGC */
1124 /* Disable speaker to prevent feedback */
1125 audiohw_enable_speaker(false);
1128 #if CONFIG_CODEC == SWCODEC
1129 audio_close_recording();
1131 audio_init_recording(0);
1132 sound_set_volume(global_settings
.volume
);
1135 /* Create new filename for recording start */
1136 rec_init_filename();
1139 /* start of the loop: we stay in this loop until user quits recscreen */
1144 /* request to re-init stuff, done after settings screen */
1146 #ifdef HAVE_FMRADIO_REC
1147 /* If input changes away from FM Radio,
1148 radio will remain off when recording screen closes. */
1149 if (global_settings
.rec_source
!= prev_rec_source
1150 && prev_rec_source
== AUDIO_SRC_FMRADIO
)
1151 radio_status
= FMRADIO_OFF
;
1152 prev_rec_source
= global_settings
.rec_source
;
1155 /* viewport init and calculations that only needs to be done once */
1159 /* top vp, 4 lines, force sys font if total screen < 6 lines
1160 NOTE: one could limit the list to 1 line and get away with 5 lines */
1161 top_height_req
[i
] = 4;
1162 #if defined(HAVE_RECORDING_HISTOGRAM)
1163 if((global_settings
.rec_histogram_interval
) && (!i
))
1164 top_height_req
[i
] += 1; /* use one line for histogram */
1165 hist_time_interval
= 1 << global_settings
.rec_histogram_interval
;
1168 viewport_set_defaults(v
, i
);
1169 if (viewport_get_nb_lines(v
) < top_height_req
[i
])
1171 /* compact needs 4 lines total */
1172 v
->font
= FONT_SYSFIXED
;
1173 compact_view
[i
] = false;
1178 if (viewport_get_nb_lines(v
) < (top_height_req
[i
]+2))
1179 compact_view
[i
] = true;
1181 compact_view
[i
] = false;
1183 vp_list
[i
] = *v
; /* get a copy now so it can be sized more easily */
1184 v
->height
= (font_get(v
->font
)->height
)*(compact_view
[i
] ? 3 :
1187 /* list section, rest of the screen */
1188 vp_list
[i
].y
+= vp_top
[i
].height
;
1189 vp_list
[i
].height
-= vp_top
[i
].height
;
1190 screens
[i
].set_viewport(&vp_top
[i
]); /* req for next calls */
1192 screens
[i
].getstringsize("W", &w
, &h
);
1193 pm_y
[i
] = font_get(vp_top
[i
].font
)->height
* 2;
1194 trig_ypos
[i
] = font_get(vp_top
[i
].font
)->height
* 3;
1196 trig_ypos
[i
] -= (font_get(vp_top
[i
].font
)->height
)/2;
1199 /* init the bottom list */
1200 gui_synclist_init(&lists
, reclist_get_name
, NULL
, false, 1, vp_list
);
1201 gui_synclist_set_title(&lists
, NULL
, Icon_NOICON
);
1203 send_event(GUI_EVENT_ACTIONUPDATE
, (void*)1); /* force a redraw */
1205 #if defined(HAVE_RECORDING_HISTOGRAM)
1207 hist_pos_y
= (compact_view
[0] ? 3 : 4) * (font_get(vp_top
[0].font
)->height
)
1209 hist_size_h
= font_get(vp_top
[0].font
)->height
- 2;
1210 memset(history_l
, 0, sizeof(unsigned char)*HIST_BUF_SIZE
);
1211 memset(history_r
, 0, sizeof(unsigned char)*HIST_BUF_SIZE
);
1217 if(global_settings
.peak_meter_clipcounter
)
1220 screens
[i
].getstringsize(str(LANG_PM_CLIPCOUNT
),
1221 &clipwidth
, &h
); /* h is same */
1222 pm_x
[i
] = clipwidth
+1;
1224 if(global_settings
.rec_trigger_mode
== TRIG_MODE_OFF
)
1225 pm_h
[i
] = font_get(vp_top
[i
].font
)->height
* 2;
1227 pm_h
[i
] = font_get(vp_top
[i
].font
)->height
;
1230 trig_width
[i
] = vp_top
[i
].width
- pm_x
[i
];
1233 #if CONFIG_CODEC == SWCODEC
1234 audio_close_recording();
1235 audio_init_recording(0);
1238 rec_init_recording_options(&rec_options
);
1239 rec_set_recording_options(&rec_options
);
1241 if(rec_create_directory() < 0)
1247 #if CONFIG_CODEC == SWCODEC && CONFIG_RTC == 0
1248 /* If format changed, a new number is required */
1249 rec_init_filename();
1254 if (global_settings
.rec_source
== AUDIO_SRC_MIC
) {
1255 agc_preset
= global_settings
.rec_agc_preset_mic
;
1256 agc_maxgain
= global_settings
.rec_agc_maxgain_mic
;
1261 agc_preset
= global_settings
.rec_agc_preset_line
;
1262 agc_maxgain
= global_settings
.rec_agc_maxgain_line
;
1264 #endif /* HAVE_AGC */
1267 update_countdown
= 0; /* Update immediately */
1269 /* populate translation table for list id -> enum */
1270 #ifdef HAVE_SPDIF_REC
1271 if(global_settings
.rec_source
== AUDIO_SRC_SPDIF
)
1273 listid_to_enum
[0] = ITEM_VOLUME_D
;
1274 #if CONFIG_CODEC == SWCODEC
1275 listid_to_enum
[1] = ITEM_SAMPLERATE_D
;
1276 listid_to_enum
[2] = ITEM_FILENAME_D
;
1278 listid_to_enum
[1] = ITEM_FILENAME_D
;
1281 gui_synclist_set_nb_items(&lists
, ITEM_COUNT_D
); /* spdif */
1285 if(HAVE_MIC_REC_((global_settings
.rec_source
== AUDIO_SRC_MIC
) || )
1286 (global_settings
.rec_channels
== 1))
1288 listid_to_enum
[0] = ITEM_VOLUME_M
;
1289 listid_to_enum
[1] = ITEM_GAIN_M
;
1291 listid_to_enum
[2] = ITEM_AGC_MODE_M
;
1292 listid_to_enum
[3] = ITEM_AGC_MAXDB_M
;
1293 listid_to_enum
[4] = ITEM_FILENAME_M
;
1295 listid_to_enum
[2] = ITEM_FILENAME_M
;
1297 gui_synclist_set_nb_items(&lists
, ITEM_COUNT_M
); /* mono */
1301 listid_to_enum
[0] = ITEM_VOLUME
;
1302 listid_to_enum
[1] = ITEM_GAIN
;
1303 listid_to_enum
[2] = ITEM_GAIN_L
;
1304 listid_to_enum
[3] = ITEM_GAIN_R
;
1306 listid_to_enum
[4] = ITEM_AGC_MODE
;
1307 listid_to_enum
[5] = ITEM_AGC_MAXDB
;
1308 listid_to_enum
[6] = ITEM_FILENAME
;
1310 listid_to_enum
[4] = ITEM_FILENAME
;
1312 gui_synclist_set_nb_items(&lists
, ITEM_COUNT
); /* stereo */
1315 gui_synclist_draw(&lists
);
1316 } /* if(done < 0) */
1318 audio_stat
= audio_status();
1320 #if (CONFIG_LED == LED_REAL)
1323 * Flash the LED while waiting to record. Turn it on while
1326 if(audio_stat
& AUDIO_STATUS_RECORD
)
1328 if (audio_stat
& AUDIO_STATUS_PAUSE
)
1330 if (--led_countdown
<= 0)
1332 led_state
= !led_state
;
1339 /* trigger is on in status TRIG_READY (no check needed) */
1345 int trig_stat
= peak_meter_trigger_status();
1347 * other trigger stati than trig_off and trig_steady
1348 * already imply that we are recording.
1350 if (trig_stat
== TRIG_STEADY
)
1352 if (--led_countdown
<= 0)
1354 led_state
= !led_state
;
1361 /* trigger is on in status TRIG_READY (no check needed) */
1365 #endif /* CONFIG_LED */
1367 /* Wait for a button a while (HZ/10) drawing the peak meter */
1368 button
= peak_meter_draw_get_btn(CONTEXT_RECSCREEN
,
1370 screen_update
, vp_top
);
1371 if (last_audio_stat
!= audio_stat
)
1373 if (audio_stat
& AUDIO_STATUS_RECORD
)
1375 rec_status
|= RCSTAT_HAVE_RECORDED
;
1377 last_audio_stat
= audio_stat
;
1381 if (recording_start_automatic
)
1383 /* simulate a button press */
1384 button
= ACTION_REC_PAUSE
;
1385 recording_start_automatic
= false;
1388 /* let list handle the button */
1389 gui_synclist_do_button(&lists
, &button
, LIST_WRAP_UNLESS_HELD
);
1394 case ACTION_SETTINGS_INC
:
1395 case ACTION_SETTINGS_INCREPEAT
:
1396 switch (listid_to_enum
[gui_synclist_get_sel_pos(&lists
)])
1399 global_settings
.volume
++;
1404 if(global_settings
.rec_source
== AUDIO_SRC_MIC
)
1406 if(global_settings
.rec_mic_gain
<
1407 sound_max(SOUND_MIC_GAIN
))
1408 global_settings
.rec_mic_gain
++;
1413 if(global_settings
.rec_left_gain
<
1414 sound_max(SOUND_LEFT_GAIN
))
1415 global_settings
.rec_left_gain
++;
1416 if(global_settings
.rec_right_gain
<
1417 sound_max(SOUND_RIGHT_GAIN
))
1418 global_settings
.rec_right_gain
++;
1422 if(global_settings
.rec_left_gain
<
1423 sound_max(SOUND_LEFT_GAIN
))
1424 global_settings
.rec_left_gain
++;
1427 if(global_settings
.rec_right_gain
<
1428 sound_max(SOUND_RIGHT_GAIN
))
1429 global_settings
.rec_right_gain
++;
1433 agc_preset
= MIN(agc_preset
+ 1, AGC_MODE_SIZE
);
1434 agc_enable
= (agc_preset
!= 0);
1436 if (global_settings
.rec_source
== AUDIO_SRC_MIC
) {
1437 global_settings
.rec_agc_preset_mic
= agc_preset
;
1438 agc_maxgain
= global_settings
.rec_agc_maxgain_mic
;
1442 global_settings
.rec_agc_preset_line
= agc_preset
;
1443 agc_maxgain
= global_settings
.rec_agc_maxgain_line
;
1446 case ITEM_AGC_MAXDB
:
1448 if (global_settings
.rec_source
== AUDIO_SRC_MIC
)
1450 agc_maxgain
= MIN(agc_maxgain
+ 1,
1451 sound_max(SOUND_MIC_GAIN
));
1452 global_settings
.rec_agc_maxgain_mic
= agc_maxgain
;
1457 agc_maxgain
= MIN(agc_maxgain
+ 1,
1458 sound_max(SOUND_LEFT_GAIN
));
1459 global_settings
.rec_agc_maxgain_line
= agc_maxgain
;
1462 #endif /* HAVE_AGC */
1465 update_countdown
= 0; /* Update immediately */
1467 case ACTION_SETTINGS_DEC
:
1468 case ACTION_SETTINGS_DECREPEAT
:
1469 switch (listid_to_enum
[gui_synclist_get_sel_pos(&lists
)])
1472 global_settings
.volume
--;
1477 if(global_settings
.rec_source
== AUDIO_SRC_MIC
)
1479 if(global_settings
.rec_mic_gain
>
1480 sound_min(SOUND_MIC_GAIN
))
1481 global_settings
.rec_mic_gain
--;
1486 if(global_settings
.rec_left_gain
>
1487 sound_min(SOUND_LEFT_GAIN
))
1488 global_settings
.rec_left_gain
--;
1489 if(global_settings
.rec_right_gain
>
1490 sound_min(SOUND_RIGHT_GAIN
))
1491 global_settings
.rec_right_gain
--;
1495 if(global_settings
.rec_left_gain
>
1496 sound_min(SOUND_LEFT_GAIN
))
1497 global_settings
.rec_left_gain
--;
1500 if(global_settings
.rec_right_gain
>
1501 sound_min(SOUND_RIGHT_GAIN
))
1502 global_settings
.rec_right_gain
--;
1506 agc_preset
= MAX(agc_preset
- 1, 0);
1507 agc_enable
= (agc_preset
!= 0);
1509 if (global_settings
.rec_source
== AUDIO_SRC_MIC
) {
1510 global_settings
.rec_agc_preset_mic
= agc_preset
;
1511 agc_maxgain
= global_settings
.rec_agc_maxgain_mic
;
1515 global_settings
.rec_agc_preset_line
= agc_preset
;
1516 agc_maxgain
= global_settings
.rec_agc_maxgain_line
;
1519 case ITEM_AGC_MAXDB
:
1521 if (global_settings
.rec_source
== AUDIO_SRC_MIC
)
1523 agc_maxgain
= MAX(agc_maxgain
- 1,
1524 sound_min(SOUND_MIC_GAIN
));
1525 global_settings
.rec_agc_maxgain_mic
= agc_maxgain
;
1529 agc_maxgain
= MAX(agc_maxgain
- 1,
1530 sound_min(SOUND_LEFT_GAIN
));
1531 global_settings
.rec_agc_maxgain_line
= agc_maxgain
;
1534 #endif /* HAVE_AGC */
1537 update_countdown
= 0; /* Update immediately */
1539 case ACTION_STD_CANCEL
:
1540 /* turn off the trigger */
1541 peak_meter_trigger(false);
1542 peak_meter_set_trigger_listener(NULL
);
1544 if(audio_stat
& AUDIO_STATUS_RECORD
)
1546 rec_command(RECORDING_CMD_STOP
);
1550 #if CONFIG_CODEC != SWCODEC
1551 peak_meter_playback(true);
1552 peak_meter_enable(false);
1556 update_countdown
= 0; /* Update immediately */
1558 #ifdef HAVE_REMOTE_LCD
1559 case ACTION_REC_LCD
:
1560 /* this feature exists for some h1x0/h3x0 targets that suffer
1561 from noise caused by remote LCD updates
1562 NOTE 1: this will leave the list on the remote
1563 NOTE 2: to be replaced by a global LCD_off() routine */
1564 if(remote_display_on
)
1566 /* switch to single screen, leave message on remote */
1568 screens
[1].clear_viewport();
1569 screens
[1].puts(0, 0, str(LANG_REMOTE_LCD_OFF
));
1570 screens
[1].puts(0, 1, str(LANG_REMOTE_LCD_ON
));
1571 screens
[1].update_viewport();
1575 /* remote switched on again */
1577 screen_update
= NB_SCREENS
;
1579 remote_display_on
= !remote_display_on
; /* toggle */
1580 update_countdown
= 0; /* Update immediately */
1583 case ACTION_REC_PAUSE
:
1584 case ACTION_REC_NEWFILE
:
1585 /* Only act if the mpeg is stopped */
1586 if(!(audio_stat
& AUDIO_STATUS_RECORD
))
1588 /* is this manual or triggered recording? */
1589 if ((global_settings
.rec_trigger_mode
== TRIG_MODE_OFF
) ||
1590 (peak_meter_trigger_status() != TRIG_OFF
))
1592 /* manual recording */
1593 rec_status
|= RCSTAT_HAVE_RECORDED
;
1594 rec_command(RECORDING_CMD_START
);
1596 if (global_settings
.talk_menu
)
1598 /* no voice possible here, but a beep */
1599 audio_beep(HZ
/2); /* longer beep on start */
1602 /* this is triggered recording */
1605 /* we don't start recording now, but enable the
1606 trigger and let the callback function
1607 trigger_listener control when the recording starts */
1608 peak_meter_trigger(true);
1609 peak_meter_set_trigger_listener(&trigger_listener
);
1614 /*if new file button pressed, start new file */
1615 if (button
== ACTION_REC_NEWFILE
)
1617 rec_command(RECORDING_CMD_START_NEWFILE
);
1621 /* if pause button pressed, pause or resume */
1623 if(audio_stat
& AUDIO_STATUS_PAUSE
)
1625 rec_command(RECORDING_CMD_RESUME
);
1626 if (global_settings
.talk_menu
)
1628 /* no voice possible here, but a beep */
1629 audio_beep(HZ
/4); /* short beep on resume */
1634 rec_command(RECORDING_CMD_PAUSE
);
1638 update_countdown
= 0; /* Update immediately */
1640 case ACTION_STD_MENU
:
1641 #if CONFIG_CODEC == SWCODEC
1642 if(!(audio_stat
& AUDIO_STATUS_RECORD
))
1644 if(audio_stat
!= AUDIO_STATUS_RECORD
)
1647 #if (CONFIG_LED == LED_REAL)
1648 /* led is restored at begin of loop / end of function */
1651 if (recording_menu(no_source
))
1654 rec_status
|= RCSTAT_BEEN_IN_USB_MODE
;
1655 #ifdef HAVE_FMRADIO_REC
1656 radio_status
= FMRADIO_OFF
;
1662 /* the init is now done at the beginning of the loop */
1667 #if CONFIG_KEYPAD == RECORDER_PAD
1669 if(audio_stat
!= AUDIO_STATUS_RECORD
)
1671 #if (CONFIG_LED == LED_REAL)
1672 /* led is restored at begin of loop / end of function */
1675 if (f2_rec_screen())
1677 rec_status
|= RCSTAT_HAVE_RECORDED
;
1681 update_countdown
= 0; /* Update immediately */
1686 if(audio_stat
& AUDIO_STATUS_RECORD
)
1688 rec_command(RECORDING_CMD_START_NEWFILE
);
1693 #if (CONFIG_LED == LED_REAL)
1694 /* led is restored at begin of loop / end of function */
1697 if (f3_rec_screen())
1699 rec_status
|= RCSTAT_HAVE_RECORDED
;
1703 update_countdown
= 0; /* Update immediately */
1706 #endif /* CONFIG_KEYPAD == RECORDER_PAD */
1708 case SYS_USB_CONNECTED
:
1709 /* Only accept USB connection when not recording */
1710 if(!(audio_stat
& AUDIO_STATUS_RECORD
))
1713 screens
[i
].set_viewport(NULL
);
1714 default_event_handler(SYS_USB_CONNECTED
);
1716 rec_status
|= RCSTAT_BEEN_IN_USB_MODE
;
1717 #ifdef HAVE_FMRADIO_REC
1718 radio_status
= FMRADIO_OFF
;
1722 } /*switch(button)*/
1725 peak_read
= !peak_read
;
1726 if (peak_read
) { /* every 2nd run of loop */
1728 peak_valid
= read_peak_levels(&peak_l
, &peak_r
, &balance
);
1731 /* Handle AGC every 200ms when enabled and peak data is valid */
1732 if (peak_read
&& agc_enable
&& peak_valid
)
1733 auto_gain_control(&peak_l
, &peak_r
, &balance
);
1736 seconds
= audio_recorded_time() / HZ
;
1738 /* start of vp_top drawing */
1739 if(update_countdown
-- == 0 || seconds
> last_seconds
)
1741 unsigned int dseconds
, dhours
, dminutes
;
1742 unsigned long num_recorded_bytes
, dsize
, dmb
;
1746 screens
[i
].set_viewport(&vp_top
[i
]);
1747 screens
[i
].clear_viewport();
1749 update_countdown
= 5;
1750 last_seconds
= seconds
;
1752 dseconds
= rec_timesplit_seconds();
1753 dsize
= rec_sizesplit_bytes();
1754 num_recorded_bytes
= audio_num_recorded_bytes();
1756 #if CONFIG_CODEC == SWCODEC
1757 if ((audio_stat
& AUDIO_STATUS_WARNING
)
1758 && (warning_counter
++ % WARNING_PERIOD
) < WARNING_PERIOD
/2)
1760 /* Switch back and forth displaying warning on first available
1761 line to ensure visibility - the motion should also help
1763 /* Don't use language string unless agreed upon to make this
1764 method permanent - could do something in the statusbar */
1765 snprintf(buf
, sizeof(buf
), "Warning: %08lX",
1766 pcm_rec_get_warnings());
1769 #endif /* CONFIG_CODEC == SWCODEC */
1770 if ((global_settings
.rec_sizesplit
) &&
1771 (global_settings
.rec_split_method
))
1773 dmb
= dsize
/1024/1024;
1774 snprintf(buf
, sizeof(buf
), "%s %luMB",
1775 str(LANG_SPLIT_SIZE
), dmb
);
1779 hours
= seconds
/ 3600;
1780 minutes
= (seconds
- (hours
* 3600)) / 60;
1781 snprintf(buf
, sizeof(buf
), "%s %02d:%02d:%02d",
1782 str(LANG_RECORDING_TIME
),
1783 hours
, minutes
, seconds
%60);
1786 FOR_NB_ACTIVE_SCREENS(i
)
1787 screens
[i
].puts(0, 0, buf
);
1789 if(audio_stat
& AUDIO_STATUS_PRERECORD
)
1791 snprintf(buf
, sizeof(buf
), "%s...",
1792 str(LANG_RECORD_PRERECORD
));
1796 /* Display the split interval if the record timesplit
1798 if ((global_settings
.rec_timesplit
) &&
1799 !(global_settings
.rec_split_method
))
1801 /* Display the record timesplit interval rather
1802 than the file size if the record timer is active */
1803 dhours
= dseconds
/ 3600;
1804 dminutes
= (dseconds
- (dhours
* 3600)) / 60;
1805 snprintf(buf
, sizeof(buf
), "%s %02d:%02d",
1806 str(LANG_RECORDING_TIMESPLIT_REC
),
1811 output_dyn_value(buf2
, sizeof buf2
,
1814 snprintf(buf
, sizeof(buf
), "%s %s",
1815 str(LANG_RECORDING_SIZE
), buf2
);
1819 FOR_NB_ACTIVE_SCREENS(i
)
1820 screens
[i
].puts(0, 1, buf
);
1822 /* We will do file splitting regardless, either at the end of
1823 a split interval, or when the filesize approaches the 2GB
1824 FAT file size (compatibility) limit. */
1825 if ((audio_stat
&& !(global_settings
.rec_split_method
)
1826 && global_settings
.rec_timesplit
&& (seconds
>= dseconds
))
1827 || (audio_stat
&& global_settings
.rec_split_method
1828 && global_settings
.rec_sizesplit
1829 && (num_recorded_bytes
>= dsize
))
1830 || (num_recorded_bytes
>= MAX_FILE_SIZE
))
1832 if (!(global_settings
.rec_split_type
)
1833 || (num_recorded_bytes
>= MAX_FILE_SIZE
))
1835 rec_command(RECORDING_CMD_START_NEWFILE
);
1840 peak_meter_trigger(false);
1841 peak_meter_set_trigger_listener(NULL
);
1842 if( global_settings
.rec_split_type
== 1)
1843 rec_command(RECORDING_CMD_STOP
);
1845 rec_command(RECORDING_CMD_STOP_SHUTDOWN
);
1847 update_countdown
= 0;
1850 /* draw the clipcounter just in front of the peakmeter */
1851 if(global_settings
.peak_meter_clipcounter
)
1853 int clipcount
= pm_get_clipcount();
1854 FOR_NB_ACTIVE_SCREENS(i
)
1856 if(!compact_view
[i
])
1858 screens
[i
].puts(0, 2, str(LANG_PM_CLIPCOUNT
));
1859 screens
[i
].putsf(0, 3, "%4d", clipcount
);
1862 screens
[i
].putsf(0, 2, "%4d", clipcount
);
1866 #ifdef HAVE_RECORDING_HISTOGRAM
1867 if(global_settings
.rec_histogram_interval
)
1869 if (peak_valid
&& !(hist_time
% hist_time_interval
) && hist_l
)
1871 /* fill history buffer */
1872 history_l
[history_pos
] = hist_l
* hist_size_h
/ 32767;
1873 history_r
[history_pos
] = hist_r
* hist_size_h
/ 32767;
1874 history_pos
= (history_pos
+ 1) % HIST_BUF_SIZE
;
1875 history_l
[history_pos
] = history_r
[history_pos
] = 0;
1876 history_l
[(history_pos
+ 1) % HIST_BUF_SIZE
] = 0;
1877 history_r
[(history_pos
+ 1) % HIST_BUF_SIZE
] = 0;
1881 lcd_set_drawmode(DRMODE_SOLID
);
1882 lcd_drawrect(0, hist_pos_y
- 1,
1883 HIST_W
+ 2, hist_size_h
+ 1);
1884 lcd_drawrect(HIST_W
+ 6, hist_pos_y
- 1,
1885 HIST_W
+ 2, hist_size_h
+ 1);
1886 lcd_set_drawmode(DRMODE_FG
);
1889 for (i
= HIST_W
-1; i
>= 0; i
--)
1893 j
= HIST_BUF_SIZE
-1;
1896 if (history_l
[j
] == hist_size_h
)
1897 lcd_set_foreground(LCD_HIST_OVER
);
1898 #ifdef HAVE_LCD_COLOR
1899 else if (history_l
[j
] > hist_level_marks
[1])
1900 lcd_set_foreground(LCD_HIST_HI
);
1903 lcd_set_foreground(LCD_HIST_OK
);
1904 lcd_vline(1 + i
, HIST_Y
-1, HIST_Y
- history_l
[j
]);
1908 if (history_r
[j
] == hist_size_h
)
1909 lcd_set_foreground(LCD_HIST_OVER
);
1910 #ifdef HAVE_LCD_COLOR
1911 else if (history_r
[j
] > hist_level_marks
[1])
1912 lcd_set_foreground(LCD_HIST_HI
);
1915 lcd_set_foreground(LCD_HIST_OK
);
1916 lcd_vline(HIST_W
+7 + i
, HIST_Y
-1, HIST_Y
- history_r
[j
]);
1920 #ifdef HAVE_LCD_COLOR
1921 global_settings
.fg_color
);
1925 for (i
= 0; i
< 6; i
++)
1926 lcd_hline(HIST_W
+ 3, HIST_W
+ 4,
1927 HIST_Y
- hist_level_marks
[i
]);
1929 #endif /* HAVE_RECORDING_HISTOGRAM */
1935 /* draw the trigger status */
1936 if (peak_meter_trigger_status() != TRIG_OFF
)
1938 peak_meter_draw_trig(pm_x
, trig_ypos
, trig_width
,
1940 FOR_NB_ACTIVE_SCREENS(i
)
1941 screens
[i
].update_viewport_rect(pm_x
[i
], trig_ypos
[i
],
1942 trig_width
[i
] + 2, TRIG_HEIGHT
);
1947 if (global_settings
.rec_source
== AUDIO_SRC_MIC
)
1949 if(agc_maxgain
< (global_settings
.rec_mic_gain
))
1950 change_recording_gain(false, true, true);
1955 if(agc_maxgain
< (global_settings
.rec_left_gain
))
1956 change_recording_gain(false, true, false);
1957 if(agc_maxgain
< (global_settings
.rec_right_gain
))
1958 change_recording_gain(false, false, true);
1960 #endif /* HAVE_AGC */
1962 #if CONFIG_CODEC == SWCODEC
1963 #ifdef HAVE_SPDIF_REC
1964 if((global_settings
.rec_source
== AUDIO_SRC_SPDIF
) &&
1965 (prev_sample_rate
!= pcm_rec_sample_rate()))
1967 /* spdif samplerate changed */
1968 prev_sample_rate
= pcm_rec_sample_rate();
1976 /* update_list is set whenever content changes */
1977 update_list
= false;
1978 gui_synclist_draw(&lists
);
1981 /* draw peakmeter again (check if this can be removed) */
1982 FOR_NB_ACTIVE_SCREENS(i
)
1984 screens
[i
].set_viewport(&vp_top
[i
]);
1985 peak_meter_screen(&screens
[i
], pm_x
[i
], pm_y
[i
], pm_h
[i
]);
1986 screens
[i
].update();
1988 } /* display update every second */
1990 if(audio_stat
& AUDIO_STATUS_ERROR
)
1994 } /* end while(!done) */
1996 audio_stat
= audio_status();
1997 if (audio_stat
& AUDIO_STATUS_ERROR
)
1999 splash(0, str(LANG_DISK_FULL
));
2002 screens
[i
].update();
2004 #if CONFIG_CODEC == SWCODEC
2005 /* stop recording - some players like H10 freeze otherwise
2006 TO DO: find out why it freezes and fix properly */
2007 rec_command(RECORDING_CMD_STOP
);
2008 audio_close_recording();
2011 audio_error_clear();
2015 if (action_userabort(TIMEOUT_NOBLOCK
))
2022 #if CONFIG_CODEC == SWCODEC
2023 rec_command(RECORDING_CMD_STOP
);
2024 audio_close_recording();
2026 #ifdef HAVE_FMRADIO_REC
2027 if (radio_status
!= FMRADIO_OFF
)
2028 /* Restore radio playback - radio_status should be unchanged if started
2029 through fm radio screen (barring usb connect) */
2030 rec_set_source(AUDIO_SRC_FMRADIO
, (radio_status
& FMRADIO_PAUSED
) ?
2031 SRCF_FMRADIO_PAUSED
: SRCF_FMRADIO_PLAYING
);
2034 /* Go back to playback mode */
2035 rec_set_source(AUDIO_SRC_PLAYBACK
, SRCF_PLAYBACK
);
2037 /* restore talking */
2038 talk_disable(false);
2039 #else /* !SWCODEC */
2040 audio_init_playback();
2041 #endif /* CONFIG_CODEC == SWCODEC */
2044 /* Re-enable speaker */
2045 audiohw_enable_speaker(global_settings
.speaker_enabled
);
2048 /* make sure the trigger is really turned off */
2049 peak_meter_trigger(false);
2050 peak_meter_set_trigger_listener(NULL
);
2052 rec_status
&= ~RCSTAT_IN_RECSCREEN
;
2053 sound_settings_apply();
2056 screens
[i
].setfont(FONT_UI
);
2058 /* if the directory was created or recording happened, make sure the
2059 browser is updated */
2060 if (rec_status
& (RCSTAT_CREATED_DIRECTORY
| RCSTAT_HAVE_RECORDED
))
2063 #if (CONFIG_STORAGE & STORAGE_ATA) && (CONFIG_LED == LED_REAL) \
2064 && !defined(SIMULATOR)
2065 ata_set_led_enabled(true);
2070 return (rec_status
& RCSTAT_BEEN_IN_USB_MODE
) != 0;
2071 } /* recording_screen */
2073 #if CONFIG_KEYPAD == RECORDER_PAD
2074 static bool f2_rec_screen(void)
2076 static const char* const freq_str
[6] =
2091 struct audio_recording_options rec_options
;
2095 screens
[i
].set_viewport(NULL
);
2096 screens
[i
].setfont(FONT_SYSFIXED
);
2097 screens
[i
].getstringsize("A",&w
,&h
);
2105 screens
[i
].clear_display();
2107 /* Recording quality */
2108 screens
[i
].putsxy(0, LCD_HEIGHT
/2 - h
*2,
2109 str(LANG_SYSFONT_RECORDING_QUALITY
));
2112 snprintf(buf
, sizeof(buf
), "%d", global_settings
.rec_quality
);
2115 screens
[i
].putsxy(0, LCD_HEIGHT
/2-h
, buf
);
2116 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_FastBackward
],
2117 LCD_WIDTH
/2 - 16, LCD_HEIGHT
/2 - 4, 7, 8);
2121 snprintf(buf
, sizeof buf
, "%s:", str(LANG_SYSFONT_RECORDING_FREQUENCY
));
2122 ptr
= freq_str
[global_settings
.rec_frequency
];
2125 screens
[i
].getstringsize(buf
,&w
,&h
);
2126 screens
[i
].putsxy((LCD_WIDTH
-w
)/2, LCD_HEIGHT
- h
*2, buf
);
2127 screens
[i
].getstringsize(ptr
, &w
, &h
);
2128 screens
[i
].putsxy((LCD_WIDTH
-w
)/2, LCD_HEIGHT
- h
, ptr
);
2129 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_DownArrow
],
2130 LCD_WIDTH
/2 - 3, LCD_HEIGHT
- h
*3, 7, 8);
2134 switch ( global_settings
.rec_channels
) {
2136 ptr
= str(LANG_SYSFONT_CHANNEL_STEREO
);
2140 ptr
= str(LANG_SYSFONT_CHANNEL_MONO
);
2146 screens
[i
].getstringsize(str(LANG_SYSFONT_CHANNELS
), &w
, &h
);
2147 screens
[i
].putsxy(LCD_WIDTH
- w
, LCD_HEIGHT
/2 - h
*2,
2148 str(LANG_SYSFONT_CHANNELS
));
2149 screens
[i
].getstringsize(str(LANG_SYSFONT_MODE
), &w
, &h
);
2150 screens
[i
].putsxy(LCD_WIDTH
- w
, LCD_HEIGHT
/2 - h
,
2151 str(LANG_SYSFONT_MODE
));
2152 screens
[i
].getstringsize(ptr
, &w
, &h
);
2153 screens
[i
].putsxy(LCD_WIDTH
- w
, LCD_HEIGHT
/2, ptr
);
2154 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_FastForward
],
2155 LCD_WIDTH
/2 + 8, LCD_HEIGHT
/2 - 4, 7, 8);
2157 screens
[i
].update();
2160 button
= button_get(true);
2163 case BUTTON_F2
| BUTTON_LEFT
:
2164 global_settings
.rec_quality
++;
2165 if(global_settings
.rec_quality
> 7)
2166 global_settings
.rec_quality
= 0;
2171 case BUTTON_F2
| BUTTON_DOWN
:
2172 global_settings
.rec_frequency
++;
2173 if(global_settings
.rec_frequency
> 5)
2174 global_settings
.rec_frequency
= 0;
2179 case BUTTON_F2
| BUTTON_RIGHT
:
2180 global_settings
.rec_channels
++;
2181 if(global_settings
.rec_channels
> 1)
2182 global_settings
.rec_channels
= 0;
2186 case BUTTON_F2
| BUTTON_REL
:
2192 case BUTTON_F2
| BUTTON_REPEAT
:
2197 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
2203 rec_init_recording_options(&rec_options
);
2204 rec_set_recording_options(&rec_options
);
2210 screens
[i
].setfont(FONT_UI
);
2215 static bool f3_rec_screen(void)
2221 const char *src_str
[] =
2223 str(LANG_SYSFONT_RECORDING_SRC_MIC
),
2224 str(LANG_SYSFONT_LINE_IN
),
2225 str(LANG_SYSFONT_RECORDING_SRC_DIGITAL
)
2227 struct audio_recording_options rec_options
;
2231 screens
[i
].set_viewport(NULL
);
2232 screens
[i
].setfont(FONT_SYSFIXED
);
2233 screens
[i
].getstringsize("A",&w
,&h
);
2237 const char* ptr
= src_str
[global_settings
.rec_source
];
2240 screens
[i
].clear_display();
2242 /* Recording source */
2243 screens
[i
].putsxy(0, LCD_HEIGHT
/2 - h
*2,
2244 str(LANG_SYSFONT_RECORDING_SOURCE
));
2246 screens
[i
].getstringsize(ptr
, &w
, &h
);
2247 screens
[i
].putsxy(0, LCD_HEIGHT
/2-h
, ptr
);
2248 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_FastBackward
],
2249 LCD_WIDTH
/2 - 16, LCD_HEIGHT
/2 - 4, 7, 8);
2253 ptr
= str(LANG_SYSFONT_RECORD_TRIGGER
);
2256 screens
[i
].getstringsize(ptr
,&w
,&h
);
2257 screens
[i
].putsxy((LCD_WIDTH
-w
)/2, LCD_HEIGHT
- h
*2, ptr
);
2258 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_DownArrow
],
2259 LCD_WIDTH
/2 - 3, LCD_HEIGHT
- h
*3, 7, 8);
2261 screens
[i
].update();
2264 button
= button_get(true);
2267 case BUTTON_F3
| BUTTON_DOWN
:
2270 settings_apply_trigger();
2276 case BUTTON_F3
| BUTTON_LEFT
:
2277 global_settings
.rec_source
++;
2278 if(global_settings
.rec_source
> AUDIO_SRC_MAX
)
2279 global_settings
.rec_source
= 0;
2283 case BUTTON_F3
| BUTTON_REL
:
2289 case BUTTON_F3
| BUTTON_REPEAT
:
2294 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
2300 rec_init_recording_options(&rec_options
);
2301 rec_set_recording_options(&rec_options
);
2307 screens
[i
].setfont(FONT_UI
);
2311 #endif /* CONFIG_KEYPAD == RECORDER_PAD */
2313 #if CONFIG_CODEC == SWCODEC
2314 void audio_beep(int duration
)
2321 /* stubs for recording sim */
2322 void audio_init_recording(unsigned int buffer_offset
)
2324 buffer_offset
= buffer_offset
;
2327 void audio_close_recording(void)
2331 unsigned long pcm_rec_get_warnings(void)
2336 unsigned long pcm_rec_sample_rate(void)
2341 unsigned long audio_recorded_time(void)
2346 unsigned long audio_num_recorded_bytes(void)
2348 return 5 * 1024 * 1024;
2351 void rec_set_source(int source
, unsigned flags
)
2357 void audio_set_recording_options(struct audio_recording_options
*options
)
2362 void audio_set_recording_gain(int left
, int right
, int type
)
2369 void audio_record(const char *filename
)
2371 filename
= filename
;
2374 void audio_new_file(const char *filename
)
2376 filename
= filename
;
2379 void audio_stop_recording(void)
2383 void audio_pause_recording(void)
2387 void audio_resume_recording(void)
2391 #endif /* #ifdef SIMULATOR */
2392 #endif /* #ifdef CONFIG_CODEC == SWCODEC */
2394 #endif /* HAVE_RECORDING */