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"
38 #if defined(HAVE_SPDIF_IN) || defined(HAVE_SPDIF_OUT)
41 #endif /* CONFIG_CODEC == SWCODEC */
42 #include "pcm_record.h"
43 #include "recording.h"
44 #include "mp3_playback.h"
54 #include "peakmeter.h"
56 #include "sound_menu.h"
57 #include "timefuncs.h"
67 #if (CONFIG_STORAGE & STORAGE_ATA) && (CONFIG_LED == LED_REAL) \
68 && !defined(SIMULATOR)
72 #include "screen_access.h"
78 #include "appevents.h"
81 /* This array holds the record timer interval lengths, in seconds */
82 static const unsigned long rec_timer_seconds
[] =
96 10L*60*60, /* 10:00 */
97 12L*60*60, /* 12:00 */
98 18L*60*60, /* 18:00 */
102 static unsigned int rec_timesplit_seconds(void)
104 return rec_timer_seconds
[global_settings
.rec_timesplit
];
107 /* This array holds the record size interval lengths, in bytes */
108 static const unsigned long rec_size_bytes
[] =
111 5*1024*1024, /* 5MB */
112 10*1024*1024, /* 10MB */
113 15*1024*1024, /* 15MB */
114 32*1024*1024, /* 32MB */
115 64*1024*1024, /* 64MB */
116 75*1024*1024, /* 75MB */
117 100*1024*1024, /* 100MB */
118 128*1024*1024, /* 128MB */
119 256*1024*1024, /* 256MB */
120 512*1024*1024, /* 512MB */
121 650*1024*1024, /* 650MB */
122 700*1024*1024, /* 700MB */
123 1024*1024*1024, /* 1GB */
124 1536*1024*1024, /* 1.5GB */
125 1792*1024*1024, /* 1.75GB */
128 static unsigned long rec_sizesplit_bytes(void)
130 return rec_size_bytes
[global_settings
.rec_sizesplit
];
133 void settings_apply_trigger(void)
135 int start_thres
, stop_thres
;
136 if (global_settings
.peak_meter_dbfs
)
138 start_thres
= global_settings
.rec_start_thres_db
- 1;
139 stop_thres
= global_settings
.rec_stop_thres_db
- 1;
143 start_thres
= global_settings
.rec_start_thres_linear
;
144 stop_thres
= global_settings
.rec_stop_thres_linear
;
147 peak_meter_define_trigger(
149 global_settings
.rec_start_duration
*HZ
,
150 MIN(global_settings
.rec_start_duration
*HZ
/ 2, 2*HZ
),
152 global_settings
.rec_stop_postrec
*HZ
,
153 global_settings
.rec_stop_gap
*HZ
156 /* recording screen status flags */
157 enum rec_status_flags
159 RCSTAT_IN_RECSCREEN
= 0x00000001,
160 RCSTAT_BEEN_IN_USB_MODE
= 0x00000002,
161 RCSTAT_CREATED_DIRECTORY
= 0x00000004,
162 RCSTAT_HAVE_RECORDED
= 0x00000008,
165 static int rec_status
= 0;
167 bool in_recording_screen(void)
169 return (rec_status
& RCSTAT_IN_RECSCREEN
) != 0;
172 #if CONFIG_KEYPAD == RECORDER_PAD
173 static bool f2_rec_screen(void);
174 static bool f3_rec_screen(void);
177 #define MAX_FILE_SIZE 0x7F800000 /* 2 GB - 4 MB */
179 #ifndef HAVE_REMOTE_LCD
180 static const int screen_update
= NB_SCREENS
;
182 static int screen_update
= NB_SCREENS
;
183 static bool remote_display_on
= true;
186 /* as we have the ability to disable the remote, we need an alternative loop */
187 #define FOR_NB_ACTIVE_SCREENS(i) for(i = 0; i < screen_update; i++)
189 static bool update_list
= false; /* (GIU) list needs updating */
191 /** File name creation **/
193 /* current file number to assist in creating unique numbered filenames
194 without actually having to create the file on disk */
195 static int file_number
= -1;
196 #endif /* CONFIG_RTC */
198 #if CONFIG_CODEC == SWCODEC
200 #define REC_FILE_ENDING(rec_format) \
201 (audio_formats[rec_format_afmt[rec_format]].ext_list)
203 #else /* CONFIG_CODEC != SWCODEC */
205 /* default record file extension for HWCODEC */
206 #define REC_FILE_ENDING(rec_format) \
207 (audio_formats[AFMT_MPA_L3].ext_list)
209 #endif /* CONFIG_CODEC == SWCODEC */
211 /* path for current file */
212 static char path_buffer
[MAX_PATH
];
214 /** Automatic Gain Control (AGC) **/
217 * peak_time is incremented every 0.2s, every 2nd run of record screen loop.
218 * hist_time is incremented every 0.5s, display update.
219 * peak_time is the counter of the peak hold read and agc process,
220 * overflow every 13 years 8-)
222 static long peak_time
= 0;
224 static short peak_valid_mem
[4];
225 #define BAL_MEM_SIZE 24
226 static short balance_mem
[BAL_MEM_SIZE
];
228 /* Automatic Gain Control */
229 #define AGC_MODE_SIZE 5
230 #define AGC_SAFETY_MODE 0
232 static const char* agc_preset_str
[] =
233 { "Off", "S", "L", "D", "M", "V" };
240 #define AGC_CLIP 32766
241 #define AGC_PEAK 29883 /* fast gain reduction threshold -0.8dB */
242 #define AGC_HIGH 27254 /* accelerated gain reduction threshold -1.6dB */
243 #define AGC_IMG 823 /* threshold for balance control -32dB */
244 /* autogain high level thresholds (-3dB, -7dB, -4dB, -5dB, -5dB) */
245 static const short agc_th_hi
[AGC_MODE_SIZE
] =
246 { 23197, 14637, 21156, 18428, 18426 };
247 /* autogain low level thresholds (-14dB, -11dB, -6dB, -7dB, -8dB) */
248 static const short agc_th_lo
[AGC_MODE_SIZE
] =
249 { 6538, 9235, 16422, 14636, 13045 };
250 /* autogain threshold times [1/5s] or [200ms] */
251 static const short agc_tdrop
[AGC_MODE_SIZE
] =
252 { 900, 225, 150, 60, 8 };
253 static const short agc_trise
[AGC_MODE_SIZE
] =
254 { 9000, 750, 400, 150, 20 };
255 static const short agc_tbal
[AGC_MODE_SIZE
] =
256 { 4500, 500, 300, 100, 15 };
258 static bool agc_enable
= true;
259 static short agc_preset
;
261 static int agc_left
= 0;
262 static int agc_right
= 0;
263 /* AGC time since high target volume was exceeded */
264 static short agc_droptime
= 0;
265 /* AGC time since volume fallen below low target */
266 static short agc_risetime
= 0;
267 /* AGC balance time exceeding +/- 0.7dB */
268 static short agc_baltime
= 0;
269 /* AGC maximum gain */
270 static short agc_maxgain
;
271 #endif /* HAVE_AGC */
272 #if defined(HAVE_AGC) || defined(HAVE_RECORDING_HISTOGRAM)
273 static long hist_time
= 0;
274 #endif /* HAVE_AGC or HAVE_RECORDING_HISTOGRAM */
276 /* TO DO: move some of this stuff inside the recording function? */
277 #ifdef HAVE_RECORDING_HISTOGRAM
278 static int hist_l
= 0;
279 static int hist_r
= 0;
280 #define HIST_BUF_SIZE (LCD_WIDTH)
281 #define HIST_Y (hist_pos_y+hist_size_h-1)
282 #define HIST_W (LCD_WIDTH / 2 - 4)
284 #ifdef HAVE_LCD_COLOR
285 #define LCD_BAL_L LCD_RGBPACK(0, 0, 255)
286 #define LCD_BAL_R LCD_RGBPACK(204, 0, 0)
287 #define LCD_HIST_OVER LCD_RGBPACK(204, 0, 0)
288 #define LCD_HIST_HI LCD_RGBPACK(255, 204, 0)
289 #define LCD_HIST_OK LCD_RGBPACK(51, 153, 0)
290 #else /* HAVE_LCD_COLOR */
291 #define LCD_BATT_OK LCD_BLACK
292 #define LCD_BATT_LO LCD_DARKGRAY
293 #define LCD_DISK_OK LCD_BLACK
294 #define LCD_DISK_LO LCD_DARKGRAY
295 #define LCD_HIST_OVER LCD_BLACK
296 #define LCD_HIST_OK LCD_DARKGRAY
297 #define LCD_BAL LCD_DARKGRAY
298 #endif /* HAVE_LCD_COLOR */
299 #else /* LCD_DEPTH > 1 */
300 #define LCD_HIST_OVER LCD_DEFAULT_FG
301 #define LCD_HIST_OK LCD_DEFAULT_FG
302 #define LCD_BAL LCD_DEFAULT_FG
303 #endif /* LCD_DEPTH > 1 */
304 #endif /* HAVE_RECORDING_HISTOGRAM */
306 static void set_gain(void)
309 if(global_settings
.rec_source
== AUDIO_SRC_MIC
)
311 audio_set_recording_gain(global_settings
.rec_mic_gain
,
317 /* AUDIO_SRC_LINEIN, AUDIO_SRC_FMRADIO, AUDIO_SRC_SPDIF */
318 audio_set_recording_gain(global_settings
.rec_left_gain
,
319 global_settings
.rec_right_gain
,
322 /* reset the clipping indicators */
323 peak_meter_set_clip_hold(global_settings
.peak_meter_clip_hold
);
328 /* Read peak meter values & calculate balance.
329 * Returns validity of peak values.
330 * Used for automatic gain control and history diagram.
332 static bool read_peak_levels(int *peak_l
, int *peak_r
, int *balance
)
334 peak_meter_get_peakhold(peak_l
, peak_r
);
335 peak_valid_mem
[peak_time
% 3] = *peak_l
;
336 if (((peak_valid_mem
[0] == peak_valid_mem
[1]) &&
337 (peak_valid_mem
[1] == peak_valid_mem
[2])) &&
338 ((*peak_l
< 32767) || storage_disk_is_active()))
341 if (*peak_r
> *peak_l
)
342 balance_mem
[peak_time
% BAL_MEM_SIZE
] = (*peak_l
?
343 MIN((10000 * *peak_r
) / *peak_l
- 10000, 15118) : 15118);
345 balance_mem
[peak_time
% BAL_MEM_SIZE
] = (*peak_r
?
346 MAX(10000 - (10000 * *peak_l
) / *peak_r
, -15118) : -15118);
349 for (i
= 0; i
< BAL_MEM_SIZE
; i
++)
350 *balance
+= balance_mem
[i
];
351 *balance
= *balance
/ BAL_MEM_SIZE
;
353 #ifdef HAVE_RECORDING_HISTOGRAM
354 if (*peak_l
> hist_l
)
356 if (*peak_r
> hist_r
)
363 /* AGC helper function to check if maximum gain is reached */
364 static bool agc_gain_is_max(bool left
, bool right
)
366 /* range -128...+108 [0.5dB] */
367 short gain_current_l
;
368 short gain_current_r
;
373 switch (global_settings
.rec_source
)
375 #if defined(HAVE_LINE_REC) || defined(HAVE_FMRADIO_REC)
376 HAVE_LINE_REC_(case AUDIO_SRC_LINEIN
:)
377 HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO
:)
378 gain_current_l
= global_settings
.rec_left_gain
;
379 gain_current_r
= global_settings
.rec_right_gain
;
381 #endif /* LINE, FMRADIO */
382 #if defined(HAVE_MIC_REC)
385 gain_current_l
= global_settings
.rec_mic_gain
;
386 gain_current_r
= global_settings
.rec_mic_gain
;
390 return ((left
&& (gain_current_l
>= agc_maxgain
)) ||
391 (right
&& (gain_current_r
>= agc_maxgain
)));
394 static void change_recording_gain(bool increment
, bool left
, bool right
)
396 int factor
= (increment
? 1 : -1);
398 switch (global_settings
.rec_source
)
400 #if defined(HAVE_LINE_REC) || defined(HAVE_FMRADIO_REC)
401 HAVE_LINE_REC_(case AUDIO_SRC_LINEIN
:)
402 HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO
:)
403 if (left
) global_settings
.rec_left_gain
+= factor
;
404 if (right
) global_settings
.rec_right_gain
+= factor
;
406 #endif /* LINE, FMRADIO */
407 #if defined(HAVE_MIC_REC)
409 global_settings
.rec_mic_gain
+= factor
;
415 * Handle automatic gain control (AGC).
416 * Change recording gain if peak_x levels are above or below
417 * target volume for specified timeouts.
419 static void auto_gain_control(int *peak_l
, int *peak_r
, int *balance
)
425 if (*peak_l
> agc_left
)
428 agc_left
-= (agc_left
- *peak_l
+ 3) >> 2;
429 if (*peak_r
> agc_right
)
432 agc_right
-= (agc_right
- *peak_r
+ 3) >> 2;
433 agc_mono
= (agc_left
+ agc_right
) / 2;
435 agc_mode
= abs(agc_preset
) - 1;
441 if (agc_mode
!= AGC_SAFETY_MODE
) {
442 /* Automatic balance control - only if not in safety mode */
443 if ((agc_left
> AGC_IMG
) && (agc_right
> AGC_IMG
))
448 agc_baltime
-= !(peak_time
% 4); /* 0.47 - 0.75dB */
449 else if (*balance
> -4125)
450 agc_baltime
--; /* 0.75 - 3.00dB */
451 else if (*balance
> -7579)
452 agc_baltime
-= 2; /* 3.00 - 4.90dB */
454 agc_baltime
-= !(peak_time
% 8); /* 4.90 - inf dB */
456 agc_baltime
-= (peak_time
% 2);
458 else if (*balance
> 556)
461 agc_baltime
+= !(peak_time
% 4);
462 else if (*balance
< 4125)
464 else if (*balance
< 7579)
467 agc_baltime
+= !(peak_time
% 8);
469 agc_baltime
+= (peak_time
% 2);
472 if ((*balance
* agc_baltime
) < 0)
475 agc_baltime
-= peak_time
% 2;
477 agc_baltime
+= peak_time
% 2;
480 increment
= ((agc_risetime
/ 2) > agc_droptime
);
482 if (agc_baltime
< -agc_tbal
[agc_mode
])
484 if (!increment
|| !agc_gain_is_max(!increment
, increment
)) {
485 change_recording_gain(increment
, !increment
, increment
);
490 else if (agc_baltime
> +agc_tbal
[agc_mode
])
492 if (!increment
|| !agc_gain_is_max(increment
, !increment
)) {
493 change_recording_gain(increment
, increment
, !increment
);
499 else if (!(hist_time
% 4))
508 /* Automatic gain control */
509 if ((agc_left
> agc_th_hi
[agc_mode
]) || (agc_right
> agc_th_hi
[agc_mode
]))
511 if ((agc_left
> AGC_CLIP
) || (agc_right
> AGC_CLIP
))
512 agc_droptime
+= agc_tdrop
[agc_mode
] /
513 (global_settings
.rec_agc_cliptime
+ 1);
514 if (agc_left
> AGC_HIGH
) {
517 if (agc_left
> AGC_PEAK
)
520 if (agc_right
> AGC_HIGH
) {
523 if (agc_right
> AGC_PEAK
)
526 if (agc_mono
> agc_th_hi
[agc_mode
])
529 agc_droptime
+= !(peak_time
% 2);
531 if (agc_droptime
>= agc_tdrop
[agc_mode
])
533 change_recording_gain(false, true, true);
538 agc_risetime
= MAX(agc_risetime
- 1, 0);
540 else if (agc_mono
< agc_th_lo
[agc_mode
])
542 if (agc_mono
< (agc_th_lo
[agc_mode
] / 8))
543 agc_risetime
+= !(peak_time
% 5);
544 else if (agc_mono
< (agc_th_lo
[agc_mode
] / 2))
549 if (agc_risetime
>= agc_trise
[agc_mode
]) {
550 if ((agc_mode
!= AGC_SAFETY_MODE
) &&
551 (!agc_gain_is_max(true, true))) {
552 change_recording_gain(true, true, true);
558 agc_droptime
= MAX(agc_droptime
- 1, 0);
560 else if (!(peak_time
% 6)) /* on target level every 1.2 sec */
562 agc_risetime
= MAX(agc_risetime
- 1, 0);
563 agc_droptime
= MAX(agc_droptime
- 1, 0);
566 #endif /* HAVE_AGC */
568 static const char* const fmtstr
[] =
570 "%c%d %s", /* no decimals */
571 "%c%d.%d %s ", /* 1 decimal */
572 "%c%d.%02d %s " /* 2 decimals */
575 static char *fmt_gain(int snd
, int val
, char *str
, int len
)
581 val
= sound_val2phys(snd
, val
);
587 numdec
= sound_numdecimals(snd
);
588 unit
= sound_unit(snd
);
592 i
= val
/ (10*numdec
);
593 d
= val
% (10*numdec
);
594 snprintf(str
, len
, fmtstr
[numdec
], sign
, i
, d
, unit
);
597 snprintf(str
, len
, fmtstr
[numdec
], sign
, val
, unit
);
602 /* the list below must match enum audio_sources in audio.h */
603 static const char* const prestr
[] =
605 HAVE_MIC_IN_([AUDIO_SRC_MIC
] = "R_MIC_",)
606 HAVE_LINE_REC_([AUDIO_SRC_LINEIN
] = "R_LINE_",)
607 HAVE_SPDIF_IN_([AUDIO_SRC_SPDIF
] = "R_SPDIF_",)
608 HAVE_FMRADIO_REC_([AUDIO_SRC_FMRADIO
] = "R_FM_",)
611 char *rec_create_filename(char *buffer
)
614 const char *pref
= "R_";
616 /* Directory existence and writeablility should have already been
617 * verified - do not pass NULL pointers to pcmrec */
619 if((unsigned)global_settings
.rec_source
< AUDIO_NUM_SOURCES
)
621 pref
= prestr
[global_settings
.rec_source
];
624 strcpy(buffer
, global_settings
.rec_directory
);
626 snprintf(ext
, sizeof(ext
), ".%s",
627 REC_FILE_ENDING(global_settings
.rec_format
));
630 return create_numbered_filename(buffer
, buffer
, pref
, ext
, 4,
633 /* We'll wait at least up to the start of the next second so no duplicate
635 return create_datetime_filename(buffer
, buffer
, pref
, ext
, true);
640 /* Hit disk to get a starting filename for the type */
641 static void rec_init_filename(void)
644 rec_create_filename(path_buffer
);
649 int rec_create_directory(void)
652 const char * const folder
= global_settings
.rec_directory
;
654 if (strcmp(folder
, "/") && !dir_exists(folder
))
660 while (action_userabort(HZ
) == false)
663 str(LANG_REC_DIR_NOT_WRITABLE
),
664 str(LANG_OFF_ABORT
));
669 rec_status
|= RCSTAT_CREATED_DIRECTORY
;
677 void rec_init_recording_options(struct audio_recording_options
*options
)
679 options
->rec_source
= global_settings
.rec_source
;
680 options
->rec_frequency
= global_settings
.rec_frequency
;
681 options
->rec_channels
= global_settings
.rec_channels
;
682 options
->rec_prerecord_time
= global_settings
.rec_prerecord_time
;
683 #if CONFIG_CODEC == SWCODEC
684 options
->rec_mono_mode
= global_settings
.rec_mono_mode
;
685 options
->rec_source_flags
= 0;
686 options
->enc_config
.rec_format
= global_settings
.rec_format
;
687 global_to_encoder_config(&options
->enc_config
);
689 options
->rec_quality
= global_settings
.rec_quality
;
690 options
->rec_editable
= global_settings
.rec_editable
;
694 #if CONFIG_CODEC == SWCODEC && !defined (SIMULATOR)
695 void rec_set_source(int source
, unsigned flags
)
697 /* Set audio input source, power up/down devices */
698 audio_set_input_source(source
, flags
);
700 /* Set peakmeters for recording or reset to playback */
701 peak_meter_playback((flags
& SRCF_RECORDING
) == 0);
702 peak_meter_enable(true);
704 #endif /* CONFIG_CODEC == SWCODEC && !defined (SIMULATOR) */
706 void rec_set_recording_options(struct audio_recording_options
*options
)
708 #if CONFIG_CODEC != SWCODEC
709 if (global_settings
.rec_prerecord_time
)
711 talk_buffer_steal(); /* will use the mp3 buffer */
713 #else /* == SWCODEC */
714 rec_set_source(options
->rec_source
,
715 options
->rec_source_flags
| SRCF_RECORDING
);
716 #endif /* CONFIG_CODEC != SWCODEC */
718 audio_set_recording_options(options
);
721 void rec_command(enum recording_command cmd
)
725 case RECORDING_CMD_STOP_SHUTDOWN
:
726 pm_activate_clipcount(false);
727 audio_stop_recording();
728 #if CONFIG_CODEC == SWCODEC
729 audio_close_recording();
733 case RECORDING_CMD_STOP
:
734 pm_activate_clipcount(false);
735 audio_stop_recording();
737 case RECORDING_CMD_START
:
738 /* steal mp3 buffer, create unique filename and start recording */
739 pm_reset_clipcount();
740 pm_activate_clipcount(true);
741 #if CONFIG_CODEC != SWCODEC
742 talk_buffer_steal(); /* we use the mp3 buffer */
744 audio_record(rec_create_filename(path_buffer
));
746 case RECORDING_CMD_START_NEWFILE
:
747 /* create unique filename and start recording*/
748 pm_reset_clipcount();
749 pm_activate_clipcount(true); /* just to be sure */
750 audio_new_file(rec_create_filename(path_buffer
));
752 case RECORDING_CMD_PAUSE
:
753 pm_activate_clipcount(false);
754 audio_pause_recording();
756 case RECORDING_CMD_RESUME
:
757 pm_activate_clipcount(true);
758 audio_resume_recording();
764 /* used in trigger_listerner and recording_screen */
765 static unsigned int last_seconds
= 0;
768 * Callback function so that the peak meter code can send an event
769 * to this application. This function can be passed to
770 * peak_meter_set_trigger_listener in order to activate the trigger.
772 static void trigger_listener(int trigger_status
)
774 switch (trigger_status
)
777 if(!(audio_status() & AUDIO_STATUS_RECORD
))
779 rec_status
|= RCSTAT_HAVE_RECORDED
;
780 rec_command(RECORDING_CMD_START
);
781 #if CONFIG_CODEC != SWCODEC
782 /* give control to mpeg thread so that it can start
784 yield(); yield(); yield();
788 /* if we're already recording this is a retrigger */
791 if((audio_status() & AUDIO_STATUS_PAUSE
) &&
792 (global_settings
.rec_trigger_type
== TRIG_TYPE_PAUSE
))
794 rec_command(RECORDING_CMD_RESUME
);
796 /* New file on trig start*/
797 else if (global_settings
.rec_trigger_type
!= TRIG_TYPE_NEW_FILE
)
799 rec_command(RECORDING_CMD_START_NEWFILE
);
800 /* tell recording_screen to reset the time */
806 /* A _change_ to TRIG_READY means the current recording has stopped */
808 if(audio_status() & AUDIO_STATUS_RECORD
)
810 switch(global_settings
.rec_trigger_type
)
812 case TRIG_TYPE_STOP
: /* Stop */
813 rec_command(RECORDING_CMD_STOP
);
816 case TRIG_TYPE_PAUSE
: /* Pause */
817 rec_command(RECORDING_CMD_PAUSE
);
820 case TRIG_TYPE_NEW_FILE
: /* New file on trig stop*/
821 rec_command(RECORDING_CMD_START_NEWFILE
);
822 /* tell recording_screen to reset the time */
826 case 3: /* Stop and shutdown */
827 rec_command(RECORDING_CMD_STOP_SHUTDOWN
);
831 if (global_settings
.rec_trigger_mode
!= TRIG_MODE_REARM
)
833 peak_meter_set_trigger_listener(NULL
);
834 peak_meter_trigger(false);
841 /* Stuff for drawing the screen */
843 enum rec_list_items_stereo
{
859 enum rec_list_items_mono
{
864 ITEM_AGC_MAXDB_M
= 5,
873 #ifdef HAVE_SPDIF_REC
874 enum rec_list_items_spdif
{
876 #if CONFIG_CODEC == SWCODEC
877 ITEM_SAMPLERATE_D
= 6,
887 static int listid_to_enum
[ITEM_COUNT
];
889 static const char* reclist_get_name(int selected_item
, void * data
,
890 char * buffer
, size_t buffer_len
)
896 data
= data
; /* not used */
897 if(selected_item
>= ITEM_COUNT
)
900 switch (listid_to_enum
[selected_item
])
903 snprintf(buffer
, buffer_len
, "%s: %s", str(LANG_VOLUME
),
904 fmt_gain(SOUND_VOLUME
,
905 global_settings
.volume
,
906 buf2
, sizeof(buf2
)));
910 if(global_settings
.rec_source
== AUDIO_SRC_MIC
)
912 /* Draw MIC recording gain */
913 snprintf(buffer
, buffer_len
, "%s: %s", str(LANG_GAIN
),
914 fmt_gain(SOUND_MIC_GAIN
,
915 global_settings
.rec_mic_gain
,
916 buf2
, sizeof(buf2
)));
921 int avg_gain
= (global_settings
.rec_left_gain
+
922 global_settings
.rec_right_gain
) / 2;
923 snprintf(buffer
, buffer_len
, "%s: %s", str(LANG_GAIN
),
924 fmt_gain(SOUND_LEFT_GAIN
,
926 buf2
, sizeof(buf2
)));
930 snprintf(buffer
, buffer_len
, "%s: %s",
932 fmt_gain(SOUND_LEFT_GAIN
,
933 global_settings
.rec_left_gain
,
934 buf2
, sizeof(buf2
)));
937 snprintf(buffer
, buffer_len
, "%s: %s",
938 str(LANG_GAIN_RIGHT
),
939 fmt_gain(SOUND_RIGHT_GAIN
,
940 global_settings
.rec_right_gain
,
941 buf2
, sizeof(buf2
)));
945 snprintf(buffer
, buffer_len
, "%s: %s",
946 str(LANG_RECORDING_AGC_PRESET
),
947 agc_preset_str
[agc_preset
]);
951 snprintf(buffer
, buffer_len
, "%s: %s",
952 str(LANG_RECORDING_AGC_MAXGAIN
),
953 fmt_gain(SOUND_LEFT_GAIN
,
954 agc_maxgain
, buf2
, sizeof(buf2
)));
956 else if (global_settings
.rec_source
== AUDIO_SRC_MIC
)
957 snprintf(buffer
, buffer_len
, "%s: %s (%s)",
958 str(LANG_RECORDING_AGC_MAXGAIN
),
959 fmt_gain(SOUND_MIC_GAIN
,
960 agc_maxgain
, buf2
, sizeof(buf2
)),
961 fmt_gain(SOUND_MIC_GAIN
,
962 agc_maxgain
- global_settings
.rec_mic_gain
,
963 buf3
, sizeof(buf3
)));
966 snprintf(buffer
, buffer_len
, "%s: %s (%s)",
967 str(LANG_RECORDING_AGC_MAXGAIN
),
968 fmt_gain(SOUND_LEFT_GAIN
,
969 agc_maxgain
, buf2
, sizeof(buf2
)),
970 fmt_gain(SOUND_LEFT_GAIN
,
972 (global_settings
.rec_left_gain
+
973 global_settings
.rec_right_gain
)/2,
974 buf3
, sizeof(buf3
)));
977 #if CONFIG_CODEC == SWCODEC
978 #ifdef HAVE_SPDIF_REC
979 case ITEM_SAMPLERATE_D
:
980 snprintf(buffer
, buffer_len
, "%s: %lu",
981 str(LANG_RECORDING_FREQUENCY
),
982 pcm_rec_sample_rate());
988 if(audio_status() & AUDIO_STATUS_RECORD
)
990 size_t tot_len
= strlen(path_buffer
) +
991 strlen(str(LANG_RECORDING_FILENAME
)) + 1;
992 if(tot_len
> buffer_len
)
994 snprintf(buffer
, buffer_len
, "%s %s",
995 str(LANG_RECORDING_FILENAME
),
996 path_buffer
+ tot_len
- buffer_len
);
1000 snprintf(buffer
, buffer_len
, "%s %s",
1001 str(LANG_RECORDING_FILENAME
), path_buffer
);
1006 return str(LANG_RECORDING_FILENAME
);
1017 bool recording_start_automatic
= false;
1019 bool recording_screen(bool no_source
)
1022 int done
= -1; /* negative to re-init, positive to quit, zero to run */
1023 char buf
[32]; /* for preparing strings */
1024 char buf2
[32]; /* for preparing strings */
1025 int w
, h
; /* character width/height */
1026 int update_countdown
= 0; /* refresh counter */
1027 unsigned int seconds
;
1029 int audio_stat
= 0; /* status of the audio system */
1030 int last_audio_stat
= -1; /* previous status so we can act on changes */
1031 struct viewport vp_list
[NB_SCREENS
], vp_top
[NB_SCREENS
]; /* the viewports */
1033 #if CONFIG_CODEC == SWCODEC
1034 int warning_counter
= 0;
1035 #define WARNING_PERIOD 7
1038 #if CONFIG_CODEC == SWCODEC
1039 #ifdef HAVE_SPDIF_REC
1040 unsigned long prev_sample_rate
= 0;
1044 #ifdef HAVE_FMRADIO_REC
1045 /* Radio is left on if:
1046 * 1) Is was on at the start and the initial source is FM Radio
1047 * 2) 1) and the source was never changed to something else
1049 int radio_status
= (global_settings
.rec_source
!= AUDIO_SRC_FMRADIO
) ?
1050 FMRADIO_OFF
: get_radio_status();
1052 #if (CONFIG_LED == LED_REAL)
1053 bool led_state
= false;
1054 int led_countdown
= 2;
1057 bool peak_read
= false;
1062 int pm_x
[NB_SCREENS
]; /* peakmeter (and trigger bar) x pos */
1063 int pm_y
[NB_SCREENS
]; /* peakmeter y pos */
1064 int pm_h
[NB_SCREENS
]; /* peakmeter height */
1065 int trig_ypos
[NB_SCREENS
]; /* trigger bar y pos */
1066 int trig_width
[NB_SCREENS
]; /* trigger bar width */
1067 int top_height_req
[NB_SCREENS
]; /* required height for top half */
1068 /* tweak layout tiny screens / big fonts */
1069 bool compact_view
[NB_SCREENS
] = { false };
1070 struct gui_synclist lists
; /* the list in the bottom vp */
1071 #if defined(HAVE_AGC) || defined(HAVE_RECORDING_HISTOGRAM)
1072 bool peak_valid
= false;
1074 #if defined(HAVE_RECORDING_HISTOGRAM)
1076 unsigned short hist_pos_y
= 0;
1077 unsigned short hist_size_h
= 0;
1078 int history_pos
= 0;
1079 short hist_time_interval
= 1; /* 1, 2, 4, 8 */
1080 unsigned char history_l
[HIST_BUF_SIZE
];
1081 unsigned char history_r
[HIST_BUF_SIZE
];
1082 const char hist_level_marks
[6] = { 29, 26, 23, 17, 9, 2};
1084 #ifdef HAVE_FMRADIO_REC
1085 int prev_rec_source
= global_settings
.rec_source
; /* detect source change */
1088 struct audio_recording_options rec_options
;
1089 rec_status
= RCSTAT_IN_RECSCREEN
;
1091 #if (CONFIG_STORAGE & STORAGE_ATA) && (CONFIG_LED == LED_REAL) \
1092 && !defined(SIMULATOR)
1093 ata_set_led_enabled(false);
1096 #if CONFIG_CODEC == SWCODEC
1097 /* This should be done before touching audio settings */
1098 while (!audio_is_thread_ready())
1101 /* recording_menu gets messed up: so prevent manus talking */
1103 /* audio_init_recording stops anything playing when it takes the audio
1106 /* Yes, we use the D/A for monitoring */
1107 peak_meter_enable(true);
1108 peak_meter_playback(true);
1112 peak_meter_get_peakhold(&peak_l
, &peak_r
);
1115 pm_reset_clipcount();
1116 pm_activate_clipcount(false);
1117 settings_apply_trigger();
1120 agc_preset_str
[0] = str(LANG_OFF
);
1121 agc_preset_str
[1] = str(LANG_AGC_SAFETY
);
1122 agc_preset_str
[2] = str(LANG_AGC_LIVE
);
1123 agc_preset_str
[3] = str(LANG_AGC_DJSET
);
1124 agc_preset_str
[4] = str(LANG_AGC_MEDIUM
);
1125 agc_preset_str
[5] = str(LANG_AGC_VOICE
);
1126 #endif /* HAVE_AGC */
1129 /* Disable speaker to prevent feedback */
1130 audiohw_enable_speaker(false);
1133 #if CONFIG_CODEC == SWCODEC
1134 audio_close_recording();
1136 audio_init_recording(0);
1137 sound_set_volume(global_settings
.volume
);
1140 /* Create new filename for recording start */
1141 rec_init_filename();
1144 /* start of the loop: we stay in this loop until user quits recscreen */
1149 /* request to re-init stuff, done after settings screen */
1151 #ifdef HAVE_FMRADIO_REC
1152 /* If input changes away from FM Radio,
1153 radio will remain off when recording screen closes. */
1154 if (global_settings
.rec_source
!= prev_rec_source
1155 && prev_rec_source
== AUDIO_SRC_FMRADIO
)
1156 radio_status
= FMRADIO_OFF
;
1157 prev_rec_source
= global_settings
.rec_source
;
1160 /* viewport init and calculations that only needs to be done once */
1164 /* top vp, 4 lines, force sys font if total screen < 6 lines
1165 NOTE: one could limit the list to 1 line and get away with 5 lines */
1166 top_height_req
[i
] = 4;
1167 #if defined(HAVE_RECORDING_HISTOGRAM)
1168 if((global_settings
.rec_histogram_interval
) && (!i
))
1169 top_height_req
[i
] += 1; /* use one line for histogram */
1170 hist_time_interval
= 1 << global_settings
.rec_histogram_interval
;
1173 viewport_set_defaults(v
, i
);
1174 if (viewport_get_nb_lines(v
) < top_height_req
[i
])
1176 /* compact needs 4 lines total */
1177 v
->font
= FONT_SYSFIXED
;
1178 compact_view
[i
] = false;
1183 if (viewport_get_nb_lines(v
) < (top_height_req
[i
]+2))
1184 compact_view
[i
] = true;
1186 compact_view
[i
] = false;
1188 vp_list
[i
] = *v
; /* get a copy now so it can be sized more easily */
1189 v
->height
= (font_get(v
->font
)->height
)*(compact_view
[i
] ? 3 :
1192 /* list section, rest of the screen */
1193 vp_list
[i
].y
+= vp_top
[i
].height
;
1194 vp_list
[i
].height
-= vp_top
[i
].height
;
1195 screens
[i
].set_viewport(&vp_top
[i
]); /* req for next calls */
1197 screens
[i
].getstringsize("W", &w
, &h
);
1198 pm_y
[i
] = font_get(vp_top
[i
].font
)->height
* 2;
1199 trig_ypos
[i
] = font_get(vp_top
[i
].font
)->height
* 3;
1201 trig_ypos
[i
] -= (font_get(vp_top
[i
].font
)->height
)/2;
1204 /* init the bottom list */
1205 gui_synclist_init(&lists
, reclist_get_name
, NULL
, false, 1, vp_list
);
1206 gui_synclist_set_title(&lists
, NULL
, Icon_NOICON
);
1208 send_event(GUI_EVENT_ACTIONUPDATE
, (void*)1); /* force a redraw */
1210 #if defined(HAVE_RECORDING_HISTOGRAM)
1212 hist_pos_y
= (compact_view
[0] ? 3 : 4) * (font_get(vp_top
[0].font
)->height
)
1214 hist_size_h
= font_get(vp_top
[0].font
)->height
- 2;
1215 memset(history_l
, 0, sizeof(unsigned char)*HIST_BUF_SIZE
);
1216 memset(history_r
, 0, sizeof(unsigned char)*HIST_BUF_SIZE
);
1222 if(global_settings
.peak_meter_clipcounter
)
1225 screens
[i
].getstringsize(str(LANG_PM_CLIPCOUNT
),
1226 &clipwidth
, &h
); /* h is same */
1227 pm_x
[i
] = clipwidth
+1;
1229 if(global_settings
.rec_trigger_mode
== TRIG_MODE_OFF
)
1230 pm_h
[i
] = font_get(vp_top
[i
].font
)->height
* 2;
1232 pm_h
[i
] = font_get(vp_top
[i
].font
)->height
;
1235 trig_width
[i
] = vp_top
[i
].width
- pm_x
[i
];
1238 #if CONFIG_CODEC == SWCODEC
1239 audio_close_recording();
1240 audio_init_recording(0);
1243 rec_init_recording_options(&rec_options
);
1244 rec_set_recording_options(&rec_options
);
1246 if(rec_create_directory() < 0)
1252 #if CONFIG_CODEC == SWCODEC && CONFIG_RTC == 0
1253 /* If format changed, a new number is required */
1254 rec_init_filename();
1259 if (global_settings
.rec_source
== AUDIO_SRC_MIC
) {
1260 agc_preset
= global_settings
.rec_agc_preset_mic
;
1261 agc_maxgain
= global_settings
.rec_agc_maxgain_mic
;
1266 agc_preset
= global_settings
.rec_agc_preset_line
;
1267 agc_maxgain
= global_settings
.rec_agc_maxgain_line
;
1269 #endif /* HAVE_AGC */
1272 update_countdown
= 0; /* Update immediately */
1274 /* populate translation table for list id -> enum */
1275 #ifdef HAVE_SPDIF_REC
1276 if(global_settings
.rec_source
== AUDIO_SRC_SPDIF
)
1278 listid_to_enum
[0] = ITEM_VOLUME_D
;
1279 #if CONFIG_CODEC == SWCODEC
1280 listid_to_enum
[1] = ITEM_SAMPLERATE_D
;
1281 listid_to_enum
[2] = ITEM_FILENAME_D
;
1283 listid_to_enum
[1] = ITEM_FILENAME_D
;
1286 gui_synclist_set_nb_items(&lists
, ITEM_COUNT_D
); /* spdif */
1290 if(HAVE_MIC_REC_((global_settings
.rec_source
== AUDIO_SRC_MIC
) || )
1291 (global_settings
.rec_channels
== 1))
1293 listid_to_enum
[0] = ITEM_VOLUME_M
;
1294 listid_to_enum
[1] = ITEM_GAIN_M
;
1296 listid_to_enum
[2] = ITEM_AGC_MODE_M
;
1297 listid_to_enum
[3] = ITEM_AGC_MAXDB_M
;
1298 listid_to_enum
[4] = ITEM_FILENAME_M
;
1300 listid_to_enum
[2] = ITEM_FILENAME_M
;
1302 gui_synclist_set_nb_items(&lists
, ITEM_COUNT_M
); /* mono */
1306 listid_to_enum
[0] = ITEM_VOLUME
;
1307 listid_to_enum
[1] = ITEM_GAIN
;
1308 listid_to_enum
[2] = ITEM_GAIN_L
;
1309 listid_to_enum
[3] = ITEM_GAIN_R
;
1311 listid_to_enum
[4] = ITEM_AGC_MODE
;
1312 listid_to_enum
[5] = ITEM_AGC_MAXDB
;
1313 listid_to_enum
[6] = ITEM_FILENAME
;
1315 listid_to_enum
[4] = ITEM_FILENAME
;
1317 gui_synclist_set_nb_items(&lists
, ITEM_COUNT
); /* stereo */
1320 gui_synclist_draw(&lists
);
1321 } /* if(done < 0) */
1323 audio_stat
= audio_status();
1325 #if (CONFIG_LED == LED_REAL)
1328 * Flash the LED while waiting to record. Turn it on while
1331 if(audio_stat
& AUDIO_STATUS_RECORD
)
1333 if (audio_stat
& AUDIO_STATUS_PAUSE
)
1335 if (--led_countdown
<= 0)
1337 led_state
= !led_state
;
1344 /* trigger is on in status TRIG_READY (no check needed) */
1350 int trig_stat
= peak_meter_trigger_status();
1352 * other trigger stati than trig_off and trig_steady
1353 * already imply that we are recording.
1355 if (trig_stat
== TRIG_STEADY
)
1357 if (--led_countdown
<= 0)
1359 led_state
= !led_state
;
1366 /* trigger is on in status TRIG_READY (no check needed) */
1370 #endif /* CONFIG_LED */
1372 /* Wait for a button a while (HZ/10) drawing the peak meter */
1373 button
= peak_meter_draw_get_btn(CONTEXT_RECSCREEN
,
1375 screen_update
, vp_top
);
1376 if (last_audio_stat
!= audio_stat
)
1378 if (audio_stat
& AUDIO_STATUS_RECORD
)
1380 rec_status
|= RCSTAT_HAVE_RECORDED
;
1382 last_audio_stat
= audio_stat
;
1386 if (recording_start_automatic
)
1388 /* simulate a button press */
1389 button
= ACTION_REC_PAUSE
;
1390 recording_start_automatic
= false;
1393 /* let list handle the button */
1394 gui_synclist_do_button(&lists
, &button
, LIST_WRAP_UNLESS_HELD
);
1399 case ACTION_SETTINGS_INC
:
1400 case ACTION_SETTINGS_INCREPEAT
:
1401 switch (listid_to_enum
[gui_synclist_get_sel_pos(&lists
)])
1404 global_settings
.volume
++;
1409 if(global_settings
.rec_source
== AUDIO_SRC_MIC
)
1411 if(global_settings
.rec_mic_gain
<
1412 sound_max(SOUND_MIC_GAIN
))
1413 global_settings
.rec_mic_gain
++;
1418 if(global_settings
.rec_left_gain
<
1419 sound_max(SOUND_LEFT_GAIN
))
1420 global_settings
.rec_left_gain
++;
1421 if(global_settings
.rec_right_gain
<
1422 sound_max(SOUND_RIGHT_GAIN
))
1423 global_settings
.rec_right_gain
++;
1427 if(global_settings
.rec_left_gain
<
1428 sound_max(SOUND_LEFT_GAIN
))
1429 global_settings
.rec_left_gain
++;
1432 if(global_settings
.rec_right_gain
<
1433 sound_max(SOUND_RIGHT_GAIN
))
1434 global_settings
.rec_right_gain
++;
1438 agc_preset
= MIN(agc_preset
+ 1, AGC_MODE_SIZE
);
1439 agc_enable
= (agc_preset
!= 0);
1441 if (global_settings
.rec_source
== AUDIO_SRC_MIC
) {
1442 global_settings
.rec_agc_preset_mic
= agc_preset
;
1443 agc_maxgain
= global_settings
.rec_agc_maxgain_mic
;
1447 global_settings
.rec_agc_preset_line
= agc_preset
;
1448 agc_maxgain
= global_settings
.rec_agc_maxgain_line
;
1451 case ITEM_AGC_MAXDB
:
1453 if (global_settings
.rec_source
== AUDIO_SRC_MIC
)
1455 agc_maxgain
= MIN(agc_maxgain
+ 1,
1456 sound_max(SOUND_MIC_GAIN
));
1457 global_settings
.rec_agc_maxgain_mic
= agc_maxgain
;
1462 agc_maxgain
= MIN(agc_maxgain
+ 1,
1463 sound_max(SOUND_LEFT_GAIN
));
1464 global_settings
.rec_agc_maxgain_line
= agc_maxgain
;
1467 #endif /* HAVE_AGC */
1470 update_countdown
= 0; /* Update immediately */
1472 case ACTION_SETTINGS_DEC
:
1473 case ACTION_SETTINGS_DECREPEAT
:
1474 switch (listid_to_enum
[gui_synclist_get_sel_pos(&lists
)])
1477 global_settings
.volume
--;
1482 if(global_settings
.rec_source
== AUDIO_SRC_MIC
)
1484 if(global_settings
.rec_mic_gain
>
1485 sound_min(SOUND_MIC_GAIN
))
1486 global_settings
.rec_mic_gain
--;
1491 if(global_settings
.rec_left_gain
>
1492 sound_min(SOUND_LEFT_GAIN
))
1493 global_settings
.rec_left_gain
--;
1494 if(global_settings
.rec_right_gain
>
1495 sound_min(SOUND_RIGHT_GAIN
))
1496 global_settings
.rec_right_gain
--;
1500 if(global_settings
.rec_left_gain
>
1501 sound_min(SOUND_LEFT_GAIN
))
1502 global_settings
.rec_left_gain
--;
1505 if(global_settings
.rec_right_gain
>
1506 sound_min(SOUND_RIGHT_GAIN
))
1507 global_settings
.rec_right_gain
--;
1511 agc_preset
= MAX(agc_preset
- 1, 0);
1512 agc_enable
= (agc_preset
!= 0);
1514 if (global_settings
.rec_source
== AUDIO_SRC_MIC
) {
1515 global_settings
.rec_agc_preset_mic
= agc_preset
;
1516 agc_maxgain
= global_settings
.rec_agc_maxgain_mic
;
1520 global_settings
.rec_agc_preset_line
= agc_preset
;
1521 agc_maxgain
= global_settings
.rec_agc_maxgain_line
;
1524 case ITEM_AGC_MAXDB
:
1526 if (global_settings
.rec_source
== AUDIO_SRC_MIC
)
1528 agc_maxgain
= MAX(agc_maxgain
- 1,
1529 sound_min(SOUND_MIC_GAIN
));
1530 global_settings
.rec_agc_maxgain_mic
= agc_maxgain
;
1534 agc_maxgain
= MAX(agc_maxgain
- 1,
1535 sound_min(SOUND_LEFT_GAIN
));
1536 global_settings
.rec_agc_maxgain_line
= agc_maxgain
;
1539 #endif /* HAVE_AGC */
1542 update_countdown
= 0; /* Update immediately */
1544 case ACTION_STD_CANCEL
:
1545 /* turn off the trigger */
1546 peak_meter_trigger(false);
1547 peak_meter_set_trigger_listener(NULL
);
1549 if(audio_stat
& AUDIO_STATUS_RECORD
)
1551 rec_command(RECORDING_CMD_STOP
);
1555 #if CONFIG_CODEC != SWCODEC
1556 peak_meter_playback(true);
1557 peak_meter_enable(false);
1561 update_countdown
= 0; /* Update immediately */
1563 #ifdef HAVE_REMOTE_LCD
1564 case ACTION_REC_LCD
:
1565 /* this feature exists for some h1x0/h3x0 targets that suffer
1566 from noise caused by remote LCD updates
1567 NOTE 1: this will leave the list on the remote
1568 NOTE 2: to be replaced by a global LCD_off() routine */
1569 if(remote_display_on
)
1571 /* switch to single screen, leave message on remote */
1573 screens
[1].clear_viewport();
1574 screens
[1].puts(0, 0, str(LANG_REMOTE_LCD_OFF
));
1575 screens
[1].puts(0, 1, str(LANG_REMOTE_LCD_ON
));
1576 screens
[1].update_viewport();
1580 /* remote switched on again */
1582 screen_update
= NB_SCREENS
;
1584 remote_display_on
= !remote_display_on
; /* toggle */
1585 update_countdown
= 0; /* Update immediately */
1588 case ACTION_REC_PAUSE
:
1589 case ACTION_REC_NEWFILE
:
1590 /* Only act if the mpeg is stopped */
1591 if(!(audio_stat
& AUDIO_STATUS_RECORD
))
1593 /* is this manual or triggered recording? */
1594 if ((global_settings
.rec_trigger_mode
== TRIG_MODE_OFF
) ||
1595 (peak_meter_trigger_status() != TRIG_OFF
))
1597 /* manual recording */
1598 rec_status
|= RCSTAT_HAVE_RECORDED
;
1599 rec_command(RECORDING_CMD_START
);
1601 if (global_settings
.talk_menu
)
1603 /* no voice possible here, but a beep */
1604 audio_beep(HZ
/2); /* longer beep on start */
1607 /* this is triggered recording */
1610 /* we don't start recording now, but enable the
1611 trigger and let the callback function
1612 trigger_listener control when the recording starts */
1613 peak_meter_trigger(true);
1614 peak_meter_set_trigger_listener(&trigger_listener
);
1619 /*if new file button pressed, start new file */
1620 if (button
== ACTION_REC_NEWFILE
)
1622 rec_command(RECORDING_CMD_START_NEWFILE
);
1626 /* if pause button pressed, pause or resume */
1628 if(audio_stat
& AUDIO_STATUS_PAUSE
)
1630 rec_command(RECORDING_CMD_RESUME
);
1631 if (global_settings
.talk_menu
)
1633 /* no voice possible here, but a beep */
1634 audio_beep(HZ
/4); /* short beep on resume */
1639 rec_command(RECORDING_CMD_PAUSE
);
1643 update_countdown
= 0; /* Update immediately */
1645 case ACTION_STD_MENU
:
1646 #if CONFIG_CODEC == SWCODEC
1647 if(!(audio_stat
& AUDIO_STATUS_RECORD
))
1649 if(audio_stat
!= AUDIO_STATUS_RECORD
)
1652 #if (CONFIG_LED == LED_REAL)
1653 /* led is restored at begin of loop / end of function */
1656 if (recording_menu(no_source
))
1659 rec_status
|= RCSTAT_BEEN_IN_USB_MODE
;
1660 #ifdef HAVE_FMRADIO_REC
1661 radio_status
= FMRADIO_OFF
;
1667 /* the init is now done at the beginning of the loop */
1672 #if CONFIG_KEYPAD == RECORDER_PAD
1674 if(audio_stat
!= AUDIO_STATUS_RECORD
)
1676 #if (CONFIG_LED == LED_REAL)
1677 /* led is restored at begin of loop / end of function */
1680 if (f2_rec_screen())
1682 rec_status
|= RCSTAT_HAVE_RECORDED
;
1686 update_countdown
= 0; /* Update immediately */
1691 if(audio_stat
& AUDIO_STATUS_RECORD
)
1693 rec_command(RECORDING_CMD_START_NEWFILE
);
1698 #if (CONFIG_LED == LED_REAL)
1699 /* led is restored at begin of loop / end of function */
1702 if (f3_rec_screen())
1704 rec_status
|= RCSTAT_HAVE_RECORDED
;
1708 update_countdown
= 0; /* Update immediately */
1711 #endif /* CONFIG_KEYPAD == RECORDER_PAD */
1713 case SYS_USB_CONNECTED
:
1714 /* Only accept USB connection when not recording */
1715 if(!(audio_stat
& AUDIO_STATUS_RECORD
))
1718 screens
[i
].set_viewport(NULL
);
1719 default_event_handler(SYS_USB_CONNECTED
);
1721 rec_status
|= RCSTAT_BEEN_IN_USB_MODE
;
1722 #ifdef HAVE_FMRADIO_REC
1723 radio_status
= FMRADIO_OFF
;
1727 } /*switch(button)*/
1730 peak_read
= !peak_read
;
1731 if (peak_read
) { /* every 2nd run of loop */
1733 peak_valid
= read_peak_levels(&peak_l
, &peak_r
, &balance
);
1736 /* Handle AGC every 200ms when enabled and peak data is valid */
1737 if (peak_read
&& agc_enable
&& peak_valid
)
1738 auto_gain_control(&peak_l
, &peak_r
, &balance
);
1741 seconds
= audio_recorded_time() / HZ
;
1743 /* start of vp_top drawing */
1744 if(update_countdown
-- == 0 || seconds
> last_seconds
)
1746 unsigned int dseconds
, dhours
, dminutes
;
1747 unsigned long num_recorded_bytes
, dsize
, dmb
;
1751 screens
[i
].set_viewport(&vp_top
[i
]);
1752 screens
[i
].clear_viewport();
1754 update_countdown
= 5;
1755 last_seconds
= seconds
;
1757 dseconds
= rec_timesplit_seconds();
1758 dsize
= rec_sizesplit_bytes();
1759 num_recorded_bytes
= audio_num_recorded_bytes();
1761 #if CONFIG_CODEC == SWCODEC
1762 if ((audio_stat
& AUDIO_STATUS_WARNING
)
1763 && (warning_counter
++ % WARNING_PERIOD
) < WARNING_PERIOD
/2)
1765 /* Switch back and forth displaying warning on first available
1766 line to ensure visibility - the motion should also help
1768 /* Don't use language string unless agreed upon to make this
1769 method permanent - could do something in the statusbar */
1770 snprintf(buf
, sizeof(buf
), "Warning: %08lX",
1771 pcm_rec_get_warnings());
1774 #endif /* CONFIG_CODEC == SWCODEC */
1775 if ((global_settings
.rec_sizesplit
) &&
1776 (global_settings
.rec_split_method
))
1778 dmb
= dsize
/1024/1024;
1779 snprintf(buf
, sizeof(buf
), "%s %luMB",
1780 str(LANG_SPLIT_SIZE
), dmb
);
1784 hours
= seconds
/ 3600;
1785 minutes
= (seconds
- (hours
* 3600)) / 60;
1786 snprintf(buf
, sizeof(buf
), "%s %02d:%02d:%02d",
1787 str(LANG_RECORDING_TIME
),
1788 hours
, minutes
, seconds
%60);
1791 FOR_NB_ACTIVE_SCREENS(i
)
1792 screens
[i
].puts(0, 0, buf
);
1794 if(audio_stat
& AUDIO_STATUS_PRERECORD
)
1796 snprintf(buf
, sizeof(buf
), "%s...",
1797 str(LANG_RECORD_PRERECORD
));
1801 /* Display the split interval if the record timesplit
1803 if ((global_settings
.rec_timesplit
) &&
1804 !(global_settings
.rec_split_method
))
1806 /* Display the record timesplit interval rather
1807 than the file size if the record timer is active */
1808 dhours
= dseconds
/ 3600;
1809 dminutes
= (dseconds
- (dhours
* 3600)) / 60;
1810 snprintf(buf
, sizeof(buf
), "%s %02d:%02d",
1811 str(LANG_RECORDING_TIMESPLIT_REC
),
1816 output_dyn_value(buf2
, sizeof buf2
,
1819 snprintf(buf
, sizeof(buf
), "%s %s",
1820 str(LANG_RECORDING_SIZE
), buf2
);
1824 FOR_NB_ACTIVE_SCREENS(i
)
1825 screens
[i
].puts(0, 1, buf
);
1827 /* We will do file splitting regardless, either at the end of
1828 a split interval, or when the filesize approaches the 2GB
1829 FAT file size (compatibility) limit. */
1830 if ((audio_stat
&& !(global_settings
.rec_split_method
)
1831 && global_settings
.rec_timesplit
&& (seconds
>= dseconds
))
1832 || (audio_stat
&& global_settings
.rec_split_method
1833 && global_settings
.rec_sizesplit
1834 && (num_recorded_bytes
>= dsize
))
1835 || (num_recorded_bytes
>= MAX_FILE_SIZE
))
1837 if (!(global_settings
.rec_split_type
)
1838 || (num_recorded_bytes
>= MAX_FILE_SIZE
))
1840 rec_command(RECORDING_CMD_START_NEWFILE
);
1845 peak_meter_trigger(false);
1846 peak_meter_set_trigger_listener(NULL
);
1847 if( global_settings
.rec_split_type
== 1)
1848 rec_command(RECORDING_CMD_STOP
);
1850 rec_command(RECORDING_CMD_STOP_SHUTDOWN
);
1852 update_countdown
= 0;
1855 /* draw the clipcounter just in front of the peakmeter */
1856 if(global_settings
.peak_meter_clipcounter
)
1858 int clipcount
= pm_get_clipcount();
1859 FOR_NB_ACTIVE_SCREENS(i
)
1861 if(!compact_view
[i
])
1863 screens
[i
].puts(0, 2, str(LANG_PM_CLIPCOUNT
));
1864 screens
[i
].putsf(0, 3, "%4d", clipcount
);
1867 screens
[i
].putsf(0, 2, "%4d", clipcount
);
1871 #ifdef HAVE_RECORDING_HISTOGRAM
1872 if(global_settings
.rec_histogram_interval
)
1874 if (peak_valid
&& !(hist_time
% hist_time_interval
) && hist_l
)
1876 /* fill history buffer */
1877 history_l
[history_pos
] = hist_l
* hist_size_h
/ 32767;
1878 history_r
[history_pos
] = hist_r
* hist_size_h
/ 32767;
1879 history_pos
= (history_pos
+ 1) % HIST_BUF_SIZE
;
1880 history_l
[history_pos
] = history_r
[history_pos
] = 0;
1881 history_l
[(history_pos
+ 1) % HIST_BUF_SIZE
] = 0;
1882 history_r
[(history_pos
+ 1) % HIST_BUF_SIZE
] = 0;
1886 lcd_set_drawmode(DRMODE_SOLID
);
1887 lcd_drawrect(0, hist_pos_y
- 1,
1888 HIST_W
+ 2, hist_size_h
+ 1);
1889 lcd_drawrect(HIST_W
+ 6, hist_pos_y
- 1,
1890 HIST_W
+ 2, hist_size_h
+ 1);
1891 lcd_set_drawmode(DRMODE_FG
);
1894 for (i
= HIST_W
-1; i
>= 0; i
--)
1898 j
= HIST_BUF_SIZE
-1;
1901 if (history_l
[j
] == hist_size_h
)
1902 lcd_set_foreground(LCD_HIST_OVER
);
1903 #ifdef HAVE_LCD_COLOR
1904 else if (history_l
[j
] > hist_level_marks
[1])
1905 lcd_set_foreground(LCD_HIST_HI
);
1908 lcd_set_foreground(LCD_HIST_OK
);
1909 lcd_vline(1 + i
, HIST_Y
-1, HIST_Y
- history_l
[j
]);
1913 if (history_r
[j
] == hist_size_h
)
1914 lcd_set_foreground(LCD_HIST_OVER
);
1915 #ifdef HAVE_LCD_COLOR
1916 else if (history_r
[j
] > hist_level_marks
[1])
1917 lcd_set_foreground(LCD_HIST_HI
);
1920 lcd_set_foreground(LCD_HIST_OK
);
1921 lcd_vline(HIST_W
+7 + i
, HIST_Y
-1, HIST_Y
- history_r
[j
]);
1925 #ifdef HAVE_LCD_COLOR
1926 global_settings
.fg_color
);
1930 for (i
= 0; i
< 6; i
++)
1931 lcd_hline(HIST_W
+ 3, HIST_W
+ 4,
1932 HIST_Y
- hist_level_marks
[i
]);
1934 #endif /* HAVE_RECORDING_HISTOGRAM */
1940 /* draw the trigger status */
1941 if (peak_meter_trigger_status() != TRIG_OFF
)
1943 peak_meter_draw_trig(pm_x
, trig_ypos
, trig_width
,
1945 FOR_NB_ACTIVE_SCREENS(i
)
1946 screens
[i
].update_viewport_rect(pm_x
[i
], trig_ypos
[i
],
1947 trig_width
[i
] + 2, TRIG_HEIGHT
);
1952 if (global_settings
.rec_source
== AUDIO_SRC_MIC
)
1954 if(agc_maxgain
< (global_settings
.rec_mic_gain
))
1955 change_recording_gain(false, true, true);
1960 if(agc_maxgain
< (global_settings
.rec_left_gain
))
1961 change_recording_gain(false, true, false);
1962 if(agc_maxgain
< (global_settings
.rec_right_gain
))
1963 change_recording_gain(false, false, true);
1965 #endif /* HAVE_AGC */
1967 #if CONFIG_CODEC == SWCODEC
1968 #ifdef HAVE_SPDIF_REC
1969 if((global_settings
.rec_source
== AUDIO_SRC_SPDIF
) &&
1970 (prev_sample_rate
!= pcm_rec_sample_rate()))
1972 /* spdif samplerate changed */
1973 prev_sample_rate
= pcm_rec_sample_rate();
1981 /* update_list is set whenever content changes */
1982 update_list
= false;
1983 gui_synclist_draw(&lists
);
1986 /* draw peakmeter again (check if this can be removed) */
1987 FOR_NB_ACTIVE_SCREENS(i
)
1989 screens
[i
].set_viewport(&vp_top
[i
]);
1990 peak_meter_screen(&screens
[i
], pm_x
[i
], pm_y
[i
], pm_h
[i
]);
1991 screens
[i
].update();
1993 } /* display update every second */
1995 if(audio_stat
& AUDIO_STATUS_ERROR
)
1999 } /* end while(!done) */
2001 audio_stat
= audio_status();
2002 if (audio_stat
& AUDIO_STATUS_ERROR
)
2004 splash(0, str(LANG_DISK_FULL
));
2007 screens
[i
].update();
2009 #if CONFIG_CODEC == SWCODEC
2010 /* stop recording - some players like H10 freeze otherwise
2011 TO DO: find out why it freezes and fix properly */
2012 rec_command(RECORDING_CMD_STOP
);
2013 audio_close_recording();
2016 audio_error_clear();
2020 if (action_userabort(TIMEOUT_NOBLOCK
))
2027 #if CONFIG_CODEC == SWCODEC
2028 rec_command(RECORDING_CMD_STOP
);
2029 audio_close_recording();
2031 #ifdef HAVE_FMRADIO_REC
2032 if (radio_status
!= FMRADIO_OFF
)
2033 /* Restore radio playback - radio_status should be unchanged if started
2034 through fm radio screen (barring usb connect) */
2035 rec_set_source(AUDIO_SRC_FMRADIO
, (radio_status
& FMRADIO_PAUSED
) ?
2036 SRCF_FMRADIO_PAUSED
: SRCF_FMRADIO_PLAYING
);
2039 /* Go back to playback mode */
2040 rec_set_source(AUDIO_SRC_PLAYBACK
, SRCF_PLAYBACK
);
2042 /* restore talking */
2043 talk_disable(false);
2044 #else /* !SWCODEC */
2045 audio_init_playback();
2046 #endif /* CONFIG_CODEC == SWCODEC */
2049 /* Re-enable speaker */
2050 audiohw_enable_speaker(global_settings
.speaker_enabled
);
2053 /* make sure the trigger is really turned off */
2054 peak_meter_trigger(false);
2055 peak_meter_set_trigger_listener(NULL
);
2057 rec_status
&= ~RCSTAT_IN_RECSCREEN
;
2058 sound_settings_apply();
2061 screens
[i
].setfont(FONT_UI
);
2063 /* if the directory was created or recording happened, make sure the
2064 browser is updated */
2065 if (rec_status
& (RCSTAT_CREATED_DIRECTORY
| RCSTAT_HAVE_RECORDED
))
2068 #if (CONFIG_STORAGE & STORAGE_ATA) && (CONFIG_LED == LED_REAL) \
2069 && !defined(SIMULATOR)
2070 ata_set_led_enabled(true);
2075 return (rec_status
& RCSTAT_BEEN_IN_USB_MODE
) != 0;
2076 } /* recording_screen */
2078 #if CONFIG_KEYPAD == RECORDER_PAD
2079 static bool f2_rec_screen(void)
2081 static const char* const freq_str
[6] =
2096 struct audio_recording_options rec_options
;
2100 screens
[i
].set_viewport(NULL
);
2101 screens
[i
].setfont(FONT_SYSFIXED
);
2102 screens
[i
].getstringsize("A",&w
,&h
);
2110 screens
[i
].clear_display();
2112 /* Recording quality */
2113 screens
[i
].putsxy(0, LCD_HEIGHT
/2 - h
*2,
2114 str(LANG_SYSFONT_RECORDING_QUALITY
));
2117 snprintf(buf
, sizeof(buf
), "%d", global_settings
.rec_quality
);
2120 screens
[i
].putsxy(0, LCD_HEIGHT
/2-h
, buf
);
2121 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_FastBackward
],
2122 LCD_WIDTH
/2 - 16, LCD_HEIGHT
/2 - 4, 7, 8);
2126 snprintf(buf
, sizeof buf
, "%s:", str(LANG_SYSFONT_RECORDING_FREQUENCY
));
2127 ptr
= freq_str
[global_settings
.rec_frequency
];
2130 screens
[i
].getstringsize(buf
,&w
,&h
);
2131 screens
[i
].putsxy((LCD_WIDTH
-w
)/2, LCD_HEIGHT
- h
*2, buf
);
2132 screens
[i
].getstringsize(ptr
, &w
, &h
);
2133 screens
[i
].putsxy((LCD_WIDTH
-w
)/2, LCD_HEIGHT
- h
, ptr
);
2134 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_DownArrow
],
2135 LCD_WIDTH
/2 - 3, LCD_HEIGHT
- h
*3, 7, 8);
2139 switch ( global_settings
.rec_channels
) {
2141 ptr
= str(LANG_SYSFONT_CHANNEL_STEREO
);
2145 ptr
= str(LANG_SYSFONT_CHANNEL_MONO
);
2151 screens
[i
].getstringsize(str(LANG_SYSFONT_CHANNELS
), &w
, &h
);
2152 screens
[i
].putsxy(LCD_WIDTH
- w
, LCD_HEIGHT
/2 - h
*2,
2153 str(LANG_SYSFONT_CHANNELS
));
2154 screens
[i
].getstringsize(str(LANG_SYSFONT_MODE
), &w
, &h
);
2155 screens
[i
].putsxy(LCD_WIDTH
- w
, LCD_HEIGHT
/2 - h
,
2156 str(LANG_SYSFONT_MODE
));
2157 screens
[i
].getstringsize(ptr
, &w
, &h
);
2158 screens
[i
].putsxy(LCD_WIDTH
- w
, LCD_HEIGHT
/2, ptr
);
2159 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_FastForward
],
2160 LCD_WIDTH
/2 + 8, LCD_HEIGHT
/2 - 4, 7, 8);
2162 screens
[i
].update();
2165 button
= button_get(true);
2168 case BUTTON_F2
| BUTTON_LEFT
:
2169 global_settings
.rec_quality
++;
2170 if(global_settings
.rec_quality
> 7)
2171 global_settings
.rec_quality
= 0;
2176 case BUTTON_F2
| BUTTON_DOWN
:
2177 global_settings
.rec_frequency
++;
2178 if(global_settings
.rec_frequency
> 5)
2179 global_settings
.rec_frequency
= 0;
2184 case BUTTON_F2
| BUTTON_RIGHT
:
2185 global_settings
.rec_channels
++;
2186 if(global_settings
.rec_channels
> 1)
2187 global_settings
.rec_channels
= 0;
2191 case BUTTON_F2
| BUTTON_REL
:
2197 case BUTTON_F2
| BUTTON_REPEAT
:
2202 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
2208 rec_init_recording_options(&rec_options
);
2209 rec_set_recording_options(&rec_options
);
2215 screens
[i
].setfont(FONT_UI
);
2220 static bool f3_rec_screen(void)
2226 const char *src_str
[] =
2228 str(LANG_SYSFONT_RECORDING_SRC_MIC
),
2229 str(LANG_SYSFONT_LINE_IN
),
2230 str(LANG_SYSFONT_RECORDING_SRC_DIGITAL
)
2232 struct audio_recording_options rec_options
;
2236 screens
[i
].set_viewport(NULL
);
2237 screens
[i
].setfont(FONT_SYSFIXED
);
2238 screens
[i
].getstringsize("A",&w
,&h
);
2242 const char* ptr
= src_str
[global_settings
.rec_source
];
2245 screens
[i
].clear_display();
2247 /* Recording source */
2248 screens
[i
].putsxy(0, LCD_HEIGHT
/2 - h
*2,
2249 str(LANG_SYSFONT_RECORDING_SOURCE
));
2251 screens
[i
].getstringsize(ptr
, &w
, &h
);
2252 screens
[i
].putsxy(0, LCD_HEIGHT
/2-h
, ptr
);
2253 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_FastBackward
],
2254 LCD_WIDTH
/2 - 16, LCD_HEIGHT
/2 - 4, 7, 8);
2258 ptr
= str(LANG_SYSFONT_RECORD_TRIGGER
);
2261 screens
[i
].getstringsize(ptr
,&w
,&h
);
2262 screens
[i
].putsxy((LCD_WIDTH
-w
)/2, LCD_HEIGHT
- h
*2, ptr
);
2263 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_DownArrow
],
2264 LCD_WIDTH
/2 - 3, LCD_HEIGHT
- h
*3, 7, 8);
2266 screens
[i
].update();
2269 button
= button_get(true);
2272 case BUTTON_F3
| BUTTON_DOWN
:
2275 settings_apply_trigger();
2281 case BUTTON_F3
| BUTTON_LEFT
:
2282 global_settings
.rec_source
++;
2283 if(global_settings
.rec_source
> AUDIO_SRC_MAX
)
2284 global_settings
.rec_source
= 0;
2288 case BUTTON_F3
| BUTTON_REL
:
2294 case BUTTON_F3
| BUTTON_REPEAT
:
2299 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
2305 rec_init_recording_options(&rec_options
);
2306 rec_set_recording_options(&rec_options
);
2312 screens
[i
].setfont(FONT_UI
);
2316 #endif /* CONFIG_KEYPAD == RECORDER_PAD */
2318 #if CONFIG_CODEC == SWCODEC
2319 void audio_beep(int duration
)
2326 /* stubs for recording sim */
2327 void audio_init_recording(unsigned int buffer_offset
)
2329 buffer_offset
= buffer_offset
;
2332 void audio_close_recording(void)
2336 unsigned long pcm_rec_get_warnings(void)
2341 unsigned long pcm_rec_sample_rate(void)
2346 unsigned long audio_recorded_time(void)
2351 unsigned long audio_num_recorded_bytes(void)
2353 return 5 * 1024 * 1024;
2356 void rec_set_source(int source
, unsigned flags
)
2362 void audio_set_recording_options(struct audio_recording_options
*options
)
2367 void audio_set_recording_gain(int left
, int right
, int type
)
2374 void audio_record(const char *filename
)
2376 filename
= filename
;
2379 void audio_new_file(const char *filename
)
2381 filename
= filename
;
2384 void audio_stop_recording(void)
2388 void audio_pause_recording(void)
2392 void audio_resume_recording(void)
2396 #endif /* #ifdef SIMULATOR */
2397 #endif /* #ifdef CONFIG_CODEC == SWCODEC */
2399 #endif /* HAVE_RECORDING */