Update Beast installation instructions to use beastpatcher and remove instructions...
[kugel-rb.git] / apps / recorder / recording.c
blobde979dda50804a28eef6915c1e42f1ce296e5955
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 "statusbar.h"
57 #include "menu.h"
58 #include "sound_menu.h"
59 #include "timefuncs.h"
60 #include "debug.h"
61 #include "misc.h"
62 #include "tree.h"
63 #include "string.h"
64 #include "dir.h"
65 #include "errno.h"
66 #include "talk.h"
67 #include "sound.h"
68 #include "storage.h"
69 #if (CONFIG_STORAGE & STORAGE_ATA) && (CONFIG_LED == LED_REAL) \
70 && !defined(SIMULATOR)
71 #include "ata.h"
72 #endif
73 #include "splash.h"
74 #include "screen_access.h"
75 #include "action.h"
76 #include "radio.h"
77 #include "sound_menu.h"
78 #include "viewport.h"
79 #include "list.h"
80 #include "general.h"
82 #ifdef HAVE_RECORDING
83 /* This array holds the record timer interval lengths, in seconds */
84 static const unsigned long rec_timer_seconds[] =
86 0, /* 0 means OFF */
87 5*60, /* 00:05 */
88 10*60, /* 00:10 */
89 15*60, /* 00:15 */
90 30*60, /* 00:30 */
91 60*60, /* 01:00 */
92 74*60, /* 74:00 */
93 80*60, /* 80:00 */
94 2*60*60, /* 02:00 */
95 4*60*60, /* 04:00 */
96 6*60*60, /* 06:00 */
97 8*60*60, /* 08:00 */
98 10L*60*60, /* 10:00 */
99 12L*60*60, /* 12:00 */
100 18L*60*60, /* 18:00 */
101 24L*60*60 /* 24:00 */
104 static unsigned int rec_timesplit_seconds(void)
106 return rec_timer_seconds[global_settings.rec_timesplit];
109 /* This array holds the record size interval lengths, in bytes */
110 static const unsigned long rec_size_bytes[] =
112 0, /* 0 means OFF */
113 5*1024*1024, /* 5MB */
114 10*1024*1024, /* 10MB */
115 15*1024*1024, /* 15MB */
116 32*1024*1024, /* 32MB */
117 64*1024*1024, /* 64MB */
118 75*1024*1024, /* 75MB */
119 100*1024*1024, /* 100MB */
120 128*1024*1024, /* 128MB */
121 256*1024*1024, /* 256MB */
122 512*1024*1024, /* 512MB */
123 650*1024*1024, /* 650MB */
124 700*1024*1024, /* 700MB */
125 1024*1024*1024, /* 1GB */
126 1536*1024*1024, /* 1.5GB */
127 1792*1024*1024, /* 1.75GB */
130 static unsigned long rec_sizesplit_bytes(void)
132 return rec_size_bytes[global_settings.rec_sizesplit];
135 void settings_apply_trigger(void)
137 int start_thres, stop_thres;
138 if (global_settings.peak_meter_dbfs)
140 start_thres = global_settings.rec_start_thres_db - 1;
141 stop_thres = global_settings.rec_stop_thres_db - 1;
143 else
145 start_thres = global_settings.rec_start_thres_linear;
146 stop_thres = global_settings.rec_stop_thres_linear;
149 peak_meter_define_trigger(
150 start_thres,
151 global_settings.rec_start_duration*HZ,
152 MIN(global_settings.rec_start_duration*HZ / 2, 2*HZ),
153 stop_thres,
154 global_settings.rec_stop_postrec*HZ,
155 global_settings.rec_stop_gap*HZ
158 /* recording screen status flags */
159 enum rec_status_flags
161 RCSTAT_IN_RECSCREEN = 0x00000001,
162 RCSTAT_BEEN_IN_USB_MODE = 0x00000002,
163 RCSTAT_CREATED_DIRECTORY = 0x00000004,
164 RCSTAT_HAVE_RECORDED = 0x00000008,
167 static int rec_status = 0;
169 bool in_recording_screen(void)
171 return (rec_status & RCSTAT_IN_RECSCREEN) != 0;
174 #if CONFIG_KEYPAD == RECORDER_PAD
175 static bool f2_rec_screen(void);
176 static bool f3_rec_screen(void);
177 #endif
179 #define MAX_FILE_SIZE 0x7F800000 /* 2 GB - 4 MB */
181 #ifndef HAVE_REMOTE_LCD
182 static const int screen_update = NB_SCREENS;
183 #else
184 static int screen_update = NB_SCREENS;
185 static bool remote_display_on = true;
186 #endif
188 /* as we have the ability to disable the remote, we need an alternative loop */
189 #define FOR_NB_ACTIVE_SCREENS(i) for(i = 0; i < screen_update; i++)
191 static bool update_list = false; /* (GIU) list needs updating */
193 /** File name creation **/
194 #if CONFIG_RTC == 0
195 /* current file number to assist in creating unique numbered filenames
196 without actually having to create the file on disk */
197 static int file_number = -1;
198 #endif /* CONFIG_RTC */
200 #if CONFIG_CODEC == SWCODEC
202 #define REC_FILE_ENDING(rec_format) \
203 (audio_formats[rec_format_afmt[rec_format]].ext_list)
205 #else /* CONFIG_CODEC != SWCODEC */
207 /* default record file extension for HWCODEC */
208 #define REC_FILE_ENDING(rec_format) \
209 (audio_formats[AFMT_MPA_L3].ext_list)
211 #endif /* CONFIG_CODEC == SWCODEC */
213 /* path for current file */
214 static char path_buffer[MAX_PATH];
216 /** Automatic Gain Control (AGC) **/
217 #ifdef HAVE_AGC
218 /* Timing counters:
219 * peak_time is incremented every 0.2s, every 2nd run of record screen loop.
220 * hist_time is incremented every 0.5s, display update.
221 * peak_time is the counter of the peak hold read and agc process,
222 * overflow every 13 years 8-)
224 static long peak_time = 0;
225 static long hist_time = 0;
227 static short peak_valid_mem[4];
228 #define BAL_MEM_SIZE 24
229 static short balance_mem[BAL_MEM_SIZE];
231 /* Automatic Gain Control */
232 #define AGC_MODE_SIZE 5
233 #define AGC_SAFETY_MODE 0
235 static const char* agc_preset_str[] =
236 { "Off", "S", "L", "D", "M", "V" };
237 /* "Off",
238 "Safety (clip)",
239 "Live (slow)",
240 "DJ-Set (slow)",
241 "Medium",
242 "Voice (fast)" */
243 #define AGC_CLIP 32766
244 #define AGC_PEAK 29883 /* fast gain reduction threshold -0.8dB */
245 #define AGC_HIGH 27254 /* accelerated gain reduction threshold -1.6dB */
246 #define AGC_IMG 823 /* threshold for balance control -32dB */
247 /* autogain high level thresholds (-3dB, -7dB, -4dB, -5dB, -5dB) */
248 static const short agc_th_hi[AGC_MODE_SIZE] =
249 { 23197, 14637, 21156, 18428, 18426 };
250 /* autogain low level thresholds (-14dB, -11dB, -6dB, -7dB, -8dB) */
251 static const short agc_th_lo[AGC_MODE_SIZE] =
252 { 6538, 9235, 16422, 14636, 13045 };
253 /* autogain threshold times [1/5s] or [200ms] */
254 static const short agc_tdrop[AGC_MODE_SIZE] =
255 { 900, 225, 150, 60, 8 };
256 static const short agc_trise[AGC_MODE_SIZE] =
257 { 9000, 750, 400, 150, 20 };
258 static const short agc_tbal[AGC_MODE_SIZE] =
259 { 4500, 500, 300, 100, 15 };
260 /* AGC operation */
261 static bool agc_enable = true;
262 static short agc_preset;
263 /* AGC levels */
264 static int agc_left = 0;
265 static int agc_right = 0;
266 /* AGC time since high target volume was exceeded */
267 static short agc_droptime = 0;
268 /* AGC time since volume fallen below low target */
269 static short agc_risetime = 0;
270 /* AGC balance time exceeding +/- 0.7dB */
271 static short agc_baltime = 0;
272 /* AGC maximum gain */
273 static short agc_maxgain;
274 #endif /* HAVE_AGC */
276 static void set_gain(void)
278 #ifdef HAVE_MIC_REC
279 if(global_settings.rec_source == AUDIO_SRC_MIC)
281 audio_set_recording_gain(global_settings.rec_mic_gain,
282 0, AUDIO_GAIN_MIC);
284 else
285 #endif /* MIC */
287 /* AUDIO_SRC_LINEIN, AUDIO_SRC_FMRADIO, AUDIO_SRC_SPDIF */
288 audio_set_recording_gain(global_settings.rec_left_gain,
289 global_settings.rec_right_gain,
290 AUDIO_GAIN_LINEIN);
292 /* reset the clipping indicators */
293 peak_meter_set_clip_hold(global_settings.peak_meter_clip_hold);
294 update_list = true;
297 #ifdef HAVE_AGC
298 /* Read peak meter values & calculate balance.
299 * Returns validity of peak values.
300 * Used for automatic gain control and history diagram.
302 static bool read_peak_levels(int *peak_l, int *peak_r, int *balance)
304 peak_meter_get_peakhold(peak_l, peak_r);
305 peak_valid_mem[peak_time % 3] = *peak_l;
306 if (((peak_valid_mem[0] == peak_valid_mem[1]) &&
307 (peak_valid_mem[1] == peak_valid_mem[2])) &&
308 ((*peak_l < 32767) || storage_disk_is_active()))
309 return false;
311 if (*peak_r > *peak_l)
312 balance_mem[peak_time % BAL_MEM_SIZE] = (*peak_l ?
313 MIN((10000 * *peak_r) / *peak_l - 10000, 15118) : 15118);
314 else
315 balance_mem[peak_time % BAL_MEM_SIZE] = (*peak_r ?
316 MAX(10000 - (10000 * *peak_l) / *peak_r, -15118) : -15118);
317 *balance = 0;
318 int i;
319 for (i = 0; i < BAL_MEM_SIZE; i++)
320 *balance += balance_mem[i];
321 *balance = *balance / BAL_MEM_SIZE;
323 return true;
326 /* AGC helper function to check if maximum gain is reached */
327 static bool agc_gain_is_max(bool left, bool right)
329 /* range -128...+108 [0.5dB] */
330 short gain_current_l;
331 short gain_current_r;
333 if (agc_preset == 0)
334 return false;
336 switch (global_settings.rec_source)
338 #if defined(HAVE_LINE_REC) || defined(HAVE_FMRADIO_REC)
339 HAVE_LINE_REC_(case AUDIO_SRC_LINEIN:)
340 HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO:)
341 gain_current_l = global_settings.rec_left_gain;
342 gain_current_r = global_settings.rec_right_gain;
343 break;
344 #endif /* LINE, FMRADIO */
345 #if defined(HAVE_MIC_REC)
346 case AUDIO_SRC_MIC:
347 default:
348 gain_current_l = global_settings.rec_mic_gain;
349 gain_current_r = global_settings.rec_mic_gain;
350 #endif /* MIC */
353 return ((left && (gain_current_l >= agc_maxgain)) ||
354 (right && (gain_current_r >= agc_maxgain)));
357 static void change_recording_gain(bool increment, bool left, bool right)
359 int factor = (increment ? 1 : -1);
361 switch (global_settings.rec_source)
363 #if defined(HAVE_LINE_REC) || defined(HAVE_FMRADIO_REC)
364 HAVE_LINE_REC_(case AUDIO_SRC_LINEIN:)
365 HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO:)
366 if (left) global_settings.rec_left_gain += factor;
367 if (right) global_settings.rec_right_gain += factor;
368 break;
369 #endif /* LINE, FMRADIO */
370 #if defined(HAVE_MIC_REC)
371 case AUDIO_SRC_MIC:
372 global_settings.rec_mic_gain += factor;
373 #endif
378 * Handle automatic gain control (AGC).
379 * Change recording gain if peak_x levels are above or below
380 * target volume for specified timeouts.
382 static void auto_gain_control(int *peak_l, int *peak_r, int *balance)
384 int agc_mono;
385 short agc_mode;
386 bool increment;
388 if (*peak_l > agc_left)
389 agc_left = *peak_l;
390 else
391 agc_left -= (agc_left - *peak_l + 3) >> 2;
392 if (*peak_r > agc_right)
393 agc_right = *peak_r;
394 else
395 agc_right -= (agc_right - *peak_r + 3) >> 2;
396 agc_mono = (agc_left + agc_right) / 2;
398 agc_mode = abs(agc_preset) - 1;
399 if (agc_mode < 0) {
400 agc_enable = false;
401 return;
404 if (agc_mode != AGC_SAFETY_MODE) {
405 /* Automatic balance control - only if not in safety mode */
406 if ((agc_left > AGC_IMG) && (agc_right > AGC_IMG))
408 if (*balance < -556)
410 if (*balance > -900)
411 agc_baltime -= !(peak_time % 4); /* 0.47 - 0.75dB */
412 else if (*balance > -4125)
413 agc_baltime--; /* 0.75 - 3.00dB */
414 else if (*balance > -7579)
415 agc_baltime -= 2; /* 3.00 - 4.90dB */
416 else
417 agc_baltime -= !(peak_time % 8); /* 4.90 - inf dB */
418 if (agc_baltime > 0)
419 agc_baltime -= (peak_time % 2);
421 else if (*balance > 556)
423 if (*balance < 900)
424 agc_baltime += !(peak_time % 4);
425 else if (*balance < 4125)
426 agc_baltime++;
427 else if (*balance < 7579)
428 agc_baltime += 2;
429 else
430 agc_baltime += !(peak_time % 8);
431 if (agc_baltime < 0)
432 agc_baltime += (peak_time % 2);
435 if ((*balance * agc_baltime) < 0)
437 if (*balance < 0)
438 agc_baltime -= peak_time % 2;
439 else
440 agc_baltime += peak_time % 2;
443 increment = ((agc_risetime / 2) > agc_droptime);
445 if (agc_baltime < -agc_tbal[agc_mode])
447 if (!increment || !agc_gain_is_max(!increment, increment)) {
448 change_recording_gain(increment, !increment, increment);
449 set_gain();
451 agc_baltime = 0;
453 else if (agc_baltime > +agc_tbal[agc_mode])
455 if (!increment || !agc_gain_is_max(increment, !increment)) {
456 change_recording_gain(increment, increment, !increment);
457 set_gain();
459 agc_baltime = 0;
462 else if (!(hist_time % 4))
464 if (agc_baltime < 0)
465 agc_baltime++;
466 else
467 agc_baltime--;
471 /* Automatic gain control */
472 if ((agc_left > agc_th_hi[agc_mode]) || (agc_right > agc_th_hi[agc_mode]))
474 if ((agc_left > AGC_CLIP) || (agc_right > AGC_CLIP))
475 agc_droptime += agc_tdrop[agc_mode] /
476 (global_settings.rec_agc_cliptime + 1);
477 if (agc_left > AGC_HIGH) {
478 agc_droptime++;
479 agc_risetime=0;
480 if (agc_left > AGC_PEAK)
481 agc_droptime += 2;
483 if (agc_right > AGC_HIGH) {
484 agc_droptime++;
485 agc_risetime=0;
486 if (agc_right > AGC_PEAK)
487 agc_droptime += 2;
489 if (agc_mono > agc_th_hi[agc_mode])
490 agc_droptime++;
491 else
492 agc_droptime += !(peak_time % 2);
494 if (agc_droptime >= agc_tdrop[agc_mode])
496 change_recording_gain(false, true, true);
497 agc_droptime = 0;
498 agc_risetime = 0;
499 set_gain();
501 agc_risetime = MAX(agc_risetime - 1, 0);
503 else if (agc_mono < agc_th_lo[agc_mode])
505 if (agc_mono < (agc_th_lo[agc_mode] / 8))
506 agc_risetime += !(peak_time % 5);
507 else if (agc_mono < (agc_th_lo[agc_mode] / 2))
508 agc_risetime += 2;
509 else
510 agc_risetime++;
512 if (agc_risetime >= agc_trise[agc_mode]) {
513 if ((agc_mode != AGC_SAFETY_MODE) &&
514 (!agc_gain_is_max(true, true))) {
515 change_recording_gain(true, true, true);
516 set_gain();
518 agc_risetime = 0;
519 agc_droptime = 0;
521 agc_droptime = MAX(agc_droptime - 1, 0);
523 else if (!(peak_time % 6)) /* on target level every 1.2 sec */
525 agc_risetime = MAX(agc_risetime - 1, 0);
526 agc_droptime = MAX(agc_droptime - 1, 0);
529 #endif /* HAVE_AGC */
531 static const char* const fmtstr[] =
533 "%c%d %s", /* no decimals */
534 "%c%d.%d %s ", /* 1 decimal */
535 "%c%d.%02d %s " /* 2 decimals */
538 static char *fmt_gain(int snd, int val, char *str, int len)
540 int i, d, numdec;
541 const char *unit;
542 char sign = ' ';
544 val = sound_val2phys(snd, val);
545 if(val < 0)
547 sign = '-';
548 val = -val;
550 numdec = sound_numdecimals(snd);
551 unit = sound_unit(snd);
553 if(numdec)
555 i = val / (10*numdec);
556 d = val % (10*numdec);
557 snprintf(str, len, fmtstr[numdec], sign, i, d, unit);
559 else
560 snprintf(str, len, fmtstr[numdec], sign, val, unit);
562 return str;
565 /* the list below must match enum audio_sources in audio.h */
566 static const char* const prestr[] =
568 HAVE_MIC_IN_([AUDIO_SRC_MIC] = "R_MIC_",)
569 HAVE_LINE_REC_([AUDIO_SRC_LINEIN] = "R_LINE_",)
570 HAVE_SPDIF_IN_([AUDIO_SRC_SPDIF] = "R_SPDIF_",)
571 HAVE_FMRADIO_REC_([AUDIO_SRC_FMRADIO] = "R_FM_",)
574 char *rec_create_filename(char *buffer)
576 char ext[16];
577 const char *pref = "R_";
579 /* Directory existence and writeablility should have already been
580 * verified - do not pass NULL pointers to pcmrec */
582 if((unsigned)global_settings.rec_source < AUDIO_NUM_SOURCES)
584 pref = prestr[global_settings.rec_source];
587 strcpy(buffer, global_settings.rec_directory);
589 snprintf(ext, sizeof(ext), ".%s",
590 REC_FILE_ENDING(global_settings.rec_format));
592 #if CONFIG_RTC == 0
593 return create_numbered_filename(buffer, buffer, pref, ext, 4,
594 &file_number);
595 #else
596 /* We'll wait at least up to the start of the next second so no duplicate
597 names are created */
598 return create_datetime_filename(buffer, buffer, pref, ext, true);
599 #endif
602 #if CONFIG_RTC == 0
603 /* Hit disk to get a starting filename for the type */
604 static void rec_init_filename(void)
606 file_number = -1;
607 rec_create_filename(path_buffer);
608 file_number--;
610 #endif
612 int rec_create_directory(void)
614 int rc = 0;
615 const char * const folder = global_settings.rec_directory;
617 if (strcmp(folder, "/") && !dir_exists(folder))
619 rc = mkdir(folder);
621 if(rc < 0)
623 while (action_userabort(HZ) == false)
625 splashf(0, "%s %s",
626 str(LANG_REC_DIR_NOT_WRITABLE),
627 str(LANG_OFF_ABORT));
630 else
632 rec_status |= RCSTAT_CREATED_DIRECTORY;
633 rc = 1;
637 return rc;
640 void rec_init_recording_options(struct audio_recording_options *options)
642 options->rec_source = global_settings.rec_source;
643 options->rec_frequency = global_settings.rec_frequency;
644 options->rec_channels = global_settings.rec_channels;
645 options->rec_prerecord_time = global_settings.rec_prerecord_time;
646 #if CONFIG_CODEC == SWCODEC
647 options->rec_mono_mode = global_settings.rec_mono_mode;
648 options->rec_source_flags = 0;
649 options->enc_config.rec_format = global_settings.rec_format;
650 global_to_encoder_config(&options->enc_config);
651 #else
652 options->rec_quality = global_settings.rec_quality;
653 options->rec_editable = global_settings.rec_editable;
654 #endif
657 #if CONFIG_CODEC == SWCODEC && !defined (SIMULATOR)
658 void rec_set_source(int source, unsigned flags)
660 /* Set audio input source, power up/down devices */
661 audio_set_input_source(source, flags);
663 /* Set peakmeters for recording or reset to playback */
664 peak_meter_playback((flags & SRCF_RECORDING) == 0);
665 peak_meter_enabled = true;
667 #endif /* CONFIG_CODEC == SWCODEC && !defined (SIMULATOR) */
669 void rec_set_recording_options(struct audio_recording_options *options)
671 #if CONFIG_CODEC != SWCODEC
672 if (global_settings.rec_prerecord_time)
674 talk_buffer_steal(); /* will use the mp3 buffer */
676 #else /* == SWCODEC */
677 rec_set_source(options->rec_source,
678 options->rec_source_flags | SRCF_RECORDING);
679 #endif /* CONFIG_CODEC != SWCODEC */
681 audio_set_recording_options(options);
684 void rec_command(enum recording_command cmd)
686 switch(cmd)
688 case RECORDING_CMD_STOP_SHUTDOWN:
689 pm_activate_clipcount(false);
690 audio_stop_recording();
691 #if CONFIG_CODEC == SWCODEC
692 audio_close_recording();
693 #endif
694 sys_poweroff();
695 break;
696 case RECORDING_CMD_STOP:
697 pm_activate_clipcount(false);
698 audio_stop_recording();
699 break;
700 case RECORDING_CMD_START:
701 /* steal mp3 buffer, create unique filename and start recording */
702 pm_reset_clipcount();
703 pm_activate_clipcount(true);
704 #if CONFIG_CODEC != SWCODEC
705 talk_buffer_steal(); /* we use the mp3 buffer */
706 #endif
707 audio_record(rec_create_filename(path_buffer));
708 break;
709 case RECORDING_CMD_START_NEWFILE:
710 /* create unique filename and start recording*/
711 pm_reset_clipcount();
712 pm_activate_clipcount(true); /* just to be sure */
713 audio_new_file(rec_create_filename(path_buffer));
714 break;
715 case RECORDING_CMD_PAUSE:
716 pm_activate_clipcount(false);
717 audio_pause_recording();
718 break;
719 case RECORDING_CMD_RESUME:
720 pm_activate_clipcount(true);
721 audio_resume_recording();
722 break;
724 update_list = true;
727 /* used in trigger_listerner and recording_screen */
728 static unsigned int last_seconds = 0;
731 * Callback function so that the peak meter code can send an event
732 * to this application. This function can be passed to
733 * peak_meter_set_trigger_listener in order to activate the trigger.
735 static void trigger_listener(int trigger_status)
737 switch (trigger_status)
739 case TRIG_GO:
740 if(!(audio_status() & AUDIO_STATUS_RECORD))
742 rec_status |= RCSTAT_HAVE_RECORDED;
743 rec_command(RECORDING_CMD_START);
744 #if CONFIG_CODEC != SWCODEC
745 /* give control to mpeg thread so that it can start
746 recording */
747 yield(); yield(); yield();
748 #endif
751 /* if we're already recording this is a retrigger */
752 else
754 if((audio_status() & AUDIO_STATUS_PAUSE) &&
755 (global_settings.rec_trigger_type == TRIG_TYPE_PAUSE))
757 rec_command(RECORDING_CMD_RESUME);
759 /* New file on trig start*/
760 else if (global_settings.rec_trigger_type != TRIG_TYPE_NEW_FILE)
762 rec_command(RECORDING_CMD_START_NEWFILE);
763 /* tell recording_screen to reset the time */
764 last_seconds = 0;
767 break;
769 /* A _change_ to TRIG_READY means the current recording has stopped */
770 case TRIG_READY:
771 if(audio_status() & AUDIO_STATUS_RECORD)
773 switch(global_settings.rec_trigger_type)
775 case TRIG_TYPE_STOP: /* Stop */
776 rec_command(RECORDING_CMD_STOP);
777 break;
779 case TRIG_TYPE_PAUSE: /* Pause */
780 rec_command(RECORDING_CMD_PAUSE);
781 break;
783 case TRIG_TYPE_NEW_FILE: /* New file on trig stop*/
784 rec_command(RECORDING_CMD_START_NEWFILE);
785 /* tell recording_screen to reset the time */
786 last_seconds = 0;
787 break;
789 case 3: /* Stop and shutdown */
790 rec_command(RECORDING_CMD_STOP_SHUTDOWN);
791 break;
794 if (global_settings.rec_trigger_mode != TRIG_MODE_REARM)
796 peak_meter_set_trigger_listener(NULL);
797 peak_meter_trigger(false);
800 break;
804 /* Stuff for drawing the screen */
806 enum rec_list_items_stereo {
807 ITEM_VOLUME = 0,
808 ITEM_GAIN = 1,
809 ITEM_GAIN_L = 2,
810 ITEM_GAIN_R = 3,
811 #ifdef HAVE_AGC
812 ITEM_AGC_MODE = 4,
813 ITEM_AGC_MAXDB = 5,
814 ITEM_FILENAME = 7,
815 ITEM_COUNT = 7,
816 #else
817 ITEM_FILENAME = 7,
818 ITEM_COUNT = 5,
819 #endif
822 enum rec_list_items_mono {
823 ITEM_VOLUME_M = 0,
824 ITEM_GAIN_M = 1,
825 #ifdef HAVE_AGC
826 ITEM_AGC_MODE_M = 4,
827 ITEM_AGC_MAXDB_M = 5,
828 ITEM_FILENAME_M = 7,
829 ITEM_COUNT_M = 5,
830 #else
831 ITEM_FILENAME_M = 7,
832 ITEM_COUNT_M = 3,
833 #endif
836 #ifdef HAVE_SPDIF_REC
837 enum rec_list_items_spdif {
838 ITEM_VOLUME_D = 0,
839 #if CONFIG_CODEC == SWCODEC
840 ITEM_SAMPLERATE_D = 6,
841 ITEM_FILENAME_D = 7,
842 ITEM_COUNT_D = 3,
843 #else
844 ITEM_FILENAME_D = 7,
845 ITEM_COUNT_D = 2,
846 #endif
848 #endif
850 static int listid_to_enum[ITEM_COUNT];
852 static char * reclist_get_name(int selected_item, void * data,
853 char * buffer, size_t buffer_len)
855 char buf2[32];
856 #ifdef HAVE_AGC
857 char buf3[32];
858 #endif
859 data = data; /* not used */
860 if(selected_item >= ITEM_COUNT)
861 return "";
863 switch (listid_to_enum[selected_item])
865 case ITEM_VOLUME:
866 snprintf(buffer, buffer_len, "%s: %s", str(LANG_VOLUME),
867 fmt_gain(SOUND_VOLUME,
868 global_settings.volume,
869 buf2, sizeof(buf2)));
870 break;
871 case ITEM_GAIN:
872 #ifdef HAVE_MIC_REC
873 if(global_settings.rec_source == AUDIO_SRC_MIC)
875 /* Draw MIC recording gain */
876 snprintf(buffer, buffer_len, "%s: %s", str(LANG_GAIN),
877 fmt_gain(SOUND_MIC_GAIN,
878 global_settings.rec_mic_gain,
879 buf2, sizeof(buf2)));
881 else
882 #endif /* MIC */
884 int avg_gain = (global_settings.rec_left_gain +
885 global_settings.rec_right_gain) / 2;
886 snprintf(buffer, buffer_len, "%s: %s", str(LANG_GAIN),
887 fmt_gain(SOUND_LEFT_GAIN,
888 avg_gain,
889 buf2, sizeof(buf2)));
891 break;
892 case ITEM_GAIN_L:
893 snprintf(buffer, buffer_len, "%s: %s",
894 str(LANG_GAIN_LEFT),
895 fmt_gain(SOUND_LEFT_GAIN,
896 global_settings.rec_left_gain,
897 buf2, sizeof(buf2)));
898 break;
899 case ITEM_GAIN_R:
900 snprintf(buffer, buffer_len, "%s: %s",
901 str(LANG_GAIN_RIGHT),
902 fmt_gain(SOUND_RIGHT_GAIN,
903 global_settings.rec_right_gain,
904 buf2, sizeof(buf2)));
905 break;
906 #ifdef HAVE_AGC
907 case ITEM_AGC_MODE:
908 snprintf(buffer, buffer_len, "%s: %s",
909 str(LANG_RECORDING_AGC_PRESET),
910 agc_preset_str[agc_preset]);
911 break;
912 case ITEM_AGC_MAXDB:
913 if (agc_preset == 0)
914 snprintf(buffer, buffer_len, "%s: %s",
915 str(LANG_RECORDING_AGC_MAXGAIN),
916 fmt_gain(SOUND_LEFT_GAIN,
917 agc_maxgain, buf2, sizeof(buf2)));
918 #ifdef HAVE_MIC_REC
919 else if (global_settings.rec_source == AUDIO_SRC_MIC)
920 snprintf(buffer, buffer_len, "%s: %s (%s)",
921 str(LANG_RECORDING_AGC_MAXGAIN),
922 fmt_gain(SOUND_MIC_GAIN,
923 agc_maxgain, buf2, sizeof(buf2)),
924 fmt_gain(SOUND_MIC_GAIN,
925 agc_maxgain - global_settings.rec_mic_gain,
926 buf3, sizeof(buf3)));
927 else
928 #endif /* MIC */
929 snprintf(buffer, buffer_len, "%s: %s (%s)",
930 str(LANG_RECORDING_AGC_MAXGAIN),
931 fmt_gain(SOUND_LEFT_GAIN,
932 agc_maxgain, buf2, sizeof(buf2)),
933 fmt_gain(SOUND_LEFT_GAIN,
934 agc_maxgain -
935 (global_settings.rec_left_gain +
936 global_settings.rec_right_gain)/2,
937 buf3, sizeof(buf3)));
938 break;
939 #endif
940 #if CONFIG_CODEC == SWCODEC
941 #ifdef HAVE_SPDIF_REC
942 case ITEM_SAMPLERATE_D:
943 snprintf(buffer, buffer_len, "%s: %d",
944 str(LANG_RECORDING_FREQUENCY),
945 pcm_rec_sample_rate());
946 break;
947 #endif
948 #endif
949 case ITEM_FILENAME:
951 if(audio_status() & AUDIO_STATUS_RECORD)
953 size_t tot_len = strlen(path_buffer) +
954 strlen(str(LANG_RECORDING_FILENAME)) + 1;
955 if(tot_len > buffer_len)
957 snprintf(buffer, buffer_len, "%s %s",
958 str(LANG_RECORDING_FILENAME),
959 path_buffer + tot_len - buffer_len);
961 else
963 snprintf(buffer, buffer_len, "%s %s",
964 str(LANG_RECORDING_FILENAME), path_buffer);
967 else
969 strncpy(buffer, str(LANG_RECORDING_FILENAME), buffer_len);
971 break;
973 default:
974 return "";
976 return buffer;
980 bool recording_start_automatic = false;
982 bool recording_screen(bool no_source)
984 int button;
985 int done = -1; /* negative to re-init, positive to quit, zero to run */
986 char buf[32]; /* for preparing strings */
987 char buf2[32]; /* for preparing strings */
988 int w, h; /* character width/height */
989 int update_countdown = 0; /* refresh counter */
990 unsigned int seconds;
991 int hours, minutes;
992 int audio_stat = 0; /* status of the audio system */
993 int last_audio_stat = -1; /* previous status so we can act on changes */
994 struct viewport vp_list[NB_SCREENS], vp_top[NB_SCREENS]; /* the viewports */
996 #if CONFIG_CODEC == SWCODEC
997 int warning_counter = 0;
998 #define WARNING_PERIOD 7
999 #endif
1001 #if CONFIG_CODEC == SWCODEC
1002 #ifdef HAVE_SPDIF_REC
1003 unsigned long prev_sample_rate = 0;
1004 #endif
1005 #endif
1007 #ifdef HAVE_FMRADIO_REC
1008 /* Radio is left on if:
1009 * 1) Is was on at the start and the initial source is FM Radio
1010 * 2) 1) and the source was never changed to something else
1012 int radio_status = (global_settings.rec_source != AUDIO_SRC_FMRADIO) ?
1013 FMRADIO_OFF : get_radio_status();
1014 #endif
1015 #if (CONFIG_LED == LED_REAL)
1016 bool led_state = false;
1017 int led_countdown = 2;
1018 #endif
1019 #ifdef HAVE_AGC
1020 bool peak_read = false;
1021 bool peak_valid = false;
1022 int peak_l, peak_r;
1023 int balance = 0;
1024 #endif
1025 int oldbars, recbars = VP_SB_ALLSCREENS;
1026 int i;
1027 int pm_x[NB_SCREENS]; /* peakmeter (and trigger bar) x pos */
1028 int pm_y[NB_SCREENS]; /* peakmeter y pos */
1029 int pm_h[NB_SCREENS]; /* peakmeter height */
1030 int trig_ypos[NB_SCREENS]; /* trigger bar y pos */
1031 int trig_width[NB_SCREENS]; /* trigger bar width */
1032 bool compact_view[NB_SCREENS]; /* tweak layout tiny screens / big fonts */
1034 struct gui_synclist lists; /* the list in the bottom vp */
1035 #ifdef HAVE_FMRADIO_REC
1036 int prev_rec_source = global_settings.rec_source; /* detect source change */
1037 #endif
1039 static const unsigned char *byte_units[] = {
1040 ID2P(LANG_BYTE),
1041 ID2P(LANG_KILOBYTE),
1042 ID2P(LANG_MEGABYTE),
1043 ID2P(LANG_GIGABYTE)
1046 struct audio_recording_options rec_options;
1047 rec_status = RCSTAT_IN_RECSCREEN;
1049 #if (CONFIG_STORAGE & STORAGE_ATA) && (CONFIG_LED == LED_REAL) \
1050 && !defined(SIMULATOR)
1051 ata_set_led_enabled(false);
1052 #endif
1054 #if CONFIG_CODEC == SWCODEC
1055 /* recording_menu gets messed up: so prevent manus talking */
1056 talk_disable(true);
1057 /* audio_init_recording stops anything playing when it takes the audio
1058 buffer */
1059 #else
1060 /* Yes, we use the D/A for monitoring */
1061 peak_meter_enabled = true;
1062 peak_meter_playback(true);
1063 #endif
1065 #ifdef HAVE_AGC
1066 peak_meter_get_peakhold(&peak_l, &peak_r);
1067 #endif
1069 pm_reset_clipcount();
1070 pm_activate_clipcount(false);
1071 settings_apply_trigger();
1073 #ifdef HAVE_AGC
1074 agc_preset_str[0] = str(LANG_OFF);
1075 agc_preset_str[1] = str(LANG_AGC_SAFETY);
1076 agc_preset_str[2] = str(LANG_AGC_LIVE);
1077 agc_preset_str[3] = str(LANG_AGC_DJSET);
1078 agc_preset_str[4] = str(LANG_AGC_MEDIUM);
1079 agc_preset_str[5] = str(LANG_AGC_VOICE);
1080 #endif /* HAVE_AGC */
1082 #if CONFIG_CODEC == SWCODEC
1083 audio_close_recording();
1084 #endif
1085 audio_init_recording(0);
1086 sound_set_volume(global_settings.volume);
1088 #if CONFIG_RTC == 0
1089 /* Create new filename for recording start */
1090 rec_init_filename();
1091 #endif
1093 /* viewport init and calculations that only needs to be done once */
1094 FOR_NB_SCREENS(i)
1095 recbars |= VP_SB_IGNORE_SETTING(i);
1096 oldbars = viewportmanager_set_statusbar(recbars);
1097 FOR_NB_SCREENS(i)
1099 struct viewport *v;
1100 /* top vp, 4 lines, force sys font if total screen < 6 lines
1101 NOTE: one could limit the list to 1 line and get away with 5 lines */
1102 v = &vp_top[i];
1103 viewport_set_defaults(v, i);
1104 if (viewport_get_nb_lines(v) < 4)
1106 /* compact needs 4 lines total */
1107 v->font = FONT_SYSFIXED;
1108 compact_view[i] = false;
1110 else
1112 if (viewport_get_nb_lines(v) < (4+2)) /*top=4,list=2*/
1113 compact_view[i] = true;
1114 else
1115 compact_view[i] = false;
1117 v->height = (font_get(v->font)->height)*(compact_view[i] ? 3 : 4);
1119 /* list section, rest of the screen */
1120 v = &vp_list[i];
1121 viewport_set_defaults(v, i);
1122 v->font = vp_top[i].font;
1123 v->y = vp_top[i].y + vp_top[i].height;
1124 v->height = screens[i].lcdheight - v->y; /* the rest */
1125 screens[i].set_viewport(&vp_top[i]); /* req for next calls */
1127 screens[i].getstringsize("W", &w, &h);
1128 pm_y[i] = font_get(vp_top[i].font)->height * 2;
1129 trig_ypos[i] = font_get(vp_top[i].font)->height * 3;
1130 if(compact_view[i])
1131 trig_ypos[i] -= (font_get(vp_top[i].font)->height)/2;
1134 /* init the bottom list */
1135 gui_synclist_init(&lists, reclist_get_name, NULL, false, 1, vp_list);
1136 gui_synclist_set_title(&lists, NULL, Icon_NOICON);
1138 /* start of the loop: we stay in this loop until user quits recscreen */
1139 while(done <= 0)
1141 if(done < 0)
1143 /* request to re-init stuff, done after settings screen */
1144 done = 0;
1145 #ifdef HAVE_FMRADIO_REC
1146 /* If input changes away from FM Radio,
1147 radio will remain off when recording screen closes. */
1148 if (global_settings.rec_source != prev_rec_source
1149 && prev_rec_source == AUDIO_SRC_FMRADIO)
1150 radio_status = FMRADIO_OFF;
1151 prev_rec_source = global_settings.rec_source;
1152 #endif
1154 FOR_NB_SCREENS(i)
1156 pm_x[i] = 0;
1157 if(global_settings.peak_meter_clipcounter)
1159 int clipwidth = 0;
1160 screens[i].getstringsize(str(LANG_PM_CLIPCOUNT),
1161 &clipwidth, &h); /* h is same */
1162 pm_x[i] = clipwidth+1;
1164 if(global_settings.rec_trigger_mode == TRIG_MODE_OFF)
1165 pm_h[i] = font_get(vp_top[i].font)->height * 2;
1166 else
1167 pm_h[i] = font_get(vp_top[i].font)->height;
1168 if(compact_view[i])
1169 pm_h[i] /= 2;
1170 trig_width[i] = vp_top[i].width - pm_x[i];
1173 #if CONFIG_CODEC == SWCODEC
1174 audio_close_recording();
1175 audio_init_recording(0);
1176 #endif
1178 rec_init_recording_options(&rec_options);
1179 rec_set_recording_options(&rec_options);
1181 if(rec_create_directory() < 0)
1183 rec_status = 0;
1184 goto rec_abort;
1187 #if CONFIG_CODEC == SWCODEC && CONFIG_RTC == 0
1188 /* If format changed, a new number is required */
1189 rec_init_filename();
1190 #endif
1192 #ifdef HAVE_AGC
1193 #ifdef HAVE_MIC_REC
1194 if (global_settings.rec_source == AUDIO_SRC_MIC) {
1195 agc_preset = global_settings.rec_agc_preset_mic;
1196 agc_maxgain = global_settings.rec_agc_maxgain_mic;
1198 else
1199 #endif /* MIC */
1201 agc_preset = global_settings.rec_agc_preset_line;
1202 agc_maxgain = global_settings.rec_agc_maxgain_line;
1204 #endif /* HAVE_AGC */
1206 set_gain();
1207 update_countdown = 0; /* Update immediately */
1209 /* populate translation table for list id -> enum */
1210 #ifdef HAVE_SPDIF_REC
1211 if(global_settings.rec_source == AUDIO_SRC_SPDIF)
1213 listid_to_enum[0] = ITEM_VOLUME_D;
1214 #if CONFIG_CODEC == SWCODEC
1215 listid_to_enum[1] = ITEM_SAMPLERATE_D;
1216 listid_to_enum[2] = ITEM_FILENAME_D;
1217 #else
1218 listid_to_enum[1] = ITEM_FILENAME_D;
1219 #endif
1221 gui_synclist_set_nb_items(&lists, ITEM_COUNT_D); /* spdif */
1223 else
1224 #endif
1225 if(HAVE_MIC_REC_((global_settings.rec_source == AUDIO_SRC_MIC) || )
1226 (global_settings.rec_channels == 1))
1228 listid_to_enum[0] = ITEM_VOLUME_M;
1229 listid_to_enum[1] = ITEM_GAIN_M;
1230 #ifdef HAVE_AGC
1231 listid_to_enum[2] = ITEM_AGC_MODE_M;
1232 listid_to_enum[3] = ITEM_AGC_MAXDB_M;
1233 listid_to_enum[4] = ITEM_FILENAME_M;
1234 #else
1235 listid_to_enum[2] = ITEM_FILENAME_M;
1236 #endif
1237 gui_synclist_set_nb_items(&lists, ITEM_COUNT_M); /* mono */
1239 else
1241 listid_to_enum[0] = ITEM_VOLUME;
1242 listid_to_enum[1] = ITEM_GAIN;
1243 listid_to_enum[2] = ITEM_GAIN_L;
1244 listid_to_enum[3] = ITEM_GAIN_R;
1245 #ifdef HAVE_AGC
1246 listid_to_enum[4] = ITEM_AGC_MODE;
1247 listid_to_enum[5] = ITEM_AGC_MAXDB;
1248 listid_to_enum[6] = ITEM_FILENAME;
1249 #else
1250 listid_to_enum[4] = ITEM_FILENAME;
1251 #endif
1252 gui_synclist_set_nb_items(&lists, ITEM_COUNT); /* stereo */
1255 gui_synclist_draw(&lists);
1256 } /* if(done < 0) */
1258 audio_stat = audio_status();
1260 #if (CONFIG_LED == LED_REAL)
1263 * Flash the LED while waiting to record. Turn it on while
1264 * recording.
1266 if(audio_stat & AUDIO_STATUS_RECORD)
1268 if (audio_stat & AUDIO_STATUS_PAUSE)
1270 if (--led_countdown <= 0)
1272 led_state = !led_state;
1273 led(led_state);
1274 led_countdown = 2;
1277 else
1279 /* trigger is on in status TRIG_READY (no check needed) */
1280 led(true);
1283 else
1285 int trig_stat = peak_meter_trigger_status();
1287 * other trigger stati than trig_off and trig_steady
1288 * already imply that we are recording.
1290 if (trig_stat == TRIG_STEADY)
1292 if (--led_countdown <= 0)
1294 led_state = !led_state;
1295 led(led_state);
1296 led_countdown = 2;
1299 else
1301 /* trigger is on in status TRIG_READY (no check needed) */
1302 led(false);
1305 #endif /* CONFIG_LED */
1307 /* Wait for a button a while (HZ/10) drawing the peak meter */
1308 button = peak_meter_draw_get_btn(CONTEXT_RECSCREEN,
1309 pm_x, pm_y, pm_h,
1310 screen_update, vp_top);
1311 if (last_audio_stat != audio_stat)
1313 if (audio_stat & AUDIO_STATUS_RECORD)
1315 rec_status |= RCSTAT_HAVE_RECORDED;
1317 last_audio_stat = audio_stat;
1318 update_list = true;
1321 if (recording_start_automatic)
1323 /* simulate a button press */
1324 button = ACTION_REC_PAUSE;
1325 recording_start_automatic = false;
1328 /* let list handle the button */
1329 gui_synclist_do_button(&lists, &button, LIST_WRAP_UNLESS_HELD);
1332 switch(button)
1334 case ACTION_SETTINGS_INC:
1335 case ACTION_SETTINGS_INCREPEAT:
1336 switch (listid_to_enum[gui_synclist_get_sel_pos(&lists)])
1338 case ITEM_VOLUME:
1339 global_settings.volume++;
1340 setvol();
1341 break;
1342 case ITEM_GAIN:
1343 #ifdef HAVE_MIC_REC
1344 if(global_settings.rec_source == AUDIO_SRC_MIC)
1346 if(global_settings.rec_mic_gain <
1347 sound_max(SOUND_MIC_GAIN))
1348 global_settings.rec_mic_gain++;
1350 else
1351 #endif /* MIC */
1353 if(global_settings.rec_left_gain <
1354 sound_max(SOUND_LEFT_GAIN))
1355 global_settings.rec_left_gain++;
1356 if(global_settings.rec_right_gain <
1357 sound_max(SOUND_RIGHT_GAIN))
1358 global_settings.rec_right_gain++;
1360 break;
1361 case ITEM_GAIN_L:
1362 if(global_settings.rec_left_gain <
1363 sound_max(SOUND_LEFT_GAIN))
1364 global_settings.rec_left_gain++;
1365 break;
1366 case ITEM_GAIN_R:
1367 if(global_settings.rec_right_gain <
1368 sound_max(SOUND_RIGHT_GAIN))
1369 global_settings.rec_right_gain++;
1370 break;
1371 #ifdef HAVE_AGC
1372 case ITEM_AGC_MODE:
1373 agc_preset = MIN(agc_preset + 1, AGC_MODE_SIZE);
1374 agc_enable = (agc_preset != 0);
1375 #ifdef HAVE_MIC_REC
1376 if (global_settings.rec_source == AUDIO_SRC_MIC) {
1377 global_settings.rec_agc_preset_mic = agc_preset;
1378 agc_maxgain = global_settings.rec_agc_maxgain_mic;
1379 } else
1380 #endif /* MIC */
1382 global_settings.rec_agc_preset_line = agc_preset;
1383 agc_maxgain = global_settings.rec_agc_maxgain_line;
1385 break;
1386 case ITEM_AGC_MAXDB:
1387 #ifdef HAVE_MIC_REC
1388 if (global_settings.rec_source == AUDIO_SRC_MIC)
1390 agc_maxgain = MIN(agc_maxgain + 1,
1391 sound_max(SOUND_MIC_GAIN));
1392 global_settings.rec_agc_maxgain_mic = agc_maxgain;
1394 else
1395 #endif /* MIC */
1397 agc_maxgain = MIN(agc_maxgain + 1,
1398 sound_max(SOUND_LEFT_GAIN));
1399 global_settings.rec_agc_maxgain_line = agc_maxgain;
1401 break;
1402 #endif /* HAVE_AGC */
1404 set_gain();
1405 update_countdown = 0; /* Update immediately */
1406 break;
1407 case ACTION_SETTINGS_DEC:
1408 case ACTION_SETTINGS_DECREPEAT:
1409 switch (listid_to_enum[gui_synclist_get_sel_pos(&lists)])
1411 case ITEM_VOLUME:
1412 global_settings.volume--;
1413 setvol();
1414 break;
1415 case ITEM_GAIN:
1416 #ifdef HAVE_MIC_REC
1417 if(global_settings.rec_source == AUDIO_SRC_MIC)
1419 if(global_settings.rec_mic_gain >
1420 sound_min(SOUND_MIC_GAIN))
1421 global_settings.rec_mic_gain--;
1423 else
1424 #endif /* MIC */
1426 if(global_settings.rec_left_gain >
1427 sound_min(SOUND_LEFT_GAIN))
1428 global_settings.rec_left_gain--;
1429 if(global_settings.rec_right_gain >
1430 sound_min(SOUND_RIGHT_GAIN))
1431 global_settings.rec_right_gain--;
1433 break;
1434 case ITEM_GAIN_L:
1435 if(global_settings.rec_left_gain >
1436 sound_min(SOUND_LEFT_GAIN))
1437 global_settings.rec_left_gain--;
1438 break;
1439 case ITEM_GAIN_R:
1440 if(global_settings.rec_right_gain >
1441 sound_min(SOUND_RIGHT_GAIN))
1442 global_settings.rec_right_gain--;
1443 break;
1444 #ifdef HAVE_AGC
1445 case ITEM_AGC_MODE:
1446 agc_preset = MAX(agc_preset - 1, 0);
1447 agc_enable = (agc_preset != 0);
1448 #ifdef HAVE_MIC_REC
1449 if (global_settings.rec_source == AUDIO_SRC_MIC) {
1450 global_settings.rec_agc_preset_mic = agc_preset;
1451 agc_maxgain = global_settings.rec_agc_maxgain_mic;
1452 } else
1453 #endif /* MIC */
1455 global_settings.rec_agc_preset_line = agc_preset;
1456 agc_maxgain = global_settings.rec_agc_maxgain_line;
1458 break;
1459 case ITEM_AGC_MAXDB:
1460 #ifdef HAVE_MIC_REC
1461 if (global_settings.rec_source == AUDIO_SRC_MIC)
1463 agc_maxgain = MAX(agc_maxgain - 1,
1464 sound_min(SOUND_MIC_GAIN));
1465 global_settings.rec_agc_maxgain_mic = agc_maxgain;
1466 } else
1467 #endif /* MIC */
1469 agc_maxgain = MAX(agc_maxgain - 1,
1470 sound_min(SOUND_LEFT_GAIN));
1471 global_settings.rec_agc_maxgain_line = agc_maxgain;
1473 break;
1474 #endif /* HAVE_AGC */
1476 set_gain();
1477 update_countdown = 0; /* Update immediately */
1478 break;
1479 case ACTION_STD_CANCEL:
1480 /* turn off the trigger */
1481 peak_meter_trigger(false);
1482 peak_meter_set_trigger_listener(NULL);
1484 if(audio_stat & AUDIO_STATUS_RECORD)
1486 rec_command(RECORDING_CMD_STOP);
1488 else
1490 #if CONFIG_CODEC != SWCODEC
1491 peak_meter_playback(true);
1492 peak_meter_enabled = false;
1493 #endif
1494 done = 1;
1496 update_countdown = 0; /* Update immediately */
1497 break;
1498 #ifdef HAVE_REMOTE_LCD
1499 case ACTION_REC_LCD:
1500 /* this feature exists for some h1x0/h3x0 targets that suffer
1501 from noise caused by remote LCD updates
1502 NOTE 1: this will leave the list on the remote
1503 NOTE 2: to be replaced by a global LCD_off() routine */
1504 if(remote_display_on)
1506 /* switch to single screen, leave message on remote */
1507 screen_update = 1;
1508 screens[1].clear_viewport();
1509 screens[1].puts(0, 0, str(LANG_REMOTE_LCD_OFF));
1510 screens[1].puts(0, 1, str(LANG_REMOTE_LCD_ON));
1511 screens[1].update_viewport();
1513 else
1515 /* remote switched on again */
1516 update_list = true;
1517 screen_update = NB_SCREENS;
1519 remote_display_on = !remote_display_on; /* toggle */
1520 update_countdown = 0; /* Update immediately */
1521 break;
1522 #endif
1523 case ACTION_REC_PAUSE:
1524 case ACTION_REC_NEWFILE:
1525 /* Only act if the mpeg is stopped */
1526 if(!(audio_stat & AUDIO_STATUS_RECORD))
1528 /* is this manual or triggered recording? */
1529 if ((global_settings.rec_trigger_mode == TRIG_MODE_OFF) ||
1530 (peak_meter_trigger_status() != TRIG_OFF))
1532 /* manual recording */
1533 rec_status |= RCSTAT_HAVE_RECORDED;
1534 rec_command(RECORDING_CMD_START);
1535 last_seconds = 0;
1536 if (global_settings.talk_menu)
1538 /* no voice possible here, but a beep */
1539 audio_beep(HZ/2); /* longer beep on start */
1542 /* this is triggered recording */
1543 else
1545 /* we don't start recording now, but enable the
1546 trigger and let the callback function
1547 trigger_listener control when the recording starts */
1548 peak_meter_trigger(true);
1549 peak_meter_set_trigger_listener(&trigger_listener);
1552 else
1554 /*if new file button pressed, start new file */
1555 if (button == ACTION_REC_NEWFILE)
1557 rec_command(RECORDING_CMD_START_NEWFILE);
1558 last_seconds = 0;
1560 else
1561 /* 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);
1578 update_countdown = 0; /* Update immediately */
1579 break;
1580 case ACTION_STD_MENU:
1581 #if CONFIG_CODEC == SWCODEC
1582 if(!(audio_stat & AUDIO_STATUS_RECORD))
1583 #else
1584 if(audio_stat != AUDIO_STATUS_RECORD)
1585 #endif
1587 #if (CONFIG_LED == LED_REAL)
1588 /* led is restored at begin of loop / end of function */
1589 led(false);
1590 #endif
1591 viewportmanager_set_statusbar(oldbars);
1592 if (recording_menu(no_source))
1594 done = 1;
1595 rec_status |= RCSTAT_BEEN_IN_USB_MODE;
1596 #ifdef HAVE_FMRADIO_REC
1597 radio_status = FMRADIO_OFF;
1598 #endif
1600 else
1602 done = -1;
1603 /* the init is now done at the beginning of the loop */
1605 viewportmanager_set_statusbar(recbars);
1607 break;
1609 #if CONFIG_KEYPAD == RECORDER_PAD
1610 case ACTION_REC_F2:
1611 if(audio_stat != AUDIO_STATUS_RECORD)
1613 #if (CONFIG_LED == LED_REAL)
1614 /* led is restored at begin of loop / end of function */
1615 led(false);
1616 #endif
1617 viewportmanager_set_statusbar(oldbars);
1618 if (f2_rec_screen())
1620 rec_status |= RCSTAT_HAVE_RECORDED;
1621 done = true;
1623 else
1624 update_countdown = 0; /* Update immediately */
1625 viewportmanager_set_statusbar(recbars);
1627 break;
1629 case ACTION_REC_F3:
1630 if(audio_stat & AUDIO_STATUS_RECORD)
1632 rec_command(RECORDING_CMD_START_NEWFILE);
1633 last_seconds = 0;
1635 else
1637 #if (CONFIG_LED == LED_REAL)
1638 /* led is restored at begin of loop / end of function */
1639 led(false);
1640 #endif
1641 viewportmanager_set_statusbar(oldbars);
1642 if (f3_rec_screen())
1644 rec_status |= RCSTAT_HAVE_RECORDED;
1645 done = true;
1647 else
1648 update_countdown = 0; /* Update immediately */
1649 viewportmanager_set_statusbar(recbars);
1651 break;
1652 #endif /* CONFIG_KEYPAD == RECORDER_PAD */
1654 case SYS_USB_CONNECTED:
1655 /* Only accept USB connection when not recording */
1656 if(!(audio_stat & AUDIO_STATUS_RECORD))
1658 FOR_NB_SCREENS(i)
1659 screens[i].set_viewport(NULL);
1660 default_event_handler(SYS_USB_CONNECTED);
1661 done = true;
1662 rec_status |= RCSTAT_BEEN_IN_USB_MODE;
1663 #ifdef HAVE_FMRADIO_REC
1664 radio_status = FMRADIO_OFF;
1665 #endif
1667 break;
1668 } /*switch(button)*/
1670 #ifdef HAVE_AGC
1671 peak_read = !peak_read;
1672 if (peak_read) { /* every 2nd run of loop */
1673 peak_time++;
1674 peak_valid = read_peak_levels(&peak_l, &peak_r, &balance);
1677 /* Handle AGC every 200ms when enabled and peak data is valid */
1678 if (peak_read && agc_enable && peak_valid)
1679 auto_gain_control(&peak_l, &peak_r, &balance);
1680 #endif
1682 seconds = audio_recorded_time() / HZ;
1684 /* start of vp_top drawing */
1685 if(update_countdown-- == 0 || seconds > last_seconds)
1687 unsigned int dseconds, dhours, dminutes;
1688 unsigned long num_recorded_bytes, dsize, dmb;
1691 FOR_NB_SCREENS(i)
1693 screens[i].set_viewport(&vp_top[i]);
1694 screens[i].clear_viewport();
1696 update_countdown = 5;
1697 last_seconds = seconds;
1699 dseconds = rec_timesplit_seconds();
1700 dsize = rec_sizesplit_bytes();
1701 num_recorded_bytes = audio_num_recorded_bytes();
1703 #if CONFIG_CODEC == SWCODEC
1704 if ((audio_stat & AUDIO_STATUS_WARNING)
1705 && (warning_counter++ % WARNING_PERIOD) < WARNING_PERIOD/2)
1707 /* Switch back and forth displaying warning on first available
1708 line to ensure visibility - the motion should also help
1709 draw attention */
1710 /* Don't use language string unless agreed upon to make this
1711 method permanent - could do something in the statusbar */
1712 snprintf(buf, sizeof(buf), "Warning: %08X",
1713 pcm_rec_get_warnings());
1715 else
1716 #endif /* CONFIG_CODEC == SWCODEC */
1717 if ((global_settings.rec_sizesplit) &&
1718 (global_settings.rec_split_method))
1720 dmb = dsize/1024/1024;
1721 snprintf(buf, sizeof(buf), "%s %dMB",
1722 str(LANG_SPLIT_SIZE), dmb);
1724 else
1726 hours = seconds / 3600;
1727 minutes = (seconds - (hours * 3600)) / 60;
1728 snprintf(buf, sizeof(buf), "%s %02d:%02d:%02d",
1729 str(LANG_RECORDING_TIME),
1730 hours, minutes, seconds%60);
1733 FOR_NB_ACTIVE_SCREENS(i)
1734 screens[i].puts(0, 0, buf);
1736 if(audio_stat & AUDIO_STATUS_PRERECORD)
1738 snprintf(buf, sizeof(buf), "%s...",
1739 str(LANG_RECORD_PRERECORD));
1741 else
1743 /* Display the split interval if the record timesplit
1744 is active */
1745 if ((global_settings.rec_timesplit) &&
1746 !(global_settings.rec_split_method))
1748 /* Display the record timesplit interval rather
1749 than the file size if the record timer is active */
1750 dhours = dseconds / 3600;
1751 dminutes = (dseconds - (dhours * 3600)) / 60;
1752 snprintf(buf, sizeof(buf), "%s %02d:%02d",
1753 str(LANG_RECORDING_TIMESPLIT_REC),
1754 dhours, dminutes);
1756 else
1758 output_dyn_value(buf2, sizeof buf2,
1759 num_recorded_bytes,
1760 byte_units, true);
1761 snprintf(buf, sizeof(buf), "%s %s",
1762 str(LANG_RECORDING_SIZE), buf2);
1766 FOR_NB_ACTIVE_SCREENS(i)
1767 screens[i].puts(0, 1, buf);
1769 /* We will do file splitting regardless, either at the end of
1770 a split interval, or when the filesize approaches the 2GB
1771 FAT file size (compatibility) limit. */
1772 if ((audio_stat && !(global_settings.rec_split_method)
1773 && global_settings.rec_timesplit && (seconds >= dseconds))
1774 || (audio_stat && global_settings.rec_split_method
1775 && global_settings.rec_sizesplit
1776 && (num_recorded_bytes >= dsize))
1777 || (num_recorded_bytes >= MAX_FILE_SIZE))
1779 if (!(global_settings.rec_split_type)
1780 || (num_recorded_bytes >= MAX_FILE_SIZE))
1782 rec_command(RECORDING_CMD_START_NEWFILE);
1783 last_seconds = 0;
1785 else
1787 peak_meter_trigger(false);
1788 peak_meter_set_trigger_listener(NULL);
1789 if( global_settings.rec_split_type == 1)
1790 rec_command(RECORDING_CMD_STOP);
1791 else
1792 rec_command(RECORDING_CMD_STOP_SHUTDOWN);
1794 update_countdown = 0;
1797 /* draw the clipcounter just in front of the peakmeter */
1798 if(global_settings.peak_meter_clipcounter)
1800 char clpstr[32];
1801 snprintf(clpstr, 32, "%4d", pm_get_clipcount());
1802 FOR_NB_ACTIVE_SCREENS(i)
1804 if(!compact_view[i])
1805 screens[i].puts(0, 2,str(LANG_PM_CLIPCOUNT));
1806 screens[i].puts(0, compact_view[i] ? 2 : 3, clpstr);
1810 #ifdef HAVE_AGC
1811 hist_time++;
1812 #endif
1814 /* draw the trigger status */
1815 if (peak_meter_trigger_status() != TRIG_OFF)
1817 peak_meter_draw_trig(pm_x, trig_ypos, trig_width,
1818 screen_update);
1819 FOR_NB_ACTIVE_SCREENS(i)
1820 screens[i].update_viewport_rect(pm_x[i], trig_ypos[i],
1821 trig_width[i] + 2, TRIG_HEIGHT);
1824 #ifdef HAVE_AGC
1825 #ifdef HAVE_MIC_REC
1826 if (global_settings.rec_source == AUDIO_SRC_MIC)
1828 if(agc_maxgain < (global_settings.rec_mic_gain))
1829 change_recording_gain(false, true, true);
1831 else
1832 #endif /* MIC */
1834 if(agc_maxgain < (global_settings.rec_left_gain))
1835 change_recording_gain(false, true, false);
1836 if(agc_maxgain < (global_settings.rec_right_gain))
1837 change_recording_gain(false, false, true);
1839 #endif /* HAVE_AGC */
1841 #if CONFIG_CODEC == SWCODEC
1842 #ifdef HAVE_SPDIF_REC
1843 if((global_settings.rec_source == AUDIO_SRC_SPDIF) &&
1844 (prev_sample_rate != pcm_rec_sample_rate()))
1846 /* spdif samplerate changed */
1847 prev_sample_rate = pcm_rec_sample_rate();
1848 update_list = true;
1850 #endif
1851 #endif
1853 if(update_list)
1855 /* update_list is set whenever content changes */
1856 update_list = false;
1857 gui_synclist_draw(&lists);
1860 /* draw peakmeter again (check if this can be removed) */
1861 FOR_NB_ACTIVE_SCREENS(i)
1863 screens[i].set_viewport(&vp_top[i]);
1864 peak_meter_screen(&screens[i], pm_x[i], pm_y[i], pm_h[i]);
1865 screens[i].update();
1867 } /* display update every second */
1869 if(audio_stat & AUDIO_STATUS_ERROR)
1871 done = true;
1873 } /* end while(!done) */
1875 audio_stat = audio_status();
1876 if (audio_stat & AUDIO_STATUS_ERROR)
1878 splash(0, str(LANG_DISK_FULL));
1880 FOR_NB_SCREENS(i)
1881 screens[i].update();
1883 #if CONFIG_CODEC == SWCODEC
1884 /* stop recording - some players like H10 freeze otherwise
1885 TO DO: find out why it freezes and fix properly */
1886 rec_command(RECORDING_CMD_STOP);
1887 audio_close_recording();
1888 #endif
1890 audio_error_clear();
1892 while(1)
1894 if (action_userabort(TIMEOUT_NOBLOCK))
1895 break;
1899 rec_abort:
1901 #if CONFIG_CODEC == SWCODEC
1902 rec_command(RECORDING_CMD_STOP);
1903 audio_close_recording();
1905 #ifdef HAVE_FMRADIO_REC
1906 if (radio_status != FMRADIO_OFF)
1907 /* Restore radio playback - radio_status should be unchanged if started
1908 through fm radio screen (barring usb connect) */
1909 rec_set_source(AUDIO_SRC_FMRADIO, (radio_status & FMRADIO_PAUSED) ?
1910 SRCF_FMRADIO_PAUSED : SRCF_FMRADIO_PLAYING);
1911 else
1912 #endif
1913 /* Go back to playback mode */
1914 rec_set_source(AUDIO_SRC_PLAYBACK, SRCF_PLAYBACK);
1916 /* restore talking */
1917 talk_disable(false);
1918 #else /* !SWCODEC */
1919 audio_init_playback();
1920 #endif /* CONFIG_CODEC == SWCODEC */
1922 /* make sure the trigger is really turned off */
1923 peak_meter_trigger(false);
1924 peak_meter_set_trigger_listener(NULL);
1926 rec_status &= ~RCSTAT_IN_RECSCREEN;
1927 sound_settings_apply();
1929 viewportmanager_set_statusbar(oldbars);
1930 FOR_NB_SCREENS(i)
1931 screens[i].setfont(FONT_UI);
1933 /* if the directory was created or recording happened, make sure the
1934 browser is updated */
1935 if (rec_status & (RCSTAT_CREATED_DIRECTORY | RCSTAT_HAVE_RECORDED))
1936 reload_directory();
1938 #if (CONFIG_STORAGE & STORAGE_ATA) && (CONFIG_LED == LED_REAL) \
1939 && !defined(SIMULATOR)
1940 ata_set_led_enabled(true);
1941 #endif
1943 settings_save();
1945 return (rec_status & RCSTAT_BEEN_IN_USB_MODE) != 0;
1946 } /* recording_screen */
1948 #if CONFIG_KEYPAD == RECORDER_PAD
1949 static bool f2_rec_screen(void)
1951 static const char* const freq_str[6] =
1953 "44.1kHz",
1954 "48kHz",
1955 "32kHz",
1956 "22.05kHz",
1957 "24kHz",
1958 "16kHz"
1961 bool exit = false;
1962 bool used = false;
1963 int w, h, i;
1964 char buf[32];
1965 int button;
1966 struct audio_recording_options rec_options;
1968 FOR_NB_SCREENS(i)
1970 screens[i].setfont(FONT_SYSFIXED);
1971 screens[i].getstringsize("A",&w,&h);
1974 while (!exit) {
1975 const char* ptr=NULL;
1977 FOR_NB_SCREENS(i)
1979 screens[i].clear_display();
1981 /* Recording quality */
1982 screens[i].putsxy(0, LCD_HEIGHT/2 - h*2,
1983 str(LANG_SYSFONT_RECORDING_QUALITY));
1986 snprintf(buf, sizeof(buf), "%d", global_settings.rec_quality);
1987 FOR_NB_SCREENS(i)
1989 screens[i].putsxy(0, LCD_HEIGHT/2-h, buf);
1990 screens[i].mono_bitmap(bitmap_icons_7x8[Icon_FastBackward],
1991 LCD_WIDTH/2 - 16, LCD_HEIGHT/2 - 4, 7, 8);
1994 /* Frequency */
1995 snprintf(buf, sizeof buf, "%s:", str(LANG_SYSFONT_RECORDING_FREQUENCY));
1996 ptr = freq_str[global_settings.rec_frequency];
1997 FOR_NB_SCREENS(i)
1999 screens[i].getstringsize(buf,&w,&h);
2000 screens[i].putsxy((LCD_WIDTH-w)/2, LCD_HEIGHT - h*2, buf);
2001 screens[i].getstringsize(ptr, &w, &h);
2002 screens[i].putsxy((LCD_WIDTH-w)/2, LCD_HEIGHT - h, ptr);
2003 screens[i].mono_bitmap(bitmap_icons_7x8[Icon_DownArrow],
2004 LCD_WIDTH/2 - 3, LCD_HEIGHT - h*3, 7, 8);
2007 /* Channel mode */
2008 switch ( global_settings.rec_channels ) {
2009 case 0:
2010 ptr = str(LANG_SYSFONT_CHANNEL_STEREO);
2011 break;
2013 case 1:
2014 ptr = str(LANG_SYSFONT_CHANNEL_MONO);
2015 break;
2018 FOR_NB_SCREENS(i)
2020 screens[i].getstringsize(str(LANG_SYSFONT_CHANNELS), &w, &h);
2021 screens[i].putsxy(LCD_WIDTH - w, LCD_HEIGHT/2 - h*2,
2022 str(LANG_SYSFONT_CHANNELS));
2023 screens[i].getstringsize(str(LANG_SYSFONT_MODE), &w, &h);
2024 screens[i].putsxy(LCD_WIDTH - w, LCD_HEIGHT/2 - h,
2025 str(LANG_SYSFONT_MODE));
2026 screens[i].getstringsize(ptr, &w, &h);
2027 screens[i].putsxy(LCD_WIDTH - w, LCD_HEIGHT/2, ptr);
2028 screens[i].mono_bitmap(bitmap_icons_7x8[Icon_FastForward],
2029 LCD_WIDTH/2 + 8, LCD_HEIGHT/2 - 4, 7, 8);
2031 screens[i].update();
2034 button = button_get(true);
2035 switch (button) {
2036 case BUTTON_LEFT:
2037 case BUTTON_F2 | BUTTON_LEFT:
2038 global_settings.rec_quality++;
2039 if(global_settings.rec_quality > 7)
2040 global_settings.rec_quality = 0;
2041 used = true;
2042 break;
2044 case BUTTON_DOWN:
2045 case BUTTON_F2 | BUTTON_DOWN:
2046 global_settings.rec_frequency++;
2047 if(global_settings.rec_frequency > 5)
2048 global_settings.rec_frequency = 0;
2049 used = true;
2050 break;
2052 case BUTTON_RIGHT:
2053 case BUTTON_F2 | BUTTON_RIGHT:
2054 global_settings.rec_channels++;
2055 if(global_settings.rec_channels > 1)
2056 global_settings.rec_channels = 0;
2057 used = true;
2058 break;
2060 case BUTTON_F2 | BUTTON_REL:
2061 if ( used )
2062 exit = true;
2063 used = true;
2064 break;
2066 case BUTTON_F2 | BUTTON_REPEAT:
2067 used = true;
2068 break;
2070 default:
2071 if(default_event_handler(button) == SYS_USB_CONNECTED)
2072 return true;
2073 break;
2077 rec_init_recording_options(&rec_options);
2078 rec_set_recording_options(&rec_options);
2080 set_gain();
2082 settings_save();
2083 FOR_NB_SCREENS(i)
2084 screens[i].setfont(FONT_UI);
2086 return false;
2089 static bool f3_rec_screen(void)
2091 bool exit = false;
2092 bool used = false;
2093 int w, h, i;
2094 int button;
2095 char *src_str[] =
2097 str(LANG_SYSFONT_RECORDING_SRC_MIC),
2098 str(LANG_SYSFONT_LINE_IN),
2099 str(LANG_SYSFONT_RECORDING_SRC_DIGITAL)
2101 struct audio_recording_options rec_options;
2103 FOR_NB_SCREENS(i)
2105 screens[i].setfont(FONT_SYSFIXED);
2106 screens[i].getstringsize("A",&w,&h);
2109 while (!exit) {
2110 char* ptr=NULL;
2111 ptr = src_str[global_settings.rec_source];
2112 FOR_NB_SCREENS(i)
2114 screens[i].clear_display();
2116 /* Recording source */
2117 screens[i].putsxy(0, LCD_HEIGHT/2 - h*2,
2118 str(LANG_SYSFONT_RECORDING_SOURCE));
2120 screens[i].getstringsize(ptr, &w, &h);
2121 screens[i].putsxy(0, LCD_HEIGHT/2-h, ptr);
2122 screens[i].mono_bitmap(bitmap_icons_7x8[Icon_FastBackward],
2123 LCD_WIDTH/2 - 16, LCD_HEIGHT/2 - 4, 7, 8);
2126 /* trigger setup */
2127 ptr = str(LANG_SYSFONT_RECORD_TRIGGER);
2128 FOR_NB_SCREENS(i)
2130 screens[i].getstringsize(ptr,&w,&h);
2131 screens[i].putsxy((LCD_WIDTH-w)/2, LCD_HEIGHT - h*2, ptr);
2132 screens[i].mono_bitmap(bitmap_icons_7x8[Icon_DownArrow],
2133 LCD_WIDTH/2 - 3, LCD_HEIGHT - h*3, 7, 8);
2135 screens[i].update();
2138 button = button_get(true);
2139 switch (button) {
2140 case BUTTON_DOWN:
2141 case BUTTON_F3 | BUTTON_DOWN:
2142 #ifndef SIMULATOR
2143 rectrigger();
2144 settings_apply_trigger();
2145 #endif
2146 exit = true;
2147 break;
2149 case BUTTON_LEFT:
2150 case BUTTON_F3 | BUTTON_LEFT:
2151 global_settings.rec_source++;
2152 if(global_settings.rec_source > AUDIO_SRC_MAX)
2153 global_settings.rec_source = 0;
2154 used = true;
2155 break;
2157 case BUTTON_F3 | BUTTON_REL:
2158 if ( used )
2159 exit = true;
2160 used = true;
2161 break;
2163 case BUTTON_F3 | BUTTON_REPEAT:
2164 used = true;
2165 break;
2167 default:
2168 if(default_event_handler(button) == SYS_USB_CONNECTED)
2169 return true;
2170 break;
2174 rec_init_recording_options(&rec_options);
2175 rec_set_recording_options(&rec_options);
2177 set_gain();
2179 settings_save();
2180 FOR_NB_SCREENS(i)
2181 screens[i].setfont(FONT_UI);
2183 return false;
2185 #endif /* CONFIG_KEYPAD == RECORDER_PAD */
2187 #if CONFIG_CODEC == SWCODEC
2188 void audio_beep(int duration)
2190 /* dummy */
2191 (void)duration;
2194 #ifdef SIMULATOR
2195 /* stubs for recording sim */
2196 void audio_init_recording(unsigned int buffer_offset)
2198 buffer_offset = buffer_offset;
2201 void audio_close_recording(void)
2205 unsigned long pcm_rec_get_warnings(void)
2207 return 0;
2210 unsigned long pcm_rec_sample_rate(void)
2212 return 0;
2215 unsigned long audio_recorded_time(void)
2217 return 123;
2220 unsigned long audio_num_recorded_bytes(void)
2222 return 5 * 1024 * 1024;
2225 void rec_set_source(int source, unsigned flags)
2227 source = source;
2228 flags = flags;
2231 void audio_set_recording_options(struct audio_recording_options *options)
2233 options = options;
2236 void audio_set_recording_gain(int left, int right, int type)
2238 left = left;
2239 right = right;
2240 type = type;
2243 void audio_record(const char *filename)
2245 filename = filename;
2248 void audio_new_file(const char *filename)
2250 filename = filename;
2253 void audio_stop_recording(void)
2257 void audio_pause_recording(void)
2261 void audio_resume_recording(void)
2265 #endif /* #ifdef SIMULATOR */
2266 #endif /* #ifdef CONFIG_CODEC == SWCODEC */
2268 #endif /* HAVE_RECORDING */