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 /* steals mp3 buffer, creates unique filename and starts recording */
698 void rec_record(void)
700 #if CONFIG_CODEC != SWCODEC
701 talk_buffer_steal(); /* we use the mp3 buffer */
703 audio_record(rec_create_filename(path_buffer
));
706 /* creates unique filename and starts recording */
707 void rec_new_file(void)
709 audio_new_file(rec_create_filename(path_buffer
));
712 /* used in trigger_listerner and recording_screen */
713 static unsigned int last_seconds
= 0;
716 * Callback function so that the peak meter code can send an event
717 * to this application. This function can be passed to
718 * peak_meter_set_trigger_listener in order to activate the trigger.
720 static void trigger_listener(int trigger_status
)
722 switch (trigger_status
)
725 if(!(audio_status() & AUDIO_STATUS_RECORD
))
727 rec_status
|= RCSTAT_HAVE_RECORDED
;
729 #if CONFIG_CODEC != SWCODEC
730 /* give control to mpeg thread so that it can start
732 yield(); yield(); yield();
736 /* if we're already recording this is a retrigger */
739 if((audio_status() & AUDIO_STATUS_PAUSE
) &&
740 (global_settings
.rec_trigger_type
== 1))
741 audio_resume_recording();
742 /* New file on trig start*/
743 else if (global_settings
.rec_trigger_type
!= 2)
746 /* tell recording_screen to reset the time */
752 /* A _change_ to TRIG_READY means the current recording has stopped */
754 if(audio_status() & AUDIO_STATUS_RECORD
)
756 switch(global_settings
.rec_trigger_type
)
759 audio_stop_recording();
763 audio_pause_recording();
766 case 2: /* New file on trig stop*/
768 /* tell recording_screen to reset the time */
773 if (global_settings
.rec_trigger_mode
!= TRIG_MODE_REARM
)
775 peak_meter_set_trigger_listener(NULL
);
776 peak_meter_trigger(false);
783 bool recording_start_automatic
= false;
785 bool recording_screen(bool no_source
)
792 int update_countdown
= 1;
793 unsigned int seconds
;
796 int last_audio_stat
= -1;
798 #if CONFIG_CODEC == SWCODEC
799 int warning_counter
= 0;
800 #define WARNING_PERIOD 7
802 #ifdef HAVE_FMRADIO_REC
803 /* Radio is left on if:
804 * 1) Is was on at the start and the initial source is FM Radio
805 * 2) 1) and the source was never changed to something else
807 int radio_status
= (global_settings
.rec_source
!= AUDIO_SRC_FMRADIO
) ?
808 FMRADIO_OFF
: get_radio_status();
810 #if (CONFIG_LED == LED_REAL)
811 bool led_state
= false;
812 int led_countdown
= 2;
815 bool peak_read
= false;
816 bool peak_valid
= false;
819 bool display_agc
[NB_SCREENS
];
821 int line
[NB_SCREENS
];
823 int filename_offset
[NB_SCREENS
];
824 int pm_y
[NB_SCREENS
];
825 int trig_xpos
[NB_SCREENS
];
826 int trig_ypos
[NB_SCREENS
];
827 int trig_width
[NB_SCREENS
];
829 static const unsigned char *byte_units
[] = {
836 struct audio_recording_options rec_options
;
837 if (check_dir(global_settings
.rec_directory
) == false)
840 gui_syncsplash(0, "%s %s",
841 str(LANG_REC_DIR_NOT_WRITABLE
),
842 str(LANG_OFF_ABORT
));
843 } while (action_userabort(HZ
) == false);
847 rec_status
= RCSTAT_IN_RECSCREEN
;
849 #if (CONFIG_LED == LED_REAL) && !defined(SIMULATOR)
850 ata_set_led_enabled(false);
853 #if CONFIG_CODEC == SWCODEC
854 /* recording_menu gets messed up: so prevent manus talking */
855 talk_disable_menus();
856 /* audio_init_recording stops anything playing when it takes the audio
859 /* Yes, we use the D/A for monitoring */
860 peak_meter_enabled
= true;
861 peak_meter_playback(true);
864 audio_init_recording(0);
865 sound_set_volume(global_settings
.volume
);
868 peak_meter_get_peakhold(&peak_l
, &peak_r
);
871 rec_init_recording_options(&rec_options
);
872 rec_set_recording_options(&rec_options
);
876 if(rec_create_directory() > 0)
877 rec_status
|= RCSTAT_CREATED_DIRECTORY
;
880 /* Create new filename for recording start */
884 settings_apply_trigger();
887 agc_preset_str
[0] = str(LANG_SYSFONT_OFF
);
888 agc_preset_str
[1] = str(LANG_SYSFONT_AGC_SAFETY
);
889 agc_preset_str
[2] = str(LANG_SYSFONT_AGC_LIVE
);
890 agc_preset_str
[3] = str(LANG_SYSFONT_AGC_DJSET
);
891 agc_preset_str
[4] = str(LANG_SYSFONT_AGC_MEDIUM
);
892 agc_preset_str
[5] = str(LANG_SYSFONT_AGC_VOICE
);
893 if (global_settings
.rec_source
== AUDIO_SRC_MIC
) {
894 agc_preset
= global_settings
.rec_agc_preset_mic
;
895 agc_maxgain
= global_settings
.rec_agc_maxgain_mic
;
898 agc_preset
= global_settings
.rec_agc_preset_line
;
899 agc_maxgain
= global_settings
.rec_agc_maxgain_line
;
901 #endif /* HAVE_AGC */
905 screens
[i
].setfont(FONT_SYSFIXED
);
906 screens
[i
].getstringsize("M", &w
, &h
);
907 screens
[i
].setmargins(global_settings
.invert_cursor
? 0 : w
, 8);
908 filename_offset
[i
] = ((screens
[i
].height
>= 80) ? 1 : 0);
909 pm_y
[i
] = 8 + h
* (2 + filename_offset
[i
]);
912 #ifdef HAVE_REMOTE_LCD
913 if (!remote_display_on
)
915 screens
[1].clear_display();
916 snprintf(buf
, sizeof(buf
), str(LANG_REMOTE_LCD_ON
));
917 screens
[1].puts((screens
[1].width
/w
- strlen(buf
))/2 + 1,
918 screens
[1].height
/(h
*2) + 1, buf
);
920 gui_syncsplash(0, str(LANG_REMOTE_LCD_OFF
));
926 audio_stat
= audio_status();
928 #if (CONFIG_LED == LED_REAL)
931 * Flash the LED while waiting to record. Turn it on while
934 if(audio_stat
& AUDIO_STATUS_RECORD
)
936 if (audio_stat
& AUDIO_STATUS_PAUSE
)
938 if (--led_countdown
<= 0)
940 led_state
= !led_state
;
947 /* trigger is on in status TRIG_READY (no check needed) */
953 int trigStat
= peak_meter_trigger_status();
955 * other trigger stati than trig_off and trig_steady
956 * already imply that we are recording.
958 if (trigStat
== TRIG_STEADY
)
960 if (--led_countdown
<= 0)
962 led_state
= !led_state
;
969 /* trigger is on in status TRIG_READY (no check needed) */
973 #endif /* CONFIG_LED */
975 /* Wait for a button a while (HZ/10) drawing the peak meter */
976 button
= peak_meter_draw_get_btn(0, pm_y
, h
* PM_HEIGHT
, screen_update
);
978 if (last_audio_stat
!= audio_stat
)
980 if (audio_stat
& AUDIO_STATUS_RECORD
)
982 rec_status
|= RCSTAT_HAVE_RECORDED
;
984 last_audio_stat
= audio_stat
;
988 if (recording_start_automatic
)
990 /* simulate a button press */
991 button
= ACTION_REC_PAUSE
;
992 recording_start_automatic
= false;
997 #ifdef HAVE_REMOTE_LCD
999 if (remote_display_on
)
1001 remote_display_on
= false;
1003 screens
[1].clear_display();
1004 snprintf(buf
, sizeof(buf
), str(LANG_REMOTE_LCD_ON
));
1005 screens
[1].puts((screens
[1].width
/w
- strlen(buf
))/2 + 1,
1006 screens
[1].height
/(h
*2) + 1, buf
);
1007 screens
[1].update();
1008 gui_syncsplash(0, str(LANG_REMOTE_LCD_OFF
));
1012 remote_display_on
= true;
1013 screen_update
= NB_SCREENS
;
1017 case ACTION_STD_CANCEL
:
1018 /* turn off the trigger */
1019 peak_meter_trigger(false);
1020 peak_meter_set_trigger_listener(NULL
);
1022 if(audio_stat
& AUDIO_STATUS_RECORD
)
1024 audio_stop_recording();
1028 #if CONFIG_CODEC != SWCODEC
1029 peak_meter_playback(true);
1030 peak_meter_enabled
= false;
1034 update_countdown
= 1; /* Update immediately */
1037 case ACTION_REC_PAUSE
:
1038 case ACTION_REC_NEWFILE
:
1039 /* Only act if the mpeg is stopped */
1040 if(!(audio_stat
& AUDIO_STATUS_RECORD
))
1042 /* is this manual or triggered recording? */
1043 if ((global_settings
.rec_trigger_mode
== TRIG_MODE_OFF
) ||
1044 (peak_meter_trigger_status() != TRIG_OFF
))
1046 /* manual recording */
1047 rec_status
|= RCSTAT_HAVE_RECORDED
;
1050 if (global_settings
.talk_menu
)
1052 /* no voice possible here, but a beep */
1053 audio_beep(HZ
/2); /* longer beep on start */
1056 /* this is triggered recording */
1059 /* we don't start recording now, but enable the
1060 trigger and let the callback function
1061 trigger_listener control when the recording starts */
1062 peak_meter_trigger(true);
1063 peak_meter_set_trigger_listener(&trigger_listener
);
1068 /*if new file button pressed, start new file */
1069 if (button
== ACTION_REC_NEWFILE
)
1075 /* if pause button pressed, pause or resume */
1077 if(audio_stat
& AUDIO_STATUS_PAUSE
)
1079 audio_resume_recording();
1080 if (global_settings
.talk_menu
)
1082 /* no voice possible here, but a beep */
1083 audio_beep(HZ
/4); /* short beep on resume */
1088 audio_pause_recording();
1092 update_countdown
= 1; /* Update immediately */
1095 case ACTION_STD_PREV
:
1098 update_countdown
= 1; /* Update immediately */
1101 case ACTION_STD_NEXT
:
1104 update_countdown
= 1; /* Update immediately */
1107 case ACTION_SETTINGS_INC
:
1111 global_settings
.volume
++;
1115 if(global_settings
.rec_source
== AUDIO_SRC_MIC
)
1117 if(global_settings
.rec_mic_gain
<
1118 sound_max(SOUND_MIC_GAIN
))
1119 global_settings
.rec_mic_gain
++;
1123 if(global_settings
.rec_left_gain
<
1124 sound_max(SOUND_LEFT_GAIN
))
1125 global_settings
.rec_left_gain
++;
1126 if(global_settings
.rec_right_gain
<
1127 sound_max(SOUND_RIGHT_GAIN
))
1128 global_settings
.rec_right_gain
++;
1132 if(global_settings
.rec_left_gain
<
1133 sound_max(SOUND_LEFT_GAIN
))
1134 global_settings
.rec_left_gain
++;
1137 if(global_settings
.rec_right_gain
<
1138 sound_max(SOUND_RIGHT_GAIN
))
1139 global_settings
.rec_right_gain
++;
1143 agc_preset
= MIN(agc_preset
+ 1, AGC_MODE_SIZE
);
1144 agc_enable
= (agc_preset
!= 0);
1145 if (global_settings
.rec_source
== AUDIO_SRC_MIC
) {
1146 global_settings
.rec_agc_preset_mic
= agc_preset
;
1147 agc_maxgain
= global_settings
.rec_agc_maxgain_mic
;
1149 global_settings
.rec_agc_preset_line
= agc_preset
;
1150 agc_maxgain
= global_settings
.rec_agc_maxgain_line
;
1154 if (global_settings
.rec_source
== AUDIO_SRC_MIC
)
1156 agc_maxgain
= MIN(agc_maxgain
+ 1,
1157 sound_max(SOUND_MIC_GAIN
));
1158 global_settings
.rec_agc_maxgain_mic
= agc_maxgain
;
1162 agc_maxgain
= MIN(agc_maxgain
+ 1,
1163 sound_max(SOUND_LEFT_GAIN
));
1164 global_settings
.rec_agc_maxgain_line
= agc_maxgain
;
1167 #endif /* HAVE_AGC */
1170 update_countdown
= 1; /* Update immediately */
1173 case ACTION_SETTINGS_DEC
:
1177 global_settings
.volume
--;
1181 if(global_settings
.rec_source
== AUDIO_SRC_MIC
)
1183 if(global_settings
.rec_mic_gain
>
1184 sound_min(SOUND_MIC_GAIN
))
1185 global_settings
.rec_mic_gain
--;
1189 if(global_settings
.rec_left_gain
>
1190 sound_min(SOUND_LEFT_GAIN
))
1191 global_settings
.rec_left_gain
--;
1192 if(global_settings
.rec_right_gain
>
1193 sound_min(SOUND_RIGHT_GAIN
))
1194 global_settings
.rec_right_gain
--;
1198 if(global_settings
.rec_left_gain
>
1199 sound_min(SOUND_LEFT_GAIN
))
1200 global_settings
.rec_left_gain
--;
1203 if(global_settings
.rec_right_gain
>
1204 sound_min(SOUND_RIGHT_GAIN
))
1205 global_settings
.rec_right_gain
--;
1209 agc_preset
= MAX(agc_preset
- 1, 0);
1210 agc_enable
= (agc_preset
!= 0);
1211 if (global_settings
.rec_source
== AUDIO_SRC_MIC
) {
1212 global_settings
.rec_agc_preset_mic
= agc_preset
;
1213 agc_maxgain
= global_settings
.rec_agc_maxgain_mic
;
1215 global_settings
.rec_agc_preset_line
= agc_preset
;
1216 agc_maxgain
= global_settings
.rec_agc_maxgain_line
;
1220 if (global_settings
.rec_source
== AUDIO_SRC_MIC
)
1222 agc_maxgain
= MAX(agc_maxgain
- 1,
1223 sound_min(SOUND_MIC_GAIN
));
1224 global_settings
.rec_agc_maxgain_mic
= agc_maxgain
;
1228 agc_maxgain
= MAX(agc_maxgain
- 1,
1229 sound_min(SOUND_LEFT_GAIN
));
1230 global_settings
.rec_agc_maxgain_line
= agc_maxgain
;
1233 #endif /* HAVE_AGC */
1236 update_countdown
= 1; /* Update immediately */
1239 case ACTION_STD_MENU
:
1240 #if CONFIG_CODEC == SWCODEC
1241 if(!(audio_stat
& AUDIO_STATUS_RECORD
))
1243 if(audio_stat
!= AUDIO_STATUS_RECORD
)
1246 #ifdef HAVE_FMRADIO_REC
1247 const int prev_rec_source
= global_settings
.rec_source
;
1250 #if (CONFIG_LED == LED_REAL)
1251 /* led is restored at begin of loop / end of function */
1254 if (recording_menu(no_source
))
1257 rec_status
|= RCSTAT_BEEN_IN_USB_MODE
;
1258 #ifdef HAVE_FMRADIO_REC
1259 radio_status
= FMRADIO_OFF
;
1264 #ifdef HAVE_FMRADIO_REC
1265 /* If input changes away from FM Radio, radio will
1266 remain off when recording screen closes. */
1267 if (global_settings
.rec_source
!= prev_rec_source
1268 && prev_rec_source
== AUDIO_SRC_FMRADIO
)
1269 radio_status
= FMRADIO_OFF
;
1272 #if CONFIG_CODEC == SWCODEC
1273 /* reinit after submenu exit */
1274 audio_close_recording();
1275 audio_init_recording(0);
1278 rec_init_recording_options(&rec_options
);
1279 rec_set_recording_options(&rec_options
);
1281 if(rec_create_directory() > 0)
1282 rec_status
|= RCSTAT_CREATED_DIRECTORY
;
1284 #if CONFIG_CODEC == SWCODEC && CONFIG_RTC == 0
1285 /* If format changed, a new number is required */
1286 rec_init_filename();
1290 if (global_settings
.rec_source
== AUDIO_SRC_MIC
) {
1291 agc_preset
= global_settings
.rec_agc_preset_mic
;
1292 agc_maxgain
= global_settings
.rec_agc_maxgain_mic
;
1295 agc_preset
= global_settings
.rec_agc_preset_line
;
1296 agc_maxgain
= global_settings
.rec_agc_maxgain_line
;
1302 update_countdown
= 1; /* Update immediately */
1306 screens
[i
].setfont(FONT_SYSFIXED
);
1307 screens
[i
].setmargins(
1308 global_settings
.invert_cursor
? 0 : w
, 8);
1314 #if CONFIG_KEYPAD == RECORDER_PAD
1316 if(audio_stat
!= AUDIO_STATUS_RECORD
)
1318 #if (CONFIG_LED == LED_REAL)
1319 /* led is restored at begin of loop / end of function */
1322 if (f2_rec_screen())
1324 rec_status
|= RCSTAT_HAVE_RECORDED
;
1328 update_countdown
= 1; /* Update immediately */
1333 if(audio_stat
& AUDIO_STATUS_RECORD
)
1340 #if (CONFIG_LED == LED_REAL)
1341 /* led is restored at begin of loop / end of function */
1344 if (f3_rec_screen())
1346 rec_status
|= RCSTAT_HAVE_RECORDED
;
1350 update_countdown
= 1; /* Update immediately */
1353 #endif /* CONFIG_KEYPAD == RECORDER_PAD */
1355 case SYS_USB_CONNECTED
:
1356 /* Only accept USB connection when not recording */
1357 if(!(audio_stat
& AUDIO_STATUS_RECORD
))
1359 default_event_handler(SYS_USB_CONNECTED
);
1361 rec_status
|= RCSTAT_BEEN_IN_USB_MODE
;
1362 #ifdef HAVE_FMRADIO_REC
1363 radio_status
= FMRADIO_OFF
;
1369 default_event_handler(button
);
1374 peak_read
= !peak_read
;
1375 if (peak_read
) { /* every 2nd run of loop */
1377 peak_valid
= read_peak_levels(&peak_l
, &peak_r
, &balance
);
1380 /* Handle AGC every 200ms when enabled and peak data is valid */
1381 if (peak_read
&& agc_enable
&& peak_valid
)
1382 auto_gain_control(&peak_l
, &peak_r
, &balance
);
1386 screens
[i
].setfont(FONT_SYSFIXED
);
1388 seconds
= audio_recorded_time() / HZ
;
1391 if(update_countdown
== 0 || seconds
> last_seconds
)
1393 unsigned int dseconds
, dhours
, dminutes
;
1394 unsigned long num_recorded_bytes
, dsize
, dmb
;
1397 update_countdown
= 5;
1398 last_seconds
= seconds
;
1400 dseconds
= rec_timesplit_seconds();
1401 dsize
= rec_sizesplit_bytes();
1402 num_recorded_bytes
= audio_num_recorded_bytes();
1404 for(i
= 0; i
< screen_update
; i
++)
1405 screens
[i
].clear_display();
1407 #if CONFIG_CODEC == SWCODEC
1408 if ((audio_stat
& AUDIO_STATUS_WARNING
)
1409 && (warning_counter
++ % WARNING_PERIOD
) < WARNING_PERIOD
/2)
1411 /* Switch back and forth displaying warning on first available
1412 line to ensure visibility - the motion should also help
1414 /* Don't use language string unless agreed upon to make this
1415 method permanent - could do something in the statusbar */
1416 snprintf(buf
, sizeof(buf
), "Warning: %08X",
1417 pcm_rec_get_warnings());
1420 #endif /* CONFIG_CODEC == SWCODEC */
1421 if ((global_settings
.rec_sizesplit
) && (global_settings
.rec_split_method
))
1423 dmb
= dsize
/1024/1024;
1424 snprintf(buf
, sizeof(buf
), "%s %dMB",
1425 str(LANG_SYSFONT_SPLIT_SIZE
), dmb
);
1429 hours
= seconds
/ 3600;
1430 minutes
= (seconds
- (hours
* 3600)) / 60;
1431 snprintf(buf
, sizeof(buf
), "%s %02d:%02d:%02d",
1432 str(LANG_SYSFONT_RECORDING_TIME
),
1433 hours
, minutes
, seconds
%60);
1436 for(i
= 0; i
< screen_update
; i
++)
1437 screens
[i
].puts(0, 0, buf
);
1439 if(audio_stat
& AUDIO_STATUS_PRERECORD
)
1441 snprintf(buf
, sizeof(buf
), "%s...", str(LANG_SYSFONT_RECORD_PRERECORD
));
1445 /* Display the split interval if the record timesplit
1447 if ((global_settings
.rec_timesplit
) && !(global_settings
.rec_split_method
))
1449 /* Display the record timesplit interval rather
1450 than the file size if the record timer is
1452 dhours
= dseconds
/ 3600;
1453 dminutes
= (dseconds
- (dhours
* 3600)) / 60;
1454 snprintf(buf
, sizeof(buf
), "%s %02d:%02d",
1455 str(LANG_SYSFONT_RECORD_TIMESPLIT_REC
),
1460 output_dyn_value(buf2
, sizeof buf2
,
1463 snprintf(buf
, sizeof(buf
), "%s %s",
1464 str(LANG_SYSFONT_RECORDING_SIZE
), buf2
);
1467 for(i
= 0; i
< screen_update
; i
++)
1468 screens
[i
].puts(0, 1, buf
);
1470 for(i
= 0; i
< screen_update
; i
++)
1472 if (filename_offset
[i
] > 0)
1475 if (audio_stat
& AUDIO_STATUS_RECORD
)
1477 strncpy(filename
, path_buffer
+
1478 strlen(path_buffer
) - 12, 13);
1482 snprintf(buf
, sizeof(buf
), "%s %s",
1483 str(LANG_SYSFONT_RECORDING_FILENAME
), filename
);
1484 screens
[i
].puts(0, 2, buf
);
1488 /* We will do file splitting regardless, either at the end of
1489 a split interval, or when the filesize approaches the 2GB
1490 FAT file size (compatibility) limit. */
1491 if ((audio_stat
&& !(global_settings
.rec_split_method
)
1492 && global_settings
.rec_timesplit
&& (seconds
>= dseconds
))
1493 || (audio_stat
&& global_settings
.rec_split_method
1494 && global_settings
.rec_sizesplit
&& (num_recorded_bytes
>= dsize
))
1495 || (num_recorded_bytes
>= MAX_FILE_SIZE
))
1497 if (!(global_settings
.rec_split_type
)
1498 || (num_recorded_bytes
>= MAX_FILE_SIZE
))
1505 peak_meter_trigger(false);
1506 peak_meter_set_trigger_listener(NULL
);
1507 audio_stop_recording();
1509 update_countdown
= 1;
1512 snprintf(buf
, sizeof(buf
), "%s: %s", str(LANG_SYSFONT_VOLUME
),
1513 fmt_gain(SOUND_VOLUME
,
1514 global_settings
.volume
,
1515 buf2
, sizeof(buf2
)));
1517 if (global_settings
.invert_cursor
&& (pos
++ == cursor
))
1519 for(i
= 0; i
< screen_update
; i
++)
1520 screens
[i
].puts_style_offset(0, filename_offset
[i
] +
1521 PM_HEIGHT
+ 2, buf
, STYLE_INVERT
,0);
1525 for(i
= 0; i
< screen_update
; i
++)
1526 screens
[i
].puts(0, filename_offset
[i
] + PM_HEIGHT
+ 2, buf
);
1529 if(global_settings
.rec_source
== AUDIO_SRC_MIC
)
1531 /* Draw MIC recording gain */
1532 snprintf(buf
, sizeof(buf
), "%s:%s", str(LANG_SYSFONT_RECORDING_GAIN
),
1533 fmt_gain(SOUND_MIC_GAIN
,
1534 global_settings
.rec_mic_gain
,
1535 buf2
, sizeof(buf2
)));
1536 if(global_settings
.invert_cursor
&& ((1==cursor
)||(2==cursor
)))
1538 for(i
= 0; i
< screen_update
; i
++)
1539 screens
[i
].puts_style_offset(0, filename_offset
[i
] +
1540 PM_HEIGHT
+ 3, buf
, STYLE_INVERT
,0);
1544 for(i
= 0; i
< screen_update
; i
++)
1545 screens
[i
].puts(0, filename_offset
[i
] +
1546 PM_HEIGHT
+ 3, buf
);
1550 HAVE_LINE_REC_( || global_settings
.rec_source
== AUDIO_SRC_LINEIN
)
1551 HAVE_FMRADIO_REC_( || global_settings
.rec_source
== AUDIO_SRC_FMRADIO
)
1554 /* Draw LINE or FMRADIO recording gain */
1555 snprintf(buf
, sizeof(buf
), "%s:%s",
1556 str(LANG_SYSFONT_RECORDING_LEFT
),
1557 fmt_gain(SOUND_LEFT_GAIN
,
1558 global_settings
.rec_left_gain
,
1559 buf2
, sizeof(buf2
)));
1560 if(global_settings
.invert_cursor
&& ((1==cursor
)||(2==cursor
)))
1562 for(i
= 0; i
< screen_update
; i
++)
1563 screens
[i
].puts_style_offset(0, filename_offset
[i
] +
1564 PM_HEIGHT
+ 3, buf
, STYLE_INVERT
,0);
1568 for(i
= 0; i
< screen_update
; i
++)
1569 screens
[i
].puts(0, filename_offset
[i
] +
1570 PM_HEIGHT
+ 3, buf
);
1573 snprintf(buf
, sizeof(buf
), "%s:%s",
1574 str(LANG_SYSFONT_RECORDING_RIGHT
),
1575 fmt_gain(SOUND_RIGHT_GAIN
,
1576 global_settings
.rec_right_gain
,
1577 buf2
, sizeof(buf2
)));
1578 if(global_settings
.invert_cursor
&& ((1==cursor
)||(3==cursor
)))
1580 for(i
= 0; i
< screen_update
; i
++)
1581 screens
[i
].puts_style_offset(0, filename_offset
[i
] +
1582 PM_HEIGHT
+ 4, buf
, STYLE_INVERT
,0);
1586 for(i
= 0; i
< screen_update
; i
++)
1587 screens
[i
].puts(0, filename_offset
[i
] +
1588 PM_HEIGHT
+ 4, buf
);
1594 switch (global_settings
.rec_source
)
1596 HAVE_LINE_REC_(case AUDIO_SRC_LINEIN
:)
1597 HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO
:)
1604 #ifdef HAVE_SPDIF_REC
1605 case AUDIO_SRC_SPDIF
:
1610 line
[i
] = 5; /* to prevent uninitialisation
1611 warnings for line[0] */
1615 if (screens
[i
].height
< h
* (2 + filename_offset
[i
] + PM_HEIGHT
+ line
[i
]))
1618 display_agc
[i
] = false;
1621 display_agc
[i
] = true;
1623 if ((cursor
==4) || (cursor
==5))
1624 display_agc
[i
] = true;
1627 /************** AGC test info ******************
1628 snprintf(buf, sizeof(buf), "D:%d U:%d",
1629 (agc_droptime+2)/5, (agc_risetime+2)/5);
1630 lcd_putsxy(1, LCD_HEIGHT - 8, buf);
1631 snprintf(buf, sizeof(buf), "B:%d",
1633 lcd_putsxy(LCD_WIDTH/2 + 3, LCD_HEIGHT - 8, buf);
1634 ***********************************************/
1637 snprintf(buf
, sizeof(buf
), "%s: %s",
1638 str(LANG_SYSFONT_RECORDING_AGC_MAXGAIN
),
1639 fmt_gain(SOUND_LEFT_GAIN
,
1640 agc_maxgain
, buf2
, sizeof(buf2
)));
1641 else if (agc_preset
== 0)
1642 snprintf(buf
, sizeof(buf
), "%s: %s",
1643 str(LANG_SYSFONT_RECORDING_AGC_PRESET
),
1644 agc_preset_str
[agc_preset
]);
1645 else if (global_settings
.rec_source
== AUDIO_SRC_MIC
)
1646 snprintf(buf
, sizeof(buf
), "%s: %s%s",
1647 str(LANG_SYSFONT_RECORDING_AGC_PRESET
),
1648 agc_preset_str
[agc_preset
],
1649 fmt_gain(SOUND_LEFT_GAIN
,
1651 global_settings
.rec_mic_gain
,
1652 buf2
, sizeof(buf2
)));
1654 snprintf(buf
, sizeof(buf
), "%s: %s%s",
1655 str(LANG_SYSFONT_RECORDING_AGC_PRESET
),
1656 agc_preset_str
[agc_preset
],
1657 fmt_gain(SOUND_LEFT_GAIN
,
1659 (global_settings
.rec_left_gain
+
1660 global_settings
.rec_right_gain
)/2,
1661 buf2
, sizeof(buf2
)));
1663 if(global_settings
.invert_cursor
&& ((cursor
==4) || (cursor
==5)))
1665 for(i
= 0; i
< screen_update
; i
++)
1666 screens
[i
].puts_style_offset(0, filename_offset
[i
] +
1667 PM_HEIGHT
+ line
[i
], buf
, STYLE_INVERT
,0);
1670 global_settings
.rec_source
== AUDIO_SRC_MIC
1671 HAVE_LINE_REC_(|| global_settings
.rec_source
== AUDIO_SRC_LINEIN
)
1672 HAVE_FMRADIO_REC_(|| global_settings
.rec_source
== AUDIO_SRC_FMRADIO
)
1675 for(i
= 0; i
< screen_update
; i
++) {
1676 if (display_agc
[i
]) {
1677 screens
[i
].puts(0, filename_offset
[i
] +
1678 PM_HEIGHT
+ line
[i
], buf
);
1683 if (global_settings
.rec_source
== AUDIO_SRC_MIC
)
1685 if(agc_maxgain
< (global_settings
.rec_mic_gain
))
1686 change_recording_gain(false, true, true);
1690 if(agc_maxgain
< (global_settings
.rec_left_gain
))
1691 change_recording_gain(false, true, false);
1692 if(agc_maxgain
< (global_settings
.rec_right_gain
))
1693 change_recording_gain(false, false, true);
1695 #else /* !HAVE_AGC */
1697 #endif /* HAVE_AGC */
1699 if(!global_settings
.invert_cursor
) {
1703 for(i
= 0; i
< screen_update
; i
++)
1704 screen_put_cursorxy(&screens
[i
], 0,
1705 filename_offset
[i
] +
1706 PM_HEIGHT
+ 3, true);
1708 if(global_settings
.rec_source
!= AUDIO_SRC_MIC
)
1710 for(i
= 0; i
< screen_update
; i
++)
1711 screen_put_cursorxy(&screens
[i
], 0,
1712 filename_offset
[i
] +
1713 PM_HEIGHT
+ 4, true);
1717 for(i
= 0; i
< screen_update
; i
++)
1718 screen_put_cursorxy(&screens
[i
], 0,
1719 filename_offset
[i
] +
1720 PM_HEIGHT
+ 3, true);
1723 for(i
= 0; i
< screen_update
; i
++)
1724 screen_put_cursorxy(&screens
[i
], 0,
1725 filename_offset
[i
] +
1726 PM_HEIGHT
+ 4, true);
1731 for(i
= 0; i
< screen_update
; i
++)
1732 screen_put_cursorxy(&screens
[i
], 0,
1733 filename_offset
[i
] +
1734 PM_HEIGHT
+ line
[i
], true);
1736 #endif /* HAVE_AGC */
1738 for(i
= 0; i
< screen_update
; i
++)
1739 screen_put_cursorxy(&screens
[i
], 0,
1740 filename_offset
[i
] +
1741 PM_HEIGHT
+ 2, true);
1749 for(i
= 0; i
< screen_update
; i
++)
1751 gui_statusbar_draw(&(statusbars
.statusbars
[i
]), true);
1752 peak_meter_screen(&screens
[i
], 0, pm_y
[i
], h
*PM_HEIGHT
);
1753 screens
[i
].update();
1756 /* draw the trigger status */
1759 trig_width
[i
] = ((screens
[i
].height
< 64) ||
1760 ((screens
[i
].height
< 72) && (PM_HEIGHT
> 1))) ?
1761 screens
[i
].width
- 14 * w
: screens
[i
].width
;
1762 trig_xpos
[i
] = screens
[i
].width
- trig_width
[i
];
1763 trig_ypos
[i
] = ((screens
[i
].height
< 72) && (PM_HEIGHT
> 1)) ?
1765 h
*(1 + filename_offset
[i
] + PM_HEIGHT
+ line
[i
]
1772 if (peak_meter_trigger_status() != TRIG_OFF
)
1774 peak_meter_draw_trig(trig_xpos
, trig_ypos
, trig_width
,
1776 for(i
= 0; i
< screen_update
; i
++){
1777 screens
[i
].update_rect(trig_xpos
[i
], trig_ypos
[i
],
1778 trig_width
[i
] + 2, TRIG_HEIGHT
);
1783 if(audio_stat
& AUDIO_STATUS_ERROR
)
1787 } /* end while(!done) */
1789 audio_stat
= audio_status();
1790 if (audio_stat
& AUDIO_STATUS_ERROR
)
1792 gui_syncsplash(0, str(LANG_SYSFONT_DISK_FULL
));
1793 gui_syncstatusbar_draw(&statusbars
, true);
1796 screens
[i
].update();
1798 audio_error_clear();
1802 if (action_userabort(TIMEOUT_NOBLOCK
))
1807 #if CONFIG_CODEC == SWCODEC
1808 audio_stop_recording();
1809 audio_close_recording();
1811 #ifdef HAVE_FMRADIO_REC
1812 if (radio_status
!= FMRADIO_OFF
)
1813 /* Restore radio playback - radio_status should be unchanged if started
1814 through fm radio screen (barring usb connect) */
1815 rec_set_source(AUDIO_SRC_FMRADIO
, (radio_status
& FMRADIO_PAUSED
) ?
1816 SRCF_FMRADIO_PAUSED
: SRCF_FMRADIO_PLAYING
);
1819 /* Go back to playback mode */
1820 rec_set_source(AUDIO_SRC_PLAYBACK
, SRCF_PLAYBACK
);
1822 /* restore talk_menu setting */
1823 talk_enable_menus();
1824 #else /* !SWCODEC */
1825 audio_init_playback();
1826 #endif /* CONFIG_CODEC == SWCODEC */
1828 /* make sure the trigger is really turned off */
1829 peak_meter_trigger(false);
1830 peak_meter_set_trigger_listener(NULL
);
1832 rec_status
&= ~RCSTAT_IN_RECSCREEN
;
1833 sound_settings_apply();
1836 screens
[i
].setfont(FONT_UI
);
1838 /* if the directory was created or recording happened, make sure the
1839 browser is updated */
1840 if (rec_status
& (RCSTAT_CREATED_DIRECTORY
| RCSTAT_HAVE_RECORDED
))
1843 #if (CONFIG_LED == LED_REAL) && !defined(SIMULATOR)
1844 ata_set_led_enabled(true);
1849 return (rec_status
& RCSTAT_BEEN_IN_USB_MODE
) != 0;
1850 } /* recording_screen */
1852 #if CONFIG_KEYPAD == RECORDER_PAD
1853 static bool f2_rec_screen(void)
1855 static const char* const freq_str
[6] =
1870 struct audio_recording_options rec_options
;
1874 screens
[i
].setfont(FONT_SYSFIXED
);
1875 screens
[i
].getstringsize("A",&w
,&h
);
1879 const char* ptr
=NULL
;
1883 screens
[i
].clear_display();
1885 /* Recording quality */
1886 screens
[i
].putsxy(0, LCD_HEIGHT
/2 - h
*2,
1887 str(LANG_SYSFONT_RECORDING_QUALITY
));
1890 snprintf(buf
, sizeof(buf
), "%d", global_settings
.rec_quality
);
1893 screens
[i
].putsxy(0, LCD_HEIGHT
/2-h
, buf
);
1894 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_FastBackward
],
1895 LCD_WIDTH
/2 - 16, LCD_HEIGHT
/2 - 4, 7, 8);
1899 snprintf(buf
, sizeof buf
, "%s:", str(LANG_SYSFONT_RECORDING_FREQUENCY
));
1900 ptr
= freq_str
[global_settings
.rec_frequency
];
1903 screens
[i
].getstringsize(buf
,&w
,&h
);
1904 screens
[i
].putsxy((LCD_WIDTH
-w
)/2, LCD_HEIGHT
- h
*2, buf
);
1905 screens
[i
].getstringsize(ptr
, &w
, &h
);
1906 screens
[i
].putsxy((LCD_WIDTH
-w
)/2, LCD_HEIGHT
- h
, ptr
);
1907 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_DownArrow
],
1908 LCD_WIDTH
/2 - 3, LCD_HEIGHT
- h
*3, 7, 8);
1912 switch ( global_settings
.rec_channels
) {
1914 ptr
= str(LANG_SYSFONT_CHANNEL_STEREO
);
1918 ptr
= str(LANG_SYSFONT_CHANNEL_MONO
);
1924 screens
[i
].getstringsize(str(LANG_SYSFONT_RECORDING_CHANNELS
), &w
, &h
);
1925 screens
[i
].putsxy(LCD_WIDTH
- w
, LCD_HEIGHT
/2 - h
*2,
1926 str(LANG_SYSFONT_RECORDING_CHANNELS
));
1927 screens
[i
].getstringsize(str(LANG_SYSFONT_F2_MODE
), &w
, &h
);
1928 screens
[i
].putsxy(LCD_WIDTH
- w
, LCD_HEIGHT
/2 - h
,
1929 str(LANG_SYSFONT_F2_MODE
));
1930 screens
[i
].getstringsize(ptr
, &w
, &h
);
1931 screens
[i
].putsxy(LCD_WIDTH
- w
, LCD_HEIGHT
/2, ptr
);
1932 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_FastForward
],
1933 LCD_WIDTH
/2 + 8, LCD_HEIGHT
/2 - 4, 7, 8);
1935 screens
[i
].update();
1938 button
= button_get(true);
1941 case BUTTON_F2
| BUTTON_LEFT
:
1942 global_settings
.rec_quality
++;
1943 if(global_settings
.rec_quality
> 7)
1944 global_settings
.rec_quality
= 0;
1949 case BUTTON_F2
| BUTTON_DOWN
:
1950 global_settings
.rec_frequency
++;
1951 if(global_settings
.rec_frequency
> 5)
1952 global_settings
.rec_frequency
= 0;
1957 case BUTTON_F2
| BUTTON_RIGHT
:
1958 global_settings
.rec_channels
++;
1959 if(global_settings
.rec_channels
> 1)
1960 global_settings
.rec_channels
= 0;
1964 case BUTTON_F2
| BUTTON_REL
:
1970 case BUTTON_F2
| BUTTON_REPEAT
:
1975 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
1981 rec_init_recording_options(&rec_options
);
1982 rec_set_recording_options(&rec_options
);
1988 screens
[i
].setfont(FONT_UI
);
1993 static bool f3_rec_screen(void)
2001 str(LANG_SYSFONT_RECORDING_SRC_MIC
),
2002 str(LANG_SYSFONT_RECORDING_SRC_LINE
),
2003 str(LANG_SYSFONT_RECORDING_SRC_DIGITAL
)
2005 struct audio_recording_options rec_options
;
2009 screens
[i
].setfont(FONT_SYSFIXED
);
2010 screens
[i
].getstringsize("A",&w
,&h
);
2015 ptr
= src_str
[global_settings
.rec_source
];
2018 screens
[i
].clear_display();
2020 /* Recording source */
2021 screens
[i
].putsxy(0, LCD_HEIGHT
/2 - h
*2,
2022 str(LANG_SYSFONT_RECORDING_SOURCE
));
2024 screens
[i
].getstringsize(ptr
, &w
, &h
);
2025 screens
[i
].putsxy(0, LCD_HEIGHT
/2-h
, ptr
);
2026 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_FastBackward
],
2027 LCD_WIDTH
/2 - 16, LCD_HEIGHT
/2 - 4, 7, 8);
2031 ptr
= str(LANG_SYSFONT_RECORD_TRIGGER
);
2034 screens
[i
].getstringsize(ptr
,&w
,&h
);
2035 screens
[i
].putsxy((LCD_WIDTH
-w
)/2, LCD_HEIGHT
- h
*2, ptr
);
2036 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_DownArrow
],
2037 LCD_WIDTH
/2 - 3, LCD_HEIGHT
- h
*3, 7, 8);
2039 screens
[i
].update();
2042 button
= button_get(true);
2045 case BUTTON_F3
| BUTTON_DOWN
:
2048 settings_apply_trigger();
2054 case BUTTON_F3
| BUTTON_LEFT
:
2055 global_settings
.rec_source
++;
2056 if(global_settings
.rec_source
> AUDIO_SRC_MAX
)
2057 global_settings
.rec_source
= 0;
2061 case BUTTON_F3
| BUTTON_REL
:
2067 case BUTTON_F3
| BUTTON_REPEAT
:
2072 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
2078 rec_init_recording_options(&rec_options
);
2079 rec_set_recording_options(&rec_options
);
2085 screens
[i
].setfont(FONT_UI
);
2089 #endif /* CONFIG_KEYPAD == RECORDER_PAD */
2091 #if CONFIG_CODEC == SWCODEC
2092 void audio_beep(int duration
)
2099 /* stubs for recording sim */
2100 void audio_init_recording(unsigned int buffer_offset
)
2102 buffer_offset
= buffer_offset
;
2105 void audio_close_recording(void)
2109 unsigned long pcm_rec_get_warnings(void)
2114 unsigned long audio_recorded_time(void)
2119 unsigned long audio_num_recorded_bytes(void)
2121 return 5 * 1024 * 1024;
2124 void rec_set_source(int source
, unsigned flags
)
2130 void audio_set_recording_options(struct audio_recording_options
*options
)
2135 void audio_set_recording_gain(int left
, int right
, int type
)
2142 void audio_record(const char *filename
)
2144 filename
= filename
;
2147 void audio_new_file(const char *filename
)
2149 filename
= filename
;
2152 void audio_stop_recording(void)
2156 void audio_pause_recording(void)
2160 void audio_resume_recording(void)
2164 #endif /* #ifdef SIMULATOR */
2165 #endif /* #ifdef CONFIG_CODEC == SWCODEC */
2167 #endif /* HAVE_RECORDING */