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"
73 /* recording screen status flags */
76 RCSTAT_IN_RECSCREEN
= 0x00000001,
77 RCSTAT_BEEN_IN_USB_MODE
= 0x00000002,
78 RCSTAT_CREATED_DIRECTORY
= 0x00000004,
79 RCSTAT_HAVE_RECORDED
= 0x00000008,
82 static int rec_status
= 0;
84 bool in_recording_screen(void)
86 return (rec_status
& RCSTAT_IN_RECSCREEN
) != 0;
89 #define PM_HEIGHT ((LCD_HEIGHT >= 72) ? 2 : 1)
91 #if CONFIG_KEYPAD == RECORDER_PAD
92 static bool f2_rec_screen(void);
93 static bool f3_rec_screen(void);
96 #define MAX_FILE_SIZE 0x7F800000 /* 2 GB - 4 MB */
98 static int screen_update
= NB_SCREENS
;
99 #ifdef HAVE_REMOTE_LCD
100 static bool remote_display_on
= true;
103 /** File name creation **/
105 /* current file number to assist in creating unique numbered filenames
106 without actually having to create the file on disk */
107 static int file_number
= -1;
108 #endif /* CONFIG_RTC */
110 #if CONFIG_CODEC == SWCODEC
112 #define REC_FILE_ENDING(rec_format) \
113 (audio_formats[rec_format_afmt[rec_format]].ext_list)
115 #else /* CONFIG_CODEC != SWCODEC */
117 /* default record file extension for HWCODEC */
118 #define REC_FILE_ENDING(rec_format) \
119 (audio_formats[AFMT_MPA_L3].ext_list)
121 #endif /* CONFIG_CODEC == SWCODEC */
123 /* path for current file */
124 static char path_buffer
[MAX_PATH
];
126 /** Automatic Gain Control (AGC) **/
129 * peak_time is incremented every 0.2s, every 2nd run of record screen loop.
130 * hist_time is incremented every 0.5s, display update.
131 * peak_time is the counter of the peak hold read and agc process,
132 * overflow every 13 years 8-)
134 static long peak_time
= 0;
135 static long hist_time
= 0;
137 static short peak_valid_mem
[4];
138 #define BAL_MEM_SIZE 24
139 static short balance_mem
[BAL_MEM_SIZE
];
141 /* Automatic Gain Control */
142 #define AGC_MODE_SIZE 5
143 #define AGC_SAFETY_MODE 0
145 static const char* agc_preset_str
[] =
146 { "Off", "S", "L", "D", "M", "V" };
153 #define AGC_CLIP 32766
154 #define AGC_PEAK 29883 /* fast gain reduction threshold -0.8dB */
155 #define AGC_HIGH 27254 /* accelerated gain reduction threshold -1.6dB */
156 #define AGC_IMG 823 /* threshold for balance control -32dB */
157 /* autogain high level thresholds (-3dB, -7dB, -4dB, -5dB, -5dB) */
158 static const short agc_th_hi
[AGC_MODE_SIZE
] =
159 { 23197, 14637, 21156, 18428, 18426 };
160 /* autogain low level thresholds (-14dB, -11dB, -6dB, -7dB, -8dB) */
161 static const short agc_th_lo
[AGC_MODE_SIZE
] =
162 { 6538, 9235, 16422, 14636, 13045 };
163 /* autogain threshold times [1/5s] or [200ms] */
164 static const short agc_tdrop
[AGC_MODE_SIZE
] =
165 { 900, 225, 150, 60, 8 };
166 static const short agc_trise
[AGC_MODE_SIZE
] =
167 { 9000, 750, 400, 150, 20 };
168 static const short agc_tbal
[AGC_MODE_SIZE
] =
169 { 4500, 500, 300, 100, 15 };
171 static bool agc_enable
= true;
172 static short agc_preset
;
174 static int agc_left
= 0;
175 static int agc_right
= 0;
176 /* AGC time since high target volume was exceeded */
177 static short agc_droptime
= 0;
178 /* AGC time since volume fallen below low target */
179 static short agc_risetime
= 0;
180 /* AGC balance time exceeding +/- 0.7dB */
181 static short agc_baltime
= 0;
182 /* AGC maximum gain */
183 static short agc_maxgain
;
184 #endif /* HAVE_AGC */
186 static void set_gain(void)
188 if(global_settings
.rec_source
== AUDIO_SRC_MIC
)
190 audio_set_recording_gain(global_settings
.rec_mic_gain
,
195 /* AUDIO_SRC_LINEIN, AUDIO_SRC_FMRADIO, AUDIO_SRC_SPDIF */
196 audio_set_recording_gain(global_settings
.rec_left_gain
,
197 global_settings
.rec_right_gain
,
203 /* Read peak meter values & calculate balance.
204 * Returns validity of peak values.
205 * Used for automatic gain control and history diagram.
207 static bool read_peak_levels(int *peak_l
, int *peak_r
, int *balance
)
209 peak_meter_get_peakhold(peak_l
, peak_r
);
210 peak_valid_mem
[peak_time
% 3] = *peak_l
;
211 if (((peak_valid_mem
[0] == peak_valid_mem
[1]) &&
212 (peak_valid_mem
[1] == peak_valid_mem
[2])) &&
215 || ata_disk_is_active()
220 if (*peak_r
> *peak_l
)
221 balance_mem
[peak_time
% BAL_MEM_SIZE
] = (*peak_l
?
222 MIN((10000 * *peak_r
) / *peak_l
- 10000, 15118) : 15118);
224 balance_mem
[peak_time
% BAL_MEM_SIZE
] = (*peak_r
?
225 MAX(10000 - (10000 * *peak_l
) / *peak_r
, -15118) : -15118);
228 for (i
= 0; i
< BAL_MEM_SIZE
; i
++)
229 *balance
+= balance_mem
[i
];
230 *balance
= *balance
/ BAL_MEM_SIZE
;
235 /* AGC helper function to check if maximum gain is reached */
236 static bool agc_gain_is_max(bool left
, bool right
)
238 /* range -128...+108 [0.5dB] */
239 short gain_current_l
;
240 short gain_current_r
;
245 switch (global_settings
.rec_source
)
247 HAVE_LINE_REC_(case AUDIO_SRC_LINEIN
:)
248 HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO
:)
249 gain_current_l
= global_settings
.rec_left_gain
;
250 gain_current_r
= global_settings
.rec_right_gain
;
254 gain_current_l
= global_settings
.rec_mic_gain
;
255 gain_current_r
= global_settings
.rec_mic_gain
;
258 return ((left
&& (gain_current_l
>= agc_maxgain
)) ||
259 (right
&& (gain_current_r
>= agc_maxgain
)));
262 static void change_recording_gain(bool increment
, bool left
, bool right
)
264 int factor
= (increment
? 1 : -1);
266 switch (global_settings
.rec_source
)
268 HAVE_LINE_REC_(case AUDIO_SRC_LINEIN
:)
269 HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO
:)
270 if (left
) global_settings
.rec_left_gain
+= factor
;
271 if (right
) global_settings
.rec_right_gain
+= factor
;
274 global_settings
.rec_mic_gain
+= factor
;
279 * Handle automatic gain control (AGC).
280 * Change recording gain if peak_x levels are above or below
281 * target volume for specified timeouts.
283 static void auto_gain_control(int *peak_l
, int *peak_r
, int *balance
)
289 if (*peak_l
> agc_left
)
292 agc_left
-= (agc_left
- *peak_l
+ 3) >> 2;
293 if (*peak_r
> agc_right
)
296 agc_right
-= (agc_right
- *peak_r
+ 3) >> 2;
297 agc_mono
= (agc_left
+ agc_right
) / 2;
299 agc_mode
= abs(agc_preset
) - 1;
305 if (agc_mode
!= AGC_SAFETY_MODE
) {
306 /* Automatic balance control - only if not in safety mode */
307 if ((agc_left
> AGC_IMG
) && (agc_right
> AGC_IMG
))
312 agc_baltime
-= !(peak_time
% 4); /* 0.47 - 0.75dB */
313 else if (*balance
> -4125)
314 agc_baltime
--; /* 0.75 - 3.00dB */
315 else if (*balance
> -7579)
316 agc_baltime
-= 2; /* 3.00 - 4.90dB */
318 agc_baltime
-= !(peak_time
% 8); /* 4.90 - inf dB */
320 agc_baltime
-= (peak_time
% 2);
322 else if (*balance
> 556)
325 agc_baltime
+= !(peak_time
% 4);
326 else if (*balance
< 4125)
328 else if (*balance
< 7579)
331 agc_baltime
+= !(peak_time
% 8);
333 agc_baltime
+= (peak_time
% 2);
336 if ((*balance
* agc_baltime
) < 0)
339 agc_baltime
-= peak_time
% 2;
341 agc_baltime
+= peak_time
% 2;
344 increment
= ((agc_risetime
/ 2) > agc_droptime
);
346 if (agc_baltime
< -agc_tbal
[agc_mode
])
348 if (!increment
|| !agc_gain_is_max(!increment
, increment
)) {
349 change_recording_gain(increment
, !increment
, increment
);
354 else if (agc_baltime
> +agc_tbal
[agc_mode
])
356 if (!increment
|| !agc_gain_is_max(increment
, !increment
)) {
357 change_recording_gain(increment
, increment
, !increment
);
363 else if (!(hist_time
% 4))
372 /* Automatic gain control */
373 if ((agc_left
> agc_th_hi
[agc_mode
]) || (agc_right
> agc_th_hi
[agc_mode
]))
375 if ((agc_left
> AGC_CLIP
) || (agc_right
> AGC_CLIP
))
376 agc_droptime
+= agc_tdrop
[agc_mode
] /
377 (global_settings
.rec_agc_cliptime
+ 1);
378 if (agc_left
> AGC_HIGH
) {
381 if (agc_left
> AGC_PEAK
)
384 if (agc_right
> AGC_HIGH
) {
387 if (agc_right
> AGC_PEAK
)
390 if (agc_mono
> agc_th_hi
[agc_mode
])
393 agc_droptime
+= !(peak_time
% 2);
395 if (agc_droptime
>= agc_tdrop
[agc_mode
])
397 change_recording_gain(false, true, true);
402 agc_risetime
= MAX(agc_risetime
- 1, 0);
404 else if (agc_mono
< agc_th_lo
[agc_mode
])
406 if (agc_mono
< (agc_th_lo
[agc_mode
] / 8))
407 agc_risetime
+= !(peak_time
% 5);
408 else if (agc_mono
< (agc_th_lo
[agc_mode
] / 2))
413 if (agc_risetime
>= agc_trise
[agc_mode
]) {
414 if ((agc_mode
!= AGC_SAFETY_MODE
) &&
415 (!agc_gain_is_max(true, true))) {
416 change_recording_gain(true, true, true);
422 agc_droptime
= MAX(agc_droptime
- 1, 0);
424 else if (!(peak_time
% 6)) /* on target level every 1.2 sec */
426 agc_risetime
= MAX(agc_risetime
- 1, 0);
427 agc_droptime
= MAX(agc_droptime
- 1, 0);
430 #endif /* HAVE_AGC */
432 static const char* const fmtstr
[] =
434 "%c%d %s", /* no decimals */
435 "%c%d.%d %s ", /* 1 decimal */
436 "%c%d.%02d %s " /* 2 decimals */
439 static char *fmt_gain(int snd
, int val
, char *str
, int len
)
445 val
= sound_val2phys(snd
, val
);
451 numdec
= sound_numdecimals(snd
);
452 unit
= sound_unit(snd
);
456 i
= val
/ (10*numdec
);
457 d
= val
% (10*numdec
);
458 snprintf(str
, len
, fmtstr
[numdec
], sign
, i
, d
, unit
);
461 snprintf(str
, len
, fmtstr
[numdec
], sign
, val
, unit
);
468 static void adjust_cursor(void)
476 switch(global_settings
.rec_source
)
483 HAVE_LINE_REC_(case AUDIO_SRC_LINEIN
:)
484 HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO
:)
491 #else /* !HAVE_AGC */
492 switch(global_settings
.rec_source
)
497 HAVE_LINE_REC_(case AUDIO_SRC_LINEIN
:)
498 HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO
:)
505 #endif /* HAVE_AGC */
507 if(cursor
> max_cursor
)
511 static bool check_dir(char *folder
)
513 DIR *dir
= opendir(folder
);
514 if (!dir
&& strcmp(folder
, "/"))
516 int rc
= mkdir(folder
);
525 char *rec_create_filename(char *buffer
)
528 strcpy(buffer
,global_settings
.rec_directory
);
529 if (!check_dir(buffer
))
532 snprintf(ext
, sizeof(ext
), ".%s",
533 REC_FILE_ENDING(global_settings
.rec_format
));
536 return create_numbered_filename(buffer
, buffer
, "rec_", ext
, 4,
539 /* We'll wait at least up to the start of the next second so no duplicate
541 return create_datetime_filename(buffer
, buffer
, "R", ext
, true);
546 /* Hit disk to get a starting filename for the type */
547 void rec_init_filename(void)
550 rec_create_filename(path_buffer
);
555 int rec_create_directory(void)
557 return check_dir(global_settings
.rec_directory
)?1:0;
560 void rec_init_recording_options(struct audio_recording_options
*options
)
562 options
->rec_source
= global_settings
.rec_source
;
563 options
->rec_frequency
= global_settings
.rec_frequency
;
564 options
->rec_channels
= global_settings
.rec_channels
;
565 options
->rec_prerecord_time
= global_settings
.rec_prerecord_time
;
566 #if CONFIG_CODEC == SWCODEC
567 options
->rec_source_flags
= 0;
568 options
->enc_config
.rec_format
= global_settings
.rec_format
;
569 global_to_encoder_config(&options
->enc_config
);
571 options
->rec_quality
= global_settings
.rec_quality
;
572 options
->rec_editable
= global_settings
.rec_editable
;
576 #if CONFIG_CODEC == SWCODEC && !defined (SIMULATOR)
577 void rec_set_source(int source
, unsigned flags
)
579 /* Set audio input source, power up/down devices */
580 audio_set_input_source(source
, flags
);
582 /* Set peakmeters for recording or reset to playback */
583 peak_meter_playback((flags
& SRCF_RECORDING
) == 0);
584 peak_meter_enabled
= true;
586 #endif /* CONFIG_CODEC == SWCODEC && !defined (SIMULATOR) */
588 void rec_set_recording_options(struct audio_recording_options
*options
)
590 #if CONFIG_CODEC != SWCODEC
591 if (global_settings
.rec_prerecord_time
)
592 talk_buffer_steal(); /* will use the mp3 buffer */
593 #else /* == SWOCODEC */
594 rec_set_source(options
->rec_source
,
595 options
->rec_source_flags
| SRCF_RECORDING
);
596 #endif /* CONFIG_CODEC != SWCODEC */
598 audio_set_recording_options(options
);
601 /* steals mp3 buffer, creates unique filename and starts recording */
602 void rec_record(void)
604 #if CONFIG_CODEC != SWCODEC
605 talk_buffer_steal(); /* we use the mp3 buffer */
607 audio_record(rec_create_filename(path_buffer
));
610 /* creates unique filename and starts recording */
611 void rec_new_file(void)
613 audio_new_file(rec_create_filename(path_buffer
));
616 /* used in trigger_listerner and recording_screen */
617 static unsigned int last_seconds
= 0;
620 * Callback function so that the peak meter code can send an event
621 * to this application. This function can be passed to
622 * peak_meter_set_trigger_listener in order to activate the trigger.
624 static void trigger_listener(int trigger_status
)
626 switch (trigger_status
)
629 if(!(audio_status() & AUDIO_STATUS_RECORD
))
631 rec_status
|= RCSTAT_HAVE_RECORDED
;
633 #if CONFIG_CODEC != SWCODEC
634 /* give control to mpeg thread so that it can start
636 yield(); yield(); yield();
640 /* if we're already recording this is a retrigger */
643 if((audio_status() & AUDIO_STATUS_PAUSE
) &&
644 (global_settings
.rec_trigger_type
== 1))
645 audio_resume_recording();
646 /* New file on trig start*/
647 else if (global_settings
.rec_trigger_type
!= 2)
650 /* tell recording_screen to reset the time */
656 /* A _change_ to TRIG_READY means the current recording has stopped */
658 if(audio_status() & AUDIO_STATUS_RECORD
)
660 switch(global_settings
.rec_trigger_type
)
663 audio_stop_recording();
667 audio_pause_recording();
670 case 2: /* New file on trig stop*/
672 /* tell recording_screen to reset the time */
677 if (global_settings
.rec_trigger_mode
!= TRIG_MODE_REARM
)
679 peak_meter_set_trigger_listener(NULL
);
680 peak_meter_trigger(false);
687 bool recording_start_automatic
= false;
689 bool recording_screen(bool no_source
)
696 int update_countdown
= 1;
697 unsigned int seconds
;
700 int last_audio_stat
= -1;
702 #if CONFIG_CODEC == SWCODEC
703 int warning_counter
= 0;
704 #define WARNING_PERIOD 7
706 #ifdef HAVE_FMRADIO_REC
707 /* Radio is left on if:
708 * 1) Is was on at the start and the initial source is FM Radio
709 * 2) 1) and the source was never changed to something else
711 int radio_status
= (global_settings
.rec_source
!= AUDIO_SRC_FMRADIO
) ?
712 FMRADIO_OFF
: get_radio_status();
714 #if (CONFIG_LED == LED_REAL)
715 bool led_state
= false;
716 int led_countdown
= 2;
719 bool peak_read
= false;
720 bool peak_valid
= false;
723 bool display_agc
[NB_SCREENS
];
725 int line
[NB_SCREENS
];
727 int filename_offset
[NB_SCREENS
];
728 int pm_y
[NB_SCREENS
];
729 int trig_xpos
[NB_SCREENS
];
730 int trig_ypos
[NB_SCREENS
];
731 int trig_width
[NB_SCREENS
];
733 static const unsigned char *byte_units
[] = {
740 struct audio_recording_options rec_options
;
741 if (check_dir(global_settings
.rec_directory
) == false)
744 gui_syncsplash(0, "%s %s",
745 str(LANG_REC_DIR_NOT_WRITABLE
),
746 str(LANG_OFF_ABORT
));
747 } while (action_userabort(HZ
) == false);
751 rec_status
= RCSTAT_IN_RECSCREEN
;
753 #if (CONFIG_LED == LED_REAL) && !defined(SIMULATOR)
754 ata_set_led_enabled(false);
757 #if CONFIG_CODEC == SWCODEC
758 /* recording_menu gets messed up: so prevent manus talking */
759 talk_disable_menus();
760 /* audio_init_recording stops anything playing when it takes the audio
763 /* Yes, we use the D/A for monitoring */
764 peak_meter_enabled
= true;
765 peak_meter_playback(true);
768 audio_init_recording(0);
769 sound_set_volume(global_settings
.volume
);
772 peak_meter_get_peakhold(&peak_l
, &peak_r
);
775 rec_init_recording_options(&rec_options
);
776 rec_set_recording_options(&rec_options
);
780 if(rec_create_directory() > 0)
781 rec_status
|= RCSTAT_CREATED_DIRECTORY
;
784 /* Create new filename for recording start */
788 settings_apply_trigger();
791 agc_preset_str
[0] = str(LANG_SYSFONT_OFF
);
792 agc_preset_str
[1] = str(LANG_SYSFONT_AGC_SAFETY
);
793 agc_preset_str
[2] = str(LANG_SYSFONT_AGC_LIVE
);
794 agc_preset_str
[3] = str(LANG_SYSFONT_AGC_DJSET
);
795 agc_preset_str
[4] = str(LANG_SYSFONT_AGC_MEDIUM
);
796 agc_preset_str
[5] = str(LANG_SYSFONT_AGC_VOICE
);
797 if (global_settings
.rec_source
== AUDIO_SRC_MIC
) {
798 agc_preset
= global_settings
.rec_agc_preset_mic
;
799 agc_maxgain
= global_settings
.rec_agc_maxgain_mic
;
802 agc_preset
= global_settings
.rec_agc_preset_line
;
803 agc_maxgain
= global_settings
.rec_agc_maxgain_line
;
805 #endif /* HAVE_AGC */
809 screens
[i
].setfont(FONT_SYSFIXED
);
810 screens
[i
].getstringsize("M", &w
, &h
);
811 screens
[i
].setmargins(global_settings
.invert_cursor
? 0 : w
, 8);
812 filename_offset
[i
] = ((screens
[i
].height
>= 80) ? 1 : 0);
813 pm_y
[i
] = 8 + h
* (2 + filename_offset
[i
]);
816 #ifdef HAVE_REMOTE_LCD
817 if (!remote_display_on
)
819 screens
[1].clear_display();
820 snprintf(buf
, sizeof(buf
), str(LANG_REMOTE_LCD_ON
));
821 screens
[1].puts((screens
[1].width
/w
- strlen(buf
))/2 + 1,
822 screens
[1].height
/(h
*2) + 1, buf
);
824 gui_syncsplash(0, str(LANG_REMOTE_LCD_OFF
));
830 audio_stat
= audio_status();
832 #if (CONFIG_LED == LED_REAL)
835 * Flash the LED while waiting to record. Turn it on while
838 if(audio_stat
& AUDIO_STATUS_RECORD
)
840 if (audio_stat
& AUDIO_STATUS_PAUSE
)
842 if (--led_countdown
<= 0)
844 led_state
= !led_state
;
851 /* trigger is on in status TRIG_READY (no check needed) */
857 int trigStat
= peak_meter_trigger_status();
859 * other trigger stati than trig_off and trig_steady
860 * already imply that we are recording.
862 if (trigStat
== TRIG_STEADY
)
864 if (--led_countdown
<= 0)
866 led_state
= !led_state
;
873 /* trigger is on in status TRIG_READY (no check needed) */
877 #endif /* CONFIG_LED */
879 /* Wait for a button a while (HZ/10) drawing the peak meter */
880 button
= peak_meter_draw_get_btn(0, pm_y
, h
* PM_HEIGHT
, screen_update
);
882 if (last_audio_stat
!= audio_stat
)
884 if (audio_stat
& AUDIO_STATUS_RECORD
)
886 rec_status
|= RCSTAT_HAVE_RECORDED
;
888 last_audio_stat
= audio_stat
;
892 if (recording_start_automatic
)
894 /* simulate a button press */
895 button
= ACTION_REC_PAUSE
;
896 recording_start_automatic
= false;
901 #ifdef HAVE_REMOTE_LCD
903 if (remote_display_on
)
905 remote_display_on
= false;
907 screens
[1].clear_display();
908 snprintf(buf
, sizeof(buf
), str(LANG_REMOTE_LCD_ON
));
909 screens
[1].puts((screens
[1].width
/w
- strlen(buf
))/2 + 1,
910 screens
[1].height
/(h
*2) + 1, buf
);
912 gui_syncsplash(0, str(LANG_REMOTE_LCD_OFF
));
916 remote_display_on
= true;
917 screen_update
= NB_SCREENS
;
921 case ACTION_STD_CANCEL
:
922 /* turn off the trigger */
923 peak_meter_trigger(false);
924 peak_meter_set_trigger_listener(NULL
);
926 if(audio_stat
& AUDIO_STATUS_RECORD
)
928 audio_stop_recording();
932 #if CONFIG_CODEC != SWCODEC
933 peak_meter_playback(true);
934 peak_meter_enabled
= false;
938 update_countdown
= 1; /* Update immediately */
941 case ACTION_REC_PAUSE
:
942 case ACTION_REC_NEWFILE
:
943 /* Only act if the mpeg is stopped */
944 if(!(audio_stat
& AUDIO_STATUS_RECORD
))
946 /* is this manual or triggered recording? */
947 if ((global_settings
.rec_trigger_mode
== TRIG_MODE_OFF
) ||
948 (peak_meter_trigger_status() != TRIG_OFF
))
950 /* manual recording */
951 rec_status
|= RCSTAT_HAVE_RECORDED
;
954 if (global_settings
.talk_menu
)
956 /* no voice possible here, but a beep */
957 audio_beep(HZ
/2); /* longer beep on start */
960 /* this is triggered recording */
963 /* we don't start recording now, but enable the
964 trigger and let the callback function
965 trigger_listener control when the recording starts */
966 peak_meter_trigger(true);
967 peak_meter_set_trigger_listener(&trigger_listener
);
972 /*if new file button pressed, start new file */
973 if (button
== ACTION_REC_NEWFILE
)
979 /* if pause button pressed, pause or resume */
981 if(audio_stat
& AUDIO_STATUS_PAUSE
)
983 audio_resume_recording();
984 if (global_settings
.talk_menu
)
986 /* no voice possible here, but a beep */
987 audio_beep(HZ
/4); /* short beep on resume */
992 audio_pause_recording();
996 update_countdown
= 1; /* Update immediately */
999 case ACTION_STD_PREV
:
1002 update_countdown
= 1; /* Update immediately */
1005 case ACTION_STD_NEXT
:
1008 update_countdown
= 1; /* Update immediately */
1011 case ACTION_SETTINGS_INC
:
1015 global_settings
.volume
++;
1019 if(global_settings
.rec_source
== AUDIO_SRC_MIC
)
1021 if(global_settings
.rec_mic_gain
<
1022 sound_max(SOUND_MIC_GAIN
))
1023 global_settings
.rec_mic_gain
++;
1027 if(global_settings
.rec_left_gain
<
1028 sound_max(SOUND_LEFT_GAIN
))
1029 global_settings
.rec_left_gain
++;
1030 if(global_settings
.rec_right_gain
<
1031 sound_max(SOUND_RIGHT_GAIN
))
1032 global_settings
.rec_right_gain
++;
1036 if(global_settings
.rec_left_gain
<
1037 sound_max(SOUND_LEFT_GAIN
))
1038 global_settings
.rec_left_gain
++;
1041 if(global_settings
.rec_right_gain
<
1042 sound_max(SOUND_RIGHT_GAIN
))
1043 global_settings
.rec_right_gain
++;
1047 agc_preset
= MIN(agc_preset
+ 1, AGC_MODE_SIZE
);
1048 agc_enable
= (agc_preset
!= 0);
1049 if (global_settings
.rec_source
== AUDIO_SRC_MIC
) {
1050 global_settings
.rec_agc_preset_mic
= agc_preset
;
1051 agc_maxgain
= global_settings
.rec_agc_maxgain_mic
;
1053 global_settings
.rec_agc_preset_line
= agc_preset
;
1054 agc_maxgain
= global_settings
.rec_agc_maxgain_line
;
1058 if (global_settings
.rec_source
== AUDIO_SRC_MIC
)
1060 agc_maxgain
= MIN(agc_maxgain
+ 1,
1061 sound_max(SOUND_MIC_GAIN
));
1062 global_settings
.rec_agc_maxgain_mic
= agc_maxgain
;
1066 agc_maxgain
= MIN(agc_maxgain
+ 1,
1067 sound_max(SOUND_LEFT_GAIN
));
1068 global_settings
.rec_agc_maxgain_line
= agc_maxgain
;
1071 #endif /* HAVE_AGC */
1074 update_countdown
= 1; /* Update immediately */
1077 case ACTION_SETTINGS_DEC
:
1081 global_settings
.volume
--;
1085 if(global_settings
.rec_source
== AUDIO_SRC_MIC
)
1087 if(global_settings
.rec_mic_gain
>
1088 sound_min(SOUND_MIC_GAIN
))
1089 global_settings
.rec_mic_gain
--;
1093 if(global_settings
.rec_left_gain
>
1094 sound_min(SOUND_LEFT_GAIN
))
1095 global_settings
.rec_left_gain
--;
1096 if(global_settings
.rec_right_gain
>
1097 sound_min(SOUND_RIGHT_GAIN
))
1098 global_settings
.rec_right_gain
--;
1102 if(global_settings
.rec_left_gain
>
1103 sound_min(SOUND_LEFT_GAIN
))
1104 global_settings
.rec_left_gain
--;
1107 if(global_settings
.rec_right_gain
>
1108 sound_min(SOUND_RIGHT_GAIN
))
1109 global_settings
.rec_right_gain
--;
1113 agc_preset
= MAX(agc_preset
- 1, 0);
1114 agc_enable
= (agc_preset
!= 0);
1115 if (global_settings
.rec_source
== AUDIO_SRC_MIC
) {
1116 global_settings
.rec_agc_preset_mic
= agc_preset
;
1117 agc_maxgain
= global_settings
.rec_agc_maxgain_mic
;
1119 global_settings
.rec_agc_preset_line
= agc_preset
;
1120 agc_maxgain
= global_settings
.rec_agc_maxgain_line
;
1124 if (global_settings
.rec_source
== AUDIO_SRC_MIC
)
1126 agc_maxgain
= MAX(agc_maxgain
- 1,
1127 sound_min(SOUND_MIC_GAIN
));
1128 global_settings
.rec_agc_maxgain_mic
= agc_maxgain
;
1132 agc_maxgain
= MAX(agc_maxgain
- 1,
1133 sound_min(SOUND_LEFT_GAIN
));
1134 global_settings
.rec_agc_maxgain_line
= agc_maxgain
;
1137 #endif /* HAVE_AGC */
1140 update_countdown
= 1; /* Update immediately */
1143 case ACTION_STD_MENU
:
1144 #if CONFIG_CODEC == SWCODEC
1145 if(!(audio_stat
& AUDIO_STATUS_RECORD
))
1147 if(audio_stat
!= AUDIO_STATUS_RECORD
)
1150 #ifdef HAVE_FMRADIO_REC
1151 const int prev_rec_source
= global_settings
.rec_source
;
1154 #if (CONFIG_LED == LED_REAL)
1155 /* led is restored at begin of loop / end of function */
1158 if (recording_menu(no_source
))
1161 rec_status
|= RCSTAT_BEEN_IN_USB_MODE
;
1162 #ifdef HAVE_FMRADIO_REC
1163 radio_status
= FMRADIO_OFF
;
1168 #ifdef HAVE_FMRADIO_REC
1169 /* If input changes away from FM Radio, radio will
1170 remain off when recording screen closes. */
1171 if (global_settings
.rec_source
!= prev_rec_source
1172 && prev_rec_source
== AUDIO_SRC_FMRADIO
)
1173 radio_status
= FMRADIO_OFF
;
1176 #if CONFIG_CODEC == SWCODEC
1177 /* reinit after submenu exit */
1178 audio_close_recording();
1179 audio_init_recording(0);
1182 rec_init_recording_options(&rec_options
);
1183 rec_set_recording_options(&rec_options
);
1185 if(rec_create_directory() > 0)
1186 rec_status
|= RCSTAT_CREATED_DIRECTORY
;
1188 #if CONFIG_CODEC == SWCODEC && CONFIG_RTC == 0
1189 /* If format changed, a new number is required */
1190 rec_init_filename();
1194 if (global_settings
.rec_source
== AUDIO_SRC_MIC
) {
1195 agc_preset
= global_settings
.rec_agc_preset_mic
;
1196 agc_maxgain
= global_settings
.rec_agc_maxgain_mic
;
1199 agc_preset
= global_settings
.rec_agc_preset_line
;
1200 agc_maxgain
= global_settings
.rec_agc_maxgain_line
;
1206 update_countdown
= 1; /* Update immediately */
1210 screens
[i
].setfont(FONT_SYSFIXED
);
1211 screens
[i
].setmargins(
1212 global_settings
.invert_cursor
? 0 : w
, 8);
1218 #if CONFIG_KEYPAD == RECORDER_PAD
1220 if(audio_stat
!= AUDIO_STATUS_RECORD
)
1222 #if (CONFIG_LED == LED_REAL)
1223 /* led is restored at begin of loop / end of function */
1226 if (f2_rec_screen())
1228 rec_status
|= RCSTAT_HAVE_RECORDED
;
1232 update_countdown
= 1; /* Update immediately */
1237 if(audio_stat
& AUDIO_STATUS_RECORD
)
1244 #if (CONFIG_LED == LED_REAL)
1245 /* led is restored at begin of loop / end of function */
1248 if (f3_rec_screen())
1250 rec_status
|= RCSTAT_HAVE_RECORDED
;
1254 update_countdown
= 1; /* Update immediately */
1257 #endif /* CONFIG_KEYPAD == RECORDER_PAD */
1259 case SYS_USB_CONNECTED
:
1260 /* Only accept USB connection when not recording */
1261 if(!(audio_stat
& AUDIO_STATUS_RECORD
))
1263 default_event_handler(SYS_USB_CONNECTED
);
1265 rec_status
|= RCSTAT_BEEN_IN_USB_MODE
;
1266 #ifdef HAVE_FMRADIO_REC
1267 radio_status
= FMRADIO_OFF
;
1273 default_event_handler(button
);
1278 peak_read
= !peak_read
;
1279 if (peak_read
) { /* every 2nd run of loop */
1281 peak_valid
= read_peak_levels(&peak_l
, &peak_r
, &balance
);
1284 /* Handle AGC every 200ms when enabled and peak data is valid */
1285 if (peak_read
&& agc_enable
&& peak_valid
)
1286 auto_gain_control(&peak_l
, &peak_r
, &balance
);
1290 screens
[i
].setfont(FONT_SYSFIXED
);
1292 seconds
= audio_recorded_time() / HZ
;
1295 if(update_countdown
== 0 || seconds
> last_seconds
)
1297 unsigned int dseconds
, dhours
, dminutes
;
1298 unsigned long num_recorded_bytes
, dsize
, dmb
;
1301 update_countdown
= 5;
1302 last_seconds
= seconds
;
1304 dseconds
= rec_timesplit_seconds();
1305 dsize
= rec_sizesplit_bytes();
1306 num_recorded_bytes
= audio_num_recorded_bytes();
1308 for(i
= 0; i
< screen_update
; i
++)
1309 screens
[i
].clear_display();
1311 #if CONFIG_CODEC == SWCODEC
1312 if ((audio_stat
& AUDIO_STATUS_WARNING
)
1313 && (warning_counter
++ % WARNING_PERIOD
) < WARNING_PERIOD
/2)
1315 /* Switch back and forth displaying warning on first available
1316 line to ensure visibility - the motion should also help
1318 /* Don't use language string unless agreed upon to make this
1319 method permanent - could do something in the statusbar */
1320 snprintf(buf
, sizeof(buf
), "Warning: %08X",
1321 pcm_rec_get_warnings());
1324 #endif /* CONFIG_CODEC == SWCODEC */
1325 if ((global_settings
.rec_sizesplit
) && (global_settings
.rec_split_method
))
1327 dmb
= dsize
/1024/1024;
1328 snprintf(buf
, sizeof(buf
), "%s %dMB",
1329 str(LANG_SYSFONT_SPLIT_SIZE
), dmb
);
1333 hours
= seconds
/ 3600;
1334 minutes
= (seconds
- (hours
* 3600)) / 60;
1335 snprintf(buf
, sizeof(buf
), "%s %02d:%02d:%02d",
1336 str(LANG_SYSFONT_RECORDING_TIME
),
1337 hours
, minutes
, seconds
%60);
1340 for(i
= 0; i
< screen_update
; i
++)
1341 screens
[i
].puts(0, 0, buf
);
1343 if(audio_stat
& AUDIO_STATUS_PRERECORD
)
1345 snprintf(buf
, sizeof(buf
), "%s...", str(LANG_SYSFONT_RECORD_PRERECORD
));
1349 /* Display the split interval if the record timesplit
1351 if ((global_settings
.rec_timesplit
) && !(global_settings
.rec_split_method
))
1353 /* Display the record timesplit interval rather
1354 than the file size if the record timer is
1356 dhours
= dseconds
/ 3600;
1357 dminutes
= (dseconds
- (dhours
* 3600)) / 60;
1358 snprintf(buf
, sizeof(buf
), "%s %02d:%02d",
1359 str(LANG_SYSFONT_RECORD_TIMESPLIT_REC
),
1364 output_dyn_value(buf2
, sizeof buf2
,
1367 snprintf(buf
, sizeof(buf
), "%s %s",
1368 str(LANG_SYSFONT_RECORDING_SIZE
), buf2
);
1371 for(i
= 0; i
< screen_update
; i
++)
1372 screens
[i
].puts(0, 1, buf
);
1374 for(i
= 0; i
< screen_update
; i
++)
1376 if (filename_offset
[i
] > 0)
1379 if (audio_stat
& AUDIO_STATUS_RECORD
)
1381 strncpy(filename
, path_buffer
+
1382 strlen(path_buffer
) - 12, 13);
1386 snprintf(buf
, sizeof(buf
), "%s %s",
1387 str(LANG_SYSFONT_RECORDING_FILENAME
), filename
);
1388 screens
[i
].puts(0, 2, buf
);
1392 /* We will do file splitting regardless, either at the end of
1393 a split interval, or when the filesize approaches the 2GB
1394 FAT file size (compatibility) limit. */
1395 if ((audio_stat
&& !(global_settings
.rec_split_method
)
1396 && global_settings
.rec_timesplit
&& (seconds
>= dseconds
))
1397 || (audio_stat
&& global_settings
.rec_split_method
1398 && global_settings
.rec_sizesplit
&& (num_recorded_bytes
>= dsize
))
1399 || (num_recorded_bytes
>= MAX_FILE_SIZE
))
1401 if (!(global_settings
.rec_split_type
)
1402 || (num_recorded_bytes
>= MAX_FILE_SIZE
))
1409 peak_meter_trigger(false);
1410 peak_meter_set_trigger_listener(NULL
);
1411 audio_stop_recording();
1413 update_countdown
= 1;
1416 snprintf(buf
, sizeof(buf
), "%s: %s", str(LANG_SYSFONT_VOLUME
),
1417 fmt_gain(SOUND_VOLUME
,
1418 global_settings
.volume
,
1419 buf2
, sizeof(buf2
)));
1421 if (global_settings
.invert_cursor
&& (pos
++ == cursor
))
1423 for(i
= 0; i
< screen_update
; i
++)
1424 screens
[i
].puts_style_offset(0, filename_offset
[i
] +
1425 PM_HEIGHT
+ 2, buf
, STYLE_INVERT
,0);
1429 for(i
= 0; i
< screen_update
; i
++)
1430 screens
[i
].puts(0, filename_offset
[i
] + PM_HEIGHT
+ 2, buf
);
1433 if(global_settings
.rec_source
== AUDIO_SRC_MIC
)
1435 /* Draw MIC recording gain */
1436 snprintf(buf
, sizeof(buf
), "%s:%s", str(LANG_SYSFONT_RECORDING_GAIN
),
1437 fmt_gain(SOUND_MIC_GAIN
,
1438 global_settings
.rec_mic_gain
,
1439 buf2
, sizeof(buf2
)));
1440 if(global_settings
.invert_cursor
&& ((1==cursor
)||(2==cursor
)))
1442 for(i
= 0; i
< screen_update
; i
++)
1443 screens
[i
].puts_style_offset(0, filename_offset
[i
] +
1444 PM_HEIGHT
+ 3, buf
, STYLE_INVERT
,0);
1448 for(i
= 0; i
< screen_update
; i
++)
1449 screens
[i
].puts(0, filename_offset
[i
] +
1450 PM_HEIGHT
+ 3, buf
);
1454 HAVE_LINE_REC_( || global_settings
.rec_source
== AUDIO_SRC_LINEIN
)
1455 HAVE_FMRADIO_REC_( || global_settings
.rec_source
== AUDIO_SRC_FMRADIO
)
1458 /* Draw LINE or FMRADIO recording gain */
1459 snprintf(buf
, sizeof(buf
), "%s:%s",
1460 str(LANG_SYSFONT_RECORDING_LEFT
),
1461 fmt_gain(SOUND_LEFT_GAIN
,
1462 global_settings
.rec_left_gain
,
1463 buf2
, sizeof(buf2
)));
1464 if(global_settings
.invert_cursor
&& ((1==cursor
)||(2==cursor
)))
1466 for(i
= 0; i
< screen_update
; i
++)
1467 screens
[i
].puts_style_offset(0, filename_offset
[i
] +
1468 PM_HEIGHT
+ 3, buf
, STYLE_INVERT
,0);
1472 for(i
= 0; i
< screen_update
; i
++)
1473 screens
[i
].puts(0, filename_offset
[i
] +
1474 PM_HEIGHT
+ 3, buf
);
1477 snprintf(buf
, sizeof(buf
), "%s:%s",
1478 str(LANG_SYSFONT_RECORDING_RIGHT
),
1479 fmt_gain(SOUND_RIGHT_GAIN
,
1480 global_settings
.rec_right_gain
,
1481 buf2
, sizeof(buf2
)));
1482 if(global_settings
.invert_cursor
&& ((1==cursor
)||(3==cursor
)))
1484 for(i
= 0; i
< screen_update
; i
++)
1485 screens
[i
].puts_style_offset(0, filename_offset
[i
] +
1486 PM_HEIGHT
+ 4, buf
, STYLE_INVERT
,0);
1490 for(i
= 0; i
< screen_update
; i
++)
1491 screens
[i
].puts(0, filename_offset
[i
] +
1492 PM_HEIGHT
+ 4, buf
);
1498 switch (global_settings
.rec_source
)
1500 HAVE_LINE_REC_(case AUDIO_SRC_LINEIN
:)
1501 HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO
:)
1508 #ifdef HAVE_SPDIF_REC
1509 case AUDIO_SRC_SPDIF
:
1514 line
[i
] = 5; /* to prevent uninitialisation
1515 warnings for line[0] */
1519 if (screens
[i
].height
< h
* (2 + filename_offset
[i
] + PM_HEIGHT
+ line
[i
]))
1522 display_agc
[i
] = false;
1525 display_agc
[i
] = true;
1527 if ((cursor
==4) || (cursor
==5))
1528 display_agc
[i
] = true;
1531 /************** AGC test info ******************
1532 snprintf(buf, sizeof(buf), "D:%d U:%d",
1533 (agc_droptime+2)/5, (agc_risetime+2)/5);
1534 lcd_putsxy(1, LCD_HEIGHT - 8, buf);
1535 snprintf(buf, sizeof(buf), "B:%d",
1537 lcd_putsxy(LCD_WIDTH/2 + 3, LCD_HEIGHT - 8, buf);
1538 ***********************************************/
1541 snprintf(buf
, sizeof(buf
), "%s: %s",
1542 str(LANG_SYSFONT_RECORDING_AGC_MAXGAIN
),
1543 fmt_gain(SOUND_LEFT_GAIN
,
1544 agc_maxgain
, buf2
, sizeof(buf2
)));
1545 else if (agc_preset
== 0)
1546 snprintf(buf
, sizeof(buf
), "%s: %s",
1547 str(LANG_SYSFONT_RECORDING_AGC_PRESET
),
1548 agc_preset_str
[agc_preset
]);
1549 else if (global_settings
.rec_source
== AUDIO_SRC_MIC
)
1550 snprintf(buf
, sizeof(buf
), "%s: %s%s",
1551 str(LANG_SYSFONT_RECORDING_AGC_PRESET
),
1552 agc_preset_str
[agc_preset
],
1553 fmt_gain(SOUND_LEFT_GAIN
,
1555 global_settings
.rec_mic_gain
,
1556 buf2
, sizeof(buf2
)));
1558 snprintf(buf
, sizeof(buf
), "%s: %s%s",
1559 str(LANG_SYSFONT_RECORDING_AGC_PRESET
),
1560 agc_preset_str
[agc_preset
],
1561 fmt_gain(SOUND_LEFT_GAIN
,
1563 (global_settings
.rec_left_gain
+
1564 global_settings
.rec_right_gain
)/2,
1565 buf2
, sizeof(buf2
)));
1567 if(global_settings
.invert_cursor
&& ((cursor
==4) || (cursor
==5)))
1569 for(i
= 0; i
< screen_update
; i
++)
1570 screens
[i
].puts_style_offset(0, filename_offset
[i
] +
1571 PM_HEIGHT
+ line
[i
], buf
, STYLE_INVERT
,0);
1574 global_settings
.rec_source
== AUDIO_SRC_MIC
1575 HAVE_LINE_REC_(|| global_settings
.rec_source
== AUDIO_SRC_LINEIN
)
1576 HAVE_FMRADIO_REC_(|| global_settings
.rec_source
== AUDIO_SRC_FMRADIO
)
1579 for(i
= 0; i
< screen_update
; i
++) {
1580 if (display_agc
[i
]) {
1581 screens
[i
].puts(0, filename_offset
[i
] +
1582 PM_HEIGHT
+ line
[i
], buf
);
1587 if (global_settings
.rec_source
== AUDIO_SRC_MIC
)
1589 if(agc_maxgain
< (global_settings
.rec_mic_gain
))
1590 change_recording_gain(false, true, true);
1594 if(agc_maxgain
< (global_settings
.rec_left_gain
))
1595 change_recording_gain(false, true, false);
1596 if(agc_maxgain
< (global_settings
.rec_right_gain
))
1597 change_recording_gain(false, false, true);
1599 #else /* !HAVE_AGC */
1601 #endif /* HAVE_AGC */
1603 if(!global_settings
.invert_cursor
) {
1607 for(i
= 0; i
< screen_update
; i
++)
1608 screen_put_cursorxy(&screens
[i
], 0,
1609 filename_offset
[i
] +
1610 PM_HEIGHT
+ 3, true);
1612 if(global_settings
.rec_source
!= AUDIO_SRC_MIC
)
1614 for(i
= 0; i
< screen_update
; i
++)
1615 screen_put_cursorxy(&screens
[i
], 0,
1616 filename_offset
[i
] +
1617 PM_HEIGHT
+ 4, true);
1621 for(i
= 0; i
< screen_update
; i
++)
1622 screen_put_cursorxy(&screens
[i
], 0,
1623 filename_offset
[i
] +
1624 PM_HEIGHT
+ 3, true);
1627 for(i
= 0; i
< screen_update
; i
++)
1628 screen_put_cursorxy(&screens
[i
], 0,
1629 filename_offset
[i
] +
1630 PM_HEIGHT
+ 4, true);
1635 for(i
= 0; i
< screen_update
; i
++)
1636 screen_put_cursorxy(&screens
[i
], 0,
1637 filename_offset
[i
] +
1638 PM_HEIGHT
+ line
[i
], true);
1640 #endif /* HAVE_AGC */
1642 for(i
= 0; i
< screen_update
; i
++)
1643 screen_put_cursorxy(&screens
[i
], 0,
1644 filename_offset
[i
] +
1645 PM_HEIGHT
+ 2, true);
1653 for(i
= 0; i
< screen_update
; i
++)
1655 gui_statusbar_draw(&(statusbars
.statusbars
[i
]), true);
1656 peak_meter_screen(&screens
[i
], 0, pm_y
[i
], h
*PM_HEIGHT
);
1657 screens
[i
].update();
1660 /* draw the trigger status */
1663 trig_width
[i
] = ((screens
[i
].height
< 64) ||
1664 ((screens
[i
].height
< 72) && (PM_HEIGHT
> 1))) ?
1665 screens
[i
].width
- 14 * w
: screens
[i
].width
;
1666 trig_xpos
[i
] = screens
[i
].width
- trig_width
[i
];
1667 trig_ypos
[i
] = ((screens
[i
].height
< 72) && (PM_HEIGHT
> 1)) ?
1669 h
*(1 + filename_offset
[i
] + PM_HEIGHT
+ line
[i
]
1676 if (peak_meter_trigger_status() != TRIG_OFF
)
1678 peak_meter_draw_trig(trig_xpos
, trig_ypos
, trig_width
,
1680 for(i
= 0; i
< screen_update
; i
++){
1681 screens
[i
].update_rect(trig_xpos
[i
], trig_ypos
[i
],
1682 trig_width
[i
] + 2, TRIG_HEIGHT
);
1687 if(audio_stat
& AUDIO_STATUS_ERROR
)
1691 } /* end while(!done) */
1693 audio_stat
= audio_status();
1694 if (audio_stat
& AUDIO_STATUS_ERROR
)
1696 gui_syncsplash(0, str(LANG_SYSFONT_DISK_FULL
));
1697 gui_syncstatusbar_draw(&statusbars
, true);
1700 screens
[i
].update();
1702 audio_error_clear();
1706 if (action_userabort(TIMEOUT_NOBLOCK
))
1711 #if CONFIG_CODEC == SWCODEC
1712 audio_stop_recording();
1713 audio_close_recording();
1715 #ifdef HAVE_FMRADIO_REC
1716 if (radio_status
!= FMRADIO_OFF
)
1717 /* Restore radio playback - radio_status should be unchanged if started
1718 through fm radio screen (barring usb connect) */
1719 rec_set_source(AUDIO_SRC_FMRADIO
, (radio_status
& FMRADIO_PAUSED
) ?
1720 SRCF_FMRADIO_PAUSED
: SRCF_FMRADIO_PLAYING
);
1723 /* Go back to playback mode */
1724 rec_set_source(AUDIO_SRC_PLAYBACK
, SRCF_PLAYBACK
);
1726 /* restore talk_menu setting */
1727 talk_enable_menus();
1728 #else /* !SWCODEC */
1729 audio_init_playback();
1730 #endif /* CONFIG_CODEC == SWCODEC */
1732 /* make sure the trigger is really turned off */
1733 peak_meter_trigger(false);
1734 peak_meter_set_trigger_listener(NULL
);
1736 rec_status
&= ~RCSTAT_IN_RECSCREEN
;
1737 sound_settings_apply();
1740 screens
[i
].setfont(FONT_UI
);
1742 /* if the directory was created or recording happened, make sure the
1743 browser is updated */
1744 if (rec_status
& (RCSTAT_CREATED_DIRECTORY
| RCSTAT_HAVE_RECORDED
))
1747 #if (CONFIG_LED == LED_REAL) && !defined(SIMULATOR)
1748 ata_set_led_enabled(true);
1753 return (rec_status
& RCSTAT_BEEN_IN_USB_MODE
) != 0;
1754 } /* recording_screen */
1756 #if CONFIG_KEYPAD == RECORDER_PAD
1757 static bool f2_rec_screen(void)
1759 static const char* const freq_str
[6] =
1774 struct audio_recording_options rec_options
;
1778 screens
[i
].setfont(FONT_SYSFIXED
);
1779 screens
[i
].getstringsize("A",&w
,&h
);
1783 const char* ptr
=NULL
;
1787 screens
[i
].clear_display();
1789 /* Recording quality */
1790 screens
[i
].putsxy(0, LCD_HEIGHT
/2 - h
*2,
1791 str(LANG_SYSFONT_RECORDING_QUALITY
));
1794 snprintf(buf
, sizeof(buf
), "%d", global_settings
.rec_quality
);
1797 screens
[i
].putsxy(0, LCD_HEIGHT
/2-h
, buf
);
1798 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_FastBackward
],
1799 LCD_WIDTH
/2 - 16, LCD_HEIGHT
/2 - 4, 7, 8);
1803 snprintf(buf
, sizeof buf
, "%s:", str(LANG_SYSFONT_RECORDING_FREQUENCY
));
1804 ptr
= freq_str
[global_settings
.rec_frequency
];
1807 screens
[i
].getstringsize(buf
,&w
,&h
);
1808 screens
[i
].putsxy((LCD_WIDTH
-w
)/2, LCD_HEIGHT
- h
*2, buf
);
1809 screens
[i
].getstringsize(ptr
, &w
, &h
);
1810 screens
[i
].putsxy((LCD_WIDTH
-w
)/2, LCD_HEIGHT
- h
, ptr
);
1811 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_DownArrow
],
1812 LCD_WIDTH
/2 - 3, LCD_HEIGHT
- h
*3, 7, 8);
1816 switch ( global_settings
.rec_channels
) {
1818 ptr
= str(LANG_SYSFONT_CHANNEL_STEREO
);
1822 ptr
= str(LANG_SYSFONT_CHANNEL_MONO
);
1828 screens
[i
].getstringsize(str(LANG_SYSFONT_RECORDING_CHANNELS
), &w
, &h
);
1829 screens
[i
].putsxy(LCD_WIDTH
- w
, LCD_HEIGHT
/2 - h
*2,
1830 str(LANG_SYSFONT_RECORDING_CHANNELS
));
1831 screens
[i
].getstringsize(str(LANG_SYSFONT_F2_MODE
), &w
, &h
);
1832 screens
[i
].putsxy(LCD_WIDTH
- w
, LCD_HEIGHT
/2 - h
,
1833 str(LANG_SYSFONT_F2_MODE
));
1834 screens
[i
].getstringsize(ptr
, &w
, &h
);
1835 screens
[i
].putsxy(LCD_WIDTH
- w
, LCD_HEIGHT
/2, ptr
);
1836 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_FastForward
],
1837 LCD_WIDTH
/2 + 8, LCD_HEIGHT
/2 - 4, 7, 8);
1839 screens
[i
].update();
1842 button
= button_get(true);
1845 case BUTTON_F2
| BUTTON_LEFT
:
1846 global_settings
.rec_quality
++;
1847 if(global_settings
.rec_quality
> 7)
1848 global_settings
.rec_quality
= 0;
1853 case BUTTON_F2
| BUTTON_DOWN
:
1854 global_settings
.rec_frequency
++;
1855 if(global_settings
.rec_frequency
> 5)
1856 global_settings
.rec_frequency
= 0;
1861 case BUTTON_F2
| BUTTON_RIGHT
:
1862 global_settings
.rec_channels
++;
1863 if(global_settings
.rec_channels
> 1)
1864 global_settings
.rec_channels
= 0;
1868 case BUTTON_F2
| BUTTON_REL
:
1874 case BUTTON_F2
| BUTTON_REPEAT
:
1879 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
1885 rec_init_recording_options(&rec_options
);
1886 rec_set_recording_options(&rec_options
);
1892 screens
[i
].setfont(FONT_UI
);
1897 static bool f3_rec_screen(void)
1905 str(LANG_SYSFONT_RECORDING_SRC_MIC
),
1906 str(LANG_SYSFONT_RECORDING_SRC_LINE
),
1907 str(LANG_SYSFONT_RECORDING_SRC_DIGITAL
)
1909 struct audio_recording_options rec_options
;
1913 screens
[i
].setfont(FONT_SYSFIXED
);
1914 screens
[i
].getstringsize("A",&w
,&h
);
1919 ptr
= src_str
[global_settings
.rec_source
];
1922 screens
[i
].clear_display();
1924 /* Recording source */
1925 screens
[i
].putsxy(0, LCD_HEIGHT
/2 - h
*2,
1926 str(LANG_SYSFONT_RECORDING_SOURCE
));
1928 screens
[i
].getstringsize(ptr
, &w
, &h
);
1929 screens
[i
].putsxy(0, LCD_HEIGHT
/2-h
, ptr
);
1930 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_FastBackward
],
1931 LCD_WIDTH
/2 - 16, LCD_HEIGHT
/2 - 4, 7, 8);
1935 ptr
= str(LANG_SYSFONT_RECORD_TRIGGER
);
1938 screens
[i
].getstringsize(ptr
,&w
,&h
);
1939 screens
[i
].putsxy((LCD_WIDTH
-w
)/2, LCD_HEIGHT
- h
*2, ptr
);
1940 screens
[i
].mono_bitmap(bitmap_icons_7x8
[Icon_DownArrow
],
1941 LCD_WIDTH
/2 - 3, LCD_HEIGHT
- h
*3, 7, 8);
1943 screens
[i
].update();
1946 button
= button_get(true);
1949 case BUTTON_F3
| BUTTON_DOWN
:
1952 settings_apply_trigger();
1958 case BUTTON_F3
| BUTTON_LEFT
:
1959 global_settings
.rec_source
++;
1960 if(global_settings
.rec_source
> AUDIO_SRC_MAX
)
1961 global_settings
.rec_source
= 0;
1965 case BUTTON_F3
| BUTTON_REL
:
1971 case BUTTON_F3
| BUTTON_REPEAT
:
1976 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
1982 rec_init_recording_options(&rec_options
);
1983 rec_set_recording_options(&rec_options
);
1989 screens
[i
].setfont(FONT_UI
);
1993 #endif /* CONFIG_KEYPAD == RECORDER_PAD */
1995 #if CONFIG_CODEC == SWCODEC
1996 void audio_beep(int duration
)
2003 /* stubs for recording sim */
2004 void audio_init_recording(unsigned int buffer_offset
)
2006 buffer_offset
= buffer_offset
;
2009 void audio_close_recording(void)
2013 unsigned long pcm_rec_get_warnings(void)
2018 unsigned long audio_recorded_time(void)
2023 unsigned long audio_num_recorded_bytes(void)
2025 return 5 * 1024 * 1024;
2028 void rec_set_source(int source
, unsigned flags
)
2034 void audio_set_recording_options(struct audio_recording_options
*options
)
2039 void audio_set_recording_gain(int left
, int right
, int type
)
2046 void audio_record(const char *filename
)
2048 filename
= filename
;
2051 void audio_new_file(const char *filename
)
2053 filename
= filename
;
2056 void audio_stop_recording(void)
2060 void audio_pause_recording(void)
2064 void audio_resume_recording(void)
2068 #endif /* #ifdef SIMULATOR */
2069 #endif /* #ifdef CONFIG_CODEC == SWCODEC */
2071 #endif /* HAVE_RECORDING */