Const correctness for output_dyn_value and unify some identical constants
[kugel-rb.git] / apps / recorder / recording.c
blobda97306cfe30e1e57728a5e5dd87e0374323c8de
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 by Linus Nielsen Feltzing
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include "config.h"
24 #include <stdio.h>
25 #include <stdbool.h>
26 #include <stdlib.h>
28 #include "system.h"
29 #include "power.h"
30 #include "powermgmt.h"
31 #include "lcd.h"
32 #include "led.h"
33 #include "mpeg.h"
34 #include "audio.h"
35 #if CONFIG_CODEC == SWCODEC
36 #include "thread.h"
37 #include "playback.h"
38 #include "enc_config.h"
39 #if defined(HAVE_SPDIF_IN) || defined(HAVE_SPDIF_OUT)
40 #include "spdif.h"
41 #endif
42 #endif /* CONFIG_CODEC == SWCODEC */
43 #include "pcm_record.h"
44 #include "recording.h"
45 #include "mp3_playback.h"
46 #include "mas.h"
47 #include "button.h"
48 #include "kernel.h"
49 #include "settings.h"
50 #include "lang.h"
51 #include "font.h"
52 #include "icons.h"
53 #include "icon.h"
54 #include "screens.h"
55 #include "peakmeter.h"
56 #include "menu.h"
57 #include "sound_menu.h"
58 #include "timefuncs.h"
59 #include "debug.h"
60 #include "misc.h"
61 #include "tree.h"
62 #include "string.h"
63 #include "dir.h"
64 #include "errno.h"
65 #include "talk.h"
66 #include "sound.h"
67 #include "storage.h"
68 #if (CONFIG_STORAGE & STORAGE_ATA) && (CONFIG_LED == LED_REAL) \
69 && !defined(SIMULATOR)
70 #include "ata.h"
71 #endif
72 #include "splash.h"
73 #include "screen_access.h"
74 #include "action.h"
75 #include "radio.h"
76 #include "viewport.h"
77 #include "list.h"
78 #include "general.h"
79 #include "appevents.h"
81 #ifdef HAVE_RECORDING
82 /* This array holds the record timer interval lengths, in seconds */
83 static const unsigned long rec_timer_seconds[] =
85 0, /* 0 means OFF */
86 5*60, /* 00:05 */
87 10*60, /* 00:10 */
88 15*60, /* 00:15 */
89 30*60, /* 00:30 */
90 60*60, /* 01:00 */
91 74*60, /* 01:14 */
92 80*60, /* 01:20 */
93 2*60*60, /* 02:00 */
94 4*60*60, /* 04:00 */
95 6*60*60, /* 06:00 */
96 8*60*60, /* 08:00 */
97 10L*60*60, /* 10:00 */
98 12L*60*60, /* 12:00 */
99 18L*60*60, /* 18:00 */
100 24L*60*60 /* 24:00 */
103 static unsigned int rec_timesplit_seconds(void)
105 return rec_timer_seconds[global_settings.rec_timesplit];
108 /* This array holds the record size interval lengths, in bytes */
109 static const unsigned long rec_size_bytes[] =
111 0, /* 0 means OFF */
112 5*1024*1024, /* 5MB */
113 10*1024*1024, /* 10MB */
114 15*1024*1024, /* 15MB */
115 32*1024*1024, /* 32MB */
116 64*1024*1024, /* 64MB */
117 75*1024*1024, /* 75MB */
118 100*1024*1024, /* 100MB */
119 128*1024*1024, /* 128MB */
120 256*1024*1024, /* 256MB */
121 512*1024*1024, /* 512MB */
122 650*1024*1024, /* 650MB */
123 700*1024*1024, /* 700MB */
124 1024*1024*1024, /* 1GB */
125 1536*1024*1024, /* 1.5GB */
126 1792*1024*1024, /* 1.75GB */
129 static unsigned long rec_sizesplit_bytes(void)
131 return rec_size_bytes[global_settings.rec_sizesplit];
134 void settings_apply_trigger(void)
136 int start_thres, stop_thres;
137 if (global_settings.peak_meter_dbfs)
139 start_thres = global_settings.rec_start_thres_db - 1;
140 stop_thres = global_settings.rec_stop_thres_db - 1;
142 else
144 start_thres = global_settings.rec_start_thres_linear;
145 stop_thres = global_settings.rec_stop_thres_linear;
148 peak_meter_define_trigger(
149 start_thres,
150 global_settings.rec_start_duration*HZ,
151 MIN(global_settings.rec_start_duration*HZ / 2, 2*HZ),
152 stop_thres,
153 global_settings.rec_stop_postrec*HZ,
154 global_settings.rec_stop_gap*HZ
157 /* recording screen status flags */
158 enum rec_status_flags
160 RCSTAT_IN_RECSCREEN = 0x00000001,
161 RCSTAT_BEEN_IN_USB_MODE = 0x00000002,
162 RCSTAT_CREATED_DIRECTORY = 0x00000004,
163 RCSTAT_HAVE_RECORDED = 0x00000008,
166 static int rec_status = 0;
168 bool in_recording_screen(void)
170 return (rec_status & RCSTAT_IN_RECSCREEN) != 0;
173 #if CONFIG_KEYPAD == RECORDER_PAD
174 static bool f2_rec_screen(void);
175 static bool f3_rec_screen(void);
176 #endif
178 #define MAX_FILE_SIZE 0x7F800000 /* 2 GB - 4 MB */
180 #ifndef HAVE_REMOTE_LCD
181 static const int screen_update = NB_SCREENS;
182 #else
183 static int screen_update = NB_SCREENS;
184 static bool remote_display_on = true;
185 #endif
187 /* as we have the ability to disable the remote, we need an alternative loop */
188 #define FOR_NB_ACTIVE_SCREENS(i) for(i = 0; i < screen_update; i++)
190 static bool update_list = false; /* (GIU) list needs updating */
192 /** File name creation **/
193 #if CONFIG_RTC == 0
194 /* current file number to assist in creating unique numbered filenames
195 without actually having to create the file on disk */
196 static int file_number = -1;
197 #endif /* CONFIG_RTC */
199 #if CONFIG_CODEC == SWCODEC
201 #define REC_FILE_ENDING(rec_format) \
202 (audio_formats[rec_format_afmt[rec_format]].ext_list)
204 #else /* CONFIG_CODEC != SWCODEC */
206 /* default record file extension for HWCODEC */
207 #define REC_FILE_ENDING(rec_format) \
208 (audio_formats[AFMT_MPA_L3].ext_list)
210 #endif /* CONFIG_CODEC == SWCODEC */
212 /* path for current file */
213 static char path_buffer[MAX_PATH];
215 /** Automatic Gain Control (AGC) **/
216 #ifdef HAVE_AGC
217 /* Timing counters:
218 * peak_time is incremented every 0.2s, every 2nd run of record screen loop.
219 * hist_time is incremented every 0.5s, display update.
220 * peak_time is the counter of the peak hold read and agc process,
221 * overflow every 13 years 8-)
223 static long peak_time = 0;
224 static long hist_time = 0;
226 static short peak_valid_mem[4];
227 #define BAL_MEM_SIZE 24
228 static short balance_mem[BAL_MEM_SIZE];
230 /* Automatic Gain Control */
231 #define AGC_MODE_SIZE 5
232 #define AGC_SAFETY_MODE 0
234 static const char* agc_preset_str[] =
235 { "Off", "S", "L", "D", "M", "V" };
236 /* "Off",
237 "Safety (clip)",
238 "Live (slow)",
239 "DJ-Set (slow)",
240 "Medium",
241 "Voice (fast)" */
242 #define AGC_CLIP 32766
243 #define AGC_PEAK 29883 /* fast gain reduction threshold -0.8dB */
244 #define AGC_HIGH 27254 /* accelerated gain reduction threshold -1.6dB */
245 #define AGC_IMG 823 /* threshold for balance control -32dB */
246 /* autogain high level thresholds (-3dB, -7dB, -4dB, -5dB, -5dB) */
247 static const short agc_th_hi[AGC_MODE_SIZE] =
248 { 23197, 14637, 21156, 18428, 18426 };
249 /* autogain low level thresholds (-14dB, -11dB, -6dB, -7dB, -8dB) */
250 static const short agc_th_lo[AGC_MODE_SIZE] =
251 { 6538, 9235, 16422, 14636, 13045 };
252 /* autogain threshold times [1/5s] or [200ms] */
253 static const short agc_tdrop[AGC_MODE_SIZE] =
254 { 900, 225, 150, 60, 8 };
255 static const short agc_trise[AGC_MODE_SIZE] =
256 { 9000, 750, 400, 150, 20 };
257 static const short agc_tbal[AGC_MODE_SIZE] =
258 { 4500, 500, 300, 100, 15 };
259 /* AGC operation */
260 static bool agc_enable = true;
261 static short agc_preset;
262 /* AGC levels */
263 static int agc_left = 0;
264 static int agc_right = 0;
265 /* AGC time since high target volume was exceeded */
266 static short agc_droptime = 0;
267 /* AGC time since volume fallen below low target */
268 static short agc_risetime = 0;
269 /* AGC balance time exceeding +/- 0.7dB */
270 static short agc_baltime = 0;
271 /* AGC maximum gain */
272 static short agc_maxgain;
273 #endif /* HAVE_AGC */
275 static void set_gain(void)
277 #ifdef HAVE_MIC_REC
278 if(global_settings.rec_source == AUDIO_SRC_MIC)
280 audio_set_recording_gain(global_settings.rec_mic_gain,
281 0, AUDIO_GAIN_MIC);
283 else
284 #endif /* MIC */
286 /* AUDIO_SRC_LINEIN, AUDIO_SRC_FMRADIO, AUDIO_SRC_SPDIF */
287 audio_set_recording_gain(global_settings.rec_left_gain,
288 global_settings.rec_right_gain,
289 AUDIO_GAIN_LINEIN);
291 /* reset the clipping indicators */
292 peak_meter_set_clip_hold(global_settings.peak_meter_clip_hold);
293 update_list = true;
296 #ifdef HAVE_AGC
297 /* Read peak meter values & calculate balance.
298 * Returns validity of peak values.
299 * Used for automatic gain control and history diagram.
301 static bool read_peak_levels(int *peak_l, int *peak_r, int *balance)
303 peak_meter_get_peakhold(peak_l, peak_r);
304 peak_valid_mem[peak_time % 3] = *peak_l;
305 if (((peak_valid_mem[0] == peak_valid_mem[1]) &&
306 (peak_valid_mem[1] == peak_valid_mem[2])) &&
307 ((*peak_l < 32767) || storage_disk_is_active()))
308 return false;
310 if (*peak_r > *peak_l)
311 balance_mem[peak_time % BAL_MEM_SIZE] = (*peak_l ?
312 MIN((10000 * *peak_r) / *peak_l - 10000, 15118) : 15118);
313 else
314 balance_mem[peak_time % BAL_MEM_SIZE] = (*peak_r ?
315 MAX(10000 - (10000 * *peak_l) / *peak_r, -15118) : -15118);
316 *balance = 0;
317 int i;
318 for (i = 0; i < BAL_MEM_SIZE; i++)
319 *balance += balance_mem[i];
320 *balance = *balance / BAL_MEM_SIZE;
322 return true;
325 /* AGC helper function to check if maximum gain is reached */
326 static bool agc_gain_is_max(bool left, bool right)
328 /* range -128...+108 [0.5dB] */
329 short gain_current_l;
330 short gain_current_r;
332 if (agc_preset == 0)
333 return false;
335 switch (global_settings.rec_source)
337 #if defined(HAVE_LINE_REC) || defined(HAVE_FMRADIO_REC)
338 HAVE_LINE_REC_(case AUDIO_SRC_LINEIN:)
339 HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO:)
340 gain_current_l = global_settings.rec_left_gain;
341 gain_current_r = global_settings.rec_right_gain;
342 break;
343 #endif /* LINE, FMRADIO */
344 #if defined(HAVE_MIC_REC)
345 case AUDIO_SRC_MIC:
346 default:
347 gain_current_l = global_settings.rec_mic_gain;
348 gain_current_r = global_settings.rec_mic_gain;
349 #endif /* MIC */
352 return ((left && (gain_current_l >= agc_maxgain)) ||
353 (right && (gain_current_r >= agc_maxgain)));
356 static void change_recording_gain(bool increment, bool left, bool right)
358 int factor = (increment ? 1 : -1);
360 switch (global_settings.rec_source)
362 #if defined(HAVE_LINE_REC) || defined(HAVE_FMRADIO_REC)
363 HAVE_LINE_REC_(case AUDIO_SRC_LINEIN:)
364 HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO:)
365 if (left) global_settings.rec_left_gain += factor;
366 if (right) global_settings.rec_right_gain += factor;
367 break;
368 #endif /* LINE, FMRADIO */
369 #if defined(HAVE_MIC_REC)
370 case AUDIO_SRC_MIC:
371 global_settings.rec_mic_gain += factor;
372 #endif
377 * Handle automatic gain control (AGC).
378 * Change recording gain if peak_x levels are above or below
379 * target volume for specified timeouts.
381 static void auto_gain_control(int *peak_l, int *peak_r, int *balance)
383 int agc_mono;
384 short agc_mode;
385 bool increment;
387 if (*peak_l > agc_left)
388 agc_left = *peak_l;
389 else
390 agc_left -= (agc_left - *peak_l + 3) >> 2;
391 if (*peak_r > agc_right)
392 agc_right = *peak_r;
393 else
394 agc_right -= (agc_right - *peak_r + 3) >> 2;
395 agc_mono = (agc_left + agc_right) / 2;
397 agc_mode = abs(agc_preset) - 1;
398 if (agc_mode < 0) {
399 agc_enable = false;
400 return;
403 if (agc_mode != AGC_SAFETY_MODE) {
404 /* Automatic balance control - only if not in safety mode */
405 if ((agc_left > AGC_IMG) && (agc_right > AGC_IMG))
407 if (*balance < -556)
409 if (*balance > -900)
410 agc_baltime -= !(peak_time % 4); /* 0.47 - 0.75dB */
411 else if (*balance > -4125)
412 agc_baltime--; /* 0.75 - 3.00dB */
413 else if (*balance > -7579)
414 agc_baltime -= 2; /* 3.00 - 4.90dB */
415 else
416 agc_baltime -= !(peak_time % 8); /* 4.90 - inf dB */
417 if (agc_baltime > 0)
418 agc_baltime -= (peak_time % 2);
420 else if (*balance > 556)
422 if (*balance < 900)
423 agc_baltime += !(peak_time % 4);
424 else if (*balance < 4125)
425 agc_baltime++;
426 else if (*balance < 7579)
427 agc_baltime += 2;
428 else
429 agc_baltime += !(peak_time % 8);
430 if (agc_baltime < 0)
431 agc_baltime += (peak_time % 2);
434 if ((*balance * agc_baltime) < 0)
436 if (*balance < 0)
437 agc_baltime -= peak_time % 2;
438 else
439 agc_baltime += peak_time % 2;
442 increment = ((agc_risetime / 2) > agc_droptime);
444 if (agc_baltime < -agc_tbal[agc_mode])
446 if (!increment || !agc_gain_is_max(!increment, increment)) {
447 change_recording_gain(increment, !increment, increment);
448 set_gain();
450 agc_baltime = 0;
452 else if (agc_baltime > +agc_tbal[agc_mode])
454 if (!increment || !agc_gain_is_max(increment, !increment)) {
455 change_recording_gain(increment, increment, !increment);
456 set_gain();
458 agc_baltime = 0;
461 else if (!(hist_time % 4))
463 if (agc_baltime < 0)
464 agc_baltime++;
465 else
466 agc_baltime--;
470 /* Automatic gain control */
471 if ((agc_left > agc_th_hi[agc_mode]) || (agc_right > agc_th_hi[agc_mode]))
473 if ((agc_left > AGC_CLIP) || (agc_right > AGC_CLIP))
474 agc_droptime += agc_tdrop[agc_mode] /
475 (global_settings.rec_agc_cliptime + 1);
476 if (agc_left > AGC_HIGH) {
477 agc_droptime++;
478 agc_risetime=0;
479 if (agc_left > AGC_PEAK)
480 agc_droptime += 2;
482 if (agc_right > AGC_HIGH) {
483 agc_droptime++;
484 agc_risetime=0;
485 if (agc_right > AGC_PEAK)
486 agc_droptime += 2;
488 if (agc_mono > agc_th_hi[agc_mode])
489 agc_droptime++;
490 else
491 agc_droptime += !(peak_time % 2);
493 if (agc_droptime >= agc_tdrop[agc_mode])
495 change_recording_gain(false, true, true);
496 agc_droptime = 0;
497 agc_risetime = 0;
498 set_gain();
500 agc_risetime = MAX(agc_risetime - 1, 0);
502 else if (agc_mono < agc_th_lo[agc_mode])
504 if (agc_mono < (agc_th_lo[agc_mode] / 8))
505 agc_risetime += !(peak_time % 5);
506 else if (agc_mono < (agc_th_lo[agc_mode] / 2))
507 agc_risetime += 2;
508 else
509 agc_risetime++;
511 if (agc_risetime >= agc_trise[agc_mode]) {
512 if ((agc_mode != AGC_SAFETY_MODE) &&
513 (!agc_gain_is_max(true, true))) {
514 change_recording_gain(true, true, true);
515 set_gain();
517 agc_risetime = 0;
518 agc_droptime = 0;
520 agc_droptime = MAX(agc_droptime - 1, 0);
522 else if (!(peak_time % 6)) /* on target level every 1.2 sec */
524 agc_risetime = MAX(agc_risetime - 1, 0);
525 agc_droptime = MAX(agc_droptime - 1, 0);
528 #endif /* HAVE_AGC */
530 static const char* const fmtstr[] =
532 "%c%d %s", /* no decimals */
533 "%c%d.%d %s ", /* 1 decimal */
534 "%c%d.%02d %s " /* 2 decimals */
537 static char *fmt_gain(int snd, int val, char *str, int len)
539 int i, d, numdec;
540 const char *unit;
541 char sign = ' ';
543 val = sound_val2phys(snd, val);
544 if(val < 0)
546 sign = '-';
547 val = -val;
549 numdec = sound_numdecimals(snd);
550 unit = sound_unit(snd);
552 if(numdec)
554 i = val / (10*numdec);
555 d = val % (10*numdec);
556 snprintf(str, len, fmtstr[numdec], sign, i, d, unit);
558 else
559 snprintf(str, len, fmtstr[numdec], sign, val, unit);
561 return str;
564 /* the list below must match enum audio_sources in audio.h */
565 static const char* const prestr[] =
567 HAVE_MIC_IN_([AUDIO_SRC_MIC] = "R_MIC_",)
568 HAVE_LINE_REC_([AUDIO_SRC_LINEIN] = "R_LINE_",)
569 HAVE_SPDIF_IN_([AUDIO_SRC_SPDIF] = "R_SPDIF_",)
570 HAVE_FMRADIO_REC_([AUDIO_SRC_FMRADIO] = "R_FM_",)
573 char *rec_create_filename(char *buffer)
575 char ext[16];
576 const char *pref = "R_";
578 /* Directory existence and writeablility should have already been
579 * verified - do not pass NULL pointers to pcmrec */
581 if((unsigned)global_settings.rec_source < AUDIO_NUM_SOURCES)
583 pref = prestr[global_settings.rec_source];
586 strcpy(buffer, global_settings.rec_directory);
588 snprintf(ext, sizeof(ext), ".%s",
589 REC_FILE_ENDING(global_settings.rec_format));
591 #if CONFIG_RTC == 0
592 return create_numbered_filename(buffer, buffer, pref, ext, 4,
593 &file_number);
594 #else
595 /* We'll wait at least up to the start of the next second so no duplicate
596 names are created */
597 return create_datetime_filename(buffer, buffer, pref, ext, true);
598 #endif
601 #if CONFIG_RTC == 0
602 /* Hit disk to get a starting filename for the type */
603 static void rec_init_filename(void)
605 file_number = -1;
606 rec_create_filename(path_buffer);
607 file_number--;
609 #endif
611 int rec_create_directory(void)
613 int rc = 0;
614 const char * const folder = global_settings.rec_directory;
616 if (strcmp(folder, "/") && !dir_exists(folder))
618 rc = mkdir(folder);
620 if(rc < 0)
622 while (action_userabort(HZ) == false)
624 splashf(0, "%s %s",
625 str(LANG_REC_DIR_NOT_WRITABLE),
626 str(LANG_OFF_ABORT));
629 else
631 rec_status |= RCSTAT_CREATED_DIRECTORY;
632 rc = 1;
636 return rc;
639 void rec_init_recording_options(struct audio_recording_options *options)
641 options->rec_source = global_settings.rec_source;
642 options->rec_frequency = global_settings.rec_frequency;
643 options->rec_channels = global_settings.rec_channels;
644 options->rec_prerecord_time = global_settings.rec_prerecord_time;
645 #if CONFIG_CODEC == SWCODEC
646 options->rec_mono_mode = global_settings.rec_mono_mode;
647 options->rec_source_flags = 0;
648 options->enc_config.rec_format = global_settings.rec_format;
649 global_to_encoder_config(&options->enc_config);
650 #else
651 options->rec_quality = global_settings.rec_quality;
652 options->rec_editable = global_settings.rec_editable;
653 #endif
656 #if CONFIG_CODEC == SWCODEC && !defined (SIMULATOR)
657 void rec_set_source(int source, unsigned flags)
659 /* Set audio input source, power up/down devices */
660 audio_set_input_source(source, flags);
662 /* Set peakmeters for recording or reset to playback */
663 peak_meter_playback((flags & SRCF_RECORDING) == 0);
664 peak_meter_enabled = true;
666 #endif /* CONFIG_CODEC == SWCODEC && !defined (SIMULATOR) */
668 void rec_set_recording_options(struct audio_recording_options *options)
670 #if CONFIG_CODEC != SWCODEC
671 if (global_settings.rec_prerecord_time)
673 talk_buffer_steal(); /* will use the mp3 buffer */
675 #else /* == SWCODEC */
676 rec_set_source(options->rec_source,
677 options->rec_source_flags | SRCF_RECORDING);
678 #endif /* CONFIG_CODEC != SWCODEC */
680 audio_set_recording_options(options);
683 void rec_command(enum recording_command cmd)
685 switch(cmd)
687 case RECORDING_CMD_STOP_SHUTDOWN:
688 pm_activate_clipcount(false);
689 audio_stop_recording();
690 #if CONFIG_CODEC == SWCODEC
691 audio_close_recording();
692 #endif
693 sys_poweroff();
694 break;
695 case RECORDING_CMD_STOP:
696 pm_activate_clipcount(false);
697 audio_stop_recording();
698 break;
699 case RECORDING_CMD_START:
700 /* steal mp3 buffer, create unique filename and start recording */
701 pm_reset_clipcount();
702 pm_activate_clipcount(true);
703 #if CONFIG_CODEC != SWCODEC
704 talk_buffer_steal(); /* we use the mp3 buffer */
705 #endif
706 audio_record(rec_create_filename(path_buffer));
707 break;
708 case RECORDING_CMD_START_NEWFILE:
709 /* create unique filename and start recording*/
710 pm_reset_clipcount();
711 pm_activate_clipcount(true); /* just to be sure */
712 audio_new_file(rec_create_filename(path_buffer));
713 break;
714 case RECORDING_CMD_PAUSE:
715 pm_activate_clipcount(false);
716 audio_pause_recording();
717 break;
718 case RECORDING_CMD_RESUME:
719 pm_activate_clipcount(true);
720 audio_resume_recording();
721 break;
723 update_list = true;
726 /* used in trigger_listerner and recording_screen */
727 static unsigned int last_seconds = 0;
730 * Callback function so that the peak meter code can send an event
731 * to this application. This function can be passed to
732 * peak_meter_set_trigger_listener in order to activate the trigger.
734 static void trigger_listener(int trigger_status)
736 switch (trigger_status)
738 case TRIG_GO:
739 if(!(audio_status() & AUDIO_STATUS_RECORD))
741 rec_status |= RCSTAT_HAVE_RECORDED;
742 rec_command(RECORDING_CMD_START);
743 #if CONFIG_CODEC != SWCODEC
744 /* give control to mpeg thread so that it can start
745 recording */
746 yield(); yield(); yield();
747 #endif
750 /* if we're already recording this is a retrigger */
751 else
753 if((audio_status() & AUDIO_STATUS_PAUSE) &&
754 (global_settings.rec_trigger_type == TRIG_TYPE_PAUSE))
756 rec_command(RECORDING_CMD_RESUME);
758 /* New file on trig start*/
759 else if (global_settings.rec_trigger_type != TRIG_TYPE_NEW_FILE)
761 rec_command(RECORDING_CMD_START_NEWFILE);
762 /* tell recording_screen to reset the time */
763 last_seconds = 0;
766 break;
768 /* A _change_ to TRIG_READY means the current recording has stopped */
769 case TRIG_READY:
770 if(audio_status() & AUDIO_STATUS_RECORD)
772 switch(global_settings.rec_trigger_type)
774 case TRIG_TYPE_STOP: /* Stop */
775 rec_command(RECORDING_CMD_STOP);
776 break;
778 case TRIG_TYPE_PAUSE: /* Pause */
779 rec_command(RECORDING_CMD_PAUSE);
780 break;
782 case TRIG_TYPE_NEW_FILE: /* New file on trig stop*/
783 rec_command(RECORDING_CMD_START_NEWFILE);
784 /* tell recording_screen to reset the time */
785 last_seconds = 0;
786 break;
788 case 3: /* Stop and shutdown */
789 rec_command(RECORDING_CMD_STOP_SHUTDOWN);
790 break;
793 if (global_settings.rec_trigger_mode != TRIG_MODE_REARM)
795 peak_meter_set_trigger_listener(NULL);
796 peak_meter_trigger(false);
799 break;
803 /* Stuff for drawing the screen */
805 enum rec_list_items_stereo {
806 ITEM_VOLUME = 0,
807 ITEM_GAIN = 1,
808 ITEM_GAIN_L = 2,
809 ITEM_GAIN_R = 3,
810 #ifdef HAVE_AGC
811 ITEM_AGC_MODE = 4,
812 ITEM_AGC_MAXDB = 5,
813 ITEM_FILENAME = 7,
814 ITEM_COUNT = 7,
815 #else
816 ITEM_FILENAME = 7,
817 ITEM_COUNT = 5,
818 #endif
821 enum rec_list_items_mono {
822 ITEM_VOLUME_M = 0,
823 ITEM_GAIN_M = 1,
824 #ifdef HAVE_AGC
825 ITEM_AGC_MODE_M = 4,
826 ITEM_AGC_MAXDB_M = 5,
827 ITEM_FILENAME_M = 7,
828 ITEM_COUNT_M = 5,
829 #else
830 ITEM_FILENAME_M = 7,
831 ITEM_COUNT_M = 3,
832 #endif
835 #ifdef HAVE_SPDIF_REC
836 enum rec_list_items_spdif {
837 ITEM_VOLUME_D = 0,
838 #if CONFIG_CODEC == SWCODEC
839 ITEM_SAMPLERATE_D = 6,
840 ITEM_FILENAME_D = 7,
841 ITEM_COUNT_D = 3,
842 #else
843 ITEM_FILENAME_D = 7,
844 ITEM_COUNT_D = 2,
845 #endif
847 #endif
849 static int listid_to_enum[ITEM_COUNT];
851 static const char* reclist_get_name(int selected_item, void * data,
852 char * buffer, size_t buffer_len)
854 char buf2[32];
855 #ifdef HAVE_AGC
856 char buf3[32];
857 #endif
858 data = data; /* not used */
859 if(selected_item >= ITEM_COUNT)
860 return "";
862 switch (listid_to_enum[selected_item])
864 case ITEM_VOLUME:
865 snprintf(buffer, buffer_len, "%s: %s", str(LANG_VOLUME),
866 fmt_gain(SOUND_VOLUME,
867 global_settings.volume,
868 buf2, sizeof(buf2)));
869 break;
870 case ITEM_GAIN:
871 #ifdef HAVE_MIC_REC
872 if(global_settings.rec_source == AUDIO_SRC_MIC)
874 /* Draw MIC recording gain */
875 snprintf(buffer, buffer_len, "%s: %s", str(LANG_GAIN),
876 fmt_gain(SOUND_MIC_GAIN,
877 global_settings.rec_mic_gain,
878 buf2, sizeof(buf2)));
880 else
881 #endif /* MIC */
883 int avg_gain = (global_settings.rec_left_gain +
884 global_settings.rec_right_gain) / 2;
885 snprintf(buffer, buffer_len, "%s: %s", str(LANG_GAIN),
886 fmt_gain(SOUND_LEFT_GAIN,
887 avg_gain,
888 buf2, sizeof(buf2)));
890 break;
891 case ITEM_GAIN_L:
892 snprintf(buffer, buffer_len, "%s: %s",
893 str(LANG_GAIN_LEFT),
894 fmt_gain(SOUND_LEFT_GAIN,
895 global_settings.rec_left_gain,
896 buf2, sizeof(buf2)));
897 break;
898 case ITEM_GAIN_R:
899 snprintf(buffer, buffer_len, "%s: %s",
900 str(LANG_GAIN_RIGHT),
901 fmt_gain(SOUND_RIGHT_GAIN,
902 global_settings.rec_right_gain,
903 buf2, sizeof(buf2)));
904 break;
905 #ifdef HAVE_AGC
906 case ITEM_AGC_MODE:
907 snprintf(buffer, buffer_len, "%s: %s",
908 str(LANG_RECORDING_AGC_PRESET),
909 agc_preset_str[agc_preset]);
910 break;
911 case ITEM_AGC_MAXDB:
912 if (agc_preset == 0)
913 snprintf(buffer, buffer_len, "%s: %s",
914 str(LANG_RECORDING_AGC_MAXGAIN),
915 fmt_gain(SOUND_LEFT_GAIN,
916 agc_maxgain, buf2, sizeof(buf2)));
917 #ifdef HAVE_MIC_REC
918 else if (global_settings.rec_source == AUDIO_SRC_MIC)
919 snprintf(buffer, buffer_len, "%s: %s (%s)",
920 str(LANG_RECORDING_AGC_MAXGAIN),
921 fmt_gain(SOUND_MIC_GAIN,
922 agc_maxgain, buf2, sizeof(buf2)),
923 fmt_gain(SOUND_MIC_GAIN,
924 agc_maxgain - global_settings.rec_mic_gain,
925 buf3, sizeof(buf3)));
926 else
927 #endif /* MIC */
928 snprintf(buffer, buffer_len, "%s: %s (%s)",
929 str(LANG_RECORDING_AGC_MAXGAIN),
930 fmt_gain(SOUND_LEFT_GAIN,
931 agc_maxgain, buf2, sizeof(buf2)),
932 fmt_gain(SOUND_LEFT_GAIN,
933 agc_maxgain -
934 (global_settings.rec_left_gain +
935 global_settings.rec_right_gain)/2,
936 buf3, sizeof(buf3)));
937 break;
938 #endif
939 #if CONFIG_CODEC == SWCODEC
940 #ifdef HAVE_SPDIF_REC
941 case ITEM_SAMPLERATE_D:
942 snprintf(buffer, buffer_len, "%s: %d",
943 str(LANG_RECORDING_FREQUENCY),
944 pcm_rec_sample_rate());
945 break;
946 #endif
947 #endif
948 case ITEM_FILENAME:
950 if(audio_status() & AUDIO_STATUS_RECORD)
952 size_t tot_len = strlen(path_buffer) +
953 strlen(str(LANG_RECORDING_FILENAME)) + 1;
954 if(tot_len > buffer_len)
956 snprintf(buffer, buffer_len, "%s %s",
957 str(LANG_RECORDING_FILENAME),
958 path_buffer + tot_len - buffer_len);
960 else
962 snprintf(buffer, buffer_len, "%s %s",
963 str(LANG_RECORDING_FILENAME), path_buffer);
966 else
968 return str(LANG_RECORDING_FILENAME);
970 break;
972 default:
973 return "";
975 return buffer;
979 bool recording_start_automatic = false;
981 bool recording_screen(bool no_source)
983 int button;
984 int done = -1; /* negative to re-init, positive to quit, zero to run */
985 char buf[32]; /* for preparing strings */
986 char buf2[32]; /* for preparing strings */
987 int w, h; /* character width/height */
988 int update_countdown = 0; /* refresh counter */
989 unsigned int seconds;
990 int hours, minutes;
991 int audio_stat = 0; /* status of the audio system */
992 int last_audio_stat = -1; /* previous status so we can act on changes */
993 struct viewport vp_list[NB_SCREENS], vp_top[NB_SCREENS]; /* the viewports */
995 #if CONFIG_CODEC == SWCODEC
996 int warning_counter = 0;
997 #define WARNING_PERIOD 7
998 #endif
1000 #if CONFIG_CODEC == SWCODEC
1001 #ifdef HAVE_SPDIF_REC
1002 unsigned long prev_sample_rate = 0;
1003 #endif
1004 #endif
1006 #ifdef HAVE_FMRADIO_REC
1007 /* Radio is left on if:
1008 * 1) Is was on at the start and the initial source is FM Radio
1009 * 2) 1) and the source was never changed to something else
1011 int radio_status = (global_settings.rec_source != AUDIO_SRC_FMRADIO) ?
1012 FMRADIO_OFF : get_radio_status();
1013 #endif
1014 #if (CONFIG_LED == LED_REAL)
1015 bool led_state = false;
1016 int led_countdown = 2;
1017 #endif
1018 #ifdef HAVE_AGC
1019 bool peak_read = false;
1020 bool peak_valid = false;
1021 int peak_l, peak_r;
1022 int balance = 0;
1023 #endif
1024 int oldbars, recbars = VP_SB_ALLSCREENS;
1025 int i;
1026 int pm_x[NB_SCREENS]; /* peakmeter (and trigger bar) x pos */
1027 int pm_y[NB_SCREENS]; /* peakmeter y pos */
1028 int pm_h[NB_SCREENS]; /* peakmeter height */
1029 int trig_ypos[NB_SCREENS]; /* trigger bar y pos */
1030 int trig_width[NB_SCREENS]; /* trigger bar width */
1031 bool compact_view[NB_SCREENS]; /* tweak layout tiny screens / big fonts */
1033 struct gui_synclist lists; /* the list in the bottom vp */
1034 #ifdef HAVE_FMRADIO_REC
1035 int prev_rec_source = global_settings.rec_source; /* detect source change */
1036 #endif
1038 struct audio_recording_options rec_options;
1039 rec_status = RCSTAT_IN_RECSCREEN;
1041 #if (CONFIG_STORAGE & STORAGE_ATA) && (CONFIG_LED == LED_REAL) \
1042 && !defined(SIMULATOR)
1043 ata_set_led_enabled(false);
1044 #endif
1046 #if CONFIG_CODEC == SWCODEC
1047 /* recording_menu gets messed up: so prevent manus talking */
1048 talk_disable(true);
1049 /* audio_init_recording stops anything playing when it takes the audio
1050 buffer */
1051 #else
1052 /* Yes, we use the D/A for monitoring */
1053 peak_meter_enabled = true;
1054 peak_meter_playback(true);
1055 #endif
1057 #ifdef HAVE_AGC
1058 peak_meter_get_peakhold(&peak_l, &peak_r);
1059 #endif
1061 pm_reset_clipcount();
1062 pm_activate_clipcount(false);
1063 settings_apply_trigger();
1065 #ifdef HAVE_AGC
1066 agc_preset_str[0] = str(LANG_OFF);
1067 agc_preset_str[1] = str(LANG_AGC_SAFETY);
1068 agc_preset_str[2] = str(LANG_AGC_LIVE);
1069 agc_preset_str[3] = str(LANG_AGC_DJSET);
1070 agc_preset_str[4] = str(LANG_AGC_MEDIUM);
1071 agc_preset_str[5] = str(LANG_AGC_VOICE);
1072 #endif /* HAVE_AGC */
1074 #if CONFIG_CODEC == SWCODEC
1075 audio_close_recording();
1076 #endif
1077 audio_init_recording(0);
1078 sound_set_volume(global_settings.volume);
1080 #if CONFIG_RTC == 0
1081 /* Create new filename for recording start */
1082 rec_init_filename();
1083 #endif
1085 /* viewport init and calculations that only needs to be done once */
1086 FOR_NB_SCREENS(i)
1087 recbars |= VP_SB_IGNORE_SETTING(i);
1088 oldbars = viewportmanager_set_statusbar(recbars);
1089 FOR_NB_SCREENS(i)
1091 struct viewport *v;
1092 /* top vp, 4 lines, force sys font if total screen < 6 lines
1093 NOTE: one could limit the list to 1 line and get away with 5 lines */
1094 v = &vp_top[i];
1095 viewport_set_defaults(v, i);
1096 if (viewport_get_nb_lines(v) < 4)
1098 /* compact needs 4 lines total */
1099 v->font = FONT_SYSFIXED;
1100 compact_view[i] = false;
1102 else
1104 if (viewport_get_nb_lines(v) < (4+2)) /*top=4,list=2*/
1105 compact_view[i] = true;
1106 else
1107 compact_view[i] = false;
1109 vp_list[i] = *v; /* get a copy now so it can be sized more easily */
1110 v->height = (font_get(v->font)->height)*(compact_view[i] ? 3 : 4);
1112 /* list section, rest of the screen */
1113 vp_list[i].y += vp_top[i].height;
1114 vp_list[i].height -= vp_top[i].height;
1115 screens[i].set_viewport(&vp_top[i]); /* req for next calls */
1117 screens[i].getstringsize("W", &w, &h);
1118 pm_y[i] = font_get(vp_top[i].font)->height * 2;
1119 trig_ypos[i] = font_get(vp_top[i].font)->height * 3;
1120 if(compact_view[i])
1121 trig_ypos[i] -= (font_get(vp_top[i].font)->height)/2;
1124 /* init the bottom list */
1125 gui_synclist_init(&lists, reclist_get_name, NULL, false, 1, vp_list);
1126 gui_synclist_set_title(&lists, NULL, Icon_NOICON);
1128 /* start of the loop: we stay in this loop until user quits recscreen */
1129 while(done <= 0)
1131 if(done < 0)
1133 /* request to re-init stuff, done after settings screen */
1134 done = 0;
1135 #ifdef HAVE_FMRADIO_REC
1136 /* If input changes away from FM Radio,
1137 radio will remain off when recording screen closes. */
1138 if (global_settings.rec_source != prev_rec_source
1139 && prev_rec_source == AUDIO_SRC_FMRADIO)
1140 radio_status = FMRADIO_OFF;
1141 prev_rec_source = global_settings.rec_source;
1142 #endif
1144 FOR_NB_SCREENS(i)
1146 pm_x[i] = 0;
1147 if(global_settings.peak_meter_clipcounter)
1149 int clipwidth = 0;
1150 screens[i].getstringsize(str(LANG_PM_CLIPCOUNT),
1151 &clipwidth, &h); /* h is same */
1152 pm_x[i] = clipwidth+1;
1154 if(global_settings.rec_trigger_mode == TRIG_MODE_OFF)
1155 pm_h[i] = font_get(vp_top[i].font)->height * 2;
1156 else
1157 pm_h[i] = font_get(vp_top[i].font)->height;
1158 if(compact_view[i])
1159 pm_h[i] /= 2;
1160 trig_width[i] = vp_top[i].width - pm_x[i];
1163 #if CONFIG_CODEC == SWCODEC
1164 audio_close_recording();
1165 audio_init_recording(0);
1166 #endif
1168 rec_init_recording_options(&rec_options);
1169 rec_set_recording_options(&rec_options);
1171 if(rec_create_directory() < 0)
1173 rec_status = 0;
1174 goto rec_abort;
1177 #if CONFIG_CODEC == SWCODEC && CONFIG_RTC == 0
1178 /* If format changed, a new number is required */
1179 rec_init_filename();
1180 #endif
1182 #ifdef HAVE_AGC
1183 #ifdef HAVE_MIC_REC
1184 if (global_settings.rec_source == AUDIO_SRC_MIC) {
1185 agc_preset = global_settings.rec_agc_preset_mic;
1186 agc_maxgain = global_settings.rec_agc_maxgain_mic;
1188 else
1189 #endif /* MIC */
1191 agc_preset = global_settings.rec_agc_preset_line;
1192 agc_maxgain = global_settings.rec_agc_maxgain_line;
1194 #endif /* HAVE_AGC */
1196 set_gain();
1197 update_countdown = 0; /* Update immediately */
1199 /* populate translation table for list id -> enum */
1200 #ifdef HAVE_SPDIF_REC
1201 if(global_settings.rec_source == AUDIO_SRC_SPDIF)
1203 listid_to_enum[0] = ITEM_VOLUME_D;
1204 #if CONFIG_CODEC == SWCODEC
1205 listid_to_enum[1] = ITEM_SAMPLERATE_D;
1206 listid_to_enum[2] = ITEM_FILENAME_D;
1207 #else
1208 listid_to_enum[1] = ITEM_FILENAME_D;
1209 #endif
1211 gui_synclist_set_nb_items(&lists, ITEM_COUNT_D); /* spdif */
1213 else
1214 #endif
1215 if(HAVE_MIC_REC_((global_settings.rec_source == AUDIO_SRC_MIC) || )
1216 (global_settings.rec_channels == 1))
1218 listid_to_enum[0] = ITEM_VOLUME_M;
1219 listid_to_enum[1] = ITEM_GAIN_M;
1220 #ifdef HAVE_AGC
1221 listid_to_enum[2] = ITEM_AGC_MODE_M;
1222 listid_to_enum[3] = ITEM_AGC_MAXDB_M;
1223 listid_to_enum[4] = ITEM_FILENAME_M;
1224 #else
1225 listid_to_enum[2] = ITEM_FILENAME_M;
1226 #endif
1227 gui_synclist_set_nb_items(&lists, ITEM_COUNT_M); /* mono */
1229 else
1231 listid_to_enum[0] = ITEM_VOLUME;
1232 listid_to_enum[1] = ITEM_GAIN;
1233 listid_to_enum[2] = ITEM_GAIN_L;
1234 listid_to_enum[3] = ITEM_GAIN_R;
1235 #ifdef HAVE_AGC
1236 listid_to_enum[4] = ITEM_AGC_MODE;
1237 listid_to_enum[5] = ITEM_AGC_MAXDB;
1238 listid_to_enum[6] = ITEM_FILENAME;
1239 #else
1240 listid_to_enum[4] = ITEM_FILENAME;
1241 #endif
1242 gui_synclist_set_nb_items(&lists, ITEM_COUNT); /* stereo */
1245 gui_synclist_draw(&lists);
1246 } /* if(done < 0) */
1248 audio_stat = audio_status();
1250 #if (CONFIG_LED == LED_REAL)
1253 * Flash the LED while waiting to record. Turn it on while
1254 * recording.
1256 if(audio_stat & AUDIO_STATUS_RECORD)
1258 if (audio_stat & AUDIO_STATUS_PAUSE)
1260 if (--led_countdown <= 0)
1262 led_state = !led_state;
1263 led(led_state);
1264 led_countdown = 2;
1267 else
1269 /* trigger is on in status TRIG_READY (no check needed) */
1270 led(true);
1273 else
1275 int trig_stat = peak_meter_trigger_status();
1277 * other trigger stati than trig_off and trig_steady
1278 * already imply that we are recording.
1280 if (trig_stat == TRIG_STEADY)
1282 if (--led_countdown <= 0)
1284 led_state = !led_state;
1285 led(led_state);
1286 led_countdown = 2;
1289 else
1291 /* trigger is on in status TRIG_READY (no check needed) */
1292 led(false);
1295 #endif /* CONFIG_LED */
1297 /* Wait for a button a while (HZ/10) drawing the peak meter */
1298 button = peak_meter_draw_get_btn(CONTEXT_RECSCREEN,
1299 pm_x, pm_y, pm_h,
1300 screen_update, vp_top);
1301 if (last_audio_stat != audio_stat)
1303 if (audio_stat & AUDIO_STATUS_RECORD)
1305 rec_status |= RCSTAT_HAVE_RECORDED;
1307 last_audio_stat = audio_stat;
1308 update_list = true;
1311 if (recording_start_automatic)
1313 /* simulate a button press */
1314 button = ACTION_REC_PAUSE;
1315 recording_start_automatic = false;
1318 /* let list handle the button */
1319 gui_synclist_do_button(&lists, &button, LIST_WRAP_UNLESS_HELD);
1322 switch(button)
1324 case ACTION_SETTINGS_INC:
1325 case ACTION_SETTINGS_INCREPEAT:
1326 switch (listid_to_enum[gui_synclist_get_sel_pos(&lists)])
1328 case ITEM_VOLUME:
1329 global_settings.volume++;
1330 setvol();
1331 break;
1332 case ITEM_GAIN:
1333 #ifdef HAVE_MIC_REC
1334 if(global_settings.rec_source == AUDIO_SRC_MIC)
1336 if(global_settings.rec_mic_gain <
1337 sound_max(SOUND_MIC_GAIN))
1338 global_settings.rec_mic_gain++;
1340 else
1341 #endif /* MIC */
1343 if(global_settings.rec_left_gain <
1344 sound_max(SOUND_LEFT_GAIN))
1345 global_settings.rec_left_gain++;
1346 if(global_settings.rec_right_gain <
1347 sound_max(SOUND_RIGHT_GAIN))
1348 global_settings.rec_right_gain++;
1350 break;
1351 case ITEM_GAIN_L:
1352 if(global_settings.rec_left_gain <
1353 sound_max(SOUND_LEFT_GAIN))
1354 global_settings.rec_left_gain++;
1355 break;
1356 case ITEM_GAIN_R:
1357 if(global_settings.rec_right_gain <
1358 sound_max(SOUND_RIGHT_GAIN))
1359 global_settings.rec_right_gain++;
1360 break;
1361 #ifdef HAVE_AGC
1362 case ITEM_AGC_MODE:
1363 agc_preset = MIN(agc_preset + 1, AGC_MODE_SIZE);
1364 agc_enable = (agc_preset != 0);
1365 #ifdef HAVE_MIC_REC
1366 if (global_settings.rec_source == AUDIO_SRC_MIC) {
1367 global_settings.rec_agc_preset_mic = agc_preset;
1368 agc_maxgain = global_settings.rec_agc_maxgain_mic;
1369 } else
1370 #endif /* MIC */
1372 global_settings.rec_agc_preset_line = agc_preset;
1373 agc_maxgain = global_settings.rec_agc_maxgain_line;
1375 break;
1376 case ITEM_AGC_MAXDB:
1377 #ifdef HAVE_MIC_REC
1378 if (global_settings.rec_source == AUDIO_SRC_MIC)
1380 agc_maxgain = MIN(agc_maxgain + 1,
1381 sound_max(SOUND_MIC_GAIN));
1382 global_settings.rec_agc_maxgain_mic = agc_maxgain;
1384 else
1385 #endif /* MIC */
1387 agc_maxgain = MIN(agc_maxgain + 1,
1388 sound_max(SOUND_LEFT_GAIN));
1389 global_settings.rec_agc_maxgain_line = agc_maxgain;
1391 break;
1392 #endif /* HAVE_AGC */
1394 set_gain();
1395 update_countdown = 0; /* Update immediately */
1396 break;
1397 case ACTION_SETTINGS_DEC:
1398 case ACTION_SETTINGS_DECREPEAT:
1399 switch (listid_to_enum[gui_synclist_get_sel_pos(&lists)])
1401 case ITEM_VOLUME:
1402 global_settings.volume--;
1403 setvol();
1404 break;
1405 case ITEM_GAIN:
1406 #ifdef HAVE_MIC_REC
1407 if(global_settings.rec_source == AUDIO_SRC_MIC)
1409 if(global_settings.rec_mic_gain >
1410 sound_min(SOUND_MIC_GAIN))
1411 global_settings.rec_mic_gain--;
1413 else
1414 #endif /* MIC */
1416 if(global_settings.rec_left_gain >
1417 sound_min(SOUND_LEFT_GAIN))
1418 global_settings.rec_left_gain--;
1419 if(global_settings.rec_right_gain >
1420 sound_min(SOUND_RIGHT_GAIN))
1421 global_settings.rec_right_gain--;
1423 break;
1424 case ITEM_GAIN_L:
1425 if(global_settings.rec_left_gain >
1426 sound_min(SOUND_LEFT_GAIN))
1427 global_settings.rec_left_gain--;
1428 break;
1429 case ITEM_GAIN_R:
1430 if(global_settings.rec_right_gain >
1431 sound_min(SOUND_RIGHT_GAIN))
1432 global_settings.rec_right_gain--;
1433 break;
1434 #ifdef HAVE_AGC
1435 case ITEM_AGC_MODE:
1436 agc_preset = MAX(agc_preset - 1, 0);
1437 agc_enable = (agc_preset != 0);
1438 #ifdef HAVE_MIC_REC
1439 if (global_settings.rec_source == AUDIO_SRC_MIC) {
1440 global_settings.rec_agc_preset_mic = agc_preset;
1441 agc_maxgain = global_settings.rec_agc_maxgain_mic;
1442 } else
1443 #endif /* MIC */
1445 global_settings.rec_agc_preset_line = agc_preset;
1446 agc_maxgain = global_settings.rec_agc_maxgain_line;
1448 break;
1449 case ITEM_AGC_MAXDB:
1450 #ifdef HAVE_MIC_REC
1451 if (global_settings.rec_source == AUDIO_SRC_MIC)
1453 agc_maxgain = MAX(agc_maxgain - 1,
1454 sound_min(SOUND_MIC_GAIN));
1455 global_settings.rec_agc_maxgain_mic = agc_maxgain;
1456 } else
1457 #endif /* MIC */
1459 agc_maxgain = MAX(agc_maxgain - 1,
1460 sound_min(SOUND_LEFT_GAIN));
1461 global_settings.rec_agc_maxgain_line = agc_maxgain;
1463 break;
1464 #endif /* HAVE_AGC */
1466 set_gain();
1467 update_countdown = 0; /* Update immediately */
1468 break;
1469 case ACTION_STD_CANCEL:
1470 /* turn off the trigger */
1471 peak_meter_trigger(false);
1472 peak_meter_set_trigger_listener(NULL);
1474 if(audio_stat & AUDIO_STATUS_RECORD)
1476 rec_command(RECORDING_CMD_STOP);
1478 else
1480 #if CONFIG_CODEC != SWCODEC
1481 peak_meter_playback(true);
1482 peak_meter_enabled = false;
1483 #endif
1484 done = 1;
1486 update_countdown = 0; /* Update immediately */
1487 break;
1488 #ifdef HAVE_REMOTE_LCD
1489 case ACTION_REC_LCD:
1490 /* this feature exists for some h1x0/h3x0 targets that suffer
1491 from noise caused by remote LCD updates
1492 NOTE 1: this will leave the list on the remote
1493 NOTE 2: to be replaced by a global LCD_off() routine */
1494 if(remote_display_on)
1496 /* switch to single screen, leave message on remote */
1497 screen_update = 1;
1498 screens[1].clear_viewport();
1499 screens[1].puts(0, 0, str(LANG_REMOTE_LCD_OFF));
1500 screens[1].puts(0, 1, str(LANG_REMOTE_LCD_ON));
1501 screens[1].update_viewport();
1503 else
1505 /* remote switched on again */
1506 update_list = true;
1507 screen_update = NB_SCREENS;
1509 remote_display_on = !remote_display_on; /* toggle */
1510 update_countdown = 0; /* Update immediately */
1511 break;
1512 #endif
1513 case ACTION_REC_NEWFILE:
1514 /* start recording or start a new file */
1515 if(audio_stat & AUDIO_STATUS_RECORD)
1517 rec_command(RECORDING_CMD_START_NEWFILE);
1518 last_seconds = 0;
1520 else
1522 /* is this manual or triggered recording? */
1523 if ((global_settings.rec_trigger_mode == TRIG_MODE_OFF) ||
1524 (peak_meter_trigger_status() != TRIG_OFF))
1526 /* manual recording */
1527 rec_status |= RCSTAT_HAVE_RECORDED;
1528 rec_command(RECORDING_CMD_START);
1529 last_seconds = 0;
1530 if (global_settings.talk_menu)
1532 /* no voice possible here, but a beep */
1533 audio_beep(HZ/2); /* longer beep on start */
1536 /* this is triggered recording */
1537 else
1539 /* we don't start recording now, but enable the
1540 trigger and let the callback function
1541 trigger_listener control when the recording starts */
1542 peak_meter_trigger(true);
1543 peak_meter_set_trigger_listener(&trigger_listener);
1546 update_countdown = 0; /* Update immediately */
1547 break;
1548 case ACTION_REC_PAUSE:
1549 /* Only act if a recording is ongoing (paused or not) */
1550 if(audio_stat & AUDIO_STATUS_RECORD)
1552 /* if pause button pressed, pause or resume */
1553 if(audio_stat & AUDIO_STATUS_PAUSE)
1555 rec_command(RECORDING_CMD_RESUME);
1556 if (global_settings.talk_menu)
1558 /* no voice possible here, but a beep */
1559 audio_beep(HZ/4); /* short beep on resume */
1562 else
1564 rec_command(RECORDING_CMD_PAUSE);
1567 update_countdown = 0; /* Update immediately */
1568 break;
1569 case ACTION_STD_MENU:
1570 #if CONFIG_CODEC == SWCODEC
1571 if(!(audio_stat & AUDIO_STATUS_RECORD))
1572 #else
1573 if(audio_stat != AUDIO_STATUS_RECORD)
1574 #endif
1576 #if (CONFIG_LED == LED_REAL)
1577 /* led is restored at begin of loop / end of function */
1578 led(false);
1579 #endif
1580 viewportmanager_set_statusbar(oldbars);
1581 if (recording_menu(no_source))
1583 done = 1;
1584 rec_status |= RCSTAT_BEEN_IN_USB_MODE;
1585 #ifdef HAVE_FMRADIO_REC
1586 radio_status = FMRADIO_OFF;
1587 #endif
1589 else
1591 done = -1;
1592 /* the init is now done at the beginning of the loop */
1594 viewportmanager_set_statusbar(recbars);
1596 break;
1598 #if CONFIG_KEYPAD == RECORDER_PAD
1599 case ACTION_REC_F2:
1600 if(audio_stat != AUDIO_STATUS_RECORD)
1602 #if (CONFIG_LED == LED_REAL)
1603 /* led is restored at begin of loop / end of function */
1604 led(false);
1605 #endif
1606 viewportmanager_set_statusbar(oldbars);
1607 if (f2_rec_screen())
1609 rec_status |= RCSTAT_HAVE_RECORDED;
1610 done = true;
1612 else
1613 update_countdown = 0; /* Update immediately */
1614 viewportmanager_set_statusbar(recbars);
1616 break;
1618 case ACTION_REC_F3:
1619 if(audio_stat & AUDIO_STATUS_RECORD)
1621 rec_command(RECORDING_CMD_START_NEWFILE);
1622 last_seconds = 0;
1624 else
1626 #if (CONFIG_LED == LED_REAL)
1627 /* led is restored at begin of loop / end of function */
1628 led(false);
1629 #endif
1630 viewportmanager_set_statusbar(oldbars);
1631 if (f3_rec_screen())
1633 rec_status |= RCSTAT_HAVE_RECORDED;
1634 done = true;
1636 else
1637 update_countdown = 0; /* Update immediately */
1638 viewportmanager_set_statusbar(recbars);
1640 break;
1641 #endif /* CONFIG_KEYPAD == RECORDER_PAD */
1643 case SYS_USB_CONNECTED:
1644 /* Only accept USB connection when not recording */
1645 if(!(audio_stat & AUDIO_STATUS_RECORD))
1647 FOR_NB_SCREENS(i)
1648 screens[i].set_viewport(NULL);
1649 default_event_handler(SYS_USB_CONNECTED);
1650 done = true;
1651 rec_status |= RCSTAT_BEEN_IN_USB_MODE;
1652 #ifdef HAVE_FMRADIO_REC
1653 radio_status = FMRADIO_OFF;
1654 #endif
1656 break;
1657 } /*switch(button)*/
1659 #ifdef HAVE_AGC
1660 peak_read = !peak_read;
1661 if (peak_read) { /* every 2nd run of loop */
1662 peak_time++;
1663 peak_valid = read_peak_levels(&peak_l, &peak_r, &balance);
1666 /* Handle AGC every 200ms when enabled and peak data is valid */
1667 if (peak_read && agc_enable && peak_valid)
1668 auto_gain_control(&peak_l, &peak_r, &balance);
1669 #endif
1671 seconds = audio_recorded_time() / HZ;
1673 /* start of vp_top drawing */
1674 if(update_countdown-- == 0 || seconds > last_seconds)
1676 unsigned int dseconds, dhours, dminutes;
1677 unsigned long num_recorded_bytes, dsize, dmb;
1680 FOR_NB_SCREENS(i)
1682 screens[i].set_viewport(&vp_top[i]);
1683 screens[i].clear_viewport();
1685 update_countdown = 5;
1686 last_seconds = seconds;
1688 dseconds = rec_timesplit_seconds();
1689 dsize = rec_sizesplit_bytes();
1690 num_recorded_bytes = audio_num_recorded_bytes();
1692 #if CONFIG_CODEC == SWCODEC
1693 if ((audio_stat & AUDIO_STATUS_WARNING)
1694 && (warning_counter++ % WARNING_PERIOD) < WARNING_PERIOD/2)
1696 /* Switch back and forth displaying warning on first available
1697 line to ensure visibility - the motion should also help
1698 draw attention */
1699 /* Don't use language string unless agreed upon to make this
1700 method permanent - could do something in the statusbar */
1701 snprintf(buf, sizeof(buf), "Warning: %08X",
1702 pcm_rec_get_warnings());
1704 else
1705 #endif /* CONFIG_CODEC == SWCODEC */
1706 if ((global_settings.rec_sizesplit) &&
1707 (global_settings.rec_split_method))
1709 dmb = dsize/1024/1024;
1710 snprintf(buf, sizeof(buf), "%s %dMB",
1711 str(LANG_SPLIT_SIZE), dmb);
1713 else
1715 hours = seconds / 3600;
1716 minutes = (seconds - (hours * 3600)) / 60;
1717 snprintf(buf, sizeof(buf), "%s %02d:%02d:%02d",
1718 str(LANG_RECORDING_TIME),
1719 hours, minutes, seconds%60);
1722 FOR_NB_ACTIVE_SCREENS(i)
1723 screens[i].puts(0, 0, buf);
1725 if(audio_stat & AUDIO_STATUS_PRERECORD)
1727 snprintf(buf, sizeof(buf), "%s...",
1728 str(LANG_RECORD_PRERECORD));
1730 else
1732 /* Display the split interval if the record timesplit
1733 is active */
1734 if ((global_settings.rec_timesplit) &&
1735 !(global_settings.rec_split_method))
1737 /* Display the record timesplit interval rather
1738 than the file size if the record timer is active */
1739 dhours = dseconds / 3600;
1740 dminutes = (dseconds - (dhours * 3600)) / 60;
1741 snprintf(buf, sizeof(buf), "%s %02d:%02d",
1742 str(LANG_RECORDING_TIMESPLIT_REC),
1743 dhours, dminutes);
1745 else
1747 output_dyn_value(buf2, sizeof buf2,
1748 num_recorded_bytes,
1749 byte_units, true);
1750 snprintf(buf, sizeof(buf), "%s %s",
1751 str(LANG_RECORDING_SIZE), buf2);
1755 FOR_NB_ACTIVE_SCREENS(i)
1756 screens[i].puts(0, 1, buf);
1758 /* We will do file splitting regardless, either at the end of
1759 a split interval, or when the filesize approaches the 2GB
1760 FAT file size (compatibility) limit. */
1761 if ((audio_stat && !(global_settings.rec_split_method)
1762 && global_settings.rec_timesplit && (seconds >= dseconds))
1763 || (audio_stat && global_settings.rec_split_method
1764 && global_settings.rec_sizesplit
1765 && (num_recorded_bytes >= dsize))
1766 || (num_recorded_bytes >= MAX_FILE_SIZE))
1768 if (!(global_settings.rec_split_type)
1769 || (num_recorded_bytes >= MAX_FILE_SIZE))
1771 rec_command(RECORDING_CMD_START_NEWFILE);
1772 last_seconds = 0;
1774 else
1776 peak_meter_trigger(false);
1777 peak_meter_set_trigger_listener(NULL);
1778 if( global_settings.rec_split_type == 1)
1779 rec_command(RECORDING_CMD_STOP);
1780 else
1781 rec_command(RECORDING_CMD_STOP_SHUTDOWN);
1783 update_countdown = 0;
1786 /* draw the clipcounter just in front of the peakmeter */
1787 if(global_settings.peak_meter_clipcounter)
1789 char clpstr[32];
1790 snprintf(clpstr, 32, "%4d", pm_get_clipcount());
1791 FOR_NB_ACTIVE_SCREENS(i)
1793 if(!compact_view[i])
1794 screens[i].puts(0, 2,str(LANG_PM_CLIPCOUNT));
1795 screens[i].puts(0, compact_view[i] ? 2 : 3, clpstr);
1799 #ifdef HAVE_AGC
1800 hist_time++;
1801 #endif
1803 /* draw the trigger status */
1804 if (peak_meter_trigger_status() != TRIG_OFF)
1806 peak_meter_draw_trig(pm_x, trig_ypos, trig_width,
1807 screen_update);
1808 FOR_NB_ACTIVE_SCREENS(i)
1809 screens[i].update_viewport_rect(pm_x[i], trig_ypos[i],
1810 trig_width[i] + 2, TRIG_HEIGHT);
1813 #ifdef HAVE_AGC
1814 #ifdef HAVE_MIC_REC
1815 if (global_settings.rec_source == AUDIO_SRC_MIC)
1817 if(agc_maxgain < (global_settings.rec_mic_gain))
1818 change_recording_gain(false, true, true);
1820 else
1821 #endif /* MIC */
1823 if(agc_maxgain < (global_settings.rec_left_gain))
1824 change_recording_gain(false, true, false);
1825 if(agc_maxgain < (global_settings.rec_right_gain))
1826 change_recording_gain(false, false, true);
1828 #endif /* HAVE_AGC */
1830 #if CONFIG_CODEC == SWCODEC
1831 #ifdef HAVE_SPDIF_REC
1832 if((global_settings.rec_source == AUDIO_SRC_SPDIF) &&
1833 (prev_sample_rate != pcm_rec_sample_rate()))
1835 /* spdif samplerate changed */
1836 prev_sample_rate = pcm_rec_sample_rate();
1837 update_list = true;
1839 #endif
1840 #endif
1842 if(update_list)
1844 /* update_list is set whenever content changes */
1845 update_list = false;
1846 gui_synclist_draw(&lists);
1849 /* draw peakmeter again (check if this can be removed) */
1850 FOR_NB_ACTIVE_SCREENS(i)
1852 screens[i].set_viewport(&vp_top[i]);
1853 peak_meter_screen(&screens[i], pm_x[i], pm_y[i], pm_h[i]);
1854 screens[i].update();
1856 } /* display update every second */
1858 if(audio_stat & AUDIO_STATUS_ERROR)
1860 done = true;
1862 } /* end while(!done) */
1864 audio_stat = audio_status();
1865 if (audio_stat & AUDIO_STATUS_ERROR)
1867 splash(0, str(LANG_DISK_FULL));
1869 FOR_NB_SCREENS(i)
1870 screens[i].update();
1872 #if CONFIG_CODEC == SWCODEC
1873 /* stop recording - some players like H10 freeze otherwise
1874 TO DO: find out why it freezes and fix properly */
1875 rec_command(RECORDING_CMD_STOP);
1876 audio_close_recording();
1877 #endif
1879 audio_error_clear();
1881 while(1)
1883 if (action_userabort(TIMEOUT_NOBLOCK))
1884 break;
1888 rec_abort:
1890 #if CONFIG_CODEC == SWCODEC
1891 rec_command(RECORDING_CMD_STOP);
1892 audio_close_recording();
1894 #ifdef HAVE_FMRADIO_REC
1895 if (radio_status != FMRADIO_OFF)
1896 /* Restore radio playback - radio_status should be unchanged if started
1897 through fm radio screen (barring usb connect) */
1898 rec_set_source(AUDIO_SRC_FMRADIO, (radio_status & FMRADIO_PAUSED) ?
1899 SRCF_FMRADIO_PAUSED : SRCF_FMRADIO_PLAYING);
1900 else
1901 #endif
1902 /* Go back to playback mode */
1903 rec_set_source(AUDIO_SRC_PLAYBACK, SRCF_PLAYBACK);
1905 /* restore talking */
1906 talk_disable(false);
1907 #else /* !SWCODEC */
1908 audio_init_playback();
1909 #endif /* CONFIG_CODEC == SWCODEC */
1911 /* make sure the trigger is really turned off */
1912 peak_meter_trigger(false);
1913 peak_meter_set_trigger_listener(NULL);
1915 rec_status &= ~RCSTAT_IN_RECSCREEN;
1916 sound_settings_apply();
1918 FOR_NB_SCREENS(i)
1919 screens[i].setfont(FONT_UI);
1921 viewportmanager_set_statusbar(oldbars);
1922 send_event(GUI_EVENT_REFRESH, NULL);
1924 /* if the directory was created or recording happened, make sure the
1925 browser is updated */
1926 if (rec_status & (RCSTAT_CREATED_DIRECTORY | RCSTAT_HAVE_RECORDED))
1927 reload_directory();
1929 #if (CONFIG_STORAGE & STORAGE_ATA) && (CONFIG_LED == LED_REAL) \
1930 && !defined(SIMULATOR)
1931 ata_set_led_enabled(true);
1932 #endif
1934 settings_save();
1936 return (rec_status & RCSTAT_BEEN_IN_USB_MODE) != 0;
1937 } /* recording_screen */
1939 #if CONFIG_KEYPAD == RECORDER_PAD
1940 static bool f2_rec_screen(void)
1942 static const char* const freq_str[6] =
1944 "44.1kHz",
1945 "48kHz",
1946 "32kHz",
1947 "22.05kHz",
1948 "24kHz",
1949 "16kHz"
1952 bool exit = false;
1953 bool used = false;
1954 int w, h, i;
1955 char buf[32];
1956 int button;
1957 struct audio_recording_options rec_options;
1959 FOR_NB_SCREENS(i)
1961 screens[i].setfont(FONT_SYSFIXED);
1962 screens[i].getstringsize("A",&w,&h);
1965 while (!exit) {
1966 const char* ptr;
1968 FOR_NB_SCREENS(i)
1970 screens[i].clear_display();
1972 /* Recording quality */
1973 screens[i].putsxy(0, LCD_HEIGHT/2 - h*2,
1974 str(LANG_SYSFONT_RECORDING_QUALITY));
1977 snprintf(buf, sizeof(buf), "%d", global_settings.rec_quality);
1978 FOR_NB_SCREENS(i)
1980 screens[i].putsxy(0, LCD_HEIGHT/2-h, buf);
1981 screens[i].mono_bitmap(bitmap_icons_7x8[Icon_FastBackward],
1982 LCD_WIDTH/2 - 16, LCD_HEIGHT/2 - 4, 7, 8);
1985 /* Frequency */
1986 snprintf(buf, sizeof buf, "%s:", str(LANG_SYSFONT_RECORDING_FREQUENCY));
1987 ptr = freq_str[global_settings.rec_frequency];
1988 FOR_NB_SCREENS(i)
1990 screens[i].getstringsize(buf,&w,&h);
1991 screens[i].putsxy((LCD_WIDTH-w)/2, LCD_HEIGHT - h*2, buf);
1992 screens[i].getstringsize(ptr, &w, &h);
1993 screens[i].putsxy((LCD_WIDTH-w)/2, LCD_HEIGHT - h, ptr);
1994 screens[i].mono_bitmap(bitmap_icons_7x8[Icon_DownArrow],
1995 LCD_WIDTH/2 - 3, LCD_HEIGHT - h*3, 7, 8);
1998 /* Channel mode */
1999 switch ( global_settings.rec_channels ) {
2000 case 0:
2001 ptr = str(LANG_SYSFONT_CHANNEL_STEREO);
2002 break;
2004 case 1:
2005 ptr = str(LANG_SYSFONT_CHANNEL_MONO);
2006 break;
2009 FOR_NB_SCREENS(i)
2011 screens[i].getstringsize(str(LANG_SYSFONT_CHANNELS), &w, &h);
2012 screens[i].putsxy(LCD_WIDTH - w, LCD_HEIGHT/2 - h*2,
2013 str(LANG_SYSFONT_CHANNELS));
2014 screens[i].getstringsize(str(LANG_SYSFONT_MODE), &w, &h);
2015 screens[i].putsxy(LCD_WIDTH - w, LCD_HEIGHT/2 - h,
2016 str(LANG_SYSFONT_MODE));
2017 screens[i].getstringsize(ptr, &w, &h);
2018 screens[i].putsxy(LCD_WIDTH - w, LCD_HEIGHT/2, ptr);
2019 screens[i].mono_bitmap(bitmap_icons_7x8[Icon_FastForward],
2020 LCD_WIDTH/2 + 8, LCD_HEIGHT/2 - 4, 7, 8);
2022 screens[i].update();
2025 button = button_get(true);
2026 switch (button) {
2027 case BUTTON_LEFT:
2028 case BUTTON_F2 | BUTTON_LEFT:
2029 global_settings.rec_quality++;
2030 if(global_settings.rec_quality > 7)
2031 global_settings.rec_quality = 0;
2032 used = true;
2033 break;
2035 case BUTTON_DOWN:
2036 case BUTTON_F2 | BUTTON_DOWN:
2037 global_settings.rec_frequency++;
2038 if(global_settings.rec_frequency > 5)
2039 global_settings.rec_frequency = 0;
2040 used = true;
2041 break;
2043 case BUTTON_RIGHT:
2044 case BUTTON_F2 | BUTTON_RIGHT:
2045 global_settings.rec_channels++;
2046 if(global_settings.rec_channels > 1)
2047 global_settings.rec_channels = 0;
2048 used = true;
2049 break;
2051 case BUTTON_F2 | BUTTON_REL:
2052 if ( used )
2053 exit = true;
2054 used = true;
2055 break;
2057 case BUTTON_F2 | BUTTON_REPEAT:
2058 used = true;
2059 break;
2061 default:
2062 if(default_event_handler(button) == SYS_USB_CONNECTED)
2063 return true;
2064 break;
2068 rec_init_recording_options(&rec_options);
2069 rec_set_recording_options(&rec_options);
2071 set_gain();
2073 settings_save();
2074 FOR_NB_SCREENS(i)
2075 screens[i].setfont(FONT_UI);
2077 return false;
2080 static bool f3_rec_screen(void)
2082 bool exit = false;
2083 bool used = false;
2084 int w, h, i;
2085 int button;
2086 const char *src_str[] =
2088 str(LANG_SYSFONT_RECORDING_SRC_MIC),
2089 str(LANG_SYSFONT_LINE_IN),
2090 str(LANG_SYSFONT_RECORDING_SRC_DIGITAL)
2092 struct audio_recording_options rec_options;
2094 FOR_NB_SCREENS(i)
2096 screens[i].setfont(FONT_SYSFIXED);
2097 screens[i].getstringsize("A",&w,&h);
2100 while (!exit) {
2101 const char* ptr = src_str[global_settings.rec_source];
2102 FOR_NB_SCREENS(i)
2104 screens[i].clear_display();
2106 /* Recording source */
2107 screens[i].putsxy(0, LCD_HEIGHT/2 - h*2,
2108 str(LANG_SYSFONT_RECORDING_SOURCE));
2110 screens[i].getstringsize(ptr, &w, &h);
2111 screens[i].putsxy(0, LCD_HEIGHT/2-h, ptr);
2112 screens[i].mono_bitmap(bitmap_icons_7x8[Icon_FastBackward],
2113 LCD_WIDTH/2 - 16, LCD_HEIGHT/2 - 4, 7, 8);
2116 /* trigger setup */
2117 ptr = str(LANG_SYSFONT_RECORD_TRIGGER);
2118 FOR_NB_SCREENS(i)
2120 screens[i].getstringsize(ptr,&w,&h);
2121 screens[i].putsxy((LCD_WIDTH-w)/2, LCD_HEIGHT - h*2, ptr);
2122 screens[i].mono_bitmap(bitmap_icons_7x8[Icon_DownArrow],
2123 LCD_WIDTH/2 - 3, LCD_HEIGHT - h*3, 7, 8);
2125 screens[i].update();
2128 button = button_get(true);
2129 switch (button) {
2130 case BUTTON_DOWN:
2131 case BUTTON_F3 | BUTTON_DOWN:
2132 #ifndef SIMULATOR
2133 rectrigger();
2134 settings_apply_trigger();
2135 #endif
2136 exit = true;
2137 break;
2139 case BUTTON_LEFT:
2140 case BUTTON_F3 | BUTTON_LEFT:
2141 global_settings.rec_source++;
2142 if(global_settings.rec_source > AUDIO_SRC_MAX)
2143 global_settings.rec_source = 0;
2144 used = true;
2145 break;
2147 case BUTTON_F3 | BUTTON_REL:
2148 if ( used )
2149 exit = true;
2150 used = true;
2151 break;
2153 case BUTTON_F3 | BUTTON_REPEAT:
2154 used = true;
2155 break;
2157 default:
2158 if(default_event_handler(button) == SYS_USB_CONNECTED)
2159 return true;
2160 break;
2164 rec_init_recording_options(&rec_options);
2165 rec_set_recording_options(&rec_options);
2167 set_gain();
2169 settings_save();
2170 FOR_NB_SCREENS(i)
2171 screens[i].setfont(FONT_UI);
2173 return false;
2175 #endif /* CONFIG_KEYPAD == RECORDER_PAD */
2177 #if CONFIG_CODEC == SWCODEC
2178 void audio_beep(int duration)
2180 /* dummy */
2181 (void)duration;
2184 #ifdef SIMULATOR
2185 /* stubs for recording sim */
2186 void audio_init_recording(unsigned int buffer_offset)
2188 buffer_offset = buffer_offset;
2191 void audio_close_recording(void)
2195 unsigned long pcm_rec_get_warnings(void)
2197 return 0;
2200 unsigned long pcm_rec_sample_rate(void)
2202 return 0;
2205 unsigned long audio_recorded_time(void)
2207 return 123;
2210 unsigned long audio_num_recorded_bytes(void)
2212 return 5 * 1024 * 1024;
2215 void rec_set_source(int source, unsigned flags)
2217 source = source;
2218 flags = flags;
2221 void audio_set_recording_options(struct audio_recording_options *options)
2223 options = options;
2226 void audio_set_recording_gain(int left, int right, int type)
2228 left = left;
2229 right = right;
2230 type = type;
2233 void audio_record(const char *filename)
2235 filename = filename;
2238 void audio_new_file(const char *filename)
2240 filename = filename;
2243 void audio_stop_recording(void)
2247 void audio_pause_recording(void)
2251 void audio_resume_recording(void)
2255 #endif /* #ifdef SIMULATOR */
2256 #endif /* #ifdef CONFIG_CODEC == SWCODEC */
2258 #endif /* HAVE_RECORDING */