Refactor and unify objcopy calls in the build system. Also now properly handles DEBUG...
[maemo-rb.git] / apps / recorder / recording.c
blobe3a976b7ac537c5fa60737de3599ad03591ced2e
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 "audio.h"
34 #if CONFIG_CODEC == SWCODEC
35 #include "thread.h"
36 #include "enc_config.h"
37 #include "playback.h"
38 #if defined(HAVE_SPDIF_IN) || defined(HAVE_SPDIF_OUT)
39 #include "spdif.h"
40 #endif
41 #endif /* CONFIG_CODEC == SWCODEC */
42 #include "pcm_record.h"
43 #include "recording.h"
44 #include "mp3_playback.h"
45 #include "button.h"
46 #include "kernel.h"
47 #include "settings.h"
48 #include "lang.h"
49 #include "font.h"
50 #include "icons.h"
51 #include "icon.h"
52 #include "screens.h"
53 #include "peakmeter.h"
54 #include "menu.h"
55 #include "sound_menu.h"
56 #include "timefuncs.h"
57 #include "debug.h"
58 #include "misc.h"
59 #include "filefuncs.h"
60 #include "tree.h"
61 #include "string.h"
62 #include "dir.h"
63 #include "errno.h"
64 #include "talk.h"
65 #include "sound.h"
66 #include "storage.h"
67 #if (CONFIG_STORAGE & STORAGE_ATA) && (CONFIG_LED == LED_REAL) \
68 && !defined(SIMULATOR)
69 #include "ata.h"
70 #endif
71 #include "splash.h"
72 #include "screen_access.h"
73 #include "action.h"
74 #include "radio.h"
75 #include "viewport.h"
76 #include "list.h"
77 #include "general.h"
78 #include "appevents.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(int 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;
224 static short peak_valid_mem[4];
225 #define BAL_MEM_SIZE 24
226 static short balance_mem[BAL_MEM_SIZE];
228 /* Automatic Gain Control */
229 #define AGC_MODE_SIZE 5
230 #define AGC_SAFETY_MODE 0
232 static const char* agc_preset_str[] =
233 { "Off", "S", "L", "D", "M", "V" };
234 /* "Off",
235 "Safety (clip)",
236 "Live (slow)",
237 "DJ-Set (slow)",
238 "Medium",
239 "Voice (fast)" */
240 #define AGC_CLIP 32766
241 #define AGC_PEAK 29883 /* fast gain reduction threshold -0.8dB */
242 #define AGC_HIGH 27254 /* accelerated gain reduction threshold -1.6dB */
243 #define AGC_IMG 823 /* threshold for balance control -32dB */
244 /* autogain high level thresholds (-3dB, -7dB, -4dB, -5dB, -5dB) */
245 static const short agc_th_hi[AGC_MODE_SIZE] =
246 { 23197, 14637, 21156, 18428, 18426 };
247 /* autogain low level thresholds (-14dB, -11dB, -6dB, -7dB, -8dB) */
248 static const short agc_th_lo[AGC_MODE_SIZE] =
249 { 6538, 9235, 16422, 14636, 13045 };
250 /* autogain threshold times [1/5s] or [200ms] */
251 static const short agc_tdrop[AGC_MODE_SIZE] =
252 { 900, 225, 150, 60, 8 };
253 static const short agc_trise[AGC_MODE_SIZE] =
254 { 9000, 750, 400, 150, 20 };
255 static const short agc_tbal[AGC_MODE_SIZE] =
256 { 4500, 500, 300, 100, 15 };
257 /* AGC operation */
258 static bool agc_enable = true;
259 static short agc_preset;
260 /* AGC levels */
261 static int agc_left = 0;
262 static int agc_right = 0;
263 /* AGC time since high target volume was exceeded */
264 static short agc_droptime = 0;
265 /* AGC time since volume fallen below low target */
266 static short agc_risetime = 0;
267 /* AGC balance time exceeding +/- 0.7dB */
268 static short agc_baltime = 0;
269 /* AGC maximum gain */
270 static short agc_maxgain;
271 #endif /* HAVE_AGC */
272 #if defined(HAVE_AGC)
273 static long hist_time = 0;
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 if (global_settings.rec_mic_gain > sound_max(SOUND_MIC_GAIN))
282 global_settings.rec_mic_gain = sound_max(SOUND_MIC_GAIN);
284 if (global_settings.rec_mic_gain < sound_min(SOUND_MIC_GAIN))
285 global_settings.rec_mic_gain = sound_min(SOUND_MIC_GAIN);
287 audio_set_recording_gain(global_settings.rec_mic_gain,
288 0, AUDIO_GAIN_MIC);
290 else
291 #endif /* MIC */
293 if (global_settings.rec_left_gain > sound_max(SOUND_LEFT_GAIN))
294 global_settings.rec_left_gain = sound_max(SOUND_LEFT_GAIN);
296 if (global_settings.rec_left_gain < sound_min(SOUND_LEFT_GAIN))
297 global_settings.rec_left_gain = sound_min(SOUND_LEFT_GAIN);
299 if (global_settings.rec_right_gain > sound_max(SOUND_RIGHT_GAIN))
300 global_settings.rec_right_gain = sound_max(SOUND_RIGHT_GAIN);
302 if (global_settings.rec_right_gain < sound_min(SOUND_RIGHT_GAIN))
303 global_settings.rec_right_gain = sound_min(SOUND_RIGHT_GAIN);
305 /* AUDIO_SRC_LINEIN, AUDIO_SRC_FMRADIO, AUDIO_SRC_SPDIF */
306 audio_set_recording_gain(global_settings.rec_left_gain,
307 global_settings.rec_right_gain,
308 AUDIO_GAIN_LINEIN);
310 /* reset the clipping indicators */
311 peak_meter_set_clip_hold(global_settings.peak_meter_clip_hold);
312 update_list = true;
315 #ifdef HAVE_AGC
316 /* Read peak meter values & calculate balance.
317 * Returns validity of peak values.
318 * Used for automatic gain control and history diagram.
320 static bool read_peak_levels(int *peak_l, int *peak_r, int *balance)
322 peak_meter_get_peakhold(peak_l, peak_r);
323 peak_valid_mem[peak_time % 3] = *peak_l;
324 if (((peak_valid_mem[0] == peak_valid_mem[1]) &&
325 (peak_valid_mem[1] == peak_valid_mem[2])) &&
326 ((*peak_l < 32767) || storage_disk_is_active()))
327 return false;
329 if (*peak_r > *peak_l)
330 balance_mem[peak_time % BAL_MEM_SIZE] = (*peak_l ?
331 MIN((10000 * *peak_r) / *peak_l - 10000, 15118) : 15118);
332 else
333 balance_mem[peak_time % BAL_MEM_SIZE] = (*peak_r ?
334 MAX(10000 - (10000 * *peak_l) / *peak_r, -15118) : -15118);
335 *balance = 0;
336 int i;
337 for (i = 0; i < BAL_MEM_SIZE; i++)
338 *balance += balance_mem[i];
339 *balance = *balance / BAL_MEM_SIZE;
341 return true;
344 /* AGC helper function to check if maximum gain is reached */
345 static bool agc_gain_is_max(bool left, bool right)
347 /* range -128...+108 [0.5dB] */
348 short gain_current_l;
349 short gain_current_r;
351 if (agc_preset == 0)
352 return false;
354 switch (global_settings.rec_source)
356 #if defined(HAVE_LINE_REC) || defined(HAVE_FMRADIO_REC)
357 HAVE_LINE_REC_(case AUDIO_SRC_LINEIN:)
358 HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO:)
359 gain_current_l = global_settings.rec_left_gain;
360 gain_current_r = global_settings.rec_right_gain;
361 break;
362 #endif /* LINE, FMRADIO */
363 #if defined(HAVE_MIC_REC)
364 case AUDIO_SRC_MIC:
365 default:
366 gain_current_l = global_settings.rec_mic_gain;
367 gain_current_r = global_settings.rec_mic_gain;
368 #endif /* MIC */
371 return ((left && (gain_current_l >= agc_maxgain)) ||
372 (right && (gain_current_r >= agc_maxgain)));
375 static void change_recording_gain(bool increment, bool left, bool right)
377 int factor = (increment ? 1 : -1);
379 switch (global_settings.rec_source)
381 #if defined(HAVE_LINE_REC) || defined(HAVE_FMRADIO_REC)
382 HAVE_LINE_REC_(case AUDIO_SRC_LINEIN:)
383 HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO:)
384 if (left) global_settings.rec_left_gain +=
385 factor * sound_steps(SOUND_LEFT_GAIN);
386 if (right) global_settings.rec_right_gain +=
387 factor * sound_steps(SOUND_RIGHT_GAIN);
388 break;
389 #endif /* LINE, FMRADIO */
390 #if defined(HAVE_MIC_REC)
391 case AUDIO_SRC_MIC:
392 global_settings.rec_mic_gain += factor * sound_steps(SOUND_MIC_GAIN);
393 #endif
398 * Handle automatic gain control (AGC).
399 * Change recording gain if peak_x levels are above or below
400 * target volume for specified timeouts.
402 static void auto_gain_control(int *peak_l, int *peak_r, int *balance)
404 int agc_mono;
405 short agc_mode;
406 bool increment;
408 if (*peak_l > agc_left)
409 agc_left = *peak_l;
410 else
411 agc_left -= (agc_left - *peak_l + 3) >> 2;
412 if (*peak_r > agc_right)
413 agc_right = *peak_r;
414 else
415 agc_right -= (agc_right - *peak_r + 3) >> 2;
416 agc_mono = (agc_left + agc_right) / 2;
418 agc_mode = abs(agc_preset) - 1;
419 if (agc_mode < 0) {
420 agc_enable = false;
421 return;
424 if (agc_mode != AGC_SAFETY_MODE) {
425 /* Automatic balance control - only if not in safety mode */
426 if ((agc_left > AGC_IMG) && (agc_right > AGC_IMG))
428 if (*balance < -556)
430 if (*balance > -900)
431 agc_baltime -= !(peak_time % 4); /* 0.47 - 0.75dB */
432 else if (*balance > -4125)
433 agc_baltime--; /* 0.75 - 3.00dB */
434 else if (*balance > -7579)
435 agc_baltime -= 2; /* 3.00 - 4.90dB */
436 else
437 agc_baltime -= !(peak_time % 8); /* 4.90 - inf dB */
438 if (agc_baltime > 0)
439 agc_baltime -= (peak_time % 2);
441 else if (*balance > 556)
443 if (*balance < 900)
444 agc_baltime += !(peak_time % 4);
445 else if (*balance < 4125)
446 agc_baltime++;
447 else if (*balance < 7579)
448 agc_baltime += 2;
449 else
450 agc_baltime += !(peak_time % 8);
451 if (agc_baltime < 0)
452 agc_baltime += (peak_time % 2);
455 if ((*balance * agc_baltime) < 0)
457 if (*balance < 0)
458 agc_baltime -= peak_time % 2;
459 else
460 agc_baltime += peak_time % 2;
463 increment = ((agc_risetime / 2) > agc_droptime);
465 if (agc_baltime < -agc_tbal[agc_mode])
467 if (!increment || !agc_gain_is_max(!increment, increment)) {
468 change_recording_gain(increment, !increment, increment);
469 set_gain();
471 agc_baltime = 0;
473 else if (agc_baltime > +agc_tbal[agc_mode])
475 if (!increment || !agc_gain_is_max(increment, !increment)) {
476 change_recording_gain(increment, increment, !increment);
477 set_gain();
479 agc_baltime = 0;
482 else if (!(hist_time % 4))
484 if (agc_baltime < 0)
485 agc_baltime++;
486 else
487 agc_baltime--;
491 /* Automatic gain control */
492 if ((agc_left > agc_th_hi[agc_mode]) || (agc_right > agc_th_hi[agc_mode]))
494 if ((agc_left > AGC_CLIP) || (agc_right > AGC_CLIP))
495 agc_droptime += agc_tdrop[agc_mode] /
496 (global_settings.rec_agc_cliptime + 1);
497 if (agc_left > AGC_HIGH) {
498 agc_droptime++;
499 agc_risetime = 0;
500 if (agc_left > AGC_PEAK)
501 agc_droptime += 2;
503 if (agc_right > AGC_HIGH) {
504 agc_droptime++;
505 agc_risetime=0;
506 if (agc_right > AGC_PEAK)
507 agc_droptime += 2;
509 if (agc_mono > agc_th_hi[agc_mode])
510 agc_droptime++;
511 else
512 agc_droptime += !(peak_time % 2);
514 if (agc_droptime >= agc_tdrop[agc_mode])
516 change_recording_gain(false, true, true);
517 agc_droptime = 0;
518 agc_risetime = 0;
519 set_gain();
521 agc_risetime = MAX(agc_risetime - 1, 0);
523 else if (agc_mono < agc_th_lo[agc_mode])
525 if (agc_mono < (agc_th_lo[agc_mode] / 8))
526 agc_risetime += !(peak_time % 5);
527 else if (agc_mono < (agc_th_lo[agc_mode] / 2))
528 agc_risetime += 2;
529 else
530 agc_risetime++;
532 if (agc_risetime >= agc_trise[agc_mode]) {
533 if ((agc_mode != AGC_SAFETY_MODE) &&
534 (!agc_gain_is_max(true, true))) {
535 change_recording_gain(true, true, true);
536 set_gain();
538 agc_risetime = 0;
539 agc_droptime = 0;
541 agc_droptime = MAX(agc_droptime - 1, 0);
543 else if (!(peak_time % 6)) /* on target level every 1.2 sec */
545 agc_risetime = MAX(agc_risetime - 1, 0);
546 agc_droptime = MAX(agc_droptime - 1, 0);
549 #endif /* HAVE_AGC */
551 static const char* const fmtstr[] =
553 "%c%d %s", /* no decimals */
554 "%c%d.%d %s ", /* 1 decimal */
555 "%c%d.%02d %s " /* 2 decimals */
558 static const char factor[] = {1, 10, 100};
560 static char *fmt_gain(int snd, int val, char *str, int len)
562 int i, d, numdec;
563 const char *unit;
564 char sign = ' ';
566 val = sound_val2phys(snd, val);
567 if(val < 0)
569 sign = '-';
570 val = -val;
572 numdec = sound_numdecimals(snd);
573 unit = sound_unit(snd);
575 if(numdec)
577 i = val / factor[numdec];
578 d = val % factor[numdec];
579 snprintf(str, len, fmtstr[numdec], sign, i, d, unit);
581 else
582 snprintf(str, len, fmtstr[numdec], sign, val, unit);
584 return str;
587 /* the list below must match enum audio_sources in audio.h */
588 static const char* const prestr[] =
590 HAVE_MIC_IN_([AUDIO_SRC_MIC] = "R_MIC_",)
591 HAVE_LINE_REC_([AUDIO_SRC_LINEIN] = "R_LINE_",)
592 HAVE_SPDIF_IN_([AUDIO_SRC_SPDIF] = "R_SPDIF_",)
593 HAVE_FMRADIO_REC_([AUDIO_SRC_FMRADIO] = "R_FM_",)
596 char *rec_create_filename(char *buffer)
598 char ext[16];
599 const char *pref = "R_";
601 /* Directory existence and writeablility should have already been
602 * verified - do not pass NULL pointers to pcmrec */
604 if((unsigned)global_settings.rec_source < AUDIO_NUM_SOURCES)
606 pref = prestr[global_settings.rec_source];
609 strcpy(buffer, !strcmp(global_settings.rec_directory, "/")?
610 "": global_settings.rec_directory);
612 snprintf(ext, sizeof(ext), ".%s",
613 REC_FILE_ENDING(global_settings.rec_format));
615 #if CONFIG_RTC == 0
616 return create_numbered_filename(buffer, buffer, pref, ext, 4,
617 &file_number);
618 #else
619 /* We'll wait at least up to the start of the next second so no duplicate
620 names are created */
621 return create_datetime_filename(buffer, buffer, pref, ext, true);
622 #endif
625 #if CONFIG_RTC == 0
626 /* Hit disk to get a starting filename for the type */
627 static void rec_init_filename(void)
629 file_number = -1;
630 rec_create_filename(path_buffer);
631 file_number--;
633 #endif
635 int rec_create_directory(void)
637 int rc = 0;
638 const char * const folder = global_settings.rec_directory;
640 if (strcmp(folder, "/") && !dir_exists(folder))
642 rc = mkdir(folder);
644 if(rc < 0)
646 while (action_userabort(HZ) == false)
648 splashf(0, "%s %s",
649 str(LANG_REC_DIR_NOT_WRITABLE),
650 str(LANG_OFF_ABORT));
653 else
655 rec_status |= RCSTAT_CREATED_DIRECTORY;
656 rc = 1;
660 return rc;
663 void rec_init_recording_options(struct audio_recording_options *options)
665 options->rec_source = global_settings.rec_source;
666 options->rec_frequency = global_settings.rec_frequency;
667 options->rec_channels = global_settings.rec_channels;
668 options->rec_prerecord_time = global_settings.rec_prerecord_time;
669 #if CONFIG_CODEC == SWCODEC
670 options->rec_mono_mode = global_settings.rec_mono_mode;
671 options->rec_source_flags = 0;
672 options->enc_config.rec_format = global_settings.rec_format;
673 global_to_encoder_config(&options->enc_config);
674 #else
675 options->rec_quality = global_settings.rec_quality;
676 options->rec_editable = global_settings.rec_editable;
677 #endif
680 #if CONFIG_CODEC == SWCODEC
681 void rec_set_source(int source, unsigned flags)
683 /* Set audio input source, power up/down devices */
684 audio_set_input_source(source, flags);
686 /* Set peakmeters for recording or reset to playback */
687 peak_meter_playback((flags & SRCF_RECORDING) == 0);
688 peak_meter_enable(true);
690 #endif /* CONFIG_CODEC == SWCODEC */
692 void rec_set_recording_options(struct audio_recording_options *options)
694 #if CONFIG_CODEC != SWCODEC
695 if (global_settings.rec_prerecord_time)
697 talk_buffer_steal(); /* will use the mp3 buffer */
699 #else /* == SWCODEC */
700 rec_set_source(options->rec_source,
701 options->rec_source_flags | SRCF_RECORDING);
702 #endif /* CONFIG_CODEC != SWCODEC */
704 audio_set_recording_options(options);
707 void rec_command(enum recording_command cmd)
709 switch(cmd)
711 case RECORDING_CMD_STOP_SHUTDOWN:
712 pm_activate_clipcount(false);
713 audio_stop_recording();
714 #if CONFIG_CODEC == SWCODEC
715 audio_close_recording();
716 #endif
717 sys_poweroff();
718 break;
719 case RECORDING_CMD_STOP:
720 pm_activate_clipcount(false);
721 audio_stop_recording();
722 break;
723 case RECORDING_CMD_START:
724 /* steal mp3 buffer, create unique filename and start recording */
725 pm_reset_clipcount();
726 pm_activate_clipcount(true);
727 #if CONFIG_CODEC != SWCODEC
728 talk_buffer_steal(); /* we use the mp3 buffer */
729 #endif
730 audio_record(rec_create_filename(path_buffer));
731 break;
732 case RECORDING_CMD_START_NEWFILE:
733 /* create unique filename and start recording*/
734 pm_reset_clipcount();
735 pm_activate_clipcount(true); /* just to be sure */
736 audio_new_file(rec_create_filename(path_buffer));
737 break;
738 case RECORDING_CMD_PAUSE:
739 pm_activate_clipcount(false);
740 audio_pause_recording();
741 break;
742 case RECORDING_CMD_RESUME:
743 pm_activate_clipcount(true);
744 audio_resume_recording();
745 break;
747 update_list = true;
750 /* used in trigger_listerner and recording_screen */
751 static unsigned int last_seconds = 0;
754 * Callback function so that the peak meter code can send an event
755 * to this application. This function can be passed to
756 * peak_meter_set_trigger_listener in order to activate the trigger.
758 static void trigger_listener(int trigger_status)
760 switch (trigger_status)
762 case TRIG_GO:
763 if(!(audio_status() & AUDIO_STATUS_RECORD))
765 rec_status |= RCSTAT_HAVE_RECORDED;
766 rec_command(RECORDING_CMD_START);
767 #if CONFIG_CODEC != SWCODEC
768 /* give control to mpeg thread so that it can start
769 recording */
770 yield(); yield(); yield();
771 #endif
774 /* if we're already recording this is a retrigger */
775 else
777 if((audio_status() & AUDIO_STATUS_PAUSE) &&
778 (global_settings.rec_trigger_type == TRIG_TYPE_PAUSE))
780 rec_command(RECORDING_CMD_RESUME);
782 /* New file on trig start*/
783 else if (global_settings.rec_trigger_type != TRIG_TYPE_NEW_FILE)
785 rec_command(RECORDING_CMD_START_NEWFILE);
786 /* tell recording_screen to reset the time */
787 last_seconds = 0;
790 break;
792 /* A _change_ to TRIG_READY means the current recording has stopped */
793 case TRIG_READY:
794 if(audio_status() & AUDIO_STATUS_RECORD)
796 switch(global_settings.rec_trigger_type)
798 case TRIG_TYPE_STOP: /* Stop */
799 rec_command(RECORDING_CMD_STOP);
800 break;
802 case TRIG_TYPE_PAUSE: /* Pause */
803 rec_command(RECORDING_CMD_PAUSE);
804 break;
806 case TRIG_TYPE_NEW_FILE: /* New file on trig stop*/
807 rec_command(RECORDING_CMD_START_NEWFILE);
808 /* tell recording_screen to reset the time */
809 last_seconds = 0;
810 break;
812 case 3: /* Stop and shutdown */
813 rec_command(RECORDING_CMD_STOP_SHUTDOWN);
814 break;
817 if (global_settings.rec_trigger_mode != TRIG_MODE_REARM)
819 peak_meter_set_trigger_listener(NULL);
820 peak_meter_trigger(false);
823 break;
827 /* Stuff for drawing the screen */
829 enum rec_list_items_stereo {
830 ITEM_VOLUME = 0,
831 ITEM_GAIN = 1,
832 ITEM_GAIN_L = 2,
833 ITEM_GAIN_R = 3,
834 #ifdef HAVE_AGC
835 ITEM_AGC_MODE = 4,
836 ITEM_AGC_MAXDB = 5,
837 ITEM_FILENAME = 7,
838 ITEM_COUNT = 7,
839 #else
840 ITEM_FILENAME = 7,
841 ITEM_COUNT = 5,
842 #endif
845 enum rec_list_items_mono {
846 ITEM_VOLUME_M = 0,
847 ITEM_GAIN_M = 1,
848 #ifdef HAVE_AGC
849 ITEM_AGC_MODE_M = 4,
850 ITEM_AGC_MAXDB_M = 5,
851 ITEM_FILENAME_M = 7,
852 ITEM_COUNT_M = 5,
853 #else
854 ITEM_FILENAME_M = 7,
855 ITEM_COUNT_M = 3,
856 #endif
859 #ifdef HAVE_SPDIF_REC
860 enum rec_list_items_spdif {
861 ITEM_VOLUME_D = 0,
862 #if CONFIG_CODEC == SWCODEC
863 ITEM_SAMPLERATE_D = 6,
864 ITEM_FILENAME_D = 7,
865 ITEM_COUNT_D = 3,
866 #else
867 ITEM_FILENAME_D = 7,
868 ITEM_COUNT_D = 2,
869 #endif
871 #endif
873 static int listid_to_enum[ITEM_COUNT];
875 static const char* reclist_get_name(int selected_item, void * data,
876 char * buffer, size_t buffer_len)
878 char buf2[32];
879 #ifdef HAVE_AGC
880 char buf3[32];
881 #endif
882 data = data; /* not used */
883 if(selected_item >= ITEM_COUNT)
884 return "";
886 switch (listid_to_enum[selected_item])
888 case ITEM_VOLUME:
889 snprintf(buffer, buffer_len, "%s: %s", str(LANG_VOLUME),
890 fmt_gain(SOUND_VOLUME,
891 global_settings.volume,
892 buf2, sizeof(buf2)));
893 break;
894 case ITEM_GAIN:
895 #ifdef HAVE_MIC_REC
896 if(global_settings.rec_source == AUDIO_SRC_MIC)
898 /* Draw MIC recording gain */
899 snprintf(buffer, buffer_len, "%s: %s", str(LANG_GAIN),
900 fmt_gain(SOUND_MIC_GAIN,
901 global_settings.rec_mic_gain,
902 buf2, sizeof(buf2)));
904 else
905 #endif /* MIC */
907 int avg_gain = (global_settings.rec_left_gain +
908 global_settings.rec_right_gain) / 2;
909 snprintf(buffer, buffer_len, "%s: %s", str(LANG_GAIN),
910 fmt_gain(SOUND_LEFT_GAIN,
911 avg_gain,
912 buf2, sizeof(buf2)));
914 break;
915 case ITEM_GAIN_L:
916 snprintf(buffer, buffer_len, "%s: %s",
917 str(LANG_GAIN_LEFT),
918 fmt_gain(SOUND_LEFT_GAIN,
919 global_settings.rec_left_gain,
920 buf2, sizeof(buf2)));
921 break;
922 case ITEM_GAIN_R:
923 snprintf(buffer, buffer_len, "%s: %s",
924 str(LANG_GAIN_RIGHT),
925 fmt_gain(SOUND_RIGHT_GAIN,
926 global_settings.rec_right_gain,
927 buf2, sizeof(buf2)));
928 break;
929 #ifdef HAVE_AGC
930 case ITEM_AGC_MODE:
931 snprintf(buffer, buffer_len, "%s: %s",
932 str(LANG_RECORDING_AGC_PRESET),
933 agc_preset_str[agc_preset]);
934 break;
935 case ITEM_AGC_MAXDB:
936 if (agc_preset == 0)
937 snprintf(buffer, buffer_len, "%s: %s",
938 str(LANG_RECORDING_AGC_MAXGAIN),
939 fmt_gain(SOUND_LEFT_GAIN,
940 agc_maxgain, buf2, sizeof(buf2)));
941 #ifdef HAVE_MIC_REC
942 else if (global_settings.rec_source == AUDIO_SRC_MIC)
943 snprintf(buffer, buffer_len, "%s: %s (%s)",
944 str(LANG_RECORDING_AGC_MAXGAIN),
945 fmt_gain(SOUND_MIC_GAIN,
946 agc_maxgain, buf2, sizeof(buf2)),
947 fmt_gain(SOUND_MIC_GAIN,
948 agc_maxgain - global_settings.rec_mic_gain,
949 buf3, sizeof(buf3)));
950 else
951 #endif /* MIC */
952 snprintf(buffer, buffer_len, "%s: %s (%s)",
953 str(LANG_RECORDING_AGC_MAXGAIN),
954 fmt_gain(SOUND_LEFT_GAIN,
955 agc_maxgain, buf2, sizeof(buf2)),
956 fmt_gain(SOUND_LEFT_GAIN,
957 agc_maxgain -
958 (global_settings.rec_left_gain +
959 global_settings.rec_right_gain)/2,
960 buf3, sizeof(buf3)));
961 break;
962 #endif
963 #if CONFIG_CODEC == SWCODEC
964 #ifdef HAVE_SPDIF_REC
965 case ITEM_SAMPLERATE_D:
966 snprintf(buffer, buffer_len, "%s: %lu",
967 str(LANG_RECORDING_FREQUENCY),
968 pcm_rec_sample_rate());
969 break;
970 #endif
971 #endif
972 case ITEM_FILENAME:
974 if(audio_status() & AUDIO_STATUS_RECORD)
976 size_t tot_len = strlen(path_buffer) +
977 strlen(str(LANG_RECORDING_FILENAME)) + 1;
978 if(tot_len > buffer_len)
980 snprintf(buffer, buffer_len, "%s %s",
981 str(LANG_RECORDING_FILENAME),
982 path_buffer + tot_len - buffer_len);
984 else
986 snprintf(buffer, buffer_len, "%s %s",
987 str(LANG_RECORDING_FILENAME), path_buffer);
990 else
992 return str(LANG_RECORDING_FILENAME);
994 break;
996 default:
997 return "";
999 return buffer;
1003 bool recording_start_automatic = false;
1005 bool recording_screen(bool no_source)
1007 int button;
1008 int done = -1; /* negative to re-init, positive to quit, zero to run */
1009 char buf[32]; /* for preparing strings */
1010 char buf2[32]; /* for preparing strings */
1011 int w, h; /* character width/height */
1012 int update_countdown = 0; /* refresh counter */
1013 unsigned int seconds;
1014 int hours, minutes;
1015 int audio_stat = 0; /* status of the audio system */
1016 int last_audio_stat = -1; /* previous status so we can act on changes */
1017 struct viewport vp_list[NB_SCREENS], vp_top[NB_SCREENS]; /* the viewports */
1019 #if CONFIG_CODEC == SWCODEC
1020 int warning_counter = 0;
1021 #define WARNING_PERIOD 7
1022 #endif
1024 #if CONFIG_CODEC == SWCODEC
1025 #ifdef HAVE_SPDIF_REC
1026 unsigned long prev_sample_rate = 0;
1027 #endif
1028 #endif
1030 #ifdef HAVE_FMRADIO_REC
1031 /* Radio is left on if:
1032 * 1) Is was on at the start and the initial source is FM Radio
1033 * 2) 1) and the source was never changed to something else
1035 int radio_status = (global_settings.rec_source != AUDIO_SRC_FMRADIO) ?
1036 FMRADIO_OFF : get_radio_status();
1037 #endif
1038 #if (CONFIG_LED == LED_REAL)
1039 bool led_state = false;
1040 int led_countdown = 2;
1041 #endif
1042 #ifdef HAVE_AGC
1043 bool peak_read = false;
1044 int peak_l, peak_r;
1045 int balance = 0;
1046 #endif
1047 int pm_x[NB_SCREENS]; /* peakmeter (and trigger bar) x pos */
1048 int pm_y[NB_SCREENS]; /* peakmeter y pos */
1049 int pm_h[NB_SCREENS]; /* peakmeter height */
1050 int trig_ypos[NB_SCREENS]; /* trigger bar y pos */
1051 int trig_width[NB_SCREENS]; /* trigger bar width */
1052 int top_height_req[NB_SCREENS]; /* required height for top half */
1053 /* tweak layout tiny screens / big fonts */
1054 bool compact_view[NB_SCREENS] = { false };
1055 struct gui_synclist lists; /* the list in the bottom vp */
1056 #if defined(HAVE_AGC)
1057 bool peak_valid = false;
1058 #endif
1059 #if defined(HAVE_HISTOGRAM)
1060 unsigned short hist_pos_y = 0;
1061 unsigned short hist_size_h = 0;
1062 #endif
1063 #ifdef HAVE_FMRADIO_REC
1064 int prev_rec_source = global_settings.rec_source; /* detect source change */
1065 #endif
1067 struct audio_recording_options rec_options;
1068 rec_status = RCSTAT_IN_RECSCREEN;
1069 push_current_activity(ACTIVITY_RECORDING);
1071 #if (CONFIG_STORAGE & STORAGE_ATA) && (CONFIG_LED == LED_REAL) \
1072 && !defined(SIMULATOR)
1073 ata_set_led_enabled(false);
1074 #endif
1076 #if CONFIG_CODEC == SWCODEC
1077 /* This should be done before touching audio settings */
1078 while (!pcm_is_initialized())
1079 sleep(0);
1081 /* recording_menu gets messed up: so prevent manus talking */
1082 talk_disable(true);
1083 /* audio_init_recording stops anything playing when it takes the audio
1084 buffer */
1085 #else
1086 /* Yes, we use the D/A for monitoring */
1087 peak_meter_enable(true);
1088 peak_meter_playback(true);
1089 #endif
1091 #ifdef HAVE_AGC
1092 peak_meter_get_peakhold(&peak_l, &peak_r);
1093 #endif
1095 pm_reset_clipcount();
1096 pm_activate_clipcount(false);
1097 settings_apply_trigger();
1099 #ifdef HAVE_AGC
1100 agc_preset_str[0] = str(LANG_OFF);
1101 agc_preset_str[1] = str(LANG_AGC_SAFETY);
1102 agc_preset_str[2] = str(LANG_AGC_LIVE);
1103 agc_preset_str[3] = str(LANG_AGC_DJSET);
1104 agc_preset_str[4] = str(LANG_AGC_MEDIUM);
1105 agc_preset_str[5] = str(LANG_AGC_VOICE);
1106 #endif /* HAVE_AGC */
1108 #ifdef HAVE_SPEAKER
1109 /* Disable speaker to prevent feedback */
1110 audiohw_enable_speaker(false);
1111 #endif
1113 audio_init_recording();
1114 sound_set_volume(global_settings.volume);
1116 #if CONFIG_RTC == 0
1117 /* Create new filename for recording start */
1118 rec_init_filename();
1119 #endif
1121 /* start of the loop: we stay in this loop until user quits recscreen */
1122 while(done <= 0)
1124 if(done < 0)
1126 /* request to re-init stuff, done after settings screen */
1127 done = 0;
1128 #ifdef HAVE_FMRADIO_REC
1129 /* If input changes away from FM Radio,
1130 radio will remain off when recording screen closes. */
1131 if (global_settings.rec_source != prev_rec_source
1132 && prev_rec_source == AUDIO_SRC_FMRADIO)
1133 radio_status = FMRADIO_OFF;
1134 prev_rec_source = global_settings.rec_source;
1135 #endif
1137 /* viewport init and calculations that only needs to be done once */
1138 FOR_NB_SCREENS(i)
1140 struct viewport *v;
1141 /* top vp, 4 lines, force sys font if total screen < 6 lines
1142 NOTE: one could limit the list to 1 line and get away with 5 lines */
1143 top_height_req[i] = 4;
1144 #if defined(HAVE_HISTOGRAM)
1145 if((global_settings.histogram_interval) && (!i))
1146 top_height_req[i] += 1; /* use one line for histogram */
1147 #endif
1148 v = &vp_top[i];
1149 viewport_set_defaults(v, i);
1150 if (viewport_get_nb_lines(v) < top_height_req[i])
1152 /* compact needs 4 lines total */
1153 v->font = FONT_SYSFIXED;
1154 compact_view[i] = false;
1156 else
1158 /*top=4,list=2*/
1159 if (viewport_get_nb_lines(v) < (top_height_req[i]+2))
1160 compact_view[i] = true;
1161 else
1162 compact_view[i] = false;
1164 vp_list[i] = *v; /* get a copy now so it can be sized more easily */
1165 v->height = (font_get(v->font)->height)*(compact_view[i] ? 3 :
1166 top_height_req[i]);
1168 /* list section, rest of the screen */
1169 vp_list[i].y += vp_top[i].height;
1170 vp_list[i].height -= vp_top[i].height;
1171 screens[i].set_viewport(&vp_top[i]); /* req for next calls */
1173 screens[i].getstringsize("W", &w, &h);
1174 pm_y[i] = font_get(vp_top[i].font)->height * 2;
1175 trig_ypos[i] = font_get(vp_top[i].font)->height * 3;
1176 if(compact_view[i])
1177 trig_ypos[i] -= (font_get(vp_top[i].font)->height)/2;
1180 /* init the bottom list */
1181 gui_synclist_init(&lists, reclist_get_name, NULL, false, 1, vp_list);
1182 gui_synclist_set_title(&lists, NULL, Icon_NOICON);
1184 send_event(GUI_EVENT_ACTIONUPDATE, (void*)1); /* force a redraw */
1186 #if defined(HAVE_HISTOGRAM)
1187 hist_pos_y = (compact_view[0] ? 3 : 4) * (font_get(vp_top[0].font)->height)
1188 + 1;
1189 hist_size_h = font_get(vp_top[0].font)->height - 2;
1190 histogram_init();
1191 #endif
1193 FOR_NB_SCREENS(i)
1195 pm_x[i] = 0;
1196 if(global_settings.peak_meter_clipcounter)
1198 int clipwidth = 0;
1199 screens[i].getstringsize(str(LANG_PM_CLIPCOUNT),
1200 &clipwidth, &h); /* h is same */
1201 pm_x[i] = clipwidth+1;
1203 if(global_settings.rec_trigger_mode == TRIG_MODE_OFF)
1204 pm_h[i] = font_get(vp_top[i].font)->height * 2;
1205 else
1206 pm_h[i] = font_get(vp_top[i].font)->height;
1207 if(compact_view[i])
1208 pm_h[i] /= 2;
1209 trig_width[i] = vp_top[i].width - pm_x[i];
1212 #if CONFIG_CODEC == SWCODEC
1213 audio_close_recording();
1214 audio_init_recording();
1215 #endif
1217 rec_init_recording_options(&rec_options);
1218 rec_set_recording_options(&rec_options);
1220 if(rec_create_directory() < 0)
1222 rec_status = 0;
1223 goto rec_abort;
1226 #if CONFIG_CODEC == SWCODEC && CONFIG_RTC == 0
1227 /* If format changed, a new number is required */
1228 rec_init_filename();
1229 #endif
1231 #ifdef HAVE_AGC
1232 #ifdef HAVE_MIC_REC
1233 if (global_settings.rec_source == AUDIO_SRC_MIC) {
1234 agc_preset = global_settings.rec_agc_preset_mic;
1235 agc_maxgain = global_settings.rec_agc_maxgain_mic;
1237 else
1238 #endif /* MIC */
1240 agc_preset = global_settings.rec_agc_preset_line;
1241 agc_maxgain = global_settings.rec_agc_maxgain_line;
1243 #endif /* HAVE_AGC */
1245 set_gain();
1246 update_countdown = 0; /* Update immediately */
1248 /* populate translation table for list id -> enum */
1249 #ifdef HAVE_SPDIF_REC
1250 if(global_settings.rec_source == AUDIO_SRC_SPDIF)
1252 listid_to_enum[0] = ITEM_VOLUME_D;
1253 #if CONFIG_CODEC == SWCODEC
1254 listid_to_enum[1] = ITEM_SAMPLERATE_D;
1255 listid_to_enum[2] = ITEM_FILENAME_D;
1256 #else
1257 listid_to_enum[1] = ITEM_FILENAME_D;
1258 #endif
1260 gui_synclist_set_nb_items(&lists, ITEM_COUNT_D); /* spdif */
1262 else
1263 #endif
1264 if(HAVE_MIC_REC_((global_settings.rec_source == AUDIO_SRC_MIC) || )
1265 (global_settings.rec_channels == 1))
1267 listid_to_enum[0] = ITEM_VOLUME_M;
1268 listid_to_enum[1] = ITEM_GAIN_M;
1269 #ifdef HAVE_AGC
1270 listid_to_enum[2] = ITEM_AGC_MODE_M;
1271 listid_to_enum[3] = ITEM_AGC_MAXDB_M;
1272 listid_to_enum[4] = ITEM_FILENAME_M;
1273 #else
1274 listid_to_enum[2] = ITEM_FILENAME_M;
1275 #endif
1276 gui_synclist_set_nb_items(&lists, ITEM_COUNT_M); /* mono */
1278 else
1280 listid_to_enum[0] = ITEM_VOLUME;
1281 listid_to_enum[1] = ITEM_GAIN;
1282 listid_to_enum[2] = ITEM_GAIN_L;
1283 listid_to_enum[3] = ITEM_GAIN_R;
1284 #ifdef HAVE_AGC
1285 listid_to_enum[4] = ITEM_AGC_MODE;
1286 listid_to_enum[5] = ITEM_AGC_MAXDB;
1287 listid_to_enum[6] = ITEM_FILENAME;
1288 #else
1289 listid_to_enum[4] = ITEM_FILENAME;
1290 #endif
1291 gui_synclist_set_nb_items(&lists, ITEM_COUNT); /* stereo */
1294 gui_synclist_draw(&lists);
1295 } /* if(done < 0) */
1297 audio_stat = audio_status();
1299 #if (CONFIG_LED == LED_REAL)
1302 * Flash the LED while waiting to record. Turn it on while
1303 * recording.
1305 if(audio_stat & AUDIO_STATUS_RECORD)
1307 if (audio_stat & AUDIO_STATUS_PAUSE)
1309 if (--led_countdown <= 0)
1311 led_state = !led_state;
1312 led(led_state);
1313 led_countdown = 2;
1316 else
1318 /* trigger is on in status TRIG_READY (no check needed) */
1319 led(true);
1322 else
1324 int trig_stat = peak_meter_trigger_status();
1326 * other trigger stati than trig_off and trig_steady
1327 * already imply that we are recording.
1329 if (trig_stat == TRIG_STEADY)
1331 if (--led_countdown <= 0)
1333 led_state = !led_state;
1334 led(led_state);
1335 led_countdown = 2;
1338 else
1340 /* trigger is on in status TRIG_READY (no check needed) */
1341 led(false);
1344 #endif /* CONFIG_LED */
1346 /* Wait for a button a while (HZ/10) drawing the peak meter */
1347 button = peak_meter_draw_get_btn(CONTEXT_RECSCREEN,
1348 pm_x, pm_y, pm_h,
1349 screen_update, vp_top);
1350 if (last_audio_stat != audio_stat)
1352 if (audio_stat & AUDIO_STATUS_RECORD)
1354 rec_status |= RCSTAT_HAVE_RECORDED;
1356 last_audio_stat = audio_stat;
1357 update_list = true;
1360 if (recording_start_automatic)
1362 /* simulate a button press */
1363 button = ACTION_REC_PAUSE;
1364 recording_start_automatic = false;
1367 /* let list handle the button */
1368 gui_synclist_do_button(&lists, &button, LIST_WRAP_UNLESS_HELD);
1371 switch(button)
1373 case ACTION_SETTINGS_INC:
1374 case ACTION_SETTINGS_INCREPEAT:
1375 switch (listid_to_enum[gui_synclist_get_sel_pos(&lists)])
1377 case ITEM_VOLUME:
1378 global_settings.volume += sound_steps(SOUND_VOLUME);
1379 setvol();
1380 break;
1381 case ITEM_GAIN:
1382 #ifdef HAVE_MIC_REC
1383 if(global_settings.rec_source == AUDIO_SRC_MIC)
1385 global_settings.rec_mic_gain +=
1386 sound_steps(SOUND_MIC_GAIN);
1388 else
1389 #endif /* MIC */
1391 global_settings.rec_left_gain +=
1392 sound_steps(SOUND_LEFT_GAIN);
1393 global_settings.rec_right_gain +=
1394 sound_steps(SOUND_RIGHT_GAIN);
1396 break;
1397 case ITEM_GAIN_L:
1398 global_settings.rec_left_gain +=
1399 sound_steps(SOUND_LEFT_GAIN);
1401 break;
1402 case ITEM_GAIN_R:
1403 global_settings.rec_right_gain +=
1404 sound_steps(SOUND_RIGHT_GAIN);
1406 break;
1407 #ifdef HAVE_AGC
1408 case ITEM_AGC_MODE:
1409 agc_preset = MIN(agc_preset + 1, AGC_MODE_SIZE);
1410 agc_enable = (agc_preset != 0);
1411 #ifdef HAVE_MIC_REC
1412 if (global_settings.rec_source == AUDIO_SRC_MIC) {
1413 global_settings.rec_agc_preset_mic = agc_preset;
1414 agc_maxgain = global_settings.rec_agc_maxgain_mic;
1415 } else
1416 #endif /* MIC */
1418 global_settings.rec_agc_preset_line = agc_preset;
1419 agc_maxgain = global_settings.rec_agc_maxgain_line;
1421 break;
1422 case ITEM_AGC_MAXDB:
1423 #ifdef HAVE_MIC_REC
1424 if (global_settings.rec_source == AUDIO_SRC_MIC)
1426 agc_maxgain = MIN(agc_maxgain + 1,
1427 sound_max(SOUND_MIC_GAIN));
1428 global_settings.rec_agc_maxgain_mic = agc_maxgain;
1430 else
1431 #endif /* MIC */
1433 agc_maxgain = MIN(agc_maxgain + 1,
1434 sound_max(SOUND_LEFT_GAIN));
1435 global_settings.rec_agc_maxgain_line = agc_maxgain;
1437 break;
1438 #endif /* HAVE_AGC */
1440 set_gain();
1441 update_countdown = 0; /* Update immediately */
1442 break;
1443 case ACTION_SETTINGS_DEC:
1444 case ACTION_SETTINGS_DECREPEAT:
1445 switch (listid_to_enum[gui_synclist_get_sel_pos(&lists)])
1447 case ITEM_VOLUME:
1448 global_settings.volume -= sound_steps(SOUND_VOLUME);
1450 /* check range and update */
1451 setvol();
1452 break;
1453 case ITEM_GAIN:
1454 #ifdef HAVE_MIC_REC
1455 if(global_settings.rec_source == AUDIO_SRC_MIC)
1457 global_settings.rec_mic_gain -=
1458 sound_steps(SOUND_MIC_GAIN);
1460 else
1461 #endif /* MIC */
1463 global_settings.rec_left_gain -=
1464 sound_steps(SOUND_LEFT_GAIN);
1466 global_settings.rec_right_gain -=
1467 sound_steps(SOUND_RIGHT_GAIN);
1469 break;
1470 case ITEM_GAIN_L:
1471 global_settings.rec_left_gain -=
1472 sound_steps(SOUND_LEFT_GAIN);
1474 break;
1475 case ITEM_GAIN_R:
1476 global_settings.rec_right_gain -=
1477 sound_steps(SOUND_RIGHT_GAIN);
1479 break;
1480 #ifdef HAVE_AGC
1481 case ITEM_AGC_MODE:
1482 agc_preset = MAX(agc_preset - 1, 0);
1483 agc_enable = (agc_preset != 0);
1484 #ifdef HAVE_MIC_REC
1485 if (global_settings.rec_source == AUDIO_SRC_MIC) {
1486 global_settings.rec_agc_preset_mic = agc_preset;
1487 agc_maxgain = global_settings.rec_agc_maxgain_mic;
1488 } else
1489 #endif /* MIC */
1491 global_settings.rec_agc_preset_line = agc_preset;
1492 agc_maxgain = global_settings.rec_agc_maxgain_line;
1494 break;
1495 case ITEM_AGC_MAXDB:
1496 #ifdef HAVE_MIC_REC
1497 if (global_settings.rec_source == AUDIO_SRC_MIC)
1499 agc_maxgain = MAX(agc_maxgain - 1,
1500 sound_min(SOUND_MIC_GAIN));
1501 global_settings.rec_agc_maxgain_mic = agc_maxgain;
1502 } else
1503 #endif /* MIC */
1505 agc_maxgain = MAX(agc_maxgain - 1,
1506 sound_min(SOUND_LEFT_GAIN));
1507 global_settings.rec_agc_maxgain_line = agc_maxgain;
1509 break;
1510 #endif /* HAVE_AGC */
1512 set_gain();
1513 update_countdown = 0; /* Update immediately */
1514 break;
1515 case ACTION_STD_CANCEL:
1516 /* turn off the trigger */
1517 peak_meter_trigger(false);
1518 peak_meter_set_trigger_listener(NULL);
1520 if(audio_stat & AUDIO_STATUS_RECORD)
1522 rec_command(RECORDING_CMD_STOP);
1524 else
1526 #if CONFIG_CODEC != SWCODEC
1527 peak_meter_playback(true);
1528 peak_meter_enable(false);
1529 #endif
1530 done = 1;
1532 update_countdown = 0; /* Update immediately */
1533 break;
1534 #ifdef HAVE_REMOTE_LCD
1535 case ACTION_REC_LCD:
1536 /* this feature exists for some h1x0/h3x0 targets that suffer
1537 from noise caused by remote LCD updates
1538 NOTE 1: this will leave the list on the remote
1539 NOTE 2: to be replaced by a global LCD_off() routine */
1540 if(remote_display_on)
1542 /* switch to single screen, leave message on remote */
1543 screen_update = 1;
1544 screens[1].clear_viewport();
1545 screens[1].puts(0, 0, str(LANG_REMOTE_LCD_OFF));
1546 screens[1].puts(0, 1, str(LANG_REMOTE_LCD_ON));
1547 screens[1].update_viewport();
1549 else
1551 /* remote switched on again */
1552 update_list = true;
1553 screen_update = NB_SCREENS;
1555 remote_display_on = !remote_display_on; /* toggle */
1556 update_countdown = 0; /* Update immediately */
1557 break;
1558 #endif
1559 case ACTION_REC_PAUSE:
1560 case ACTION_REC_NEWFILE:
1561 /* Only act if the mpeg is stopped */
1562 if(!(audio_stat & AUDIO_STATUS_RECORD))
1564 /* is this manual or triggered recording? */
1565 if ((global_settings.rec_trigger_mode == TRIG_MODE_OFF) ||
1566 (peak_meter_trigger_status() != TRIG_OFF))
1568 /* manual recording */
1569 rec_status |= RCSTAT_HAVE_RECORDED;
1570 rec_command(RECORDING_CMD_START);
1571 last_seconds = 0;
1572 if (global_settings.talk_menu)
1574 /* no voice possible here, but a beep */
1575 audio_beep(HZ/2); /* longer beep on start */
1578 /* this is triggered recording */
1579 else
1581 /* we don't start recording now, but enable the
1582 trigger and let the callback function
1583 trigger_listener control when the recording starts */
1584 peak_meter_trigger(true);
1585 peak_meter_set_trigger_listener(&trigger_listener);
1588 else
1590 /*if new file button pressed, start new file */
1591 if (button == ACTION_REC_NEWFILE)
1593 rec_command(RECORDING_CMD_START_NEWFILE);
1594 last_seconds = 0;
1596 else
1597 /* if pause button pressed, pause or resume */
1599 if(audio_stat & AUDIO_STATUS_PAUSE)
1601 rec_command(RECORDING_CMD_RESUME);
1602 if (global_settings.talk_menu)
1604 /* no voice possible here, but a beep */
1605 audio_beep(HZ/4); /* short beep on resume */
1608 else
1610 rec_command(RECORDING_CMD_PAUSE);
1614 update_countdown = 0; /* Update immediately */
1615 break;
1616 case ACTION_STD_MENU:
1617 #if CONFIG_CODEC == SWCODEC
1618 if(!(audio_stat & AUDIO_STATUS_RECORD))
1619 #else
1620 if(audio_stat != AUDIO_STATUS_RECORD)
1621 #endif
1623 #if (CONFIG_LED == LED_REAL)
1624 /* led is restored at begin of loop / end of function */
1625 led(false);
1626 #endif
1627 if (recording_menu(no_source))
1629 done = 1;
1630 rec_status |= RCSTAT_BEEN_IN_USB_MODE;
1631 #ifdef HAVE_FMRADIO_REC
1632 radio_status = FMRADIO_OFF;
1633 #endif
1635 else
1637 done = -1;
1638 /* the init is now done at the beginning of the loop */
1641 break;
1643 #if CONFIG_KEYPAD == RECORDER_PAD
1644 case ACTION_REC_F2:
1645 if(audio_stat != AUDIO_STATUS_RECORD)
1647 #if (CONFIG_LED == LED_REAL)
1648 /* led is restored at begin of loop / end of function */
1649 led(false);
1650 #endif
1651 if (f2_rec_screen())
1653 rec_status |= RCSTAT_HAVE_RECORDED;
1654 done = true;
1656 else
1657 update_countdown = 0; /* Update immediately */
1659 break;
1661 case ACTION_REC_F3:
1662 if(audio_stat & AUDIO_STATUS_RECORD)
1664 rec_command(RECORDING_CMD_START_NEWFILE);
1665 last_seconds = 0;
1667 else
1669 #if (CONFIG_LED == LED_REAL)
1670 /* led is restored at begin of loop / end of function */
1671 led(false);
1672 #endif
1673 if (f3_rec_screen())
1675 rec_status |= RCSTAT_HAVE_RECORDED;
1676 done = true;
1678 else
1679 update_countdown = 0; /* Update immediately */
1681 break;
1682 #endif /* CONFIG_KEYPAD == RECORDER_PAD */
1684 case SYS_USB_CONNECTED:
1685 /* Only accept USB connection when not recording */
1686 if(!(audio_stat & AUDIO_STATUS_RECORD))
1688 FOR_NB_SCREENS(i)
1689 screens[i].set_viewport(NULL);
1690 default_event_handler(SYS_USB_CONNECTED);
1691 done = true;
1692 rec_status |= RCSTAT_BEEN_IN_USB_MODE;
1693 #ifdef HAVE_FMRADIO_REC
1694 radio_status = FMRADIO_OFF;
1695 #endif
1697 break;
1698 } /*switch(button)*/
1700 #ifdef HAVE_AGC
1701 peak_read = !peak_read;
1702 if (peak_read) { /* every 2nd run of loop */
1703 peak_time++;
1704 peak_valid = read_peak_levels(&peak_l, &peak_r, &balance);
1707 /* Handle AGC every 200ms when enabled and peak data is valid */
1708 if (peak_read && agc_enable && peak_valid)
1709 auto_gain_control(&peak_l, &peak_r, &balance);
1710 #endif
1712 seconds = audio_recorded_time() / HZ;
1714 /* start of vp_top drawing */
1715 if(update_countdown-- == 0 || seconds > last_seconds)
1717 unsigned int dseconds, dhours, dminutes;
1718 unsigned long num_recorded_bytes, dsize, dmb;
1720 FOR_NB_SCREENS(i)
1722 screens[i].set_viewport(&vp_top[i]);
1723 screens[i].clear_viewport();
1725 update_countdown = 5;
1726 last_seconds = seconds;
1728 dseconds = rec_timesplit_seconds();
1729 dsize = rec_sizesplit_bytes();
1730 num_recorded_bytes = audio_num_recorded_bytes();
1732 #if CONFIG_CODEC == SWCODEC
1733 if ((audio_stat & AUDIO_STATUS_WARNING)
1734 && (warning_counter++ % WARNING_PERIOD) < WARNING_PERIOD/2)
1736 /* Switch back and forth displaying warning on first available
1737 line to ensure visibility - the motion should also help
1738 draw attention */
1739 /* Don't use language string unless agreed upon to make this
1740 method permanent - could do something in the statusbar */
1741 snprintf(buf, sizeof(buf), "Warning: %08lX",
1742 pcm_rec_get_warnings());
1744 else
1745 #endif /* CONFIG_CODEC == SWCODEC */
1746 if ((global_settings.rec_sizesplit) &&
1747 (global_settings.rec_split_method))
1749 dmb = dsize/1024/1024;
1750 snprintf(buf, sizeof(buf), "%s %luMB",
1751 str(LANG_SPLIT_SIZE), dmb);
1753 else
1755 hours = seconds / 3600;
1756 minutes = (seconds - (hours * 3600)) / 60;
1757 snprintf(buf, sizeof(buf), "%s %02d:%02d:%02d",
1758 str(LANG_RECORDING_TIME),
1759 hours, minutes, seconds%60);
1762 FOR_NB_ACTIVE_SCREENS(i)
1763 screens[i].puts(0, 0, buf);
1765 if(audio_stat & AUDIO_STATUS_PRERECORD)
1767 snprintf(buf, sizeof(buf), "%s...",
1768 str(LANG_RECORD_PRERECORD));
1770 else
1772 /* Display the split interval if the record timesplit
1773 is active */
1774 if ((global_settings.rec_timesplit) &&
1775 !(global_settings.rec_split_method))
1777 /* Display the record timesplit interval rather
1778 than the file size if the record timer is active */
1779 dhours = dseconds / 3600;
1780 dminutes = (dseconds - (dhours * 3600)) / 60;
1781 snprintf(buf, sizeof(buf), "%s %02d:%02d",
1782 str(LANG_RECORDING_TIMESPLIT_REC),
1783 dhours, dminutes);
1785 else
1787 output_dyn_value(buf2, sizeof buf2,
1788 num_recorded_bytes,
1789 byte_units, true);
1790 snprintf(buf, sizeof(buf), "%s %s",
1791 str(LANG_RECORDING_SIZE), buf2);
1795 FOR_NB_ACTIVE_SCREENS(i)
1796 screens[i].puts(0, 1, buf);
1798 /* We will do file splitting regardless, either at the end of
1799 a split interval, or when the filesize approaches the 2GB
1800 FAT file size (compatibility) limit. */
1801 if ((audio_stat && !(global_settings.rec_split_method)
1802 && global_settings.rec_timesplit && (seconds >= dseconds))
1803 || (audio_stat && global_settings.rec_split_method
1804 && global_settings.rec_sizesplit
1805 && (num_recorded_bytes >= dsize))
1806 || (num_recorded_bytes >= MAX_FILE_SIZE))
1808 if (!(global_settings.rec_split_type)
1809 || (num_recorded_bytes >= MAX_FILE_SIZE))
1811 rec_command(RECORDING_CMD_START_NEWFILE);
1812 last_seconds = 0;
1814 else
1816 peak_meter_trigger(false);
1817 peak_meter_set_trigger_listener(NULL);
1818 if( global_settings.rec_split_type == 1)
1819 rec_command(RECORDING_CMD_STOP);
1820 else
1821 rec_command(RECORDING_CMD_STOP_SHUTDOWN);
1823 update_countdown = 0;
1826 /* draw the clipcounter just in front of the peakmeter */
1827 if(global_settings.peak_meter_clipcounter)
1829 int clipcount = pm_get_clipcount();
1830 FOR_NB_ACTIVE_SCREENS(i)
1832 if(!compact_view[i])
1834 screens[i].puts(0, 2, str(LANG_PM_CLIPCOUNT));
1835 screens[i].putsf(0, 3, "%4d", clipcount);
1837 else
1838 screens[i].putsf(0, 2, "%4d", clipcount);
1842 #ifdef HAVE_HISTOGRAM
1843 if(global_settings.histogram_interval)
1845 histogram_draw(0,
1846 screens[0].getwidth()/2,
1847 hist_pos_y,
1848 hist_pos_y,
1849 screens[0].getwidth()/2,
1850 hist_size_h);
1852 #endif
1854 #ifdef HAVE_AGC
1855 hist_time++;
1856 #endif
1857 /* draw the trigger status */
1858 if (peak_meter_trigger_status() != TRIG_OFF)
1860 peak_meter_draw_trig(pm_x, trig_ypos, trig_width,
1861 screen_update);
1862 FOR_NB_ACTIVE_SCREENS(i)
1863 screens[i].update_viewport_rect(pm_x[i], trig_ypos[i],
1864 trig_width[i] + 2, TRIG_HEIGHT);
1867 #ifdef HAVE_AGC
1868 #ifdef HAVE_MIC_REC
1869 if (global_settings.rec_source == AUDIO_SRC_MIC)
1871 if(agc_maxgain < (global_settings.rec_mic_gain))
1872 change_recording_gain(false, true, true);
1874 else
1875 #endif /* MIC */
1877 if(agc_maxgain < (global_settings.rec_left_gain))
1878 change_recording_gain(false, true, false);
1879 if(agc_maxgain < (global_settings.rec_right_gain))
1880 change_recording_gain(false, false, true);
1882 #endif /* HAVE_AGC */
1884 #if CONFIG_CODEC == SWCODEC
1885 #ifdef HAVE_SPDIF_REC
1886 if((global_settings.rec_source == AUDIO_SRC_SPDIF) &&
1887 (prev_sample_rate != pcm_rec_sample_rate()))
1889 /* spdif samplerate changed */
1890 prev_sample_rate = pcm_rec_sample_rate();
1891 update_list = true;
1893 #endif
1894 #endif
1896 if(update_list)
1898 /* update_list is set whenever content changes */
1899 update_list = false;
1900 gui_synclist_draw(&lists);
1903 /* draw peakmeter again (check if this can be removed) */
1904 FOR_NB_ACTIVE_SCREENS(i)
1906 screens[i].set_viewport(&vp_top[i]);
1907 peak_meter_screen(&screens[i], pm_x[i], pm_y[i], pm_h[i]);
1908 screens[i].update();
1910 } /* display update every second */
1912 if(audio_stat & AUDIO_STATUS_ERROR)
1914 done = true;
1916 } /* end while(!done) */
1918 audio_stat = audio_status();
1919 if (audio_stat & AUDIO_STATUS_ERROR)
1921 splash(0, str(LANG_DISK_FULL));
1923 FOR_NB_SCREENS(i)
1924 screens[i].update();
1926 #if CONFIG_CODEC == SWCODEC
1927 /* stop recording - some players like H10 freeze otherwise
1928 TO DO: find out why it freezes and fix properly */
1929 rec_command(RECORDING_CMD_STOP);
1930 audio_close_recording();
1931 #endif
1933 audio_error_clear();
1935 while(1)
1937 if (action_userabort(TIMEOUT_NOBLOCK))
1938 break;
1942 rec_abort:
1944 #if CONFIG_CODEC == SWCODEC
1945 rec_command(RECORDING_CMD_STOP);
1946 audio_close_recording();
1948 #ifdef HAVE_FMRADIO_REC
1949 if (radio_status != FMRADIO_OFF)
1950 /* Restore radio playback - radio_status should be unchanged if started
1951 through fm radio screen (barring usb connect) */
1952 rec_set_source(AUDIO_SRC_FMRADIO, (radio_status & FMRADIO_PAUSED) ?
1953 SRCF_FMRADIO_PAUSED : SRCF_FMRADIO_PLAYING);
1954 else
1955 #endif
1956 /* Go back to playback mode */
1957 rec_set_source(AUDIO_SRC_PLAYBACK, SRCF_PLAYBACK);
1959 /* restore talking */
1960 talk_disable(false);
1961 #else /* !SWCODEC */
1962 audio_init_playback();
1963 #endif /* CONFIG_CODEC == SWCODEC */
1965 #ifdef HAVE_SPEAKER
1966 /* Re-enable speaker */
1967 audiohw_enable_speaker(global_settings.speaker_enabled);
1968 #endif
1970 /* make sure the trigger is really turned off */
1971 peak_meter_trigger(false);
1972 peak_meter_set_trigger_listener(NULL);
1974 rec_status &= ~RCSTAT_IN_RECSCREEN;
1975 sound_settings_apply();
1977 FOR_NB_SCREENS(i)
1978 screens[i].setfont(FONT_UI);
1980 /* if the directory was created or recording happened, make sure the
1981 browser is updated */
1982 if (rec_status & (RCSTAT_CREATED_DIRECTORY | RCSTAT_HAVE_RECORDED))
1983 reload_directory();
1985 #if (CONFIG_STORAGE & STORAGE_ATA) && (CONFIG_LED == LED_REAL) \
1986 && !defined(SIMULATOR)
1987 ata_set_led_enabled(true);
1988 #endif
1990 settings_save();
1991 pop_current_activity();
1992 return (rec_status & RCSTAT_BEEN_IN_USB_MODE) != 0;
1993 } /* recording_screen */
1995 #if CONFIG_KEYPAD == RECORDER_PAD
1996 static bool f2_rec_screen(void)
1998 static const char* const freq_str[6] =
2000 "44.1kHz",
2001 "48kHz",
2002 "32kHz",
2003 "22.05kHz",
2004 "24kHz",
2005 "16kHz"
2008 bool exit = false;
2009 bool used = false;
2010 int w, h;
2011 char buf[32];
2012 int button;
2013 struct audio_recording_options rec_options;
2015 FOR_NB_SCREENS(i)
2017 screens[i].set_viewport(NULL);
2018 screens[i].setfont(FONT_SYSFIXED);
2019 screens[i].getstringsize("A",&w,&h);
2022 while (!exit) {
2023 const char* ptr;
2025 FOR_NB_SCREENS(i)
2027 screens[i].clear_display();
2029 /* Recording quality */
2030 screens[i].putsxy(0, LCD_HEIGHT/2 - h*2,
2031 str(LANG_SYSFONT_RECORDING_QUALITY));
2034 snprintf(buf, sizeof(buf), "%d", global_settings.rec_quality);
2035 FOR_NB_SCREENS(i)
2037 screens[i].putsxy(0, LCD_HEIGHT/2-h, buf);
2038 screens[i].mono_bitmap(bitmap_icons_7x8[Icon_FastBackward],
2039 LCD_WIDTH/2 - 16, LCD_HEIGHT/2 - 4, 7, 8);
2042 /* Frequency */
2043 snprintf(buf, sizeof buf, "%s:", str(LANG_SYSFONT_RECORDING_FREQUENCY));
2044 ptr = freq_str[global_settings.rec_frequency];
2045 FOR_NB_SCREENS(i)
2047 screens[i].getstringsize(buf,&w,&h);
2048 screens[i].putsxy((LCD_WIDTH-w)/2, LCD_HEIGHT - h*2, buf);
2049 screens[i].getstringsize(ptr, &w, &h);
2050 screens[i].putsxy((LCD_WIDTH-w)/2, LCD_HEIGHT - h, ptr);
2051 screens[i].mono_bitmap(bitmap_icons_7x8[Icon_DownArrow],
2052 LCD_WIDTH/2 - 3, LCD_HEIGHT - h*3, 7, 8);
2055 /* Channel mode */
2056 switch ( global_settings.rec_channels ) {
2057 case 0:
2058 ptr = str(LANG_SYSFONT_CHANNEL_STEREO);
2059 break;
2061 case 1:
2062 ptr = str(LANG_SYSFONT_CHANNEL_MONO);
2063 break;
2066 FOR_NB_SCREENS(i)
2068 screens[i].getstringsize(str(LANG_SYSFONT_CHANNELS), &w, &h);
2069 screens[i].putsxy(LCD_WIDTH - w, LCD_HEIGHT/2 - h*2,
2070 str(LANG_SYSFONT_CHANNELS));
2071 screens[i].getstringsize(str(LANG_SYSFONT_MODE), &w, &h);
2072 screens[i].putsxy(LCD_WIDTH - w, LCD_HEIGHT/2 - h,
2073 str(LANG_SYSFONT_MODE));
2074 screens[i].getstringsize(ptr, &w, &h);
2075 screens[i].putsxy(LCD_WIDTH - w, LCD_HEIGHT/2, ptr);
2076 screens[i].mono_bitmap(bitmap_icons_7x8[Icon_FastForward],
2077 LCD_WIDTH/2 + 8, LCD_HEIGHT/2 - 4, 7, 8);
2079 screens[i].update();
2082 button = button_get(true);
2083 switch (button) {
2084 case BUTTON_LEFT:
2085 case BUTTON_F2 | BUTTON_LEFT:
2086 global_settings.rec_quality++;
2087 if(global_settings.rec_quality > 7)
2088 global_settings.rec_quality = 0;
2089 used = true;
2090 break;
2092 case BUTTON_DOWN:
2093 case BUTTON_F2 | BUTTON_DOWN:
2094 global_settings.rec_frequency++;
2095 if(global_settings.rec_frequency > 5)
2096 global_settings.rec_frequency = 0;
2097 used = true;
2098 break;
2100 case BUTTON_RIGHT:
2101 case BUTTON_F2 | BUTTON_RIGHT:
2102 global_settings.rec_channels++;
2103 if(global_settings.rec_channels > 1)
2104 global_settings.rec_channels = 0;
2105 used = true;
2106 break;
2108 case BUTTON_F2 | BUTTON_REL:
2109 if ( used )
2110 exit = true;
2111 used = true;
2112 break;
2114 case BUTTON_F2 | BUTTON_REPEAT:
2115 used = true;
2116 break;
2118 default:
2119 if(default_event_handler(button) == SYS_USB_CONNECTED)
2120 return true;
2121 break;
2125 rec_init_recording_options(&rec_options);
2126 rec_set_recording_options(&rec_options);
2128 set_gain();
2130 settings_save();
2131 FOR_NB_SCREENS(i)
2132 screens[i].setfont(FONT_UI);
2134 return false;
2137 static bool f3_rec_screen(void)
2139 bool exit = false;
2140 bool used = false;
2141 int w, h;
2142 int button;
2143 const char *src_str[] =
2145 str(LANG_SYSFONT_RECORDING_SRC_MIC),
2146 str(LANG_SYSFONT_LINE_IN),
2147 str(LANG_SYSFONT_RECORDING_SRC_DIGITAL)
2149 struct audio_recording_options rec_options;
2151 FOR_NB_SCREENS(i)
2153 screens[i].set_viewport(NULL);
2154 screens[i].setfont(FONT_SYSFIXED);
2155 screens[i].getstringsize("A",&w,&h);
2158 while (!exit) {
2159 const char* ptr = src_str[global_settings.rec_source];
2160 FOR_NB_SCREENS(i)
2162 screens[i].clear_display();
2164 /* Recording source */
2165 screens[i].putsxy(0, LCD_HEIGHT/2 - h*2,
2166 str(LANG_SYSFONT_RECORDING_SOURCE));
2168 screens[i].getstringsize(ptr, &w, &h);
2169 screens[i].putsxy(0, LCD_HEIGHT/2-h, ptr);
2170 screens[i].mono_bitmap(bitmap_icons_7x8[Icon_FastBackward],
2171 LCD_WIDTH/2 - 16, LCD_HEIGHT/2 - 4, 7, 8);
2174 /* trigger setup */
2175 ptr = str(LANG_SYSFONT_RECORD_TRIGGER);
2176 FOR_NB_SCREENS(i)
2178 screens[i].getstringsize(ptr,&w,&h);
2179 screens[i].putsxy((LCD_WIDTH-w)/2, LCD_HEIGHT - h*2, ptr);
2180 screens[i].mono_bitmap(bitmap_icons_7x8[Icon_DownArrow],
2181 LCD_WIDTH/2 - 3, LCD_HEIGHT - h*3, 7, 8);
2183 screens[i].update();
2186 button = button_get(true);
2187 switch (button) {
2188 case BUTTON_DOWN:
2189 case BUTTON_F3 | BUTTON_DOWN:
2190 #ifndef SIMULATOR
2191 rectrigger();
2192 settings_apply_trigger();
2193 #endif
2194 exit = true;
2195 break;
2197 case BUTTON_LEFT:
2198 case BUTTON_F3 | BUTTON_LEFT:
2199 global_settings.rec_source++;
2200 if(global_settings.rec_source > AUDIO_SRC_MAX)
2201 global_settings.rec_source = 0;
2202 used = true;
2203 break;
2205 case BUTTON_F3 | BUTTON_REL:
2206 if ( used )
2207 exit = true;
2208 used = true;
2209 break;
2211 case BUTTON_F3 | BUTTON_REPEAT:
2212 used = true;
2213 break;
2215 default:
2216 if(default_event_handler(button) == SYS_USB_CONNECTED)
2217 return true;
2218 break;
2222 rec_init_recording_options(&rec_options);
2223 rec_set_recording_options(&rec_options);
2225 set_gain();
2227 settings_save();
2228 FOR_NB_SCREENS(i)
2229 screens[i].setfont(FONT_UI);
2231 return false;
2233 #endif /* CONFIG_KEYPAD == RECORDER_PAD */
2235 #if CONFIG_CODEC == SWCODEC
2236 void audio_beep(int duration)
2238 /* dummy */
2239 (void)duration;
2241 #endif /* #ifdef CONFIG_CODEC == SWCODEC */
2243 #endif /* HAVE_RECORDING */