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
35 #include "enc_config.h"
36 #if defined(HAVE_SPDIF_IN) || defined(HAVE_SPDIF_OUT)
39 #endif /* CONFIG_CODEC == SWCODEC */
40 #include "recording.h"
41 #include "mp3_playback.h"
51 #include "peakmeter.h"
52 #include "statusbar.h"
54 #include "sound_menu.h"
55 #include "timefuncs.h"
67 #include "screen_access.h"
71 /* This array holds the record timer interval lengths, in seconds */
72 static const unsigned long rec_timer_seconds
[] =
86 10L*60*60, /* 10:00 */
87 12L*60*60, /* 12:00 */
88 18L*60*60, /* 18:00 */
92 static unsigned int rec_timesplit_seconds(void)
94 return rec_timer_seconds
[global_settings
.rec_timesplit
];
97 /* This array holds the record size interval lengths, in bytes */
98 static const unsigned long rec_size_bytes
[] =
101 5*1024*1024, /* 5MB */
102 10*1024*1024, /* 10MB */
103 15*1024*1024, /* 15MB */
104 32*1024*1024, /* 32MB */
105 64*1024*1024, /* 64MB */
106 75*1024*1024, /* 75MB */
107 100*1024*1024, /* 100MB */
108 128*1024*1024, /* 128MB */
109 256*1024*1024, /* 256MB */
110 512*1024*1024, /* 512MB */
111 650*1024*1024, /* 650MB */
112 700*1024*1024, /* 700MB */
113 1024*1024*1024, /* 1GB */
114 1536*1024*1024, /* 1.5GB */
115 1792*1024*1024, /* 1.75GB */
118 static unsigned long rec_sizesplit_bytes(void)
120 return rec_size_bytes
[global_settings
.rec_sizesplit
];
123 * Time strings used for the trigger durations.
124 * Keep synchronous to trigger_times in settings_apply_trigger
126 const struct opt_items trig_durations
[TRIG_DURATION_COUNT
] =
128 #define TS(x) { (unsigned char *)(#x "s"), TALK_ID(x, UNIT_SEC) }
129 #define TM(x) { (unsigned char *)(#x "min"), TALK_ID(x, UNIT_MIN) }
130 TS(0), TS(1), TS(2), TS(5),
131 TS(10), TS(15), TS(20), TS(25), TS(30),
132 TM(1), TM(2), TM(5), TM(10)
137 void settings_apply_trigger(void)
139 /* Keep synchronous to trig_durations and trig_durations_conf*/
140 static const long trigger_times
[TRIG_DURATION_COUNT
] = {
142 10*HZ
, 15*HZ
, 20*HZ
, 25*HZ
, 30*HZ
,
143 60*HZ
, 2*60*HZ
, 5*60*HZ
, 10*60*HZ
146 peak_meter_define_trigger(
147 global_settings
.rec_start_thres
,
148 trigger_times
[global_settings
.rec_start_duration
],
149 MIN(trigger_times
[global_settings
.rec_start_duration
] / 2, 2*HZ
),
150 global_settings
.rec_stop_thres
,
151 trigger_times
[global_settings
.rec_stop_postrec
],
152 trigger_times
[global_settings
.rec_stop_gap
]
155 /* recording screen status flags */
156 enum rec_status_flags
158 RCSTAT_IN_RECSCREEN
= 0x00000001,
159 RCSTAT_BEEN_IN_USB_MODE
= 0x00000002,
160 RCSTAT_CREATED_DIRECTORY
= 0x00000004,
161 RCSTAT_HAVE_RECORDED
= 0x00000008,
164 static int rec_status
= 0;
166 bool in_recording_screen(void)
168 return (rec_status
& RCSTAT_IN_RECSCREEN
) != 0;
171 #define PM_HEIGHT ((LCD_HEIGHT >= 72) ? 2 : 1)
173 #if CONFIG_KEYPAD == RECORDER_PAD
174 static bool f2_rec_screen(void);
175 static bool f3_rec_screen(void);
178 #define MAX_FILE_SIZE 0x7F800000 /* 2 GB - 4 MB */
180 #ifndef HAVE_REMOTE_LCD
181 static const int screen_update
= NB_SCREENS
;
183 static int screen_update
= NB_SCREENS
;
184 static bool remote_display_on
= true;
187 /** File name creation **/
189 /* current file number to assist in creating unique numbered filenames
190 without actually having to create the file on disk */
191 static int file_number
= -1;
192 #endif /* CONFIG_RTC */
194 #if CONFIG_CODEC == SWCODEC
196 #define REC_FILE_ENDING(rec_format) \
197 (audio_formats[rec_format_afmt[rec_format]].ext_list)
199 #else /* CONFIG_CODEC != SWCODEC */
201 /* default record file extension for HWCODEC */
202 #define REC_FILE_ENDING(rec_format) \
203 (audio_formats[AFMT_MPA_L3].ext_list)
205 #endif /* CONFIG_CODEC == SWCODEC */
207 /* path for current file */
208 static char path_buffer
[MAX_PATH
];
210 /** Automatic Gain Control (AGC) **/
213 * peak_time is incremented every 0.2s, every 2nd run of record screen loop.
214 * hist_time is incremented every 0.5s, display update.
215 * peak_time is the counter of the peak hold read and agc process,
216 * overflow every 13 years 8-)
218 static long peak_time
= 0;
219 static long hist_time
= 0;
221 static short peak_valid_mem
[4];
222 #define BAL_MEM_SIZE 24
223 static short balance_mem
[BAL_MEM_SIZE
];
225 /* Automatic Gain Control */
226 #define AGC_MODE_SIZE 5
227 #define AGC_SAFETY_MODE 0
229 static const char* agc_preset_str
[] =
230 { "Off", "S", "L", "D", "M", "V" };
237 #define AGC_CLIP 32766
238 #define AGC_PEAK 29883 /* fast gain reduction threshold -0.8dB */
239 #define AGC_HIGH 27254 /* accelerated gain reduction threshold -1.6dB */
240 #define AGC_IMG 823 /* threshold for balance control -32dB */
241 /* autogain high level thresholds (-3dB, -7dB, -4dB, -5dB, -5dB) */
242 static const short agc_th_hi
[AGC_MODE_SIZE
] =
243 { 23197, 14637, 21156, 18428, 18426 };
244 /* autogain low level thresholds (-14dB, -11dB, -6dB, -7dB, -8dB) */
245 static const short agc_th_lo
[AGC_MODE_SIZE
] =
246 { 6538, 9235, 16422, 14636, 13045 };
247 /* autogain threshold times [1/5s] or [200ms] */
248 static const short agc_tdrop
[AGC_MODE_SIZE
] =
249 { 900, 225, 150, 60, 8 };
250 static const short agc_trise
[AGC_MODE_SIZE
] =
251 { 9000, 750, 400, 150, 20 };
252 static const short agc_tbal
[AGC_MODE_SIZE
] =
253 { 4500, 500, 300, 100, 15 };
255 static bool agc_enable
= true;
256 static short agc_preset
;
258 static int agc_left
= 0;
259 static int agc_right
= 0;
260 /* AGC time since high target volume was exceeded */
261 static short agc_droptime
= 0;
262 /* AGC time since volume fallen below low target */
263 static short agc_risetime
= 0;
264 /* AGC balance time exceeding +/- 0.7dB */
265 static short agc_baltime
= 0;
266 /* AGC maximum gain */
267 static short agc_maxgain
;
268 #endif /* HAVE_AGC */
270 static void set_gain(void)
272 if(global_settings
.rec_source
== AUDIO_SRC_MIC
)
274 audio_set_recording_gain(global_settings
.rec_mic_gain
,
279 /* AUDIO_SRC_LINEIN, AUDIO_SRC_FMRADIO, AUDIO_SRC_SPDIF */
280 audio_set_recording_gain(global_settings
.rec_left_gain
,
281 global_settings
.rec_right_gain
,
287 /* Read peak meter values & calculate balance.
288 * Returns validity of peak values.
289 * Used for automatic gain control and history diagram.
291 static bool read_peak_levels(int *peak_l
, int *peak_r
, int *balance
)
293 peak_meter_get_peakhold(peak_l
, peak_r
);
294 peak_valid_mem
[peak_time
% 3] = *peak_l
;
295 if (((peak_valid_mem
[0] == peak_valid_mem
[1]) &&
296 (peak_valid_mem
[1] == peak_valid_mem
[2])) &&
299 || ata_disk_is_active()
304 if (*peak_r
> *peak_l
)
305 balance_mem
[peak_time
% BAL_MEM_SIZE
] = (*peak_l
?
306 MIN((10000 * *peak_r
) / *peak_l
- 10000, 15118) : 15118);
308 balance_mem
[peak_time
% BAL_MEM_SIZE
] = (*peak_r
?
309 MAX(10000 - (10000 * *peak_l
) / *peak_r
, -15118) : -15118);
312 for (i
= 0; i
< BAL_MEM_SIZE
; i
++)
313 *balance
+= balance_mem
[i
];
314 *balance
= *balance
/ BAL_MEM_SIZE
;
319 /* AGC helper function to check if maximum gain is reached */
320 static bool agc_gain_is_max(bool left
, bool right
)
322 /* range -128...+108 [0.5dB] */
323 short gain_current_l
;
324 short gain_current_r
;
329 switch (global_settings
.rec_source
)
331 HAVE_LINE_REC_(case AUDIO_SRC_LINEIN
:)
332 HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO
:)
333 gain_current_l
= global_settings
.rec_left_gain
;
334 gain_current_r
= global_settings
.rec_right_gain
;
338 gain_current_l
= global_settings
.rec_mic_gain
;
339 gain_current_r
= global_settings
.rec_mic_gain
;
342 return ((left
&& (gain_current_l
>= agc_maxgain
)) ||
343 (right
&& (gain_current_r
>= agc_maxgain
)));
346 static void change_recording_gain(bool increment
, bool left
, bool right
)
348 int factor
= (increment
? 1 : -1);
350 switch (global_settings
.rec_source
)
352 HAVE_LINE_REC_(case AUDIO_SRC_LINEIN
:)
353 HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO
:)
354 if (left
) global_settings
.rec_left_gain
+= factor
;
355 if (right
) global_settings
.rec_right_gain
+= factor
;
358 global_settings
.rec_mic_gain
+= factor
;
363 * Handle automatic gain control (AGC).
364 * Change recording gain if peak_x levels are above or below
365 * target volume for specified timeouts.
367 static void auto_gain_control(int *peak_l
, int *peak_r
, int *balance
)
373 if (*peak_l
> agc_left
)
376 agc_left
-= (agc_left
- *peak_l
+ 3) >> 2;
377 if (*peak_r
> agc_right
)
380 agc_right
-= (agc_right
- *peak_r
+ 3) >> 2;
381 agc_mono
= (agc_left
+ agc_right
) / 2;
383 agc_mode
= abs(agc_preset
) - 1;
389 if (agc_mode
!= AGC_SAFETY_MODE
) {
390 /* Automatic balance control - only if not in safety mode */
391 if ((agc_left
> AGC_IMG
) && (agc_right
> AGC_IMG
))
396 agc_baltime
-= !(peak_time
% 4); /* 0.47 - 0.75dB */
397 else if (*balance
> -4125)
398 agc_baltime
--; /* 0.75 - 3.00dB */
399 else if (*balance
> -7579)
400 agc_baltime
-= 2; /* 3.00 - 4.90dB */
402 agc_baltime
-= !(peak_time
% 8); /* 4.90 - inf dB */
404 agc_baltime
-= (peak_time
% 2);
406 else if (*balance
> 556)
409 agc_baltime
+= !(peak_time
% 4);
410 else if (*balance
< 4125)
412 else if (*balance
< 7579)
415 agc_baltime
+= !(peak_time
% 8);
417 agc_baltime
+= (peak_time
% 2);
420 if ((*balance
* agc_baltime
) < 0)
423 agc_baltime
-= peak_time
% 2;
425 agc_baltime
+= peak_time
% 2;
428 increment
= ((agc_risetime
/ 2) > agc_droptime
);
430 if (agc_baltime
< -agc_tbal
[agc_mode
])
432 if (!increment
|| !agc_gain_is_max(!increment
, increment
)) {
433 change_recording_gain(increment
, !increment
, increment
);
438 else if (agc_baltime
> +agc_tbal
[agc_mode
])
440 if (!increment
|| !agc_gain_is_max(increment
, !increment
)) {
441 change_recording_gain(increment
, increment
, !increment
);
447 else if (!(hist_time
% 4))
456 /* Automatic gain control */
457 if ((agc_left
> agc_th_hi
[agc_mode
]) || (agc_right
> agc_th_hi
[agc_mode
]))
459 if ((agc_left
> AGC_CLIP
) || (agc_right
> AGC_CLIP
))
460 agc_droptime
+= agc_tdrop
[agc_mode
] /
461 (global_settings
.rec_agc_cliptime
+ 1);
462 if (agc_left
> AGC_HIGH
) {
465 if (agc_left
> AGC_PEAK
)
468 if (agc_right
> AGC_HIGH
) {
471 if (agc_right
> AGC_PEAK
)
474 if (agc_mono
> agc_th_hi
[agc_mode
])
477 agc_droptime
+= !(peak_time
% 2);
479 if (agc_droptime
>= agc_tdrop
[agc_mode
])
481 change_recording_gain(false, true, true);
486 agc_risetime
= MAX(agc_risetime
- 1, 0);
488 else if (agc_mono
< agc_th_lo
[agc_mode
])
490 if (agc_mono
< (agc_th_lo
[agc_mode
] / 8))
491 agc_risetime
+= !(peak_time
% 5);
492 else if (agc_mono
< (agc_th_lo
[agc_mode
] / 2))
497 if (agc_risetime
>= agc_trise
[agc_mode
]) {
498 if ((agc_mode
!= AGC_SAFETY_MODE
) &&
499 (!agc_gain_is_max(true, true))) {
500 change_recording_gain(true, true, true);
506 agc_droptime
= MAX(agc_droptime
- 1, 0);
508 else if (!(peak_time
% 6)) /* on target level every 1.2 sec */
510 agc_risetime
= MAX(agc_risetime
- 1, 0);
511 agc_droptime
= MAX(agc_droptime
- 1, 0);
514 #endif /* HAVE_AGC */
516 static const char* const fmtstr
[] =
518 "%c%d %s", /* no decimals */
519 "%c%d.%d %s ", /* 1 decimal */
520 "%c%d.%02d %s " /* 2 decimals */
523 static char *fmt_gain(int snd
, int val
, char *str
, int len
)
529 val
= sound_val2phys(snd
, val
);
535 numdec
= sound_numdecimals(snd
);
536 unit
= sound_unit(snd
);
540 i
= val
/ (10*numdec
);
541 d
= val
% (10*numdec
);
542 snprintf(str
, len
, fmtstr
[numdec
], sign
, i
, d
, unit
);
545 snprintf(str
, len
, fmtstr
[numdec
], sign
, val
, unit
);
552 static void adjust_cursor(void)
560 switch(global_settings
.rec_source
)
567 HAVE_LINE_REC_(case AUDIO_SRC_LINEIN
:)
568 HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO
:)
575 #else /* !HAVE_AGC */
576 switch(global_settings
.rec_source
)
581 HAVE_LINE_REC_(case AUDIO_SRC_LINEIN
:)
582 HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO
:)
589 #endif /* HAVE_AGC */
591 if(cursor
> max_cursor
)
595 /* the list below must match enum audio_sources in audio.h */
596 static const char* const prestr
[] =
598 HAVE_MIC_IN_([AUDIO_SRC_MIC
] = "R_MIC_",)
599 HAVE_LINE_REC_([AUDIO_SRC_LINEIN
] = "R_LINE_",)
600 HAVE_SPDIF_IN_([AUDIO_SRC_SPDIF
] = "R_SPDIF_",)
601 HAVE_FMRADIO_REC_([AUDIO_SRC_FMRADIO
] = "R_FM_",)
604 char *rec_create_filename(char *buffer
)
607 const char *pref
= "R_";
609 /* Directory existence and writeablility should have already been
610 * verified - do not pass NULL pointers to pcmrec */
612 if((unsigned)global_settings
.rec_source
< AUDIO_NUM_SOURCES
)
614 pref
= prestr
[global_settings
.rec_source
];
617 strcpy(buffer
, global_settings
.rec_directory
);
619 snprintf(ext
, sizeof(ext
), ".%s",
620 REC_FILE_ENDING(global_settings
.rec_format
));
623 return create_numbered_filename(buffer
, buffer
, pref
, ext
, 4,
626 /* We'll wait at least up to the start of the next second so no duplicate
628 return create_datetime_filename(buffer
, buffer
, pref
, ext
, true);
633 /* Hit disk to get a starting filename for the type */
634 static void rec_init_filename(void)
637 rec_create_filename(path_buffer
);
642 int rec_create_directory(void)
645 const char * const folder
= global_settings
.rec_directory
;
647 if (strcmp(folder
, "/") && !dir_exists(folder
))
653 while (action_userabort(HZ
) == false)
655 gui_syncsplash(0, "%s %s",
656 str(LANG_REC_DIR_NOT_WRITABLE
),
657 str(LANG_OFF_ABORT
));
662 rec_status
|= RCSTAT_CREATED_DIRECTORY
;
670 void rec_init_recording_options(struct audio_recording_options
*options
)
672 options
->rec_source
= global_settings
.rec_source
;
673 options
->rec_frequency
= global_settings
.rec_frequency
;
674 options
->rec_channels
= global_settings
.rec_channels
;
675 options
->rec_prerecord_time
= global_settings
.rec_prerecord_time
;
676 #if CONFIG_CODEC == SWCODEC
677 options
->rec_source_flags
= 0;
678 options
->enc_config
.rec_format
= global_settings
.rec_format
;
679 global_to_encoder_config(&options
->enc_config
);
681 options
->rec_quality
= global_settings
.rec_quality
;
682 options
->rec_editable
= global_settings
.rec_editable
;
686 #if CONFIG_CODEC == SWCODEC && !defined (SIMULATOR)
687 void rec_set_source(int source
, unsigned flags
)
689 /* Set audio input source, power up/down devices */
690 audio_set_input_source(source
, flags
);
692 /* Set peakmeters for recording or reset to playback */
693 peak_meter_playback((flags
& SRCF_RECORDING
) == 0);
694 peak_meter_enabled
= true;
696 #endif /* CONFIG_CODEC == SWCODEC && !defined (SIMULATOR) */
698 void rec_set_recording_options(struct audio_recording_options
*options
)
700 #if CONFIG_CODEC != SWCODEC
701 if (global_settings
.rec_prerecord_time
)
703 talk_buffer_steal(); /* will use the mp3 buffer */
705 #else /* == SWCODEC */
706 rec_set_source(options
->rec_source
,
707 options
->rec_source_flags
| SRCF_RECORDING
);
708 #endif /* CONFIG_CODEC != SWCODEC */
710 audio_set_recording_options(options
);
713 void rec_command(enum recording_command cmd
)
717 case RECORDING_CMD_STOP
:
718 pm_activate_clipcount(false);
719 audio_stop_recording();
721 case RECORDING_CMD_START
:
722 /* steal mp3 buffer, create unique filename and start recording */
723 pm_reset_clipcount();
724 pm_activate_clipcount(true);
725 #if CONFIG_CODEC != SWCODEC
726 talk_buffer_steal(); /* we use the mp3 buffer */
728 audio_record(rec_create_filename(path_buffer
));
730 case RECORDING_CMD_START_NEWFILE
:
731 /* create unique filename and start recording*/
732 pm_reset_clipcount();
733 pm_activate_clipcount(true); /* just to be sure */
734 audio_new_file(rec_create_filename(path_buffer
));
736 case RECORDING_CMD_PAUSE
:
737 pm_activate_clipcount(false);
738 audio_pause_recording();
740 case RECORDING_CMD_RESUME
:
741 pm_activate_clipcount(true);
742 audio_resume_recording();
747 /* used in trigger_listerner and recording_screen */
748 static unsigned int last_seconds
= 0;
751 * Callback function so that the peak meter code can send an event
752 * to this application. This function can be passed to
753 * peak_meter_set_trigger_listener in order to activate the trigger.
755 static void trigger_listener(int trigger_status
)
757 switch (trigger_status
)
760 if(!(audio_status() & AUDIO_STATUS_RECORD
))
762 rec_status
|= RCSTAT_HAVE_RECORDED
;
763 rec_command(RECORDING_CMD_START
);
764 #if CONFIG_CODEC != SWCODEC
765 /* give control to mpeg thread so that it can start
767 yield(); yield(); yield();
771 /* if we're already recording this is a retrigger */
774 if((audio_status() & AUDIO_STATUS_PAUSE
) &&
775 (global_settings
.rec_trigger_type
== 1))
777 rec_command(RECORDING_CMD_RESUME
);
779 /* New file on trig start*/
780 else if (global_settings
.rec_trigger_type
!= 2)
782 rec_command(RECORDING_CMD_START_NEWFILE
);
783 /* tell recording_screen to reset the time */
789 /* A _change_ to TRIG_READY means the current recording has stopped */
791 if(audio_status() & AUDIO_STATUS_RECORD
)
793 switch(global_settings
.rec_trigger_type
)
796 rec_command(RECORDING_CMD_STOP
);
800 rec_command(RECORDING_CMD_PAUSE
);
803 case 2: /* New file on trig stop*/
804 rec_command(RECORDING_CMD_START_NEWFILE
);
805 /* tell recording_screen to reset the time */
810 if (global_settings
.rec_trigger_mode
!= TRIG_MODE_REARM
)
812 peak_meter_set_trigger_listener(NULL
);
813 peak_meter_trigger(false);
820 bool recording_start_automatic
= false;
822 bool recording_screen(bool no_source
)
829 int update_countdown
= 1;
830 unsigned int seconds
;
833 int last_audio_stat
= -1;
835 #if CONFIG_CODEC == SWCODEC
836 int warning_counter
= 0;
837 #define WARNING_PERIOD 7
839 #ifdef HAVE_FMRADIO_REC
840 /* Radio is left on if:
841 * 1) Is was on at the start and the initial source is FM Radio
842 * 2) 1) and the source was never changed to something else
844 int radio_status
= (global_settings
.rec_source
!= AUDIO_SRC_FMRADIO
) ?
845 FMRADIO_OFF
: get_radio_status();
847 #if (CONFIG_LED == LED_REAL)
848 bool led_state
= false;
849 int led_countdown
= 2;
852 bool peak_read
= false;
853 bool peak_valid
= false;
856 bool display_agc
[NB_SCREENS
];
858 int line
[NB_SCREENS
];
860 int filename_offset
[NB_SCREENS
];
861 int pm_y
[NB_SCREENS
];
862 int trig_xpos
[NB_SCREENS
];
863 int trig_ypos
[NB_SCREENS
];
864 int trig_width
[NB_SCREENS
];
865 /* pm_x = offset pm to put clipcount in front.
866 Use lcd_getstringsize() when not using SYSFONT */
867 int pm_x
= global_settings
.peak_meter_clipcounter
? 30 : 0;
869 static const unsigned char *byte_units
[] = {
876 int base_style
= STYLE_INVERT
;
878 #ifdef HAVE_LCD_COLOR
879 if (global_settings
.cursor_style
== 2) {
880 base_style
|= STYLE_COLORBAR
;
882 else if (global_settings
.cursor_style
== 3) {
883 base_style
|= STYLE_GRADIENT
;
887 struct audio_recording_options rec_options
;
888 rec_status
= RCSTAT_IN_RECSCREEN
;
890 if (rec_create_directory() < 0)
897 #if (CONFIG_LED == LED_REAL) && !defined(SIMULATOR)
898 ata_set_led_enabled(false);
901 #if CONFIG_CODEC == SWCODEC
902 /* recording_menu gets messed up: so prevent manus talking */
904 /* audio_init_recording stops anything playing when it takes the audio
907 /* Yes, we use the D/A for monitoring */
908 peak_meter_enabled
= true;
909 peak_meter_playback(true);
912 audio_init_recording(0);
913 sound_set_volume(global_settings
.volume
);
916 peak_meter_get_peakhold(&peak_l
, &peak_r
);
919 rec_init_recording_options(&rec_options
);
920 rec_set_recording_options(&rec_options
);
925 /* Create new filename for recording start */
929 pm_reset_clipcount();
930 pm_activate_clipcount(false);
931 settings_apply_trigger();
934 agc_preset_str
[0] = str(LANG_SYSFONT_OFF
);
935 agc_preset_str
[1] = str(LANG_SYSFONT_AGC_SAFETY
);
936 agc_preset_str
[2] = str(LANG_SYSFONT_AGC_LIVE
);
937 agc_preset_str
[3] = str(LANG_SYSFONT_AGC_DJSET
);
938 agc_preset_str
[4] = str(LANG_SYSFONT_AGC_MEDIUM
);
939 agc_preset_str
[5] = str(LANG_SYSFONT_AGC_VOICE
);
940 if (global_settings
.rec_source
== AUDIO_SRC_MIC
) {
941 agc_preset
= global_settings
.rec_agc_preset_mic
;
942 agc_maxgain
= global_settings
.rec_agc_maxgain_mic
;
945 agc_preset
= global_settings
.rec_agc_preset_line
;
946 agc_maxgain
= global_settings
.rec_agc_maxgain_line
;
948 #endif /* HAVE_AGC */
952 screens
[i
].setfont(FONT_SYSFIXED
);
953 screens
[i
].getstringsize("M", &w
, &h
);
954 screens
[i
].setmargins(global_settings
.cursor_style
? 0 : w
, 8);
955 filename_offset
[i
] = ((screens
[i
].height
>= 80) ? 1 : 0);
956 pm_y
[i
] = 8 + h
* (2 + filename_offset
[i
]);
959 #ifdef HAVE_REMOTE_LCD
960 if (!remote_display_on
)
962 screens
[1].clear_display();
963 snprintf(buf
, sizeof(buf
), str(LANG_REMOTE_LCD_ON
));
964 screens
[1].puts((screens
[1].width
/w
- strlen(buf
))/2 + 1,
965 screens
[1].height
/(h
*2) + 1, buf
);
967 gui_syncsplash(0, str(LANG_REMOTE_LCD_OFF
));
973 audio_stat
= audio_status();
975 #if (CONFIG_LED == LED_REAL)
978 * Flash the LED while waiting to record. Turn it on while
981 if(audio_stat
& AUDIO_STATUS_RECORD
)
983 if (audio_stat
& AUDIO_STATUS_PAUSE
)
985 if (--led_countdown
<= 0)
987 led_state
= !led_state
;
994 /* trigger is on in status TRIG_READY (no check needed) */
1000 int trigStat
= peak_meter_trigger_status();
1002 * other trigger stati than trig_off and trig_steady
1003 * already imply that we are recording.
1005 if (trigStat
== TRIG_STEADY
)
1007 if (--led_countdown
<= 0)
1009 led_state
= !led_state
;
1016 /* trigger is on in status TRIG_READY (no check needed) */
1020 #endif /* CONFIG_LED */
1022 /* Wait for a button a while (HZ/10) drawing the peak meter */
1023 button
= peak_meter_draw_get_btn(pm_x
, pm_y
, h
* PM_HEIGHT
,
1026 if (last_audio_stat
!= audio_stat
)
1028 if (audio_stat
& AUDIO_STATUS_RECORD
)
1030 rec_status
|= RCSTAT_HAVE_RECORDED
;
1032 last_audio_stat
= audio_stat
;
1036 if (recording_start_automatic
)
1038 /* simulate a button press */
1039 button
= ACTION_REC_PAUSE
;
1040 recording_start_automatic
= false;
1045 #ifdef HAVE_REMOTE_LCD
1046 case ACTION_REC_LCD
:
1047 if (remote_display_on
)
1049 remote_display_on
= false;
1051 screens
[1].clear_display();
1052 snprintf(buf
, sizeof(buf
), str(LANG_REMOTE_LCD_ON
));
1053 screens
[1].puts((screens
[1].width
/w
- strlen(buf
))/2 + 1,
1054 screens
[1].height
/(h
*2) + 1, buf
);
1055 screens
[1].update();
1056 gui_syncsplash(0, str(LANG_REMOTE_LCD_OFF
));
1060 remote_display_on
= true;
1061 screen_update
= NB_SCREENS
;
1065 case ACTION_STD_CANCEL
:
1066 /* turn off the trigger */
1067 peak_meter_trigger(false);
1068 peak_meter_set_trigger_listener(NULL
);
1070 if(audio_stat
& AUDIO_STATUS_RECORD
)
1072 rec_command(RECORDING_CMD_STOP
);
1076 #if CONFIG_CODEC != SWCODEC
1077 peak_meter_playback(true);
1078 peak_meter_enabled
= false;
1082 update_countdown
= 1; /* Update immediately */
1085 case ACTION_REC_PAUSE
:
1086 case ACTION_REC_NEWFILE
:
1087 /* Only act if the mpeg is stopped */
1088 if(!(audio_stat
& AUDIO_STATUS_RECORD
))
1090 /* is this manual or triggered recording? */
1091 if ((global_settings
.rec_trigger_mode
== TRIG_MODE_OFF
) ||
1092 (peak_meter_trigger_status() != TRIG_OFF
))
1094 /* manual recording */
1095 rec_status
|= RCSTAT_HAVE_RECORDED
;
1096 rec_command(RECORDING_CMD_START
);
1098 if (global_settings
.talk_menu
)
1100 /* no voice possible here, but a beep */
1101 audio_beep(HZ
/2); /* longer beep on start */
1104 /* this is triggered recording */
1107 /* we don't start recording now, but enable the
1108 trigger and let the callback function
1109 trigger_listener control when the recording starts */
1110 peak_meter_trigger(true);
1111 peak_meter_set_trigger_listener(&trigger_listener
);
1116 /*if new file button pressed, start new file */
1117 if (button
== ACTION_REC_NEWFILE
)
1119 rec_command(RECORDING_CMD_START_NEWFILE
);
1123 /* if pause button pressed, pause or resume */
1125 if(audio_stat
& AUDIO_STATUS_PAUSE
)
1127 rec_command(RECORDING_CMD_RESUME
);
1128 if (global_settings
.talk_menu
)
1130 /* no voice possible here, but a beep */
1131 audio_beep(HZ
/4); /* short beep on resume */
1136 rec_command(RECORDING_CMD_PAUSE
);
1140 update_countdown
= 1; /* Update immediately */
1143 case ACTION_STD_PREV
:
1146 update_countdown
= 1; /* Update immediately */
1149 case ACTION_STD_NEXT
:
1152 update_countdown
= 1; /* Update immediately */
1155 case ACTION_SETTINGS_INC
:
1156 case ACTION_SETTINGS_INCREPEAT
:
1160 global_settings
.volume
++;
1164 if(global_settings
.rec_source
== AUDIO_SRC_MIC
)
1166 if(global_settings
.rec_mic_gain
<
1167 sound_max(SOUND_MIC_GAIN
))
1168 global_settings
.rec_mic_gain
++;
1172 if(global_settings
.rec_left_gain
<
1173 sound_max(SOUND_LEFT_GAIN
))
1174 global_settings
.rec_left_gain
++;
1175 if(global_settings
.rec_right_gain
<
1176 sound_max(SOUND_RIGHT_GAIN
))
1177 global_settings
.rec_right_gain
++;
1181 if(global_settings
.rec_left_gain
<
1182 sound_max(SOUND_LEFT_GAIN
))
1183 global_settings
.rec_left_gain
++;
1186 if(global_settings
.rec_right_gain
<
1187 sound_max(SOUND_RIGHT_GAIN
))
1188 global_settings
.rec_right_gain
++;
1192 agc_preset
= MIN(agc_preset
+ 1, AGC_MODE_SIZE
);
1193 agc_enable
= (agc_preset
!= 0);
1194 if (global_settings
.rec_source
== AUDIO_SRC_MIC
) {
1195 global_settings
.rec_agc_preset_mic
= agc_preset
;
1196 agc_maxgain
= global_settings
.rec_agc_maxgain_mic
;
1198 global_settings
.rec_agc_preset_line
= agc_preset
;
1199 agc_maxgain
= global_settings
.rec_agc_maxgain_line
;
1203 if (global_settings
.rec_source
== AUDIO_SRC_MIC
)
1205 agc_maxgain
= MIN(agc_maxgain
+ 1,
1206 sound_max(SOUND_MIC_GAIN
));
1207 global_settings
.rec_agc_maxgain_mic
= agc_maxgain
;
1211 agc_maxgain
= MIN(agc_maxgain
+ 1,
1212 sound_max(SOUND_LEFT_GAIN
));
1213 global_settings
.rec_agc_maxgain_line
= agc_maxgain
;
1216 #endif /* HAVE_AGC */
1219 update_countdown
= 1; /* Update immediately */
1222 case ACTION_SETTINGS_DEC
:
1223 case ACTION_SETTINGS_DECREPEAT
:
1227 global_settings
.volume
--;
1231 if(global_settings
.rec_source
== AUDIO_SRC_MIC
)
1233 if(global_settings
.rec_mic_gain
>
1234 sound_min(SOUND_MIC_GAIN
))
1235 global_settings
.rec_mic_gain
--;
1239 if(global_settings
.rec_left_gain
>
1240 sound_min(SOUND_LEFT_GAIN
))
1241 global_settings
.rec_left_gain
--;
1242 if(global_settings
.rec_right_gain
>
1243 sound_min(SOUND_RIGHT_GAIN
))
1244 global_settings
.rec_right_gain
--;
1248 if(global_settings
.rec_left_gain
>
1249 sound_min(SOUND_LEFT_GAIN
))
1250 global_settings
.rec_left_gain
--;
1253 if(global_settings
.rec_right_gain
>
1254 sound_min(SOUND_RIGHT_GAIN
))
1255 global_settings
.rec_right_gain
--;
1259 agc_preset
= MAX(agc_preset
- 1, 0);
1260 agc_enable
= (agc_preset
!= 0);
1261 if (global_settings
.rec_source
== AUDIO_SRC_MIC
) {
1262 global_settings
.rec_agc_preset_mic
= agc_preset
;
1263 agc_maxgain
= global_settings
.rec_agc_maxgain_mic
;
1265 global_settings
.rec_agc_preset_line
= agc_preset
;
1266 agc_maxgain
= global_settings
.rec_agc_maxgain_line
;
1270 if (global_settings
.rec_source
== AUDIO_SRC_MIC
)
1272 agc_maxgain
= MAX(agc_maxgain
- 1,
1273 sound_min(SOUND_MIC_GAIN
));
1274 global_settings
.rec_agc_maxgain_mic
= agc_maxgain
;
1278 agc_maxgain
= MAX(agc_maxgain
- 1,
1279 sound_min(SOUND_LEFT_GAIN
));
1280 global_settings
.rec_agc_maxgain_line
= agc_maxgain
;
1283 #endif /* HAVE_AGC */
1286 update_countdown
= 1; /* Update immediately */
1289 case ACTION_STD_MENU
:
1290 #if CONFIG_CODEC == SWCODEC
1291 if(!(audio_stat
& AUDIO_STATUS_RECORD
))
1293 if(audio_stat
!= AUDIO_STATUS_RECORD
)
1296 #ifdef HAVE_FMRADIO_REC
1297 const int prev_rec_source
= global_settings
.rec_source
;
1300 #if (CONFIG_LED == LED_REAL)
1301 /* led is restored at begin of loop / end of function */
1304 if (recording_menu(no_source
))
1307 rec_status
|= RCSTAT_BEEN_IN_USB_MODE
;
1308 #ifdef HAVE_FMRADIO_REC
1309 radio_status
= FMRADIO_OFF
;
1314 #ifdef HAVE_FMRADIO_REC
1315 /* If input changes away from FM Radio, radio will
1316 remain off when recording screen closes. */
1317 if (global_settings
.rec_source
!= prev_rec_source
1318 && prev_rec_source
== AUDIO_SRC_FMRADIO
)
1319 radio_status
= FMRADIO_OFF
;
1322 #if CONFIG_CODEC == SWCODEC
1323 /* reinit after submenu exit */
1324 audio_close_recording();
1325 audio_init_recording(0);
1328 rec_init_recording_options(&rec_options
);
1329 rec_set_recording_options(&rec_options
);
1331 if(rec_create_directory() < 0)
1336 #if CONFIG_CODEC == SWCODEC && CONFIG_RTC == 0
1337 /* If format changed, a new number is required */
1338 rec_init_filename();
1342 if (global_settings
.rec_source
== AUDIO_SRC_MIC
) {
1343 agc_preset
= global_settings
.rec_agc_preset_mic
;
1344 agc_maxgain
= global_settings
.rec_agc_maxgain_mic
;
1347 agc_preset
= global_settings
.rec_agc_preset_line
;
1348 agc_maxgain
= global_settings
.rec_agc_maxgain_line
;
1354 update_countdown
= 1; /* Update immediately */
1358 screens
[i
].setfont(FONT_SYSFIXED
);
1359 screens
[i
].setmargins(
1360 global_settings
.cursor_style
? 0 : w
, 8);
1366 #if CONFIG_KEYPAD == RECORDER_PAD
1368 if(audio_stat
!= AUDIO_STATUS_RECORD
)
1370 #if (CONFIG_LED == LED_REAL)
1371 /* led is restored at begin of loop / end of function */
1374 if (f2_rec_screen())
1376 rec_status
|= RCSTAT_HAVE_RECORDED
;
1380 update_countdown
= 1; /* Update immediately */
1385 if(audio_stat
& AUDIO_STATUS_RECORD
)
1387 rec_command(RECORDING_CMD_START_NEWFILE
);
1392 #if (CONFIG_LED == LED_REAL)
1393 /* led is restored at begin of loop / end of function */
1396 if (f3_rec_screen())
1398 rec_status
|= RCSTAT_HAVE_RECORDED
;
1402 update_countdown
= 1; /* Update immediately */
1405 #endif /* CONFIG_KEYPAD == RECORDER_PAD */
1407 case SYS_USB_CONNECTED
:
1408 /* Only accept USB connection when not recording */
1409 if(!(audio_stat
& AUDIO_STATUS_RECORD
))
1411 default_event_handler(SYS_USB_CONNECTED
);
1413 rec_status
|= RCSTAT_BEEN_IN_USB_MODE
;
1414 #ifdef HAVE_FMRADIO_REC
1415 radio_status
= FMRADIO_OFF
;
1421 default_event_handler(button
);
1426 peak_read
= !peak_read
;
1427 if (peak_read
) { /* every 2nd run of loop */
1429 peak_valid
= read_peak_levels(&peak_l
, &peak_r
, &balance
);
1432 /* Handle AGC every 200ms when enabled and peak data is valid */
1433 if (peak_read
&& agc_enable
&& peak_valid
)
1434 auto_gain_control(&peak_l
, &peak_r
, &balance
);
1438 screens
[i
].setfont(FONT_SYSFIXED
);
1440 seconds
= audio_recorded_time() / HZ
;
1443 if(update_countdown
== 0 || seconds
> last_seconds
)
1445 unsigned int dseconds
, dhours
, dminutes
;
1446 unsigned long num_recorded_bytes
, dsize
, dmb
;
1449 update_countdown
= 5;
1450 last_seconds
= seconds
;
1452 dseconds
= rec_timesplit_seconds();
1453 dsize
= rec_sizesplit_bytes();
1454 num_recorded_bytes
= audio_num_recorded_bytes();
1456 for(i
= 0; i
< screen_update
; i
++)
1457 screens
[i
].clear_display();
1461 #ifdef HAVE_LCD_COLOR
1462 /* special action for gradient - set default for 1 line gradient */
1463 if(global_settings
.cursor_style
== 3)
1464 style
= base_style
| CURLN_PACK(0) | NUMLN_PACK(1);
1465 #endif /* HAVE_LCD_COLOR */
1467 #if CONFIG_CODEC == SWCODEC
1468 if ((audio_stat
& AUDIO_STATUS_WARNING
)
1469 && (warning_counter
++ % WARNING_PERIOD
) < WARNING_PERIOD
/2)
1471 /* Switch back and forth displaying warning on first available
1472 line to ensure visibility - the motion should also help
1474 /* Don't use language string unless agreed upon to make this
1475 method permanent - could do something in the statusbar */
1476 snprintf(buf
, sizeof(buf
), "Warning: %08X",
1477 pcm_rec_get_warnings());
1480 #endif /* CONFIG_CODEC == SWCODEC */
1481 if ((global_settings
.rec_sizesplit
) &&
1482 (global_settings
.rec_split_method
))
1484 dmb
= dsize
/1024/1024;
1485 snprintf(buf
, sizeof(buf
), "%s %dMB",
1486 str(LANG_SYSFONT_SPLIT_SIZE
), dmb
);
1490 hours
= seconds
/ 3600;
1491 minutes
= (seconds
- (hours
* 3600)) / 60;
1492 snprintf(buf
, sizeof(buf
), "%s %02d:%02d:%02d",
1493 str(LANG_SYSFONT_RECORDING_TIME
),
1494 hours
, minutes
, seconds
%60);
1497 for(i
= 0; i
< screen_update
; i
++)
1498 screens
[i
].puts(0, 0, buf
);
1500 if(audio_stat
& AUDIO_STATUS_PRERECORD
)
1502 snprintf(buf
, sizeof(buf
), "%s...",
1503 str(LANG_SYSFONT_RECORD_PRERECORD
));
1507 /* Display the split interval if the record timesplit
1509 if ((global_settings
.rec_timesplit
) &&
1510 !(global_settings
.rec_split_method
))
1512 /* Display the record timesplit interval rather
1513 than the file size if the record timer is
1515 dhours
= dseconds
/ 3600;
1516 dminutes
= (dseconds
- (dhours
* 3600)) / 60;
1517 snprintf(buf
, sizeof(buf
), "%s %02d:%02d",
1518 str(LANG_SYSFONT_RECORD_TIMESPLIT_REC
),
1523 output_dyn_value(buf2
, sizeof buf2
,
1526 snprintf(buf
, sizeof(buf
), "%s %s",
1527 str(LANG_SYSFONT_RECORDING_SIZE
), buf2
);
1530 for(i
= 0; i
< screen_update
; i
++)
1531 screens
[i
].puts(0, 1, buf
);
1533 for(i
= 0; i
< screen_update
; i
++)
1535 if (filename_offset
[i
] > 0)
1538 if (audio_stat
& AUDIO_STATUS_RECORD
)
1540 strncpy(filename
, path_buffer
+
1541 strlen(path_buffer
) - 12, 13);
1545 snprintf(buf
, sizeof(buf
), "%s %s",
1546 str(LANG_SYSFONT_RECORDING_FILENAME
), filename
);
1547 screens
[i
].puts(0, 2, buf
);
1551 /* We will do file splitting regardless, either at the end of
1552 a split interval, or when the filesize approaches the 2GB
1553 FAT file size (compatibility) limit. */
1554 if ((audio_stat
&& !(global_settings
.rec_split_method
)
1555 && global_settings
.rec_timesplit
&& (seconds
>= dseconds
))
1556 || (audio_stat
&& global_settings
.rec_split_method
1557 && global_settings
.rec_sizesplit
1558 && (num_recorded_bytes
>= dsize
))
1559 || (num_recorded_bytes
>= MAX_FILE_SIZE
))
1561 if (!(global_settings
.rec_split_type
)
1562 || (num_recorded_bytes
>= MAX_FILE_SIZE
))
1564 rec_command(RECORDING_CMD_START_NEWFILE
);
1569 peak_meter_trigger(false);
1570 peak_meter_set_trigger_listener(NULL
);
1571 rec_command(RECORDING_CMD_STOP
);
1573 update_countdown
= 1;
1576 /* draw the clipcounter just in front of the peakmeter */
1577 if(global_settings
.peak_meter_clipcounter
)
1580 snprintf(clpstr
, 32, "%4d", pm_get_clipcount());
1581 for(i
= 0; i
< screen_update
; i
++)
1584 screens
[i
].puts(0, 2 + filename_offset
[i
],
1585 str(LANG_SYSFONT_PM_CLIPCOUNT
));
1586 screens
[i
].puts(0, 1 + PM_HEIGHT
+ filename_offset
[i
],
1591 snprintf(buf
, sizeof(buf
), "%s: %s", str(LANG_SYSFONT_VOLUME
),
1592 fmt_gain(SOUND_VOLUME
,
1593 global_settings
.volume
,
1594 buf2
, sizeof(buf2
)));
1596 if (global_settings
.cursor_style
&& (pos
++ == cursor
))
1598 for(i
= 0; i
< screen_update
; i
++)
1599 screens
[i
].puts_style_offset(0, filename_offset
[i
] +
1600 PM_HEIGHT
+ 2, buf
, style
,0);
1604 for(i
= 0; i
< screen_update
; i
++)
1605 screens
[i
].puts(0, filename_offset
[i
] + PM_HEIGHT
+ 2, buf
);
1608 if(global_settings
.rec_source
== AUDIO_SRC_MIC
)
1610 /* Draw MIC recording gain */
1611 snprintf(buf
, sizeof(buf
), "%s:%s", str(LANG_SYSFONT_GAIN
),
1612 fmt_gain(SOUND_MIC_GAIN
,
1613 global_settings
.rec_mic_gain
,
1614 buf2
, sizeof(buf2
)));
1615 if(global_settings
.cursor_style
&& ((1==cursor
)||(2==cursor
)))
1617 for(i
= 0; i
< screen_update
; i
++)
1618 screens
[i
].puts_style_offset(0, filename_offset
[i
] +
1619 PM_HEIGHT
+ 3, buf
, style
,0);
1623 for(i
= 0; i
< screen_update
; i
++)
1624 screens
[i
].puts(0, filename_offset
[i
] +
1625 PM_HEIGHT
+ 3, buf
);
1629 HAVE_LINE_REC_( || global_settings
.rec_source
==
1631 HAVE_FMRADIO_REC_( || global_settings
.rec_source
==
1635 /* Draw LINE or FMRADIO recording gain */
1636 snprintf(buf
, sizeof(buf
), "%s:%s",
1637 str(LANG_SYSFONT_RECORDING_LEFT
),
1638 fmt_gain(SOUND_LEFT_GAIN
,
1639 global_settings
.rec_left_gain
,
1640 buf2
, sizeof(buf2
)));
1641 #ifdef HAVE_LCD_COLOR
1642 /* special action for gradient - double line gradient - line1 */
1643 if((global_settings
.cursor_style
== 3) &&
1645 style
= base_style
| CURLN_PACK(0) | NUMLN_PACK(2);
1646 #endif /* HAVE_LCD_COLOR */
1647 if(global_settings
.cursor_style
&& ((1==cursor
)||(2==cursor
)))
1649 for(i
= 0; i
< screen_update
; i
++)
1650 screens
[i
].puts_style_offset(0, filename_offset
[i
] +
1651 PM_HEIGHT
+ 3, buf
, style
,0);
1655 for(i
= 0; i
< screen_update
; i
++)
1656 screens
[i
].puts(0, filename_offset
[i
] +
1657 PM_HEIGHT
+ 3, buf
);
1660 snprintf(buf
, sizeof(buf
), "%s:%s",
1661 str(LANG_SYSFONT_RECORDING_RIGHT
),
1662 fmt_gain(SOUND_RIGHT_GAIN
,
1663 global_settings
.rec_right_gain
,
1664 buf2
, sizeof(buf2
)));
1665 #ifdef HAVE_LCD_COLOR
1666 /* special action for gradient - double line gradient - line2 */
1667 if((global_settings
.cursor_style
== 3) &&
1669 style
= base_style
| CURLN_PACK(1) | NUMLN_PACK(2);
1670 #endif /* HAVE_LCD_COLOR */
1671 if(global_settings
.cursor_style
&& ((1==cursor
)||(3==cursor
)))
1673 for(i
= 0; i
< screen_update
; i
++)
1674 screens
[i
].puts_style_offset(0, filename_offset
[i
] +
1675 PM_HEIGHT
+ 4, buf
, style
,0);
1679 for(i
= 0; i
< screen_update
; i
++)
1680 screens
[i
].puts(0, filename_offset
[i
] +
1681 PM_HEIGHT
+ 4, buf
);
1684 #ifdef HAVE_LCD_COLOR
1685 /* special action for gradient - back to single line gradient */
1686 if(global_settings
.cursor_style
== 3)
1687 style
= base_style
| CURLN_PACK(0) | NUMLN_PACK(1);
1688 #endif /* HAVE_LCD_COLOR */
1692 switch (global_settings
.rec_source
)
1694 HAVE_LINE_REC_(case AUDIO_SRC_LINEIN
:)
1695 HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO
:)
1702 #ifdef HAVE_SPDIF_REC
1703 case AUDIO_SRC_SPDIF
:
1708 line
[i
] = 5; /* to prevent uninitialisation
1709 warnings for line[0] */
1713 if (screens
[i
].height
< h
* (2 + filename_offset
[i
] +
1714 PM_HEIGHT
+ line
[i
]))
1717 display_agc
[i
] = false;
1720 display_agc
[i
] = true;
1722 if ((cursor
==4) || (cursor
==5))
1723 display_agc
[i
] = true;
1726 /************** AGC test info ******************
1727 snprintf(buf, sizeof(buf), "D:%d U:%d",
1728 (agc_droptime+2)/5, (agc_risetime+2)/5);
1729 lcd_putsxy(1, LCD_HEIGHT - 8, buf);
1730 snprintf(buf, sizeof(buf), "B:%d",
1732 lcd_putsxy(LCD_WIDTH/2 + 3, LCD_HEIGHT - 8, buf);
1733 ***********************************************/
1736 snprintf(buf
, sizeof(buf
), "%s: %s",
1737 str(LANG_SYSFONT_RECORDING_AGC_MAXGAIN
),
1738 fmt_gain(SOUND_LEFT_GAIN
,
1739 agc_maxgain
, buf2
, sizeof(buf2
)));
1740 else if (agc_preset
== 0)
1741 snprintf(buf
, sizeof(buf
), "%s: %s",
1742 str(LANG_SYSFONT_RECORDING_AGC_PRESET
),
1743 agc_preset_str
[agc_preset
]);
1744 else if (global_settings
.rec_source
== AUDIO_SRC_MIC
)
1745 snprintf(buf
, sizeof(buf
), "%s: %s%s",
1746 str(LANG_SYSFONT_RECORDING_AGC_PRESET
),
1747 agc_preset_str
[agc_preset
],
1748 fmt_gain(SOUND_LEFT_GAIN
,
1750 global_settings
.rec_mic_gain
,
1751 buf2
, sizeof(buf2
)));
1753 snprintf(buf
, sizeof(buf
), "%s: %s%s",
1754 str(LANG_SYSFONT_RECORDING_AGC_PRESET
),
1755 agc_preset_str
[agc_preset
],
1756 fmt_gain(SOUND_LEFT_GAIN
,
1758 (global_settings
.rec_left_gain
+
1759 global_settings
.rec_right_gain
)/2,
1760 buf2
, sizeof(buf2
)));
1762 if(global_settings
.cursor_style
&& ((cursor
==4) || (cursor
==5)))
1764 for(i
= 0; i
< screen_update
; i
++)
1765 screens
[i
].puts_style_offset(0, filename_offset
[i
] +
1766 PM_HEIGHT
+ line
[i
], buf
, style
,0);
1768 else if (global_settings
.rec_source
== AUDIO_SRC_MIC
1769 HAVE_LINE_REC_(|| global_settings
.rec_source
==
1771 HAVE_FMRADIO_REC_(|| global_settings
.rec_source
==
1775 for(i
= 0; i
< screen_update
; i
++) {
1776 if (display_agc
[i
]) {
1777 screens
[i
].puts(0, filename_offset
[i
] +
1778 PM_HEIGHT
+ line
[i
], buf
);
1783 if (global_settings
.rec_source
== AUDIO_SRC_MIC
)
1785 if(agc_maxgain
< (global_settings
.rec_mic_gain
))
1786 change_recording_gain(false, true, true);
1790 if(agc_maxgain
< (global_settings
.rec_left_gain
))
1791 change_recording_gain(false, true, false);
1792 if(agc_maxgain
< (global_settings
.rec_right_gain
))
1793 change_recording_gain(false, false, true);
1795 #else /* !HAVE_AGC */
1797 #endif /* HAVE_AGC */
1799 if(!global_settings
.cursor_style
) {
1803 for(i
= 0; i
< screen_update
; i
++)
1804 screen_put_cursorxy(&screens
[i
], 0,
1805 filename_offset
[i
] +
1806 PM_HEIGHT
+ 3, true);
1808 if(global_settings
.rec_source
!= AUDIO_SRC_MIC
)
1810 for(i
= 0; i
< screen_update
; i
++)
1811 screen_put_cursorxy(&screens
[i
], 0,
1812 filename_offset
[i
] +
1813 PM_HEIGHT
+ 4, true);
1817 for(i
= 0; i
< screen_update
; i
++)
1818 screen_put_cursorxy(&screens
[i
], 0,
1819 filename_offset
[i
] +
1820 PM_HEIGHT
+ 3, true);
1823 for(i
= 0; i
< screen_update
; i
++)
1824 screen_put_cursorxy(&screens
[i
], 0,
1825 filename_offset
[i
] +
1826 PM_HEIGHT
+ 4, true);
1831 for(i
= 0; i
< screen_update
; i
++)
1832 screen_put_cursorxy(&screens
[i
], 0,
1833 filename_offset
[i
] +
1834 PM_HEIGHT
+ line
[i
], true);
1836 #endif /* HAVE_AGC */
1838 for(i
= 0; i
< screen_update
; i
++)
1839 screen_put_cursorxy(&screens
[i
], 0,
1840 filename_offset
[i
] +
1841 PM_HEIGHT
+ 2, true);
1849 for(i
= 0; i
< screen_update
; i
++)
1851 gui_statusbar_draw(&(statusbars
.statusbars
[i
]), true);
1852 peak_meter_screen(&screens
[i
], pm_x
, pm_y
[i
], h
*PM_HEIGHT
);
1853 screens
[i
].update();
1856 /* draw the trigger status */
1859 trig_width
[i
] = ((screens
[i
].height
< 64) ||
1860 ((screens
[i
].height
< 72) && (PM_HEIGHT
> 1))) ?
1861 screens
[i
].width
- 14 * w
: screens
[i
].width
;
1862 trig_xpos
[i
] = screens
[i
].width
- trig_width
[i
];
1863 trig_ypos
[i
] = ((screens
[i
].height
< 72) && (PM_HEIGHT
> 1)) ?
1865 h
*(1 + filename_offset
[i
] + PM_HEIGHT
+
1873 if (peak_meter_trigger_status() != TRIG_OFF
)
1875 peak_meter_draw_trig(trig_xpos
, trig_ypos
, trig_width
,
1877 for(i
= 0; i
< screen_update
; i
++){
1878 screens
[i
].update_rect(trig_xpos
[i
], trig_ypos
[i
],
1879 trig_width
[i
] + 2, TRIG_HEIGHT
);
1884 if(audio_stat
& AUDIO_STATUS_ERROR
)
1888 } /* end while(!done) */
1890 audio_stat
= audio_status();
1891 if (audio_stat
& AUDIO_STATUS_ERROR
)
1893 gui_syncsplash(0, str(LANG_SYSFONT_DISK_FULL
));
1894 gui_syncstatusbar_draw(&statusbars
, true);
1897 screens
[i
].update();
1899 #if CONFIG_CODEC == SWCODEC
1900 /* stop recording - some players like H10 freeze otherwise
1901 TO DO: find out why it freezes and fix properly */
1902 rec_command(RECORDING_CMD_STOP
);
1903 audio_close_recording();
1906 audio_error_clear();
1910 if (action_userabort(TIMEOUT_NOBLOCK
))
1917 #if CONFIG_CODEC == SWCODEC
1918 rec_command(RECORDING_CMD_STOP
);
1919 audio_close_recording();
1921 #ifdef HAVE_FMRADIO_REC
1922 if (radio_status
!= FMRADIO_OFF
)
1923 /* Restore radio playback - radio_status should be unchanged if started
1924 through fm radio screen (barring usb connect) */
1925 rec_set_source(AUDIO_SRC_FMRADIO
, (radio_status
& FMRADIO_PAUSED
) ?
1926 SRCF_FMRADIO_PAUSED
: SRCF_FMRADIO_PLAYING
);
1929 /* Go back to playback mode */
1930 rec_set_source(AUDIO_SRC_PLAYBACK
, SRCF_PLAYBACK
);
1932 /* restore talking */
1933 talk_disable(false);
1934 #else /* !SWCODEC */
1935 audio_init_playback();
1936 #endif /* CONFIG_CODEC == SWCODEC */
1938 /* make sure the trigger is really turned off */
1939 peak_meter_trigger(false);
1940 peak_meter_set_trigger_listener(NULL
);
1942 rec_status
&= ~RCSTAT_IN_RECSCREEN
;
1943 sound_settings_apply();
1946 screens
[i
].setfont(FONT_UI
);
1948 /* if the directory was created or recording happened, make sure the
1949 browser is updated */
1950 if (rec_status
& (RCSTAT_CREATED_DIRECTORY
| RCSTAT_HAVE_RECORDED
))
1953 #if (CONFIG_LED == LED_REAL) && !defined(SIMULATOR)
1954 ata_set_led_enabled(true);
1959 return (rec_status
& RCSTAT_BEEN_IN_USB_MODE
) != 0;
1960 } /* recording_screen */
1962 #if CONFIG_KEYPAD == RECORDER_PAD
1963 static bool f2_rec_screen(void)
1965 static const char* const freq_str
[6] =
1980 struct audio_recording_options rec_options
;
1984 screens
[i
].setfont(FONT_SYSFIXED
);
1985 screens
[i
].getstringsize("A",&w
,&h
);
1989 const char* ptr
=NULL
;
1993 screens
[i
].clear_display();
1995 /* Recording quality */
1996 screens
[i
].putsxy(0, LCD_HEIGHT
/2 - h
*2,
1997 str(LANG_SYSFONT_RECORDING_QUALITY
));
2000 snprintf(buf
, sizeof(buf
), "%d", global_settings
.rec_quality
);
2003 screens
[i
].putsxy(0, LCD_HEIGHT
/2-h
, buf
);
2004 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_FastBackward
],
2005 LCD_WIDTH
/2 - 16, LCD_HEIGHT
/2 - 4, 7, 8);
2009 snprintf(buf
, sizeof buf
, "%s:", str(LANG_SYSFONT_RECORDING_FREQUENCY
));
2010 ptr
= freq_str
[global_settings
.rec_frequency
];
2013 screens
[i
].getstringsize(buf
,&w
,&h
);
2014 screens
[i
].putsxy((LCD_WIDTH
-w
)/2, LCD_HEIGHT
- h
*2, buf
);
2015 screens
[i
].getstringsize(ptr
, &w
, &h
);
2016 screens
[i
].putsxy((LCD_WIDTH
-w
)/2, LCD_HEIGHT
- h
, ptr
);
2017 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_DownArrow
],
2018 LCD_WIDTH
/2 - 3, LCD_HEIGHT
- h
*3, 7, 8);
2022 switch ( global_settings
.rec_channels
) {
2024 ptr
= str(LANG_SYSFONT_CHANNEL_STEREO
);
2028 ptr
= str(LANG_SYSFONT_CHANNEL_MONO
);
2034 screens
[i
].getstringsize(str(LANG_SYSFONT_CHANNELS
), &w
, &h
);
2035 screens
[i
].putsxy(LCD_WIDTH
- w
, LCD_HEIGHT
/2 - h
*2,
2036 str(LANG_SYSFONT_CHANNELS
));
2037 screens
[i
].getstringsize(str(LANG_SYSFONT_MODE
), &w
, &h
);
2038 screens
[i
].putsxy(LCD_WIDTH
- w
, LCD_HEIGHT
/2 - h
,
2039 str(LANG_SYSFONT_MODE
));
2040 screens
[i
].getstringsize(ptr
, &w
, &h
);
2041 screens
[i
].putsxy(LCD_WIDTH
- w
, LCD_HEIGHT
/2, ptr
);
2042 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_FastForward
],
2043 LCD_WIDTH
/2 + 8, LCD_HEIGHT
/2 - 4, 7, 8);
2045 screens
[i
].update();
2048 button
= button_get(true);
2051 case BUTTON_F2
| BUTTON_LEFT
:
2052 global_settings
.rec_quality
++;
2053 if(global_settings
.rec_quality
> 7)
2054 global_settings
.rec_quality
= 0;
2059 case BUTTON_F2
| BUTTON_DOWN
:
2060 global_settings
.rec_frequency
++;
2061 if(global_settings
.rec_frequency
> 5)
2062 global_settings
.rec_frequency
= 0;
2067 case BUTTON_F2
| BUTTON_RIGHT
:
2068 global_settings
.rec_channels
++;
2069 if(global_settings
.rec_channels
> 1)
2070 global_settings
.rec_channels
= 0;
2074 case BUTTON_F2
| BUTTON_REL
:
2080 case BUTTON_F2
| BUTTON_REPEAT
:
2085 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
2091 rec_init_recording_options(&rec_options
);
2092 rec_set_recording_options(&rec_options
);
2098 screens
[i
].setfont(FONT_UI
);
2103 static bool f3_rec_screen(void)
2111 str(LANG_SYSFONT_RECORDING_SRC_MIC
),
2112 str(LANG_SYSFONT_LINE_IN
),
2113 str(LANG_SYSFONT_RECORDING_SRC_DIGITAL
)
2115 struct audio_recording_options rec_options
;
2119 screens
[i
].setfont(FONT_SYSFIXED
);
2120 screens
[i
].getstringsize("A",&w
,&h
);
2125 ptr
= src_str
[global_settings
.rec_source
];
2128 screens
[i
].clear_display();
2130 /* Recording source */
2131 screens
[i
].putsxy(0, LCD_HEIGHT
/2 - h
*2,
2132 str(LANG_SYSFONT_RECORDING_SOURCE
));
2134 screens
[i
].getstringsize(ptr
, &w
, &h
);
2135 screens
[i
].putsxy(0, LCD_HEIGHT
/2-h
, ptr
);
2136 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_FastBackward
],
2137 LCD_WIDTH
/2 - 16, LCD_HEIGHT
/2 - 4, 7, 8);
2141 ptr
= str(LANG_SYSFONT_RECORD_TRIGGER
);
2144 screens
[i
].getstringsize(ptr
,&w
,&h
);
2145 screens
[i
].putsxy((LCD_WIDTH
-w
)/2, LCD_HEIGHT
- h
*2, ptr
);
2146 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_DownArrow
],
2147 LCD_WIDTH
/2 - 3, LCD_HEIGHT
- h
*3, 7, 8);
2149 screens
[i
].update();
2152 button
= button_get(true);
2155 case BUTTON_F3
| BUTTON_DOWN
:
2158 settings_apply_trigger();
2164 case BUTTON_F3
| BUTTON_LEFT
:
2165 global_settings
.rec_source
++;
2166 if(global_settings
.rec_source
> AUDIO_SRC_MAX
)
2167 global_settings
.rec_source
= 0;
2171 case BUTTON_F3
| BUTTON_REL
:
2177 case BUTTON_F3
| BUTTON_REPEAT
:
2182 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
2188 rec_init_recording_options(&rec_options
);
2189 rec_set_recording_options(&rec_options
);
2195 screens
[i
].setfont(FONT_UI
);
2199 #endif /* CONFIG_KEYPAD == RECORDER_PAD */
2201 #if CONFIG_CODEC == SWCODEC
2202 void audio_beep(int duration
)
2209 /* stubs for recording sim */
2210 void audio_init_recording(unsigned int buffer_offset
)
2212 buffer_offset
= buffer_offset
;
2215 void audio_close_recording(void)
2219 unsigned long pcm_rec_get_warnings(void)
2224 unsigned long audio_recorded_time(void)
2229 unsigned long audio_num_recorded_bytes(void)
2231 return 5 * 1024 * 1024;
2234 void rec_set_source(int source
, unsigned flags
)
2240 void audio_set_recording_options(struct audio_recording_options
*options
)
2245 void audio_set_recording_gain(int left
, int right
, int type
)
2252 void audio_record(const char *filename
)
2254 filename
= filename
;
2257 void audio_new_file(const char *filename
)
2259 filename
= filename
;
2262 void audio_stop_recording(void)
2266 void audio_pause_recording(void)
2270 void audio_resume_recording(void)
2274 #endif /* #ifdef SIMULATOR */
2275 #endif /* #ifdef CONFIG_CODEC == SWCODEC */
2277 #endif /* HAVE_RECORDING */