User definable UI viewport, to be able to restrict the UI into a viewport for all...
[kugel-rb/myfork.git] / apps / recorder / recording.c
blob2716d932b5a5bc7a757d29b45c76bce422f20490
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 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 strlcpy(buffer, str(LANG_RECORDING_FILENAME), buffer_len);
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 static const unsigned char *byte_units[] = {
1039 ID2P(LANG_BYTE),
1040 ID2P(LANG_KILOBYTE),
1041 ID2P(LANG_MEGABYTE),
1042 ID2P(LANG_GIGABYTE)
1045 struct audio_recording_options rec_options;
1046 rec_status = RCSTAT_IN_RECSCREEN;
1048 #if (CONFIG_STORAGE & STORAGE_ATA) && (CONFIG_LED == LED_REAL) \
1049 && !defined(SIMULATOR)
1050 ata_set_led_enabled(false);
1051 #endif
1053 #if CONFIG_CODEC == SWCODEC
1054 /* recording_menu gets messed up: so prevent manus talking */
1055 talk_disable(true);
1056 /* audio_init_recording stops anything playing when it takes the audio
1057 buffer */
1058 #else
1059 /* Yes, we use the D/A for monitoring */
1060 peak_meter_enabled = true;
1061 peak_meter_playback(true);
1062 #endif
1064 #ifdef HAVE_AGC
1065 peak_meter_get_peakhold(&peak_l, &peak_r);
1066 #endif
1068 pm_reset_clipcount();
1069 pm_activate_clipcount(false);
1070 settings_apply_trigger();
1072 #ifdef HAVE_AGC
1073 agc_preset_str[0] = str(LANG_OFF);
1074 agc_preset_str[1] = str(LANG_AGC_SAFETY);
1075 agc_preset_str[2] = str(LANG_AGC_LIVE);
1076 agc_preset_str[3] = str(LANG_AGC_DJSET);
1077 agc_preset_str[4] = str(LANG_AGC_MEDIUM);
1078 agc_preset_str[5] = str(LANG_AGC_VOICE);
1079 #endif /* HAVE_AGC */
1081 #if CONFIG_CODEC == SWCODEC
1082 audio_close_recording();
1083 #endif
1084 audio_init_recording(0);
1085 sound_set_volume(global_settings.volume);
1087 #if CONFIG_RTC == 0
1088 /* Create new filename for recording start */
1089 rec_init_filename();
1090 #endif
1092 /* viewport init and calculations that only needs to be done once */
1093 FOR_NB_SCREENS(i)
1094 recbars |= VP_SB_IGNORE_SETTING(i);
1095 oldbars = viewportmanager_set_statusbar(recbars);
1096 FOR_NB_SCREENS(i)
1098 struct viewport *v;
1099 /* top vp, 4 lines, force sys font if total screen < 6 lines
1100 NOTE: one could limit the list to 1 line and get away with 5 lines */
1101 v = &vp_top[i];
1102 viewport_set_defaults(v, i);
1103 if (viewport_get_nb_lines(v) < 4)
1105 /* compact needs 4 lines total */
1106 v->font = FONT_SYSFIXED;
1107 compact_view[i] = false;
1109 else
1111 if (viewport_get_nb_lines(v) < (4+2)) /*top=4,list=2*/
1112 compact_view[i] = true;
1113 else
1114 compact_view[i] = false;
1116 vp_list[i] = *v; /* get a copy now so it can be sized more easily */
1117 v->height = (font_get(v->font)->height)*(compact_view[i] ? 3 : 4);
1119 /* list section, rest of the screen */
1120 vp_list[i].y += vp_top[i].height;
1121 vp_list[i].height -= vp_top[i].height;
1122 screens[i].set_viewport(&vp_top[i]); /* req for next calls */
1124 screens[i].getstringsize("W", &w, &h);
1125 pm_y[i] = font_get(vp_top[i].font)->height * 2;
1126 trig_ypos[i] = font_get(vp_top[i].font)->height * 3;
1127 if(compact_view[i])
1128 trig_ypos[i] -= (font_get(vp_top[i].font)->height)/2;
1131 /* init the bottom list */
1132 gui_synclist_init(&lists, reclist_get_name, NULL, false, 1, vp_list);
1133 gui_synclist_set_title(&lists, NULL, Icon_NOICON);
1135 /* start of the loop: we stay in this loop until user quits recscreen */
1136 while(done <= 0)
1138 if(done < 0)
1140 /* request to re-init stuff, done after settings screen */
1141 done = 0;
1142 #ifdef HAVE_FMRADIO_REC
1143 /* If input changes away from FM Radio,
1144 radio will remain off when recording screen closes. */
1145 if (global_settings.rec_source != prev_rec_source
1146 && prev_rec_source == AUDIO_SRC_FMRADIO)
1147 radio_status = FMRADIO_OFF;
1148 prev_rec_source = global_settings.rec_source;
1149 #endif
1151 FOR_NB_SCREENS(i)
1153 pm_x[i] = 0;
1154 if(global_settings.peak_meter_clipcounter)
1156 int clipwidth = 0;
1157 screens[i].getstringsize(str(LANG_PM_CLIPCOUNT),
1158 &clipwidth, &h); /* h is same */
1159 pm_x[i] = clipwidth+1;
1161 if(global_settings.rec_trigger_mode == TRIG_MODE_OFF)
1162 pm_h[i] = font_get(vp_top[i].font)->height * 2;
1163 else
1164 pm_h[i] = font_get(vp_top[i].font)->height;
1165 if(compact_view[i])
1166 pm_h[i] /= 2;
1167 trig_width[i] = vp_top[i].width - pm_x[i];
1170 #if CONFIG_CODEC == SWCODEC
1171 audio_close_recording();
1172 audio_init_recording(0);
1173 #endif
1175 rec_init_recording_options(&rec_options);
1176 rec_set_recording_options(&rec_options);
1178 if(rec_create_directory() < 0)
1180 rec_status = 0;
1181 goto rec_abort;
1184 #if CONFIG_CODEC == SWCODEC && CONFIG_RTC == 0
1185 /* If format changed, a new number is required */
1186 rec_init_filename();
1187 #endif
1189 #ifdef HAVE_AGC
1190 #ifdef HAVE_MIC_REC
1191 if (global_settings.rec_source == AUDIO_SRC_MIC) {
1192 agc_preset = global_settings.rec_agc_preset_mic;
1193 agc_maxgain = global_settings.rec_agc_maxgain_mic;
1195 else
1196 #endif /* MIC */
1198 agc_preset = global_settings.rec_agc_preset_line;
1199 agc_maxgain = global_settings.rec_agc_maxgain_line;
1201 #endif /* HAVE_AGC */
1203 set_gain();
1204 update_countdown = 0; /* Update immediately */
1206 /* populate translation table for list id -> enum */
1207 #ifdef HAVE_SPDIF_REC
1208 if(global_settings.rec_source == AUDIO_SRC_SPDIF)
1210 listid_to_enum[0] = ITEM_VOLUME_D;
1211 #if CONFIG_CODEC == SWCODEC
1212 listid_to_enum[1] = ITEM_SAMPLERATE_D;
1213 listid_to_enum[2] = ITEM_FILENAME_D;
1214 #else
1215 listid_to_enum[1] = ITEM_FILENAME_D;
1216 #endif
1218 gui_synclist_set_nb_items(&lists, ITEM_COUNT_D); /* spdif */
1220 else
1221 #endif
1222 if(HAVE_MIC_REC_((global_settings.rec_source == AUDIO_SRC_MIC) || )
1223 (global_settings.rec_channels == 1))
1225 listid_to_enum[0] = ITEM_VOLUME_M;
1226 listid_to_enum[1] = ITEM_GAIN_M;
1227 #ifdef HAVE_AGC
1228 listid_to_enum[2] = ITEM_AGC_MODE_M;
1229 listid_to_enum[3] = ITEM_AGC_MAXDB_M;
1230 listid_to_enum[4] = ITEM_FILENAME_M;
1231 #else
1232 listid_to_enum[2] = ITEM_FILENAME_M;
1233 #endif
1234 gui_synclist_set_nb_items(&lists, ITEM_COUNT_M); /* mono */
1236 else
1238 listid_to_enum[0] = ITEM_VOLUME;
1239 listid_to_enum[1] = ITEM_GAIN;
1240 listid_to_enum[2] = ITEM_GAIN_L;
1241 listid_to_enum[3] = ITEM_GAIN_R;
1242 #ifdef HAVE_AGC
1243 listid_to_enum[4] = ITEM_AGC_MODE;
1244 listid_to_enum[5] = ITEM_AGC_MAXDB;
1245 listid_to_enum[6] = ITEM_FILENAME;
1246 #else
1247 listid_to_enum[4] = ITEM_FILENAME;
1248 #endif
1249 gui_synclist_set_nb_items(&lists, ITEM_COUNT); /* stereo */
1252 gui_synclist_draw(&lists);
1253 } /* if(done < 0) */
1255 audio_stat = audio_status();
1257 #if (CONFIG_LED == LED_REAL)
1260 * Flash the LED while waiting to record. Turn it on while
1261 * recording.
1263 if(audio_stat & AUDIO_STATUS_RECORD)
1265 if (audio_stat & AUDIO_STATUS_PAUSE)
1267 if (--led_countdown <= 0)
1269 led_state = !led_state;
1270 led(led_state);
1271 led_countdown = 2;
1274 else
1276 /* trigger is on in status TRIG_READY (no check needed) */
1277 led(true);
1280 else
1282 int trig_stat = peak_meter_trigger_status();
1284 * other trigger stati than trig_off and trig_steady
1285 * already imply that we are recording.
1287 if (trig_stat == TRIG_STEADY)
1289 if (--led_countdown <= 0)
1291 led_state = !led_state;
1292 led(led_state);
1293 led_countdown = 2;
1296 else
1298 /* trigger is on in status TRIG_READY (no check needed) */
1299 led(false);
1302 #endif /* CONFIG_LED */
1304 /* Wait for a button a while (HZ/10) drawing the peak meter */
1305 button = peak_meter_draw_get_btn(CONTEXT_RECSCREEN,
1306 pm_x, pm_y, pm_h,
1307 screen_update, vp_top);
1308 if (last_audio_stat != audio_stat)
1310 if (audio_stat & AUDIO_STATUS_RECORD)
1312 rec_status |= RCSTAT_HAVE_RECORDED;
1314 last_audio_stat = audio_stat;
1315 update_list = true;
1318 if (recording_start_automatic)
1320 /* simulate a button press */
1321 button = ACTION_REC_PAUSE;
1322 recording_start_automatic = false;
1325 /* let list handle the button */
1326 gui_synclist_do_button(&lists, &button, LIST_WRAP_UNLESS_HELD);
1329 switch(button)
1331 case ACTION_SETTINGS_INC:
1332 case ACTION_SETTINGS_INCREPEAT:
1333 switch (listid_to_enum[gui_synclist_get_sel_pos(&lists)])
1335 case ITEM_VOLUME:
1336 global_settings.volume++;
1337 setvol();
1338 break;
1339 case ITEM_GAIN:
1340 #ifdef HAVE_MIC_REC
1341 if(global_settings.rec_source == AUDIO_SRC_MIC)
1343 if(global_settings.rec_mic_gain <
1344 sound_max(SOUND_MIC_GAIN))
1345 global_settings.rec_mic_gain++;
1347 else
1348 #endif /* MIC */
1350 if(global_settings.rec_left_gain <
1351 sound_max(SOUND_LEFT_GAIN))
1352 global_settings.rec_left_gain++;
1353 if(global_settings.rec_right_gain <
1354 sound_max(SOUND_RIGHT_GAIN))
1355 global_settings.rec_right_gain++;
1357 break;
1358 case ITEM_GAIN_L:
1359 if(global_settings.rec_left_gain <
1360 sound_max(SOUND_LEFT_GAIN))
1361 global_settings.rec_left_gain++;
1362 break;
1363 case ITEM_GAIN_R:
1364 if(global_settings.rec_right_gain <
1365 sound_max(SOUND_RIGHT_GAIN))
1366 global_settings.rec_right_gain++;
1367 break;
1368 #ifdef HAVE_AGC
1369 case ITEM_AGC_MODE:
1370 agc_preset = MIN(agc_preset + 1, AGC_MODE_SIZE);
1371 agc_enable = (agc_preset != 0);
1372 #ifdef HAVE_MIC_REC
1373 if (global_settings.rec_source == AUDIO_SRC_MIC) {
1374 global_settings.rec_agc_preset_mic = agc_preset;
1375 agc_maxgain = global_settings.rec_agc_maxgain_mic;
1376 } else
1377 #endif /* MIC */
1379 global_settings.rec_agc_preset_line = agc_preset;
1380 agc_maxgain = global_settings.rec_agc_maxgain_line;
1382 break;
1383 case ITEM_AGC_MAXDB:
1384 #ifdef HAVE_MIC_REC
1385 if (global_settings.rec_source == AUDIO_SRC_MIC)
1387 agc_maxgain = MIN(agc_maxgain + 1,
1388 sound_max(SOUND_MIC_GAIN));
1389 global_settings.rec_agc_maxgain_mic = agc_maxgain;
1391 else
1392 #endif /* MIC */
1394 agc_maxgain = MIN(agc_maxgain + 1,
1395 sound_max(SOUND_LEFT_GAIN));
1396 global_settings.rec_agc_maxgain_line = agc_maxgain;
1398 break;
1399 #endif /* HAVE_AGC */
1401 set_gain();
1402 update_countdown = 0; /* Update immediately */
1403 break;
1404 case ACTION_SETTINGS_DEC:
1405 case ACTION_SETTINGS_DECREPEAT:
1406 switch (listid_to_enum[gui_synclist_get_sel_pos(&lists)])
1408 case ITEM_VOLUME:
1409 global_settings.volume--;
1410 setvol();
1411 break;
1412 case ITEM_GAIN:
1413 #ifdef HAVE_MIC_REC
1414 if(global_settings.rec_source == AUDIO_SRC_MIC)
1416 if(global_settings.rec_mic_gain >
1417 sound_min(SOUND_MIC_GAIN))
1418 global_settings.rec_mic_gain--;
1420 else
1421 #endif /* MIC */
1423 if(global_settings.rec_left_gain >
1424 sound_min(SOUND_LEFT_GAIN))
1425 global_settings.rec_left_gain--;
1426 if(global_settings.rec_right_gain >
1427 sound_min(SOUND_RIGHT_GAIN))
1428 global_settings.rec_right_gain--;
1430 break;
1431 case ITEM_GAIN_L:
1432 if(global_settings.rec_left_gain >
1433 sound_min(SOUND_LEFT_GAIN))
1434 global_settings.rec_left_gain--;
1435 break;
1436 case ITEM_GAIN_R:
1437 if(global_settings.rec_right_gain >
1438 sound_min(SOUND_RIGHT_GAIN))
1439 global_settings.rec_right_gain--;
1440 break;
1441 #ifdef HAVE_AGC
1442 case ITEM_AGC_MODE:
1443 agc_preset = MAX(agc_preset - 1, 0);
1444 agc_enable = (agc_preset != 0);
1445 #ifdef HAVE_MIC_REC
1446 if (global_settings.rec_source == AUDIO_SRC_MIC) {
1447 global_settings.rec_agc_preset_mic = agc_preset;
1448 agc_maxgain = global_settings.rec_agc_maxgain_mic;
1449 } else
1450 #endif /* MIC */
1452 global_settings.rec_agc_preset_line = agc_preset;
1453 agc_maxgain = global_settings.rec_agc_maxgain_line;
1455 break;
1456 case ITEM_AGC_MAXDB:
1457 #ifdef HAVE_MIC_REC
1458 if (global_settings.rec_source == AUDIO_SRC_MIC)
1460 agc_maxgain = MAX(agc_maxgain - 1,
1461 sound_min(SOUND_MIC_GAIN));
1462 global_settings.rec_agc_maxgain_mic = agc_maxgain;
1463 } else
1464 #endif /* MIC */
1466 agc_maxgain = MAX(agc_maxgain - 1,
1467 sound_min(SOUND_LEFT_GAIN));
1468 global_settings.rec_agc_maxgain_line = agc_maxgain;
1470 break;
1471 #endif /* HAVE_AGC */
1473 set_gain();
1474 update_countdown = 0; /* Update immediately */
1475 break;
1476 case ACTION_STD_CANCEL:
1477 /* turn off the trigger */
1478 peak_meter_trigger(false);
1479 peak_meter_set_trigger_listener(NULL);
1481 if(audio_stat & AUDIO_STATUS_RECORD)
1483 rec_command(RECORDING_CMD_STOP);
1485 else
1487 #if CONFIG_CODEC != SWCODEC
1488 peak_meter_playback(true);
1489 peak_meter_enabled = false;
1490 #endif
1491 done = 1;
1493 update_countdown = 0; /* Update immediately */
1494 break;
1495 #ifdef HAVE_REMOTE_LCD
1496 case ACTION_REC_LCD:
1497 /* this feature exists for some h1x0/h3x0 targets that suffer
1498 from noise caused by remote LCD updates
1499 NOTE 1: this will leave the list on the remote
1500 NOTE 2: to be replaced by a global LCD_off() routine */
1501 if(remote_display_on)
1503 /* switch to single screen, leave message on remote */
1504 screen_update = 1;
1505 screens[1].clear_viewport();
1506 screens[1].puts(0, 0, str(LANG_REMOTE_LCD_OFF));
1507 screens[1].puts(0, 1, str(LANG_REMOTE_LCD_ON));
1508 screens[1].update_viewport();
1510 else
1512 /* remote switched on again */
1513 update_list = true;
1514 screen_update = NB_SCREENS;
1516 remote_display_on = !remote_display_on; /* toggle */
1517 update_countdown = 0; /* Update immediately */
1518 break;
1519 #endif
1520 case ACTION_REC_NEWFILE:
1522 /* Only act if in the middle of recording. */
1523 if(audio_stat & AUDIO_STATUS_RECORD)
1525 rec_command(RECORDING_CMD_START_NEWFILE);
1526 last_seconds = 0;
1528 break;
1530 case ACTION_REC_PAUSE:
1532 /* Only act if the mpeg is stopped */
1533 if(!(audio_stat & AUDIO_STATUS_RECORD))
1535 /* is this manual or triggered recording? */
1536 if ((global_settings.rec_trigger_mode == TRIG_MODE_OFF) ||
1537 (peak_meter_trigger_status() != TRIG_OFF))
1539 /* manual recording */
1540 rec_status |= RCSTAT_HAVE_RECORDED;
1541 rec_command(RECORDING_CMD_START);
1542 last_seconds = 0;
1543 if (global_settings.talk_menu)
1545 /* no voice possible here, but a beep */
1546 audio_beep(HZ/2); /* longer beep on start */
1549 /* this is triggered recording */
1550 else
1552 /* we don't start recording now, but enable the
1553 trigger and let the callback function
1554 trigger_listener control when the recording starts */
1555 peak_meter_trigger(true);
1556 peak_meter_set_trigger_listener(&trigger_listener);
1559 /* If we're in the middle of recording */
1560 else
1562 /* if pause button pressed, pause or resume */
1563 if(audio_stat & AUDIO_STATUS_PAUSE)
1565 rec_command(RECORDING_CMD_RESUME);
1566 if (global_settings.talk_menu)
1568 /* no voice possible here, but a beep */
1569 audio_beep(HZ/4); /* short beep on resume */
1572 else
1574 rec_command(RECORDING_CMD_PAUSE);
1577 update_countdown = 0; /* Update immediately */
1578 break;
1579 case ACTION_STD_MENU:
1580 #if CONFIG_CODEC == SWCODEC
1581 if(!(audio_stat & AUDIO_STATUS_RECORD))
1582 #else
1583 if(audio_stat != AUDIO_STATUS_RECORD)
1584 #endif
1586 #if (CONFIG_LED == LED_REAL)
1587 /* led is restored at begin of loop / end of function */
1588 led(false);
1589 #endif
1590 viewportmanager_set_statusbar(oldbars);
1591 if (recording_menu(no_source))
1593 done = 1;
1594 rec_status |= RCSTAT_BEEN_IN_USB_MODE;
1595 #ifdef HAVE_FMRADIO_REC
1596 radio_status = FMRADIO_OFF;
1597 #endif
1599 else
1601 done = -1;
1602 /* the init is now done at the beginning of the loop */
1604 viewportmanager_set_statusbar(recbars);
1606 break;
1608 #if CONFIG_KEYPAD == RECORDER_PAD
1609 case ACTION_REC_F2:
1610 if(audio_stat != AUDIO_STATUS_RECORD)
1612 #if (CONFIG_LED == LED_REAL)
1613 /* led is restored at begin of loop / end of function */
1614 led(false);
1615 #endif
1616 viewportmanager_set_statusbar(oldbars);
1617 if (f2_rec_screen())
1619 rec_status |= RCSTAT_HAVE_RECORDED;
1620 done = true;
1622 else
1623 update_countdown = 0; /* Update immediately */
1624 viewportmanager_set_statusbar(recbars);
1626 break;
1628 case ACTION_REC_F3:
1629 if(audio_stat & AUDIO_STATUS_RECORD)
1631 rec_command(RECORDING_CMD_START_NEWFILE);
1632 last_seconds = 0;
1634 else
1636 #if (CONFIG_LED == LED_REAL)
1637 /* led is restored at begin of loop / end of function */
1638 led(false);
1639 #endif
1640 viewportmanager_set_statusbar(oldbars);
1641 if (f3_rec_screen())
1643 rec_status |= RCSTAT_HAVE_RECORDED;
1644 done = true;
1646 else
1647 update_countdown = 0; /* Update immediately */
1648 viewportmanager_set_statusbar(recbars);
1650 break;
1651 #endif /* CONFIG_KEYPAD == RECORDER_PAD */
1653 case SYS_USB_CONNECTED:
1654 /* Only accept USB connection when not recording */
1655 if(!(audio_stat & AUDIO_STATUS_RECORD))
1657 FOR_NB_SCREENS(i)
1658 screens[i].set_viewport(NULL);
1659 default_event_handler(SYS_USB_CONNECTED);
1660 done = true;
1661 rec_status |= RCSTAT_BEEN_IN_USB_MODE;
1662 #ifdef HAVE_FMRADIO_REC
1663 radio_status = FMRADIO_OFF;
1664 #endif
1666 break;
1667 } /*switch(button)*/
1669 #ifdef HAVE_AGC
1670 peak_read = !peak_read;
1671 if (peak_read) { /* every 2nd run of loop */
1672 peak_time++;
1673 peak_valid = read_peak_levels(&peak_l, &peak_r, &balance);
1676 /* Handle AGC every 200ms when enabled and peak data is valid */
1677 if (peak_read && agc_enable && peak_valid)
1678 auto_gain_control(&peak_l, &peak_r, &balance);
1679 #endif
1681 seconds = audio_recorded_time() / HZ;
1683 /* start of vp_top drawing */
1684 if(update_countdown-- == 0 || seconds > last_seconds)
1686 unsigned int dseconds, dhours, dminutes;
1687 unsigned long num_recorded_bytes, dsize, dmb;
1690 FOR_NB_SCREENS(i)
1692 screens[i].set_viewport(&vp_top[i]);
1693 screens[i].clear_viewport();
1695 update_countdown = 5;
1696 last_seconds = seconds;
1698 dseconds = rec_timesplit_seconds();
1699 dsize = rec_sizesplit_bytes();
1700 num_recorded_bytes = audio_num_recorded_bytes();
1702 #if CONFIG_CODEC == SWCODEC
1703 if ((audio_stat & AUDIO_STATUS_WARNING)
1704 && (warning_counter++ % WARNING_PERIOD) < WARNING_PERIOD/2)
1706 /* Switch back and forth displaying warning on first available
1707 line to ensure visibility - the motion should also help
1708 draw attention */
1709 /* Don't use language string unless agreed upon to make this
1710 method permanent - could do something in the statusbar */
1711 snprintf(buf, sizeof(buf), "Warning: %08X",
1712 pcm_rec_get_warnings());
1714 else
1715 #endif /* CONFIG_CODEC == SWCODEC */
1716 if ((global_settings.rec_sizesplit) &&
1717 (global_settings.rec_split_method))
1719 dmb = dsize/1024/1024;
1720 snprintf(buf, sizeof(buf), "%s %dMB",
1721 str(LANG_SPLIT_SIZE), dmb);
1723 else
1725 hours = seconds / 3600;
1726 minutes = (seconds - (hours * 3600)) / 60;
1727 snprintf(buf, sizeof(buf), "%s %02d:%02d:%02d",
1728 str(LANG_RECORDING_TIME),
1729 hours, minutes, seconds%60);
1732 FOR_NB_ACTIVE_SCREENS(i)
1733 screens[i].puts(0, 0, buf);
1735 if(audio_stat & AUDIO_STATUS_PRERECORD)
1737 snprintf(buf, sizeof(buf), "%s...",
1738 str(LANG_RECORD_PRERECORD));
1740 else
1742 /* Display the split interval if the record timesplit
1743 is active */
1744 if ((global_settings.rec_timesplit) &&
1745 !(global_settings.rec_split_method))
1747 /* Display the record timesplit interval rather
1748 than the file size if the record timer is active */
1749 dhours = dseconds / 3600;
1750 dminutes = (dseconds - (dhours * 3600)) / 60;
1751 snprintf(buf, sizeof(buf), "%s %02d:%02d",
1752 str(LANG_RECORDING_TIMESPLIT_REC),
1753 dhours, dminutes);
1755 else
1757 output_dyn_value(buf2, sizeof buf2,
1758 num_recorded_bytes,
1759 byte_units, true);
1760 snprintf(buf, sizeof(buf), "%s %s",
1761 str(LANG_RECORDING_SIZE), buf2);
1765 FOR_NB_ACTIVE_SCREENS(i)
1766 screens[i].puts(0, 1, buf);
1768 /* We will do file splitting regardless, either at the end of
1769 a split interval, or when the filesize approaches the 2GB
1770 FAT file size (compatibility) limit. */
1771 if ((audio_stat && !(global_settings.rec_split_method)
1772 && global_settings.rec_timesplit && (seconds >= dseconds))
1773 || (audio_stat && global_settings.rec_split_method
1774 && global_settings.rec_sizesplit
1775 && (num_recorded_bytes >= dsize))
1776 || (num_recorded_bytes >= MAX_FILE_SIZE))
1778 if (!(global_settings.rec_split_type)
1779 || (num_recorded_bytes >= MAX_FILE_SIZE))
1781 rec_command(RECORDING_CMD_START_NEWFILE);
1782 last_seconds = 0;
1784 else
1786 peak_meter_trigger(false);
1787 peak_meter_set_trigger_listener(NULL);
1788 if( global_settings.rec_split_type == 1)
1789 rec_command(RECORDING_CMD_STOP);
1790 else
1791 rec_command(RECORDING_CMD_STOP_SHUTDOWN);
1793 update_countdown = 0;
1796 /* draw the clipcounter just in front of the peakmeter */
1797 if(global_settings.peak_meter_clipcounter)
1799 char clpstr[32];
1800 snprintf(clpstr, 32, "%4d", pm_get_clipcount());
1801 FOR_NB_ACTIVE_SCREENS(i)
1803 if(!compact_view[i])
1804 screens[i].puts(0, 2,str(LANG_PM_CLIPCOUNT));
1805 screens[i].puts(0, compact_view[i] ? 2 : 3, clpstr);
1809 #ifdef HAVE_AGC
1810 hist_time++;
1811 #endif
1813 /* draw the trigger status */
1814 if (peak_meter_trigger_status() != TRIG_OFF)
1816 peak_meter_draw_trig(pm_x, trig_ypos, trig_width,
1817 screen_update);
1818 FOR_NB_ACTIVE_SCREENS(i)
1819 screens[i].update_viewport_rect(pm_x[i], trig_ypos[i],
1820 trig_width[i] + 2, TRIG_HEIGHT);
1823 #ifdef HAVE_AGC
1824 #ifdef HAVE_MIC_REC
1825 if (global_settings.rec_source == AUDIO_SRC_MIC)
1827 if(agc_maxgain < (global_settings.rec_mic_gain))
1828 change_recording_gain(false, true, true);
1830 else
1831 #endif /* MIC */
1833 if(agc_maxgain < (global_settings.rec_left_gain))
1834 change_recording_gain(false, true, false);
1835 if(agc_maxgain < (global_settings.rec_right_gain))
1836 change_recording_gain(false, false, true);
1838 #endif /* HAVE_AGC */
1840 #if CONFIG_CODEC == SWCODEC
1841 #ifdef HAVE_SPDIF_REC
1842 if((global_settings.rec_source == AUDIO_SRC_SPDIF) &&
1843 (prev_sample_rate != pcm_rec_sample_rate()))
1845 /* spdif samplerate changed */
1846 prev_sample_rate = pcm_rec_sample_rate();
1847 update_list = true;
1849 #endif
1850 #endif
1852 if(update_list)
1854 /* update_list is set whenever content changes */
1855 update_list = false;
1856 gui_synclist_draw(&lists);
1859 /* draw peakmeter again (check if this can be removed) */
1860 FOR_NB_ACTIVE_SCREENS(i)
1862 screens[i].set_viewport(&vp_top[i]);
1863 peak_meter_screen(&screens[i], pm_x[i], pm_y[i], pm_h[i]);
1864 screens[i].update();
1866 } /* display update every second */
1868 if(audio_stat & AUDIO_STATUS_ERROR)
1870 done = true;
1872 } /* end while(!done) */
1874 audio_stat = audio_status();
1875 if (audio_stat & AUDIO_STATUS_ERROR)
1877 splash(0, str(LANG_DISK_FULL));
1879 FOR_NB_SCREENS(i)
1880 screens[i].update();
1882 #if CONFIG_CODEC == SWCODEC
1883 /* stop recording - some players like H10 freeze otherwise
1884 TO DO: find out why it freezes and fix properly */
1885 rec_command(RECORDING_CMD_STOP);
1886 audio_close_recording();
1887 #endif
1889 audio_error_clear();
1891 while(1)
1893 if (action_userabort(TIMEOUT_NOBLOCK))
1894 break;
1898 rec_abort:
1900 #if CONFIG_CODEC == SWCODEC
1901 rec_command(RECORDING_CMD_STOP);
1902 audio_close_recording();
1904 #ifdef HAVE_FMRADIO_REC
1905 if (radio_status != FMRADIO_OFF)
1906 /* Restore radio playback - radio_status should be unchanged if started
1907 through fm radio screen (barring usb connect) */
1908 rec_set_source(AUDIO_SRC_FMRADIO, (radio_status & FMRADIO_PAUSED) ?
1909 SRCF_FMRADIO_PAUSED : SRCF_FMRADIO_PLAYING);
1910 else
1911 #endif
1912 /* Go back to playback mode */
1913 rec_set_source(AUDIO_SRC_PLAYBACK, SRCF_PLAYBACK);
1915 /* restore talking */
1916 talk_disable(false);
1917 #else /* !SWCODEC */
1918 audio_init_playback();
1919 #endif /* CONFIG_CODEC == SWCODEC */
1921 /* make sure the trigger is really turned off */
1922 peak_meter_trigger(false);
1923 peak_meter_set_trigger_listener(NULL);
1925 rec_status &= ~RCSTAT_IN_RECSCREEN;
1926 sound_settings_apply();
1928 FOR_NB_SCREENS(i)
1929 screens[i].setfont(FONT_UI);
1931 viewportmanager_set_statusbar(oldbars);
1932 send_event(GUI_EVENT_REFRESH, NULL);
1934 /* if the directory was created or recording happened, make sure the
1935 browser is updated */
1936 if (rec_status & (RCSTAT_CREATED_DIRECTORY | RCSTAT_HAVE_RECORDED))
1937 reload_directory();
1939 #if (CONFIG_STORAGE & STORAGE_ATA) && (CONFIG_LED == LED_REAL) \
1940 && !defined(SIMULATOR)
1941 ata_set_led_enabled(true);
1942 #endif
1944 settings_save();
1946 return (rec_status & RCSTAT_BEEN_IN_USB_MODE) != 0;
1947 } /* recording_screen */
1949 #if CONFIG_KEYPAD == RECORDER_PAD
1950 static bool f2_rec_screen(void)
1952 static const char* const freq_str[6] =
1954 "44.1kHz",
1955 "48kHz",
1956 "32kHz",
1957 "22.05kHz",
1958 "24kHz",
1959 "16kHz"
1962 bool exit = false;
1963 bool used = false;
1964 int w, h, i;
1965 char buf[32];
1966 int button;
1967 struct audio_recording_options rec_options;
1969 FOR_NB_SCREENS(i)
1971 screens[i].setfont(FONT_SYSFIXED);
1972 screens[i].getstringsize("A",&w,&h);
1975 while (!exit) {
1976 const char* ptr=NULL;
1978 FOR_NB_SCREENS(i)
1980 screens[i].clear_display();
1982 /* Recording quality */
1983 screens[i].putsxy(0, LCD_HEIGHT/2 - h*2,
1984 str(LANG_SYSFONT_RECORDING_QUALITY));
1987 snprintf(buf, sizeof(buf), "%d", global_settings.rec_quality);
1988 FOR_NB_SCREENS(i)
1990 screens[i].putsxy(0, LCD_HEIGHT/2-h, buf);
1991 screens[i].mono_bitmap(bitmap_icons_7x8[Icon_FastBackward],
1992 LCD_WIDTH/2 - 16, LCD_HEIGHT/2 - 4, 7, 8);
1995 /* Frequency */
1996 snprintf(buf, sizeof buf, "%s:", str(LANG_SYSFONT_RECORDING_FREQUENCY));
1997 ptr = freq_str[global_settings.rec_frequency];
1998 FOR_NB_SCREENS(i)
2000 screens[i].getstringsize(buf,&w,&h);
2001 screens[i].putsxy((LCD_WIDTH-w)/2, LCD_HEIGHT - h*2, buf);
2002 screens[i].getstringsize(ptr, &w, &h);
2003 screens[i].putsxy((LCD_WIDTH-w)/2, LCD_HEIGHT - h, ptr);
2004 screens[i].mono_bitmap(bitmap_icons_7x8[Icon_DownArrow],
2005 LCD_WIDTH/2 - 3, LCD_HEIGHT - h*3, 7, 8);
2008 /* Channel mode */
2009 switch ( global_settings.rec_channels ) {
2010 case 0:
2011 ptr = str(LANG_SYSFONT_CHANNEL_STEREO);
2012 break;
2014 case 1:
2015 ptr = str(LANG_SYSFONT_CHANNEL_MONO);
2016 break;
2019 FOR_NB_SCREENS(i)
2021 screens[i].getstringsize(str(LANG_SYSFONT_CHANNELS), &w, &h);
2022 screens[i].putsxy(LCD_WIDTH - w, LCD_HEIGHT/2 - h*2,
2023 str(LANG_SYSFONT_CHANNELS));
2024 screens[i].getstringsize(str(LANG_SYSFONT_MODE), &w, &h);
2025 screens[i].putsxy(LCD_WIDTH - w, LCD_HEIGHT/2 - h,
2026 str(LANG_SYSFONT_MODE));
2027 screens[i].getstringsize(ptr, &w, &h);
2028 screens[i].putsxy(LCD_WIDTH - w, LCD_HEIGHT/2, ptr);
2029 screens[i].mono_bitmap(bitmap_icons_7x8[Icon_FastForward],
2030 LCD_WIDTH/2 + 8, LCD_HEIGHT/2 - 4, 7, 8);
2032 screens[i].update();
2035 button = button_get(true);
2036 switch (button) {
2037 case BUTTON_LEFT:
2038 case BUTTON_F2 | BUTTON_LEFT:
2039 global_settings.rec_quality++;
2040 if(global_settings.rec_quality > 7)
2041 global_settings.rec_quality = 0;
2042 used = true;
2043 break;
2045 case BUTTON_DOWN:
2046 case BUTTON_F2 | BUTTON_DOWN:
2047 global_settings.rec_frequency++;
2048 if(global_settings.rec_frequency > 5)
2049 global_settings.rec_frequency = 0;
2050 used = true;
2051 break;
2053 case BUTTON_RIGHT:
2054 case BUTTON_F2 | BUTTON_RIGHT:
2055 global_settings.rec_channels++;
2056 if(global_settings.rec_channels > 1)
2057 global_settings.rec_channels = 0;
2058 used = true;
2059 break;
2061 case BUTTON_F2 | BUTTON_REL:
2062 if ( used )
2063 exit = true;
2064 used = true;
2065 break;
2067 case BUTTON_F2 | BUTTON_REPEAT:
2068 used = true;
2069 break;
2071 default:
2072 if(default_event_handler(button) == SYS_USB_CONNECTED)
2073 return true;
2074 break;
2078 rec_init_recording_options(&rec_options);
2079 rec_set_recording_options(&rec_options);
2081 set_gain();
2083 settings_save();
2084 FOR_NB_SCREENS(i)
2085 screens[i].setfont(FONT_UI);
2087 return false;
2090 static bool f3_rec_screen(void)
2092 bool exit = false;
2093 bool used = false;
2094 int w, h, i;
2095 int button;
2096 char *src_str[] =
2098 str(LANG_SYSFONT_RECORDING_SRC_MIC),
2099 str(LANG_SYSFONT_LINE_IN),
2100 str(LANG_SYSFONT_RECORDING_SRC_DIGITAL)
2102 struct audio_recording_options rec_options;
2104 FOR_NB_SCREENS(i)
2106 screens[i].setfont(FONT_SYSFIXED);
2107 screens[i].getstringsize("A",&w,&h);
2110 while (!exit) {
2111 char* ptr=NULL;
2112 ptr = src_str[global_settings.rec_source];
2113 FOR_NB_SCREENS(i)
2115 screens[i].clear_display();
2117 /* Recording source */
2118 screens[i].putsxy(0, LCD_HEIGHT/2 - h*2,
2119 str(LANG_SYSFONT_RECORDING_SOURCE));
2121 screens[i].getstringsize(ptr, &w, &h);
2122 screens[i].putsxy(0, LCD_HEIGHT/2-h, ptr);
2123 screens[i].mono_bitmap(bitmap_icons_7x8[Icon_FastBackward],
2124 LCD_WIDTH/2 - 16, LCD_HEIGHT/2 - 4, 7, 8);
2127 /* trigger setup */
2128 ptr = str(LANG_SYSFONT_RECORD_TRIGGER);
2129 FOR_NB_SCREENS(i)
2131 screens[i].getstringsize(ptr,&w,&h);
2132 screens[i].putsxy((LCD_WIDTH-w)/2, LCD_HEIGHT - h*2, ptr);
2133 screens[i].mono_bitmap(bitmap_icons_7x8[Icon_DownArrow],
2134 LCD_WIDTH/2 - 3, LCD_HEIGHT - h*3, 7, 8);
2136 screens[i].update();
2139 button = button_get(true);
2140 switch (button) {
2141 case BUTTON_DOWN:
2142 case BUTTON_F3 | BUTTON_DOWN:
2143 #ifndef SIMULATOR
2144 rectrigger();
2145 settings_apply_trigger();
2146 #endif
2147 exit = true;
2148 break;
2150 case BUTTON_LEFT:
2151 case BUTTON_F3 | BUTTON_LEFT:
2152 global_settings.rec_source++;
2153 if(global_settings.rec_source > AUDIO_SRC_MAX)
2154 global_settings.rec_source = 0;
2155 used = true;
2156 break;
2158 case BUTTON_F3 | BUTTON_REL:
2159 if ( used )
2160 exit = true;
2161 used = true;
2162 break;
2164 case BUTTON_F3 | BUTTON_REPEAT:
2165 used = true;
2166 break;
2168 default:
2169 if(default_event_handler(button) == SYS_USB_CONNECTED)
2170 return true;
2171 break;
2175 rec_init_recording_options(&rec_options);
2176 rec_set_recording_options(&rec_options);
2178 set_gain();
2180 settings_save();
2181 FOR_NB_SCREENS(i)
2182 screens[i].setfont(FONT_UI);
2184 return false;
2186 #endif /* CONFIG_KEYPAD == RECORDER_PAD */
2188 #if CONFIG_CODEC == SWCODEC
2189 void audio_beep(int duration)
2191 /* dummy */
2192 (void)duration;
2195 #ifdef SIMULATOR
2196 /* stubs for recording sim */
2197 void audio_init_recording(unsigned int buffer_offset)
2199 buffer_offset = buffer_offset;
2202 void audio_close_recording(void)
2206 unsigned long pcm_rec_get_warnings(void)
2208 return 0;
2211 unsigned long pcm_rec_sample_rate(void)
2213 return 0;
2216 unsigned long audio_recorded_time(void)
2218 return 123;
2221 unsigned long audio_num_recorded_bytes(void)
2223 return 5 * 1024 * 1024;
2226 void rec_set_source(int source, unsigned flags)
2228 source = source;
2229 flags = flags;
2232 void audio_set_recording_options(struct audio_recording_options *options)
2234 options = options;
2237 void audio_set_recording_gain(int left, int right, int type)
2239 left = left;
2240 right = right;
2241 type = type;
2244 void audio_record(const char *filename)
2246 filename = filename;
2249 void audio_new_file(const char *filename)
2251 filename = filename;
2254 void audio_stop_recording(void)
2258 void audio_pause_recording(void)
2262 void audio_resume_recording(void)
2266 #endif /* #ifdef SIMULATOR */
2267 #endif /* #ifdef CONFIG_CODEC == SWCODEC */
2269 #endif /* HAVE_RECORDING */