1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 by Linus Nielsen Feltzing
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
28 #include "powermgmt.h"
33 #if CONFIG_CODEC == SWCODEC
36 #include "enc_config.h"
37 #if defined(HAVE_SPDIF_IN) || defined(HAVE_SPDIF_OUT)
40 #endif /* CONFIG_CODEC == SWCODEC */
41 #include "recording.h"
42 #include "mp3_playback.h"
52 #include "peakmeter.h"
53 #include "statusbar.h"
55 #include "sound_menu.h"
56 #include "timefuncs.h"
67 #include "screen_access.h"
70 #include "sound_menu.h"
73 /* This array holds the record timer interval lengths, in seconds */
74 static const unsigned long rec_timer_seconds
[] =
88 10L*60*60, /* 10:00 */
89 12L*60*60, /* 12:00 */
90 18L*60*60, /* 18:00 */
94 static unsigned int rec_timesplit_seconds(void)
96 return rec_timer_seconds
[global_settings
.rec_timesplit
];
99 /* This array holds the record size interval lengths, in bytes */
100 static const unsigned long rec_size_bytes
[] =
103 5*1024*1024, /* 5MB */
104 10*1024*1024, /* 10MB */
105 15*1024*1024, /* 15MB */
106 32*1024*1024, /* 32MB */
107 64*1024*1024, /* 64MB */
108 75*1024*1024, /* 75MB */
109 100*1024*1024, /* 100MB */
110 128*1024*1024, /* 128MB */
111 256*1024*1024, /* 256MB */
112 512*1024*1024, /* 512MB */
113 650*1024*1024, /* 650MB */
114 700*1024*1024, /* 700MB */
115 1024*1024*1024, /* 1GB */
116 1536*1024*1024, /* 1.5GB */
117 1792*1024*1024, /* 1.75GB */
120 static unsigned long rec_sizesplit_bytes(void)
122 return rec_size_bytes
[global_settings
.rec_sizesplit
];
125 * Time strings used for the trigger durations.
126 * Keep synchronous to trigger_times in settings_apply_trigger
128 const struct opt_items trig_durations
[TRIG_DURATION_COUNT
] =
130 #define TS(x) { (unsigned char *)(#x "s"), TALK_ID(x, UNIT_SEC) }
131 #define TM(x) { (unsigned char *)(#x "min"), TALK_ID(x, UNIT_MIN) }
132 TS(0), TS(1), TS(2), TS(5),
133 TS(10), TS(15), TS(20), TS(25), TS(30),
134 TM(1), TM(2), TM(5), TM(10)
139 void settings_apply_trigger(void)
141 /* Keep synchronous to trig_durations and trig_durations_conf*/
142 static const long trigger_times
[TRIG_DURATION_COUNT
] = {
144 10*HZ
, 15*HZ
, 20*HZ
, 25*HZ
, 30*HZ
,
145 60*HZ
, 2*60*HZ
, 5*60*HZ
, 10*60*HZ
148 peak_meter_define_trigger(
149 global_settings
.rec_start_thres
,
150 trigger_times
[global_settings
.rec_start_duration
],
151 MIN(trigger_times
[global_settings
.rec_start_duration
] / 2, 2*HZ
),
152 global_settings
.rec_stop_thres
,
153 trigger_times
[global_settings
.rec_stop_postrec
],
154 trigger_times
[global_settings
.rec_stop_gap
]
157 /* recording screen status flags */
158 enum rec_status_flags
160 RCSTAT_IN_RECSCREEN
= 0x00000001,
161 RCSTAT_BEEN_IN_USB_MODE
= 0x00000002,
162 RCSTAT_CREATED_DIRECTORY
= 0x00000004,
163 RCSTAT_HAVE_RECORDED
= 0x00000008,
166 static int rec_status
= 0;
168 bool in_recording_screen(void)
170 return (rec_status
& RCSTAT_IN_RECSCREEN
) != 0;
173 #define PM_HEIGHT ((LCD_HEIGHT >= 72) ? 2 : 1)
175 #if CONFIG_KEYPAD == RECORDER_PAD
176 static bool f2_rec_screen(void);
177 static bool f3_rec_screen(void);
180 #define MAX_FILE_SIZE 0x7F800000 /* 2 GB - 4 MB */
182 #ifndef HAVE_REMOTE_LCD
183 static const int screen_update
= NB_SCREENS
;
185 static int screen_update
= NB_SCREENS
;
186 static bool remote_display_on
= true;
189 /** File name creation **/
191 /* current file number to assist in creating unique numbered filenames
192 without actually having to create the file on disk */
193 static int file_number
= -1;
194 #endif /* CONFIG_RTC */
196 #if CONFIG_CODEC == SWCODEC
198 #define REC_FILE_ENDING(rec_format) \
199 (audio_formats[rec_format_afmt[rec_format]].ext_list)
201 #else /* CONFIG_CODEC != SWCODEC */
203 /* default record file extension for HWCODEC */
204 #define REC_FILE_ENDING(rec_format) \
205 (audio_formats[AFMT_MPA_L3].ext_list)
207 #endif /* CONFIG_CODEC == SWCODEC */
209 /* path for current file */
210 static char path_buffer
[MAX_PATH
];
212 /** Automatic Gain Control (AGC) **/
215 * peak_time is incremented every 0.2s, every 2nd run of record screen loop.
216 * hist_time is incremented every 0.5s, display update.
217 * peak_time is the counter of the peak hold read and agc process,
218 * overflow every 13 years 8-)
220 static long peak_time
= 0;
221 static long hist_time
= 0;
223 static short peak_valid_mem
[4];
224 #define BAL_MEM_SIZE 24
225 static short balance_mem
[BAL_MEM_SIZE
];
227 /* Automatic Gain Control */
228 #define AGC_MODE_SIZE 5
229 #define AGC_SAFETY_MODE 0
231 static const char* agc_preset_str
[] =
232 { "Off", "S", "L", "D", "M", "V" };
239 #define AGC_CLIP 32766
240 #define AGC_PEAK 29883 /* fast gain reduction threshold -0.8dB */
241 #define AGC_HIGH 27254 /* accelerated gain reduction threshold -1.6dB */
242 #define AGC_IMG 823 /* threshold for balance control -32dB */
243 /* autogain high level thresholds (-3dB, -7dB, -4dB, -5dB, -5dB) */
244 static const short agc_th_hi
[AGC_MODE_SIZE
] =
245 { 23197, 14637, 21156, 18428, 18426 };
246 /* autogain low level thresholds (-14dB, -11dB, -6dB, -7dB, -8dB) */
247 static const short agc_th_lo
[AGC_MODE_SIZE
] =
248 { 6538, 9235, 16422, 14636, 13045 };
249 /* autogain threshold times [1/5s] or [200ms] */
250 static const short agc_tdrop
[AGC_MODE_SIZE
] =
251 { 900, 225, 150, 60, 8 };
252 static const short agc_trise
[AGC_MODE_SIZE
] =
253 { 9000, 750, 400, 150, 20 };
254 static const short agc_tbal
[AGC_MODE_SIZE
] =
255 { 4500, 500, 300, 100, 15 };
257 static bool agc_enable
= true;
258 static short agc_preset
;
260 static int agc_left
= 0;
261 static int agc_right
= 0;
262 /* AGC time since high target volume was exceeded */
263 static short agc_droptime
= 0;
264 /* AGC time since volume fallen below low target */
265 static short agc_risetime
= 0;
266 /* AGC balance time exceeding +/- 0.7dB */
267 static short agc_baltime
= 0;
268 /* AGC maximum gain */
269 static short agc_maxgain
;
270 #endif /* HAVE_AGC */
272 static void set_gain(void)
274 if(global_settings
.rec_source
== AUDIO_SRC_MIC
)
276 audio_set_recording_gain(global_settings
.rec_mic_gain
,
281 /* AUDIO_SRC_LINEIN, AUDIO_SRC_FMRADIO, AUDIO_SRC_SPDIF */
282 audio_set_recording_gain(global_settings
.rec_left_gain
,
283 global_settings
.rec_right_gain
,
286 /* reset the clipping indicators */
287 peak_meter_set_clip_hold(global_settings
.peak_meter_clip_hold
);
291 /* Read peak meter values & calculate balance.
292 * Returns validity of peak values.
293 * Used for automatic gain control and history diagram.
295 static bool read_peak_levels(int *peak_l
, int *peak_r
, int *balance
)
297 peak_meter_get_peakhold(peak_l
, peak_r
);
298 peak_valid_mem
[peak_time
% 3] = *peak_l
;
299 if (((peak_valid_mem
[0] == peak_valid_mem
[1]) &&
300 (peak_valid_mem
[1] == peak_valid_mem
[2])) &&
303 || ata_disk_is_active()
308 if (*peak_r
> *peak_l
)
309 balance_mem
[peak_time
% BAL_MEM_SIZE
] = (*peak_l
?
310 MIN((10000 * *peak_r
) / *peak_l
- 10000, 15118) : 15118);
312 balance_mem
[peak_time
% BAL_MEM_SIZE
] = (*peak_r
?
313 MAX(10000 - (10000 * *peak_l
) / *peak_r
, -15118) : -15118);
316 for (i
= 0; i
< BAL_MEM_SIZE
; i
++)
317 *balance
+= balance_mem
[i
];
318 *balance
= *balance
/ BAL_MEM_SIZE
;
323 /* AGC helper function to check if maximum gain is reached */
324 static bool agc_gain_is_max(bool left
, bool right
)
326 /* range -128...+108 [0.5dB] */
327 short gain_current_l
;
328 short gain_current_r
;
333 switch (global_settings
.rec_source
)
335 HAVE_LINE_REC_(case AUDIO_SRC_LINEIN
:)
336 HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO
:)
337 gain_current_l
= global_settings
.rec_left_gain
;
338 gain_current_r
= global_settings
.rec_right_gain
;
342 gain_current_l
= global_settings
.rec_mic_gain
;
343 gain_current_r
= global_settings
.rec_mic_gain
;
346 return ((left
&& (gain_current_l
>= agc_maxgain
)) ||
347 (right
&& (gain_current_r
>= agc_maxgain
)));
350 static void change_recording_gain(bool increment
, bool left
, bool right
)
352 int factor
= (increment
? 1 : -1);
354 switch (global_settings
.rec_source
)
356 HAVE_LINE_REC_(case AUDIO_SRC_LINEIN
:)
357 HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO
:)
358 if (left
) global_settings
.rec_left_gain
+= factor
;
359 if (right
) global_settings
.rec_right_gain
+= factor
;
362 global_settings
.rec_mic_gain
+= factor
;
367 * Handle automatic gain control (AGC).
368 * Change recording gain if peak_x levels are above or below
369 * target volume for specified timeouts.
371 static void auto_gain_control(int *peak_l
, int *peak_r
, int *balance
)
377 if (*peak_l
> agc_left
)
380 agc_left
-= (agc_left
- *peak_l
+ 3) >> 2;
381 if (*peak_r
> agc_right
)
384 agc_right
-= (agc_right
- *peak_r
+ 3) >> 2;
385 agc_mono
= (agc_left
+ agc_right
) / 2;
387 agc_mode
= abs(agc_preset
) - 1;
393 if (agc_mode
!= AGC_SAFETY_MODE
) {
394 /* Automatic balance control - only if not in safety mode */
395 if ((agc_left
> AGC_IMG
) && (agc_right
> AGC_IMG
))
400 agc_baltime
-= !(peak_time
% 4); /* 0.47 - 0.75dB */
401 else if (*balance
> -4125)
402 agc_baltime
--; /* 0.75 - 3.00dB */
403 else if (*balance
> -7579)
404 agc_baltime
-= 2; /* 3.00 - 4.90dB */
406 agc_baltime
-= !(peak_time
% 8); /* 4.90 - inf dB */
408 agc_baltime
-= (peak_time
% 2);
410 else if (*balance
> 556)
413 agc_baltime
+= !(peak_time
% 4);
414 else if (*balance
< 4125)
416 else if (*balance
< 7579)
419 agc_baltime
+= !(peak_time
% 8);
421 agc_baltime
+= (peak_time
% 2);
424 if ((*balance
* agc_baltime
) < 0)
427 agc_baltime
-= peak_time
% 2;
429 agc_baltime
+= peak_time
% 2;
432 increment
= ((agc_risetime
/ 2) > agc_droptime
);
434 if (agc_baltime
< -agc_tbal
[agc_mode
])
436 if (!increment
|| !agc_gain_is_max(!increment
, increment
)) {
437 change_recording_gain(increment
, !increment
, increment
);
442 else if (agc_baltime
> +agc_tbal
[agc_mode
])
444 if (!increment
|| !agc_gain_is_max(increment
, !increment
)) {
445 change_recording_gain(increment
, increment
, !increment
);
451 else if (!(hist_time
% 4))
460 /* Automatic gain control */
461 if ((agc_left
> agc_th_hi
[agc_mode
]) || (agc_right
> agc_th_hi
[agc_mode
]))
463 if ((agc_left
> AGC_CLIP
) || (agc_right
> AGC_CLIP
))
464 agc_droptime
+= agc_tdrop
[agc_mode
] /
465 (global_settings
.rec_agc_cliptime
+ 1);
466 if (agc_left
> AGC_HIGH
) {
469 if (agc_left
> AGC_PEAK
)
472 if (agc_right
> AGC_HIGH
) {
475 if (agc_right
> AGC_PEAK
)
478 if (agc_mono
> agc_th_hi
[agc_mode
])
481 agc_droptime
+= !(peak_time
% 2);
483 if (agc_droptime
>= agc_tdrop
[agc_mode
])
485 change_recording_gain(false, true, true);
490 agc_risetime
= MAX(agc_risetime
- 1, 0);
492 else if (agc_mono
< agc_th_lo
[agc_mode
])
494 if (agc_mono
< (agc_th_lo
[agc_mode
] / 8))
495 agc_risetime
+= !(peak_time
% 5);
496 else if (agc_mono
< (agc_th_lo
[agc_mode
] / 2))
501 if (agc_risetime
>= agc_trise
[agc_mode
]) {
502 if ((agc_mode
!= AGC_SAFETY_MODE
) &&
503 (!agc_gain_is_max(true, true))) {
504 change_recording_gain(true, true, true);
510 agc_droptime
= MAX(agc_droptime
- 1, 0);
512 else if (!(peak_time
% 6)) /* on target level every 1.2 sec */
514 agc_risetime
= MAX(agc_risetime
- 1, 0);
515 agc_droptime
= MAX(agc_droptime
- 1, 0);
518 #endif /* HAVE_AGC */
520 static const char* const fmtstr
[] =
522 "%c%d %s", /* no decimals */
523 "%c%d.%d %s ", /* 1 decimal */
524 "%c%d.%02d %s " /* 2 decimals */
527 static char *fmt_gain(int snd
, int val
, char *str
, int len
)
533 val
= sound_val2phys(snd
, val
);
539 numdec
= sound_numdecimals(snd
);
540 unit
= sound_unit(snd
);
544 i
= val
/ (10*numdec
);
545 d
= val
% (10*numdec
);
546 snprintf(str
, len
, fmtstr
[numdec
], sign
, i
, d
, unit
);
549 snprintf(str
, len
, fmtstr
[numdec
], sign
, val
, unit
);
556 static void adjust_cursor(void)
564 switch(global_settings
.rec_source
)
571 HAVE_LINE_REC_(case AUDIO_SRC_LINEIN
:)
572 HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO
:)
579 #else /* !HAVE_AGC */
580 switch(global_settings
.rec_source
)
585 HAVE_LINE_REC_(case AUDIO_SRC_LINEIN
:)
586 HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO
:)
593 #endif /* HAVE_AGC */
595 if(cursor
> max_cursor
)
599 /* the list below must match enum audio_sources in audio.h */
600 static const char* const prestr
[] =
602 HAVE_MIC_IN_([AUDIO_SRC_MIC
] = "R_MIC_",)
603 HAVE_LINE_REC_([AUDIO_SRC_LINEIN
] = "R_LINE_",)
604 HAVE_SPDIF_IN_([AUDIO_SRC_SPDIF
] = "R_SPDIF_",)
605 HAVE_FMRADIO_REC_([AUDIO_SRC_FMRADIO
] = "R_FM_",)
608 char *rec_create_filename(char *buffer
)
611 const char *pref
= "R_";
613 /* Directory existence and writeablility should have already been
614 * verified - do not pass NULL pointers to pcmrec */
616 if((unsigned)global_settings
.rec_source
< AUDIO_NUM_SOURCES
)
618 pref
= prestr
[global_settings
.rec_source
];
621 strcpy(buffer
, global_settings
.rec_directory
);
623 snprintf(ext
, sizeof(ext
), ".%s",
624 REC_FILE_ENDING(global_settings
.rec_format
));
627 return create_numbered_filename(buffer
, buffer
, pref
, ext
, 4,
630 /* We'll wait at least up to the start of the next second so no duplicate
632 return create_datetime_filename(buffer
, buffer
, pref
, ext
, true);
637 /* Hit disk to get a starting filename for the type */
638 static void rec_init_filename(void)
641 rec_create_filename(path_buffer
);
646 int rec_create_directory(void)
649 const char * const folder
= global_settings
.rec_directory
;
651 if (strcmp(folder
, "/") && !dir_exists(folder
))
657 while (action_userabort(HZ
) == false)
659 gui_syncsplash(0, "%s %s",
660 str(LANG_REC_DIR_NOT_WRITABLE
),
661 str(LANG_OFF_ABORT
));
666 rec_status
|= RCSTAT_CREATED_DIRECTORY
;
674 void rec_init_recording_options(struct audio_recording_options
*options
)
676 options
->rec_source
= global_settings
.rec_source
;
677 options
->rec_frequency
= global_settings
.rec_frequency
;
678 options
->rec_channels
= global_settings
.rec_channels
;
679 options
->rec_prerecord_time
= global_settings
.rec_prerecord_time
;
680 #if CONFIG_CODEC == SWCODEC
681 options
->rec_source_flags
= 0;
682 options
->enc_config
.rec_format
= global_settings
.rec_format
;
683 global_to_encoder_config(&options
->enc_config
);
685 options
->rec_quality
= global_settings
.rec_quality
;
686 options
->rec_editable
= global_settings
.rec_editable
;
690 #if CONFIG_CODEC == SWCODEC && !defined (SIMULATOR)
691 void rec_set_source(int source
, unsigned flags
)
693 /* Set audio input source, power up/down devices */
694 audio_set_input_source(source
, flags
);
696 /* Set peakmeters for recording or reset to playback */
697 peak_meter_playback((flags
& SRCF_RECORDING
) == 0);
698 peak_meter_enabled
= true;
700 #endif /* CONFIG_CODEC == SWCODEC && !defined (SIMULATOR) */
702 void rec_set_recording_options(struct audio_recording_options
*options
)
704 #if CONFIG_CODEC != SWCODEC
705 if (global_settings
.rec_prerecord_time
)
707 talk_buffer_steal(); /* will use the mp3 buffer */
709 #else /* == SWCODEC */
710 rec_set_source(options
->rec_source
,
711 options
->rec_source_flags
| SRCF_RECORDING
);
712 #endif /* CONFIG_CODEC != SWCODEC */
714 audio_set_recording_options(options
);
717 void rec_command(enum recording_command cmd
)
721 case RECORDING_CMD_STOP_SHUTDOWN
:
722 pm_activate_clipcount(false);
723 audio_stop_recording();
724 #if CONFIG_CODEC == SWCODEC
725 audio_close_recording();
729 case RECORDING_CMD_STOP
:
730 pm_activate_clipcount(false);
731 audio_stop_recording();
733 case RECORDING_CMD_START
:
734 /* steal mp3 buffer, create unique filename and start recording */
735 pm_reset_clipcount();
736 pm_activate_clipcount(true);
737 #if CONFIG_CODEC != SWCODEC
738 talk_buffer_steal(); /* we use the mp3 buffer */
740 audio_record(rec_create_filename(path_buffer
));
742 case RECORDING_CMD_START_NEWFILE
:
743 /* create unique filename and start recording*/
744 pm_reset_clipcount();
745 pm_activate_clipcount(true); /* just to be sure */
746 audio_new_file(rec_create_filename(path_buffer
));
748 case RECORDING_CMD_PAUSE
:
749 pm_activate_clipcount(false);
750 audio_pause_recording();
752 case RECORDING_CMD_RESUME
:
753 pm_activate_clipcount(true);
754 audio_resume_recording();
759 /* used in trigger_listerner and recording_screen */
760 static unsigned int last_seconds
= 0;
763 * Callback function so that the peak meter code can send an event
764 * to this application. This function can be passed to
765 * peak_meter_set_trigger_listener in order to activate the trigger.
767 static void trigger_listener(int trigger_status
)
769 switch (trigger_status
)
772 if(!(audio_status() & AUDIO_STATUS_RECORD
))
774 rec_status
|= RCSTAT_HAVE_RECORDED
;
775 rec_command(RECORDING_CMD_START
);
776 #if CONFIG_CODEC != SWCODEC
777 /* give control to mpeg thread so that it can start
779 yield(); yield(); yield();
783 /* if we're already recording this is a retrigger */
786 if((audio_status() & AUDIO_STATUS_PAUSE
) &&
787 (global_settings
.rec_trigger_type
== 1))
789 rec_command(RECORDING_CMD_RESUME
);
791 /* New file on trig start*/
792 else if (global_settings
.rec_trigger_type
!= 2)
794 rec_command(RECORDING_CMD_START_NEWFILE
);
795 /* tell recording_screen to reset the time */
801 /* A _change_ to TRIG_READY means the current recording has stopped */
803 if(audio_status() & AUDIO_STATUS_RECORD
)
805 switch(global_settings
.rec_trigger_type
)
808 rec_command(RECORDING_CMD_STOP
);
812 rec_command(RECORDING_CMD_PAUSE
);
815 case 2: /* New file on trig stop*/
816 rec_command(RECORDING_CMD_START_NEWFILE
);
817 /* tell recording_screen to reset the time */
821 case 3: /* Stop and shutdown */
822 rec_command(RECORDING_CMD_STOP_SHUTDOWN
);
826 if (global_settings
.rec_trigger_mode
!= TRIG_MODE_REARM
)
828 peak_meter_set_trigger_listener(NULL
);
829 peak_meter_trigger(false);
836 bool recording_start_automatic
= false;
838 bool recording_screen(bool no_source
)
845 int update_countdown
= 1;
846 unsigned int seconds
;
849 int last_audio_stat
= -1;
851 #if CONFIG_CODEC == SWCODEC
852 int warning_counter
= 0;
853 #define WARNING_PERIOD 7
855 #ifdef HAVE_FMRADIO_REC
856 /* Radio is left on if:
857 * 1) Is was on at the start and the initial source is FM Radio
858 * 2) 1) and the source was never changed to something else
860 int radio_status
= (global_settings
.rec_source
!= AUDIO_SRC_FMRADIO
) ?
861 FMRADIO_OFF
: get_radio_status();
863 #if (CONFIG_LED == LED_REAL)
864 bool led_state
= false;
865 int led_countdown
= 2;
868 bool peak_read
= false;
869 bool peak_valid
= false;
872 bool display_agc
[NB_SCREENS
];
874 int line
[NB_SCREENS
];
876 int filename_offset
[NB_SCREENS
];
877 int pm_y
[NB_SCREENS
];
878 int trig_xpos
[NB_SCREENS
];
879 int trig_ypos
[NB_SCREENS
];
880 int trig_width
[NB_SCREENS
];
881 /* pm_x = offset pm to put clipcount in front.
882 Use lcd_getstringsize() when not using SYSFONT */
883 int pm_x
= global_settings
.peak_meter_clipcounter
? 30 : 0;
885 static const unsigned char *byte_units
[] = {
892 int base_style
= STYLE_INVERT
;
894 #ifdef HAVE_LCD_COLOR
895 if (global_settings
.cursor_style
== 2) {
896 base_style
|= STYLE_COLORBAR
;
898 else if (global_settings
.cursor_style
== 3) {
899 base_style
|= STYLE_GRADIENT
;
903 struct audio_recording_options rec_options
;
904 rec_status
= RCSTAT_IN_RECSCREEN
;
906 if (rec_create_directory() < 0)
913 #if (CONFIG_LED == LED_REAL) && !defined(SIMULATOR)
914 ata_set_led_enabled(false);
917 #if CONFIG_CODEC == SWCODEC
918 /* recording_menu gets messed up: so prevent manus talking */
920 /* audio_init_recording stops anything playing when it takes the audio
923 /* Yes, we use the D/A for monitoring */
924 peak_meter_enabled
= true;
925 peak_meter_playback(true);
928 audio_init_recording(0);
929 sound_set_volume(global_settings
.volume
);
932 peak_meter_get_peakhold(&peak_l
, &peak_r
);
935 rec_init_recording_options(&rec_options
);
936 rec_set_recording_options(&rec_options
);
941 /* Create new filename for recording start */
945 pm_reset_clipcount();
946 pm_activate_clipcount(false);
947 settings_apply_trigger();
950 agc_preset_str
[0] = str(LANG_SYSFONT_OFF
);
951 agc_preset_str
[1] = str(LANG_SYSFONT_AGC_SAFETY
);
952 agc_preset_str
[2] = str(LANG_SYSFONT_AGC_LIVE
);
953 agc_preset_str
[3] = str(LANG_SYSFONT_AGC_DJSET
);
954 agc_preset_str
[4] = str(LANG_SYSFONT_AGC_MEDIUM
);
955 agc_preset_str
[5] = str(LANG_SYSFONT_AGC_VOICE
);
956 if (global_settings
.rec_source
== AUDIO_SRC_MIC
) {
957 agc_preset
= global_settings
.rec_agc_preset_mic
;
958 agc_maxgain
= global_settings
.rec_agc_maxgain_mic
;
961 agc_preset
= global_settings
.rec_agc_preset_line
;
962 agc_maxgain
= global_settings
.rec_agc_maxgain_line
;
964 #endif /* HAVE_AGC */
968 screens
[i
].setfont(FONT_SYSFIXED
);
969 screens
[i
].getstringsize("M", &w
, &h
);
970 screens
[i
].setmargins(global_settings
.cursor_style
? 0 : w
, 8);
971 filename_offset
[i
] = ((screens
[i
].height
>= 80) ? 1 : 0);
972 pm_y
[i
] = 8 + h
* (2 + filename_offset
[i
]);
975 #ifdef HAVE_REMOTE_LCD
976 if (!remote_display_on
)
978 screens
[1].clear_display();
979 snprintf(buf
, sizeof(buf
), str(LANG_REMOTE_LCD_ON
));
980 screens
[1].puts((screens
[1].width
/w
- strlen(buf
))/2 + 1,
981 screens
[1].height
/(h
*2) + 1, buf
);
983 gui_syncsplash(0, str(LANG_REMOTE_LCD_OFF
));
989 audio_stat
= audio_status();
991 #if (CONFIG_LED == LED_REAL)
994 * Flash the LED while waiting to record. Turn it on while
997 if(audio_stat
& AUDIO_STATUS_RECORD
)
999 if (audio_stat
& AUDIO_STATUS_PAUSE
)
1001 if (--led_countdown
<= 0)
1003 led_state
= !led_state
;
1010 /* trigger is on in status TRIG_READY (no check needed) */
1016 int trigStat
= peak_meter_trigger_status();
1018 * other trigger stati than trig_off and trig_steady
1019 * already imply that we are recording.
1021 if (trigStat
== TRIG_STEADY
)
1023 if (--led_countdown
<= 0)
1025 led_state
= !led_state
;
1032 /* trigger is on in status TRIG_READY (no check needed) */
1036 #endif /* CONFIG_LED */
1038 /* Wait for a button a while (HZ/10) drawing the peak meter */
1039 button
= peak_meter_draw_get_btn(pm_x
, pm_y
, h
* PM_HEIGHT
,
1042 if (last_audio_stat
!= audio_stat
)
1044 if (audio_stat
& AUDIO_STATUS_RECORD
)
1046 rec_status
|= RCSTAT_HAVE_RECORDED
;
1048 last_audio_stat
= audio_stat
;
1052 if (recording_start_automatic
)
1054 /* simulate a button press */
1055 button
= ACTION_REC_PAUSE
;
1056 recording_start_automatic
= false;
1061 #ifdef HAVE_REMOTE_LCD
1062 case ACTION_REC_LCD
:
1063 if (remote_display_on
)
1065 remote_display_on
= false;
1067 screens
[1].clear_display();
1068 snprintf(buf
, sizeof(buf
), str(LANG_REMOTE_LCD_ON
));
1069 screens
[1].puts((screens
[1].width
/w
- strlen(buf
))/2 + 1,
1070 screens
[1].height
/(h
*2) + 1, buf
);
1071 screens
[1].update();
1072 gui_syncsplash(0, str(LANG_REMOTE_LCD_OFF
));
1076 remote_display_on
= true;
1077 screen_update
= NB_SCREENS
;
1081 case ACTION_STD_CANCEL
:
1082 /* turn off the trigger */
1083 peak_meter_trigger(false);
1084 peak_meter_set_trigger_listener(NULL
);
1086 if(audio_stat
& AUDIO_STATUS_RECORD
)
1088 rec_command(RECORDING_CMD_STOP
);
1092 #if CONFIG_CODEC != SWCODEC
1093 peak_meter_playback(true);
1094 peak_meter_enabled
= false;
1098 update_countdown
= 1; /* Update immediately */
1101 case ACTION_REC_PAUSE
:
1102 case ACTION_REC_NEWFILE
:
1103 /* Only act if the mpeg is stopped */
1104 if(!(audio_stat
& AUDIO_STATUS_RECORD
))
1106 /* is this manual or triggered recording? */
1107 if ((global_settings
.rec_trigger_mode
== TRIG_MODE_OFF
) ||
1108 (peak_meter_trigger_status() != TRIG_OFF
))
1110 /* manual recording */
1111 rec_status
|= RCSTAT_HAVE_RECORDED
;
1112 rec_command(RECORDING_CMD_START
);
1114 if (global_settings
.talk_menu
)
1116 /* no voice possible here, but a beep */
1117 audio_beep(HZ
/2); /* longer beep on start */
1120 /* this is triggered recording */
1123 /* we don't start recording now, but enable the
1124 trigger and let the callback function
1125 trigger_listener control when the recording starts */
1126 peak_meter_trigger(true);
1127 peak_meter_set_trigger_listener(&trigger_listener
);
1132 /*if new file button pressed, start new file */
1133 if (button
== ACTION_REC_NEWFILE
)
1135 rec_command(RECORDING_CMD_START_NEWFILE
);
1139 /* if pause button pressed, pause or resume */
1141 if(audio_stat
& AUDIO_STATUS_PAUSE
)
1143 rec_command(RECORDING_CMD_RESUME
);
1144 if (global_settings
.talk_menu
)
1146 /* no voice possible here, but a beep */
1147 audio_beep(HZ
/4); /* short beep on resume */
1152 rec_command(RECORDING_CMD_PAUSE
);
1156 update_countdown
= 1; /* Update immediately */
1159 case ACTION_STD_PREV
:
1162 update_countdown
= 1; /* Update immediately */
1165 case ACTION_STD_NEXT
:
1168 update_countdown
= 1; /* Update immediately */
1171 case ACTION_SETTINGS_INC
:
1172 case ACTION_SETTINGS_INCREPEAT
:
1176 global_settings
.volume
++;
1180 if(global_settings
.rec_source
== AUDIO_SRC_MIC
)
1182 if(global_settings
.rec_mic_gain
<
1183 sound_max(SOUND_MIC_GAIN
))
1184 global_settings
.rec_mic_gain
++;
1188 if(global_settings
.rec_left_gain
<
1189 sound_max(SOUND_LEFT_GAIN
))
1190 global_settings
.rec_left_gain
++;
1191 if(global_settings
.rec_right_gain
<
1192 sound_max(SOUND_RIGHT_GAIN
))
1193 global_settings
.rec_right_gain
++;
1197 if(global_settings
.rec_left_gain
<
1198 sound_max(SOUND_LEFT_GAIN
))
1199 global_settings
.rec_left_gain
++;
1202 if(global_settings
.rec_right_gain
<
1203 sound_max(SOUND_RIGHT_GAIN
))
1204 global_settings
.rec_right_gain
++;
1208 agc_preset
= MIN(agc_preset
+ 1, AGC_MODE_SIZE
);
1209 agc_enable
= (agc_preset
!= 0);
1210 if (global_settings
.rec_source
== AUDIO_SRC_MIC
) {
1211 global_settings
.rec_agc_preset_mic
= agc_preset
;
1212 agc_maxgain
= global_settings
.rec_agc_maxgain_mic
;
1214 global_settings
.rec_agc_preset_line
= agc_preset
;
1215 agc_maxgain
= global_settings
.rec_agc_maxgain_line
;
1219 if (global_settings
.rec_source
== AUDIO_SRC_MIC
)
1221 agc_maxgain
= MIN(agc_maxgain
+ 1,
1222 sound_max(SOUND_MIC_GAIN
));
1223 global_settings
.rec_agc_maxgain_mic
= agc_maxgain
;
1227 agc_maxgain
= MIN(agc_maxgain
+ 1,
1228 sound_max(SOUND_LEFT_GAIN
));
1229 global_settings
.rec_agc_maxgain_line
= agc_maxgain
;
1232 #endif /* HAVE_AGC */
1235 update_countdown
= 1; /* Update immediately */
1238 case ACTION_SETTINGS_DEC
:
1239 case ACTION_SETTINGS_DECREPEAT
:
1243 global_settings
.volume
--;
1247 if(global_settings
.rec_source
== AUDIO_SRC_MIC
)
1249 if(global_settings
.rec_mic_gain
>
1250 sound_min(SOUND_MIC_GAIN
))
1251 global_settings
.rec_mic_gain
--;
1255 if(global_settings
.rec_left_gain
>
1256 sound_min(SOUND_LEFT_GAIN
))
1257 global_settings
.rec_left_gain
--;
1258 if(global_settings
.rec_right_gain
>
1259 sound_min(SOUND_RIGHT_GAIN
))
1260 global_settings
.rec_right_gain
--;
1264 if(global_settings
.rec_left_gain
>
1265 sound_min(SOUND_LEFT_GAIN
))
1266 global_settings
.rec_left_gain
--;
1269 if(global_settings
.rec_right_gain
>
1270 sound_min(SOUND_RIGHT_GAIN
))
1271 global_settings
.rec_right_gain
--;
1275 agc_preset
= MAX(agc_preset
- 1, 0);
1276 agc_enable
= (agc_preset
!= 0);
1277 if (global_settings
.rec_source
== AUDIO_SRC_MIC
) {
1278 global_settings
.rec_agc_preset_mic
= agc_preset
;
1279 agc_maxgain
= global_settings
.rec_agc_maxgain_mic
;
1281 global_settings
.rec_agc_preset_line
= agc_preset
;
1282 agc_maxgain
= global_settings
.rec_agc_maxgain_line
;
1286 if (global_settings
.rec_source
== AUDIO_SRC_MIC
)
1288 agc_maxgain
= MAX(agc_maxgain
- 1,
1289 sound_min(SOUND_MIC_GAIN
));
1290 global_settings
.rec_agc_maxgain_mic
= agc_maxgain
;
1294 agc_maxgain
= MAX(agc_maxgain
- 1,
1295 sound_min(SOUND_LEFT_GAIN
));
1296 global_settings
.rec_agc_maxgain_line
= agc_maxgain
;
1299 #endif /* HAVE_AGC */
1302 update_countdown
= 1; /* Update immediately */
1305 case ACTION_STD_MENU
:
1306 #if CONFIG_CODEC == SWCODEC
1307 if(!(audio_stat
& AUDIO_STATUS_RECORD
))
1309 if(audio_stat
!= AUDIO_STATUS_RECORD
)
1312 #ifdef HAVE_FMRADIO_REC
1313 const int prev_rec_source
= global_settings
.rec_source
;
1316 #if (CONFIG_LED == LED_REAL)
1317 /* led is restored at begin of loop / end of function */
1320 if (recording_menu(no_source
))
1323 rec_status
|= RCSTAT_BEEN_IN_USB_MODE
;
1324 #ifdef HAVE_FMRADIO_REC
1325 radio_status
= FMRADIO_OFF
;
1330 #ifdef HAVE_FMRADIO_REC
1331 /* If input changes away from FM Radio, radio will
1332 remain off when recording screen closes. */
1333 if (global_settings
.rec_source
!= prev_rec_source
1334 && prev_rec_source
== AUDIO_SRC_FMRADIO
)
1335 radio_status
= FMRADIO_OFF
;
1338 #if CONFIG_CODEC == SWCODEC
1339 /* reinit after submenu exit */
1340 audio_close_recording();
1341 audio_init_recording(0);
1344 rec_init_recording_options(&rec_options
);
1345 rec_set_recording_options(&rec_options
);
1347 if(rec_create_directory() < 0)
1352 #if CONFIG_CODEC == SWCODEC && CONFIG_RTC == 0
1353 /* If format changed, a new number is required */
1354 rec_init_filename();
1358 if (global_settings
.rec_source
== AUDIO_SRC_MIC
) {
1359 agc_preset
= global_settings
.rec_agc_preset_mic
;
1360 agc_maxgain
= global_settings
.rec_agc_maxgain_mic
;
1363 agc_preset
= global_settings
.rec_agc_preset_line
;
1364 agc_maxgain
= global_settings
.rec_agc_maxgain_line
;
1370 update_countdown
= 1; /* Update immediately */
1374 screens
[i
].setfont(FONT_SYSFIXED
);
1375 screens
[i
].setmargins(
1376 global_settings
.cursor_style
? 0 : w
, 8);
1382 #if CONFIG_KEYPAD == RECORDER_PAD
1384 if(audio_stat
!= AUDIO_STATUS_RECORD
)
1386 #if (CONFIG_LED == LED_REAL)
1387 /* led is restored at begin of loop / end of function */
1390 if (f2_rec_screen())
1392 rec_status
|= RCSTAT_HAVE_RECORDED
;
1396 update_countdown
= 1; /* Update immediately */
1401 if(audio_stat
& AUDIO_STATUS_RECORD
)
1403 rec_command(RECORDING_CMD_START_NEWFILE
);
1408 #if (CONFIG_LED == LED_REAL)
1409 /* led is restored at begin of loop / end of function */
1412 if (f3_rec_screen())
1414 rec_status
|= RCSTAT_HAVE_RECORDED
;
1418 update_countdown
= 1; /* Update immediately */
1421 #endif /* CONFIG_KEYPAD == RECORDER_PAD */
1423 case SYS_USB_CONNECTED
:
1424 /* Only accept USB connection when not recording */
1425 if(!(audio_stat
& AUDIO_STATUS_RECORD
))
1427 default_event_handler(SYS_USB_CONNECTED
);
1429 rec_status
|= RCSTAT_BEEN_IN_USB_MODE
;
1430 #ifdef HAVE_FMRADIO_REC
1431 radio_status
= FMRADIO_OFF
;
1437 default_event_handler(button
);
1442 peak_read
= !peak_read
;
1443 if (peak_read
) { /* every 2nd run of loop */
1445 peak_valid
= read_peak_levels(&peak_l
, &peak_r
, &balance
);
1448 /* Handle AGC every 200ms when enabled and peak data is valid */
1449 if (peak_read
&& agc_enable
&& peak_valid
)
1450 auto_gain_control(&peak_l
, &peak_r
, &balance
);
1454 screens
[i
].setfont(FONT_SYSFIXED
);
1456 seconds
= audio_recorded_time() / HZ
;
1459 if(update_countdown
== 0 || seconds
> last_seconds
)
1461 unsigned int dseconds
, dhours
, dminutes
;
1462 unsigned long num_recorded_bytes
, dsize
, dmb
;
1465 update_countdown
= 5;
1466 last_seconds
= seconds
;
1468 dseconds
= rec_timesplit_seconds();
1469 dsize
= rec_sizesplit_bytes();
1470 num_recorded_bytes
= audio_num_recorded_bytes();
1472 for(i
= 0; i
< screen_update
; i
++)
1473 screens
[i
].clear_display();
1477 #ifdef HAVE_LCD_COLOR
1478 /* special action for gradient - set default for 1 line gradient */
1479 if(global_settings
.cursor_style
== 3)
1480 style
= base_style
| CURLN_PACK(0) | NUMLN_PACK(1);
1481 #endif /* HAVE_LCD_COLOR */
1483 #if CONFIG_CODEC == SWCODEC
1484 if ((audio_stat
& AUDIO_STATUS_WARNING
)
1485 && (warning_counter
++ % WARNING_PERIOD
) < WARNING_PERIOD
/2)
1487 /* Switch back and forth displaying warning on first available
1488 line to ensure visibility - the motion should also help
1490 /* Don't use language string unless agreed upon to make this
1491 method permanent - could do something in the statusbar */
1492 snprintf(buf
, sizeof(buf
), "Warning: %08X",
1493 pcm_rec_get_warnings());
1496 #endif /* CONFIG_CODEC == SWCODEC */
1497 if ((global_settings
.rec_sizesplit
) &&
1498 (global_settings
.rec_split_method
))
1500 dmb
= dsize
/1024/1024;
1501 snprintf(buf
, sizeof(buf
), "%s %dMB",
1502 str(LANG_SYSFONT_SPLIT_SIZE
), dmb
);
1506 hours
= seconds
/ 3600;
1507 minutes
= (seconds
- (hours
* 3600)) / 60;
1508 snprintf(buf
, sizeof(buf
), "%s %02d:%02d:%02d",
1509 str(LANG_SYSFONT_RECORDING_TIME
),
1510 hours
, minutes
, seconds
%60);
1513 for(i
= 0; i
< screen_update
; i
++)
1514 screens
[i
].puts(0, 0, buf
);
1516 if(audio_stat
& AUDIO_STATUS_PRERECORD
)
1518 snprintf(buf
, sizeof(buf
), "%s...",
1519 str(LANG_SYSFONT_RECORD_PRERECORD
));
1523 /* Display the split interval if the record timesplit
1525 if ((global_settings
.rec_timesplit
) &&
1526 !(global_settings
.rec_split_method
))
1528 /* Display the record timesplit interval rather
1529 than the file size if the record timer is
1531 dhours
= dseconds
/ 3600;
1532 dminutes
= (dseconds
- (dhours
* 3600)) / 60;
1533 snprintf(buf
, sizeof(buf
), "%s %02d:%02d",
1534 str(LANG_SYSFONT_RECORD_TIMESPLIT_REC
),
1539 output_dyn_value(buf2
, sizeof buf2
,
1542 snprintf(buf
, sizeof(buf
), "%s %s",
1543 str(LANG_SYSFONT_RECORDING_SIZE
), buf2
);
1546 for(i
= 0; i
< screen_update
; i
++)
1547 screens
[i
].puts(0, 1, buf
);
1549 for(i
= 0; i
< screen_update
; i
++)
1551 if (filename_offset
[i
] > 0)
1554 if (audio_stat
& AUDIO_STATUS_RECORD
)
1556 strncpy(filename
, path_buffer
+
1557 strlen(path_buffer
) - 12, 13);
1561 snprintf(buf
, sizeof(buf
), "%s %s",
1562 str(LANG_SYSFONT_RECORDING_FILENAME
), filename
);
1563 screens
[i
].puts(0, 2, buf
);
1567 /* We will do file splitting regardless, either at the end of
1568 a split interval, or when the filesize approaches the 2GB
1569 FAT file size (compatibility) limit. */
1570 if ((audio_stat
&& !(global_settings
.rec_split_method
)
1571 && global_settings
.rec_timesplit
&& (seconds
>= dseconds
))
1572 || (audio_stat
&& global_settings
.rec_split_method
1573 && global_settings
.rec_sizesplit
1574 && (num_recorded_bytes
>= dsize
))
1575 || (num_recorded_bytes
>= MAX_FILE_SIZE
))
1577 if (!(global_settings
.rec_split_type
)
1578 || (num_recorded_bytes
>= MAX_FILE_SIZE
))
1580 rec_command(RECORDING_CMD_START_NEWFILE
);
1585 peak_meter_trigger(false);
1586 peak_meter_set_trigger_listener(NULL
);
1587 if( global_settings
.rec_split_type
== 1)
1588 rec_command(RECORDING_CMD_STOP
);
1590 rec_command(RECORDING_CMD_STOP_SHUTDOWN
);
1592 update_countdown
= 1;
1595 /* draw the clipcounter just in front of the peakmeter */
1596 if(global_settings
.peak_meter_clipcounter
)
1599 snprintf(clpstr
, 32, "%4d", pm_get_clipcount());
1600 for(i
= 0; i
< screen_update
; i
++)
1603 screens
[i
].puts(0, 2 + filename_offset
[i
],
1604 str(LANG_SYSFONT_PM_CLIPCOUNT
));
1605 screens
[i
].puts(0, 1 + PM_HEIGHT
+ filename_offset
[i
],
1610 snprintf(buf
, sizeof(buf
), "%s: %s", str(LANG_SYSFONT_VOLUME
),
1611 fmt_gain(SOUND_VOLUME
,
1612 global_settings
.volume
,
1613 buf2
, sizeof(buf2
)));
1615 if (global_settings
.cursor_style
&& (pos
++ == cursor
))
1617 for(i
= 0; i
< screen_update
; i
++)
1618 screens
[i
].puts_style_offset(0, filename_offset
[i
] +
1619 PM_HEIGHT
+ 2, buf
, style
,0);
1623 for(i
= 0; i
< screen_update
; i
++)
1624 screens
[i
].puts(0, filename_offset
[i
] + 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
].puts(0, filename_offset
[i
] +
1644 PM_HEIGHT
+ 3, buf
);
1648 HAVE_LINE_REC_( || global_settings
.rec_source
==
1650 HAVE_FMRADIO_REC_( || global_settings
.rec_source
==
1654 /* Draw LINE or FMRADIO recording gain */
1655 snprintf(buf
, sizeof(buf
), "%s:%s",
1656 str(LANG_SYSFONT_RECORDING_LEFT
),
1657 fmt_gain(SOUND_LEFT_GAIN
,
1658 global_settings
.rec_left_gain
,
1659 buf2
, sizeof(buf2
)));
1660 #ifdef HAVE_LCD_COLOR
1661 /* special action for gradient - double line gradient - line1 */
1662 if((global_settings
.cursor_style
== 3) &&
1664 style
= base_style
| CURLN_PACK(0) | NUMLN_PACK(2);
1665 #endif /* HAVE_LCD_COLOR */
1666 if(global_settings
.cursor_style
&& ((1==cursor
)||(2==cursor
)))
1668 for(i
= 0; i
< screen_update
; i
++)
1669 screens
[i
].puts_style_offset(0, filename_offset
[i
] +
1670 PM_HEIGHT
+ 3, buf
, style
,0);
1674 for(i
= 0; i
< screen_update
; i
++)
1675 screens
[i
].puts(0, filename_offset
[i
] +
1676 PM_HEIGHT
+ 3, buf
);
1679 snprintf(buf
, sizeof(buf
), "%s:%s",
1680 str(LANG_SYSFONT_RECORDING_RIGHT
),
1681 fmt_gain(SOUND_RIGHT_GAIN
,
1682 global_settings
.rec_right_gain
,
1683 buf2
, sizeof(buf2
)));
1684 #ifdef HAVE_LCD_COLOR
1685 /* special action for gradient - double line gradient - line2 */
1686 if((global_settings
.cursor_style
== 3) &&
1688 style
= base_style
| CURLN_PACK(1) | NUMLN_PACK(2);
1689 #endif /* HAVE_LCD_COLOR */
1690 if(global_settings
.cursor_style
&& ((1==cursor
)||(3==cursor
)))
1692 for(i
= 0; i
< screen_update
; i
++)
1693 screens
[i
].puts_style_offset(0, filename_offset
[i
] +
1694 PM_HEIGHT
+ 4, buf
, style
,0);
1698 for(i
= 0; i
< screen_update
; i
++)
1699 screens
[i
].puts(0, filename_offset
[i
] +
1700 PM_HEIGHT
+ 4, buf
);
1703 #ifdef HAVE_LCD_COLOR
1704 /* special action for gradient - back to single line gradient */
1705 if(global_settings
.cursor_style
== 3)
1706 style
= base_style
| CURLN_PACK(0) | NUMLN_PACK(1);
1707 #endif /* HAVE_LCD_COLOR */
1711 switch (global_settings
.rec_source
)
1713 HAVE_LINE_REC_(case AUDIO_SRC_LINEIN
:)
1714 HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO
:)
1721 #ifdef HAVE_SPDIF_REC
1722 case AUDIO_SRC_SPDIF
:
1727 line
[i
] = 5; /* to prevent uninitialisation
1728 warnings for line[0] */
1732 if (screens
[i
].height
< h
* (2 + filename_offset
[i
] +
1733 PM_HEIGHT
+ line
[i
]))
1736 display_agc
[i
] = false;
1739 display_agc
[i
] = true;
1741 if ((cursor
==4) || (cursor
==5))
1742 display_agc
[i
] = true;
1745 /************** AGC test info ******************
1746 snprintf(buf, sizeof(buf), "D:%d U:%d",
1747 (agc_droptime+2)/5, (agc_risetime+2)/5);
1748 lcd_putsxy(1, LCD_HEIGHT - 8, buf);
1749 snprintf(buf, sizeof(buf), "B:%d",
1751 lcd_putsxy(LCD_WIDTH/2 + 3, LCD_HEIGHT - 8, buf);
1752 ***********************************************/
1755 snprintf(buf
, sizeof(buf
), "%s: %s",
1756 str(LANG_SYSFONT_RECORDING_AGC_MAXGAIN
),
1757 fmt_gain(SOUND_LEFT_GAIN
,
1758 agc_maxgain
, buf2
, sizeof(buf2
)));
1759 else if (agc_preset
== 0)
1760 snprintf(buf
, sizeof(buf
), "%s: %s",
1761 str(LANG_SYSFONT_RECORDING_AGC_PRESET
),
1762 agc_preset_str
[agc_preset
]);
1763 else if (global_settings
.rec_source
== AUDIO_SRC_MIC
)
1764 snprintf(buf
, sizeof(buf
), "%s: %s%s",
1765 str(LANG_SYSFONT_RECORDING_AGC_PRESET
),
1766 agc_preset_str
[agc_preset
],
1767 fmt_gain(SOUND_LEFT_GAIN
,
1769 global_settings
.rec_mic_gain
,
1770 buf2
, sizeof(buf2
)));
1772 snprintf(buf
, sizeof(buf
), "%s: %s%s",
1773 str(LANG_SYSFONT_RECORDING_AGC_PRESET
),
1774 agc_preset_str
[agc_preset
],
1775 fmt_gain(SOUND_LEFT_GAIN
,
1777 (global_settings
.rec_left_gain
+
1778 global_settings
.rec_right_gain
)/2,
1779 buf2
, sizeof(buf2
)));
1781 if(global_settings
.cursor_style
&& ((cursor
==4) || (cursor
==5)))
1783 for(i
= 0; i
< screen_update
; i
++)
1784 screens
[i
].puts_style_offset(0, filename_offset
[i
] +
1785 PM_HEIGHT
+ line
[i
], buf
, style
,0);
1787 else if (global_settings
.rec_source
== AUDIO_SRC_MIC
1788 HAVE_LINE_REC_(|| global_settings
.rec_source
==
1790 HAVE_FMRADIO_REC_(|| global_settings
.rec_source
==
1794 for(i
= 0; i
< screen_update
; i
++) {
1795 if (display_agc
[i
]) {
1796 screens
[i
].puts(0, filename_offset
[i
] +
1797 PM_HEIGHT
+ line
[i
], buf
);
1802 if (global_settings
.rec_source
== AUDIO_SRC_MIC
)
1804 if(agc_maxgain
< (global_settings
.rec_mic_gain
))
1805 change_recording_gain(false, true, true);
1809 if(agc_maxgain
< (global_settings
.rec_left_gain
))
1810 change_recording_gain(false, true, false);
1811 if(agc_maxgain
< (global_settings
.rec_right_gain
))
1812 change_recording_gain(false, false, true);
1814 #else /* !HAVE_AGC */
1816 #endif /* HAVE_AGC */
1818 if(!global_settings
.cursor_style
) {
1822 for(i
= 0; i
< screen_update
; i
++)
1823 screen_put_cursorxy(&screens
[i
], 0,
1824 filename_offset
[i
] +
1825 PM_HEIGHT
+ 3, true);
1827 if(global_settings
.rec_source
!= AUDIO_SRC_MIC
)
1829 for(i
= 0; i
< screen_update
; i
++)
1830 screen_put_cursorxy(&screens
[i
], 0,
1831 filename_offset
[i
] +
1832 PM_HEIGHT
+ 4, true);
1836 for(i
= 0; i
< screen_update
; i
++)
1837 screen_put_cursorxy(&screens
[i
], 0,
1838 filename_offset
[i
] +
1839 PM_HEIGHT
+ 3, true);
1842 for(i
= 0; i
< screen_update
; i
++)
1843 screen_put_cursorxy(&screens
[i
], 0,
1844 filename_offset
[i
] +
1845 PM_HEIGHT
+ 4, true);
1850 for(i
= 0; i
< screen_update
; i
++)
1851 screen_put_cursorxy(&screens
[i
], 0,
1852 filename_offset
[i
] +
1853 PM_HEIGHT
+ line
[i
], true);
1855 #endif /* HAVE_AGC */
1857 for(i
= 0; i
< screen_update
; i
++)
1858 screen_put_cursorxy(&screens
[i
], 0,
1859 filename_offset
[i
] +
1860 PM_HEIGHT
+ 2, true);
1868 for(i
= 0; i
< screen_update
; i
++)
1870 gui_statusbar_draw(&(statusbars
.statusbars
[i
]), true);
1871 peak_meter_screen(&screens
[i
], pm_x
, pm_y
[i
], h
*PM_HEIGHT
);
1872 screens
[i
].update();
1875 /* draw the trigger status */
1878 trig_width
[i
] = ((screens
[i
].height
< 64) ||
1879 ((screens
[i
].height
< 72) && (PM_HEIGHT
> 1))) ?
1880 screens
[i
].width
- 14 * w
: screens
[i
].width
;
1881 trig_xpos
[i
] = screens
[i
].width
- trig_width
[i
];
1882 trig_ypos
[i
] = ((screens
[i
].height
< 72) && (PM_HEIGHT
> 1)) ?
1884 h
*(1 + filename_offset
[i
] + PM_HEIGHT
+
1892 if (peak_meter_trigger_status() != TRIG_OFF
)
1894 peak_meter_draw_trig(trig_xpos
, trig_ypos
, trig_width
,
1896 for(i
= 0; i
< screen_update
; i
++){
1897 screens
[i
].update_rect(trig_xpos
[i
], trig_ypos
[i
],
1898 trig_width
[i
] + 2, TRIG_HEIGHT
);
1903 if(audio_stat
& AUDIO_STATUS_ERROR
)
1907 } /* end while(!done) */
1909 audio_stat
= audio_status();
1910 if (audio_stat
& AUDIO_STATUS_ERROR
)
1912 gui_syncsplash(0, str(LANG_SYSFONT_DISK_FULL
));
1913 gui_syncstatusbar_draw(&statusbars
, true);
1916 screens
[i
].update();
1918 #if CONFIG_CODEC == SWCODEC
1919 /* stop recording - some players like H10 freeze otherwise
1920 TO DO: find out why it freezes and fix properly */
1921 rec_command(RECORDING_CMD_STOP
);
1922 audio_close_recording();
1925 audio_error_clear();
1929 if (action_userabort(TIMEOUT_NOBLOCK
))
1936 #if CONFIG_CODEC == SWCODEC
1937 rec_command(RECORDING_CMD_STOP
);
1938 audio_close_recording();
1940 #ifdef HAVE_FMRADIO_REC
1941 if (radio_status
!= FMRADIO_OFF
)
1942 /* Restore radio playback - radio_status should be unchanged if started
1943 through fm radio screen (barring usb connect) */
1944 rec_set_source(AUDIO_SRC_FMRADIO
, (radio_status
& FMRADIO_PAUSED
) ?
1945 SRCF_FMRADIO_PAUSED
: SRCF_FMRADIO_PLAYING
);
1948 /* Go back to playback mode */
1949 rec_set_source(AUDIO_SRC_PLAYBACK
, SRCF_PLAYBACK
);
1951 /* restore talking */
1952 talk_disable(false);
1953 #else /* !SWCODEC */
1954 audio_init_playback();
1955 #endif /* CONFIG_CODEC == SWCODEC */
1957 /* make sure the trigger is really turned off */
1958 peak_meter_trigger(false);
1959 peak_meter_set_trigger_listener(NULL
);
1961 rec_status
&= ~RCSTAT_IN_RECSCREEN
;
1962 sound_settings_apply();
1965 screens
[i
].setfont(FONT_UI
);
1967 /* if the directory was created or recording happened, make sure the
1968 browser is updated */
1969 if (rec_status
& (RCSTAT_CREATED_DIRECTORY
| RCSTAT_HAVE_RECORDED
))
1972 #if (CONFIG_LED == LED_REAL) && !defined(SIMULATOR)
1973 ata_set_led_enabled(true);
1978 return (rec_status
& RCSTAT_BEEN_IN_USB_MODE
) != 0;
1979 } /* recording_screen */
1981 #if CONFIG_KEYPAD == RECORDER_PAD
1982 static bool f2_rec_screen(void)
1984 static const char* const freq_str
[6] =
1999 struct audio_recording_options rec_options
;
2003 screens
[i
].setfont(FONT_SYSFIXED
);
2004 screens
[i
].getstringsize("A",&w
,&h
);
2008 const char* ptr
=NULL
;
2012 screens
[i
].clear_display();
2014 /* Recording quality */
2015 screens
[i
].putsxy(0, LCD_HEIGHT
/2 - h
*2,
2016 str(LANG_SYSFONT_RECORDING_QUALITY
));
2019 snprintf(buf
, sizeof(buf
), "%d", global_settings
.rec_quality
);
2022 screens
[i
].putsxy(0, LCD_HEIGHT
/2-h
, buf
);
2023 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_FastBackward
],
2024 LCD_WIDTH
/2 - 16, LCD_HEIGHT
/2 - 4, 7, 8);
2028 snprintf(buf
, sizeof buf
, "%s:", str(LANG_SYSFONT_RECORDING_FREQUENCY
));
2029 ptr
= freq_str
[global_settings
.rec_frequency
];
2032 screens
[i
].getstringsize(buf
,&w
,&h
);
2033 screens
[i
].putsxy((LCD_WIDTH
-w
)/2, LCD_HEIGHT
- h
*2, buf
);
2034 screens
[i
].getstringsize(ptr
, &w
, &h
);
2035 screens
[i
].putsxy((LCD_WIDTH
-w
)/2, LCD_HEIGHT
- h
, ptr
);
2036 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_DownArrow
],
2037 LCD_WIDTH
/2 - 3, LCD_HEIGHT
- h
*3, 7, 8);
2041 switch ( global_settings
.rec_channels
) {
2043 ptr
= str(LANG_SYSFONT_CHANNEL_STEREO
);
2047 ptr
= str(LANG_SYSFONT_CHANNEL_MONO
);
2053 screens
[i
].getstringsize(str(LANG_SYSFONT_CHANNELS
), &w
, &h
);
2054 screens
[i
].putsxy(LCD_WIDTH
- w
, LCD_HEIGHT
/2 - h
*2,
2055 str(LANG_SYSFONT_CHANNELS
));
2056 screens
[i
].getstringsize(str(LANG_SYSFONT_MODE
), &w
, &h
);
2057 screens
[i
].putsxy(LCD_WIDTH
- w
, LCD_HEIGHT
/2 - h
,
2058 str(LANG_SYSFONT_MODE
));
2059 screens
[i
].getstringsize(ptr
, &w
, &h
);
2060 screens
[i
].putsxy(LCD_WIDTH
- w
, LCD_HEIGHT
/2, ptr
);
2061 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_FastForward
],
2062 LCD_WIDTH
/2 + 8, LCD_HEIGHT
/2 - 4, 7, 8);
2064 screens
[i
].update();
2067 button
= button_get(true);
2070 case BUTTON_F2
| BUTTON_LEFT
:
2071 global_settings
.rec_quality
++;
2072 if(global_settings
.rec_quality
> 7)
2073 global_settings
.rec_quality
= 0;
2078 case BUTTON_F2
| BUTTON_DOWN
:
2079 global_settings
.rec_frequency
++;
2080 if(global_settings
.rec_frequency
> 5)
2081 global_settings
.rec_frequency
= 0;
2086 case BUTTON_F2
| BUTTON_RIGHT
:
2087 global_settings
.rec_channels
++;
2088 if(global_settings
.rec_channels
> 1)
2089 global_settings
.rec_channels
= 0;
2093 case BUTTON_F2
| BUTTON_REL
:
2099 case BUTTON_F2
| BUTTON_REPEAT
:
2104 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
2110 rec_init_recording_options(&rec_options
);
2111 rec_set_recording_options(&rec_options
);
2117 screens
[i
].setfont(FONT_UI
);
2122 static bool f3_rec_screen(void)
2130 str(LANG_SYSFONT_RECORDING_SRC_MIC
),
2131 str(LANG_SYSFONT_LINE_IN
),
2132 str(LANG_SYSFONT_RECORDING_SRC_DIGITAL
)
2134 struct audio_recording_options rec_options
;
2138 screens
[i
].setfont(FONT_SYSFIXED
);
2139 screens
[i
].getstringsize("A",&w
,&h
);
2144 ptr
= src_str
[global_settings
.rec_source
];
2147 screens
[i
].clear_display();
2149 /* Recording source */
2150 screens
[i
].putsxy(0, LCD_HEIGHT
/2 - h
*2,
2151 str(LANG_SYSFONT_RECORDING_SOURCE
));
2153 screens
[i
].getstringsize(ptr
, &w
, &h
);
2154 screens
[i
].putsxy(0, LCD_HEIGHT
/2-h
, ptr
);
2155 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_FastBackward
],
2156 LCD_WIDTH
/2 - 16, LCD_HEIGHT
/2 - 4, 7, 8);
2160 ptr
= str(LANG_SYSFONT_RECORD_TRIGGER
);
2163 screens
[i
].getstringsize(ptr
,&w
,&h
);
2164 screens
[i
].putsxy((LCD_WIDTH
-w
)/2, LCD_HEIGHT
- h
*2, ptr
);
2165 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_DownArrow
],
2166 LCD_WIDTH
/2 - 3, LCD_HEIGHT
- h
*3, 7, 8);
2168 screens
[i
].update();
2171 button
= button_get(true);
2174 case BUTTON_F3
| BUTTON_DOWN
:
2177 settings_apply_trigger();
2183 case BUTTON_F3
| BUTTON_LEFT
:
2184 global_settings
.rec_source
++;
2185 if(global_settings
.rec_source
> AUDIO_SRC_MAX
)
2186 global_settings
.rec_source
= 0;
2190 case BUTTON_F3
| BUTTON_REL
:
2196 case BUTTON_F3
| BUTTON_REPEAT
:
2201 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
2207 rec_init_recording_options(&rec_options
);
2208 rec_set_recording_options(&rec_options
);
2214 screens
[i
].setfont(FONT_UI
);
2218 #endif /* CONFIG_KEYPAD == RECORDER_PAD */
2220 #if CONFIG_CODEC == SWCODEC
2221 void audio_beep(int duration
)
2228 /* stubs for recording sim */
2229 void audio_init_recording(unsigned int buffer_offset
)
2231 buffer_offset
= buffer_offset
;
2234 void audio_close_recording(void)
2238 unsigned long pcm_rec_get_warnings(void)
2243 unsigned long audio_recorded_time(void)
2248 unsigned long audio_num_recorded_bytes(void)
2250 return 5 * 1024 * 1024;
2253 void rec_set_source(int source
, unsigned flags
)
2259 void audio_set_recording_options(struct audio_recording_options
*options
)
2264 void audio_set_recording_gain(int left
, int right
, int type
)
2271 void audio_record(const char *filename
)
2273 filename
= filename
;
2276 void audio_new_file(const char *filename
)
2278 filename
= filename
;
2281 void audio_stop_recording(void)
2285 void audio_pause_recording(void)
2289 void audio_resume_recording(void)
2293 #endif /* #ifdef SIMULATOR */
2294 #endif /* #ifdef CONFIG_CODEC == SWCODEC */
2296 #endif /* HAVE_RECORDING */