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 "pcm_record.h"
44 #include "recording.h"
45 #include "mp3_playback.h"
55 #include "peakmeter.h"
56 #include "statusbar.h"
58 #include "sound_menu.h"
59 #include "timefuncs.h"
69 #if (CONFIG_STORAGE & STORAGE_ATA) && (CONFIG_LED == LED_REAL) \
70 && !defined(SIMULATOR)
74 #include "screen_access.h"
77 #include "sound_menu.h"
83 /* This array holds the record timer interval lengths, in seconds */
84 static const unsigned long rec_timer_seconds
[] =
98 10L*60*60, /* 10:00 */
99 12L*60*60, /* 12:00 */
100 18L*60*60, /* 18:00 */
101 24L*60*60 /* 24:00 */
104 static unsigned int rec_timesplit_seconds(void)
106 return rec_timer_seconds
[global_settings
.rec_timesplit
];
109 /* This array holds the record size interval lengths, in bytes */
110 static const unsigned long rec_size_bytes
[] =
113 5*1024*1024, /* 5MB */
114 10*1024*1024, /* 10MB */
115 15*1024*1024, /* 15MB */
116 32*1024*1024, /* 32MB */
117 64*1024*1024, /* 64MB */
118 75*1024*1024, /* 75MB */
119 100*1024*1024, /* 100MB */
120 128*1024*1024, /* 128MB */
121 256*1024*1024, /* 256MB */
122 512*1024*1024, /* 512MB */
123 650*1024*1024, /* 650MB */
124 700*1024*1024, /* 700MB */
125 1024*1024*1024, /* 1GB */
126 1536*1024*1024, /* 1.5GB */
127 1792*1024*1024, /* 1.75GB */
130 static unsigned long rec_sizesplit_bytes(void)
132 return rec_size_bytes
[global_settings
.rec_sizesplit
];
135 void settings_apply_trigger(void)
137 int start_thres
, stop_thres
;
138 if (global_settings
.peak_meter_dbfs
)
140 start_thres
= global_settings
.rec_start_thres_db
- 1;
141 stop_thres
= global_settings
.rec_stop_thres_db
- 1;
145 start_thres
= global_settings
.rec_start_thres_linear
;
146 stop_thres
= global_settings
.rec_stop_thres_linear
;
149 peak_meter_define_trigger(
151 global_settings
.rec_start_duration
*HZ
,
152 MIN(global_settings
.rec_start_duration
*HZ
/ 2, 2*HZ
),
154 global_settings
.rec_stop_postrec
*HZ
,
155 global_settings
.rec_stop_gap
*HZ
158 /* recording screen status flags */
159 enum rec_status_flags
161 RCSTAT_IN_RECSCREEN
= 0x00000001,
162 RCSTAT_BEEN_IN_USB_MODE
= 0x00000002,
163 RCSTAT_CREATED_DIRECTORY
= 0x00000004,
164 RCSTAT_HAVE_RECORDED
= 0x00000008,
167 static int rec_status
= 0;
169 bool in_recording_screen(void)
171 return (rec_status
& RCSTAT_IN_RECSCREEN
) != 0;
174 #if CONFIG_KEYPAD == RECORDER_PAD
175 static bool f2_rec_screen(void);
176 static bool f3_rec_screen(void);
179 #define MAX_FILE_SIZE 0x7F800000 /* 2 GB - 4 MB */
181 #ifndef HAVE_REMOTE_LCD
182 static const int screen_update
= NB_SCREENS
;
184 static int screen_update
= NB_SCREENS
;
185 static bool remote_display_on
= true;
188 /* as we have the ability to disable the remote, we need an alternative loop */
189 #define FOR_NB_ACTIVE_SCREENS(i) for(i = 0; i < screen_update; i++)
191 static bool update_list
= false; /* (GIU) list needs updating */
193 /** File name creation **/
195 /* current file number to assist in creating unique numbered filenames
196 without actually having to create the file on disk */
197 static int file_number
= -1;
198 #endif /* CONFIG_RTC */
200 #if CONFIG_CODEC == SWCODEC
202 #define REC_FILE_ENDING(rec_format) \
203 (audio_formats[rec_format_afmt[rec_format]].ext_list)
205 #else /* CONFIG_CODEC != SWCODEC */
207 /* default record file extension for HWCODEC */
208 #define REC_FILE_ENDING(rec_format) \
209 (audio_formats[AFMT_MPA_L3].ext_list)
211 #endif /* CONFIG_CODEC == SWCODEC */
213 /* path for current file */
214 static char path_buffer
[MAX_PATH
];
216 /** Automatic Gain Control (AGC) **/
219 * peak_time is incremented every 0.2s, every 2nd run of record screen loop.
220 * hist_time is incremented every 0.5s, display update.
221 * peak_time is the counter of the peak hold read and agc process,
222 * overflow every 13 years 8-)
224 static long peak_time
= 0;
225 static long hist_time
= 0;
227 static short peak_valid_mem
[4];
228 #define BAL_MEM_SIZE 24
229 static short balance_mem
[BAL_MEM_SIZE
];
231 /* Automatic Gain Control */
232 #define AGC_MODE_SIZE 5
233 #define AGC_SAFETY_MODE 0
235 static const char* agc_preset_str
[] =
236 { "Off", "S", "L", "D", "M", "V" };
243 #define AGC_CLIP 32766
244 #define AGC_PEAK 29883 /* fast gain reduction threshold -0.8dB */
245 #define AGC_HIGH 27254 /* accelerated gain reduction threshold -1.6dB */
246 #define AGC_IMG 823 /* threshold for balance control -32dB */
247 /* autogain high level thresholds (-3dB, -7dB, -4dB, -5dB, -5dB) */
248 static const short agc_th_hi
[AGC_MODE_SIZE
] =
249 { 23197, 14637, 21156, 18428, 18426 };
250 /* autogain low level thresholds (-14dB, -11dB, -6dB, -7dB, -8dB) */
251 static const short agc_th_lo
[AGC_MODE_SIZE
] =
252 { 6538, 9235, 16422, 14636, 13045 };
253 /* autogain threshold times [1/5s] or [200ms] */
254 static const short agc_tdrop
[AGC_MODE_SIZE
] =
255 { 900, 225, 150, 60, 8 };
256 static const short agc_trise
[AGC_MODE_SIZE
] =
257 { 9000, 750, 400, 150, 20 };
258 static const short agc_tbal
[AGC_MODE_SIZE
] =
259 { 4500, 500, 300, 100, 15 };
261 static bool agc_enable
= true;
262 static short agc_preset
;
264 static int agc_left
= 0;
265 static int agc_right
= 0;
266 /* AGC time since high target volume was exceeded */
267 static short agc_droptime
= 0;
268 /* AGC time since volume fallen below low target */
269 static short agc_risetime
= 0;
270 /* AGC balance time exceeding +/- 0.7dB */
271 static short agc_baltime
= 0;
272 /* AGC maximum gain */
273 static short agc_maxgain
;
274 #endif /* HAVE_AGC */
276 static void set_gain(void)
279 if(global_settings
.rec_source
== AUDIO_SRC_MIC
)
281 audio_set_recording_gain(global_settings
.rec_mic_gain
,
287 /* AUDIO_SRC_LINEIN, AUDIO_SRC_FMRADIO, AUDIO_SRC_SPDIF */
288 audio_set_recording_gain(global_settings
.rec_left_gain
,
289 global_settings
.rec_right_gain
,
292 /* reset the clipping indicators */
293 peak_meter_set_clip_hold(global_settings
.peak_meter_clip_hold
);
298 /* Read peak meter values & calculate balance.
299 * Returns validity of peak values.
300 * Used for automatic gain control and history diagram.
302 static bool read_peak_levels(int *peak_l
, int *peak_r
, int *balance
)
304 peak_meter_get_peakhold(peak_l
, peak_r
);
305 peak_valid_mem
[peak_time
% 3] = *peak_l
;
306 if (((peak_valid_mem
[0] == peak_valid_mem
[1]) &&
307 (peak_valid_mem
[1] == peak_valid_mem
[2])) &&
308 ((*peak_l
< 32767) || storage_disk_is_active()))
311 if (*peak_r
> *peak_l
)
312 balance_mem
[peak_time
% BAL_MEM_SIZE
] = (*peak_l
?
313 MIN((10000 * *peak_r
) / *peak_l
- 10000, 15118) : 15118);
315 balance_mem
[peak_time
% BAL_MEM_SIZE
] = (*peak_r
?
316 MAX(10000 - (10000 * *peak_l
) / *peak_r
, -15118) : -15118);
319 for (i
= 0; i
< BAL_MEM_SIZE
; i
++)
320 *balance
+= balance_mem
[i
];
321 *balance
= *balance
/ BAL_MEM_SIZE
;
326 /* AGC helper function to check if maximum gain is reached */
327 static bool agc_gain_is_max(bool left
, bool right
)
329 /* range -128...+108 [0.5dB] */
330 short gain_current_l
;
331 short gain_current_r
;
336 switch (global_settings
.rec_source
)
338 #if defined(HAVE_LINE_REC) || defined(HAVE_FMRADIO_REC)
339 HAVE_LINE_REC_(case AUDIO_SRC_LINEIN
:)
340 HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO
:)
341 gain_current_l
= global_settings
.rec_left_gain
;
342 gain_current_r
= global_settings
.rec_right_gain
;
344 #endif /* LINE, FMRADIO */
345 #if defined(HAVE_MIC_REC)
348 gain_current_l
= global_settings
.rec_mic_gain
;
349 gain_current_r
= global_settings
.rec_mic_gain
;
353 return ((left
&& (gain_current_l
>= agc_maxgain
)) ||
354 (right
&& (gain_current_r
>= agc_maxgain
)));
357 static void change_recording_gain(bool increment
, bool left
, bool right
)
359 int factor
= (increment
? 1 : -1);
361 switch (global_settings
.rec_source
)
363 #if defined(HAVE_LINE_REC) || defined(HAVE_FMRADIO_REC)
364 HAVE_LINE_REC_(case AUDIO_SRC_LINEIN
:)
365 HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO
:)
366 if (left
) global_settings
.rec_left_gain
+= factor
;
367 if (right
) global_settings
.rec_right_gain
+= factor
;
369 #endif /* LINE, FMRADIO */
370 #if defined(HAVE_MIC_REC)
372 global_settings
.rec_mic_gain
+= factor
;
378 * Handle automatic gain control (AGC).
379 * Change recording gain if peak_x levels are above or below
380 * target volume for specified timeouts.
382 static void auto_gain_control(int *peak_l
, int *peak_r
, int *balance
)
388 if (*peak_l
> agc_left
)
391 agc_left
-= (agc_left
- *peak_l
+ 3) >> 2;
392 if (*peak_r
> agc_right
)
395 agc_right
-= (agc_right
- *peak_r
+ 3) >> 2;
396 agc_mono
= (agc_left
+ agc_right
) / 2;
398 agc_mode
= abs(agc_preset
) - 1;
404 if (agc_mode
!= AGC_SAFETY_MODE
) {
405 /* Automatic balance control - only if not in safety mode */
406 if ((agc_left
> AGC_IMG
) && (agc_right
> AGC_IMG
))
411 agc_baltime
-= !(peak_time
% 4); /* 0.47 - 0.75dB */
412 else if (*balance
> -4125)
413 agc_baltime
--; /* 0.75 - 3.00dB */
414 else if (*balance
> -7579)
415 agc_baltime
-= 2; /* 3.00 - 4.90dB */
417 agc_baltime
-= !(peak_time
% 8); /* 4.90 - inf dB */
419 agc_baltime
-= (peak_time
% 2);
421 else if (*balance
> 556)
424 agc_baltime
+= !(peak_time
% 4);
425 else if (*balance
< 4125)
427 else if (*balance
< 7579)
430 agc_baltime
+= !(peak_time
% 8);
432 agc_baltime
+= (peak_time
% 2);
435 if ((*balance
* agc_baltime
) < 0)
438 agc_baltime
-= peak_time
% 2;
440 agc_baltime
+= peak_time
% 2;
443 increment
= ((agc_risetime
/ 2) > agc_droptime
);
445 if (agc_baltime
< -agc_tbal
[agc_mode
])
447 if (!increment
|| !agc_gain_is_max(!increment
, increment
)) {
448 change_recording_gain(increment
, !increment
, increment
);
453 else if (agc_baltime
> +agc_tbal
[agc_mode
])
455 if (!increment
|| !agc_gain_is_max(increment
, !increment
)) {
456 change_recording_gain(increment
, increment
, !increment
);
462 else if (!(hist_time
% 4))
471 /* Automatic gain control */
472 if ((agc_left
> agc_th_hi
[agc_mode
]) || (agc_right
> agc_th_hi
[agc_mode
]))
474 if ((agc_left
> AGC_CLIP
) || (agc_right
> AGC_CLIP
))
475 agc_droptime
+= agc_tdrop
[agc_mode
] /
476 (global_settings
.rec_agc_cliptime
+ 1);
477 if (agc_left
> AGC_HIGH
) {
480 if (agc_left
> AGC_PEAK
)
483 if (agc_right
> AGC_HIGH
) {
486 if (agc_right
> AGC_PEAK
)
489 if (agc_mono
> agc_th_hi
[agc_mode
])
492 agc_droptime
+= !(peak_time
% 2);
494 if (agc_droptime
>= agc_tdrop
[agc_mode
])
496 change_recording_gain(false, true, true);
501 agc_risetime
= MAX(agc_risetime
- 1, 0);
503 else if (agc_mono
< agc_th_lo
[agc_mode
])
505 if (agc_mono
< (agc_th_lo
[agc_mode
] / 8))
506 agc_risetime
+= !(peak_time
% 5);
507 else if (agc_mono
< (agc_th_lo
[agc_mode
] / 2))
512 if (agc_risetime
>= agc_trise
[agc_mode
]) {
513 if ((agc_mode
!= AGC_SAFETY_MODE
) &&
514 (!agc_gain_is_max(true, true))) {
515 change_recording_gain(true, true, true);
521 agc_droptime
= MAX(agc_droptime
- 1, 0);
523 else if (!(peak_time
% 6)) /* on target level every 1.2 sec */
525 agc_risetime
= MAX(agc_risetime
- 1, 0);
526 agc_droptime
= MAX(agc_droptime
- 1, 0);
529 #endif /* HAVE_AGC */
531 static const char* const fmtstr
[] =
533 "%c%d %s", /* no decimals */
534 "%c%d.%d %s ", /* 1 decimal */
535 "%c%d.%02d %s " /* 2 decimals */
538 static char *fmt_gain(int snd
, int val
, char *str
, int len
)
544 val
= sound_val2phys(snd
, val
);
550 numdec
= sound_numdecimals(snd
);
551 unit
= sound_unit(snd
);
555 i
= val
/ (10*numdec
);
556 d
= val
% (10*numdec
);
557 snprintf(str
, len
, fmtstr
[numdec
], sign
, i
, d
, unit
);
560 snprintf(str
, len
, fmtstr
[numdec
], sign
, val
, unit
);
565 /* the list below must match enum audio_sources in audio.h */
566 static const char* const prestr
[] =
568 HAVE_MIC_IN_([AUDIO_SRC_MIC
] = "R_MIC_",)
569 HAVE_LINE_REC_([AUDIO_SRC_LINEIN
] = "R_LINE_",)
570 HAVE_SPDIF_IN_([AUDIO_SRC_SPDIF
] = "R_SPDIF_",)
571 HAVE_FMRADIO_REC_([AUDIO_SRC_FMRADIO
] = "R_FM_",)
574 char *rec_create_filename(char *buffer
)
577 const char *pref
= "R_";
579 /* Directory existence and writeablility should have already been
580 * verified - do not pass NULL pointers to pcmrec */
582 if((unsigned)global_settings
.rec_source
< AUDIO_NUM_SOURCES
)
584 pref
= prestr
[global_settings
.rec_source
];
587 strcpy(buffer
, global_settings
.rec_directory
);
589 snprintf(ext
, sizeof(ext
), ".%s",
590 REC_FILE_ENDING(global_settings
.rec_format
));
593 return create_numbered_filename(buffer
, buffer
, pref
, ext
, 4,
596 /* We'll wait at least up to the start of the next second so no duplicate
598 return create_datetime_filename(buffer
, buffer
, pref
, ext
, true);
603 /* Hit disk to get a starting filename for the type */
604 static void rec_init_filename(void)
607 rec_create_filename(path_buffer
);
612 int rec_create_directory(void)
615 const char * const folder
= global_settings
.rec_directory
;
617 if (strcmp(folder
, "/") && !dir_exists(folder
))
623 while (action_userabort(HZ
) == false)
626 str(LANG_REC_DIR_NOT_WRITABLE
),
627 str(LANG_OFF_ABORT
));
632 rec_status
|= RCSTAT_CREATED_DIRECTORY
;
640 void rec_init_recording_options(struct audio_recording_options
*options
)
642 options
->rec_source
= global_settings
.rec_source
;
643 options
->rec_frequency
= global_settings
.rec_frequency
;
644 options
->rec_channels
= global_settings
.rec_channels
;
645 options
->rec_prerecord_time
= global_settings
.rec_prerecord_time
;
646 #if CONFIG_CODEC == SWCODEC
647 options
->rec_mono_mode
= global_settings
.rec_mono_mode
;
648 options
->rec_source_flags
= 0;
649 options
->enc_config
.rec_format
= global_settings
.rec_format
;
650 global_to_encoder_config(&options
->enc_config
);
652 options
->rec_quality
= global_settings
.rec_quality
;
653 options
->rec_editable
= global_settings
.rec_editable
;
657 #if CONFIG_CODEC == SWCODEC && !defined (SIMULATOR)
658 void rec_set_source(int source
, unsigned flags
)
660 /* Set audio input source, power up/down devices */
661 audio_set_input_source(source
, flags
);
663 /* Set peakmeters for recording or reset to playback */
664 peak_meter_playback((flags
& SRCF_RECORDING
) == 0);
665 peak_meter_enabled
= true;
667 #endif /* CONFIG_CODEC == SWCODEC && !defined (SIMULATOR) */
669 void rec_set_recording_options(struct audio_recording_options
*options
)
671 #if CONFIG_CODEC != SWCODEC
672 if (global_settings
.rec_prerecord_time
)
674 talk_buffer_steal(); /* will use the mp3 buffer */
676 #else /* == SWCODEC */
677 rec_set_source(options
->rec_source
,
678 options
->rec_source_flags
| SRCF_RECORDING
);
679 #endif /* CONFIG_CODEC != SWCODEC */
681 audio_set_recording_options(options
);
684 void rec_command(enum recording_command cmd
)
688 case RECORDING_CMD_STOP_SHUTDOWN
:
689 pm_activate_clipcount(false);
690 audio_stop_recording();
691 #if CONFIG_CODEC == SWCODEC
692 audio_close_recording();
696 case RECORDING_CMD_STOP
:
697 pm_activate_clipcount(false);
698 audio_stop_recording();
700 case RECORDING_CMD_START
:
701 /* steal mp3 buffer, create unique filename and start recording */
702 pm_reset_clipcount();
703 pm_activate_clipcount(true);
704 #if CONFIG_CODEC != SWCODEC
705 talk_buffer_steal(); /* we use the mp3 buffer */
707 audio_record(rec_create_filename(path_buffer
));
709 case RECORDING_CMD_START_NEWFILE
:
710 /* create unique filename and start recording*/
711 pm_reset_clipcount();
712 pm_activate_clipcount(true); /* just to be sure */
713 audio_new_file(rec_create_filename(path_buffer
));
715 case RECORDING_CMD_PAUSE
:
716 pm_activate_clipcount(false);
717 audio_pause_recording();
719 case RECORDING_CMD_RESUME
:
720 pm_activate_clipcount(true);
721 audio_resume_recording();
727 /* used in trigger_listerner and recording_screen */
728 static unsigned int last_seconds
= 0;
731 * Callback function so that the peak meter code can send an event
732 * to this application. This function can be passed to
733 * peak_meter_set_trigger_listener in order to activate the trigger.
735 static void trigger_listener(int trigger_status
)
737 switch (trigger_status
)
740 if(!(audio_status() & AUDIO_STATUS_RECORD
))
742 rec_status
|= RCSTAT_HAVE_RECORDED
;
743 rec_command(RECORDING_CMD_START
);
744 #if CONFIG_CODEC != SWCODEC
745 /* give control to mpeg thread so that it can start
747 yield(); yield(); yield();
751 /* if we're already recording this is a retrigger */
754 if((audio_status() & AUDIO_STATUS_PAUSE
) &&
755 (global_settings
.rec_trigger_type
== TRIG_TYPE_PAUSE
))
757 rec_command(RECORDING_CMD_RESUME
);
759 /* New file on trig start*/
760 else if (global_settings
.rec_trigger_type
!= TRIG_TYPE_NEW_FILE
)
762 rec_command(RECORDING_CMD_START_NEWFILE
);
763 /* tell recording_screen to reset the time */
769 /* A _change_ to TRIG_READY means the current recording has stopped */
771 if(audio_status() & AUDIO_STATUS_RECORD
)
773 switch(global_settings
.rec_trigger_type
)
775 case TRIG_TYPE_STOP
: /* Stop */
776 rec_command(RECORDING_CMD_STOP
);
779 case TRIG_TYPE_PAUSE
: /* Pause */
780 rec_command(RECORDING_CMD_PAUSE
);
783 case TRIG_TYPE_NEW_FILE
: /* New file on trig stop*/
784 rec_command(RECORDING_CMD_START_NEWFILE
);
785 /* tell recording_screen to reset the time */
789 case 3: /* Stop and shutdown */
790 rec_command(RECORDING_CMD_STOP_SHUTDOWN
);
794 if (global_settings
.rec_trigger_mode
!= TRIG_MODE_REARM
)
796 peak_meter_set_trigger_listener(NULL
);
797 peak_meter_trigger(false);
804 /* Stuff for drawing the screen */
806 enum rec_list_items_stereo
{
822 enum rec_list_items_mono
{
827 ITEM_AGC_MAXDB_M
= 5,
836 #ifdef HAVE_SPDIF_REC
837 enum rec_list_items_spdif
{
839 #if CONFIG_CODEC == SWCODEC
840 ITEM_SAMPLERATE_D
= 6,
850 static int listid_to_enum
[ITEM_COUNT
];
852 static char * reclist_get_name(int selected_item
, void * data
,
853 char * buffer
, size_t buffer_len
)
859 data
= data
; /* not used */
860 if(selected_item
>= ITEM_COUNT
)
863 switch (listid_to_enum
[selected_item
])
866 snprintf(buffer
, buffer_len
, "%s: %s", str(LANG_VOLUME
),
867 fmt_gain(SOUND_VOLUME
,
868 global_settings
.volume
,
869 buf2
, sizeof(buf2
)));
873 if(global_settings
.rec_source
== AUDIO_SRC_MIC
)
875 /* Draw MIC recording gain */
876 snprintf(buffer
, buffer_len
, "%s: %s", str(LANG_GAIN
),
877 fmt_gain(SOUND_MIC_GAIN
,
878 global_settings
.rec_mic_gain
,
879 buf2
, sizeof(buf2
)));
884 int avg_gain
= (global_settings
.rec_left_gain
+
885 global_settings
.rec_right_gain
) / 2;
886 snprintf(buffer
, buffer_len
, "%s: %s", str(LANG_GAIN
),
887 fmt_gain(SOUND_LEFT_GAIN
,
889 buf2
, sizeof(buf2
)));
893 snprintf(buffer
, buffer_len
, "%s: %s",
895 fmt_gain(SOUND_LEFT_GAIN
,
896 global_settings
.rec_left_gain
,
897 buf2
, sizeof(buf2
)));
900 snprintf(buffer
, buffer_len
, "%s: %s",
901 str(LANG_GAIN_RIGHT
),
902 fmt_gain(SOUND_RIGHT_GAIN
,
903 global_settings
.rec_right_gain
,
904 buf2
, sizeof(buf2
)));
908 snprintf(buffer
, buffer_len
, "%s: %s",
909 str(LANG_RECORDING_AGC_PRESET
),
910 agc_preset_str
[agc_preset
]);
914 snprintf(buffer
, buffer_len
, "%s: %s",
915 str(LANG_RECORDING_AGC_MAXGAIN
),
916 fmt_gain(SOUND_LEFT_GAIN
,
917 agc_maxgain
, buf2
, sizeof(buf2
)));
919 else if (global_settings
.rec_source
== AUDIO_SRC_MIC
)
920 snprintf(buffer
, buffer_len
, "%s: %s (%s)",
921 str(LANG_RECORDING_AGC_MAXGAIN
),
922 fmt_gain(SOUND_MIC_GAIN
,
923 agc_maxgain
, buf2
, sizeof(buf2
)),
924 fmt_gain(SOUND_MIC_GAIN
,
925 agc_maxgain
- global_settings
.rec_mic_gain
,
926 buf3
, sizeof(buf3
)));
929 snprintf(buffer
, buffer_len
, "%s: %s (%s)",
930 str(LANG_RECORDING_AGC_MAXGAIN
),
931 fmt_gain(SOUND_LEFT_GAIN
,
932 agc_maxgain
, buf2
, sizeof(buf2
)),
933 fmt_gain(SOUND_LEFT_GAIN
,
935 (global_settings
.rec_left_gain
+
936 global_settings
.rec_right_gain
)/2,
937 buf3
, sizeof(buf3
)));
940 #if CONFIG_CODEC == SWCODEC
941 #ifdef HAVE_SPDIF_REC
942 case ITEM_SAMPLERATE_D
:
943 snprintf(buffer
, buffer_len
, "%s: %d",
944 str(LANG_RECORDING_FREQUENCY
),
945 pcm_rec_sample_rate());
951 if(audio_status() & AUDIO_STATUS_RECORD
)
953 size_t tot_len
= strlen(path_buffer
) +
954 strlen(str(LANG_RECORDING_FILENAME
)) + 1;
955 if(tot_len
> buffer_len
)
957 snprintf(buffer
, buffer_len
, "%s %s",
958 str(LANG_RECORDING_FILENAME
),
959 path_buffer
+ tot_len
- buffer_len
);
963 snprintf(buffer
, buffer_len
, "%s %s",
964 str(LANG_RECORDING_FILENAME
), path_buffer
);
969 strncpy(buffer
, str(LANG_RECORDING_FILENAME
), buffer_len
);
980 bool recording_start_automatic
= false;
982 bool recording_screen(bool no_source
)
985 int done
= -1; /* negative to re-init, positive to quit, zero to run */
986 char buf
[32]; /* for preparing strings */
987 char buf2
[32]; /* for preparing strings */
988 int w
, h
; /* character width/height */
989 int update_countdown
= 0; /* refresh counter */
990 unsigned int seconds
;
992 int audio_stat
= 0; /* status of the audio system */
993 int last_audio_stat
= -1; /* previous status so we can act on changes */
994 struct viewport vp_list
[NB_SCREENS
], vp_top
[NB_SCREENS
]; /* the viewports */
996 #if CONFIG_CODEC == SWCODEC
997 int warning_counter
= 0;
998 #define WARNING_PERIOD 7
1001 #if CONFIG_CODEC == SWCODEC
1002 #ifdef HAVE_SPDIF_REC
1003 unsigned long prev_sample_rate
= 0;
1007 #ifdef HAVE_FMRADIO_REC
1008 /* Radio is left on if:
1009 * 1) Is was on at the start and the initial source is FM Radio
1010 * 2) 1) and the source was never changed to something else
1012 int radio_status
= (global_settings
.rec_source
!= AUDIO_SRC_FMRADIO
) ?
1013 FMRADIO_OFF
: get_radio_status();
1015 #if (CONFIG_LED == LED_REAL)
1016 bool led_state
= false;
1017 int led_countdown
= 2;
1020 bool peak_read
= false;
1021 bool peak_valid
= false;
1025 int oldbars
, recbars
= VP_SB_ALLSCREENS
;
1027 int pm_x
[NB_SCREENS
]; /* peakmeter (and trigger bar) x pos */
1028 int pm_y
[NB_SCREENS
]; /* peakmeter y pos */
1029 int pm_h
[NB_SCREENS
]; /* peakmeter height */
1030 int trig_ypos
[NB_SCREENS
]; /* trigger bar y pos */
1031 int trig_width
[NB_SCREENS
]; /* trigger bar width */
1032 bool compact_view
[NB_SCREENS
]; /* tweak layout tiny screens / big fonts */
1034 struct gui_synclist lists
; /* the list in the bottom vp */
1035 #ifdef HAVE_FMRADIO_REC
1036 int prev_rec_source
= global_settings
.rec_source
; /* detect source change */
1039 static const unsigned char *byte_units
[] = {
1041 ID2P(LANG_KILOBYTE
),
1042 ID2P(LANG_MEGABYTE
),
1046 struct audio_recording_options rec_options
;
1047 rec_status
= RCSTAT_IN_RECSCREEN
;
1049 #if (CONFIG_STORAGE & STORAGE_ATA) && (CONFIG_LED == LED_REAL) \
1050 && !defined(SIMULATOR)
1051 ata_set_led_enabled(false);
1054 #if CONFIG_CODEC == SWCODEC
1055 /* recording_menu gets messed up: so prevent manus talking */
1057 /* audio_init_recording stops anything playing when it takes the audio
1060 /* Yes, we use the D/A for monitoring */
1061 peak_meter_enabled
= true;
1062 peak_meter_playback(true);
1066 peak_meter_get_peakhold(&peak_l
, &peak_r
);
1069 pm_reset_clipcount();
1070 pm_activate_clipcount(false);
1071 settings_apply_trigger();
1074 agc_preset_str
[0] = str(LANG_OFF
);
1075 agc_preset_str
[1] = str(LANG_AGC_SAFETY
);
1076 agc_preset_str
[2] = str(LANG_AGC_LIVE
);
1077 agc_preset_str
[3] = str(LANG_AGC_DJSET
);
1078 agc_preset_str
[4] = str(LANG_AGC_MEDIUM
);
1079 agc_preset_str
[5] = str(LANG_AGC_VOICE
);
1080 #endif /* HAVE_AGC */
1082 #if CONFIG_CODEC == SWCODEC
1083 audio_close_recording();
1085 audio_init_recording(0);
1086 sound_set_volume(global_settings
.volume
);
1089 /* Create new filename for recording start */
1090 rec_init_filename();
1093 /* viewport init and calculations that only needs to be done once */
1095 recbars
|= VP_SB_IGNORE_SETTING(i
);
1096 oldbars
= viewportmanager_set_statusbar(recbars
);
1100 /* top vp, 4 lines, force sys font if total screen < 6 lines
1101 NOTE: one could limit the list to 1 line and get away with 5 lines */
1103 viewport_set_defaults(v
, i
);
1104 if (viewport_get_nb_lines(v
) < 4)
1106 /* compact needs 4 lines total */
1107 v
->font
= FONT_SYSFIXED
;
1108 compact_view
[i
] = false;
1112 if (viewport_get_nb_lines(v
) < (4+2)) /*top=4,list=2*/
1113 compact_view
[i
] = true;
1115 compact_view
[i
] = false;
1117 v
->height
= (font_get(v
->font
)->height
)*(compact_view
[i
] ? 3 : 4);
1119 /* list section, rest of the screen */
1121 viewport_set_defaults(v
, i
);
1122 v
->font
= vp_top
[i
].font
;
1123 v
->y
= vp_top
[i
].y
+ vp_top
[i
].height
;
1124 v
->height
= screens
[i
].lcdheight
- v
->y
; /* the rest */
1125 screens
[i
].set_viewport(&vp_top
[i
]); /* req for next calls */
1127 screens
[i
].getstringsize("W", &w
, &h
);
1128 pm_y
[i
] = font_get(vp_top
[i
].font
)->height
* 2;
1129 trig_ypos
[i
] = font_get(vp_top
[i
].font
)->height
* 3;
1131 trig_ypos
[i
] -= (font_get(vp_top
[i
].font
)->height
)/2;
1134 /* init the bottom list */
1135 gui_synclist_init(&lists
, reclist_get_name
, NULL
, false, 1, vp_list
);
1136 gui_synclist_set_title(&lists
, NULL
, Icon_NOICON
);
1138 /* start of the loop: we stay in this loop until user quits recscreen */
1143 /* request to re-init stuff, done after settings screen */
1145 #ifdef HAVE_FMRADIO_REC
1146 /* If input changes away from FM Radio,
1147 radio will remain off when recording screen closes. */
1148 if (global_settings
.rec_source
!= prev_rec_source
1149 && prev_rec_source
== AUDIO_SRC_FMRADIO
)
1150 radio_status
= FMRADIO_OFF
;
1151 prev_rec_source
= global_settings
.rec_source
;
1157 if(global_settings
.peak_meter_clipcounter
)
1160 screens
[i
].getstringsize(str(LANG_PM_CLIPCOUNT
),
1161 &clipwidth
, &h
); /* h is same */
1162 pm_x
[i
] = clipwidth
+1;
1164 if(global_settings
.rec_trigger_mode
== TRIG_MODE_OFF
)
1165 pm_h
[i
] = font_get(vp_top
[i
].font
)->height
* 2;
1167 pm_h
[i
] = font_get(vp_top
[i
].font
)->height
;
1170 trig_width
[i
] = vp_top
[i
].width
- pm_x
[i
];
1173 #if CONFIG_CODEC == SWCODEC
1174 audio_close_recording();
1175 audio_init_recording(0);
1178 rec_init_recording_options(&rec_options
);
1179 rec_set_recording_options(&rec_options
);
1181 if(rec_create_directory() < 0)
1187 #if CONFIG_CODEC == SWCODEC && CONFIG_RTC == 0
1188 /* If format changed, a new number is required */
1189 rec_init_filename();
1194 if (global_settings
.rec_source
== AUDIO_SRC_MIC
) {
1195 agc_preset
= global_settings
.rec_agc_preset_mic
;
1196 agc_maxgain
= global_settings
.rec_agc_maxgain_mic
;
1201 agc_preset
= global_settings
.rec_agc_preset_line
;
1202 agc_maxgain
= global_settings
.rec_agc_maxgain_line
;
1204 #endif /* HAVE_AGC */
1207 update_countdown
= 0; /* Update immediately */
1209 /* populate translation table for list id -> enum */
1210 #ifdef HAVE_SPDIF_REC
1211 if(global_settings
.rec_source
== AUDIO_SRC_SPDIF
)
1213 listid_to_enum
[0] = ITEM_VOLUME_D
;
1214 #if CONFIG_CODEC == SWCODEC
1215 listid_to_enum
[1] = ITEM_SAMPLERATE_D
;
1216 listid_to_enum
[2] = ITEM_FILENAME_D
;
1218 listid_to_enum
[1] = ITEM_FILENAME_D
;
1221 gui_synclist_set_nb_items(&lists
, ITEM_COUNT_D
); /* spdif */
1225 if(HAVE_MIC_REC_((global_settings
.rec_source
== AUDIO_SRC_MIC
) || )
1226 (global_settings
.rec_channels
== 1))
1228 listid_to_enum
[0] = ITEM_VOLUME_M
;
1229 listid_to_enum
[1] = ITEM_GAIN_M
;
1231 listid_to_enum
[2] = ITEM_AGC_MODE_M
;
1232 listid_to_enum
[3] = ITEM_AGC_MAXDB_M
;
1233 listid_to_enum
[4] = ITEM_FILENAME_M
;
1235 listid_to_enum
[2] = ITEM_FILENAME_M
;
1237 gui_synclist_set_nb_items(&lists
, ITEM_COUNT_M
); /* mono */
1241 listid_to_enum
[0] = ITEM_VOLUME
;
1242 listid_to_enum
[1] = ITEM_GAIN
;
1243 listid_to_enum
[2] = ITEM_GAIN_L
;
1244 listid_to_enum
[3] = ITEM_GAIN_R
;
1246 listid_to_enum
[4] = ITEM_AGC_MODE
;
1247 listid_to_enum
[5] = ITEM_AGC_MAXDB
;
1248 listid_to_enum
[6] = ITEM_FILENAME
;
1250 listid_to_enum
[4] = ITEM_FILENAME
;
1252 gui_synclist_set_nb_items(&lists
, ITEM_COUNT
); /* stereo */
1255 gui_synclist_draw(&lists
);
1256 } /* if(done < 0) */
1258 audio_stat
= audio_status();
1260 #if (CONFIG_LED == LED_REAL)
1263 * Flash the LED while waiting to record. Turn it on while
1266 if(audio_stat
& AUDIO_STATUS_RECORD
)
1268 if (audio_stat
& AUDIO_STATUS_PAUSE
)
1270 if (--led_countdown
<= 0)
1272 led_state
= !led_state
;
1279 /* trigger is on in status TRIG_READY (no check needed) */
1285 int trig_stat
= peak_meter_trigger_status();
1287 * other trigger stati than trig_off and trig_steady
1288 * already imply that we are recording.
1290 if (trig_stat
== TRIG_STEADY
)
1292 if (--led_countdown
<= 0)
1294 led_state
= !led_state
;
1301 /* trigger is on in status TRIG_READY (no check needed) */
1305 #endif /* CONFIG_LED */
1307 /* Wait for a button a while (HZ/10) drawing the peak meter */
1308 button
= peak_meter_draw_get_btn(CONTEXT_RECSCREEN
,
1310 screen_update
, vp_top
);
1311 if (last_audio_stat
!= audio_stat
)
1313 if (audio_stat
& AUDIO_STATUS_RECORD
)
1315 rec_status
|= RCSTAT_HAVE_RECORDED
;
1317 last_audio_stat
= audio_stat
;
1321 if (recording_start_automatic
)
1323 /* simulate a button press */
1324 button
= ACTION_REC_PAUSE
;
1325 recording_start_automatic
= false;
1328 /* let list handle the button */
1329 gui_synclist_do_button(&lists
, &button
, LIST_WRAP_UNLESS_HELD
);
1334 case ACTION_SETTINGS_INC
:
1335 case ACTION_SETTINGS_INCREPEAT
:
1336 switch (listid_to_enum
[gui_synclist_get_sel_pos(&lists
)])
1339 global_settings
.volume
++;
1344 if(global_settings
.rec_source
== AUDIO_SRC_MIC
)
1346 if(global_settings
.rec_mic_gain
<
1347 sound_max(SOUND_MIC_GAIN
))
1348 global_settings
.rec_mic_gain
++;
1353 if(global_settings
.rec_left_gain
<
1354 sound_max(SOUND_LEFT_GAIN
))
1355 global_settings
.rec_left_gain
++;
1356 if(global_settings
.rec_right_gain
<
1357 sound_max(SOUND_RIGHT_GAIN
))
1358 global_settings
.rec_right_gain
++;
1362 if(global_settings
.rec_left_gain
<
1363 sound_max(SOUND_LEFT_GAIN
))
1364 global_settings
.rec_left_gain
++;
1367 if(global_settings
.rec_right_gain
<
1368 sound_max(SOUND_RIGHT_GAIN
))
1369 global_settings
.rec_right_gain
++;
1373 agc_preset
= MIN(agc_preset
+ 1, AGC_MODE_SIZE
);
1374 agc_enable
= (agc_preset
!= 0);
1376 if (global_settings
.rec_source
== AUDIO_SRC_MIC
) {
1377 global_settings
.rec_agc_preset_mic
= agc_preset
;
1378 agc_maxgain
= global_settings
.rec_agc_maxgain_mic
;
1382 global_settings
.rec_agc_preset_line
= agc_preset
;
1383 agc_maxgain
= global_settings
.rec_agc_maxgain_line
;
1386 case ITEM_AGC_MAXDB
:
1388 if (global_settings
.rec_source
== AUDIO_SRC_MIC
)
1390 agc_maxgain
= MIN(agc_maxgain
+ 1,
1391 sound_max(SOUND_MIC_GAIN
));
1392 global_settings
.rec_agc_maxgain_mic
= agc_maxgain
;
1397 agc_maxgain
= MIN(agc_maxgain
+ 1,
1398 sound_max(SOUND_LEFT_GAIN
));
1399 global_settings
.rec_agc_maxgain_line
= agc_maxgain
;
1402 #endif /* HAVE_AGC */
1405 update_countdown
= 0; /* Update immediately */
1407 case ACTION_SETTINGS_DEC
:
1408 case ACTION_SETTINGS_DECREPEAT
:
1409 switch (listid_to_enum
[gui_synclist_get_sel_pos(&lists
)])
1412 global_settings
.volume
--;
1417 if(global_settings
.rec_source
== AUDIO_SRC_MIC
)
1419 if(global_settings
.rec_mic_gain
>
1420 sound_min(SOUND_MIC_GAIN
))
1421 global_settings
.rec_mic_gain
--;
1426 if(global_settings
.rec_left_gain
>
1427 sound_min(SOUND_LEFT_GAIN
))
1428 global_settings
.rec_left_gain
--;
1429 if(global_settings
.rec_right_gain
>
1430 sound_min(SOUND_RIGHT_GAIN
))
1431 global_settings
.rec_right_gain
--;
1435 if(global_settings
.rec_left_gain
>
1436 sound_min(SOUND_LEFT_GAIN
))
1437 global_settings
.rec_left_gain
--;
1440 if(global_settings
.rec_right_gain
>
1441 sound_min(SOUND_RIGHT_GAIN
))
1442 global_settings
.rec_right_gain
--;
1446 agc_preset
= MAX(agc_preset
- 1, 0);
1447 agc_enable
= (agc_preset
!= 0);
1449 if (global_settings
.rec_source
== AUDIO_SRC_MIC
) {
1450 global_settings
.rec_agc_preset_mic
= agc_preset
;
1451 agc_maxgain
= global_settings
.rec_agc_maxgain_mic
;
1455 global_settings
.rec_agc_preset_line
= agc_preset
;
1456 agc_maxgain
= global_settings
.rec_agc_maxgain_line
;
1459 case ITEM_AGC_MAXDB
:
1461 if (global_settings
.rec_source
== AUDIO_SRC_MIC
)
1463 agc_maxgain
= MAX(agc_maxgain
- 1,
1464 sound_min(SOUND_MIC_GAIN
));
1465 global_settings
.rec_agc_maxgain_mic
= agc_maxgain
;
1469 agc_maxgain
= MAX(agc_maxgain
- 1,
1470 sound_min(SOUND_LEFT_GAIN
));
1471 global_settings
.rec_agc_maxgain_line
= agc_maxgain
;
1474 #endif /* HAVE_AGC */
1477 update_countdown
= 0; /* Update immediately */
1479 case ACTION_STD_CANCEL
:
1480 /* turn off the trigger */
1481 peak_meter_trigger(false);
1482 peak_meter_set_trigger_listener(NULL
);
1484 if(audio_stat
& AUDIO_STATUS_RECORD
)
1486 rec_command(RECORDING_CMD_STOP
);
1490 #if CONFIG_CODEC != SWCODEC
1491 peak_meter_playback(true);
1492 peak_meter_enabled
= false;
1496 update_countdown
= 0; /* Update immediately */
1498 #ifdef HAVE_REMOTE_LCD
1499 case ACTION_REC_LCD
:
1500 /* this feature exists for some h1x0/h3x0 targets that suffer
1501 from noise caused by remote LCD updates
1502 NOTE 1: this will leave the list on the remote
1503 NOTE 2: to be replaced by a global LCD_off() routine */
1504 if(remote_display_on
)
1506 /* switch to single screen, leave message on remote */
1508 screens
[1].clear_viewport();
1509 screens
[1].puts(0, 0, str(LANG_REMOTE_LCD_OFF
));
1510 screens
[1].puts(0, 1, str(LANG_REMOTE_LCD_ON
));
1511 screens
[1].update_viewport();
1515 /* remote switched on again */
1517 screen_update
= NB_SCREENS
;
1519 remote_display_on
= !remote_display_on
; /* toggle */
1520 update_countdown
= 0; /* Update immediately */
1523 case ACTION_REC_PAUSE
:
1524 case ACTION_REC_NEWFILE
:
1525 /* Only act if the mpeg is stopped */
1526 if(!(audio_stat
& AUDIO_STATUS_RECORD
))
1528 /* is this manual or triggered recording? */
1529 if ((global_settings
.rec_trigger_mode
== TRIG_MODE_OFF
) ||
1530 (peak_meter_trigger_status() != TRIG_OFF
))
1532 /* manual recording */
1533 rec_status
|= RCSTAT_HAVE_RECORDED
;
1534 rec_command(RECORDING_CMD_START
);
1536 if (global_settings
.talk_menu
)
1538 /* no voice possible here, but a beep */
1539 audio_beep(HZ
/2); /* longer beep on start */
1542 /* this is triggered recording */
1545 /* we don't start recording now, but enable the
1546 trigger and let the callback function
1547 trigger_listener control when the recording starts */
1548 peak_meter_trigger(true);
1549 peak_meter_set_trigger_listener(&trigger_listener
);
1554 /*if new file button pressed, start new file */
1555 if (button
== ACTION_REC_NEWFILE
)
1557 rec_command(RECORDING_CMD_START_NEWFILE
);
1561 /* if pause button pressed, pause or resume */
1563 if(audio_stat
& AUDIO_STATUS_PAUSE
)
1565 rec_command(RECORDING_CMD_RESUME
);
1566 if (global_settings
.talk_menu
)
1568 /* no voice possible here, but a beep */
1569 audio_beep(HZ
/4); /* short beep on resume */
1574 rec_command(RECORDING_CMD_PAUSE
);
1578 update_countdown
= 0; /* Update immediately */
1580 case ACTION_STD_MENU
:
1581 #if CONFIG_CODEC == SWCODEC
1582 if(!(audio_stat
& AUDIO_STATUS_RECORD
))
1584 if(audio_stat
!= AUDIO_STATUS_RECORD
)
1587 #if (CONFIG_LED == LED_REAL)
1588 /* led is restored at begin of loop / end of function */
1591 viewportmanager_set_statusbar(oldbars
);
1592 if (recording_menu(no_source
))
1595 rec_status
|= RCSTAT_BEEN_IN_USB_MODE
;
1596 #ifdef HAVE_FMRADIO_REC
1597 radio_status
= FMRADIO_OFF
;
1603 /* the init is now done at the beginning of the loop */
1605 viewportmanager_set_statusbar(recbars
);
1609 #if CONFIG_KEYPAD == RECORDER_PAD
1611 if(audio_stat
!= AUDIO_STATUS_RECORD
)
1613 #if (CONFIG_LED == LED_REAL)
1614 /* led is restored at begin of loop / end of function */
1617 viewportmanager_set_statusbar(oldbars
);
1618 if (f2_rec_screen())
1620 rec_status
|= RCSTAT_HAVE_RECORDED
;
1624 update_countdown
= 0; /* Update immediately */
1625 viewportmanager_set_statusbar(recbars
);
1630 if(audio_stat
& AUDIO_STATUS_RECORD
)
1632 rec_command(RECORDING_CMD_START_NEWFILE
);
1637 #if (CONFIG_LED == LED_REAL)
1638 /* led is restored at begin of loop / end of function */
1641 viewportmanager_set_statusbar(oldbars
);
1642 if (f3_rec_screen())
1644 rec_status
|= RCSTAT_HAVE_RECORDED
;
1648 update_countdown
= 0; /* Update immediately */
1649 viewportmanager_set_statusbar(recbars
);
1652 #endif /* CONFIG_KEYPAD == RECORDER_PAD */
1654 case SYS_USB_CONNECTED
:
1655 /* Only accept USB connection when not recording */
1656 if(!(audio_stat
& AUDIO_STATUS_RECORD
))
1659 screens
[i
].set_viewport(NULL
);
1660 default_event_handler(SYS_USB_CONNECTED
);
1662 rec_status
|= RCSTAT_BEEN_IN_USB_MODE
;
1663 #ifdef HAVE_FMRADIO_REC
1664 radio_status
= FMRADIO_OFF
;
1668 } /*switch(button)*/
1671 peak_read
= !peak_read
;
1672 if (peak_read
) { /* every 2nd run of loop */
1674 peak_valid
= read_peak_levels(&peak_l
, &peak_r
, &balance
);
1677 /* Handle AGC every 200ms when enabled and peak data is valid */
1678 if (peak_read
&& agc_enable
&& peak_valid
)
1679 auto_gain_control(&peak_l
, &peak_r
, &balance
);
1682 seconds
= audio_recorded_time() / HZ
;
1684 /* start of vp_top drawing */
1685 if(update_countdown
-- == 0 || seconds
> last_seconds
)
1687 unsigned int dseconds
, dhours
, dminutes
;
1688 unsigned long num_recorded_bytes
, dsize
, dmb
;
1693 screens
[i
].set_viewport(&vp_top
[i
]);
1694 screens
[i
].clear_viewport();
1696 update_countdown
= 5;
1697 last_seconds
= seconds
;
1699 dseconds
= rec_timesplit_seconds();
1700 dsize
= rec_sizesplit_bytes();
1701 num_recorded_bytes
= audio_num_recorded_bytes();
1703 #if CONFIG_CODEC == SWCODEC
1704 if ((audio_stat
& AUDIO_STATUS_WARNING
)
1705 && (warning_counter
++ % WARNING_PERIOD
) < WARNING_PERIOD
/2)
1707 /* Switch back and forth displaying warning on first available
1708 line to ensure visibility - the motion should also help
1710 /* Don't use language string unless agreed upon to make this
1711 method permanent - could do something in the statusbar */
1712 snprintf(buf
, sizeof(buf
), "Warning: %08X",
1713 pcm_rec_get_warnings());
1716 #endif /* CONFIG_CODEC == SWCODEC */
1717 if ((global_settings
.rec_sizesplit
) &&
1718 (global_settings
.rec_split_method
))
1720 dmb
= dsize
/1024/1024;
1721 snprintf(buf
, sizeof(buf
), "%s %dMB",
1722 str(LANG_SPLIT_SIZE
), dmb
);
1726 hours
= seconds
/ 3600;
1727 minutes
= (seconds
- (hours
* 3600)) / 60;
1728 snprintf(buf
, sizeof(buf
), "%s %02d:%02d:%02d",
1729 str(LANG_RECORDING_TIME
),
1730 hours
, minutes
, seconds
%60);
1733 FOR_NB_ACTIVE_SCREENS(i
)
1734 screens
[i
].puts(0, 0, buf
);
1736 if(audio_stat
& AUDIO_STATUS_PRERECORD
)
1738 snprintf(buf
, sizeof(buf
), "%s...",
1739 str(LANG_RECORD_PRERECORD
));
1743 /* Display the split interval if the record timesplit
1745 if ((global_settings
.rec_timesplit
) &&
1746 !(global_settings
.rec_split_method
))
1748 /* Display the record timesplit interval rather
1749 than the file size if the record timer is active */
1750 dhours
= dseconds
/ 3600;
1751 dminutes
= (dseconds
- (dhours
* 3600)) / 60;
1752 snprintf(buf
, sizeof(buf
), "%s %02d:%02d",
1753 str(LANG_RECORDING_TIMESPLIT_REC
),
1758 output_dyn_value(buf2
, sizeof buf2
,
1761 snprintf(buf
, sizeof(buf
), "%s %s",
1762 str(LANG_RECORDING_SIZE
), buf2
);
1766 FOR_NB_ACTIVE_SCREENS(i
)
1767 screens
[i
].puts(0, 1, buf
);
1769 /* We will do file splitting regardless, either at the end of
1770 a split interval, or when the filesize approaches the 2GB
1771 FAT file size (compatibility) limit. */
1772 if ((audio_stat
&& !(global_settings
.rec_split_method
)
1773 && global_settings
.rec_timesplit
&& (seconds
>= dseconds
))
1774 || (audio_stat
&& global_settings
.rec_split_method
1775 && global_settings
.rec_sizesplit
1776 && (num_recorded_bytes
>= dsize
))
1777 || (num_recorded_bytes
>= MAX_FILE_SIZE
))
1779 if (!(global_settings
.rec_split_type
)
1780 || (num_recorded_bytes
>= MAX_FILE_SIZE
))
1782 rec_command(RECORDING_CMD_START_NEWFILE
);
1787 peak_meter_trigger(false);
1788 peak_meter_set_trigger_listener(NULL
);
1789 if( global_settings
.rec_split_type
== 1)
1790 rec_command(RECORDING_CMD_STOP
);
1792 rec_command(RECORDING_CMD_STOP_SHUTDOWN
);
1794 update_countdown
= 0;
1797 /* draw the clipcounter just in front of the peakmeter */
1798 if(global_settings
.peak_meter_clipcounter
)
1801 snprintf(clpstr
, 32, "%4d", pm_get_clipcount());
1802 FOR_NB_ACTIVE_SCREENS(i
)
1804 if(!compact_view
[i
])
1805 screens
[i
].puts(0, 2,str(LANG_PM_CLIPCOUNT
));
1806 screens
[i
].puts(0, compact_view
[i
] ? 2 : 3, clpstr
);
1814 /* draw the trigger status */
1815 if (peak_meter_trigger_status() != TRIG_OFF
)
1817 peak_meter_draw_trig(pm_x
, trig_ypos
, trig_width
,
1819 FOR_NB_ACTIVE_SCREENS(i
)
1820 screens
[i
].update_viewport_rect(pm_x
[i
], trig_ypos
[i
],
1821 trig_width
[i
] + 2, TRIG_HEIGHT
);
1826 if (global_settings
.rec_source
== AUDIO_SRC_MIC
)
1828 if(agc_maxgain
< (global_settings
.rec_mic_gain
))
1829 change_recording_gain(false, true, true);
1834 if(agc_maxgain
< (global_settings
.rec_left_gain
))
1835 change_recording_gain(false, true, false);
1836 if(agc_maxgain
< (global_settings
.rec_right_gain
))
1837 change_recording_gain(false, false, true);
1839 #endif /* HAVE_AGC */
1841 #if CONFIG_CODEC == SWCODEC
1842 #ifdef HAVE_SPDIF_REC
1843 if((global_settings
.rec_source
== AUDIO_SRC_SPDIF
) &&
1844 (prev_sample_rate
!= pcm_rec_sample_rate()))
1846 /* spdif samplerate changed */
1847 prev_sample_rate
= pcm_rec_sample_rate();
1855 /* update_list is set whenever content changes */
1856 update_list
= false;
1857 gui_synclist_draw(&lists
);
1860 /* draw peakmeter again (check if this can be removed) */
1861 FOR_NB_ACTIVE_SCREENS(i
)
1863 screens
[i
].set_viewport(&vp_top
[i
]);
1864 peak_meter_screen(&screens
[i
], pm_x
[i
], pm_y
[i
], pm_h
[i
]);
1865 screens
[i
].update();
1867 } /* display update every second */
1869 if(audio_stat
& AUDIO_STATUS_ERROR
)
1873 } /* end while(!done) */
1875 audio_stat
= audio_status();
1876 if (audio_stat
& AUDIO_STATUS_ERROR
)
1878 splash(0, str(LANG_DISK_FULL
));
1881 screens
[i
].update();
1883 #if CONFIG_CODEC == SWCODEC
1884 /* stop recording - some players like H10 freeze otherwise
1885 TO DO: find out why it freezes and fix properly */
1886 rec_command(RECORDING_CMD_STOP
);
1887 audio_close_recording();
1890 audio_error_clear();
1894 if (action_userabort(TIMEOUT_NOBLOCK
))
1901 #if CONFIG_CODEC == SWCODEC
1902 rec_command(RECORDING_CMD_STOP
);
1903 audio_close_recording();
1905 #ifdef HAVE_FMRADIO_REC
1906 if (radio_status
!= FMRADIO_OFF
)
1907 /* Restore radio playback - radio_status should be unchanged if started
1908 through fm radio screen (barring usb connect) */
1909 rec_set_source(AUDIO_SRC_FMRADIO
, (radio_status
& FMRADIO_PAUSED
) ?
1910 SRCF_FMRADIO_PAUSED
: SRCF_FMRADIO_PLAYING
);
1913 /* Go back to playback mode */
1914 rec_set_source(AUDIO_SRC_PLAYBACK
, SRCF_PLAYBACK
);
1916 /* restore talking */
1917 talk_disable(false);
1918 #else /* !SWCODEC */
1919 audio_init_playback();
1920 #endif /* CONFIG_CODEC == SWCODEC */
1922 /* make sure the trigger is really turned off */
1923 peak_meter_trigger(false);
1924 peak_meter_set_trigger_listener(NULL
);
1926 rec_status
&= ~RCSTAT_IN_RECSCREEN
;
1927 sound_settings_apply();
1929 viewportmanager_set_statusbar(oldbars
);
1931 screens
[i
].setfont(FONT_UI
);
1933 /* if the directory was created or recording happened, make sure the
1934 browser is updated */
1935 if (rec_status
& (RCSTAT_CREATED_DIRECTORY
| RCSTAT_HAVE_RECORDED
))
1938 #if (CONFIG_STORAGE & STORAGE_ATA) && (CONFIG_LED == LED_REAL) \
1939 && !defined(SIMULATOR)
1940 ata_set_led_enabled(true);
1945 return (rec_status
& RCSTAT_BEEN_IN_USB_MODE
) != 0;
1946 } /* recording_screen */
1948 #if CONFIG_KEYPAD == RECORDER_PAD
1949 static bool f2_rec_screen(void)
1951 static const char* const freq_str
[6] =
1966 struct audio_recording_options rec_options
;
1970 screens
[i
].setfont(FONT_SYSFIXED
);
1971 screens
[i
].getstringsize("A",&w
,&h
);
1975 const char* ptr
=NULL
;
1979 screens
[i
].clear_display();
1981 /* Recording quality */
1982 screens
[i
].putsxy(0, LCD_HEIGHT
/2 - h
*2,
1983 str(LANG_SYSFONT_RECORDING_QUALITY
));
1986 snprintf(buf
, sizeof(buf
), "%d", global_settings
.rec_quality
);
1989 screens
[i
].putsxy(0, LCD_HEIGHT
/2-h
, buf
);
1990 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_FastBackward
],
1991 LCD_WIDTH
/2 - 16, LCD_HEIGHT
/2 - 4, 7, 8);
1995 snprintf(buf
, sizeof buf
, "%s:", str(LANG_SYSFONT_RECORDING_FREQUENCY
));
1996 ptr
= freq_str
[global_settings
.rec_frequency
];
1999 screens
[i
].getstringsize(buf
,&w
,&h
);
2000 screens
[i
].putsxy((LCD_WIDTH
-w
)/2, LCD_HEIGHT
- h
*2, buf
);
2001 screens
[i
].getstringsize(ptr
, &w
, &h
);
2002 screens
[i
].putsxy((LCD_WIDTH
-w
)/2, LCD_HEIGHT
- h
, ptr
);
2003 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_DownArrow
],
2004 LCD_WIDTH
/2 - 3, LCD_HEIGHT
- h
*3, 7, 8);
2008 switch ( global_settings
.rec_channels
) {
2010 ptr
= str(LANG_SYSFONT_CHANNEL_STEREO
);
2014 ptr
= str(LANG_SYSFONT_CHANNEL_MONO
);
2020 screens
[i
].getstringsize(str(LANG_SYSFONT_CHANNELS
), &w
, &h
);
2021 screens
[i
].putsxy(LCD_WIDTH
- w
, LCD_HEIGHT
/2 - h
*2,
2022 str(LANG_SYSFONT_CHANNELS
));
2023 screens
[i
].getstringsize(str(LANG_SYSFONT_MODE
), &w
, &h
);
2024 screens
[i
].putsxy(LCD_WIDTH
- w
, LCD_HEIGHT
/2 - h
,
2025 str(LANG_SYSFONT_MODE
));
2026 screens
[i
].getstringsize(ptr
, &w
, &h
);
2027 screens
[i
].putsxy(LCD_WIDTH
- w
, LCD_HEIGHT
/2, ptr
);
2028 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_FastForward
],
2029 LCD_WIDTH
/2 + 8, LCD_HEIGHT
/2 - 4, 7, 8);
2031 screens
[i
].update();
2034 button
= button_get(true);
2037 case BUTTON_F2
| BUTTON_LEFT
:
2038 global_settings
.rec_quality
++;
2039 if(global_settings
.rec_quality
> 7)
2040 global_settings
.rec_quality
= 0;
2045 case BUTTON_F2
| BUTTON_DOWN
:
2046 global_settings
.rec_frequency
++;
2047 if(global_settings
.rec_frequency
> 5)
2048 global_settings
.rec_frequency
= 0;
2053 case BUTTON_F2
| BUTTON_RIGHT
:
2054 global_settings
.rec_channels
++;
2055 if(global_settings
.rec_channels
> 1)
2056 global_settings
.rec_channels
= 0;
2060 case BUTTON_F2
| BUTTON_REL
:
2066 case BUTTON_F2
| BUTTON_REPEAT
:
2071 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
2077 rec_init_recording_options(&rec_options
);
2078 rec_set_recording_options(&rec_options
);
2084 screens
[i
].setfont(FONT_UI
);
2089 static bool f3_rec_screen(void)
2097 str(LANG_SYSFONT_RECORDING_SRC_MIC
),
2098 str(LANG_SYSFONT_LINE_IN
),
2099 str(LANG_SYSFONT_RECORDING_SRC_DIGITAL
)
2101 struct audio_recording_options rec_options
;
2105 screens
[i
].setfont(FONT_SYSFIXED
);
2106 screens
[i
].getstringsize("A",&w
,&h
);
2111 ptr
= src_str
[global_settings
.rec_source
];
2114 screens
[i
].clear_display();
2116 /* Recording source */
2117 screens
[i
].putsxy(0, LCD_HEIGHT
/2 - h
*2,
2118 str(LANG_SYSFONT_RECORDING_SOURCE
));
2120 screens
[i
].getstringsize(ptr
, &w
, &h
);
2121 screens
[i
].putsxy(0, LCD_HEIGHT
/2-h
, ptr
);
2122 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_FastBackward
],
2123 LCD_WIDTH
/2 - 16, LCD_HEIGHT
/2 - 4, 7, 8);
2127 ptr
= str(LANG_SYSFONT_RECORD_TRIGGER
);
2130 screens
[i
].getstringsize(ptr
,&w
,&h
);
2131 screens
[i
].putsxy((LCD_WIDTH
-w
)/2, LCD_HEIGHT
- h
*2, ptr
);
2132 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_DownArrow
],
2133 LCD_WIDTH
/2 - 3, LCD_HEIGHT
- h
*3, 7, 8);
2135 screens
[i
].update();
2138 button
= button_get(true);
2141 case BUTTON_F3
| BUTTON_DOWN
:
2144 settings_apply_trigger();
2150 case BUTTON_F3
| BUTTON_LEFT
:
2151 global_settings
.rec_source
++;
2152 if(global_settings
.rec_source
> AUDIO_SRC_MAX
)
2153 global_settings
.rec_source
= 0;
2157 case BUTTON_F3
| BUTTON_REL
:
2163 case BUTTON_F3
| BUTTON_REPEAT
:
2168 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
2174 rec_init_recording_options(&rec_options
);
2175 rec_set_recording_options(&rec_options
);
2181 screens
[i
].setfont(FONT_UI
);
2185 #endif /* CONFIG_KEYPAD == RECORDER_PAD */
2187 #if CONFIG_CODEC == SWCODEC
2188 void audio_beep(int duration
)
2195 /* stubs for recording sim */
2196 void audio_init_recording(unsigned int buffer_offset
)
2198 buffer_offset
= buffer_offset
;
2201 void audio_close_recording(void)
2205 unsigned long pcm_rec_get_warnings(void)
2210 unsigned long pcm_rec_sample_rate(void)
2215 unsigned long audio_recorded_time(void)
2220 unsigned long audio_num_recorded_bytes(void)
2222 return 5 * 1024 * 1024;
2225 void rec_set_source(int source
, unsigned flags
)
2231 void audio_set_recording_options(struct audio_recording_options
*options
)
2236 void audio_set_recording_gain(int left
, int right
, int type
)
2243 void audio_record(const char *filename
)
2245 filename
= filename
;
2248 void audio_new_file(const char *filename
)
2250 filename
= filename
;
2253 void audio_stop_recording(void)
2257 void audio_pause_recording(void)
2261 void audio_resume_recording(void)
2265 #endif /* #ifdef SIMULATOR */
2266 #endif /* #ifdef CONFIG_CODEC == SWCODEC */
2268 #endif /* HAVE_RECORDING */