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 ****************************************************************************/
32 #if CONFIG_CODEC == SWCODEC
34 #include "pcm_playback.h"
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"
68 #include "screen_access.h"
72 /* This array holds the record timer interval lengths, in seconds */
73 static const unsigned long rec_timer_seconds
[] =
87 10L*60*60, /* 10:00 */
88 12L*60*60, /* 12:00 */
89 18L*60*60, /* 18:00 */
93 static unsigned int rec_timesplit_seconds(void)
95 return rec_timer_seconds
[global_settings
.rec_timesplit
];
98 /* This array holds the record size interval lengths, in bytes */
99 static const unsigned long rec_size_bytes
[] =
102 5*1024*1024, /* 5MB */
103 10*1024*1024, /* 10MB */
104 15*1024*1024, /* 15MB */
105 32*1024*1024, /* 32MB */
106 64*1024*1024, /* 64MB */
107 75*1024*1024, /* 75MB */
108 100*1024*1024, /* 100MB */
109 128*1024*1024, /* 128MB */
110 256*1024*1024, /* 256MB */
111 512*1024*1024, /* 512MB */
112 650*1024*1024, /* 650MB */
113 700*1024*1024, /* 700MB */
114 1024*1024*1024, /* 1GB */
115 1536*1024*1024, /* 1.5GB */
116 1792*1024*1024, /* 1.75GB */
119 static unsigned long rec_sizesplit_bytes(void)
121 return rec_size_bytes
[global_settings
.rec_sizesplit
];
124 * Time strings used for the trigger durations.
125 * Keep synchronous to trigger_times in settings_apply_trigger
127 const char * const trig_durations
[TRIG_DURATION_COUNT
] =
129 "0s", "1s", "2s", "5s",
130 "10s", "15s", "20s", "25s", "30s",
131 "1min", "2min", "5min", "10min"
134 void settings_apply_trigger(void)
136 /* Keep synchronous to trig_durations and trig_durations_conf*/
137 static const long trigger_times
[TRIG_DURATION_COUNT
] = {
139 10*HZ
, 15*HZ
, 20*HZ
, 25*HZ
, 30*HZ
,
140 60*HZ
, 2*60*HZ
, 5*60*HZ
, 10*60*HZ
143 peak_meter_define_trigger(
144 global_settings
.rec_start_thres
,
145 trigger_times
[global_settings
.rec_start_duration
],
146 MIN(trigger_times
[global_settings
.rec_start_duration
] / 2, 2*HZ
),
147 global_settings
.rec_stop_thres
,
148 trigger_times
[global_settings
.rec_stop_postrec
],
149 trigger_times
[global_settings
.rec_stop_gap
]
152 /* recording screen status flags */
153 enum rec_status_flags
155 RCSTAT_IN_RECSCREEN
= 0x00000001,
156 RCSTAT_BEEN_IN_USB_MODE
= 0x00000002,
157 RCSTAT_CREATED_DIRECTORY
= 0x00000004,
158 RCSTAT_HAVE_RECORDED
= 0x00000008,
161 static int rec_status
= 0;
163 bool in_recording_screen(void)
165 return (rec_status
& RCSTAT_IN_RECSCREEN
) != 0;
168 #define PM_HEIGHT ((LCD_HEIGHT >= 72) ? 2 : 1)
170 #if CONFIG_KEYPAD == RECORDER_PAD
171 static bool f2_rec_screen(void);
172 static bool f3_rec_screen(void);
175 #define MAX_FILE_SIZE 0x7F800000 /* 2 GB - 4 MB */
177 static int screen_update
= NB_SCREENS
;
178 #ifdef HAVE_REMOTE_LCD
179 static bool remote_display_on
= true;
182 /** File name creation **/
184 /* current file number to assist in creating unique numbered filenames
185 without actually having to create the file on disk */
186 static int file_number
= -1;
187 #endif /* CONFIG_RTC */
189 #if CONFIG_CODEC == SWCODEC
191 #define REC_FILE_ENDING(rec_format) \
192 (audio_formats[rec_format_afmt[rec_format]].ext_list)
194 #else /* CONFIG_CODEC != SWCODEC */
196 /* default record file extension for HWCODEC */
197 #define REC_FILE_ENDING(rec_format) \
198 (audio_formats[AFMT_MPA_L3].ext_list)
200 #endif /* CONFIG_CODEC == SWCODEC */
202 /* path for current file */
203 static char path_buffer
[MAX_PATH
];
205 /** Automatic Gain Control (AGC) **/
208 * peak_time is incremented every 0.2s, every 2nd run of record screen loop.
209 * hist_time is incremented every 0.5s, display update.
210 * peak_time is the counter of the peak hold read and agc process,
211 * overflow every 13 years 8-)
213 static long peak_time
= 0;
214 static long hist_time
= 0;
216 static short peak_valid_mem
[4];
217 #define BAL_MEM_SIZE 24
218 static short balance_mem
[BAL_MEM_SIZE
];
220 /* Automatic Gain Control */
221 #define AGC_MODE_SIZE 5
222 #define AGC_SAFETY_MODE 0
224 static const char* agc_preset_str
[] =
225 { "Off", "S", "L", "D", "M", "V" };
232 #define AGC_CLIP 32766
233 #define AGC_PEAK 29883 /* fast gain reduction threshold -0.8dB */
234 #define AGC_HIGH 27254 /* accelerated gain reduction threshold -1.6dB */
235 #define AGC_IMG 823 /* threshold for balance control -32dB */
236 /* autogain high level thresholds (-3dB, -7dB, -4dB, -5dB, -5dB) */
237 static const short agc_th_hi
[AGC_MODE_SIZE
] =
238 { 23197, 14637, 21156, 18428, 18426 };
239 /* autogain low level thresholds (-14dB, -11dB, -6dB, -7dB, -8dB) */
240 static const short agc_th_lo
[AGC_MODE_SIZE
] =
241 { 6538, 9235, 16422, 14636, 13045 };
242 /* autogain threshold times [1/5s] or [200ms] */
243 static const short agc_tdrop
[AGC_MODE_SIZE
] =
244 { 900, 225, 150, 60, 8 };
245 static const short agc_trise
[AGC_MODE_SIZE
] =
246 { 9000, 750, 400, 150, 20 };
247 static const short agc_tbal
[AGC_MODE_SIZE
] =
248 { 4500, 500, 300, 100, 15 };
250 static bool agc_enable
= true;
251 static short agc_preset
;
253 static int agc_left
= 0;
254 static int agc_right
= 0;
255 /* AGC time since high target volume was exceeded */
256 static short agc_droptime
= 0;
257 /* AGC time since volume fallen below low target */
258 static short agc_risetime
= 0;
259 /* AGC balance time exceeding +/- 0.7dB */
260 static short agc_baltime
= 0;
261 /* AGC maximum gain */
262 static short agc_maxgain
;
263 #endif /* HAVE_AGC */
265 static void set_gain(void)
267 if(global_settings
.rec_source
== AUDIO_SRC_MIC
)
269 audio_set_recording_gain(global_settings
.rec_mic_gain
,
274 /* AUDIO_SRC_LINEIN, AUDIO_SRC_FMRADIO, AUDIO_SRC_SPDIF */
275 audio_set_recording_gain(global_settings
.rec_left_gain
,
276 global_settings
.rec_right_gain
,
282 /* Read peak meter values & calculate balance.
283 * Returns validity of peak values.
284 * Used for automatic gain control and history diagram.
286 static bool read_peak_levels(int *peak_l
, int *peak_r
, int *balance
)
288 peak_meter_get_peakhold(peak_l
, peak_r
);
289 peak_valid_mem
[peak_time
% 3] = *peak_l
;
290 if (((peak_valid_mem
[0] == peak_valid_mem
[1]) &&
291 (peak_valid_mem
[1] == peak_valid_mem
[2])) &&
294 || ata_disk_is_active()
299 if (*peak_r
> *peak_l
)
300 balance_mem
[peak_time
% BAL_MEM_SIZE
] = (*peak_l
?
301 MIN((10000 * *peak_r
) / *peak_l
- 10000, 15118) : 15118);
303 balance_mem
[peak_time
% BAL_MEM_SIZE
] = (*peak_r
?
304 MAX(10000 - (10000 * *peak_l
) / *peak_r
, -15118) : -15118);
307 for (i
= 0; i
< BAL_MEM_SIZE
; i
++)
308 *balance
+= balance_mem
[i
];
309 *balance
= *balance
/ BAL_MEM_SIZE
;
314 /* AGC helper function to check if maximum gain is reached */
315 static bool agc_gain_is_max(bool left
, bool right
)
317 /* range -128...+108 [0.5dB] */
318 short gain_current_l
;
319 short gain_current_r
;
324 switch (global_settings
.rec_source
)
326 HAVE_LINE_REC_(case AUDIO_SRC_LINEIN
:)
327 HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO
:)
328 gain_current_l
= global_settings
.rec_left_gain
;
329 gain_current_r
= global_settings
.rec_right_gain
;
333 gain_current_l
= global_settings
.rec_mic_gain
;
334 gain_current_r
= global_settings
.rec_mic_gain
;
337 return ((left
&& (gain_current_l
>= agc_maxgain
)) ||
338 (right
&& (gain_current_r
>= agc_maxgain
)));
341 static void change_recording_gain(bool increment
, bool left
, bool right
)
343 int factor
= (increment
? 1 : -1);
345 switch (global_settings
.rec_source
)
347 HAVE_LINE_REC_(case AUDIO_SRC_LINEIN
:)
348 HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO
:)
349 if (left
) global_settings
.rec_left_gain
+= factor
;
350 if (right
) global_settings
.rec_right_gain
+= factor
;
353 global_settings
.rec_mic_gain
+= factor
;
358 * Handle automatic gain control (AGC).
359 * Change recording gain if peak_x levels are above or below
360 * target volume for specified timeouts.
362 static void auto_gain_control(int *peak_l
, int *peak_r
, int *balance
)
368 if (*peak_l
> agc_left
)
371 agc_left
-= (agc_left
- *peak_l
+ 3) >> 2;
372 if (*peak_r
> agc_right
)
375 agc_right
-= (agc_right
- *peak_r
+ 3) >> 2;
376 agc_mono
= (agc_left
+ agc_right
) / 2;
378 agc_mode
= abs(agc_preset
) - 1;
384 if (agc_mode
!= AGC_SAFETY_MODE
) {
385 /* Automatic balance control - only if not in safety mode */
386 if ((agc_left
> AGC_IMG
) && (agc_right
> AGC_IMG
))
391 agc_baltime
-= !(peak_time
% 4); /* 0.47 - 0.75dB */
392 else if (*balance
> -4125)
393 agc_baltime
--; /* 0.75 - 3.00dB */
394 else if (*balance
> -7579)
395 agc_baltime
-= 2; /* 3.00 - 4.90dB */
397 agc_baltime
-= !(peak_time
% 8); /* 4.90 - inf dB */
399 agc_baltime
-= (peak_time
% 2);
401 else if (*balance
> 556)
404 agc_baltime
+= !(peak_time
% 4);
405 else if (*balance
< 4125)
407 else if (*balance
< 7579)
410 agc_baltime
+= !(peak_time
% 8);
412 agc_baltime
+= (peak_time
% 2);
415 if ((*balance
* agc_baltime
) < 0)
418 agc_baltime
-= peak_time
% 2;
420 agc_baltime
+= peak_time
% 2;
423 increment
= ((agc_risetime
/ 2) > agc_droptime
);
425 if (agc_baltime
< -agc_tbal
[agc_mode
])
427 if (!increment
|| !agc_gain_is_max(!increment
, increment
)) {
428 change_recording_gain(increment
, !increment
, increment
);
433 else if (agc_baltime
> +agc_tbal
[agc_mode
])
435 if (!increment
|| !agc_gain_is_max(increment
, !increment
)) {
436 change_recording_gain(increment
, increment
, !increment
);
442 else if (!(hist_time
% 4))
451 /* Automatic gain control */
452 if ((agc_left
> agc_th_hi
[agc_mode
]) || (agc_right
> agc_th_hi
[agc_mode
]))
454 if ((agc_left
> AGC_CLIP
) || (agc_right
> AGC_CLIP
))
455 agc_droptime
+= agc_tdrop
[agc_mode
] /
456 (global_settings
.rec_agc_cliptime
+ 1);
457 if (agc_left
> AGC_HIGH
) {
460 if (agc_left
> AGC_PEAK
)
463 if (agc_right
> AGC_HIGH
) {
466 if (agc_right
> AGC_PEAK
)
469 if (agc_mono
> agc_th_hi
[agc_mode
])
472 agc_droptime
+= !(peak_time
% 2);
474 if (agc_droptime
>= agc_tdrop
[agc_mode
])
476 change_recording_gain(false, true, true);
481 agc_risetime
= MAX(agc_risetime
- 1, 0);
483 else if (agc_mono
< agc_th_lo
[agc_mode
])
485 if (agc_mono
< (agc_th_lo
[agc_mode
] / 8))
486 agc_risetime
+= !(peak_time
% 5);
487 else if (agc_mono
< (agc_th_lo
[agc_mode
] / 2))
492 if (agc_risetime
>= agc_trise
[agc_mode
]) {
493 if ((agc_mode
!= AGC_SAFETY_MODE
) &&
494 (!agc_gain_is_max(true, true))) {
495 change_recording_gain(true, true, true);
501 agc_droptime
= MAX(agc_droptime
- 1, 0);
503 else if (!(peak_time
% 6)) /* on target level every 1.2 sec */
505 agc_risetime
= MAX(agc_risetime
- 1, 0);
506 agc_droptime
= MAX(agc_droptime
- 1, 0);
509 #endif /* HAVE_AGC */
511 static const char* const fmtstr
[] =
513 "%c%d %s", /* no decimals */
514 "%c%d.%d %s ", /* 1 decimal */
515 "%c%d.%02d %s " /* 2 decimals */
518 static char *fmt_gain(int snd
, int val
, char *str
, int len
)
524 val
= sound_val2phys(snd
, val
);
530 numdec
= sound_numdecimals(snd
);
531 unit
= sound_unit(snd
);
535 i
= val
/ (10*numdec
);
536 d
= val
% (10*numdec
);
537 snprintf(str
, len
, fmtstr
[numdec
], sign
, i
, d
, unit
);
540 snprintf(str
, len
, fmtstr
[numdec
], sign
, val
, unit
);
547 static void adjust_cursor(void)
555 switch(global_settings
.rec_source
)
562 HAVE_LINE_REC_(case AUDIO_SRC_LINEIN
:)
563 HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO
:)
570 #else /* !HAVE_AGC */
571 switch(global_settings
.rec_source
)
576 HAVE_LINE_REC_(case AUDIO_SRC_LINEIN
:)
577 HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO
:)
584 #endif /* HAVE_AGC */
586 if(cursor
> max_cursor
)
590 static bool check_dir(char *folder
)
592 DIR *dir
= opendir(folder
);
593 if (!dir
&& strcmp(folder
, "/"))
595 int rc
= mkdir(folder
);
604 /* the list below must match enum audio_sources in audio.h */
605 static const char* const prestr
[] =
607 HAVE_MIC_IN_([AUDIO_SRC_MIC
] = "R_MIC_",)
608 HAVE_LINE_REC_([AUDIO_SRC_LINEIN
] = "R_LINE_",)
609 HAVE_SPDIF_IN_([AUDIO_SRC_SPDIF
] = "R_SPDIF_",)
610 HAVE_FMRADIO_REC_([AUDIO_SRC_FMRADIO
] = "R_FM_",)
613 char *rec_create_filename(char *buffer
)
616 const char *pref
= "R_";
618 strcpy(buffer
,global_settings
.rec_directory
);
619 if (!check_dir(buffer
))
622 if((global_settings
.rec_source
> AUDIO_SRC_PLAYBACK
) &&
623 (global_settings
.rec_source
< AUDIO_NUM_SOURCES
))
625 pref
= prestr
[global_settings
.rec_source
];
628 snprintf(ext
, sizeof(ext
), ".%s",
629 REC_FILE_ENDING(global_settings
.rec_format
));
632 return create_numbered_filename(buffer
, buffer
, pref
, ext
, 4,
635 /* We'll wait at least up to the start of the next second so no duplicate
637 return create_datetime_filename(buffer
, buffer
, pref
, ext
, true);
642 /* Hit disk to get a starting filename for the type */
643 void rec_init_filename(void)
646 rec_create_filename(path_buffer
);
651 int rec_create_directory(void)
653 return check_dir(global_settings
.rec_directory
)?1:0;
656 void rec_init_recording_options(struct audio_recording_options
*options
)
658 options
->rec_source
= global_settings
.rec_source
;
659 options
->rec_frequency
= global_settings
.rec_frequency
;
660 options
->rec_channels
= global_settings
.rec_channels
;
661 options
->rec_prerecord_time
= global_settings
.rec_prerecord_time
;
662 #if CONFIG_CODEC == SWCODEC
663 options
->rec_source_flags
= 0;
664 options
->enc_config
.rec_format
= global_settings
.rec_format
;
665 global_to_encoder_config(&options
->enc_config
);
667 options
->rec_quality
= global_settings
.rec_quality
;
668 options
->rec_editable
= global_settings
.rec_editable
;
672 #if CONFIG_CODEC == SWCODEC && !defined (SIMULATOR)
673 void rec_set_source(int source
, unsigned flags
)
675 /* Set audio input source, power up/down devices */
676 audio_set_input_source(source
, flags
);
678 /* Set peakmeters for recording or reset to playback */
679 peak_meter_playback((flags
& SRCF_RECORDING
) == 0);
680 peak_meter_enabled
= true;
682 #endif /* CONFIG_CODEC == SWCODEC && !defined (SIMULATOR) */
684 void rec_set_recording_options(struct audio_recording_options
*options
)
686 #if CONFIG_CODEC != SWCODEC
687 if (global_settings
.rec_prerecord_time
)
688 talk_buffer_steal(); /* will use the mp3 buffer */
689 #else /* == SWOCODEC */
690 rec_set_source(options
->rec_source
,
691 options
->rec_source_flags
| SRCF_RECORDING
);
692 #endif /* CONFIG_CODEC != SWCODEC */
694 audio_set_recording_options(options
);
697 void rec_command(enum recording_command cmd
)
701 case RECORDING_CMD_STOP
:
702 pm_activate_clipcount(false);
703 audio_stop_recording();
705 case RECORDING_CMD_START
:
706 /* steal mp3 buffer, create unique filename and start recording */
707 pm_reset_clipcount();
708 pm_activate_clipcount(true);
709 #if CONFIG_CODEC != SWCODEC
710 talk_buffer_steal(); /* we use the mp3 buffer */
712 audio_record(rec_create_filename(path_buffer
));
714 case RECORDING_CMD_START_NEWFILE
:
715 /* create unique filename and start recording*/
716 pm_reset_clipcount();
717 pm_activate_clipcount(true); /* just to be sure */
718 audio_new_file(rec_create_filename(path_buffer
));
720 case RECORDING_CMD_PAUSE
:
721 pm_activate_clipcount(false);
722 audio_pause_recording();
724 case RECORDING_CMD_RESUME
:
725 pm_activate_clipcount(true);
726 audio_resume_recording();
731 /* used in trigger_listerner and recording_screen */
732 static unsigned int last_seconds
= 0;
735 * Callback function so that the peak meter code can send an event
736 * to this application. This function can be passed to
737 * peak_meter_set_trigger_listener in order to activate the trigger.
739 static void trigger_listener(int trigger_status
)
741 switch (trigger_status
)
744 if(!(audio_status() & AUDIO_STATUS_RECORD
))
746 rec_status
|= RCSTAT_HAVE_RECORDED
;
747 rec_command(RECORDING_CMD_START
);
748 #if CONFIG_CODEC != SWCODEC
749 /* give control to mpeg thread so that it can start
751 yield(); yield(); yield();
755 /* if we're already recording this is a retrigger */
758 if((audio_status() & AUDIO_STATUS_PAUSE
) &&
759 (global_settings
.rec_trigger_type
== 1))
761 rec_command(RECORDING_CMD_RESUME
);
763 /* New file on trig start*/
764 else if (global_settings
.rec_trigger_type
!= 2)
766 rec_command(RECORDING_CMD_START_NEWFILE
);
767 /* tell recording_screen to reset the time */
773 /* A _change_ to TRIG_READY means the current recording has stopped */
775 if(audio_status() & AUDIO_STATUS_RECORD
)
777 switch(global_settings
.rec_trigger_type
)
780 rec_command(RECORDING_CMD_STOP
);
784 rec_command(RECORDING_CMD_PAUSE
);
787 case 2: /* New file on trig stop*/
788 rec_command(RECORDING_CMD_START_NEWFILE
);
789 /* tell recording_screen to reset the time */
794 if (global_settings
.rec_trigger_mode
!= TRIG_MODE_REARM
)
796 peak_meter_set_trigger_listener(NULL
);
797 peak_meter_trigger(false);
804 bool recording_start_automatic
= false;
806 bool recording_screen(bool no_source
)
813 int update_countdown
= 1;
814 unsigned int seconds
;
817 int last_audio_stat
= -1;
819 #if CONFIG_CODEC == SWCODEC
820 int warning_counter
= 0;
821 #define WARNING_PERIOD 7
823 #ifdef HAVE_FMRADIO_REC
824 /* Radio is left on if:
825 * 1) Is was on at the start and the initial source is FM Radio
826 * 2) 1) and the source was never changed to something else
828 int radio_status
= (global_settings
.rec_source
!= AUDIO_SRC_FMRADIO
) ?
829 FMRADIO_OFF
: get_radio_status();
831 #if (CONFIG_LED == LED_REAL)
832 bool led_state
= false;
833 int led_countdown
= 2;
836 bool peak_read
= false;
837 bool peak_valid
= false;
840 bool display_agc
[NB_SCREENS
];
842 int line
[NB_SCREENS
];
844 int filename_offset
[NB_SCREENS
];
845 int pm_y
[NB_SCREENS
];
846 int trig_xpos
[NB_SCREENS
];
847 int trig_ypos
[NB_SCREENS
];
848 int trig_width
[NB_SCREENS
];
849 /* pm_x = offset pm to put clipcount in front.
850 Use lcd_getstringsize() when not using SYSFONT */
851 int pm_x
= global_settings
.peak_meter_clipcounter
? 30 : 0;
853 static const unsigned char *byte_units
[] = {
860 struct audio_recording_options rec_options
;
861 if (check_dir(global_settings
.rec_directory
) == false)
864 gui_syncsplash(0, "%s %s",
865 str(LANG_REC_DIR_NOT_WRITABLE
),
866 str(LANG_OFF_ABORT
));
867 } while (action_userabort(HZ
) == false);
871 rec_status
= RCSTAT_IN_RECSCREEN
;
873 #if (CONFIG_LED == LED_REAL) && !defined(SIMULATOR)
874 ata_set_led_enabled(false);
877 #if CONFIG_CODEC == SWCODEC
878 /* recording_menu gets messed up: so prevent manus talking */
879 talk_disable_menus();
880 /* audio_init_recording stops anything playing when it takes the audio
883 /* Yes, we use the D/A for monitoring */
884 peak_meter_enabled
= true;
885 peak_meter_playback(true);
888 audio_init_recording(0);
889 sound_set_volume(global_settings
.volume
);
892 peak_meter_get_peakhold(&peak_l
, &peak_r
);
895 rec_init_recording_options(&rec_options
);
896 rec_set_recording_options(&rec_options
);
900 if(rec_create_directory() > 0)
901 rec_status
|= RCSTAT_CREATED_DIRECTORY
;
904 /* Create new filename for recording start */
908 pm_reset_clipcount();
909 pm_activate_clipcount(false);
910 settings_apply_trigger();
913 agc_preset_str
[0] = str(LANG_SYSFONT_OFF
);
914 agc_preset_str
[1] = str(LANG_SYSFONT_AGC_SAFETY
);
915 agc_preset_str
[2] = str(LANG_SYSFONT_AGC_LIVE
);
916 agc_preset_str
[3] = str(LANG_SYSFONT_AGC_DJSET
);
917 agc_preset_str
[4] = str(LANG_SYSFONT_AGC_MEDIUM
);
918 agc_preset_str
[5] = str(LANG_SYSFONT_AGC_VOICE
);
919 if (global_settings
.rec_source
== AUDIO_SRC_MIC
) {
920 agc_preset
= global_settings
.rec_agc_preset_mic
;
921 agc_maxgain
= global_settings
.rec_agc_maxgain_mic
;
924 agc_preset
= global_settings
.rec_agc_preset_line
;
925 agc_maxgain
= global_settings
.rec_agc_maxgain_line
;
927 #endif /* HAVE_AGC */
931 screens
[i
].setfont(FONT_SYSFIXED
);
932 screens
[i
].getstringsize("M", &w
, &h
);
933 screens
[i
].setmargins(global_settings
.invert_cursor
? 0 : w
, 8);
934 filename_offset
[i
] = ((screens
[i
].height
>= 80) ? 1 : 0);
935 pm_y
[i
] = 8 + h
* (2 + filename_offset
[i
]);
938 #ifdef HAVE_REMOTE_LCD
939 if (!remote_display_on
)
941 screens
[1].clear_display();
942 snprintf(buf
, sizeof(buf
), str(LANG_REMOTE_LCD_ON
));
943 screens
[1].puts((screens
[1].width
/w
- strlen(buf
))/2 + 1,
944 screens
[1].height
/(h
*2) + 1, buf
);
946 gui_syncsplash(0, str(LANG_REMOTE_LCD_OFF
));
952 audio_stat
= audio_status();
954 #if (CONFIG_LED == LED_REAL)
957 * Flash the LED while waiting to record. Turn it on while
960 if(audio_stat
& AUDIO_STATUS_RECORD
)
962 if (audio_stat
& AUDIO_STATUS_PAUSE
)
964 if (--led_countdown
<= 0)
966 led_state
= !led_state
;
973 /* trigger is on in status TRIG_READY (no check needed) */
979 int trigStat
= peak_meter_trigger_status();
981 * other trigger stati than trig_off and trig_steady
982 * already imply that we are recording.
984 if (trigStat
== TRIG_STEADY
)
986 if (--led_countdown
<= 0)
988 led_state
= !led_state
;
995 /* trigger is on in status TRIG_READY (no check needed) */
999 #endif /* CONFIG_LED */
1001 /* Wait for a button a while (HZ/10) drawing the peak meter */
1002 button
= peak_meter_draw_get_btn(pm_x
, pm_y
, h
* PM_HEIGHT
, screen_update
);
1004 if (last_audio_stat
!= audio_stat
)
1006 if (audio_stat
& AUDIO_STATUS_RECORD
)
1008 rec_status
|= RCSTAT_HAVE_RECORDED
;
1010 last_audio_stat
= audio_stat
;
1014 if (recording_start_automatic
)
1016 /* simulate a button press */
1017 button
= ACTION_REC_PAUSE
;
1018 recording_start_automatic
= false;
1023 #ifdef HAVE_REMOTE_LCD
1024 case ACTION_REC_LCD
:
1025 if (remote_display_on
)
1027 remote_display_on
= false;
1029 screens
[1].clear_display();
1030 snprintf(buf
, sizeof(buf
), str(LANG_REMOTE_LCD_ON
));
1031 screens
[1].puts((screens
[1].width
/w
- strlen(buf
))/2 + 1,
1032 screens
[1].height
/(h
*2) + 1, buf
);
1033 screens
[1].update();
1034 gui_syncsplash(0, str(LANG_REMOTE_LCD_OFF
));
1038 remote_display_on
= true;
1039 screen_update
= NB_SCREENS
;
1043 case ACTION_STD_CANCEL
:
1044 /* turn off the trigger */
1045 peak_meter_trigger(false);
1046 peak_meter_set_trigger_listener(NULL
);
1048 if(audio_stat
& AUDIO_STATUS_RECORD
)
1050 rec_command(RECORDING_CMD_STOP
);
1054 #if CONFIG_CODEC != SWCODEC
1055 peak_meter_playback(true);
1056 peak_meter_enabled
= false;
1060 update_countdown
= 1; /* Update immediately */
1063 case ACTION_REC_PAUSE
:
1064 case ACTION_REC_NEWFILE
:
1065 /* Only act if the mpeg is stopped */
1066 if(!(audio_stat
& AUDIO_STATUS_RECORD
))
1068 /* is this manual or triggered recording? */
1069 if ((global_settings
.rec_trigger_mode
== TRIG_MODE_OFF
) ||
1070 (peak_meter_trigger_status() != TRIG_OFF
))
1072 /* manual recording */
1073 rec_status
|= RCSTAT_HAVE_RECORDED
;
1074 rec_command(RECORDING_CMD_START
);
1076 if (global_settings
.talk_menu
)
1078 /* no voice possible here, but a beep */
1079 audio_beep(HZ
/2); /* longer beep on start */
1082 /* this is triggered recording */
1085 /* we don't start recording now, but enable the
1086 trigger and let the callback function
1087 trigger_listener control when the recording starts */
1088 peak_meter_trigger(true);
1089 peak_meter_set_trigger_listener(&trigger_listener
);
1094 /*if new file button pressed, start new file */
1095 if (button
== ACTION_REC_NEWFILE
)
1097 rec_command(RECORDING_CMD_START_NEWFILE
);
1101 /* if pause button pressed, pause or resume */
1103 if(audio_stat
& AUDIO_STATUS_PAUSE
)
1105 rec_command(RECORDING_CMD_RESUME
);
1106 if (global_settings
.talk_menu
)
1108 /* no voice possible here, but a beep */
1109 audio_beep(HZ
/4); /* short beep on resume */
1114 rec_command(RECORDING_CMD_PAUSE
);
1118 update_countdown
= 1; /* Update immediately */
1121 case ACTION_STD_PREV
:
1124 update_countdown
= 1; /* Update immediately */
1127 case ACTION_STD_NEXT
:
1130 update_countdown
= 1; /* Update immediately */
1133 case ACTION_SETTINGS_INC
:
1137 global_settings
.volume
++;
1141 if(global_settings
.rec_source
== AUDIO_SRC_MIC
)
1143 if(global_settings
.rec_mic_gain
<
1144 sound_max(SOUND_MIC_GAIN
))
1145 global_settings
.rec_mic_gain
++;
1149 if(global_settings
.rec_left_gain
<
1150 sound_max(SOUND_LEFT_GAIN
))
1151 global_settings
.rec_left_gain
++;
1152 if(global_settings
.rec_right_gain
<
1153 sound_max(SOUND_RIGHT_GAIN
))
1154 global_settings
.rec_right_gain
++;
1158 if(global_settings
.rec_left_gain
<
1159 sound_max(SOUND_LEFT_GAIN
))
1160 global_settings
.rec_left_gain
++;
1163 if(global_settings
.rec_right_gain
<
1164 sound_max(SOUND_RIGHT_GAIN
))
1165 global_settings
.rec_right_gain
++;
1169 agc_preset
= MIN(agc_preset
+ 1, AGC_MODE_SIZE
);
1170 agc_enable
= (agc_preset
!= 0);
1171 if (global_settings
.rec_source
== AUDIO_SRC_MIC
) {
1172 global_settings
.rec_agc_preset_mic
= agc_preset
;
1173 agc_maxgain
= global_settings
.rec_agc_maxgain_mic
;
1175 global_settings
.rec_agc_preset_line
= agc_preset
;
1176 agc_maxgain
= global_settings
.rec_agc_maxgain_line
;
1180 if (global_settings
.rec_source
== AUDIO_SRC_MIC
)
1182 agc_maxgain
= MIN(agc_maxgain
+ 1,
1183 sound_max(SOUND_MIC_GAIN
));
1184 global_settings
.rec_agc_maxgain_mic
= agc_maxgain
;
1188 agc_maxgain
= MIN(agc_maxgain
+ 1,
1189 sound_max(SOUND_LEFT_GAIN
));
1190 global_settings
.rec_agc_maxgain_line
= agc_maxgain
;
1193 #endif /* HAVE_AGC */
1196 update_countdown
= 1; /* Update immediately */
1199 case ACTION_SETTINGS_DEC
:
1203 global_settings
.volume
--;
1207 if(global_settings
.rec_source
== AUDIO_SRC_MIC
)
1209 if(global_settings
.rec_mic_gain
>
1210 sound_min(SOUND_MIC_GAIN
))
1211 global_settings
.rec_mic_gain
--;
1215 if(global_settings
.rec_left_gain
>
1216 sound_min(SOUND_LEFT_GAIN
))
1217 global_settings
.rec_left_gain
--;
1218 if(global_settings
.rec_right_gain
>
1219 sound_min(SOUND_RIGHT_GAIN
))
1220 global_settings
.rec_right_gain
--;
1224 if(global_settings
.rec_left_gain
>
1225 sound_min(SOUND_LEFT_GAIN
))
1226 global_settings
.rec_left_gain
--;
1229 if(global_settings
.rec_right_gain
>
1230 sound_min(SOUND_RIGHT_GAIN
))
1231 global_settings
.rec_right_gain
--;
1235 agc_preset
= MAX(agc_preset
- 1, 0);
1236 agc_enable
= (agc_preset
!= 0);
1237 if (global_settings
.rec_source
== AUDIO_SRC_MIC
) {
1238 global_settings
.rec_agc_preset_mic
= agc_preset
;
1239 agc_maxgain
= global_settings
.rec_agc_maxgain_mic
;
1241 global_settings
.rec_agc_preset_line
= agc_preset
;
1242 agc_maxgain
= global_settings
.rec_agc_maxgain_line
;
1246 if (global_settings
.rec_source
== AUDIO_SRC_MIC
)
1248 agc_maxgain
= MAX(agc_maxgain
- 1,
1249 sound_min(SOUND_MIC_GAIN
));
1250 global_settings
.rec_agc_maxgain_mic
= agc_maxgain
;
1254 agc_maxgain
= MAX(agc_maxgain
- 1,
1255 sound_min(SOUND_LEFT_GAIN
));
1256 global_settings
.rec_agc_maxgain_line
= agc_maxgain
;
1259 #endif /* HAVE_AGC */
1262 update_countdown
= 1; /* Update immediately */
1265 case ACTION_STD_MENU
:
1266 #if CONFIG_CODEC == SWCODEC
1267 if(!(audio_stat
& AUDIO_STATUS_RECORD
))
1269 if(audio_stat
!= AUDIO_STATUS_RECORD
)
1272 #ifdef HAVE_FMRADIO_REC
1273 const int prev_rec_source
= global_settings
.rec_source
;
1276 #if (CONFIG_LED == LED_REAL)
1277 /* led is restored at begin of loop / end of function */
1280 if (recording_menu(no_source
))
1283 rec_status
|= RCSTAT_BEEN_IN_USB_MODE
;
1284 #ifdef HAVE_FMRADIO_REC
1285 radio_status
= FMRADIO_OFF
;
1290 #ifdef HAVE_FMRADIO_REC
1291 /* If input changes away from FM Radio, radio will
1292 remain off when recording screen closes. */
1293 if (global_settings
.rec_source
!= prev_rec_source
1294 && prev_rec_source
== AUDIO_SRC_FMRADIO
)
1295 radio_status
= FMRADIO_OFF
;
1298 #if CONFIG_CODEC == SWCODEC
1299 /* reinit after submenu exit */
1300 audio_close_recording();
1301 audio_init_recording(0);
1304 rec_init_recording_options(&rec_options
);
1305 rec_set_recording_options(&rec_options
);
1307 if(rec_create_directory() > 0)
1308 rec_status
|= RCSTAT_CREATED_DIRECTORY
;
1310 #if CONFIG_CODEC == SWCODEC && CONFIG_RTC == 0
1311 /* If format changed, a new number is required */
1312 rec_init_filename();
1316 if (global_settings
.rec_source
== AUDIO_SRC_MIC
) {
1317 agc_preset
= global_settings
.rec_agc_preset_mic
;
1318 agc_maxgain
= global_settings
.rec_agc_maxgain_mic
;
1321 agc_preset
= global_settings
.rec_agc_preset_line
;
1322 agc_maxgain
= global_settings
.rec_agc_maxgain_line
;
1328 update_countdown
= 1; /* Update immediately */
1332 screens
[i
].setfont(FONT_SYSFIXED
);
1333 screens
[i
].setmargins(
1334 global_settings
.invert_cursor
? 0 : w
, 8);
1340 #if CONFIG_KEYPAD == RECORDER_PAD
1342 if(audio_stat
!= AUDIO_STATUS_RECORD
)
1344 #if (CONFIG_LED == LED_REAL)
1345 /* led is restored at begin of loop / end of function */
1348 if (f2_rec_screen())
1350 rec_status
|= RCSTAT_HAVE_RECORDED
;
1354 update_countdown
= 1; /* Update immediately */
1359 if(audio_stat
& AUDIO_STATUS_RECORD
)
1361 rec_command(RECORDING_CMD_START_NEWFILE
);
1366 #if (CONFIG_LED == LED_REAL)
1367 /* led is restored at begin of loop / end of function */
1370 if (f3_rec_screen())
1372 rec_status
|= RCSTAT_HAVE_RECORDED
;
1376 update_countdown
= 1; /* Update immediately */
1379 #endif /* CONFIG_KEYPAD == RECORDER_PAD */
1381 case SYS_USB_CONNECTED
:
1382 /* Only accept USB connection when not recording */
1383 if(!(audio_stat
& AUDIO_STATUS_RECORD
))
1385 default_event_handler(SYS_USB_CONNECTED
);
1387 rec_status
|= RCSTAT_BEEN_IN_USB_MODE
;
1388 #ifdef HAVE_FMRADIO_REC
1389 radio_status
= FMRADIO_OFF
;
1395 default_event_handler(button
);
1400 peak_read
= !peak_read
;
1401 if (peak_read
) { /* every 2nd run of loop */
1403 peak_valid
= read_peak_levels(&peak_l
, &peak_r
, &balance
);
1406 /* Handle AGC every 200ms when enabled and peak data is valid */
1407 if (peak_read
&& agc_enable
&& peak_valid
)
1408 auto_gain_control(&peak_l
, &peak_r
, &balance
);
1412 screens
[i
].setfont(FONT_SYSFIXED
);
1414 seconds
= audio_recorded_time() / HZ
;
1417 if(update_countdown
== 0 || seconds
> last_seconds
)
1419 unsigned int dseconds
, dhours
, dminutes
;
1420 unsigned long num_recorded_bytes
, dsize
, dmb
;
1423 update_countdown
= 5;
1424 last_seconds
= seconds
;
1426 dseconds
= rec_timesplit_seconds();
1427 dsize
= rec_sizesplit_bytes();
1428 num_recorded_bytes
= audio_num_recorded_bytes();
1430 for(i
= 0; i
< screen_update
; i
++)
1431 screens
[i
].clear_display();
1433 #if CONFIG_CODEC == SWCODEC
1434 if ((audio_stat
& AUDIO_STATUS_WARNING
)
1435 && (warning_counter
++ % WARNING_PERIOD
) < WARNING_PERIOD
/2)
1437 /* Switch back and forth displaying warning on first available
1438 line to ensure visibility - the motion should also help
1440 /* Don't use language string unless agreed upon to make this
1441 method permanent - could do something in the statusbar */
1442 snprintf(buf
, sizeof(buf
), "Warning: %08X",
1443 pcm_rec_get_warnings());
1446 #endif /* CONFIG_CODEC == SWCODEC */
1447 if ((global_settings
.rec_sizesplit
) && (global_settings
.rec_split_method
))
1449 dmb
= dsize
/1024/1024;
1450 snprintf(buf
, sizeof(buf
), "%s %dMB",
1451 str(LANG_SYSFONT_SPLIT_SIZE
), dmb
);
1455 hours
= seconds
/ 3600;
1456 minutes
= (seconds
- (hours
* 3600)) / 60;
1457 snprintf(buf
, sizeof(buf
), "%s %02d:%02d:%02d",
1458 str(LANG_SYSFONT_RECORDING_TIME
),
1459 hours
, minutes
, seconds
%60);
1462 for(i
= 0; i
< screen_update
; i
++)
1463 screens
[i
].puts(0, 0, buf
);
1465 if(audio_stat
& AUDIO_STATUS_PRERECORD
)
1467 snprintf(buf
, sizeof(buf
), "%s...", str(LANG_SYSFONT_RECORD_PRERECORD
));
1471 /* Display the split interval if the record timesplit
1473 if ((global_settings
.rec_timesplit
) && !(global_settings
.rec_split_method
))
1475 /* Display the record timesplit interval rather
1476 than the file size if the record timer is
1478 dhours
= dseconds
/ 3600;
1479 dminutes
= (dseconds
- (dhours
* 3600)) / 60;
1480 snprintf(buf
, sizeof(buf
), "%s %02d:%02d",
1481 str(LANG_SYSFONT_RECORD_TIMESPLIT_REC
),
1486 output_dyn_value(buf2
, sizeof buf2
,
1489 snprintf(buf
, sizeof(buf
), "%s %s",
1490 str(LANG_SYSFONT_RECORDING_SIZE
), buf2
);
1493 for(i
= 0; i
< screen_update
; i
++)
1494 screens
[i
].puts(0, 1, buf
);
1496 for(i
= 0; i
< screen_update
; i
++)
1498 if (filename_offset
[i
] > 0)
1501 if (audio_stat
& AUDIO_STATUS_RECORD
)
1503 strncpy(filename
, path_buffer
+
1504 strlen(path_buffer
) - 12, 13);
1508 snprintf(buf
, sizeof(buf
), "%s %s",
1509 str(LANG_SYSFONT_RECORDING_FILENAME
), filename
);
1510 screens
[i
].puts(0, 2, buf
);
1514 /* We will do file splitting regardless, either at the end of
1515 a split interval, or when the filesize approaches the 2GB
1516 FAT file size (compatibility) limit. */
1517 if ((audio_stat
&& !(global_settings
.rec_split_method
)
1518 && global_settings
.rec_timesplit
&& (seconds
>= dseconds
))
1519 || (audio_stat
&& global_settings
.rec_split_method
1520 && global_settings
.rec_sizesplit
&& (num_recorded_bytes
>= dsize
))
1521 || (num_recorded_bytes
>= MAX_FILE_SIZE
))
1523 if (!(global_settings
.rec_split_type
)
1524 || (num_recorded_bytes
>= MAX_FILE_SIZE
))
1526 rec_command(RECORDING_CMD_START_NEWFILE
);
1531 peak_meter_trigger(false);
1532 peak_meter_set_trigger_listener(NULL
);
1533 rec_command(RECORDING_CMD_STOP
);
1535 update_countdown
= 1;
1538 /* draw the clipcounter just in front of the peakmeter */
1539 if(global_settings
.peak_meter_clipcounter
)
1542 snprintf(clpstr
, 32, "%4d", pm_get_clipcount());
1543 for(i
= 0; i
< screen_update
; i
++)
1546 screens
[i
].puts(0, 2 + filename_offset
[i
],
1547 str(LANG_PM_CLIPCOUNT
));
1548 screens
[i
].puts(0, 1 + PM_HEIGHT
+ filename_offset
[i
],
1553 snprintf(buf
, sizeof(buf
), "%s: %s", str(LANG_SYSFONT_VOLUME
),
1554 fmt_gain(SOUND_VOLUME
,
1555 global_settings
.volume
,
1556 buf2
, sizeof(buf2
)));
1558 if (global_settings
.invert_cursor
&& (pos
++ == cursor
))
1560 for(i
= 0; i
< screen_update
; i
++)
1561 screens
[i
].puts_style_offset(0, filename_offset
[i
] +
1562 PM_HEIGHT
+ 2, buf
, STYLE_INVERT
,0);
1566 for(i
= 0; i
< screen_update
; i
++)
1567 screens
[i
].puts(0, filename_offset
[i
] + PM_HEIGHT
+ 2, buf
);
1570 if(global_settings
.rec_source
== AUDIO_SRC_MIC
)
1572 /* Draw MIC recording gain */
1573 snprintf(buf
, sizeof(buf
), "%s:%s", str(LANG_SYSFONT_GAIN
),
1574 fmt_gain(SOUND_MIC_GAIN
,
1575 global_settings
.rec_mic_gain
,
1576 buf2
, sizeof(buf2
)));
1577 if(global_settings
.invert_cursor
&& ((1==cursor
)||(2==cursor
)))
1579 for(i
= 0; i
< screen_update
; i
++)
1580 screens
[i
].puts_style_offset(0, filename_offset
[i
] +
1581 PM_HEIGHT
+ 3, buf
, STYLE_INVERT
,0);
1585 for(i
= 0; i
< screen_update
; i
++)
1586 screens
[i
].puts(0, filename_offset
[i
] +
1587 PM_HEIGHT
+ 3, buf
);
1591 HAVE_LINE_REC_( || global_settings
.rec_source
== AUDIO_SRC_LINEIN
)
1592 HAVE_FMRADIO_REC_( || global_settings
.rec_source
== AUDIO_SRC_FMRADIO
)
1595 /* Draw LINE or FMRADIO recording gain */
1596 snprintf(buf
, sizeof(buf
), "%s:%s",
1597 str(LANG_SYSFONT_RECORDING_LEFT
),
1598 fmt_gain(SOUND_LEFT_GAIN
,
1599 global_settings
.rec_left_gain
,
1600 buf2
, sizeof(buf2
)));
1601 if(global_settings
.invert_cursor
&& ((1==cursor
)||(2==cursor
)))
1603 for(i
= 0; i
< screen_update
; i
++)
1604 screens
[i
].puts_style_offset(0, filename_offset
[i
] +
1605 PM_HEIGHT
+ 3, buf
, STYLE_INVERT
,0);
1609 for(i
= 0; i
< screen_update
; i
++)
1610 screens
[i
].puts(0, filename_offset
[i
] +
1611 PM_HEIGHT
+ 3, buf
);
1614 snprintf(buf
, sizeof(buf
), "%s:%s",
1615 str(LANG_SYSFONT_RECORDING_RIGHT
),
1616 fmt_gain(SOUND_RIGHT_GAIN
,
1617 global_settings
.rec_right_gain
,
1618 buf2
, sizeof(buf2
)));
1619 if(global_settings
.invert_cursor
&& ((1==cursor
)||(3==cursor
)))
1621 for(i
= 0; i
< screen_update
; i
++)
1622 screens
[i
].puts_style_offset(0, filename_offset
[i
] +
1623 PM_HEIGHT
+ 4, buf
, STYLE_INVERT
,0);
1627 for(i
= 0; i
< screen_update
; i
++)
1628 screens
[i
].puts(0, filename_offset
[i
] +
1629 PM_HEIGHT
+ 4, buf
);
1635 switch (global_settings
.rec_source
)
1637 HAVE_LINE_REC_(case AUDIO_SRC_LINEIN
:)
1638 HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO
:)
1645 #ifdef HAVE_SPDIF_REC
1646 case AUDIO_SRC_SPDIF
:
1651 line
[i
] = 5; /* to prevent uninitialisation
1652 warnings for line[0] */
1656 if (screens
[i
].height
< h
* (2 + filename_offset
[i
] + PM_HEIGHT
+ line
[i
]))
1659 display_agc
[i
] = false;
1662 display_agc
[i
] = true;
1664 if ((cursor
==4) || (cursor
==5))
1665 display_agc
[i
] = true;
1668 /************** AGC test info ******************
1669 snprintf(buf, sizeof(buf), "D:%d U:%d",
1670 (agc_droptime+2)/5, (agc_risetime+2)/5);
1671 lcd_putsxy(1, LCD_HEIGHT - 8, buf);
1672 snprintf(buf, sizeof(buf), "B:%d",
1674 lcd_putsxy(LCD_WIDTH/2 + 3, LCD_HEIGHT - 8, buf);
1675 ***********************************************/
1678 snprintf(buf
, sizeof(buf
), "%s: %s",
1679 str(LANG_SYSFONT_RECORDING_AGC_MAXGAIN
),
1680 fmt_gain(SOUND_LEFT_GAIN
,
1681 agc_maxgain
, buf2
, sizeof(buf2
)));
1682 else if (agc_preset
== 0)
1683 snprintf(buf
, sizeof(buf
), "%s: %s",
1684 str(LANG_SYSFONT_RECORDING_AGC_PRESET
),
1685 agc_preset_str
[agc_preset
]);
1686 else if (global_settings
.rec_source
== AUDIO_SRC_MIC
)
1687 snprintf(buf
, sizeof(buf
), "%s: %s%s",
1688 str(LANG_SYSFONT_RECORDING_AGC_PRESET
),
1689 agc_preset_str
[agc_preset
],
1690 fmt_gain(SOUND_LEFT_GAIN
,
1692 global_settings
.rec_mic_gain
,
1693 buf2
, sizeof(buf2
)));
1695 snprintf(buf
, sizeof(buf
), "%s: %s%s",
1696 str(LANG_SYSFONT_RECORDING_AGC_PRESET
),
1697 agc_preset_str
[agc_preset
],
1698 fmt_gain(SOUND_LEFT_GAIN
,
1700 (global_settings
.rec_left_gain
+
1701 global_settings
.rec_right_gain
)/2,
1702 buf2
, sizeof(buf2
)));
1704 if(global_settings
.invert_cursor
&& ((cursor
==4) || (cursor
==5)))
1706 for(i
= 0; i
< screen_update
; i
++)
1707 screens
[i
].puts_style_offset(0, filename_offset
[i
] +
1708 PM_HEIGHT
+ line
[i
], buf
, STYLE_INVERT
,0);
1711 global_settings
.rec_source
== AUDIO_SRC_MIC
1712 HAVE_LINE_REC_(|| global_settings
.rec_source
== AUDIO_SRC_LINEIN
)
1713 HAVE_FMRADIO_REC_(|| global_settings
.rec_source
== AUDIO_SRC_FMRADIO
)
1716 for(i
= 0; i
< screen_update
; i
++) {
1717 if (display_agc
[i
]) {
1718 screens
[i
].puts(0, filename_offset
[i
] +
1719 PM_HEIGHT
+ line
[i
], buf
);
1724 if (global_settings
.rec_source
== AUDIO_SRC_MIC
)
1726 if(agc_maxgain
< (global_settings
.rec_mic_gain
))
1727 change_recording_gain(false, true, true);
1731 if(agc_maxgain
< (global_settings
.rec_left_gain
))
1732 change_recording_gain(false, true, false);
1733 if(agc_maxgain
< (global_settings
.rec_right_gain
))
1734 change_recording_gain(false, false, true);
1736 #else /* !HAVE_AGC */
1738 #endif /* HAVE_AGC */
1740 if(!global_settings
.invert_cursor
) {
1744 for(i
= 0; i
< screen_update
; i
++)
1745 screen_put_cursorxy(&screens
[i
], 0,
1746 filename_offset
[i
] +
1747 PM_HEIGHT
+ 3, true);
1749 if(global_settings
.rec_source
!= AUDIO_SRC_MIC
)
1751 for(i
= 0; i
< screen_update
; i
++)
1752 screen_put_cursorxy(&screens
[i
], 0,
1753 filename_offset
[i
] +
1754 PM_HEIGHT
+ 4, true);
1758 for(i
= 0; i
< screen_update
; i
++)
1759 screen_put_cursorxy(&screens
[i
], 0,
1760 filename_offset
[i
] +
1761 PM_HEIGHT
+ 3, true);
1764 for(i
= 0; i
< screen_update
; i
++)
1765 screen_put_cursorxy(&screens
[i
], 0,
1766 filename_offset
[i
] +
1767 PM_HEIGHT
+ 4, true);
1772 for(i
= 0; i
< screen_update
; i
++)
1773 screen_put_cursorxy(&screens
[i
], 0,
1774 filename_offset
[i
] +
1775 PM_HEIGHT
+ line
[i
], true);
1777 #endif /* HAVE_AGC */
1779 for(i
= 0; i
< screen_update
; i
++)
1780 screen_put_cursorxy(&screens
[i
], 0,
1781 filename_offset
[i
] +
1782 PM_HEIGHT
+ 2, true);
1790 for(i
= 0; i
< screen_update
; i
++)
1792 gui_statusbar_draw(&(statusbars
.statusbars
[i
]), true);
1793 peak_meter_screen(&screens
[i
], pm_x
, pm_y
[i
], h
*PM_HEIGHT
);
1794 screens
[i
].update();
1797 /* draw the trigger status */
1800 trig_width
[i
] = ((screens
[i
].height
< 64) ||
1801 ((screens
[i
].height
< 72) && (PM_HEIGHT
> 1))) ?
1802 screens
[i
].width
- 14 * w
: screens
[i
].width
;
1803 trig_xpos
[i
] = screens
[i
].width
- trig_width
[i
];
1804 trig_ypos
[i
] = ((screens
[i
].height
< 72) && (PM_HEIGHT
> 1)) ?
1806 h
*(1 + filename_offset
[i
] + PM_HEIGHT
+ line
[i
]
1813 if (peak_meter_trigger_status() != TRIG_OFF
)
1815 peak_meter_draw_trig(trig_xpos
, trig_ypos
, trig_width
,
1817 for(i
= 0; i
< screen_update
; i
++){
1818 screens
[i
].update_rect(trig_xpos
[i
], trig_ypos
[i
],
1819 trig_width
[i
] + 2, TRIG_HEIGHT
);
1824 if(audio_stat
& AUDIO_STATUS_ERROR
)
1828 } /* end while(!done) */
1830 audio_stat
= audio_status();
1831 if (audio_stat
& AUDIO_STATUS_ERROR
)
1833 gui_syncsplash(0, str(LANG_SYSFONT_DISK_FULL
));
1834 gui_syncstatusbar_draw(&statusbars
, true);
1837 screens
[i
].update();
1839 audio_error_clear();
1843 if (action_userabort(TIMEOUT_NOBLOCK
))
1848 #if CONFIG_CODEC == SWCODEC
1849 rec_command(RECORDING_CMD_STOP
);
1850 audio_close_recording();
1852 #ifdef HAVE_FMRADIO_REC
1853 if (radio_status
!= FMRADIO_OFF
)
1854 /* Restore radio playback - radio_status should be unchanged if started
1855 through fm radio screen (barring usb connect) */
1856 rec_set_source(AUDIO_SRC_FMRADIO
, (radio_status
& FMRADIO_PAUSED
) ?
1857 SRCF_FMRADIO_PAUSED
: SRCF_FMRADIO_PLAYING
);
1860 /* Go back to playback mode */
1861 rec_set_source(AUDIO_SRC_PLAYBACK
, SRCF_PLAYBACK
);
1863 /* restore talk_menu setting */
1864 talk_enable_menus();
1865 #else /* !SWCODEC */
1866 audio_init_playback();
1867 #endif /* CONFIG_CODEC == SWCODEC */
1869 /* make sure the trigger is really turned off */
1870 peak_meter_trigger(false);
1871 peak_meter_set_trigger_listener(NULL
);
1873 rec_status
&= ~RCSTAT_IN_RECSCREEN
;
1874 sound_settings_apply();
1877 screens
[i
].setfont(FONT_UI
);
1879 /* if the directory was created or recording happened, make sure the
1880 browser is updated */
1881 if (rec_status
& (RCSTAT_CREATED_DIRECTORY
| RCSTAT_HAVE_RECORDED
))
1884 #if (CONFIG_LED == LED_REAL) && !defined(SIMULATOR)
1885 ata_set_led_enabled(true);
1890 return (rec_status
& RCSTAT_BEEN_IN_USB_MODE
) != 0;
1891 } /* recording_screen */
1893 #if CONFIG_KEYPAD == RECORDER_PAD
1894 static bool f2_rec_screen(void)
1896 static const char* const freq_str
[6] =
1911 struct audio_recording_options rec_options
;
1915 screens
[i
].setfont(FONT_SYSFIXED
);
1916 screens
[i
].getstringsize("A",&w
,&h
);
1920 const char* ptr
=NULL
;
1924 screens
[i
].clear_display();
1926 /* Recording quality */
1927 screens
[i
].putsxy(0, LCD_HEIGHT
/2 - h
*2,
1928 str(LANG_SYSFONT_RECORDING_QUALITY
));
1931 snprintf(buf
, sizeof(buf
), "%d", global_settings
.rec_quality
);
1934 screens
[i
].putsxy(0, LCD_HEIGHT
/2-h
, buf
);
1935 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_FastBackward
],
1936 LCD_WIDTH
/2 - 16, LCD_HEIGHT
/2 - 4, 7, 8);
1940 snprintf(buf
, sizeof buf
, "%s:", str(LANG_SYSFONT_RECORDING_FREQUENCY
));
1941 ptr
= freq_str
[global_settings
.rec_frequency
];
1944 screens
[i
].getstringsize(buf
,&w
,&h
);
1945 screens
[i
].putsxy((LCD_WIDTH
-w
)/2, LCD_HEIGHT
- h
*2, buf
);
1946 screens
[i
].getstringsize(ptr
, &w
, &h
);
1947 screens
[i
].putsxy((LCD_WIDTH
-w
)/2, LCD_HEIGHT
- h
, ptr
);
1948 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_DownArrow
],
1949 LCD_WIDTH
/2 - 3, LCD_HEIGHT
- h
*3, 7, 8);
1953 switch ( global_settings
.rec_channels
) {
1955 ptr
= str(LANG_SYSFONT_CHANNEL_STEREO
);
1959 ptr
= str(LANG_SYSFONT_CHANNEL_MONO
);
1965 screens
[i
].getstringsize(str(LANG_SYSFONT_CHANNELS
), &w
, &h
);
1966 screens
[i
].putsxy(LCD_WIDTH
- w
, LCD_HEIGHT
/2 - h
*2,
1967 str(LANG_SYSFONT_CHANNELS
));
1968 screens
[i
].getstringsize(str(LANG_SYSFONT_MODE
), &w
, &h
);
1969 screens
[i
].putsxy(LCD_WIDTH
- w
, LCD_HEIGHT
/2 - h
,
1970 str(LANG_SYSFONT_MODE
));
1971 screens
[i
].getstringsize(ptr
, &w
, &h
);
1972 screens
[i
].putsxy(LCD_WIDTH
- w
, LCD_HEIGHT
/2, ptr
);
1973 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_FastForward
],
1974 LCD_WIDTH
/2 + 8, LCD_HEIGHT
/2 - 4, 7, 8);
1976 screens
[i
].update();
1979 button
= button_get(true);
1982 case BUTTON_F2
| BUTTON_LEFT
:
1983 global_settings
.rec_quality
++;
1984 if(global_settings
.rec_quality
> 7)
1985 global_settings
.rec_quality
= 0;
1990 case BUTTON_F2
| BUTTON_DOWN
:
1991 global_settings
.rec_frequency
++;
1992 if(global_settings
.rec_frequency
> 5)
1993 global_settings
.rec_frequency
= 0;
1998 case BUTTON_F2
| BUTTON_RIGHT
:
1999 global_settings
.rec_channels
++;
2000 if(global_settings
.rec_channels
> 1)
2001 global_settings
.rec_channels
= 0;
2005 case BUTTON_F2
| BUTTON_REL
:
2011 case BUTTON_F2
| BUTTON_REPEAT
:
2016 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
2022 rec_init_recording_options(&rec_options
);
2023 rec_set_recording_options(&rec_options
);
2029 screens
[i
].setfont(FONT_UI
);
2034 static bool f3_rec_screen(void)
2042 str(LANG_SYSFONT_RECORDING_SRC_MIC
),
2043 str(LANG_SYSFONT_LINE_IN
),
2044 str(LANG_SYSFONT_RECORDING_SRC_DIGITAL
)
2046 struct audio_recording_options rec_options
;
2050 screens
[i
].setfont(FONT_SYSFIXED
);
2051 screens
[i
].getstringsize("A",&w
,&h
);
2056 ptr
= src_str
[global_settings
.rec_source
];
2059 screens
[i
].clear_display();
2061 /* Recording source */
2062 screens
[i
].putsxy(0, LCD_HEIGHT
/2 - h
*2,
2063 str(LANG_SYSFONT_RECORDING_SOURCE
));
2065 screens
[i
].getstringsize(ptr
, &w
, &h
);
2066 screens
[i
].putsxy(0, LCD_HEIGHT
/2-h
, ptr
);
2067 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_FastBackward
],
2068 LCD_WIDTH
/2 - 16, LCD_HEIGHT
/2 - 4, 7, 8);
2072 ptr
= str(LANG_SYSFONT_RECORD_TRIGGER
);
2075 screens
[i
].getstringsize(ptr
,&w
,&h
);
2076 screens
[i
].putsxy((LCD_WIDTH
-w
)/2, LCD_HEIGHT
- h
*2, ptr
);
2077 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_DownArrow
],
2078 LCD_WIDTH
/2 - 3, LCD_HEIGHT
- h
*3, 7, 8);
2080 screens
[i
].update();
2083 button
= button_get(true);
2086 case BUTTON_F3
| BUTTON_DOWN
:
2089 settings_apply_trigger();
2095 case BUTTON_F3
| BUTTON_LEFT
:
2096 global_settings
.rec_source
++;
2097 if(global_settings
.rec_source
> AUDIO_SRC_MAX
)
2098 global_settings
.rec_source
= 0;
2102 case BUTTON_F3
| BUTTON_REL
:
2108 case BUTTON_F3
| BUTTON_REPEAT
:
2113 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
2119 rec_init_recording_options(&rec_options
);
2120 rec_set_recording_options(&rec_options
);
2126 screens
[i
].setfont(FONT_UI
);
2130 #endif /* CONFIG_KEYPAD == RECORDER_PAD */
2132 #if CONFIG_CODEC == SWCODEC
2133 void audio_beep(int duration
)
2140 /* stubs for recording sim */
2141 void audio_init_recording(unsigned int buffer_offset
)
2143 buffer_offset
= buffer_offset
;
2146 void audio_close_recording(void)
2150 unsigned long pcm_rec_get_warnings(void)
2155 unsigned long audio_recorded_time(void)
2160 unsigned long audio_num_recorded_bytes(void)
2162 return 5 * 1024 * 1024;
2165 void rec_set_source(int source
, unsigned flags
)
2171 void audio_set_recording_options(struct audio_recording_options
*options
)
2176 void audio_set_recording_gain(int left
, int right
, int type
)
2183 void audio_record(const char *filename
)
2185 filename
= filename
;
2188 void audio_new_file(const char *filename
)
2190 filename
= filename
;
2193 void audio_stop_recording(void)
2197 void audio_pause_recording(void)
2201 void audio_resume_recording(void)
2205 #endif /* #ifdef SIMULATOR */
2206 #endif /* #ifdef CONFIG_CODEC == SWCODEC */
2208 #endif /* HAVE_RECORDING */