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_Y (hist_pos_y+hist_size_h-1)
280 #define HIST_W (LCD_WIDTH / 2 - 4)
282 #ifdef HAVE_LCD_COLOR
283 #define LCD_BAL_L LCD_RGBPACK(0, 0, 255)
284 #define LCD_BAL_R LCD_RGBPACK(204, 0, 0)
285 #define LCD_HIST_OVER LCD_RGBPACK(204, 0, 0)
286 #define LCD_HIST_HI LCD_RGBPACK(255, 204, 0)
287 #define LCD_HIST_OK LCD_RGBPACK(51, 153, 0)
288 #else /* HAVE_LCD_COLOR */
289 #define LCD_BATT_OK LCD_BLACK
290 #define LCD_BATT_LO LCD_DARKGRAY
291 #define LCD_DISK_OK LCD_BLACK
292 #define LCD_DISK_LO LCD_DARKGRAY
293 #define LCD_HIST_OVER LCD_BLACK
294 #define LCD_HIST_OK LCD_DARKGRAY
295 #define LCD_BAL LCD_DARKGRAY
296 #endif /* HAVE_LCD_COLOR */
297 #else /* LCD_DEPTH > 1 */
298 #define LCD_HIST_OVER LCD_DEFAULT_FG
299 #define LCD_HIST_OK LCD_DEFAULT_FG
300 #define LCD_BAL LCD_DEFAULT_FG
301 #endif /* LCD_DEPTH > 1 */
302 #endif /* HAVE_RECORDING_HISTOGRAM */
304 static void set_gain(void)
307 if(global_settings
.rec_source
== AUDIO_SRC_MIC
)
309 audio_set_recording_gain(global_settings
.rec_mic_gain
,
315 /* AUDIO_SRC_LINEIN, AUDIO_SRC_FMRADIO, AUDIO_SRC_SPDIF */
316 audio_set_recording_gain(global_settings
.rec_left_gain
,
317 global_settings
.rec_right_gain
,
320 /* reset the clipping indicators */
321 peak_meter_set_clip_hold(global_settings
.peak_meter_clip_hold
);
326 /* Read peak meter values & calculate balance.
327 * Returns validity of peak values.
328 * Used for automatic gain control and history diagram.
330 static bool read_peak_levels(int *peak_l
, int *peak_r
, int *balance
)
332 peak_meter_get_peakhold(peak_l
, peak_r
);
333 peak_valid_mem
[peak_time
% 3] = *peak_l
;
334 if (((peak_valid_mem
[0] == peak_valid_mem
[1]) &&
335 (peak_valid_mem
[1] == peak_valid_mem
[2])) &&
336 ((*peak_l
< 32767) || storage_disk_is_active()))
339 if (*peak_r
> *peak_l
)
340 balance_mem
[peak_time
% BAL_MEM_SIZE
] = (*peak_l
?
341 MIN((10000 * *peak_r
) / *peak_l
- 10000, 15118) : 15118);
343 balance_mem
[peak_time
% BAL_MEM_SIZE
] = (*peak_r
?
344 MAX(10000 - (10000 * *peak_l
) / *peak_r
, -15118) : -15118);
347 for (i
= 0; i
< BAL_MEM_SIZE
; i
++)
348 *balance
+= balance_mem
[i
];
349 *balance
= *balance
/ BAL_MEM_SIZE
;
351 #ifdef HAVE_RECORDING_HISTOGRAM
352 if (*peak_l
> hist_l
)
354 if (*peak_r
> hist_r
)
361 /* AGC helper function to check if maximum gain is reached */
362 static bool agc_gain_is_max(bool left
, bool right
)
364 /* range -128...+108 [0.5dB] */
365 short gain_current_l
;
366 short gain_current_r
;
371 switch (global_settings
.rec_source
)
373 #if defined(HAVE_LINE_REC) || defined(HAVE_FMRADIO_REC)
374 HAVE_LINE_REC_(case AUDIO_SRC_LINEIN
:)
375 HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO
:)
376 gain_current_l
= global_settings
.rec_left_gain
;
377 gain_current_r
= global_settings
.rec_right_gain
;
379 #endif /* LINE, FMRADIO */
380 #if defined(HAVE_MIC_REC)
383 gain_current_l
= global_settings
.rec_mic_gain
;
384 gain_current_r
= global_settings
.rec_mic_gain
;
388 return ((left
&& (gain_current_l
>= agc_maxgain
)) ||
389 (right
&& (gain_current_r
>= agc_maxgain
)));
392 static void change_recording_gain(bool increment
, bool left
, bool right
)
394 int factor
= (increment
? 1 : -1);
396 switch (global_settings
.rec_source
)
398 #if defined(HAVE_LINE_REC) || defined(HAVE_FMRADIO_REC)
399 HAVE_LINE_REC_(case AUDIO_SRC_LINEIN
:)
400 HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO
:)
401 if (left
) global_settings
.rec_left_gain
+= factor
;
402 if (right
) global_settings
.rec_right_gain
+= factor
;
404 #endif /* LINE, FMRADIO */
405 #if defined(HAVE_MIC_REC)
407 global_settings
.rec_mic_gain
+= factor
;
413 * Handle automatic gain control (AGC).
414 * Change recording gain if peak_x levels are above or below
415 * target volume for specified timeouts.
417 static void auto_gain_control(int *peak_l
, int *peak_r
, int *balance
)
423 if (*peak_l
> agc_left
)
426 agc_left
-= (agc_left
- *peak_l
+ 3) >> 2;
427 if (*peak_r
> agc_right
)
430 agc_right
-= (agc_right
- *peak_r
+ 3) >> 2;
431 agc_mono
= (agc_left
+ agc_right
) / 2;
433 agc_mode
= abs(agc_preset
) - 1;
439 if (agc_mode
!= AGC_SAFETY_MODE
) {
440 /* Automatic balance control - only if not in safety mode */
441 if ((agc_left
> AGC_IMG
) && (agc_right
> AGC_IMG
))
446 agc_baltime
-= !(peak_time
% 4); /* 0.47 - 0.75dB */
447 else if (*balance
> -4125)
448 agc_baltime
--; /* 0.75 - 3.00dB */
449 else if (*balance
> -7579)
450 agc_baltime
-= 2; /* 3.00 - 4.90dB */
452 agc_baltime
-= !(peak_time
% 8); /* 4.90 - inf dB */
454 agc_baltime
-= (peak_time
% 2);
456 else if (*balance
> 556)
459 agc_baltime
+= !(peak_time
% 4);
460 else if (*balance
< 4125)
462 else if (*balance
< 7579)
465 agc_baltime
+= !(peak_time
% 8);
467 agc_baltime
+= (peak_time
% 2);
470 if ((*balance
* agc_baltime
) < 0)
473 agc_baltime
-= peak_time
% 2;
475 agc_baltime
+= peak_time
% 2;
478 increment
= ((agc_risetime
/ 2) > agc_droptime
);
480 if (agc_baltime
< -agc_tbal
[agc_mode
])
482 if (!increment
|| !agc_gain_is_max(!increment
, increment
)) {
483 change_recording_gain(increment
, !increment
, increment
);
488 else if (agc_baltime
> +agc_tbal
[agc_mode
])
490 if (!increment
|| !agc_gain_is_max(increment
, !increment
)) {
491 change_recording_gain(increment
, increment
, !increment
);
497 else if (!(hist_time
% 4))
506 /* Automatic gain control */
507 if ((agc_left
> agc_th_hi
[agc_mode
]) || (agc_right
> agc_th_hi
[agc_mode
]))
509 if ((agc_left
> AGC_CLIP
) || (agc_right
> AGC_CLIP
))
510 agc_droptime
+= agc_tdrop
[agc_mode
] /
511 (global_settings
.rec_agc_cliptime
+ 1);
512 if (agc_left
> AGC_HIGH
) {
515 if (agc_left
> AGC_PEAK
)
518 if (agc_right
> AGC_HIGH
) {
521 if (agc_right
> AGC_PEAK
)
524 if (agc_mono
> agc_th_hi
[agc_mode
])
527 agc_droptime
+= !(peak_time
% 2);
529 if (agc_droptime
>= agc_tdrop
[agc_mode
])
531 change_recording_gain(false, true, true);
536 agc_risetime
= MAX(agc_risetime
- 1, 0);
538 else if (agc_mono
< agc_th_lo
[agc_mode
])
540 if (agc_mono
< (agc_th_lo
[agc_mode
] / 8))
541 agc_risetime
+= !(peak_time
% 5);
542 else if (agc_mono
< (agc_th_lo
[agc_mode
] / 2))
547 if (agc_risetime
>= agc_trise
[agc_mode
]) {
548 if ((agc_mode
!= AGC_SAFETY_MODE
) &&
549 (!agc_gain_is_max(true, true))) {
550 change_recording_gain(true, true, true);
556 agc_droptime
= MAX(agc_droptime
- 1, 0);
558 else if (!(peak_time
% 6)) /* on target level every 1.2 sec */
560 agc_risetime
= MAX(agc_risetime
- 1, 0);
561 agc_droptime
= MAX(agc_droptime
- 1, 0);
564 #endif /* HAVE_AGC */
566 static const char* const fmtstr
[] =
568 "%c%d %s", /* no decimals */
569 "%c%d.%d %s ", /* 1 decimal */
570 "%c%d.%02d %s " /* 2 decimals */
573 static char *fmt_gain(int snd
, int val
, char *str
, int len
)
579 val
= sound_val2phys(snd
, val
);
585 numdec
= sound_numdecimals(snd
);
586 unit
= sound_unit(snd
);
590 i
= val
/ (10*numdec
);
591 d
= val
% (10*numdec
);
592 snprintf(str
, len
, fmtstr
[numdec
], sign
, i
, d
, unit
);
595 snprintf(str
, len
, fmtstr
[numdec
], sign
, val
, unit
);
600 /* the list below must match enum audio_sources in audio.h */
601 static const char* const prestr
[] =
603 HAVE_MIC_IN_([AUDIO_SRC_MIC
] = "R_MIC_",)
604 HAVE_LINE_REC_([AUDIO_SRC_LINEIN
] = "R_LINE_",)
605 HAVE_SPDIF_IN_([AUDIO_SRC_SPDIF
] = "R_SPDIF_",)
606 HAVE_FMRADIO_REC_([AUDIO_SRC_FMRADIO
] = "R_FM_",)
609 char *rec_create_filename(char *buffer
)
612 const char *pref
= "R_";
614 /* Directory existence and writeablility should have already been
615 * verified - do not pass NULL pointers to pcmrec */
617 if((unsigned)global_settings
.rec_source
< AUDIO_NUM_SOURCES
)
619 pref
= prestr
[global_settings
.rec_source
];
622 strcpy(buffer
, global_settings
.rec_directory
);
624 snprintf(ext
, sizeof(ext
), ".%s",
625 REC_FILE_ENDING(global_settings
.rec_format
));
628 return create_numbered_filename(buffer
, buffer
, pref
, ext
, 4,
631 /* We'll wait at least up to the start of the next second so no duplicate
633 return create_datetime_filename(buffer
, buffer
, pref
, ext
, true);
638 /* Hit disk to get a starting filename for the type */
639 static void rec_init_filename(void)
642 rec_create_filename(path_buffer
);
647 int rec_create_directory(void)
650 const char * const folder
= global_settings
.rec_directory
;
652 if (strcmp(folder
, "/") && !dir_exists(folder
))
658 while (action_userabort(HZ
) == false)
661 str(LANG_REC_DIR_NOT_WRITABLE
),
662 str(LANG_OFF_ABORT
));
667 rec_status
|= RCSTAT_CREATED_DIRECTORY
;
675 void rec_init_recording_options(struct audio_recording_options
*options
)
677 options
->rec_source
= global_settings
.rec_source
;
678 options
->rec_frequency
= global_settings
.rec_frequency
;
679 options
->rec_channels
= global_settings
.rec_channels
;
680 options
->rec_prerecord_time
= global_settings
.rec_prerecord_time
;
681 #if CONFIG_CODEC == SWCODEC
682 options
->rec_mono_mode
= global_settings
.rec_mono_mode
;
683 options
->rec_source_flags
= 0;
684 options
->enc_config
.rec_format
= global_settings
.rec_format
;
685 global_to_encoder_config(&options
->enc_config
);
687 options
->rec_quality
= global_settings
.rec_quality
;
688 options
->rec_editable
= global_settings
.rec_editable
;
692 #if CONFIG_CODEC == SWCODEC && !defined (SIMULATOR)
693 void rec_set_source(int source
, unsigned flags
)
695 /* Set audio input source, power up/down devices */
696 audio_set_input_source(source
, flags
);
698 /* Set peakmeters for recording or reset to playback */
699 peak_meter_playback((flags
& SRCF_RECORDING
) == 0);
700 peak_meter_enabled
= true;
702 #endif /* CONFIG_CODEC == SWCODEC && !defined (SIMULATOR) */
704 void rec_set_recording_options(struct audio_recording_options
*options
)
706 #if CONFIG_CODEC != SWCODEC
707 if (global_settings
.rec_prerecord_time
)
709 talk_buffer_steal(); /* will use the mp3 buffer */
711 #else /* == SWCODEC */
712 rec_set_source(options
->rec_source
,
713 options
->rec_source_flags
| SRCF_RECORDING
);
714 #endif /* CONFIG_CODEC != SWCODEC */
716 audio_set_recording_options(options
);
719 void rec_command(enum recording_command cmd
)
723 case RECORDING_CMD_STOP_SHUTDOWN
:
724 pm_activate_clipcount(false);
725 audio_stop_recording();
726 #if CONFIG_CODEC == SWCODEC
727 audio_close_recording();
731 case RECORDING_CMD_STOP
:
732 pm_activate_clipcount(false);
733 audio_stop_recording();
735 case RECORDING_CMD_START
:
736 /* steal mp3 buffer, create unique filename and start recording */
737 pm_reset_clipcount();
738 pm_activate_clipcount(true);
739 #if CONFIG_CODEC != SWCODEC
740 talk_buffer_steal(); /* we use the mp3 buffer */
742 audio_record(rec_create_filename(path_buffer
));
744 case RECORDING_CMD_START_NEWFILE
:
745 /* create unique filename and start recording*/
746 pm_reset_clipcount();
747 pm_activate_clipcount(true); /* just to be sure */
748 audio_new_file(rec_create_filename(path_buffer
));
750 case RECORDING_CMD_PAUSE
:
751 pm_activate_clipcount(false);
752 audio_pause_recording();
754 case RECORDING_CMD_RESUME
:
755 pm_activate_clipcount(true);
756 audio_resume_recording();
762 /* used in trigger_listerner and recording_screen */
763 static unsigned int last_seconds
= 0;
766 * Callback function so that the peak meter code can send an event
767 * to this application. This function can be passed to
768 * peak_meter_set_trigger_listener in order to activate the trigger.
770 static void trigger_listener(int trigger_status
)
772 switch (trigger_status
)
775 if(!(audio_status() & AUDIO_STATUS_RECORD
))
777 rec_status
|= RCSTAT_HAVE_RECORDED
;
778 rec_command(RECORDING_CMD_START
);
779 #if CONFIG_CODEC != SWCODEC
780 /* give control to mpeg thread so that it can start
782 yield(); yield(); yield();
786 /* if we're already recording this is a retrigger */
789 if((audio_status() & AUDIO_STATUS_PAUSE
) &&
790 (global_settings
.rec_trigger_type
== TRIG_TYPE_PAUSE
))
792 rec_command(RECORDING_CMD_RESUME
);
794 /* New file on trig start*/
795 else if (global_settings
.rec_trigger_type
!= TRIG_TYPE_NEW_FILE
)
797 rec_command(RECORDING_CMD_START_NEWFILE
);
798 /* tell recording_screen to reset the time */
804 /* A _change_ to TRIG_READY means the current recording has stopped */
806 if(audio_status() & AUDIO_STATUS_RECORD
)
808 switch(global_settings
.rec_trigger_type
)
810 case TRIG_TYPE_STOP
: /* Stop */
811 rec_command(RECORDING_CMD_STOP
);
814 case TRIG_TYPE_PAUSE
: /* Pause */
815 rec_command(RECORDING_CMD_PAUSE
);
818 case TRIG_TYPE_NEW_FILE
: /* New file on trig stop*/
819 rec_command(RECORDING_CMD_START_NEWFILE
);
820 /* tell recording_screen to reset the time */
824 case 3: /* Stop and shutdown */
825 rec_command(RECORDING_CMD_STOP_SHUTDOWN
);
829 if (global_settings
.rec_trigger_mode
!= TRIG_MODE_REARM
)
831 peak_meter_set_trigger_listener(NULL
);
832 peak_meter_trigger(false);
839 /* Stuff for drawing the screen */
841 enum rec_list_items_stereo
{
857 enum rec_list_items_mono
{
862 ITEM_AGC_MAXDB_M
= 5,
871 #ifdef HAVE_SPDIF_REC
872 enum rec_list_items_spdif
{
874 #if CONFIG_CODEC == SWCODEC
875 ITEM_SAMPLERATE_D
= 6,
885 static int listid_to_enum
[ITEM_COUNT
];
887 static const char* reclist_get_name(int selected_item
, void * data
,
888 char * buffer
, size_t buffer_len
)
894 data
= data
; /* not used */
895 if(selected_item
>= ITEM_COUNT
)
898 switch (listid_to_enum
[selected_item
])
901 snprintf(buffer
, buffer_len
, "%s: %s", str(LANG_VOLUME
),
902 fmt_gain(SOUND_VOLUME
,
903 global_settings
.volume
,
904 buf2
, sizeof(buf2
)));
908 if(global_settings
.rec_source
== AUDIO_SRC_MIC
)
910 /* Draw MIC recording gain */
911 snprintf(buffer
, buffer_len
, "%s: %s", str(LANG_GAIN
),
912 fmt_gain(SOUND_MIC_GAIN
,
913 global_settings
.rec_mic_gain
,
914 buf2
, sizeof(buf2
)));
919 int avg_gain
= (global_settings
.rec_left_gain
+
920 global_settings
.rec_right_gain
) / 2;
921 snprintf(buffer
, buffer_len
, "%s: %s", str(LANG_GAIN
),
922 fmt_gain(SOUND_LEFT_GAIN
,
924 buf2
, sizeof(buf2
)));
928 snprintf(buffer
, buffer_len
, "%s: %s",
930 fmt_gain(SOUND_LEFT_GAIN
,
931 global_settings
.rec_left_gain
,
932 buf2
, sizeof(buf2
)));
935 snprintf(buffer
, buffer_len
, "%s: %s",
936 str(LANG_GAIN_RIGHT
),
937 fmt_gain(SOUND_RIGHT_GAIN
,
938 global_settings
.rec_right_gain
,
939 buf2
, sizeof(buf2
)));
943 snprintf(buffer
, buffer_len
, "%s: %s",
944 str(LANG_RECORDING_AGC_PRESET
),
945 agc_preset_str
[agc_preset
]);
949 snprintf(buffer
, buffer_len
, "%s: %s",
950 str(LANG_RECORDING_AGC_MAXGAIN
),
951 fmt_gain(SOUND_LEFT_GAIN
,
952 agc_maxgain
, buf2
, sizeof(buf2
)));
954 else if (global_settings
.rec_source
== AUDIO_SRC_MIC
)
955 snprintf(buffer
, buffer_len
, "%s: %s (%s)",
956 str(LANG_RECORDING_AGC_MAXGAIN
),
957 fmt_gain(SOUND_MIC_GAIN
,
958 agc_maxgain
, buf2
, sizeof(buf2
)),
959 fmt_gain(SOUND_MIC_GAIN
,
960 agc_maxgain
- global_settings
.rec_mic_gain
,
961 buf3
, sizeof(buf3
)));
964 snprintf(buffer
, buffer_len
, "%s: %s (%s)",
965 str(LANG_RECORDING_AGC_MAXGAIN
),
966 fmt_gain(SOUND_LEFT_GAIN
,
967 agc_maxgain
, buf2
, sizeof(buf2
)),
968 fmt_gain(SOUND_LEFT_GAIN
,
970 (global_settings
.rec_left_gain
+
971 global_settings
.rec_right_gain
)/2,
972 buf3
, sizeof(buf3
)));
975 #if CONFIG_CODEC == SWCODEC
976 #ifdef HAVE_SPDIF_REC
977 case ITEM_SAMPLERATE_D
:
978 snprintf(buffer
, buffer_len
, "%s: %d",
979 str(LANG_RECORDING_FREQUENCY
),
980 pcm_rec_sample_rate());
986 if(audio_status() & AUDIO_STATUS_RECORD
)
988 size_t tot_len
= strlen(path_buffer
) +
989 strlen(str(LANG_RECORDING_FILENAME
)) + 1;
990 if(tot_len
> buffer_len
)
992 snprintf(buffer
, buffer_len
, "%s %s",
993 str(LANG_RECORDING_FILENAME
),
994 path_buffer
+ tot_len
- buffer_len
);
998 snprintf(buffer
, buffer_len
, "%s %s",
999 str(LANG_RECORDING_FILENAME
), path_buffer
);
1004 return str(LANG_RECORDING_FILENAME
);
1015 bool recording_start_automatic
= false;
1017 bool recording_screen(bool no_source
)
1020 int done
= -1; /* negative to re-init, positive to quit, zero to run */
1021 char buf
[32]; /* for preparing strings */
1022 char buf2
[32]; /* for preparing strings */
1023 int w
, h
; /* character width/height */
1024 int update_countdown
= 0; /* refresh counter */
1025 unsigned int seconds
;
1027 int audio_stat
= 0; /* status of the audio system */
1028 int last_audio_stat
= -1; /* previous status so we can act on changes */
1029 struct viewport vp_list
[NB_SCREENS
], vp_top
[NB_SCREENS
]; /* the viewports */
1031 #if CONFIG_CODEC == SWCODEC
1032 int warning_counter
= 0;
1033 #define WARNING_PERIOD 7
1036 #if CONFIG_CODEC == SWCODEC
1037 #ifdef HAVE_SPDIF_REC
1038 unsigned long prev_sample_rate
= 0;
1042 #ifdef HAVE_FMRADIO_REC
1043 /* Radio is left on if:
1044 * 1) Is was on at the start and the initial source is FM Radio
1045 * 2) 1) and the source was never changed to something else
1047 int radio_status
= (global_settings
.rec_source
!= AUDIO_SRC_FMRADIO
) ?
1048 FMRADIO_OFF
: get_radio_status();
1050 #if (CONFIG_LED == LED_REAL)
1051 bool led_state
= false;
1052 int led_countdown
= 2;
1055 bool peak_read
= false;
1060 int pm_x
[NB_SCREENS
]; /* peakmeter (and trigger bar) x pos */
1061 int pm_y
[NB_SCREENS
]; /* peakmeter y pos */
1062 int pm_h
[NB_SCREENS
]; /* peakmeter height */
1063 int trig_ypos
[NB_SCREENS
]; /* trigger bar y pos */
1064 int trig_width
[NB_SCREENS
]; /* trigger bar width */
1065 int top_height_req
[NB_SCREENS
]; /* required height for top half */
1066 bool compact_view
[NB_SCREENS
]; /* tweak layout tiny screens / big fonts */
1067 struct gui_synclist lists
; /* the list in the bottom vp */
1068 #if defined(HAVE_AGC) || defined(HAVE_RECORDING_HISTOGRAM)
1069 bool peak_valid
= false;
1071 #if defined(HAVE_RECORDING_HISTOGRAM)
1072 unsigned short hist_pos_y
= 0;
1073 unsigned short hist_size_h
= 0;
1074 int history_pos
= 0;
1075 short hist_time_interval
= 1; /* 1, 2, 4, 8 */
1076 unsigned char history_l
[HIST_W
];
1077 unsigned char history_r
[HIST_W
];
1078 const char hist_level_marks
[6] = { 29, 26, 23, 17, 9, 2};
1080 #ifdef HAVE_FMRADIO_REC
1081 int prev_rec_source
= global_settings
.rec_source
; /* detect source change */
1084 struct audio_recording_options rec_options
;
1085 rec_status
= RCSTAT_IN_RECSCREEN
;
1087 #if (CONFIG_STORAGE & STORAGE_ATA) && (CONFIG_LED == LED_REAL) \
1088 && !defined(SIMULATOR)
1089 ata_set_led_enabled(false);
1092 #if CONFIG_CODEC == SWCODEC
1093 /* recording_menu gets messed up: so prevent manus talking */
1095 /* audio_init_recording stops anything playing when it takes the audio
1098 /* Yes, we use the D/A for monitoring */
1099 peak_meter_enabled
= true;
1100 peak_meter_playback(true);
1104 peak_meter_get_peakhold(&peak_l
, &peak_r
);
1107 pm_reset_clipcount();
1108 pm_activate_clipcount(false);
1109 settings_apply_trigger();
1112 agc_preset_str
[0] = str(LANG_OFF
);
1113 agc_preset_str
[1] = str(LANG_AGC_SAFETY
);
1114 agc_preset_str
[2] = str(LANG_AGC_LIVE
);
1115 agc_preset_str
[3] = str(LANG_AGC_DJSET
);
1116 agc_preset_str
[4] = str(LANG_AGC_MEDIUM
);
1117 agc_preset_str
[5] = str(LANG_AGC_VOICE
);
1118 #endif /* HAVE_AGC */
1121 /* Disable speaker to prevent feedback */
1122 audiohw_enable_speaker(false);
1125 #if CONFIG_CODEC == SWCODEC
1126 audio_close_recording();
1128 audio_init_recording(0);
1129 sound_set_volume(global_settings
.volume
);
1132 /* Create new filename for recording start */
1133 rec_init_filename();
1136 /* start of the loop: we stay in this loop until user quits recscreen */
1141 /* request to re-init stuff, done after settings screen */
1143 #ifdef HAVE_FMRADIO_REC
1144 /* If input changes away from FM Radio,
1145 radio will remain off when recording screen closes. */
1146 if (global_settings
.rec_source
!= prev_rec_source
1147 && prev_rec_source
== AUDIO_SRC_FMRADIO
)
1148 radio_status
= FMRADIO_OFF
;
1149 prev_rec_source
= global_settings
.rec_source
;
1152 /* viewport init and calculations that only needs to be done once */
1156 /* top vp, 4 lines, force sys font if total screen < 6 lines
1157 NOTE: one could limit the list to 1 line and get away with 5 lines */
1158 top_height_req
[i
] = 4;
1159 #if defined(HAVE_RECORDING_HISTOGRAM)
1160 if((global_settings
.rec_histogram_interval
) && (!i
))
1161 top_height_req
[i
] += 1; /* use one line for histogram */
1162 hist_time_interval
= 1 << global_settings
.rec_histogram_interval
;
1165 viewport_set_defaults(v
, i
);
1166 if (viewport_get_nb_lines(v
) < top_height_req
[i
])
1168 /* compact needs 4 lines total */
1169 v
->font
= FONT_SYSFIXED
;
1170 compact_view
[i
] = false;
1175 if (viewport_get_nb_lines(v
) < (top_height_req
[i
]+2))
1176 compact_view
[i
] = true;
1178 compact_view
[i
] = false;
1180 vp_list
[i
] = *v
; /* get a copy now so it can be sized more easily */
1181 v
->height
= (font_get(v
->font
)->height
)*(compact_view
[i
] ? 3 :
1184 /* list section, rest of the screen */
1185 vp_list
[i
].y
+= vp_top
[i
].height
;
1186 vp_list
[i
].height
-= vp_top
[i
].height
;
1187 screens
[i
].set_viewport(&vp_top
[i
]); /* req for next calls */
1189 screens
[i
].getstringsize("W", &w
, &h
);
1190 pm_y
[i
] = font_get(vp_top
[i
].font
)->height
* 2;
1191 trig_ypos
[i
] = font_get(vp_top
[i
].font
)->height
* 3;
1193 trig_ypos
[i
] -= (font_get(vp_top
[i
].font
)->height
)/2;
1196 /* init the bottom list */
1197 gui_synclist_init(&lists
, reclist_get_name
, NULL
, false, 1, vp_list
);
1198 gui_synclist_set_title(&lists
, NULL
, Icon_NOICON
);
1200 send_event(GUI_EVENT_ACTIONUPDATE
, (void*)1); /* force a redraw */
1202 #if defined(HAVE_RECORDING_HISTOGRAM)
1204 hist_pos_y
= (compact_view
[0] ? 3 : 4) * (font_get(vp_top
[0].font
)->height
)
1206 hist_size_h
= font_get(vp_top
[0].font
)->height
- 2;
1207 memset(history_l
, 0, sizeof(unsigned char)*HIST_W
);
1208 memset(history_r
, 0, sizeof(unsigned char)*HIST_W
);
1214 if(global_settings
.peak_meter_clipcounter
)
1217 screens
[i
].getstringsize(str(LANG_PM_CLIPCOUNT
),
1218 &clipwidth
, &h
); /* h is same */
1219 pm_x
[i
] = clipwidth
+1;
1221 if(global_settings
.rec_trigger_mode
== TRIG_MODE_OFF
)
1222 pm_h
[i
] = font_get(vp_top
[i
].font
)->height
* 2;
1224 pm_h
[i
] = font_get(vp_top
[i
].font
)->height
;
1227 trig_width
[i
] = vp_top
[i
].width
- pm_x
[i
];
1230 #if CONFIG_CODEC == SWCODEC
1231 audio_close_recording();
1232 audio_init_recording(0);
1235 rec_init_recording_options(&rec_options
);
1236 rec_set_recording_options(&rec_options
);
1238 if(rec_create_directory() < 0)
1244 #if CONFIG_CODEC == SWCODEC && CONFIG_RTC == 0
1245 /* If format changed, a new number is required */
1246 rec_init_filename();
1251 if (global_settings
.rec_source
== AUDIO_SRC_MIC
) {
1252 agc_preset
= global_settings
.rec_agc_preset_mic
;
1253 agc_maxgain
= global_settings
.rec_agc_maxgain_mic
;
1258 agc_preset
= global_settings
.rec_agc_preset_line
;
1259 agc_maxgain
= global_settings
.rec_agc_maxgain_line
;
1261 #endif /* HAVE_AGC */
1264 update_countdown
= 0; /* Update immediately */
1266 /* populate translation table for list id -> enum */
1267 #ifdef HAVE_SPDIF_REC
1268 if(global_settings
.rec_source
== AUDIO_SRC_SPDIF
)
1270 listid_to_enum
[0] = ITEM_VOLUME_D
;
1271 #if CONFIG_CODEC == SWCODEC
1272 listid_to_enum
[1] = ITEM_SAMPLERATE_D
;
1273 listid_to_enum
[2] = ITEM_FILENAME_D
;
1275 listid_to_enum
[1] = ITEM_FILENAME_D
;
1278 gui_synclist_set_nb_items(&lists
, ITEM_COUNT_D
); /* spdif */
1282 if(HAVE_MIC_REC_((global_settings
.rec_source
== AUDIO_SRC_MIC
) || )
1283 (global_settings
.rec_channels
== 1))
1285 listid_to_enum
[0] = ITEM_VOLUME_M
;
1286 listid_to_enum
[1] = ITEM_GAIN_M
;
1288 listid_to_enum
[2] = ITEM_AGC_MODE_M
;
1289 listid_to_enum
[3] = ITEM_AGC_MAXDB_M
;
1290 listid_to_enum
[4] = ITEM_FILENAME_M
;
1292 listid_to_enum
[2] = ITEM_FILENAME_M
;
1294 gui_synclist_set_nb_items(&lists
, ITEM_COUNT_M
); /* mono */
1298 listid_to_enum
[0] = ITEM_VOLUME
;
1299 listid_to_enum
[1] = ITEM_GAIN
;
1300 listid_to_enum
[2] = ITEM_GAIN_L
;
1301 listid_to_enum
[3] = ITEM_GAIN_R
;
1303 listid_to_enum
[4] = ITEM_AGC_MODE
;
1304 listid_to_enum
[5] = ITEM_AGC_MAXDB
;
1305 listid_to_enum
[6] = ITEM_FILENAME
;
1307 listid_to_enum
[4] = ITEM_FILENAME
;
1309 gui_synclist_set_nb_items(&lists
, ITEM_COUNT
); /* stereo */
1312 gui_synclist_draw(&lists
);
1313 } /* if(done < 0) */
1315 audio_stat
= audio_status();
1317 #if (CONFIG_LED == LED_REAL)
1320 * Flash the LED while waiting to record. Turn it on while
1323 if(audio_stat
& AUDIO_STATUS_RECORD
)
1325 if (audio_stat
& AUDIO_STATUS_PAUSE
)
1327 if (--led_countdown
<= 0)
1329 led_state
= !led_state
;
1336 /* trigger is on in status TRIG_READY (no check needed) */
1342 int trig_stat
= peak_meter_trigger_status();
1344 * other trigger stati than trig_off and trig_steady
1345 * already imply that we are recording.
1347 if (trig_stat
== TRIG_STEADY
)
1349 if (--led_countdown
<= 0)
1351 led_state
= !led_state
;
1358 /* trigger is on in status TRIG_READY (no check needed) */
1362 #endif /* CONFIG_LED */
1364 /* Wait for a button a while (HZ/10) drawing the peak meter */
1365 button
= peak_meter_draw_get_btn(CONTEXT_RECSCREEN
,
1367 screen_update
, vp_top
);
1368 if (last_audio_stat
!= audio_stat
)
1370 if (audio_stat
& AUDIO_STATUS_RECORD
)
1372 rec_status
|= RCSTAT_HAVE_RECORDED
;
1374 last_audio_stat
= audio_stat
;
1378 if (recording_start_automatic
)
1380 /* simulate a button press */
1381 button
= ACTION_REC_PAUSE
;
1382 recording_start_automatic
= false;
1385 /* let list handle the button */
1386 gui_synclist_do_button(&lists
, &button
, LIST_WRAP_UNLESS_HELD
);
1391 case ACTION_SETTINGS_INC
:
1392 case ACTION_SETTINGS_INCREPEAT
:
1393 switch (listid_to_enum
[gui_synclist_get_sel_pos(&lists
)])
1396 global_settings
.volume
++;
1401 if(global_settings
.rec_source
== AUDIO_SRC_MIC
)
1403 if(global_settings
.rec_mic_gain
<
1404 sound_max(SOUND_MIC_GAIN
))
1405 global_settings
.rec_mic_gain
++;
1410 if(global_settings
.rec_left_gain
<
1411 sound_max(SOUND_LEFT_GAIN
))
1412 global_settings
.rec_left_gain
++;
1413 if(global_settings
.rec_right_gain
<
1414 sound_max(SOUND_RIGHT_GAIN
))
1415 global_settings
.rec_right_gain
++;
1419 if(global_settings
.rec_left_gain
<
1420 sound_max(SOUND_LEFT_GAIN
))
1421 global_settings
.rec_left_gain
++;
1424 if(global_settings
.rec_right_gain
<
1425 sound_max(SOUND_RIGHT_GAIN
))
1426 global_settings
.rec_right_gain
++;
1430 agc_preset
= MIN(agc_preset
+ 1, AGC_MODE_SIZE
);
1431 agc_enable
= (agc_preset
!= 0);
1433 if (global_settings
.rec_source
== AUDIO_SRC_MIC
) {
1434 global_settings
.rec_agc_preset_mic
= agc_preset
;
1435 agc_maxgain
= global_settings
.rec_agc_maxgain_mic
;
1439 global_settings
.rec_agc_preset_line
= agc_preset
;
1440 agc_maxgain
= global_settings
.rec_agc_maxgain_line
;
1443 case ITEM_AGC_MAXDB
:
1445 if (global_settings
.rec_source
== AUDIO_SRC_MIC
)
1447 agc_maxgain
= MIN(agc_maxgain
+ 1,
1448 sound_max(SOUND_MIC_GAIN
));
1449 global_settings
.rec_agc_maxgain_mic
= agc_maxgain
;
1454 agc_maxgain
= MIN(agc_maxgain
+ 1,
1455 sound_max(SOUND_LEFT_GAIN
));
1456 global_settings
.rec_agc_maxgain_line
= agc_maxgain
;
1459 #endif /* HAVE_AGC */
1462 update_countdown
= 0; /* Update immediately */
1464 case ACTION_SETTINGS_DEC
:
1465 case ACTION_SETTINGS_DECREPEAT
:
1466 switch (listid_to_enum
[gui_synclist_get_sel_pos(&lists
)])
1469 global_settings
.volume
--;
1474 if(global_settings
.rec_source
== AUDIO_SRC_MIC
)
1476 if(global_settings
.rec_mic_gain
>
1477 sound_min(SOUND_MIC_GAIN
))
1478 global_settings
.rec_mic_gain
--;
1483 if(global_settings
.rec_left_gain
>
1484 sound_min(SOUND_LEFT_GAIN
))
1485 global_settings
.rec_left_gain
--;
1486 if(global_settings
.rec_right_gain
>
1487 sound_min(SOUND_RIGHT_GAIN
))
1488 global_settings
.rec_right_gain
--;
1492 if(global_settings
.rec_left_gain
>
1493 sound_min(SOUND_LEFT_GAIN
))
1494 global_settings
.rec_left_gain
--;
1497 if(global_settings
.rec_right_gain
>
1498 sound_min(SOUND_RIGHT_GAIN
))
1499 global_settings
.rec_right_gain
--;
1503 agc_preset
= MAX(agc_preset
- 1, 0);
1504 agc_enable
= (agc_preset
!= 0);
1506 if (global_settings
.rec_source
== AUDIO_SRC_MIC
) {
1507 global_settings
.rec_agc_preset_mic
= agc_preset
;
1508 agc_maxgain
= global_settings
.rec_agc_maxgain_mic
;
1512 global_settings
.rec_agc_preset_line
= agc_preset
;
1513 agc_maxgain
= global_settings
.rec_agc_maxgain_line
;
1516 case ITEM_AGC_MAXDB
:
1518 if (global_settings
.rec_source
== AUDIO_SRC_MIC
)
1520 agc_maxgain
= MAX(agc_maxgain
- 1,
1521 sound_min(SOUND_MIC_GAIN
));
1522 global_settings
.rec_agc_maxgain_mic
= agc_maxgain
;
1526 agc_maxgain
= MAX(agc_maxgain
- 1,
1527 sound_min(SOUND_LEFT_GAIN
));
1528 global_settings
.rec_agc_maxgain_line
= agc_maxgain
;
1531 #endif /* HAVE_AGC */
1534 update_countdown
= 0; /* Update immediately */
1536 case ACTION_STD_CANCEL
:
1537 /* turn off the trigger */
1538 peak_meter_trigger(false);
1539 peak_meter_set_trigger_listener(NULL
);
1541 if(audio_stat
& AUDIO_STATUS_RECORD
)
1543 rec_command(RECORDING_CMD_STOP
);
1547 #if CONFIG_CODEC != SWCODEC
1548 peak_meter_playback(true);
1549 peak_meter_enabled
= false;
1553 update_countdown
= 0; /* Update immediately */
1555 #ifdef HAVE_REMOTE_LCD
1556 case ACTION_REC_LCD
:
1557 /* this feature exists for some h1x0/h3x0 targets that suffer
1558 from noise caused by remote LCD updates
1559 NOTE 1: this will leave the list on the remote
1560 NOTE 2: to be replaced by a global LCD_off() routine */
1561 if(remote_display_on
)
1563 /* switch to single screen, leave message on remote */
1565 screens
[1].clear_viewport();
1566 screens
[1].puts(0, 0, str(LANG_REMOTE_LCD_OFF
));
1567 screens
[1].puts(0, 1, str(LANG_REMOTE_LCD_ON
));
1568 screens
[1].update_viewport();
1572 /* remote switched on again */
1574 screen_update
= NB_SCREENS
;
1576 remote_display_on
= !remote_display_on
; /* toggle */
1577 update_countdown
= 0; /* Update immediately */
1580 case ACTION_REC_PAUSE
:
1581 case ACTION_REC_NEWFILE
:
1582 /* Only act if the mpeg is stopped */
1583 if(!(audio_stat
& AUDIO_STATUS_RECORD
))
1585 /* is this manual or triggered recording? */
1586 if ((global_settings
.rec_trigger_mode
== TRIG_MODE_OFF
) ||
1587 (peak_meter_trigger_status() != TRIG_OFF
))
1589 /* manual recording */
1590 rec_status
|= RCSTAT_HAVE_RECORDED
;
1591 rec_command(RECORDING_CMD_START
);
1593 if (global_settings
.talk_menu
)
1595 /* no voice possible here, but a beep */
1596 audio_beep(HZ
/2); /* longer beep on start */
1599 /* this is triggered recording */
1602 /* we don't start recording now, but enable the
1603 trigger and let the callback function
1604 trigger_listener control when the recording starts */
1605 peak_meter_trigger(true);
1606 peak_meter_set_trigger_listener(&trigger_listener
);
1611 /*if new file button pressed, start new file */
1612 if (button
== ACTION_REC_NEWFILE
)
1614 rec_command(RECORDING_CMD_START_NEWFILE
);
1618 /* if pause button pressed, pause or resume */
1620 if(audio_stat
& AUDIO_STATUS_PAUSE
)
1622 rec_command(RECORDING_CMD_RESUME
);
1623 if (global_settings
.talk_menu
)
1625 /* no voice possible here, but a beep */
1626 audio_beep(HZ
/4); /* short beep on resume */
1631 rec_command(RECORDING_CMD_PAUSE
);
1635 update_countdown
= 0; /* Update immediately */
1637 case ACTION_STD_MENU
:
1638 #if CONFIG_CODEC == SWCODEC
1639 if(!(audio_stat
& AUDIO_STATUS_RECORD
))
1641 if(audio_stat
!= AUDIO_STATUS_RECORD
)
1644 #if (CONFIG_LED == LED_REAL)
1645 /* led is restored at begin of loop / end of function */
1648 if (recording_menu(no_source
))
1651 rec_status
|= RCSTAT_BEEN_IN_USB_MODE
;
1652 #ifdef HAVE_FMRADIO_REC
1653 radio_status
= FMRADIO_OFF
;
1659 /* the init is now done at the beginning of the loop */
1664 #if CONFIG_KEYPAD == RECORDER_PAD
1666 if(audio_stat
!= AUDIO_STATUS_RECORD
)
1668 #if (CONFIG_LED == LED_REAL)
1669 /* led is restored at begin of loop / end of function */
1672 if (f2_rec_screen())
1674 rec_status
|= RCSTAT_HAVE_RECORDED
;
1678 update_countdown
= 0; /* Update immediately */
1683 if(audio_stat
& AUDIO_STATUS_RECORD
)
1685 rec_command(RECORDING_CMD_START_NEWFILE
);
1690 #if (CONFIG_LED == LED_REAL)
1691 /* led is restored at begin of loop / end of function */
1694 if (f3_rec_screen())
1696 rec_status
|= RCSTAT_HAVE_RECORDED
;
1700 update_countdown
= 0; /* Update immediately */
1703 #endif /* CONFIG_KEYPAD == RECORDER_PAD */
1705 case SYS_USB_CONNECTED
:
1706 /* Only accept USB connection when not recording */
1707 if(!(audio_stat
& AUDIO_STATUS_RECORD
))
1710 screens
[i
].set_viewport(NULL
);
1711 default_event_handler(SYS_USB_CONNECTED
);
1713 rec_status
|= RCSTAT_BEEN_IN_USB_MODE
;
1714 #ifdef HAVE_FMRADIO_REC
1715 radio_status
= FMRADIO_OFF
;
1719 } /*switch(button)*/
1722 peak_read
= !peak_read
;
1723 if (peak_read
) { /* every 2nd run of loop */
1725 peak_valid
= read_peak_levels(&peak_l
, &peak_r
, &balance
);
1728 /* Handle AGC every 200ms when enabled and peak data is valid */
1729 if (peak_read
&& agc_enable
&& peak_valid
)
1730 auto_gain_control(&peak_l
, &peak_r
, &balance
);
1733 seconds
= audio_recorded_time() / HZ
;
1735 /* start of vp_top drawing */
1736 if(update_countdown
-- == 0 || seconds
> last_seconds
)
1738 unsigned int dseconds
, dhours
, dminutes
;
1739 unsigned long num_recorded_bytes
, dsize
, dmb
;
1743 screens
[i
].set_viewport(&vp_top
[i
]);
1744 screens
[i
].clear_viewport();
1746 update_countdown
= 5;
1747 last_seconds
= seconds
;
1749 dseconds
= rec_timesplit_seconds();
1750 dsize
= rec_sizesplit_bytes();
1751 num_recorded_bytes
= audio_num_recorded_bytes();
1753 #if CONFIG_CODEC == SWCODEC
1754 if ((audio_stat
& AUDIO_STATUS_WARNING
)
1755 && (warning_counter
++ % WARNING_PERIOD
) < WARNING_PERIOD
/2)
1757 /* Switch back and forth displaying warning on first available
1758 line to ensure visibility - the motion should also help
1760 /* Don't use language string unless agreed upon to make this
1761 method permanent - could do something in the statusbar */
1762 snprintf(buf
, sizeof(buf
), "Warning: %08X",
1763 pcm_rec_get_warnings());
1766 #endif /* CONFIG_CODEC == SWCODEC */
1767 if ((global_settings
.rec_sizesplit
) &&
1768 (global_settings
.rec_split_method
))
1770 dmb
= dsize
/1024/1024;
1771 snprintf(buf
, sizeof(buf
), "%s %dMB",
1772 str(LANG_SPLIT_SIZE
), dmb
);
1776 hours
= seconds
/ 3600;
1777 minutes
= (seconds
- (hours
* 3600)) / 60;
1778 snprintf(buf
, sizeof(buf
), "%s %02d:%02d:%02d",
1779 str(LANG_RECORDING_TIME
),
1780 hours
, minutes
, seconds
%60);
1783 FOR_NB_ACTIVE_SCREENS(i
)
1784 screens
[i
].puts(0, 0, buf
);
1786 if(audio_stat
& AUDIO_STATUS_PRERECORD
)
1788 snprintf(buf
, sizeof(buf
), "%s...",
1789 str(LANG_RECORD_PRERECORD
));
1793 /* Display the split interval if the record timesplit
1795 if ((global_settings
.rec_timesplit
) &&
1796 !(global_settings
.rec_split_method
))
1798 /* Display the record timesplit interval rather
1799 than the file size if the record timer is active */
1800 dhours
= dseconds
/ 3600;
1801 dminutes
= (dseconds
- (dhours
* 3600)) / 60;
1802 snprintf(buf
, sizeof(buf
), "%s %02d:%02d",
1803 str(LANG_RECORDING_TIMESPLIT_REC
),
1808 output_dyn_value(buf2
, sizeof buf2
,
1811 snprintf(buf
, sizeof(buf
), "%s %s",
1812 str(LANG_RECORDING_SIZE
), buf2
);
1816 FOR_NB_ACTIVE_SCREENS(i
)
1817 screens
[i
].puts(0, 1, buf
);
1819 /* We will do file splitting regardless, either at the end of
1820 a split interval, or when the filesize approaches the 2GB
1821 FAT file size (compatibility) limit. */
1822 if ((audio_stat
&& !(global_settings
.rec_split_method
)
1823 && global_settings
.rec_timesplit
&& (seconds
>= dseconds
))
1824 || (audio_stat
&& global_settings
.rec_split_method
1825 && global_settings
.rec_sizesplit
1826 && (num_recorded_bytes
>= dsize
))
1827 || (num_recorded_bytes
>= MAX_FILE_SIZE
))
1829 if (!(global_settings
.rec_split_type
)
1830 || (num_recorded_bytes
>= MAX_FILE_SIZE
))
1832 rec_command(RECORDING_CMD_START_NEWFILE
);
1837 peak_meter_trigger(false);
1838 peak_meter_set_trigger_listener(NULL
);
1839 if( global_settings
.rec_split_type
== 1)
1840 rec_command(RECORDING_CMD_STOP
);
1842 rec_command(RECORDING_CMD_STOP_SHUTDOWN
);
1844 update_countdown
= 0;
1847 /* draw the clipcounter just in front of the peakmeter */
1848 if(global_settings
.peak_meter_clipcounter
)
1850 int clipcount
= pm_get_clipcount();
1851 FOR_NB_ACTIVE_SCREENS(i
)
1853 if(!compact_view
[i
])
1855 screens
[i
].puts(0, 2, str(LANG_PM_CLIPCOUNT
));
1856 screens
[i
].putsf(0, 3, "%4d", clipcount
);
1859 screens
[i
].putsf(0, 2, "%4d", clipcount
);
1863 #ifdef HAVE_RECORDING_HISTOGRAM
1864 if(global_settings
.rec_histogram_interval
)
1866 if (peak_valid
&& !(hist_time
% hist_time_interval
) && hist_l
)
1868 history_l
[history_pos
] = hist_l
* hist_size_h
/ 32767;
1869 history_r
[history_pos
] = hist_r
* hist_size_h
/ 32767;
1870 history_pos
= (history_pos
+ 1) % HIST_W
;
1871 history_l
[history_pos
] = history_r
[history_pos
] = 0;
1872 history_l
[(history_pos
+ 1) % HIST_W
] = 0;
1873 history_r
[(history_pos
+ 1) % HIST_W
] = 0;
1877 lcd_set_drawmode(DRMODE_SOLID
);
1878 lcd_drawrect(0, hist_pos_y
- 1,
1879 HIST_W
+ 2, hist_size_h
+ 1);
1880 lcd_drawrect(HIST_W
+ 6, hist_pos_y
- 1,
1881 HIST_W
+ 2, hist_size_h
+ 1);
1882 lcd_set_drawmode(DRMODE_FG
);
1883 #ifdef HAVE_LCD_COLOR
1884 for (i
= 0; i
< HIST_W
; i
++)
1888 if (history_l
[i
] == hist_size_h
)
1889 lcd_set_foreground(LCD_HIST_OVER
);
1890 else if (history_l
[i
] > hist_level_marks
[1])
1891 lcd_set_foreground(LCD_HIST_HI
);
1893 lcd_set_foreground(LCD_HIST_OK
);
1894 lcd_vline(1 + i
, HIST_Y
-1, HIST_Y
- history_l
[i
]);
1898 if (history_r
[i
] == hist_size_h
)
1899 lcd_set_foreground(LCD_HIST_OVER
);
1900 else if (history_r
[i
] > hist_level_marks
[1])
1901 lcd_set_foreground(LCD_HIST_HI
);
1903 lcd_set_foreground(LCD_HIST_OK
);
1904 lcd_vline(HIST_W
+7 + i
, HIST_Y
-1, HIST_Y
- history_r
[i
]);
1908 for (i
= 0; i
< HIST_W
; i
++)
1912 if (history_l
[i
] == hist_size_h
)
1913 lcd_set_foreground(LCD_HIST_OVER
);
1915 lcd_set_foreground(LCD_HIST_OK
);
1916 lcd_vline(1 + i
, HIST_Y
-1, HIST_Y
- history_l
[i
]);
1920 if (history_r
[i
] == hist_size_h
)
1921 lcd_set_foreground(LCD_HIST_OVER
);
1923 lcd_set_foreground(LCD_HIST_OK
);
1924 lcd_vline(HIST_W
+7 + i
, HIST_Y
-1, HIST_Y
- history_r
[i
]);
1927 #endif /* HAVE_LCD_COLOR */
1929 #ifdef HAVE_LCD_COLOR
1930 global_settings
.fg_color
);
1934 for (i
= 0; i
< 6; i
++)
1935 lcd_hline(HIST_W
+ 3, HIST_W
+ 4,
1936 HIST_Y
- hist_level_marks
[i
]);
1938 #endif /* HAVE_RECORDING_HISTOGRAM */
1944 /* draw the trigger status */
1945 if (peak_meter_trigger_status() != TRIG_OFF
)
1947 peak_meter_draw_trig(pm_x
, trig_ypos
, trig_width
,
1949 FOR_NB_ACTIVE_SCREENS(i
)
1950 screens
[i
].update_viewport_rect(pm_x
[i
], trig_ypos
[i
],
1951 trig_width
[i
] + 2, TRIG_HEIGHT
);
1956 if (global_settings
.rec_source
== AUDIO_SRC_MIC
)
1958 if(agc_maxgain
< (global_settings
.rec_mic_gain
))
1959 change_recording_gain(false, true, true);
1964 if(agc_maxgain
< (global_settings
.rec_left_gain
))
1965 change_recording_gain(false, true, false);
1966 if(agc_maxgain
< (global_settings
.rec_right_gain
))
1967 change_recording_gain(false, false, true);
1969 #endif /* HAVE_AGC */
1971 #if CONFIG_CODEC == SWCODEC
1972 #ifdef HAVE_SPDIF_REC
1973 if((global_settings
.rec_source
== AUDIO_SRC_SPDIF
) &&
1974 (prev_sample_rate
!= pcm_rec_sample_rate()))
1976 /* spdif samplerate changed */
1977 prev_sample_rate
= pcm_rec_sample_rate();
1985 /* update_list is set whenever content changes */
1986 update_list
= false;
1987 gui_synclist_draw(&lists
);
1990 /* draw peakmeter again (check if this can be removed) */
1991 FOR_NB_ACTIVE_SCREENS(i
)
1993 screens
[i
].set_viewport(&vp_top
[i
]);
1994 peak_meter_screen(&screens
[i
], pm_x
[i
], pm_y
[i
], pm_h
[i
]);
1995 screens
[i
].update();
1997 } /* display update every second */
1999 if(audio_stat
& AUDIO_STATUS_ERROR
)
2003 } /* end while(!done) */
2005 audio_stat
= audio_status();
2006 if (audio_stat
& AUDIO_STATUS_ERROR
)
2008 splash(0, str(LANG_DISK_FULL
));
2011 screens
[i
].update();
2013 #if CONFIG_CODEC == SWCODEC
2014 /* stop recording - some players like H10 freeze otherwise
2015 TO DO: find out why it freezes and fix properly */
2016 rec_command(RECORDING_CMD_STOP
);
2017 audio_close_recording();
2020 audio_error_clear();
2024 if (action_userabort(TIMEOUT_NOBLOCK
))
2031 #if CONFIG_CODEC == SWCODEC
2032 rec_command(RECORDING_CMD_STOP
);
2033 audio_close_recording();
2035 #ifdef HAVE_FMRADIO_REC
2036 if (radio_status
!= FMRADIO_OFF
)
2037 /* Restore radio playback - radio_status should be unchanged if started
2038 through fm radio screen (barring usb connect) */
2039 rec_set_source(AUDIO_SRC_FMRADIO
, (radio_status
& FMRADIO_PAUSED
) ?
2040 SRCF_FMRADIO_PAUSED
: SRCF_FMRADIO_PLAYING
);
2043 /* Go back to playback mode */
2044 rec_set_source(AUDIO_SRC_PLAYBACK
, SRCF_PLAYBACK
);
2046 /* restore talking */
2047 talk_disable(false);
2048 #else /* !SWCODEC */
2049 audio_init_playback();
2050 #endif /* CONFIG_CODEC == SWCODEC */
2053 /* Re-enable speaker */
2054 audiohw_enable_speaker(global_settings
.speaker_enabled
);
2057 /* make sure the trigger is really turned off */
2058 peak_meter_trigger(false);
2059 peak_meter_set_trigger_listener(NULL
);
2061 rec_status
&= ~RCSTAT_IN_RECSCREEN
;
2062 sound_settings_apply();
2065 screens
[i
].setfont(FONT_UI
);
2067 /* if the directory was created or recording happened, make sure the
2068 browser is updated */
2069 if (rec_status
& (RCSTAT_CREATED_DIRECTORY
| RCSTAT_HAVE_RECORDED
))
2072 #if (CONFIG_STORAGE & STORAGE_ATA) && (CONFIG_LED == LED_REAL) \
2073 && !defined(SIMULATOR)
2074 ata_set_led_enabled(true);
2079 return (rec_status
& RCSTAT_BEEN_IN_USB_MODE
) != 0;
2080 } /* recording_screen */
2082 #if CONFIG_KEYPAD == RECORDER_PAD
2083 static bool f2_rec_screen(void)
2085 static const char* const freq_str
[6] =
2100 struct audio_recording_options rec_options
;
2104 screens
[i
].set_viewport(NULL
);
2105 screens
[i
].setfont(FONT_SYSFIXED
);
2106 screens
[i
].getstringsize("A",&w
,&h
);
2114 screens
[i
].clear_display();
2116 /* Recording quality */
2117 screens
[i
].putsxy(0, LCD_HEIGHT
/2 - h
*2,
2118 str(LANG_SYSFONT_RECORDING_QUALITY
));
2121 snprintf(buf
, sizeof(buf
), "%d", global_settings
.rec_quality
);
2124 screens
[i
].putsxy(0, LCD_HEIGHT
/2-h
, buf
);
2125 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_FastBackward
],
2126 LCD_WIDTH
/2 - 16, LCD_HEIGHT
/2 - 4, 7, 8);
2130 snprintf(buf
, sizeof buf
, "%s:", str(LANG_SYSFONT_RECORDING_FREQUENCY
));
2131 ptr
= freq_str
[global_settings
.rec_frequency
];
2134 screens
[i
].getstringsize(buf
,&w
,&h
);
2135 screens
[i
].putsxy((LCD_WIDTH
-w
)/2, LCD_HEIGHT
- h
*2, buf
);
2136 screens
[i
].getstringsize(ptr
, &w
, &h
);
2137 screens
[i
].putsxy((LCD_WIDTH
-w
)/2, LCD_HEIGHT
- h
, ptr
);
2138 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_DownArrow
],
2139 LCD_WIDTH
/2 - 3, LCD_HEIGHT
- h
*3, 7, 8);
2143 switch ( global_settings
.rec_channels
) {
2145 ptr
= str(LANG_SYSFONT_CHANNEL_STEREO
);
2149 ptr
= str(LANG_SYSFONT_CHANNEL_MONO
);
2155 screens
[i
].getstringsize(str(LANG_SYSFONT_CHANNELS
), &w
, &h
);
2156 screens
[i
].putsxy(LCD_WIDTH
- w
, LCD_HEIGHT
/2 - h
*2,
2157 str(LANG_SYSFONT_CHANNELS
));
2158 screens
[i
].getstringsize(str(LANG_SYSFONT_MODE
), &w
, &h
);
2159 screens
[i
].putsxy(LCD_WIDTH
- w
, LCD_HEIGHT
/2 - h
,
2160 str(LANG_SYSFONT_MODE
));
2161 screens
[i
].getstringsize(ptr
, &w
, &h
);
2162 screens
[i
].putsxy(LCD_WIDTH
- w
, LCD_HEIGHT
/2, ptr
);
2163 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_FastForward
],
2164 LCD_WIDTH
/2 + 8, LCD_HEIGHT
/2 - 4, 7, 8);
2166 screens
[i
].update();
2169 button
= button_get(true);
2172 case BUTTON_F2
| BUTTON_LEFT
:
2173 global_settings
.rec_quality
++;
2174 if(global_settings
.rec_quality
> 7)
2175 global_settings
.rec_quality
= 0;
2180 case BUTTON_F2
| BUTTON_DOWN
:
2181 global_settings
.rec_frequency
++;
2182 if(global_settings
.rec_frequency
> 5)
2183 global_settings
.rec_frequency
= 0;
2188 case BUTTON_F2
| BUTTON_RIGHT
:
2189 global_settings
.rec_channels
++;
2190 if(global_settings
.rec_channels
> 1)
2191 global_settings
.rec_channels
= 0;
2195 case BUTTON_F2
| BUTTON_REL
:
2201 case BUTTON_F2
| BUTTON_REPEAT
:
2206 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
2212 rec_init_recording_options(&rec_options
);
2213 rec_set_recording_options(&rec_options
);
2219 screens
[i
].setfont(FONT_UI
);
2224 static bool f3_rec_screen(void)
2230 const char *src_str
[] =
2232 str(LANG_SYSFONT_RECORDING_SRC_MIC
),
2233 str(LANG_SYSFONT_LINE_IN
),
2234 str(LANG_SYSFONT_RECORDING_SRC_DIGITAL
)
2236 struct audio_recording_options rec_options
;
2240 screens
[i
].set_viewport(NULL
);
2241 screens
[i
].setfont(FONT_SYSFIXED
);
2242 screens
[i
].getstringsize("A",&w
,&h
);
2246 const char* ptr
= src_str
[global_settings
.rec_source
];
2249 screens
[i
].clear_display();
2251 /* Recording source */
2252 screens
[i
].putsxy(0, LCD_HEIGHT
/2 - h
*2,
2253 str(LANG_SYSFONT_RECORDING_SOURCE
));
2255 screens
[i
].getstringsize(ptr
, &w
, &h
);
2256 screens
[i
].putsxy(0, LCD_HEIGHT
/2-h
, ptr
);
2257 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_FastBackward
],
2258 LCD_WIDTH
/2 - 16, LCD_HEIGHT
/2 - 4, 7, 8);
2262 ptr
= str(LANG_SYSFONT_RECORD_TRIGGER
);
2265 screens
[i
].getstringsize(ptr
,&w
,&h
);
2266 screens
[i
].putsxy((LCD_WIDTH
-w
)/2, LCD_HEIGHT
- h
*2, ptr
);
2267 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_DownArrow
],
2268 LCD_WIDTH
/2 - 3, LCD_HEIGHT
- h
*3, 7, 8);
2270 screens
[i
].update();
2273 button
= button_get(true);
2276 case BUTTON_F3
| BUTTON_DOWN
:
2279 settings_apply_trigger();
2285 case BUTTON_F3
| BUTTON_LEFT
:
2286 global_settings
.rec_source
++;
2287 if(global_settings
.rec_source
> AUDIO_SRC_MAX
)
2288 global_settings
.rec_source
= 0;
2292 case BUTTON_F3
| BUTTON_REL
:
2298 case BUTTON_F3
| BUTTON_REPEAT
:
2303 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
2309 rec_init_recording_options(&rec_options
);
2310 rec_set_recording_options(&rec_options
);
2316 screens
[i
].setfont(FONT_UI
);
2320 #endif /* CONFIG_KEYPAD == RECORDER_PAD */
2322 #if CONFIG_CODEC == SWCODEC
2323 void audio_beep(int duration
)
2330 /* stubs for recording sim */
2331 void audio_init_recording(unsigned int buffer_offset
)
2333 buffer_offset
= buffer_offset
;
2336 void audio_close_recording(void)
2340 unsigned long pcm_rec_get_warnings(void)
2345 unsigned long pcm_rec_sample_rate(void)
2350 unsigned long audio_recorded_time(void)
2355 unsigned long audio_num_recorded_bytes(void)
2357 return 5 * 1024 * 1024;
2360 void rec_set_source(int source
, unsigned flags
)
2366 void audio_set_recording_options(struct audio_recording_options
*options
)
2371 void audio_set_recording_gain(int left
, int right
, int type
)
2378 void audio_record(const char *filename
)
2380 filename
= filename
;
2383 void audio_new_file(const char *filename
)
2385 filename
= filename
;
2388 void audio_stop_recording(void)
2392 void audio_pause_recording(void)
2396 void audio_resume_recording(void)
2400 #endif /* #ifdef SIMULATOR */
2401 #endif /* #ifdef CONFIG_CODEC == SWCODEC */
2403 #endif /* HAVE_RECORDING */