1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 by Linus Nielsen Feltzing
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
30 #include "powermgmt.h"
35 #if CONFIG_CODEC == SWCODEC
38 #include "enc_config.h"
39 #if defined(HAVE_SPDIF_IN) || defined(HAVE_SPDIF_OUT)
42 #endif /* CONFIG_CODEC == SWCODEC */
43 #include "recording.h"
44 #include "mp3_playback.h"
54 #include "peakmeter.h"
55 #include "statusbar.h"
57 #include "sound_menu.h"
58 #include "timefuncs.h"
69 #include "screen_access.h"
72 #include "sound_menu.h"
76 /* This array holds the record timer interval lengths, in seconds */
77 static const unsigned long rec_timer_seconds
[] =
91 10L*60*60, /* 10:00 */
92 12L*60*60, /* 12:00 */
93 18L*60*60, /* 18:00 */
97 static unsigned int rec_timesplit_seconds(void)
99 return rec_timer_seconds
[global_settings
.rec_timesplit
];
102 /* This array holds the record size interval lengths, in bytes */
103 static const unsigned long rec_size_bytes
[] =
106 5*1024*1024, /* 5MB */
107 10*1024*1024, /* 10MB */
108 15*1024*1024, /* 15MB */
109 32*1024*1024, /* 32MB */
110 64*1024*1024, /* 64MB */
111 75*1024*1024, /* 75MB */
112 100*1024*1024, /* 100MB */
113 128*1024*1024, /* 128MB */
114 256*1024*1024, /* 256MB */
115 512*1024*1024, /* 512MB */
116 650*1024*1024, /* 650MB */
117 700*1024*1024, /* 700MB */
118 1024*1024*1024, /* 1GB */
119 1536*1024*1024, /* 1.5GB */
120 1792*1024*1024, /* 1.75GB */
123 static unsigned long rec_sizesplit_bytes(void)
125 return rec_size_bytes
[global_settings
.rec_sizesplit
];
128 void settings_apply_trigger(void)
130 int start_thres
, stop_thres
;
131 if (global_settings
.peak_meter_dbfs
)
133 start_thres
= global_settings
.rec_start_thres_db
- 1;
134 stop_thres
= global_settings
.rec_stop_thres_db
- 1;
138 start_thres
= global_settings
.rec_start_thres_linear
;
139 stop_thres
= global_settings
.rec_stop_thres_linear
;
142 peak_meter_define_trigger(
144 global_settings
.rec_start_duration
*HZ
,
145 MIN(global_settings
.rec_start_duration
*HZ
/ 2, 2*HZ
),
147 global_settings
.rec_stop_postrec
*HZ
,
148 global_settings
.rec_stop_gap
*HZ
151 /* recording screen status flags */
152 enum rec_status_flags
154 RCSTAT_IN_RECSCREEN
= 0x00000001,
155 RCSTAT_BEEN_IN_USB_MODE
= 0x00000002,
156 RCSTAT_CREATED_DIRECTORY
= 0x00000004,
157 RCSTAT_HAVE_RECORDED
= 0x00000008,
160 static int rec_status
= 0;
162 bool in_recording_screen(void)
164 return (rec_status
& RCSTAT_IN_RECSCREEN
) != 0;
167 #define PM_HEIGHT ((LCD_HEIGHT >= 72) ? 2 : 1)
169 #if CONFIG_KEYPAD == RECORDER_PAD
170 static bool f2_rec_screen(void);
171 static bool f3_rec_screen(void);
174 #define MAX_FILE_SIZE 0x7F800000 /* 2 GB - 4 MB */
176 #ifndef HAVE_REMOTE_LCD
177 static const int screen_update
= NB_SCREENS
;
179 static int screen_update
= NB_SCREENS
;
180 static bool remote_display_on
= true;
183 /** File name creation **/
185 /* current file number to assist in creating unique numbered filenames
186 without actually having to create the file on disk */
187 static int file_number
= -1;
188 #endif /* CONFIG_RTC */
190 #if CONFIG_CODEC == SWCODEC
192 #define REC_FILE_ENDING(rec_format) \
193 (audio_formats[rec_format_afmt[rec_format]].ext_list)
195 #else /* CONFIG_CODEC != SWCODEC */
197 /* default record file extension for HWCODEC */
198 #define REC_FILE_ENDING(rec_format) \
199 (audio_formats[AFMT_MPA_L3].ext_list)
201 #endif /* CONFIG_CODEC == SWCODEC */
203 /* path for current file */
204 static char path_buffer
[MAX_PATH
];
206 /** Automatic Gain Control (AGC) **/
209 * peak_time is incremented every 0.2s, every 2nd run of record screen loop.
210 * hist_time is incremented every 0.5s, display update.
211 * peak_time is the counter of the peak hold read and agc process,
212 * overflow every 13 years 8-)
214 static long peak_time
= 0;
215 static long hist_time
= 0;
217 static short peak_valid_mem
[4];
218 #define BAL_MEM_SIZE 24
219 static short balance_mem
[BAL_MEM_SIZE
];
221 /* Automatic Gain Control */
222 #define AGC_MODE_SIZE 5
223 #define AGC_SAFETY_MODE 0
225 static const char* agc_preset_str
[] =
226 { "Off", "S", "L", "D", "M", "V" };
233 #define AGC_CLIP 32766
234 #define AGC_PEAK 29883 /* fast gain reduction threshold -0.8dB */
235 #define AGC_HIGH 27254 /* accelerated gain reduction threshold -1.6dB */
236 #define AGC_IMG 823 /* threshold for balance control -32dB */
237 /* autogain high level thresholds (-3dB, -7dB, -4dB, -5dB, -5dB) */
238 static const short agc_th_hi
[AGC_MODE_SIZE
] =
239 { 23197, 14637, 21156, 18428, 18426 };
240 /* autogain low level thresholds (-14dB, -11dB, -6dB, -7dB, -8dB) */
241 static const short agc_th_lo
[AGC_MODE_SIZE
] =
242 { 6538, 9235, 16422, 14636, 13045 };
243 /* autogain threshold times [1/5s] or [200ms] */
244 static const short agc_tdrop
[AGC_MODE_SIZE
] =
245 { 900, 225, 150, 60, 8 };
246 static const short agc_trise
[AGC_MODE_SIZE
] =
247 { 9000, 750, 400, 150, 20 };
248 static const short agc_tbal
[AGC_MODE_SIZE
] =
249 { 4500, 500, 300, 100, 15 };
251 static bool agc_enable
= true;
252 static short agc_preset
;
254 static int agc_left
= 0;
255 static int agc_right
= 0;
256 /* AGC time since high target volume was exceeded */
257 static short agc_droptime
= 0;
258 /* AGC time since volume fallen below low target */
259 static short agc_risetime
= 0;
260 /* AGC balance time exceeding +/- 0.7dB */
261 static short agc_baltime
= 0;
262 /* AGC maximum gain */
263 static short agc_maxgain
;
264 #endif /* HAVE_AGC */
266 static void set_gain(void)
268 if(global_settings
.rec_source
== AUDIO_SRC_MIC
)
270 audio_set_recording_gain(global_settings
.rec_mic_gain
,
275 /* AUDIO_SRC_LINEIN, AUDIO_SRC_FMRADIO, AUDIO_SRC_SPDIF */
276 audio_set_recording_gain(global_settings
.rec_left_gain
,
277 global_settings
.rec_right_gain
,
280 /* reset the clipping indicators */
281 peak_meter_set_clip_hold(global_settings
.peak_meter_clip_hold
);
285 /* Read peak meter values & calculate balance.
286 * Returns validity of peak values.
287 * Used for automatic gain control and history diagram.
289 static bool read_peak_levels(int *peak_l
, int *peak_r
, int *balance
)
291 peak_meter_get_peakhold(peak_l
, peak_r
);
292 peak_valid_mem
[peak_time
% 3] = *peak_l
;
293 if (((peak_valid_mem
[0] == peak_valid_mem
[1]) &&
294 (peak_valid_mem
[1] == peak_valid_mem
[2])) &&
297 || ata_disk_is_active()
302 if (*peak_r
> *peak_l
)
303 balance_mem
[peak_time
% BAL_MEM_SIZE
] = (*peak_l
?
304 MIN((10000 * *peak_r
) / *peak_l
- 10000, 15118) : 15118);
306 balance_mem
[peak_time
% BAL_MEM_SIZE
] = (*peak_r
?
307 MAX(10000 - (10000 * *peak_l
) / *peak_r
, -15118) : -15118);
310 for (i
= 0; i
< BAL_MEM_SIZE
; i
++)
311 *balance
+= balance_mem
[i
];
312 *balance
= *balance
/ BAL_MEM_SIZE
;
317 /* AGC helper function to check if maximum gain is reached */
318 static bool agc_gain_is_max(bool left
, bool right
)
320 /* range -128...+108 [0.5dB] */
321 short gain_current_l
;
322 short gain_current_r
;
327 switch (global_settings
.rec_source
)
329 HAVE_LINE_REC_(case AUDIO_SRC_LINEIN
:)
330 HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO
:)
331 gain_current_l
= global_settings
.rec_left_gain
;
332 gain_current_r
= global_settings
.rec_right_gain
;
336 gain_current_l
= global_settings
.rec_mic_gain
;
337 gain_current_r
= global_settings
.rec_mic_gain
;
340 return ((left
&& (gain_current_l
>= agc_maxgain
)) ||
341 (right
&& (gain_current_r
>= agc_maxgain
)));
344 static void change_recording_gain(bool increment
, bool left
, bool right
)
346 int factor
= (increment
? 1 : -1);
348 switch (global_settings
.rec_source
)
350 HAVE_LINE_REC_(case AUDIO_SRC_LINEIN
:)
351 HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO
:)
352 if (left
) global_settings
.rec_left_gain
+= factor
;
353 if (right
) global_settings
.rec_right_gain
+= factor
;
356 global_settings
.rec_mic_gain
+= factor
;
361 * Handle automatic gain control (AGC).
362 * Change recording gain if peak_x levels are above or below
363 * target volume for specified timeouts.
365 static void auto_gain_control(int *peak_l
, int *peak_r
, int *balance
)
371 if (*peak_l
> agc_left
)
374 agc_left
-= (agc_left
- *peak_l
+ 3) >> 2;
375 if (*peak_r
> agc_right
)
378 agc_right
-= (agc_right
- *peak_r
+ 3) >> 2;
379 agc_mono
= (agc_left
+ agc_right
) / 2;
381 agc_mode
= abs(agc_preset
) - 1;
387 if (agc_mode
!= AGC_SAFETY_MODE
) {
388 /* Automatic balance control - only if not in safety mode */
389 if ((agc_left
> AGC_IMG
) && (agc_right
> AGC_IMG
))
394 agc_baltime
-= !(peak_time
% 4); /* 0.47 - 0.75dB */
395 else if (*balance
> -4125)
396 agc_baltime
--; /* 0.75 - 3.00dB */
397 else if (*balance
> -7579)
398 agc_baltime
-= 2; /* 3.00 - 4.90dB */
400 agc_baltime
-= !(peak_time
% 8); /* 4.90 - inf dB */
402 agc_baltime
-= (peak_time
% 2);
404 else if (*balance
> 556)
407 agc_baltime
+= !(peak_time
% 4);
408 else if (*balance
< 4125)
410 else if (*balance
< 7579)
413 agc_baltime
+= !(peak_time
% 8);
415 agc_baltime
+= (peak_time
% 2);
418 if ((*balance
* agc_baltime
) < 0)
421 agc_baltime
-= peak_time
% 2;
423 agc_baltime
+= peak_time
% 2;
426 increment
= ((agc_risetime
/ 2) > agc_droptime
);
428 if (agc_baltime
< -agc_tbal
[agc_mode
])
430 if (!increment
|| !agc_gain_is_max(!increment
, increment
)) {
431 change_recording_gain(increment
, !increment
, increment
);
436 else if (agc_baltime
> +agc_tbal
[agc_mode
])
438 if (!increment
|| !agc_gain_is_max(increment
, !increment
)) {
439 change_recording_gain(increment
, increment
, !increment
);
445 else if (!(hist_time
% 4))
454 /* Automatic gain control */
455 if ((agc_left
> agc_th_hi
[agc_mode
]) || (agc_right
> agc_th_hi
[agc_mode
]))
457 if ((agc_left
> AGC_CLIP
) || (agc_right
> AGC_CLIP
))
458 agc_droptime
+= agc_tdrop
[agc_mode
] /
459 (global_settings
.rec_agc_cliptime
+ 1);
460 if (agc_left
> AGC_HIGH
) {
463 if (agc_left
> AGC_PEAK
)
466 if (agc_right
> AGC_HIGH
) {
469 if (agc_right
> AGC_PEAK
)
472 if (agc_mono
> agc_th_hi
[agc_mode
])
475 agc_droptime
+= !(peak_time
% 2);
477 if (agc_droptime
>= agc_tdrop
[agc_mode
])
479 change_recording_gain(false, true, true);
484 agc_risetime
= MAX(agc_risetime
- 1, 0);
486 else if (agc_mono
< agc_th_lo
[agc_mode
])
488 if (agc_mono
< (agc_th_lo
[agc_mode
] / 8))
489 agc_risetime
+= !(peak_time
% 5);
490 else if (agc_mono
< (agc_th_lo
[agc_mode
] / 2))
495 if (agc_risetime
>= agc_trise
[agc_mode
]) {
496 if ((agc_mode
!= AGC_SAFETY_MODE
) &&
497 (!agc_gain_is_max(true, true))) {
498 change_recording_gain(true, true, true);
504 agc_droptime
= MAX(agc_droptime
- 1, 0);
506 else if (!(peak_time
% 6)) /* on target level every 1.2 sec */
508 agc_risetime
= MAX(agc_risetime
- 1, 0);
509 agc_droptime
= MAX(agc_droptime
- 1, 0);
512 #endif /* HAVE_AGC */
514 static const char* const fmtstr
[] =
516 "%c%d %s", /* no decimals */
517 "%c%d.%d %s ", /* 1 decimal */
518 "%c%d.%02d %s " /* 2 decimals */
521 static char *fmt_gain(int snd
, int val
, char *str
, int len
)
527 val
= sound_val2phys(snd
, val
);
533 numdec
= sound_numdecimals(snd
);
534 unit
= sound_unit(snd
);
538 i
= val
/ (10*numdec
);
539 d
= val
% (10*numdec
);
540 snprintf(str
, len
, fmtstr
[numdec
], sign
, i
, d
, unit
);
543 snprintf(str
, len
, fmtstr
[numdec
], sign
, val
, unit
);
550 static void adjust_cursor(void)
558 switch(global_settings
.rec_source
)
565 HAVE_LINE_REC_(case AUDIO_SRC_LINEIN
:)
566 HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO
:)
573 #else /* !HAVE_AGC */
574 switch(global_settings
.rec_source
)
579 HAVE_LINE_REC_(case AUDIO_SRC_LINEIN
:)
580 HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO
:)
587 #endif /* HAVE_AGC */
589 if(cursor
> max_cursor
)
593 /* the list below must match enum audio_sources in audio.h */
594 static const char* const prestr
[] =
596 HAVE_MIC_IN_([AUDIO_SRC_MIC
] = "R_MIC_",)
597 HAVE_LINE_REC_([AUDIO_SRC_LINEIN
] = "R_LINE_",)
598 HAVE_SPDIF_IN_([AUDIO_SRC_SPDIF
] = "R_SPDIF_",)
599 HAVE_FMRADIO_REC_([AUDIO_SRC_FMRADIO
] = "R_FM_",)
602 char *rec_create_filename(char *buffer
)
605 const char *pref
= "R_";
607 /* Directory existence and writeablility should have already been
608 * verified - do not pass NULL pointers to pcmrec */
610 if((unsigned)global_settings
.rec_source
< AUDIO_NUM_SOURCES
)
612 pref
= prestr
[global_settings
.rec_source
];
615 strcpy(buffer
, global_settings
.rec_directory
);
617 snprintf(ext
, sizeof(ext
), ".%s",
618 REC_FILE_ENDING(global_settings
.rec_format
));
621 return create_numbered_filename(buffer
, buffer
, pref
, ext
, 4,
624 /* We'll wait at least up to the start of the next second so no duplicate
626 return create_datetime_filename(buffer
, buffer
, pref
, ext
, true);
631 /* Hit disk to get a starting filename for the type */
632 static void rec_init_filename(void)
635 rec_create_filename(path_buffer
);
640 int rec_create_directory(void)
643 const char * const folder
= global_settings
.rec_directory
;
645 if (strcmp(folder
, "/") && !dir_exists(folder
))
651 while (action_userabort(HZ
) == false)
653 gui_syncsplash(0, "%s %s",
654 str(LANG_REC_DIR_NOT_WRITABLE
),
655 str(LANG_OFF_ABORT
));
660 rec_status
|= RCSTAT_CREATED_DIRECTORY
;
668 void rec_init_recording_options(struct audio_recording_options
*options
)
670 options
->rec_source
= global_settings
.rec_source
;
671 options
->rec_frequency
= global_settings
.rec_frequency
;
672 options
->rec_channels
= global_settings
.rec_channels
;
673 options
->rec_prerecord_time
= global_settings
.rec_prerecord_time
;
674 #if CONFIG_CODEC == SWCODEC
675 options
->rec_source_flags
= 0;
676 options
->enc_config
.rec_format
= global_settings
.rec_format
;
677 global_to_encoder_config(&options
->enc_config
);
679 options
->rec_quality
= global_settings
.rec_quality
;
680 options
->rec_editable
= global_settings
.rec_editable
;
684 #if CONFIG_CODEC == SWCODEC && !defined (SIMULATOR)
685 void rec_set_source(int source
, unsigned flags
)
687 /* Set audio input source, power up/down devices */
688 audio_set_input_source(source
, flags
);
690 /* Set peakmeters for recording or reset to playback */
691 peak_meter_playback((flags
& SRCF_RECORDING
) == 0);
692 peak_meter_enabled
= true;
694 #endif /* CONFIG_CODEC == SWCODEC && !defined (SIMULATOR) */
696 void rec_set_recording_options(struct audio_recording_options
*options
)
698 #if CONFIG_CODEC != SWCODEC
699 if (global_settings
.rec_prerecord_time
)
701 talk_buffer_steal(); /* will use the mp3 buffer */
703 #else /* == SWCODEC */
704 rec_set_source(options
->rec_source
,
705 options
->rec_source_flags
| SRCF_RECORDING
);
706 #endif /* CONFIG_CODEC != SWCODEC */
708 audio_set_recording_options(options
);
711 void rec_command(enum recording_command cmd
)
715 case RECORDING_CMD_STOP_SHUTDOWN
:
716 pm_activate_clipcount(false);
717 audio_stop_recording();
718 #if CONFIG_CODEC == SWCODEC
719 audio_close_recording();
723 case RECORDING_CMD_STOP
:
724 pm_activate_clipcount(false);
725 audio_stop_recording();
727 case RECORDING_CMD_START
:
728 /* steal mp3 buffer, create unique filename and start recording */
729 pm_reset_clipcount();
730 pm_activate_clipcount(true);
731 #if CONFIG_CODEC != SWCODEC
732 talk_buffer_steal(); /* we use the mp3 buffer */
734 audio_record(rec_create_filename(path_buffer
));
736 case RECORDING_CMD_START_NEWFILE
:
737 /* create unique filename and start recording*/
738 pm_reset_clipcount();
739 pm_activate_clipcount(true); /* just to be sure */
740 audio_new_file(rec_create_filename(path_buffer
));
742 case RECORDING_CMD_PAUSE
:
743 pm_activate_clipcount(false);
744 audio_pause_recording();
746 case RECORDING_CMD_RESUME
:
747 pm_activate_clipcount(true);
748 audio_resume_recording();
753 /* used in trigger_listerner and recording_screen */
754 static unsigned int last_seconds
= 0;
757 * Callback function so that the peak meter code can send an event
758 * to this application. This function can be passed to
759 * peak_meter_set_trigger_listener in order to activate the trigger.
761 static void trigger_listener(int trigger_status
)
763 switch (trigger_status
)
766 if(!(audio_status() & AUDIO_STATUS_RECORD
))
768 rec_status
|= RCSTAT_HAVE_RECORDED
;
769 rec_command(RECORDING_CMD_START
);
770 #if CONFIG_CODEC != SWCODEC
771 /* give control to mpeg thread so that it can start
773 yield(); yield(); yield();
777 /* if we're already recording this is a retrigger */
780 if((audio_status() & AUDIO_STATUS_PAUSE
) &&
781 (global_settings
.rec_trigger_type
== TRIG_TYPE_PAUSE
))
783 rec_command(RECORDING_CMD_RESUME
);
785 /* New file on trig start*/
786 else if (global_settings
.rec_trigger_type
!= TRIG_TYPE_NEW_FILE
)
788 rec_command(RECORDING_CMD_START_NEWFILE
);
789 /* tell recording_screen to reset the time */
795 /* A _change_ to TRIG_READY means the current recording has stopped */
797 if(audio_status() & AUDIO_STATUS_RECORD
)
799 switch(global_settings
.rec_trigger_type
)
801 case TRIG_TYPE_STOP
: /* Stop */
802 rec_command(RECORDING_CMD_STOP
);
805 case TRIG_TYPE_PAUSE
: /* Pause */
806 rec_command(RECORDING_CMD_PAUSE
);
809 case TRIG_TYPE_NEW_FILE
: /* New file on trig stop*/
810 rec_command(RECORDING_CMD_START_NEWFILE
);
811 /* tell recording_screen to reset the time */
815 case 3: /* Stop and shutdown */
816 rec_command(RECORDING_CMD_STOP_SHUTDOWN
);
820 if (global_settings
.rec_trigger_mode
!= TRIG_MODE_REARM
)
822 peak_meter_set_trigger_listener(NULL
);
823 peak_meter_trigger(false);
830 bool recording_start_automatic
= false;
832 bool recording_screen(bool no_source
)
839 int update_countdown
= 1;
840 unsigned int seconds
;
843 int last_audio_stat
= -1;
845 #if CONFIG_CODEC == SWCODEC
846 int warning_counter
= 0;
847 #define WARNING_PERIOD 7
849 #ifdef HAVE_FMRADIO_REC
850 /* Radio is left on if:
851 * 1) Is was on at the start and the initial source is FM Radio
852 * 2) 1) and the source was never changed to something else
854 int radio_status
= (global_settings
.rec_source
!= AUDIO_SRC_FMRADIO
) ?
855 FMRADIO_OFF
: get_radio_status();
857 #if (CONFIG_LED == LED_REAL)
858 bool led_state
= false;
859 int led_countdown
= 2;
862 bool peak_read
= false;
863 bool peak_valid
= false;
866 bool display_agc
[NB_SCREENS
];
868 int line
[NB_SCREENS
];
870 int filename_offset
[NB_SCREENS
];
871 int pm_y
[NB_SCREENS
];
872 int trig_xpos
[NB_SCREENS
];
873 int trig_ypos
[NB_SCREENS
];
874 int trig_width
[NB_SCREENS
];
875 /* pm_x = offset pm to put clipcount in front.
876 Use lcd_getstringsize() when not using SYSFONT */
877 int pm_x
= global_settings
.peak_meter_clipcounter
? 30 : 0;
879 static const unsigned char *byte_units
[] = {
886 int base_style
= STYLE_INVERT
;
888 struct viewport vp
[NB_SCREENS
];
889 int ymargin
= global_settings
.cursor_style
?0:10;
890 #ifdef HAVE_LCD_COLOR
891 if (global_settings
.cursor_style
== 2) {
892 base_style
|= STYLE_COLORBAR
;
894 else if (global_settings
.cursor_style
== 3) {
895 base_style
|= STYLE_GRADIENT
;
899 struct audio_recording_options rec_options
;
900 rec_status
= RCSTAT_IN_RECSCREEN
;
902 if (rec_create_directory() < 0)
909 #if (CONFIG_LED == LED_REAL) && !defined(SIMULATOR)
910 ata_set_led_enabled(false);
913 #if CONFIG_CODEC == SWCODEC
914 /* recording_menu gets messed up: so prevent manus talking */
916 /* audio_init_recording stops anything playing when it takes the audio
919 /* Yes, we use the D/A for monitoring */
920 peak_meter_enabled
= true;
921 peak_meter_playback(true);
924 audio_init_recording(0);
925 sound_set_volume(global_settings
.volume
);
928 peak_meter_get_peakhold(&peak_l
, &peak_r
);
931 rec_init_recording_options(&rec_options
);
932 rec_set_recording_options(&rec_options
);
937 /* Create new filename for recording start */
941 pm_reset_clipcount();
942 pm_activate_clipcount(false);
943 settings_apply_trigger();
946 agc_preset_str
[0] = str(LANG_SYSFONT_OFF
);
947 agc_preset_str
[1] = str(LANG_SYSFONT_AGC_SAFETY
);
948 agc_preset_str
[2] = str(LANG_SYSFONT_AGC_LIVE
);
949 agc_preset_str
[3] = str(LANG_SYSFONT_AGC_DJSET
);
950 agc_preset_str
[4] = str(LANG_SYSFONT_AGC_MEDIUM
);
951 agc_preset_str
[5] = str(LANG_SYSFONT_AGC_VOICE
);
952 if (global_settings
.rec_source
== AUDIO_SRC_MIC
) {
953 agc_preset
= global_settings
.rec_agc_preset_mic
;
954 agc_maxgain
= global_settings
.rec_agc_maxgain_mic
;
957 agc_preset
= global_settings
.rec_agc_preset_line
;
958 agc_maxgain
= global_settings
.rec_agc_maxgain_line
;
960 #endif /* HAVE_AGC */
964 viewport_set_defaults(&vp
[i
], i
);
965 vp
[i
].font
= FONT_SYSFIXED
;
966 screens
[i
].set_viewport(&vp
[i
]);
967 screens
[i
].getstringsize("M", &w
, &h
);
968 filename_offset
[i
] = ((vp
[i
].height
>= 80) ? 1 : 0);
969 pm_y
[i
] = h
* (2 + filename_offset
[i
]);
972 #ifdef HAVE_REMOTE_LCD
973 if (!remote_display_on
)
975 screens
[1].clear_display();
976 snprintf(buf
, sizeof(buf
), str(LANG_REMOTE_LCD_ON
));
977 screens
[1].puts((vp
[1].width
/w
- strlen(buf
))/2 + 1,
978 vp
[1].height
/(h
*2) + 1, buf
);
980 gui_syncsplash(0, str(LANG_REMOTE_LCD_OFF
));
986 audio_stat
= audio_status();
988 #if (CONFIG_LED == LED_REAL)
991 * Flash the LED while waiting to record. Turn it on while
994 if(audio_stat
& AUDIO_STATUS_RECORD
)
996 if (audio_stat
& AUDIO_STATUS_PAUSE
)
998 if (--led_countdown
<= 0)
1000 led_state
= !led_state
;
1007 /* trigger is on in status TRIG_READY (no check needed) */
1013 int trigStat
= peak_meter_trigger_status();
1015 * other trigger stati than trig_off and trig_steady
1016 * already imply that we are recording.
1018 if (trigStat
== TRIG_STEADY
)
1020 if (--led_countdown
<= 0)
1022 led_state
= !led_state
;
1029 /* trigger is on in status TRIG_READY (no check needed) */
1033 #endif /* CONFIG_LED */
1035 /* Wait for a button a while (HZ/10) drawing the peak meter */
1036 button
= peak_meter_draw_get_btn(CONTEXT_RECSCREEN
,
1037 pm_x
, pm_y
, h
* PM_HEIGHT
,
1040 if (last_audio_stat
!= audio_stat
)
1042 if (audio_stat
& AUDIO_STATUS_RECORD
)
1044 rec_status
|= RCSTAT_HAVE_RECORDED
;
1046 last_audio_stat
= audio_stat
;
1050 if (recording_start_automatic
)
1052 /* simulate a button press */
1053 button
= ACTION_REC_PAUSE
;
1054 recording_start_automatic
= false;
1059 #ifdef HAVE_REMOTE_LCD
1060 case ACTION_REC_LCD
:
1061 if (remote_display_on
)
1063 remote_display_on
= false;
1065 screens
[1].clear_display();
1066 snprintf(buf
, sizeof(buf
), str(LANG_REMOTE_LCD_ON
));
1067 screens
[1].puts((screens
[1].getwidth()/w
- strlen(buf
))/2 +
1069 screens
[1].getheight()/(h
*2) + 1, buf
);
1070 screens
[1].update();
1071 gui_syncsplash(0, str(LANG_REMOTE_LCD_OFF
));
1075 remote_display_on
= true;
1076 screen_update
= NB_SCREENS
;
1080 case ACTION_STD_CANCEL
:
1081 /* turn off the trigger */
1082 peak_meter_trigger(false);
1083 peak_meter_set_trigger_listener(NULL
);
1085 if(audio_stat
& AUDIO_STATUS_RECORD
)
1087 rec_command(RECORDING_CMD_STOP
);
1091 #if CONFIG_CODEC != SWCODEC
1092 peak_meter_playback(true);
1093 peak_meter_enabled
= false;
1097 update_countdown
= 1; /* Update immediately */
1100 case ACTION_REC_PAUSE
:
1101 case ACTION_REC_NEWFILE
:
1102 /* Only act if the mpeg is stopped */
1103 if(!(audio_stat
& AUDIO_STATUS_RECORD
))
1105 /* is this manual or triggered recording? */
1106 if ((global_settings
.rec_trigger_mode
== TRIG_MODE_OFF
) ||
1107 (peak_meter_trigger_status() != TRIG_OFF
))
1109 /* manual recording */
1110 rec_status
|= RCSTAT_HAVE_RECORDED
;
1111 rec_command(RECORDING_CMD_START
);
1113 if (global_settings
.talk_menu
)
1115 /* no voice possible here, but a beep */
1116 audio_beep(HZ
/2); /* longer beep on start */
1119 /* this is triggered recording */
1122 /* we don't start recording now, but enable the
1123 trigger and let the callback function
1124 trigger_listener control when the recording starts */
1125 peak_meter_trigger(true);
1126 peak_meter_set_trigger_listener(&trigger_listener
);
1131 /*if new file button pressed, start new file */
1132 if (button
== ACTION_REC_NEWFILE
)
1134 rec_command(RECORDING_CMD_START_NEWFILE
);
1138 /* if pause button pressed, pause or resume */
1140 if(audio_stat
& AUDIO_STATUS_PAUSE
)
1142 rec_command(RECORDING_CMD_RESUME
);
1143 if (global_settings
.talk_menu
)
1145 /* no voice possible here, but a beep */
1146 audio_beep(HZ
/4); /* short beep on resume */
1151 rec_command(RECORDING_CMD_PAUSE
);
1155 update_countdown
= 1; /* Update immediately */
1158 case ACTION_STD_PREV
:
1161 update_countdown
= 1; /* Update immediately */
1164 case ACTION_STD_NEXT
:
1167 update_countdown
= 1; /* Update immediately */
1170 case ACTION_SETTINGS_INC
:
1171 case ACTION_SETTINGS_INCREPEAT
:
1175 global_settings
.volume
++;
1179 if(global_settings
.rec_source
== AUDIO_SRC_MIC
)
1181 if(global_settings
.rec_mic_gain
<
1182 sound_max(SOUND_MIC_GAIN
))
1183 global_settings
.rec_mic_gain
++;
1187 if(global_settings
.rec_left_gain
<
1188 sound_max(SOUND_LEFT_GAIN
))
1189 global_settings
.rec_left_gain
++;
1190 if(global_settings
.rec_right_gain
<
1191 sound_max(SOUND_RIGHT_GAIN
))
1192 global_settings
.rec_right_gain
++;
1196 if(global_settings
.rec_left_gain
<
1197 sound_max(SOUND_LEFT_GAIN
))
1198 global_settings
.rec_left_gain
++;
1201 if(global_settings
.rec_right_gain
<
1202 sound_max(SOUND_RIGHT_GAIN
))
1203 global_settings
.rec_right_gain
++;
1207 agc_preset
= MIN(agc_preset
+ 1, AGC_MODE_SIZE
);
1208 agc_enable
= (agc_preset
!= 0);
1209 if (global_settings
.rec_source
== AUDIO_SRC_MIC
) {
1210 global_settings
.rec_agc_preset_mic
= agc_preset
;
1211 agc_maxgain
= global_settings
.rec_agc_maxgain_mic
;
1213 global_settings
.rec_agc_preset_line
= agc_preset
;
1214 agc_maxgain
= global_settings
.rec_agc_maxgain_line
;
1218 if (global_settings
.rec_source
== AUDIO_SRC_MIC
)
1220 agc_maxgain
= MIN(agc_maxgain
+ 1,
1221 sound_max(SOUND_MIC_GAIN
));
1222 global_settings
.rec_agc_maxgain_mic
= agc_maxgain
;
1226 agc_maxgain
= MIN(agc_maxgain
+ 1,
1227 sound_max(SOUND_LEFT_GAIN
));
1228 global_settings
.rec_agc_maxgain_line
= agc_maxgain
;
1231 #endif /* HAVE_AGC */
1234 update_countdown
= 1; /* Update immediately */
1237 case ACTION_SETTINGS_DEC
:
1238 case ACTION_SETTINGS_DECREPEAT
:
1242 global_settings
.volume
--;
1246 if(global_settings
.rec_source
== AUDIO_SRC_MIC
)
1248 if(global_settings
.rec_mic_gain
>
1249 sound_min(SOUND_MIC_GAIN
))
1250 global_settings
.rec_mic_gain
--;
1254 if(global_settings
.rec_left_gain
>
1255 sound_min(SOUND_LEFT_GAIN
))
1256 global_settings
.rec_left_gain
--;
1257 if(global_settings
.rec_right_gain
>
1258 sound_min(SOUND_RIGHT_GAIN
))
1259 global_settings
.rec_right_gain
--;
1263 if(global_settings
.rec_left_gain
>
1264 sound_min(SOUND_LEFT_GAIN
))
1265 global_settings
.rec_left_gain
--;
1268 if(global_settings
.rec_right_gain
>
1269 sound_min(SOUND_RIGHT_GAIN
))
1270 global_settings
.rec_right_gain
--;
1274 agc_preset
= MAX(agc_preset
- 1, 0);
1275 agc_enable
= (agc_preset
!= 0);
1276 if (global_settings
.rec_source
== AUDIO_SRC_MIC
) {
1277 global_settings
.rec_agc_preset_mic
= agc_preset
;
1278 agc_maxgain
= global_settings
.rec_agc_maxgain_mic
;
1280 global_settings
.rec_agc_preset_line
= agc_preset
;
1281 agc_maxgain
= global_settings
.rec_agc_maxgain_line
;
1285 if (global_settings
.rec_source
== AUDIO_SRC_MIC
)
1287 agc_maxgain
= MAX(agc_maxgain
- 1,
1288 sound_min(SOUND_MIC_GAIN
));
1289 global_settings
.rec_agc_maxgain_mic
= agc_maxgain
;
1293 agc_maxgain
= MAX(agc_maxgain
- 1,
1294 sound_min(SOUND_LEFT_GAIN
));
1295 global_settings
.rec_agc_maxgain_line
= agc_maxgain
;
1298 #endif /* HAVE_AGC */
1301 update_countdown
= 1; /* Update immediately */
1304 case ACTION_STD_MENU
:
1305 #if CONFIG_CODEC == SWCODEC
1306 if(!(audio_stat
& AUDIO_STATUS_RECORD
))
1308 if(audio_stat
!= AUDIO_STATUS_RECORD
)
1311 #ifdef HAVE_FMRADIO_REC
1312 const int prev_rec_source
= global_settings
.rec_source
;
1315 #if (CONFIG_LED == LED_REAL)
1316 /* led is restored at begin of loop / end of function */
1319 if (recording_menu(no_source
))
1322 rec_status
|= RCSTAT_BEEN_IN_USB_MODE
;
1323 #ifdef HAVE_FMRADIO_REC
1324 radio_status
= FMRADIO_OFF
;
1329 #ifdef HAVE_FMRADIO_REC
1330 /* If input changes away from FM Radio, radio will
1331 remain off when recording screen closes. */
1332 if (global_settings
.rec_source
!= prev_rec_source
1333 && prev_rec_source
== AUDIO_SRC_FMRADIO
)
1334 radio_status
= FMRADIO_OFF
;
1337 #if CONFIG_CODEC == SWCODEC
1338 /* reinit after submenu exit */
1339 audio_close_recording();
1340 audio_init_recording(0);
1343 rec_init_recording_options(&rec_options
);
1344 rec_set_recording_options(&rec_options
);
1346 if(rec_create_directory() < 0)
1351 #if CONFIG_CODEC == SWCODEC && CONFIG_RTC == 0
1352 /* If format changed, a new number is required */
1353 rec_init_filename();
1357 if (global_settings
.rec_source
== AUDIO_SRC_MIC
) {
1358 agc_preset
= global_settings
.rec_agc_preset_mic
;
1359 agc_maxgain
= global_settings
.rec_agc_maxgain_mic
;
1362 agc_preset
= global_settings
.rec_agc_preset_line
;
1363 agc_maxgain
= global_settings
.rec_agc_maxgain_line
;
1369 update_countdown
= 1; /* Update immediately */
1373 screens
[i
].set_viewport(&vp
[i
]);
1374 screens
[i
].setfont(FONT_SYSFIXED
);
1380 #if CONFIG_KEYPAD == RECORDER_PAD
1382 if(audio_stat
!= AUDIO_STATUS_RECORD
)
1384 #if (CONFIG_LED == LED_REAL)
1385 /* led is restored at begin of loop / end of function */
1388 if (f2_rec_screen())
1390 rec_status
|= RCSTAT_HAVE_RECORDED
;
1394 update_countdown
= 1; /* Update immediately */
1399 if(audio_stat
& AUDIO_STATUS_RECORD
)
1401 rec_command(RECORDING_CMD_START_NEWFILE
);
1406 #if (CONFIG_LED == LED_REAL)
1407 /* led is restored at begin of loop / end of function */
1410 if (f3_rec_screen())
1412 rec_status
|= RCSTAT_HAVE_RECORDED
;
1416 update_countdown
= 1; /* Update immediately */
1419 #endif /* CONFIG_KEYPAD == RECORDER_PAD */
1421 case SYS_USB_CONNECTED
:
1422 /* Only accept USB connection when not recording */
1423 if(!(audio_stat
& AUDIO_STATUS_RECORD
))
1425 default_event_handler(SYS_USB_CONNECTED
);
1427 rec_status
|= RCSTAT_BEEN_IN_USB_MODE
;
1428 #ifdef HAVE_FMRADIO_REC
1429 radio_status
= FMRADIO_OFF
;
1435 default_event_handler(button
);
1440 peak_read
= !peak_read
;
1441 if (peak_read
) { /* every 2nd run of loop */
1443 peak_valid
= read_peak_levels(&peak_l
, &peak_r
, &balance
);
1446 /* Handle AGC every 200ms when enabled and peak data is valid */
1447 if (peak_read
&& agc_enable
&& peak_valid
)
1448 auto_gain_control(&peak_l
, &peak_r
, &balance
);
1452 screens
[i
].setfont(FONT_SYSFIXED
);
1454 seconds
= audio_recorded_time() / HZ
;
1457 if(update_countdown
== 0 || seconds
> last_seconds
)
1459 unsigned int dseconds
, dhours
, dminutes
;
1460 unsigned long num_recorded_bytes
, dsize
, dmb
;
1463 update_countdown
= 5;
1464 last_seconds
= seconds
;
1466 dseconds
= rec_timesplit_seconds();
1467 dsize
= rec_sizesplit_bytes();
1468 num_recorded_bytes
= audio_num_recorded_bytes();
1470 for(i
= 0; i
< screen_update
; i
++)
1471 screens
[i
].clear_display();
1475 #ifdef HAVE_LCD_COLOR
1476 /* special action for gradient - set default for 1 line gradient */
1477 if(global_settings
.cursor_style
== 3)
1478 style
= base_style
| CURLN_PACK(0) | NUMLN_PACK(1);
1479 #endif /* HAVE_LCD_COLOR */
1481 #if CONFIG_CODEC == SWCODEC
1482 if ((audio_stat
& AUDIO_STATUS_WARNING
)
1483 && (warning_counter
++ % WARNING_PERIOD
) < WARNING_PERIOD
/2)
1485 /* Switch back and forth displaying warning on first available
1486 line to ensure visibility - the motion should also help
1488 /* Don't use language string unless agreed upon to make this
1489 method permanent - could do something in the statusbar */
1490 snprintf(buf
, sizeof(buf
), "Warning: %08X",
1491 pcm_rec_get_warnings());
1494 #endif /* CONFIG_CODEC == SWCODEC */
1495 if ((global_settings
.rec_sizesplit
) &&
1496 (global_settings
.rec_split_method
))
1498 dmb
= dsize
/1024/1024;
1499 snprintf(buf
, sizeof(buf
), "%s %dMB",
1500 str(LANG_SYSFONT_SPLIT_SIZE
), dmb
);
1504 hours
= seconds
/ 3600;
1505 minutes
= (seconds
- (hours
* 3600)) / 60;
1506 snprintf(buf
, sizeof(buf
), "%s %02d:%02d:%02d",
1507 str(LANG_SYSFONT_RECORDING_TIME
),
1508 hours
, minutes
, seconds
%60);
1511 for(i
= 0; i
< screen_update
; i
++)
1512 screens
[i
].puts(0, 0, buf
);
1514 if(audio_stat
& AUDIO_STATUS_PRERECORD
)
1516 snprintf(buf
, sizeof(buf
), "%s...",
1517 str(LANG_SYSFONT_RECORD_PRERECORD
));
1521 /* Display the split interval if the record timesplit
1523 if ((global_settings
.rec_timesplit
) &&
1524 !(global_settings
.rec_split_method
))
1526 /* Display the record timesplit interval rather
1527 than the file size if the record timer is
1529 dhours
= dseconds
/ 3600;
1530 dminutes
= (dseconds
- (dhours
* 3600)) / 60;
1531 snprintf(buf
, sizeof(buf
), "%s %02d:%02d",
1532 str(LANG_SYSFONT_RECORD_TIMESPLIT_REC
),
1537 output_dyn_value(buf2
, sizeof buf2
,
1540 snprintf(buf
, sizeof(buf
), "%s %s",
1541 str(LANG_SYSFONT_RECORDING_SIZE
), buf2
);
1544 for(i
= 0; i
< screen_update
; i
++)
1545 screens
[i
].puts(0, 1, buf
);
1547 for(i
= 0; i
< screen_update
; i
++)
1549 if (filename_offset
[i
] > 0)
1552 if (audio_stat
& AUDIO_STATUS_RECORD
)
1554 strncpy(filename
, path_buffer
+
1555 strlen(path_buffer
) - 12, 13);
1559 snprintf(buf
, sizeof(buf
), "%s %s",
1560 str(LANG_SYSFONT_RECORDING_FILENAME
), filename
);
1561 screens
[i
].puts(0, 2, buf
);
1565 /* We will do file splitting regardless, either at the end of
1566 a split interval, or when the filesize approaches the 2GB
1567 FAT file size (compatibility) limit. */
1568 if ((audio_stat
&& !(global_settings
.rec_split_method
)
1569 && global_settings
.rec_timesplit
&& (seconds
>= dseconds
))
1570 || (audio_stat
&& global_settings
.rec_split_method
1571 && global_settings
.rec_sizesplit
1572 && (num_recorded_bytes
>= dsize
))
1573 || (num_recorded_bytes
>= MAX_FILE_SIZE
))
1575 if (!(global_settings
.rec_split_type
)
1576 || (num_recorded_bytes
>= MAX_FILE_SIZE
))
1578 rec_command(RECORDING_CMD_START_NEWFILE
);
1583 peak_meter_trigger(false);
1584 peak_meter_set_trigger_listener(NULL
);
1585 if( global_settings
.rec_split_type
== 1)
1586 rec_command(RECORDING_CMD_STOP
);
1588 rec_command(RECORDING_CMD_STOP_SHUTDOWN
);
1590 update_countdown
= 1;
1593 /* draw the clipcounter just in front of the peakmeter */
1594 if(global_settings
.peak_meter_clipcounter
)
1597 snprintf(clpstr
, 32, "%4d", pm_get_clipcount());
1598 for(i
= 0; i
< screen_update
; i
++)
1601 screens
[i
].puts(0, 2 + filename_offset
[i
],
1602 str(LANG_SYSFONT_PM_CLIPCOUNT
));
1603 screens
[i
].puts(0, 1 + PM_HEIGHT
+ filename_offset
[i
],
1608 snprintf(buf
, sizeof(buf
), "%s: %s", str(LANG_SYSFONT_VOLUME
),
1609 fmt_gain(SOUND_VOLUME
,
1610 global_settings
.volume
,
1611 buf2
, sizeof(buf2
)));
1613 if (global_settings
.cursor_style
&& (pos
++ == cursor
))
1615 for(i
= 0; i
< screen_update
; i
++)
1616 screens
[i
].puts_style_offset(0, filename_offset
[i
] +
1617 PM_HEIGHT
+ 2, buf
, style
,0);
1621 for(i
= 0; i
< screen_update
; i
++)
1622 screens
[i
].putsxy(ymargin
,
1623 SYSFONT_HEIGHT
*(filename_offset
[i
]+
1624 PM_HEIGHT
+ 2), buf
);
1627 if(global_settings
.rec_source
== AUDIO_SRC_MIC
)
1629 /* Draw MIC recording gain */
1630 snprintf(buf
, sizeof(buf
), "%s:%s", str(LANG_SYSFONT_GAIN
),
1631 fmt_gain(SOUND_MIC_GAIN
,
1632 global_settings
.rec_mic_gain
,
1633 buf2
, sizeof(buf2
)));
1634 if(global_settings
.cursor_style
&& ((1==cursor
)||(2==cursor
)))
1636 for(i
= 0; i
< screen_update
; i
++)
1637 screens
[i
].puts_style_offset(0, filename_offset
[i
] +
1638 PM_HEIGHT
+ 3, buf
, style
,0);
1642 for(i
= 0; i
< screen_update
; i
++)
1643 screens
[i
].putsxy(ymargin
,
1644 SYSFONT_HEIGHT
*(filename_offset
[i
] +
1645 PM_HEIGHT
+ 3), buf
);
1649 HAVE_LINE_REC_( || global_settings
.rec_source
==
1651 HAVE_FMRADIO_REC_( || global_settings
.rec_source
==
1655 /* Draw LINE or FMRADIO recording gain */
1656 snprintf(buf
, sizeof(buf
), "%s:%s",
1657 str(LANG_SYSFONT_RECORDING_LEFT
),
1658 fmt_gain(SOUND_LEFT_GAIN
,
1659 global_settings
.rec_left_gain
,
1660 buf2
, sizeof(buf2
)));
1661 #ifdef HAVE_LCD_COLOR
1662 /* special action for gradient - double line gradient - line1 */
1663 if((global_settings
.cursor_style
== 3) &&
1665 style
= base_style
| CURLN_PACK(0) | NUMLN_PACK(2);
1666 #endif /* HAVE_LCD_COLOR */
1667 if(global_settings
.cursor_style
&& ((1==cursor
)||(2==cursor
)))
1669 for(i
= 0; i
< screen_update
; i
++)
1670 screens
[i
].puts_style_offset(0, filename_offset
[i
] +
1671 PM_HEIGHT
+ 3, buf
, style
,0);
1675 for(i
= 0; i
< screen_update
; i
++)
1676 screens
[i
].putsxy(ymargin
,
1677 SYSFONT_HEIGHT
*(filename_offset
[i
] +
1678 PM_HEIGHT
+ 3), buf
);
1681 snprintf(buf
, sizeof(buf
), "%s:%s",
1682 str(LANG_SYSFONT_RECORDING_RIGHT
),
1683 fmt_gain(SOUND_RIGHT_GAIN
,
1684 global_settings
.rec_right_gain
,
1685 buf2
, sizeof(buf2
)));
1686 #ifdef HAVE_LCD_COLOR
1687 /* special action for gradient - double line gradient - line2 */
1688 if((global_settings
.cursor_style
== 3) &&
1690 style
= base_style
| CURLN_PACK(1) | NUMLN_PACK(2);
1691 #endif /* HAVE_LCD_COLOR */
1692 if(global_settings
.cursor_style
&& ((1==cursor
)||(3==cursor
)))
1694 for(i
= 0; i
< screen_update
; i
++)
1695 screens
[i
].puts_style_offset(0, filename_offset
[i
] +
1696 PM_HEIGHT
+ 4, buf
, style
,0);
1700 for(i
= 0; i
< screen_update
; i
++)
1701 screens
[i
].putsxy(ymargin
,
1702 SYSFONT_HEIGHT
*(filename_offset
[i
] +
1703 PM_HEIGHT
+ 4), buf
);
1706 #ifdef HAVE_LCD_COLOR
1707 /* special action for gradient - back to single line gradient */
1708 if(global_settings
.cursor_style
== 3)
1709 style
= base_style
| CURLN_PACK(0) | NUMLN_PACK(1);
1710 #endif /* HAVE_LCD_COLOR */
1714 switch (global_settings
.rec_source
)
1716 HAVE_LINE_REC_(case AUDIO_SRC_LINEIN
:)
1717 HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO
:)
1724 #ifdef HAVE_SPDIF_REC
1725 case AUDIO_SRC_SPDIF
:
1730 line
[i
] = 5; /* to prevent uninitialisation
1731 warnings for line[0] */
1735 if (vp
[i
].height
< h
* (2 + filename_offset
[i
] +
1736 PM_HEIGHT
+ line
[i
]))
1739 display_agc
[i
] = false;
1742 display_agc
[i
] = true;
1744 if ((cursor
==4) || (cursor
==5))
1745 display_agc
[i
] = true;
1748 /************** AGC test info ******************
1749 snprintf(buf, sizeof(buf), "D:%d U:%d",
1750 (agc_droptime+2)/5, (agc_risetime+2)/5);
1751 lcd_putsxy(1, LCD_HEIGHT - 8, buf);
1752 snprintf(buf, sizeof(buf), "B:%d",
1754 lcd_putsxy(LCD_WIDTH/2 + 3, LCD_HEIGHT - 8, buf);
1755 ***********************************************/
1758 snprintf(buf
, sizeof(buf
), "%s: %s",
1759 str(LANG_SYSFONT_RECORDING_AGC_MAXGAIN
),
1760 fmt_gain(SOUND_LEFT_GAIN
,
1761 agc_maxgain
, buf2
, sizeof(buf2
)));
1762 else if (agc_preset
== 0)
1763 snprintf(buf
, sizeof(buf
), "%s: %s",
1764 str(LANG_SYSFONT_RECORDING_AGC_PRESET
),
1765 agc_preset_str
[agc_preset
]);
1766 else if (global_settings
.rec_source
== AUDIO_SRC_MIC
)
1767 snprintf(buf
, sizeof(buf
), "%s: %s%s",
1768 str(LANG_SYSFONT_RECORDING_AGC_PRESET
),
1769 agc_preset_str
[agc_preset
],
1770 fmt_gain(SOUND_LEFT_GAIN
,
1772 global_settings
.rec_mic_gain
,
1773 buf2
, sizeof(buf2
)));
1775 snprintf(buf
, sizeof(buf
), "%s: %s%s",
1776 str(LANG_SYSFONT_RECORDING_AGC_PRESET
),
1777 agc_preset_str
[agc_preset
],
1778 fmt_gain(SOUND_LEFT_GAIN
,
1780 (global_settings
.rec_left_gain
+
1781 global_settings
.rec_right_gain
)/2,
1782 buf2
, sizeof(buf2
)));
1784 if(global_settings
.cursor_style
&& ((cursor
==4) || (cursor
==5)))
1786 for(i
= 0; i
< screen_update
; i
++)
1787 screens
[i
].puts_style_offset(0, filename_offset
[i
] +
1788 PM_HEIGHT
+ line
[i
], buf
, style
,0);
1790 else if (global_settings
.rec_source
== AUDIO_SRC_MIC
1791 HAVE_LINE_REC_(|| global_settings
.rec_source
==
1793 HAVE_FMRADIO_REC_(|| global_settings
.rec_source
==
1797 for(i
= 0; i
< screen_update
; i
++) {
1798 if (display_agc
[i
]) {
1799 screens
[i
].putsxy(ymargin
,
1800 SYSFONT_HEIGHT
*(filename_offset
[i
] +
1801 PM_HEIGHT
+ line
[i
]), buf
);
1806 if (global_settings
.rec_source
== AUDIO_SRC_MIC
)
1808 if(agc_maxgain
< (global_settings
.rec_mic_gain
))
1809 change_recording_gain(false, true, true);
1813 if(agc_maxgain
< (global_settings
.rec_left_gain
))
1814 change_recording_gain(false, true, false);
1815 if(agc_maxgain
< (global_settings
.rec_right_gain
))
1816 change_recording_gain(false, false, true);
1818 #else /* !HAVE_AGC */
1820 #endif /* HAVE_AGC */
1822 if(!global_settings
.cursor_style
) {
1826 for(i
= 0; i
< screen_update
; i
++)
1827 screen_put_cursorxy(&screens
[i
], 0,
1828 filename_offset
[i
] +
1829 PM_HEIGHT
+ 3, true);
1831 if(global_settings
.rec_source
!= AUDIO_SRC_MIC
)
1833 for(i
= 0; i
< screen_update
; i
++)
1834 screen_put_cursorxy(&screens
[i
], 0,
1835 filename_offset
[i
] +
1836 PM_HEIGHT
+ 4, true);
1840 for(i
= 0; i
< screen_update
; i
++)
1841 screen_put_cursorxy(&screens
[i
], 0,
1842 filename_offset
[i
] +
1843 PM_HEIGHT
+ 3, true);
1846 for(i
= 0; i
< screen_update
; i
++)
1847 screen_put_cursorxy(&screens
[i
], 0,
1848 filename_offset
[i
] +
1849 PM_HEIGHT
+ 4, true);
1854 for(i
= 0; i
< screen_update
; i
++)
1855 screen_put_cursorxy(&screens
[i
], 0,
1856 filename_offset
[i
] +
1857 PM_HEIGHT
+ line
[i
], true);
1859 #endif /* HAVE_AGC */
1861 for(i
= 0; i
< screen_update
; i
++)
1862 screen_put_cursorxy(&screens
[i
], 0,
1863 filename_offset
[i
] +
1864 PM_HEIGHT
+ 2, true);
1872 for(i
= 0; i
< screen_update
; i
++)
1874 screens
[i
].set_viewport(NULL
);
1875 gui_statusbar_draw(&(statusbars
.statusbars
[i
]), true);
1876 screens
[i
].set_viewport(&vp
[i
]);
1877 peak_meter_screen(&screens
[i
], pm_x
, pm_y
[i
], h
*PM_HEIGHT
);
1878 screens
[i
].update();
1881 /* draw the trigger status */
1884 /* NOTE: UGLY width setting based on height! To be fixed! */
1885 trig_width
[i
] = ((vp
[i
].height
< 64) ||
1886 ((vp
[i
].height
< 72) && (PM_HEIGHT
> 1))) ?
1887 screens
[i
].getwidth() - 14 * w
:
1888 screens
[i
].getwidth();
1889 trig_xpos
[i
] = screens
[i
].getwidth() - trig_width
[i
];
1890 trig_ypos
[i
] = ((vp
[i
].height
< 72) && (PM_HEIGHT
> 1)) ?
1892 h
*(1 + filename_offset
[i
] + PM_HEIGHT
+
1900 if (peak_meter_trigger_status() != TRIG_OFF
)
1902 peak_meter_draw_trig(trig_xpos
, trig_ypos
, trig_width
,
1904 for(i
= 0; i
< screen_update
; i
++){
1905 screens
[i
].update_rect(trig_xpos
[i
], trig_ypos
[i
],
1906 trig_width
[i
] + 2, TRIG_HEIGHT
);
1911 if(audio_stat
& AUDIO_STATUS_ERROR
)
1915 } /* end while(!done) */
1917 audio_stat
= audio_status();
1918 if (audio_stat
& AUDIO_STATUS_ERROR
)
1920 gui_syncsplash(0, str(LANG_SYSFONT_DISK_FULL
));
1921 gui_syncstatusbar_draw(&statusbars
, true);
1924 screens
[i
].update();
1926 #if CONFIG_CODEC == SWCODEC
1927 /* stop recording - some players like H10 freeze otherwise
1928 TO DO: find out why it freezes and fix properly */
1929 rec_command(RECORDING_CMD_STOP
);
1930 audio_close_recording();
1933 audio_error_clear();
1937 if (action_userabort(TIMEOUT_NOBLOCK
))
1944 #if CONFIG_CODEC == SWCODEC
1945 rec_command(RECORDING_CMD_STOP
);
1946 audio_close_recording();
1948 #ifdef HAVE_FMRADIO_REC
1949 if (radio_status
!= FMRADIO_OFF
)
1950 /* Restore radio playback - radio_status should be unchanged if started
1951 through fm radio screen (barring usb connect) */
1952 rec_set_source(AUDIO_SRC_FMRADIO
, (radio_status
& FMRADIO_PAUSED
) ?
1953 SRCF_FMRADIO_PAUSED
: SRCF_FMRADIO_PLAYING
);
1956 /* Go back to playback mode */
1957 rec_set_source(AUDIO_SRC_PLAYBACK
, SRCF_PLAYBACK
);
1959 /* restore talking */
1960 talk_disable(false);
1961 #else /* !SWCODEC */
1962 audio_init_playback();
1963 #endif /* CONFIG_CODEC == SWCODEC */
1965 /* make sure the trigger is really turned off */
1966 peak_meter_trigger(false);
1967 peak_meter_set_trigger_listener(NULL
);
1969 rec_status
&= ~RCSTAT_IN_RECSCREEN
;
1970 sound_settings_apply();
1973 screens
[i
].setfont(FONT_UI
);
1975 /* if the directory was created or recording happened, make sure the
1976 browser is updated */
1977 if (rec_status
& (RCSTAT_CREATED_DIRECTORY
| RCSTAT_HAVE_RECORDED
))
1980 #if (CONFIG_LED == LED_REAL) && !defined(SIMULATOR)
1981 ata_set_led_enabled(true);
1986 return (rec_status
& RCSTAT_BEEN_IN_USB_MODE
) != 0;
1987 } /* recording_screen */
1989 #if CONFIG_KEYPAD == RECORDER_PAD
1990 static bool f2_rec_screen(void)
1992 static const char* const freq_str
[6] =
2007 struct audio_recording_options rec_options
;
2011 screens
[i
].setfont(FONT_SYSFIXED
);
2012 screens
[i
].getstringsize("A",&w
,&h
);
2016 const char* ptr
=NULL
;
2020 screens
[i
].clear_display();
2022 /* Recording quality */
2023 screens
[i
].putsxy(0, LCD_HEIGHT
/2 - h
*2,
2024 str(LANG_SYSFONT_RECORDING_QUALITY
));
2027 snprintf(buf
, sizeof(buf
), "%d", global_settings
.rec_quality
);
2030 screens
[i
].putsxy(0, LCD_HEIGHT
/2-h
, buf
);
2031 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_FastBackward
],
2032 LCD_WIDTH
/2 - 16, LCD_HEIGHT
/2 - 4, 7, 8);
2036 snprintf(buf
, sizeof buf
, "%s:", str(LANG_SYSFONT_RECORDING_FREQUENCY
));
2037 ptr
= freq_str
[global_settings
.rec_frequency
];
2040 screens
[i
].getstringsize(buf
,&w
,&h
);
2041 screens
[i
].putsxy((LCD_WIDTH
-w
)/2, LCD_HEIGHT
- h
*2, buf
);
2042 screens
[i
].getstringsize(ptr
, &w
, &h
);
2043 screens
[i
].putsxy((LCD_WIDTH
-w
)/2, LCD_HEIGHT
- h
, ptr
);
2044 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_DownArrow
],
2045 LCD_WIDTH
/2 - 3, LCD_HEIGHT
- h
*3, 7, 8);
2049 switch ( global_settings
.rec_channels
) {
2051 ptr
= str(LANG_SYSFONT_CHANNEL_STEREO
);
2055 ptr
= str(LANG_SYSFONT_CHANNEL_MONO
);
2061 screens
[i
].getstringsize(str(LANG_SYSFONT_CHANNELS
), &w
, &h
);
2062 screens
[i
].putsxy(LCD_WIDTH
- w
, LCD_HEIGHT
/2 - h
*2,
2063 str(LANG_SYSFONT_CHANNELS
));
2064 screens
[i
].getstringsize(str(LANG_SYSFONT_MODE
), &w
, &h
);
2065 screens
[i
].putsxy(LCD_WIDTH
- w
, LCD_HEIGHT
/2 - h
,
2066 str(LANG_SYSFONT_MODE
));
2067 screens
[i
].getstringsize(ptr
, &w
, &h
);
2068 screens
[i
].putsxy(LCD_WIDTH
- w
, LCD_HEIGHT
/2, ptr
);
2069 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_FastForward
],
2070 LCD_WIDTH
/2 + 8, LCD_HEIGHT
/2 - 4, 7, 8);
2072 screens
[i
].update();
2075 button
= button_get(true);
2078 case BUTTON_F2
| BUTTON_LEFT
:
2079 global_settings
.rec_quality
++;
2080 if(global_settings
.rec_quality
> 7)
2081 global_settings
.rec_quality
= 0;
2086 case BUTTON_F2
| BUTTON_DOWN
:
2087 global_settings
.rec_frequency
++;
2088 if(global_settings
.rec_frequency
> 5)
2089 global_settings
.rec_frequency
= 0;
2094 case BUTTON_F2
| BUTTON_RIGHT
:
2095 global_settings
.rec_channels
++;
2096 if(global_settings
.rec_channels
> 1)
2097 global_settings
.rec_channels
= 0;
2101 case BUTTON_F2
| BUTTON_REL
:
2107 case BUTTON_F2
| BUTTON_REPEAT
:
2112 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
2118 rec_init_recording_options(&rec_options
);
2119 rec_set_recording_options(&rec_options
);
2125 screens
[i
].setfont(FONT_UI
);
2130 static bool f3_rec_screen(void)
2138 str(LANG_SYSFONT_RECORDING_SRC_MIC
),
2139 str(LANG_SYSFONT_LINE_IN
),
2140 str(LANG_SYSFONT_RECORDING_SRC_DIGITAL
)
2142 struct audio_recording_options rec_options
;
2146 screens
[i
].setfont(FONT_SYSFIXED
);
2147 screens
[i
].getstringsize("A",&w
,&h
);
2152 ptr
= src_str
[global_settings
.rec_source
];
2155 screens
[i
].clear_display();
2157 /* Recording source */
2158 screens
[i
].putsxy(0, LCD_HEIGHT
/2 - h
*2,
2159 str(LANG_SYSFONT_RECORDING_SOURCE
));
2161 screens
[i
].getstringsize(ptr
, &w
, &h
);
2162 screens
[i
].putsxy(0, LCD_HEIGHT
/2-h
, ptr
);
2163 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_FastBackward
],
2164 LCD_WIDTH
/2 - 16, LCD_HEIGHT
/2 - 4, 7, 8);
2168 ptr
= str(LANG_SYSFONT_RECORD_TRIGGER
);
2171 screens
[i
].getstringsize(ptr
,&w
,&h
);
2172 screens
[i
].putsxy((LCD_WIDTH
-w
)/2, LCD_HEIGHT
- h
*2, ptr
);
2173 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_DownArrow
],
2174 LCD_WIDTH
/2 - 3, LCD_HEIGHT
- h
*3, 7, 8);
2176 screens
[i
].update();
2179 button
= button_get(true);
2182 case BUTTON_F3
| BUTTON_DOWN
:
2185 settings_apply_trigger();
2191 case BUTTON_F3
| BUTTON_LEFT
:
2192 global_settings
.rec_source
++;
2193 if(global_settings
.rec_source
> AUDIO_SRC_MAX
)
2194 global_settings
.rec_source
= 0;
2198 case BUTTON_F3
| BUTTON_REL
:
2204 case BUTTON_F3
| BUTTON_REPEAT
:
2209 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
2215 rec_init_recording_options(&rec_options
);
2216 rec_set_recording_options(&rec_options
);
2222 screens
[i
].setfont(FONT_UI
);
2226 #endif /* CONFIG_KEYPAD == RECORDER_PAD */
2228 #if CONFIG_CODEC == SWCODEC
2229 void audio_beep(int duration
)
2236 /* stubs for recording sim */
2237 void audio_init_recording(unsigned int buffer_offset
)
2239 buffer_offset
= buffer_offset
;
2242 void audio_close_recording(void)
2246 unsigned long pcm_rec_get_warnings(void)
2251 unsigned long audio_recorded_time(void)
2256 unsigned long audio_num_recorded_bytes(void)
2258 return 5 * 1024 * 1024;
2261 void rec_set_source(int source
, unsigned flags
)
2267 void audio_set_recording_options(struct audio_recording_options
*options
)
2272 void audio_set_recording_gain(int left
, int right
, int type
)
2279 void audio_record(const char *filename
)
2281 filename
= filename
;
2284 void audio_new_file(const char *filename
)
2286 filename
= filename
;
2289 void audio_stop_recording(void)
2293 void audio_pause_recording(void)
2297 void audio_resume_recording(void)
2301 #endif /* #ifdef SIMULATOR */
2302 #endif /* #ifdef CONFIG_CODEC == SWCODEC */
2304 #endif /* HAVE_RECORDING */