FS#10406 - split the statusbar setting into one for each display, and allow the bar...
[kugel-rb.git] / apps / recorder / recording.c
blobd7ab9c795cc90d432ee1fc42043dbf841dc1dcb7
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"
80 #ifdef HAVE_RECORDING
81 /* This array holds the record timer interval lengths, in seconds */
82 static const unsigned long rec_timer_seconds[] =
84 0, /* 0 means OFF */
85 5*60, /* 00:05 */
86 10*60, /* 00:10 */
87 15*60, /* 00:15 */
88 30*60, /* 00:30 */
89 60*60, /* 01:00 */
90 74*60, /* 01:14 */
91 80*60, /* 01:20 */
92 2*60*60, /* 02:00 */
93 4*60*60, /* 04:00 */
94 6*60*60, /* 06:00 */
95 8*60*60, /* 08:00 */
96 10L*60*60, /* 10:00 */
97 12L*60*60, /* 12:00 */
98 18L*60*60, /* 18:00 */
99 24L*60*60 /* 24:00 */
102 static unsigned int rec_timesplit_seconds(void)
104 return rec_timer_seconds[global_settings.rec_timesplit];
107 /* This array holds the record size interval lengths, in bytes */
108 static const unsigned long rec_size_bytes[] =
110 0, /* 0 means OFF */
111 5*1024*1024, /* 5MB */
112 10*1024*1024, /* 10MB */
113 15*1024*1024, /* 15MB */
114 32*1024*1024, /* 32MB */
115 64*1024*1024, /* 64MB */
116 75*1024*1024, /* 75MB */
117 100*1024*1024, /* 100MB */
118 128*1024*1024, /* 128MB */
119 256*1024*1024, /* 256MB */
120 512*1024*1024, /* 512MB */
121 650*1024*1024, /* 650MB */
122 700*1024*1024, /* 700MB */
123 1024*1024*1024, /* 1GB */
124 1536*1024*1024, /* 1.5GB */
125 1792*1024*1024, /* 1.75GB */
128 static unsigned long rec_sizesplit_bytes(void)
130 return rec_size_bytes[global_settings.rec_sizesplit];
133 void settings_apply_trigger(void)
135 int start_thres, stop_thres;
136 if (global_settings.peak_meter_dbfs)
138 start_thres = global_settings.rec_start_thres_db - 1;
139 stop_thres = global_settings.rec_stop_thres_db - 1;
141 else
143 start_thres = global_settings.rec_start_thres_linear;
144 stop_thres = global_settings.rec_stop_thres_linear;
147 peak_meter_define_trigger(
148 start_thres,
149 global_settings.rec_start_duration*HZ,
150 MIN(global_settings.rec_start_duration*HZ / 2, 2*HZ),
151 stop_thres,
152 global_settings.rec_stop_postrec*HZ,
153 global_settings.rec_stop_gap*HZ
156 /* recording screen status flags */
157 enum rec_status_flags
159 RCSTAT_IN_RECSCREEN = 0x00000001,
160 RCSTAT_BEEN_IN_USB_MODE = 0x00000002,
161 RCSTAT_CREATED_DIRECTORY = 0x00000004,
162 RCSTAT_HAVE_RECORDED = 0x00000008,
165 static int rec_status = 0;
167 bool in_recording_screen(void)
169 return (rec_status & RCSTAT_IN_RECSCREEN) != 0;
172 #if CONFIG_KEYPAD == RECORDER_PAD
173 static bool f2_rec_screen(void);
174 static bool f3_rec_screen(void);
175 #endif
177 #define MAX_FILE_SIZE 0x7F800000 /* 2 GB - 4 MB */
179 #ifndef HAVE_REMOTE_LCD
180 static const int screen_update = NB_SCREENS;
181 #else
182 static int screen_update = NB_SCREENS;
183 static bool remote_display_on = true;
184 #endif
186 /* as we have the ability to disable the remote, we need an alternative loop */
187 #define FOR_NB_ACTIVE_SCREENS(i) for(i = 0; i < screen_update; i++)
189 static bool update_list = false; /* (GIU) list needs updating */
191 /** File name creation **/
192 #if CONFIG_RTC == 0
193 /* current file number to assist in creating unique numbered filenames
194 without actually having to create the file on disk */
195 static int file_number = -1;
196 #endif /* CONFIG_RTC */
198 #if CONFIG_CODEC == SWCODEC
200 #define REC_FILE_ENDING(rec_format) \
201 (audio_formats[rec_format_afmt[rec_format]].ext_list)
203 #else /* CONFIG_CODEC != SWCODEC */
205 /* default record file extension for HWCODEC */
206 #define REC_FILE_ENDING(rec_format) \
207 (audio_formats[AFMT_MPA_L3].ext_list)
209 #endif /* CONFIG_CODEC == SWCODEC */
211 /* path for current file */
212 static char path_buffer[MAX_PATH];
214 /** Automatic Gain Control (AGC) **/
215 #ifdef HAVE_AGC
216 /* Timing counters:
217 * peak_time is incremented every 0.2s, every 2nd run of record screen loop.
218 * hist_time is incremented every 0.5s, display update.
219 * peak_time is the counter of the peak hold read and agc process,
220 * overflow every 13 years 8-)
222 static long peak_time = 0;
223 static long hist_time = 0;
225 static short peak_valid_mem[4];
226 #define BAL_MEM_SIZE 24
227 static short balance_mem[BAL_MEM_SIZE];
229 /* Automatic Gain Control */
230 #define AGC_MODE_SIZE 5
231 #define AGC_SAFETY_MODE 0
233 static const char* agc_preset_str[] =
234 { "Off", "S", "L", "D", "M", "V" };
235 /* "Off",
236 "Safety (clip)",
237 "Live (slow)",
238 "DJ-Set (slow)",
239 "Medium",
240 "Voice (fast)" */
241 #define AGC_CLIP 32766
242 #define AGC_PEAK 29883 /* fast gain reduction threshold -0.8dB */
243 #define AGC_HIGH 27254 /* accelerated gain reduction threshold -1.6dB */
244 #define AGC_IMG 823 /* threshold for balance control -32dB */
245 /* autogain high level thresholds (-3dB, -7dB, -4dB, -5dB, -5dB) */
246 static const short agc_th_hi[AGC_MODE_SIZE] =
247 { 23197, 14637, 21156, 18428, 18426 };
248 /* autogain low level thresholds (-14dB, -11dB, -6dB, -7dB, -8dB) */
249 static const short agc_th_lo[AGC_MODE_SIZE] =
250 { 6538, 9235, 16422, 14636, 13045 };
251 /* autogain threshold times [1/5s] or [200ms] */
252 static const short agc_tdrop[AGC_MODE_SIZE] =
253 { 900, 225, 150, 60, 8 };
254 static const short agc_trise[AGC_MODE_SIZE] =
255 { 9000, 750, 400, 150, 20 };
256 static const short agc_tbal[AGC_MODE_SIZE] =
257 { 4500, 500, 300, 100, 15 };
258 /* AGC operation */
259 static bool agc_enable = true;
260 static short agc_preset;
261 /* AGC levels */
262 static int agc_left = 0;
263 static int agc_right = 0;
264 /* AGC time since high target volume was exceeded */
265 static short agc_droptime = 0;
266 /* AGC time since volume fallen below low target */
267 static short agc_risetime = 0;
268 /* AGC balance time exceeding +/- 0.7dB */
269 static short agc_baltime = 0;
270 /* AGC maximum gain */
271 static short agc_maxgain;
272 #endif /* HAVE_AGC */
274 static void set_gain(void)
276 #ifdef HAVE_MIC_REC
277 if(global_settings.rec_source == AUDIO_SRC_MIC)
279 audio_set_recording_gain(global_settings.rec_mic_gain,
280 0, AUDIO_GAIN_MIC);
282 else
283 #endif /* MIC */
285 /* AUDIO_SRC_LINEIN, AUDIO_SRC_FMRADIO, AUDIO_SRC_SPDIF */
286 audio_set_recording_gain(global_settings.rec_left_gain,
287 global_settings.rec_right_gain,
288 AUDIO_GAIN_LINEIN);
290 /* reset the clipping indicators */
291 peak_meter_set_clip_hold(global_settings.peak_meter_clip_hold);
292 update_list = true;
295 #ifdef HAVE_AGC
296 /* Read peak meter values & calculate balance.
297 * Returns validity of peak values.
298 * Used for automatic gain control and history diagram.
300 static bool read_peak_levels(int *peak_l, int *peak_r, int *balance)
302 peak_meter_get_peakhold(peak_l, peak_r);
303 peak_valid_mem[peak_time % 3] = *peak_l;
304 if (((peak_valid_mem[0] == peak_valid_mem[1]) &&
305 (peak_valid_mem[1] == peak_valid_mem[2])) &&
306 ((*peak_l < 32767) || storage_disk_is_active()))
307 return false;
309 if (*peak_r > *peak_l)
310 balance_mem[peak_time % BAL_MEM_SIZE] = (*peak_l ?
311 MIN((10000 * *peak_r) / *peak_l - 10000, 15118) : 15118);
312 else
313 balance_mem[peak_time % BAL_MEM_SIZE] = (*peak_r ?
314 MAX(10000 - (10000 * *peak_l) / *peak_r, -15118) : -15118);
315 *balance = 0;
316 int i;
317 for (i = 0; i < BAL_MEM_SIZE; i++)
318 *balance += balance_mem[i];
319 *balance = *balance / BAL_MEM_SIZE;
321 return true;
324 /* AGC helper function to check if maximum gain is reached */
325 static bool agc_gain_is_max(bool left, bool right)
327 /* range -128...+108 [0.5dB] */
328 short gain_current_l;
329 short gain_current_r;
331 if (agc_preset == 0)
332 return false;
334 switch (global_settings.rec_source)
336 #if defined(HAVE_LINE_REC) || defined(HAVE_FMRADIO_REC)
337 HAVE_LINE_REC_(case AUDIO_SRC_LINEIN:)
338 HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO:)
339 gain_current_l = global_settings.rec_left_gain;
340 gain_current_r = global_settings.rec_right_gain;
341 break;
342 #endif /* LINE, FMRADIO */
343 #if defined(HAVE_MIC_REC)
344 case AUDIO_SRC_MIC:
345 default:
346 gain_current_l = global_settings.rec_mic_gain;
347 gain_current_r = global_settings.rec_mic_gain;
348 #endif /* MIC */
351 return ((left && (gain_current_l >= agc_maxgain)) ||
352 (right && (gain_current_r >= agc_maxgain)));
355 static void change_recording_gain(bool increment, bool left, bool right)
357 int factor = (increment ? 1 : -1);
359 switch (global_settings.rec_source)
361 #if defined(HAVE_LINE_REC) || defined(HAVE_FMRADIO_REC)
362 HAVE_LINE_REC_(case AUDIO_SRC_LINEIN:)
363 HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO:)
364 if (left) global_settings.rec_left_gain += factor;
365 if (right) global_settings.rec_right_gain += factor;
366 break;
367 #endif /* LINE, FMRADIO */
368 #if defined(HAVE_MIC_REC)
369 case AUDIO_SRC_MIC:
370 global_settings.rec_mic_gain += factor;
371 #endif
376 * Handle automatic gain control (AGC).
377 * Change recording gain if peak_x levels are above or below
378 * target volume for specified timeouts.
380 static void auto_gain_control(int *peak_l, int *peak_r, int *balance)
382 int agc_mono;
383 short agc_mode;
384 bool increment;
386 if (*peak_l > agc_left)
387 agc_left = *peak_l;
388 else
389 agc_left -= (agc_left - *peak_l + 3) >> 2;
390 if (*peak_r > agc_right)
391 agc_right = *peak_r;
392 else
393 agc_right -= (agc_right - *peak_r + 3) >> 2;
394 agc_mono = (agc_left + agc_right) / 2;
396 agc_mode = abs(agc_preset) - 1;
397 if (agc_mode < 0) {
398 agc_enable = false;
399 return;
402 if (agc_mode != AGC_SAFETY_MODE) {
403 /* Automatic balance control - only if not in safety mode */
404 if ((agc_left > AGC_IMG) && (agc_right > AGC_IMG))
406 if (*balance < -556)
408 if (*balance > -900)
409 agc_baltime -= !(peak_time % 4); /* 0.47 - 0.75dB */
410 else if (*balance > -4125)
411 agc_baltime--; /* 0.75 - 3.00dB */
412 else if (*balance > -7579)
413 agc_baltime -= 2; /* 3.00 - 4.90dB */
414 else
415 agc_baltime -= !(peak_time % 8); /* 4.90 - inf dB */
416 if (agc_baltime > 0)
417 agc_baltime -= (peak_time % 2);
419 else if (*balance > 556)
421 if (*balance < 900)
422 agc_baltime += !(peak_time % 4);
423 else if (*balance < 4125)
424 agc_baltime++;
425 else if (*balance < 7579)
426 agc_baltime += 2;
427 else
428 agc_baltime += !(peak_time % 8);
429 if (agc_baltime < 0)
430 agc_baltime += (peak_time % 2);
433 if ((*balance * agc_baltime) < 0)
435 if (*balance < 0)
436 agc_baltime -= peak_time % 2;
437 else
438 agc_baltime += peak_time % 2;
441 increment = ((agc_risetime / 2) > agc_droptime);
443 if (agc_baltime < -agc_tbal[agc_mode])
445 if (!increment || !agc_gain_is_max(!increment, increment)) {
446 change_recording_gain(increment, !increment, increment);
447 set_gain();
449 agc_baltime = 0;
451 else if (agc_baltime > +agc_tbal[agc_mode])
453 if (!increment || !agc_gain_is_max(increment, !increment)) {
454 change_recording_gain(increment, increment, !increment);
455 set_gain();
457 agc_baltime = 0;
460 else if (!(hist_time % 4))
462 if (agc_baltime < 0)
463 agc_baltime++;
464 else
465 agc_baltime--;
469 /* Automatic gain control */
470 if ((agc_left > agc_th_hi[agc_mode]) || (agc_right > agc_th_hi[agc_mode]))
472 if ((agc_left > AGC_CLIP) || (agc_right > AGC_CLIP))
473 agc_droptime += agc_tdrop[agc_mode] /
474 (global_settings.rec_agc_cliptime + 1);
475 if (agc_left > AGC_HIGH) {
476 agc_droptime++;
477 agc_risetime=0;
478 if (agc_left > AGC_PEAK)
479 agc_droptime += 2;
481 if (agc_right > AGC_HIGH) {
482 agc_droptime++;
483 agc_risetime=0;
484 if (agc_right > AGC_PEAK)
485 agc_droptime += 2;
487 if (agc_mono > agc_th_hi[agc_mode])
488 agc_droptime++;
489 else
490 agc_droptime += !(peak_time % 2);
492 if (agc_droptime >= agc_tdrop[agc_mode])
494 change_recording_gain(false, true, true);
495 agc_droptime = 0;
496 agc_risetime = 0;
497 set_gain();
499 agc_risetime = MAX(agc_risetime - 1, 0);
501 else if (agc_mono < agc_th_lo[agc_mode])
503 if (agc_mono < (agc_th_lo[agc_mode] / 8))
504 agc_risetime += !(peak_time % 5);
505 else if (agc_mono < (agc_th_lo[agc_mode] / 2))
506 agc_risetime += 2;
507 else
508 agc_risetime++;
510 if (agc_risetime >= agc_trise[agc_mode]) {
511 if ((agc_mode != AGC_SAFETY_MODE) &&
512 (!agc_gain_is_max(true, true))) {
513 change_recording_gain(true, true, true);
514 set_gain();
516 agc_risetime = 0;
517 agc_droptime = 0;
519 agc_droptime = MAX(agc_droptime - 1, 0);
521 else if (!(peak_time % 6)) /* on target level every 1.2 sec */
523 agc_risetime = MAX(agc_risetime - 1, 0);
524 agc_droptime = MAX(agc_droptime - 1, 0);
527 #endif /* HAVE_AGC */
529 static const char* const fmtstr[] =
531 "%c%d %s", /* no decimals */
532 "%c%d.%d %s ", /* 1 decimal */
533 "%c%d.%02d %s " /* 2 decimals */
536 static char *fmt_gain(int snd, int val, char *str, int len)
538 int i, d, numdec;
539 const char *unit;
540 char sign = ' ';
542 val = sound_val2phys(snd, val);
543 if(val < 0)
545 sign = '-';
546 val = -val;
548 numdec = sound_numdecimals(snd);
549 unit = sound_unit(snd);
551 if(numdec)
553 i = val / (10*numdec);
554 d = val % (10*numdec);
555 snprintf(str, len, fmtstr[numdec], sign, i, d, unit);
557 else
558 snprintf(str, len, fmtstr[numdec], sign, val, unit);
560 return str;
563 /* the list below must match enum audio_sources in audio.h */
564 static const char* const prestr[] =
566 HAVE_MIC_IN_([AUDIO_SRC_MIC] = "R_MIC_",)
567 HAVE_LINE_REC_([AUDIO_SRC_LINEIN] = "R_LINE_",)
568 HAVE_SPDIF_IN_([AUDIO_SRC_SPDIF] = "R_SPDIF_",)
569 HAVE_FMRADIO_REC_([AUDIO_SRC_FMRADIO] = "R_FM_",)
572 char *rec_create_filename(char *buffer)
574 char ext[16];
575 const char *pref = "R_";
577 /* Directory existence and writeablility should have already been
578 * verified - do not pass NULL pointers to pcmrec */
580 if((unsigned)global_settings.rec_source < AUDIO_NUM_SOURCES)
582 pref = prestr[global_settings.rec_source];
585 strcpy(buffer, global_settings.rec_directory);
587 snprintf(ext, sizeof(ext), ".%s",
588 REC_FILE_ENDING(global_settings.rec_format));
590 #if CONFIG_RTC == 0
591 return create_numbered_filename(buffer, buffer, pref, ext, 4,
592 &file_number);
593 #else
594 /* We'll wait at least up to the start of the next second so no duplicate
595 names are created */
596 return create_datetime_filename(buffer, buffer, pref, ext, true);
597 #endif
600 #if CONFIG_RTC == 0
601 /* Hit disk to get a starting filename for the type */
602 static void rec_init_filename(void)
604 file_number = -1;
605 rec_create_filename(path_buffer);
606 file_number--;
608 #endif
610 int rec_create_directory(void)
612 int rc = 0;
613 const char * const folder = global_settings.rec_directory;
615 if (strcmp(folder, "/") && !dir_exists(folder))
617 rc = mkdir(folder);
619 if(rc < 0)
621 while (action_userabort(HZ) == false)
623 splashf(0, "%s %s",
624 str(LANG_REC_DIR_NOT_WRITABLE),
625 str(LANG_OFF_ABORT));
628 else
630 rec_status |= RCSTAT_CREATED_DIRECTORY;
631 rc = 1;
635 return rc;
638 void rec_init_recording_options(struct audio_recording_options *options)
640 options->rec_source = global_settings.rec_source;
641 options->rec_frequency = global_settings.rec_frequency;
642 options->rec_channels = global_settings.rec_channels;
643 options->rec_prerecord_time = global_settings.rec_prerecord_time;
644 #if CONFIG_CODEC == SWCODEC
645 options->rec_mono_mode = global_settings.rec_mono_mode;
646 options->rec_source_flags = 0;
647 options->enc_config.rec_format = global_settings.rec_format;
648 global_to_encoder_config(&options->enc_config);
649 #else
650 options->rec_quality = global_settings.rec_quality;
651 options->rec_editable = global_settings.rec_editable;
652 #endif
655 #if CONFIG_CODEC == SWCODEC && !defined (SIMULATOR)
656 void rec_set_source(int source, unsigned flags)
658 /* Set audio input source, power up/down devices */
659 audio_set_input_source(source, flags);
661 /* Set peakmeters for recording or reset to playback */
662 peak_meter_playback((flags & SRCF_RECORDING) == 0);
663 peak_meter_enabled = true;
665 #endif /* CONFIG_CODEC == SWCODEC && !defined (SIMULATOR) */
667 void rec_set_recording_options(struct audio_recording_options *options)
669 #if CONFIG_CODEC != SWCODEC
670 if (global_settings.rec_prerecord_time)
672 talk_buffer_steal(); /* will use the mp3 buffer */
674 #else /* == SWCODEC */
675 rec_set_source(options->rec_source,
676 options->rec_source_flags | SRCF_RECORDING);
677 #endif /* CONFIG_CODEC != SWCODEC */
679 audio_set_recording_options(options);
682 void rec_command(enum recording_command cmd)
684 switch(cmd)
686 case RECORDING_CMD_STOP_SHUTDOWN:
687 pm_activate_clipcount(false);
688 audio_stop_recording();
689 #if CONFIG_CODEC == SWCODEC
690 audio_close_recording();
691 #endif
692 sys_poweroff();
693 break;
694 case RECORDING_CMD_STOP:
695 pm_activate_clipcount(false);
696 audio_stop_recording();
697 break;
698 case RECORDING_CMD_START:
699 /* steal mp3 buffer, create unique filename and start recording */
700 pm_reset_clipcount();
701 pm_activate_clipcount(true);
702 #if CONFIG_CODEC != SWCODEC
703 talk_buffer_steal(); /* we use the mp3 buffer */
704 #endif
705 audio_record(rec_create_filename(path_buffer));
706 break;
707 case RECORDING_CMD_START_NEWFILE:
708 /* create unique filename and start recording*/
709 pm_reset_clipcount();
710 pm_activate_clipcount(true); /* just to be sure */
711 audio_new_file(rec_create_filename(path_buffer));
712 break;
713 case RECORDING_CMD_PAUSE:
714 pm_activate_clipcount(false);
715 audio_pause_recording();
716 break;
717 case RECORDING_CMD_RESUME:
718 pm_activate_clipcount(true);
719 audio_resume_recording();
720 break;
722 update_list = true;
725 /* used in trigger_listerner and recording_screen */
726 static unsigned int last_seconds = 0;
729 * Callback function so that the peak meter code can send an event
730 * to this application. This function can be passed to
731 * peak_meter_set_trigger_listener in order to activate the trigger.
733 static void trigger_listener(int trigger_status)
735 switch (trigger_status)
737 case TRIG_GO:
738 if(!(audio_status() & AUDIO_STATUS_RECORD))
740 rec_status |= RCSTAT_HAVE_RECORDED;
741 rec_command(RECORDING_CMD_START);
742 #if CONFIG_CODEC != SWCODEC
743 /* give control to mpeg thread so that it can start
744 recording */
745 yield(); yield(); yield();
746 #endif
749 /* if we're already recording this is a retrigger */
750 else
752 if((audio_status() & AUDIO_STATUS_PAUSE) &&
753 (global_settings.rec_trigger_type == TRIG_TYPE_PAUSE))
755 rec_command(RECORDING_CMD_RESUME);
757 /* New file on trig start*/
758 else if (global_settings.rec_trigger_type != TRIG_TYPE_NEW_FILE)
760 rec_command(RECORDING_CMD_START_NEWFILE);
761 /* tell recording_screen to reset the time */
762 last_seconds = 0;
765 break;
767 /* A _change_ to TRIG_READY means the current recording has stopped */
768 case TRIG_READY:
769 if(audio_status() & AUDIO_STATUS_RECORD)
771 switch(global_settings.rec_trigger_type)
773 case TRIG_TYPE_STOP: /* Stop */
774 rec_command(RECORDING_CMD_STOP);
775 break;
777 case TRIG_TYPE_PAUSE: /* Pause */
778 rec_command(RECORDING_CMD_PAUSE);
779 break;
781 case TRIG_TYPE_NEW_FILE: /* New file on trig stop*/
782 rec_command(RECORDING_CMD_START_NEWFILE);
783 /* tell recording_screen to reset the time */
784 last_seconds = 0;
785 break;
787 case 3: /* Stop and shutdown */
788 rec_command(RECORDING_CMD_STOP_SHUTDOWN);
789 break;
792 if (global_settings.rec_trigger_mode != TRIG_MODE_REARM)
794 peak_meter_set_trigger_listener(NULL);
795 peak_meter_trigger(false);
798 break;
802 /* Stuff for drawing the screen */
804 enum rec_list_items_stereo {
805 ITEM_VOLUME = 0,
806 ITEM_GAIN = 1,
807 ITEM_GAIN_L = 2,
808 ITEM_GAIN_R = 3,
809 #ifdef HAVE_AGC
810 ITEM_AGC_MODE = 4,
811 ITEM_AGC_MAXDB = 5,
812 ITEM_FILENAME = 7,
813 ITEM_COUNT = 7,
814 #else
815 ITEM_FILENAME = 7,
816 ITEM_COUNT = 5,
817 #endif
820 enum rec_list_items_mono {
821 ITEM_VOLUME_M = 0,
822 ITEM_GAIN_M = 1,
823 #ifdef HAVE_AGC
824 ITEM_AGC_MODE_M = 4,
825 ITEM_AGC_MAXDB_M = 5,
826 ITEM_FILENAME_M = 7,
827 ITEM_COUNT_M = 5,
828 #else
829 ITEM_FILENAME_M = 7,
830 ITEM_COUNT_M = 3,
831 #endif
834 #ifdef HAVE_SPDIF_REC
835 enum rec_list_items_spdif {
836 ITEM_VOLUME_D = 0,
837 #if CONFIG_CODEC == SWCODEC
838 ITEM_SAMPLERATE_D = 6,
839 ITEM_FILENAME_D = 7,
840 ITEM_COUNT_D = 3,
841 #else
842 ITEM_FILENAME_D = 7,
843 ITEM_COUNT_D = 2,
844 #endif
846 #endif
848 static int listid_to_enum[ITEM_COUNT];
850 static char * reclist_get_name(int selected_item, void * data,
851 char * buffer, size_t buffer_len)
853 char buf2[32];
854 #ifdef HAVE_AGC
855 char buf3[32];
856 #endif
857 data = data; /* not used */
858 if(selected_item >= ITEM_COUNT)
859 return "";
861 switch (listid_to_enum[selected_item])
863 case ITEM_VOLUME:
864 snprintf(buffer, buffer_len, "%s: %s", str(LANG_VOLUME),
865 fmt_gain(SOUND_VOLUME,
866 global_settings.volume,
867 buf2, sizeof(buf2)));
868 break;
869 case ITEM_GAIN:
870 #ifdef HAVE_MIC_REC
871 if(global_settings.rec_source == AUDIO_SRC_MIC)
873 /* Draw MIC recording gain */
874 snprintf(buffer, buffer_len, "%s: %s", str(LANG_GAIN),
875 fmt_gain(SOUND_MIC_GAIN,
876 global_settings.rec_mic_gain,
877 buf2, sizeof(buf2)));
879 else
880 #endif /* MIC */
882 int avg_gain = (global_settings.rec_left_gain +
883 global_settings.rec_right_gain) / 2;
884 snprintf(buffer, buffer_len, "%s: %s", str(LANG_GAIN),
885 fmt_gain(SOUND_LEFT_GAIN,
886 avg_gain,
887 buf2, sizeof(buf2)));
889 break;
890 case ITEM_GAIN_L:
891 snprintf(buffer, buffer_len, "%s: %s",
892 str(LANG_GAIN_LEFT),
893 fmt_gain(SOUND_LEFT_GAIN,
894 global_settings.rec_left_gain,
895 buf2, sizeof(buf2)));
896 break;
897 case ITEM_GAIN_R:
898 snprintf(buffer, buffer_len, "%s: %s",
899 str(LANG_GAIN_RIGHT),
900 fmt_gain(SOUND_RIGHT_GAIN,
901 global_settings.rec_right_gain,
902 buf2, sizeof(buf2)));
903 break;
904 #ifdef HAVE_AGC
905 case ITEM_AGC_MODE:
906 snprintf(buffer, buffer_len, "%s: %s",
907 str(LANG_RECORDING_AGC_PRESET),
908 agc_preset_str[agc_preset]);
909 break;
910 case ITEM_AGC_MAXDB:
911 if (agc_preset == 0)
912 snprintf(buffer, buffer_len, "%s: %s",
913 str(LANG_RECORDING_AGC_MAXGAIN),
914 fmt_gain(SOUND_LEFT_GAIN,
915 agc_maxgain, buf2, sizeof(buf2)));
916 #ifdef HAVE_MIC_REC
917 else if (global_settings.rec_source == AUDIO_SRC_MIC)
918 snprintf(buffer, buffer_len, "%s: %s (%s)",
919 str(LANG_RECORDING_AGC_MAXGAIN),
920 fmt_gain(SOUND_MIC_GAIN,
921 agc_maxgain, buf2, sizeof(buf2)),
922 fmt_gain(SOUND_MIC_GAIN,
923 agc_maxgain - global_settings.rec_mic_gain,
924 buf3, sizeof(buf3)));
925 else
926 #endif /* MIC */
927 snprintf(buffer, buffer_len, "%s: %s (%s)",
928 str(LANG_RECORDING_AGC_MAXGAIN),
929 fmt_gain(SOUND_LEFT_GAIN,
930 agc_maxgain, buf2, sizeof(buf2)),
931 fmt_gain(SOUND_LEFT_GAIN,
932 agc_maxgain -
933 (global_settings.rec_left_gain +
934 global_settings.rec_right_gain)/2,
935 buf3, sizeof(buf3)));
936 break;
937 #endif
938 #if CONFIG_CODEC == SWCODEC
939 #ifdef HAVE_SPDIF_REC
940 case ITEM_SAMPLERATE_D:
941 snprintf(buffer, buffer_len, "%s: %d",
942 str(LANG_RECORDING_FREQUENCY),
943 pcm_rec_sample_rate());
944 break;
945 #endif
946 #endif
947 case ITEM_FILENAME:
949 if(audio_status() & AUDIO_STATUS_RECORD)
951 size_t tot_len = strlen(path_buffer) +
952 strlen(str(LANG_RECORDING_FILENAME)) + 1;
953 if(tot_len > buffer_len)
955 snprintf(buffer, buffer_len, "%s %s",
956 str(LANG_RECORDING_FILENAME),
957 path_buffer + tot_len - buffer_len);
959 else
961 snprintf(buffer, buffer_len, "%s %s",
962 str(LANG_RECORDING_FILENAME), path_buffer);
965 else
967 strncpy(buffer, str(LANG_RECORDING_FILENAME), buffer_len);
969 break;
971 default:
972 return "";
974 return buffer;
978 bool recording_start_automatic = false;
980 bool recording_screen(bool no_source)
982 int button;
983 int done = -1; /* negative to re-init, positive to quit, zero to run */
984 char buf[32]; /* for preparing strings */
985 char buf2[32]; /* for preparing strings */
986 int w, h; /* character width/height */
987 int update_countdown = 0; /* refresh counter */
988 unsigned int seconds;
989 int hours, minutes;
990 int audio_stat = 0; /* status of the audio system */
991 int last_audio_stat = -1; /* previous status so we can act on changes */
992 struct viewport vp_list[NB_SCREENS], vp_top[NB_SCREENS]; /* the viewports */
994 #if CONFIG_CODEC == SWCODEC
995 int warning_counter = 0;
996 #define WARNING_PERIOD 7
997 #endif
999 #if CONFIG_CODEC == SWCODEC
1000 #ifdef HAVE_SPDIF_REC
1001 unsigned long prev_sample_rate = 0;
1002 #endif
1003 #endif
1005 #ifdef HAVE_FMRADIO_REC
1006 /* Radio is left on if:
1007 * 1) Is was on at the start and the initial source is FM Radio
1008 * 2) 1) and the source was never changed to something else
1010 int radio_status = (global_settings.rec_source != AUDIO_SRC_FMRADIO) ?
1011 FMRADIO_OFF : get_radio_status();
1012 #endif
1013 #if (CONFIG_LED == LED_REAL)
1014 bool led_state = false;
1015 int led_countdown = 2;
1016 #endif
1017 #ifdef HAVE_AGC
1018 bool peak_read = false;
1019 bool peak_valid = false;
1020 int peak_l, peak_r;
1021 int balance = 0;
1022 #endif
1023 int oldbars, recbars = VP_SB_ALLSCREENS;
1024 int i;
1025 int pm_x[NB_SCREENS]; /* peakmeter (and trigger bar) x pos */
1026 int pm_y[NB_SCREENS]; /* peakmeter y pos */
1027 int pm_h[NB_SCREENS]; /* peakmeter height */
1028 int trig_ypos[NB_SCREENS]; /* trigger bar y pos */
1029 int trig_width[NB_SCREENS]; /* trigger bar width */
1030 bool compact_view[NB_SCREENS]; /* tweak layout tiny screens / big fonts */
1032 struct gui_synclist lists; /* the list in the bottom vp */
1033 #ifdef HAVE_FMRADIO_REC
1034 int prev_rec_source = global_settings.rec_source; /* detect source change */
1035 #endif
1037 static const unsigned char *byte_units[] = {
1038 ID2P(LANG_BYTE),
1039 ID2P(LANG_KILOBYTE),
1040 ID2P(LANG_MEGABYTE),
1041 ID2P(LANG_GIGABYTE)
1044 struct audio_recording_options rec_options;
1045 rec_status = RCSTAT_IN_RECSCREEN;
1047 #if (CONFIG_STORAGE & STORAGE_ATA) && (CONFIG_LED == LED_REAL) \
1048 && !defined(SIMULATOR)
1049 ata_set_led_enabled(false);
1050 #endif
1052 #if CONFIG_CODEC == SWCODEC
1053 /* recording_menu gets messed up: so prevent manus talking */
1054 talk_disable(true);
1055 /* audio_init_recording stops anything playing when it takes the audio
1056 buffer */
1057 #else
1058 /* Yes, we use the D/A for monitoring */
1059 peak_meter_enabled = true;
1060 peak_meter_playback(true);
1061 #endif
1063 #ifdef HAVE_AGC
1064 peak_meter_get_peakhold(&peak_l, &peak_r);
1065 #endif
1067 pm_reset_clipcount();
1068 pm_activate_clipcount(false);
1069 settings_apply_trigger();
1071 #ifdef HAVE_AGC
1072 agc_preset_str[0] = str(LANG_OFF);
1073 agc_preset_str[1] = str(LANG_AGC_SAFETY);
1074 agc_preset_str[2] = str(LANG_AGC_LIVE);
1075 agc_preset_str[3] = str(LANG_AGC_DJSET);
1076 agc_preset_str[4] = str(LANG_AGC_MEDIUM);
1077 agc_preset_str[5] = str(LANG_AGC_VOICE);
1078 #endif /* HAVE_AGC */
1080 #if CONFIG_CODEC == SWCODEC
1081 audio_close_recording();
1082 #endif
1083 audio_init_recording(0);
1084 sound_set_volume(global_settings.volume);
1086 #if CONFIG_RTC == 0
1087 /* Create new filename for recording start */
1088 rec_init_filename();
1089 #endif
1091 /* viewport init and calculations that only needs to be done once */
1092 FOR_NB_SCREENS(i)
1093 recbars |= VP_SB_IGNORE_SETTING(i);
1094 oldbars = viewportmanager_set_statusbar(recbars);
1095 FOR_NB_SCREENS(i)
1097 struct viewport *v;
1098 /* top vp, 4 lines, force sys font if total screen < 6 lines
1099 NOTE: one could limit the list to 1 line and get away with 5 lines */
1100 v = &vp_top[i];
1101 viewport_set_defaults(v, i);
1102 if (viewport_get_nb_lines(v) < 4)
1104 /* compact needs 4 lines total */
1105 v->font = FONT_SYSFIXED;
1106 compact_view[i] = false;
1108 else
1110 if (viewport_get_nb_lines(v) < (4+2)) /*top=4,list=2*/
1111 compact_view[i] = true;
1112 else
1113 compact_view[i] = false;
1115 vp_list[i] = *v; /* get a copy now so it can be sized more easily */
1116 v->height = (font_get(v->font)->height)*(compact_view[i] ? 3 : 4);
1118 /* list section, rest of the screen */
1119 vp_list[i].y = vp_top[i].y + vp_top[i].height;
1120 vp_list[i].height -= vp_list[i].y;
1121 screens[i].set_viewport(&vp_top[i]); /* req for next calls */
1123 screens[i].getstringsize("W", &w, &h);
1124 pm_y[i] = font_get(vp_top[i].font)->height * 2;
1125 trig_ypos[i] = font_get(vp_top[i].font)->height * 3;
1126 if(compact_view[i])
1127 trig_ypos[i] -= (font_get(vp_top[i].font)->height)/2;
1130 /* init the bottom list */
1131 gui_synclist_init(&lists, reclist_get_name, NULL, false, 1, vp_list);
1132 gui_synclist_set_title(&lists, NULL, Icon_NOICON);
1134 /* start of the loop: we stay in this loop until user quits recscreen */
1135 while(done <= 0)
1137 if(done < 0)
1139 /* request to re-init stuff, done after settings screen */
1140 done = 0;
1141 #ifdef HAVE_FMRADIO_REC
1142 /* If input changes away from FM Radio,
1143 radio will remain off when recording screen closes. */
1144 if (global_settings.rec_source != prev_rec_source
1145 && prev_rec_source == AUDIO_SRC_FMRADIO)
1146 radio_status = FMRADIO_OFF;
1147 prev_rec_source = global_settings.rec_source;
1148 #endif
1150 FOR_NB_SCREENS(i)
1152 pm_x[i] = 0;
1153 if(global_settings.peak_meter_clipcounter)
1155 int clipwidth = 0;
1156 screens[i].getstringsize(str(LANG_PM_CLIPCOUNT),
1157 &clipwidth, &h); /* h is same */
1158 pm_x[i] = clipwidth+1;
1160 if(global_settings.rec_trigger_mode == TRIG_MODE_OFF)
1161 pm_h[i] = font_get(vp_top[i].font)->height * 2;
1162 else
1163 pm_h[i] = font_get(vp_top[i].font)->height;
1164 if(compact_view[i])
1165 pm_h[i] /= 2;
1166 trig_width[i] = vp_top[i].width - pm_x[i];
1169 #if CONFIG_CODEC == SWCODEC
1170 audio_close_recording();
1171 audio_init_recording(0);
1172 #endif
1174 rec_init_recording_options(&rec_options);
1175 rec_set_recording_options(&rec_options);
1177 if(rec_create_directory() < 0)
1179 rec_status = 0;
1180 goto rec_abort;
1183 #if CONFIG_CODEC == SWCODEC && CONFIG_RTC == 0
1184 /* If format changed, a new number is required */
1185 rec_init_filename();
1186 #endif
1188 #ifdef HAVE_AGC
1189 #ifdef HAVE_MIC_REC
1190 if (global_settings.rec_source == AUDIO_SRC_MIC) {
1191 agc_preset = global_settings.rec_agc_preset_mic;
1192 agc_maxgain = global_settings.rec_agc_maxgain_mic;
1194 else
1195 #endif /* MIC */
1197 agc_preset = global_settings.rec_agc_preset_line;
1198 agc_maxgain = global_settings.rec_agc_maxgain_line;
1200 #endif /* HAVE_AGC */
1202 set_gain();
1203 update_countdown = 0; /* Update immediately */
1205 /* populate translation table for list id -> enum */
1206 #ifdef HAVE_SPDIF_REC
1207 if(global_settings.rec_source == AUDIO_SRC_SPDIF)
1209 listid_to_enum[0] = ITEM_VOLUME_D;
1210 #if CONFIG_CODEC == SWCODEC
1211 listid_to_enum[1] = ITEM_SAMPLERATE_D;
1212 listid_to_enum[2] = ITEM_FILENAME_D;
1213 #else
1214 listid_to_enum[1] = ITEM_FILENAME_D;
1215 #endif
1217 gui_synclist_set_nb_items(&lists, ITEM_COUNT_D); /* spdif */
1219 else
1220 #endif
1221 if(HAVE_MIC_REC_((global_settings.rec_source == AUDIO_SRC_MIC) || )
1222 (global_settings.rec_channels == 1))
1224 listid_to_enum[0] = ITEM_VOLUME_M;
1225 listid_to_enum[1] = ITEM_GAIN_M;
1226 #ifdef HAVE_AGC
1227 listid_to_enum[2] = ITEM_AGC_MODE_M;
1228 listid_to_enum[3] = ITEM_AGC_MAXDB_M;
1229 listid_to_enum[4] = ITEM_FILENAME_M;
1230 #else
1231 listid_to_enum[2] = ITEM_FILENAME_M;
1232 #endif
1233 gui_synclist_set_nb_items(&lists, ITEM_COUNT_M); /* mono */
1235 else
1237 listid_to_enum[0] = ITEM_VOLUME;
1238 listid_to_enum[1] = ITEM_GAIN;
1239 listid_to_enum[2] = ITEM_GAIN_L;
1240 listid_to_enum[3] = ITEM_GAIN_R;
1241 #ifdef HAVE_AGC
1242 listid_to_enum[4] = ITEM_AGC_MODE;
1243 listid_to_enum[5] = ITEM_AGC_MAXDB;
1244 listid_to_enum[6] = ITEM_FILENAME;
1245 #else
1246 listid_to_enum[4] = ITEM_FILENAME;
1247 #endif
1248 gui_synclist_set_nb_items(&lists, ITEM_COUNT); /* stereo */
1251 gui_synclist_draw(&lists);
1252 } /* if(done < 0) */
1254 audio_stat = audio_status();
1256 #if (CONFIG_LED == LED_REAL)
1259 * Flash the LED while waiting to record. Turn it on while
1260 * recording.
1262 if(audio_stat & AUDIO_STATUS_RECORD)
1264 if (audio_stat & AUDIO_STATUS_PAUSE)
1266 if (--led_countdown <= 0)
1268 led_state = !led_state;
1269 led(led_state);
1270 led_countdown = 2;
1273 else
1275 /* trigger is on in status TRIG_READY (no check needed) */
1276 led(true);
1279 else
1281 int trig_stat = peak_meter_trigger_status();
1283 * other trigger stati than trig_off and trig_steady
1284 * already imply that we are recording.
1286 if (trig_stat == TRIG_STEADY)
1288 if (--led_countdown <= 0)
1290 led_state = !led_state;
1291 led(led_state);
1292 led_countdown = 2;
1295 else
1297 /* trigger is on in status TRIG_READY (no check needed) */
1298 led(false);
1301 #endif /* CONFIG_LED */
1303 /* Wait for a button a while (HZ/10) drawing the peak meter */
1304 button = peak_meter_draw_get_btn(CONTEXT_RECSCREEN,
1305 pm_x, pm_y, pm_h,
1306 screen_update, vp_top);
1307 if (last_audio_stat != audio_stat)
1309 if (audio_stat & AUDIO_STATUS_RECORD)
1311 rec_status |= RCSTAT_HAVE_RECORDED;
1313 last_audio_stat = audio_stat;
1314 update_list = true;
1317 if (recording_start_automatic)
1319 /* simulate a button press */
1320 button = ACTION_REC_PAUSE;
1321 recording_start_automatic = false;
1324 /* let list handle the button */
1325 gui_synclist_do_button(&lists, &button, LIST_WRAP_UNLESS_HELD);
1328 switch(button)
1330 case ACTION_SETTINGS_INC:
1331 case ACTION_SETTINGS_INCREPEAT:
1332 switch (listid_to_enum[gui_synclist_get_sel_pos(&lists)])
1334 case ITEM_VOLUME:
1335 global_settings.volume++;
1336 setvol();
1337 break;
1338 case ITEM_GAIN:
1339 #ifdef HAVE_MIC_REC
1340 if(global_settings.rec_source == AUDIO_SRC_MIC)
1342 if(global_settings.rec_mic_gain <
1343 sound_max(SOUND_MIC_GAIN))
1344 global_settings.rec_mic_gain++;
1346 else
1347 #endif /* MIC */
1349 if(global_settings.rec_left_gain <
1350 sound_max(SOUND_LEFT_GAIN))
1351 global_settings.rec_left_gain++;
1352 if(global_settings.rec_right_gain <
1353 sound_max(SOUND_RIGHT_GAIN))
1354 global_settings.rec_right_gain++;
1356 break;
1357 case ITEM_GAIN_L:
1358 if(global_settings.rec_left_gain <
1359 sound_max(SOUND_LEFT_GAIN))
1360 global_settings.rec_left_gain++;
1361 break;
1362 case ITEM_GAIN_R:
1363 if(global_settings.rec_right_gain <
1364 sound_max(SOUND_RIGHT_GAIN))
1365 global_settings.rec_right_gain++;
1366 break;
1367 #ifdef HAVE_AGC
1368 case ITEM_AGC_MODE:
1369 agc_preset = MIN(agc_preset + 1, AGC_MODE_SIZE);
1370 agc_enable = (agc_preset != 0);
1371 #ifdef HAVE_MIC_REC
1372 if (global_settings.rec_source == AUDIO_SRC_MIC) {
1373 global_settings.rec_agc_preset_mic = agc_preset;
1374 agc_maxgain = global_settings.rec_agc_maxgain_mic;
1375 } else
1376 #endif /* MIC */
1378 global_settings.rec_agc_preset_line = agc_preset;
1379 agc_maxgain = global_settings.rec_agc_maxgain_line;
1381 break;
1382 case ITEM_AGC_MAXDB:
1383 #ifdef HAVE_MIC_REC
1384 if (global_settings.rec_source == AUDIO_SRC_MIC)
1386 agc_maxgain = MIN(agc_maxgain + 1,
1387 sound_max(SOUND_MIC_GAIN));
1388 global_settings.rec_agc_maxgain_mic = agc_maxgain;
1390 else
1391 #endif /* MIC */
1393 agc_maxgain = MIN(agc_maxgain + 1,
1394 sound_max(SOUND_LEFT_GAIN));
1395 global_settings.rec_agc_maxgain_line = agc_maxgain;
1397 break;
1398 #endif /* HAVE_AGC */
1400 set_gain();
1401 update_countdown = 0; /* Update immediately */
1402 break;
1403 case ACTION_SETTINGS_DEC:
1404 case ACTION_SETTINGS_DECREPEAT:
1405 switch (listid_to_enum[gui_synclist_get_sel_pos(&lists)])
1407 case ITEM_VOLUME:
1408 global_settings.volume--;
1409 setvol();
1410 break;
1411 case ITEM_GAIN:
1412 #ifdef HAVE_MIC_REC
1413 if(global_settings.rec_source == AUDIO_SRC_MIC)
1415 if(global_settings.rec_mic_gain >
1416 sound_min(SOUND_MIC_GAIN))
1417 global_settings.rec_mic_gain--;
1419 else
1420 #endif /* MIC */
1422 if(global_settings.rec_left_gain >
1423 sound_min(SOUND_LEFT_GAIN))
1424 global_settings.rec_left_gain--;
1425 if(global_settings.rec_right_gain >
1426 sound_min(SOUND_RIGHT_GAIN))
1427 global_settings.rec_right_gain--;
1429 break;
1430 case ITEM_GAIN_L:
1431 if(global_settings.rec_left_gain >
1432 sound_min(SOUND_LEFT_GAIN))
1433 global_settings.rec_left_gain--;
1434 break;
1435 case ITEM_GAIN_R:
1436 if(global_settings.rec_right_gain >
1437 sound_min(SOUND_RIGHT_GAIN))
1438 global_settings.rec_right_gain--;
1439 break;
1440 #ifdef HAVE_AGC
1441 case ITEM_AGC_MODE:
1442 agc_preset = MAX(agc_preset - 1, 0);
1443 agc_enable = (agc_preset != 0);
1444 #ifdef HAVE_MIC_REC
1445 if (global_settings.rec_source == AUDIO_SRC_MIC) {
1446 global_settings.rec_agc_preset_mic = agc_preset;
1447 agc_maxgain = global_settings.rec_agc_maxgain_mic;
1448 } else
1449 #endif /* MIC */
1451 global_settings.rec_agc_preset_line = agc_preset;
1452 agc_maxgain = global_settings.rec_agc_maxgain_line;
1454 break;
1455 case ITEM_AGC_MAXDB:
1456 #ifdef HAVE_MIC_REC
1457 if (global_settings.rec_source == AUDIO_SRC_MIC)
1459 agc_maxgain = MAX(agc_maxgain - 1,
1460 sound_min(SOUND_MIC_GAIN));
1461 global_settings.rec_agc_maxgain_mic = agc_maxgain;
1462 } else
1463 #endif /* MIC */
1465 agc_maxgain = MAX(agc_maxgain - 1,
1466 sound_min(SOUND_LEFT_GAIN));
1467 global_settings.rec_agc_maxgain_line = agc_maxgain;
1469 break;
1470 #endif /* HAVE_AGC */
1472 set_gain();
1473 update_countdown = 0; /* Update immediately */
1474 break;
1475 case ACTION_STD_CANCEL:
1476 /* turn off the trigger */
1477 peak_meter_trigger(false);
1478 peak_meter_set_trigger_listener(NULL);
1480 if(audio_stat & AUDIO_STATUS_RECORD)
1482 rec_command(RECORDING_CMD_STOP);
1484 else
1486 #if CONFIG_CODEC != SWCODEC
1487 peak_meter_playback(true);
1488 peak_meter_enabled = false;
1489 #endif
1490 done = 1;
1492 update_countdown = 0; /* Update immediately */
1493 break;
1494 #ifdef HAVE_REMOTE_LCD
1495 case ACTION_REC_LCD:
1496 /* this feature exists for some h1x0/h3x0 targets that suffer
1497 from noise caused by remote LCD updates
1498 NOTE 1: this will leave the list on the remote
1499 NOTE 2: to be replaced by a global LCD_off() routine */
1500 if(remote_display_on)
1502 /* switch to single screen, leave message on remote */
1503 screen_update = 1;
1504 screens[1].clear_viewport();
1505 screens[1].puts(0, 0, str(LANG_REMOTE_LCD_OFF));
1506 screens[1].puts(0, 1, str(LANG_REMOTE_LCD_ON));
1507 screens[1].update_viewport();
1509 else
1511 /* remote switched on again */
1512 update_list = true;
1513 screen_update = NB_SCREENS;
1515 remote_display_on = !remote_display_on; /* toggle */
1516 update_countdown = 0; /* Update immediately */
1517 break;
1518 #endif
1519 case ACTION_REC_NEWFILE:
1521 /* Only act if in the middle of recording. */
1522 if(audio_stat & AUDIO_STATUS_RECORD)
1524 rec_command(RECORDING_CMD_START_NEWFILE);
1525 last_seconds = 0;
1527 break;
1529 case ACTION_REC_PAUSE:
1531 /* Only act if the mpeg is stopped */
1532 if(!(audio_stat & AUDIO_STATUS_RECORD))
1534 /* is this manual or triggered recording? */
1535 if ((global_settings.rec_trigger_mode == TRIG_MODE_OFF) ||
1536 (peak_meter_trigger_status() != TRIG_OFF))
1538 /* manual recording */
1539 rec_status |= RCSTAT_HAVE_RECORDED;
1540 rec_command(RECORDING_CMD_START);
1541 last_seconds = 0;
1542 if (global_settings.talk_menu)
1544 /* no voice possible here, but a beep */
1545 audio_beep(HZ/2); /* longer beep on start */
1548 /* this is triggered recording */
1549 else
1551 /* we don't start recording now, but enable the
1552 trigger and let the callback function
1553 trigger_listener control when the recording starts */
1554 peak_meter_trigger(true);
1555 peak_meter_set_trigger_listener(&trigger_listener);
1558 /* If we're in the middle of recording */
1559 else
1561 /* if pause button pressed, pause or resume */
1562 if(audio_stat & AUDIO_STATUS_PAUSE)
1564 rec_command(RECORDING_CMD_RESUME);
1565 if (global_settings.talk_menu)
1567 /* no voice possible here, but a beep */
1568 audio_beep(HZ/4); /* short beep on resume */
1571 else
1573 rec_command(RECORDING_CMD_PAUSE);
1576 update_countdown = 0; /* Update immediately */
1577 break;
1578 case ACTION_STD_MENU:
1579 #if CONFIG_CODEC == SWCODEC
1580 if(!(audio_stat & AUDIO_STATUS_RECORD))
1581 #else
1582 if(audio_stat != AUDIO_STATUS_RECORD)
1583 #endif
1585 #if (CONFIG_LED == LED_REAL)
1586 /* led is restored at begin of loop / end of function */
1587 led(false);
1588 #endif
1589 viewportmanager_set_statusbar(oldbars);
1590 if (recording_menu(no_source))
1592 done = 1;
1593 rec_status |= RCSTAT_BEEN_IN_USB_MODE;
1594 #ifdef HAVE_FMRADIO_REC
1595 radio_status = FMRADIO_OFF;
1596 #endif
1598 else
1600 done = -1;
1601 /* the init is now done at the beginning of the loop */
1603 viewportmanager_set_statusbar(recbars);
1605 break;
1607 #if CONFIG_KEYPAD == RECORDER_PAD
1608 case ACTION_REC_F2:
1609 if(audio_stat != AUDIO_STATUS_RECORD)
1611 #if (CONFIG_LED == LED_REAL)
1612 /* led is restored at begin of loop / end of function */
1613 led(false);
1614 #endif
1615 viewportmanager_set_statusbar(oldbars);
1616 if (f2_rec_screen())
1618 rec_status |= RCSTAT_HAVE_RECORDED;
1619 done = true;
1621 else
1622 update_countdown = 0; /* Update immediately */
1623 viewportmanager_set_statusbar(recbars);
1625 break;
1627 case ACTION_REC_F3:
1628 if(audio_stat & AUDIO_STATUS_RECORD)
1630 rec_command(RECORDING_CMD_START_NEWFILE);
1631 last_seconds = 0;
1633 else
1635 #if (CONFIG_LED == LED_REAL)
1636 /* led is restored at begin of loop / end of function */
1637 led(false);
1638 #endif
1639 viewportmanager_set_statusbar(oldbars);
1640 if (f3_rec_screen())
1642 rec_status |= RCSTAT_HAVE_RECORDED;
1643 done = true;
1645 else
1646 update_countdown = 0; /* Update immediately */
1647 viewportmanager_set_statusbar(recbars);
1649 break;
1650 #endif /* CONFIG_KEYPAD == RECORDER_PAD */
1652 case SYS_USB_CONNECTED:
1653 /* Only accept USB connection when not recording */
1654 if(!(audio_stat & AUDIO_STATUS_RECORD))
1656 FOR_NB_SCREENS(i)
1657 screens[i].set_viewport(NULL);
1658 default_event_handler(SYS_USB_CONNECTED);
1659 done = true;
1660 rec_status |= RCSTAT_BEEN_IN_USB_MODE;
1661 #ifdef HAVE_FMRADIO_REC
1662 radio_status = FMRADIO_OFF;
1663 #endif
1665 break;
1666 } /*switch(button)*/
1668 #ifdef HAVE_AGC
1669 peak_read = !peak_read;
1670 if (peak_read) { /* every 2nd run of loop */
1671 peak_time++;
1672 peak_valid = read_peak_levels(&peak_l, &peak_r, &balance);
1675 /* Handle AGC every 200ms when enabled and peak data is valid */
1676 if (peak_read && agc_enable && peak_valid)
1677 auto_gain_control(&peak_l, &peak_r, &balance);
1678 #endif
1680 seconds = audio_recorded_time() / HZ;
1682 /* start of vp_top drawing */
1683 if(update_countdown-- == 0 || seconds > last_seconds)
1685 unsigned int dseconds, dhours, dminutes;
1686 unsigned long num_recorded_bytes, dsize, dmb;
1689 FOR_NB_SCREENS(i)
1691 screens[i].set_viewport(&vp_top[i]);
1692 screens[i].clear_viewport();
1694 update_countdown = 5;
1695 last_seconds = seconds;
1697 dseconds = rec_timesplit_seconds();
1698 dsize = rec_sizesplit_bytes();
1699 num_recorded_bytes = audio_num_recorded_bytes();
1701 #if CONFIG_CODEC == SWCODEC
1702 if ((audio_stat & AUDIO_STATUS_WARNING)
1703 && (warning_counter++ % WARNING_PERIOD) < WARNING_PERIOD/2)
1705 /* Switch back and forth displaying warning on first available
1706 line to ensure visibility - the motion should also help
1707 draw attention */
1708 /* Don't use language string unless agreed upon to make this
1709 method permanent - could do something in the statusbar */
1710 snprintf(buf, sizeof(buf), "Warning: %08X",
1711 pcm_rec_get_warnings());
1713 else
1714 #endif /* CONFIG_CODEC == SWCODEC */
1715 if ((global_settings.rec_sizesplit) &&
1716 (global_settings.rec_split_method))
1718 dmb = dsize/1024/1024;
1719 snprintf(buf, sizeof(buf), "%s %dMB",
1720 str(LANG_SPLIT_SIZE), dmb);
1722 else
1724 hours = seconds / 3600;
1725 minutes = (seconds - (hours * 3600)) / 60;
1726 snprintf(buf, sizeof(buf), "%s %02d:%02d:%02d",
1727 str(LANG_RECORDING_TIME),
1728 hours, minutes, seconds%60);
1731 FOR_NB_ACTIVE_SCREENS(i)
1732 screens[i].puts(0, 0, buf);
1734 if(audio_stat & AUDIO_STATUS_PRERECORD)
1736 snprintf(buf, sizeof(buf), "%s...",
1737 str(LANG_RECORD_PRERECORD));
1739 else
1741 /* Display the split interval if the record timesplit
1742 is active */
1743 if ((global_settings.rec_timesplit) &&
1744 !(global_settings.rec_split_method))
1746 /* Display the record timesplit interval rather
1747 than the file size if the record timer is active */
1748 dhours = dseconds / 3600;
1749 dminutes = (dseconds - (dhours * 3600)) / 60;
1750 snprintf(buf, sizeof(buf), "%s %02d:%02d",
1751 str(LANG_RECORDING_TIMESPLIT_REC),
1752 dhours, dminutes);
1754 else
1756 output_dyn_value(buf2, sizeof buf2,
1757 num_recorded_bytes,
1758 byte_units, true);
1759 snprintf(buf, sizeof(buf), "%s %s",
1760 str(LANG_RECORDING_SIZE), buf2);
1764 FOR_NB_ACTIVE_SCREENS(i)
1765 screens[i].puts(0, 1, buf);
1767 /* We will do file splitting regardless, either at the end of
1768 a split interval, or when the filesize approaches the 2GB
1769 FAT file size (compatibility) limit. */
1770 if ((audio_stat && !(global_settings.rec_split_method)
1771 && global_settings.rec_timesplit && (seconds >= dseconds))
1772 || (audio_stat && global_settings.rec_split_method
1773 && global_settings.rec_sizesplit
1774 && (num_recorded_bytes >= dsize))
1775 || (num_recorded_bytes >= MAX_FILE_SIZE))
1777 if (!(global_settings.rec_split_type)
1778 || (num_recorded_bytes >= MAX_FILE_SIZE))
1780 rec_command(RECORDING_CMD_START_NEWFILE);
1781 last_seconds = 0;
1783 else
1785 peak_meter_trigger(false);
1786 peak_meter_set_trigger_listener(NULL);
1787 if( global_settings.rec_split_type == 1)
1788 rec_command(RECORDING_CMD_STOP);
1789 else
1790 rec_command(RECORDING_CMD_STOP_SHUTDOWN);
1792 update_countdown = 0;
1795 /* draw the clipcounter just in front of the peakmeter */
1796 if(global_settings.peak_meter_clipcounter)
1798 char clpstr[32];
1799 snprintf(clpstr, 32, "%4d", pm_get_clipcount());
1800 FOR_NB_ACTIVE_SCREENS(i)
1802 if(!compact_view[i])
1803 screens[i].puts(0, 2,str(LANG_PM_CLIPCOUNT));
1804 screens[i].puts(0, compact_view[i] ? 2 : 3, clpstr);
1808 #ifdef HAVE_AGC
1809 hist_time++;
1810 #endif
1812 /* draw the trigger status */
1813 if (peak_meter_trigger_status() != TRIG_OFF)
1815 peak_meter_draw_trig(pm_x, trig_ypos, trig_width,
1816 screen_update);
1817 FOR_NB_ACTIVE_SCREENS(i)
1818 screens[i].update_viewport_rect(pm_x[i], trig_ypos[i],
1819 trig_width[i] + 2, TRIG_HEIGHT);
1822 #ifdef HAVE_AGC
1823 #ifdef HAVE_MIC_REC
1824 if (global_settings.rec_source == AUDIO_SRC_MIC)
1826 if(agc_maxgain < (global_settings.rec_mic_gain))
1827 change_recording_gain(false, true, true);
1829 else
1830 #endif /* MIC */
1832 if(agc_maxgain < (global_settings.rec_left_gain))
1833 change_recording_gain(false, true, false);
1834 if(agc_maxgain < (global_settings.rec_right_gain))
1835 change_recording_gain(false, false, true);
1837 #endif /* HAVE_AGC */
1839 #if CONFIG_CODEC == SWCODEC
1840 #ifdef HAVE_SPDIF_REC
1841 if((global_settings.rec_source == AUDIO_SRC_SPDIF) &&
1842 (prev_sample_rate != pcm_rec_sample_rate()))
1844 /* spdif samplerate changed */
1845 prev_sample_rate = pcm_rec_sample_rate();
1846 update_list = true;
1848 #endif
1849 #endif
1851 if(update_list)
1853 /* update_list is set whenever content changes */
1854 update_list = false;
1855 gui_synclist_draw(&lists);
1858 /* draw peakmeter again (check if this can be removed) */
1859 FOR_NB_ACTIVE_SCREENS(i)
1861 screens[i].set_viewport(&vp_top[i]);
1862 peak_meter_screen(&screens[i], pm_x[i], pm_y[i], pm_h[i]);
1863 screens[i].update();
1865 } /* display update every second */
1867 if(audio_stat & AUDIO_STATUS_ERROR)
1869 done = true;
1871 } /* end while(!done) */
1873 audio_stat = audio_status();
1874 if (audio_stat & AUDIO_STATUS_ERROR)
1876 splash(0, str(LANG_DISK_FULL));
1878 FOR_NB_SCREENS(i)
1879 screens[i].update();
1881 #if CONFIG_CODEC == SWCODEC
1882 /* stop recording - some players like H10 freeze otherwise
1883 TO DO: find out why it freezes and fix properly */
1884 rec_command(RECORDING_CMD_STOP);
1885 audio_close_recording();
1886 #endif
1888 audio_error_clear();
1890 while(1)
1892 if (action_userabort(TIMEOUT_NOBLOCK))
1893 break;
1897 rec_abort:
1899 #if CONFIG_CODEC == SWCODEC
1900 rec_command(RECORDING_CMD_STOP);
1901 audio_close_recording();
1903 #ifdef HAVE_FMRADIO_REC
1904 if (radio_status != FMRADIO_OFF)
1905 /* Restore radio playback - radio_status should be unchanged if started
1906 through fm radio screen (barring usb connect) */
1907 rec_set_source(AUDIO_SRC_FMRADIO, (radio_status & FMRADIO_PAUSED) ?
1908 SRCF_FMRADIO_PAUSED : SRCF_FMRADIO_PLAYING);
1909 else
1910 #endif
1911 /* Go back to playback mode */
1912 rec_set_source(AUDIO_SRC_PLAYBACK, SRCF_PLAYBACK);
1914 /* restore talking */
1915 talk_disable(false);
1916 #else /* !SWCODEC */
1917 audio_init_playback();
1918 #endif /* CONFIG_CODEC == SWCODEC */
1920 /* make sure the trigger is really turned off */
1921 peak_meter_trigger(false);
1922 peak_meter_set_trigger_listener(NULL);
1924 rec_status &= ~RCSTAT_IN_RECSCREEN;
1925 sound_settings_apply();
1927 viewportmanager_set_statusbar(oldbars);
1928 FOR_NB_SCREENS(i)
1929 screens[i].setfont(FONT_UI);
1931 /* if the directory was created or recording happened, make sure the
1932 browser is updated */
1933 if (rec_status & (RCSTAT_CREATED_DIRECTORY | RCSTAT_HAVE_RECORDED))
1934 reload_directory();
1936 #if (CONFIG_STORAGE & STORAGE_ATA) && (CONFIG_LED == LED_REAL) \
1937 && !defined(SIMULATOR)
1938 ata_set_led_enabled(true);
1939 #endif
1941 settings_save();
1943 return (rec_status & RCSTAT_BEEN_IN_USB_MODE) != 0;
1944 } /* recording_screen */
1946 #if CONFIG_KEYPAD == RECORDER_PAD
1947 static bool f2_rec_screen(void)
1949 static const char* const freq_str[6] =
1951 "44.1kHz",
1952 "48kHz",
1953 "32kHz",
1954 "22.05kHz",
1955 "24kHz",
1956 "16kHz"
1959 bool exit = false;
1960 bool used = false;
1961 int w, h, i;
1962 char buf[32];
1963 int button;
1964 struct audio_recording_options rec_options;
1966 FOR_NB_SCREENS(i)
1968 screens[i].setfont(FONT_SYSFIXED);
1969 screens[i].getstringsize("A",&w,&h);
1972 while (!exit) {
1973 const char* ptr=NULL;
1975 FOR_NB_SCREENS(i)
1977 screens[i].clear_display();
1979 /* Recording quality */
1980 screens[i].putsxy(0, LCD_HEIGHT/2 - h*2,
1981 str(LANG_SYSFONT_RECORDING_QUALITY));
1984 snprintf(buf, sizeof(buf), "%d", global_settings.rec_quality);
1985 FOR_NB_SCREENS(i)
1987 screens[i].putsxy(0, LCD_HEIGHT/2-h, buf);
1988 screens[i].mono_bitmap(bitmap_icons_7x8[Icon_FastBackward],
1989 LCD_WIDTH/2 - 16, LCD_HEIGHT/2 - 4, 7, 8);
1992 /* Frequency */
1993 snprintf(buf, sizeof buf, "%s:", str(LANG_SYSFONT_RECORDING_FREQUENCY));
1994 ptr = freq_str[global_settings.rec_frequency];
1995 FOR_NB_SCREENS(i)
1997 screens[i].getstringsize(buf,&w,&h);
1998 screens[i].putsxy((LCD_WIDTH-w)/2, LCD_HEIGHT - h*2, buf);
1999 screens[i].getstringsize(ptr, &w, &h);
2000 screens[i].putsxy((LCD_WIDTH-w)/2, LCD_HEIGHT - h, ptr);
2001 screens[i].mono_bitmap(bitmap_icons_7x8[Icon_DownArrow],
2002 LCD_WIDTH/2 - 3, LCD_HEIGHT - h*3, 7, 8);
2005 /* Channel mode */
2006 switch ( global_settings.rec_channels ) {
2007 case 0:
2008 ptr = str(LANG_SYSFONT_CHANNEL_STEREO);
2009 break;
2011 case 1:
2012 ptr = str(LANG_SYSFONT_CHANNEL_MONO);
2013 break;
2016 FOR_NB_SCREENS(i)
2018 screens[i].getstringsize(str(LANG_SYSFONT_CHANNELS), &w, &h);
2019 screens[i].putsxy(LCD_WIDTH - w, LCD_HEIGHT/2 - h*2,
2020 str(LANG_SYSFONT_CHANNELS));
2021 screens[i].getstringsize(str(LANG_SYSFONT_MODE), &w, &h);
2022 screens[i].putsxy(LCD_WIDTH - w, LCD_HEIGHT/2 - h,
2023 str(LANG_SYSFONT_MODE));
2024 screens[i].getstringsize(ptr, &w, &h);
2025 screens[i].putsxy(LCD_WIDTH - w, LCD_HEIGHT/2, ptr);
2026 screens[i].mono_bitmap(bitmap_icons_7x8[Icon_FastForward],
2027 LCD_WIDTH/2 + 8, LCD_HEIGHT/2 - 4, 7, 8);
2029 screens[i].update();
2032 button = button_get(true);
2033 switch (button) {
2034 case BUTTON_LEFT:
2035 case BUTTON_F2 | BUTTON_LEFT:
2036 global_settings.rec_quality++;
2037 if(global_settings.rec_quality > 7)
2038 global_settings.rec_quality = 0;
2039 used = true;
2040 break;
2042 case BUTTON_DOWN:
2043 case BUTTON_F2 | BUTTON_DOWN:
2044 global_settings.rec_frequency++;
2045 if(global_settings.rec_frequency > 5)
2046 global_settings.rec_frequency = 0;
2047 used = true;
2048 break;
2050 case BUTTON_RIGHT:
2051 case BUTTON_F2 | BUTTON_RIGHT:
2052 global_settings.rec_channels++;
2053 if(global_settings.rec_channels > 1)
2054 global_settings.rec_channels = 0;
2055 used = true;
2056 break;
2058 case BUTTON_F2 | BUTTON_REL:
2059 if ( used )
2060 exit = true;
2061 used = true;
2062 break;
2064 case BUTTON_F2 | BUTTON_REPEAT:
2065 used = true;
2066 break;
2068 default:
2069 if(default_event_handler(button) == SYS_USB_CONNECTED)
2070 return true;
2071 break;
2075 rec_init_recording_options(&rec_options);
2076 rec_set_recording_options(&rec_options);
2078 set_gain();
2080 settings_save();
2081 FOR_NB_SCREENS(i)
2082 screens[i].setfont(FONT_UI);
2084 return false;
2087 static bool f3_rec_screen(void)
2089 bool exit = false;
2090 bool used = false;
2091 int w, h, i;
2092 int button;
2093 char *src_str[] =
2095 str(LANG_SYSFONT_RECORDING_SRC_MIC),
2096 str(LANG_SYSFONT_LINE_IN),
2097 str(LANG_SYSFONT_RECORDING_SRC_DIGITAL)
2099 struct audio_recording_options rec_options;
2101 FOR_NB_SCREENS(i)
2103 screens[i].setfont(FONT_SYSFIXED);
2104 screens[i].getstringsize("A",&w,&h);
2107 while (!exit) {
2108 char* ptr=NULL;
2109 ptr = src_str[global_settings.rec_source];
2110 FOR_NB_SCREENS(i)
2112 screens[i].clear_display();
2114 /* Recording source */
2115 screens[i].putsxy(0, LCD_HEIGHT/2 - h*2,
2116 str(LANG_SYSFONT_RECORDING_SOURCE));
2118 screens[i].getstringsize(ptr, &w, &h);
2119 screens[i].putsxy(0, LCD_HEIGHT/2-h, ptr);
2120 screens[i].mono_bitmap(bitmap_icons_7x8[Icon_FastBackward],
2121 LCD_WIDTH/2 - 16, LCD_HEIGHT/2 - 4, 7, 8);
2124 /* trigger setup */
2125 ptr = str(LANG_SYSFONT_RECORD_TRIGGER);
2126 FOR_NB_SCREENS(i)
2128 screens[i].getstringsize(ptr,&w,&h);
2129 screens[i].putsxy((LCD_WIDTH-w)/2, LCD_HEIGHT - h*2, ptr);
2130 screens[i].mono_bitmap(bitmap_icons_7x8[Icon_DownArrow],
2131 LCD_WIDTH/2 - 3, LCD_HEIGHT - h*3, 7, 8);
2133 screens[i].update();
2136 button = button_get(true);
2137 switch (button) {
2138 case BUTTON_DOWN:
2139 case BUTTON_F3 | BUTTON_DOWN:
2140 #ifndef SIMULATOR
2141 rectrigger();
2142 settings_apply_trigger();
2143 #endif
2144 exit = true;
2145 break;
2147 case BUTTON_LEFT:
2148 case BUTTON_F3 | BUTTON_LEFT:
2149 global_settings.rec_source++;
2150 if(global_settings.rec_source > AUDIO_SRC_MAX)
2151 global_settings.rec_source = 0;
2152 used = true;
2153 break;
2155 case BUTTON_F3 | BUTTON_REL:
2156 if ( used )
2157 exit = true;
2158 used = true;
2159 break;
2161 case BUTTON_F3 | BUTTON_REPEAT:
2162 used = true;
2163 break;
2165 default:
2166 if(default_event_handler(button) == SYS_USB_CONNECTED)
2167 return true;
2168 break;
2172 rec_init_recording_options(&rec_options);
2173 rec_set_recording_options(&rec_options);
2175 set_gain();
2177 settings_save();
2178 FOR_NB_SCREENS(i)
2179 screens[i].setfont(FONT_UI);
2181 return false;
2183 #endif /* CONFIG_KEYPAD == RECORDER_PAD */
2185 #if CONFIG_CODEC == SWCODEC
2186 void audio_beep(int duration)
2188 /* dummy */
2189 (void)duration;
2192 #ifdef SIMULATOR
2193 /* stubs for recording sim */
2194 void audio_init_recording(unsigned int buffer_offset)
2196 buffer_offset = buffer_offset;
2199 void audio_close_recording(void)
2203 unsigned long pcm_rec_get_warnings(void)
2205 return 0;
2208 unsigned long pcm_rec_sample_rate(void)
2210 return 0;
2213 unsigned long audio_recorded_time(void)
2215 return 123;
2218 unsigned long audio_num_recorded_bytes(void)
2220 return 5 * 1024 * 1024;
2223 void rec_set_source(int source, unsigned flags)
2225 source = source;
2226 flags = flags;
2229 void audio_set_recording_options(struct audio_recording_options *options)
2231 options = options;
2234 void audio_set_recording_gain(int left, int right, int type)
2236 left = left;
2237 right = right;
2238 type = type;
2241 void audio_record(const char *filename)
2243 filename = filename;
2246 void audio_new_file(const char *filename)
2248 filename = filename;
2251 void audio_stop_recording(void)
2255 void audio_pause_recording(void)
2259 void audio_resume_recording(void)
2263 #endif /* #ifdef SIMULATOR */
2264 #endif /* #ifdef CONFIG_CODEC == SWCODEC */
2266 #endif /* HAVE_RECORDING */