Rework of libfaad in several areas. Allow removal of malloc with a new define FAAD_ST...
[kugel-rb.git] / apps / recorder / recording.c
blobb4f7d25cf8b27f62b985494679d8d139b11551ab
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(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) || defined(HAVE_RECORDING_HISTOGRAM)
273 static long hist_time = 0;
274 #endif /* HAVE_AGC or HAVE_RECORDING_HISTOGRAM */
275 /* Histogram data */
276 /* TO DO: move some of this stuff inside the recording function? */
277 #ifdef HAVE_RECORDING_HISTOGRAM
278 static int hist_l = 0;
279 static int hist_r = 0;
280 #define HIST_BUF_SIZE (LCD_WIDTH)
281 #define HIST_Y (hist_pos_y+hist_size_h-1)
282 #define HIST_W (LCD_WIDTH / 2 - 4)
283 #if LCD_DEPTH > 1
284 #ifdef HAVE_LCD_COLOR
285 #define LCD_BAL_L LCD_RGBPACK(0, 0, 255)
286 #define LCD_BAL_R LCD_RGBPACK(204, 0, 0)
287 #define LCD_HIST_OVER LCD_RGBPACK(204, 0, 0)
288 #define LCD_HIST_HI LCD_RGBPACK(255, 204, 0)
289 #define LCD_HIST_OK LCD_RGBPACK(51, 153, 0)
290 #else /* HAVE_LCD_COLOR */
291 #define LCD_BATT_OK LCD_BLACK
292 #define LCD_BATT_LO LCD_DARKGRAY
293 #define LCD_DISK_OK LCD_BLACK
294 #define LCD_DISK_LO LCD_DARKGRAY
295 #define LCD_HIST_OVER LCD_BLACK
296 #define LCD_HIST_OK LCD_DARKGRAY
297 #define LCD_BAL LCD_DARKGRAY
298 #endif /* HAVE_LCD_COLOR */
299 #else /* LCD_DEPTH > 1 */
300 #define LCD_HIST_OVER LCD_DEFAULT_FG
301 #define LCD_HIST_OK LCD_DEFAULT_FG
302 #define LCD_BAL LCD_DEFAULT_FG
303 #endif /* LCD_DEPTH > 1 */
304 #endif /* HAVE_RECORDING_HISTOGRAM */
306 static void set_gain(void)
308 #ifdef HAVE_MIC_REC
309 if(global_settings.rec_source == AUDIO_SRC_MIC)
311 if (global_settings.rec_mic_gain > sound_max(SOUND_MIC_GAIN))
312 global_settings.rec_mic_gain = sound_max(SOUND_MIC_GAIN);
314 if (global_settings.rec_mic_gain < sound_min(SOUND_MIC_GAIN))
315 global_settings.rec_mic_gain = sound_min(SOUND_MIC_GAIN);
317 audio_set_recording_gain(global_settings.rec_mic_gain,
318 0, AUDIO_GAIN_MIC);
320 else
321 #endif /* MIC */
323 if (global_settings.rec_left_gain > sound_max(SOUND_LEFT_GAIN))
324 global_settings.rec_left_gain = sound_max(SOUND_LEFT_GAIN);
326 if (global_settings.rec_left_gain < sound_min(SOUND_LEFT_GAIN))
327 global_settings.rec_left_gain = sound_min(SOUND_LEFT_GAIN);
329 if (global_settings.rec_right_gain > sound_max(SOUND_RIGHT_GAIN))
330 global_settings.rec_right_gain = sound_max(SOUND_RIGHT_GAIN);
332 if (global_settings.rec_right_gain < sound_min(SOUND_RIGHT_GAIN))
333 global_settings.rec_right_gain = sound_min(SOUND_RIGHT_GAIN);
335 /* AUDIO_SRC_LINEIN, AUDIO_SRC_FMRADIO, AUDIO_SRC_SPDIF */
336 audio_set_recording_gain(global_settings.rec_left_gain,
337 global_settings.rec_right_gain,
338 AUDIO_GAIN_LINEIN);
340 /* reset the clipping indicators */
341 peak_meter_set_clip_hold(global_settings.peak_meter_clip_hold);
342 update_list = true;
345 #ifdef HAVE_AGC
346 /* Read peak meter values & calculate balance.
347 * Returns validity of peak values.
348 * Used for automatic gain control and history diagram.
350 static bool read_peak_levels(int *peak_l, int *peak_r, int *balance)
352 peak_meter_get_peakhold(peak_l, peak_r);
353 peak_valid_mem[peak_time % 3] = *peak_l;
354 if (((peak_valid_mem[0] == peak_valid_mem[1]) &&
355 (peak_valid_mem[1] == peak_valid_mem[2])) &&
356 ((*peak_l < 32767) || storage_disk_is_active()))
357 return false;
359 if (*peak_r > *peak_l)
360 balance_mem[peak_time % BAL_MEM_SIZE] = (*peak_l ?
361 MIN((10000 * *peak_r) / *peak_l - 10000, 15118) : 15118);
362 else
363 balance_mem[peak_time % BAL_MEM_SIZE] = (*peak_r ?
364 MAX(10000 - (10000 * *peak_l) / *peak_r, -15118) : -15118);
365 *balance = 0;
366 int i;
367 for (i = 0; i < BAL_MEM_SIZE; i++)
368 *balance += balance_mem[i];
369 *balance = *balance / BAL_MEM_SIZE;
371 #ifdef HAVE_RECORDING_HISTOGRAM
372 if (*peak_l > hist_l)
373 hist_l = *peak_l;
374 if (*peak_r > hist_r)
375 hist_r = *peak_r;
376 #endif
378 return true;
381 /* AGC helper function to check if maximum gain is reached */
382 static bool agc_gain_is_max(bool left, bool right)
384 /* range -128...+108 [0.5dB] */
385 short gain_current_l;
386 short gain_current_r;
388 if (agc_preset == 0)
389 return false;
391 switch (global_settings.rec_source)
393 #if defined(HAVE_LINE_REC) || defined(HAVE_FMRADIO_REC)
394 HAVE_LINE_REC_(case AUDIO_SRC_LINEIN:)
395 HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO:)
396 gain_current_l = global_settings.rec_left_gain;
397 gain_current_r = global_settings.rec_right_gain;
398 break;
399 #endif /* LINE, FMRADIO */
400 #if defined(HAVE_MIC_REC)
401 case AUDIO_SRC_MIC:
402 default:
403 gain_current_l = global_settings.rec_mic_gain;
404 gain_current_r = global_settings.rec_mic_gain;
405 #endif /* MIC */
408 return ((left && (gain_current_l >= agc_maxgain)) ||
409 (right && (gain_current_r >= agc_maxgain)));
412 static void change_recording_gain(bool increment, bool left, bool right)
414 int factor = (increment ? 1 : -1);
416 switch (global_settings.rec_source)
418 #if defined(HAVE_LINE_REC) || defined(HAVE_FMRADIO_REC)
419 HAVE_LINE_REC_(case AUDIO_SRC_LINEIN:)
420 HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO:)
421 if (left) global_settings.rec_left_gain += factor;
422 if (right) global_settings.rec_right_gain += factor;
423 break;
424 #endif /* LINE, FMRADIO */
425 #if defined(HAVE_MIC_REC)
426 case AUDIO_SRC_MIC:
427 global_settings.rec_mic_gain += factor;
428 #endif
433 * Handle automatic gain control (AGC).
434 * Change recording gain if peak_x levels are above or below
435 * target volume for specified timeouts.
437 static void auto_gain_control(int *peak_l, int *peak_r, int *balance)
439 int agc_mono;
440 short agc_mode;
441 bool increment;
443 if (*peak_l > agc_left)
444 agc_left = *peak_l;
445 else
446 agc_left -= (agc_left - *peak_l + 3) >> 2;
447 if (*peak_r > agc_right)
448 agc_right = *peak_r;
449 else
450 agc_right -= (agc_right - *peak_r + 3) >> 2;
451 agc_mono = (agc_left + agc_right) / 2;
453 agc_mode = abs(agc_preset) - 1;
454 if (agc_mode < 0) {
455 agc_enable = false;
456 return;
459 if (agc_mode != AGC_SAFETY_MODE) {
460 /* Automatic balance control - only if not in safety mode */
461 if ((agc_left > AGC_IMG) && (agc_right > AGC_IMG))
463 if (*balance < -556)
465 if (*balance > -900)
466 agc_baltime -= !(peak_time % 4); /* 0.47 - 0.75dB */
467 else if (*balance > -4125)
468 agc_baltime--; /* 0.75 - 3.00dB */
469 else if (*balance > -7579)
470 agc_baltime -= 2; /* 3.00 - 4.90dB */
471 else
472 agc_baltime -= !(peak_time % 8); /* 4.90 - inf dB */
473 if (agc_baltime > 0)
474 agc_baltime -= (peak_time % 2);
476 else if (*balance > 556)
478 if (*balance < 900)
479 agc_baltime += !(peak_time % 4);
480 else if (*balance < 4125)
481 agc_baltime++;
482 else if (*balance < 7579)
483 agc_baltime += 2;
484 else
485 agc_baltime += !(peak_time % 8);
486 if (agc_baltime < 0)
487 agc_baltime += (peak_time % 2);
490 if ((*balance * agc_baltime) < 0)
492 if (*balance < 0)
493 agc_baltime -= peak_time % 2;
494 else
495 agc_baltime += peak_time % 2;
498 increment = ((agc_risetime / 2) > agc_droptime);
500 if (agc_baltime < -agc_tbal[agc_mode])
502 if (!increment || !agc_gain_is_max(!increment, increment)) {
503 change_recording_gain(increment, !increment, increment);
504 set_gain();
506 agc_baltime = 0;
508 else if (agc_baltime > +agc_tbal[agc_mode])
510 if (!increment || !agc_gain_is_max(increment, !increment)) {
511 change_recording_gain(increment, increment, !increment);
512 set_gain();
514 agc_baltime = 0;
517 else if (!(hist_time % 4))
519 if (agc_baltime < 0)
520 agc_baltime++;
521 else
522 agc_baltime--;
526 /* Automatic gain control */
527 if ((agc_left > agc_th_hi[agc_mode]) || (agc_right > agc_th_hi[agc_mode]))
529 if ((agc_left > AGC_CLIP) || (agc_right > AGC_CLIP))
530 agc_droptime += agc_tdrop[agc_mode] /
531 (global_settings.rec_agc_cliptime + 1);
532 if (agc_left > AGC_HIGH) {
533 agc_droptime++;
534 agc_risetime=0;
535 if (agc_left > AGC_PEAK)
536 agc_droptime += 2;
538 if (agc_right > AGC_HIGH) {
539 agc_droptime++;
540 agc_risetime=0;
541 if (agc_right > AGC_PEAK)
542 agc_droptime += 2;
544 if (agc_mono > agc_th_hi[agc_mode])
545 agc_droptime++;
546 else
547 agc_droptime += !(peak_time % 2);
549 if (agc_droptime >= agc_tdrop[agc_mode])
551 change_recording_gain(false, true, true);
552 agc_droptime = 0;
553 agc_risetime = 0;
554 set_gain();
556 agc_risetime = MAX(agc_risetime - 1, 0);
558 else if (agc_mono < agc_th_lo[agc_mode])
560 if (agc_mono < (agc_th_lo[agc_mode] / 8))
561 agc_risetime += !(peak_time % 5);
562 else if (agc_mono < (agc_th_lo[agc_mode] / 2))
563 agc_risetime += 2;
564 else
565 agc_risetime++;
567 if (agc_risetime >= agc_trise[agc_mode]) {
568 if ((agc_mode != AGC_SAFETY_MODE) &&
569 (!agc_gain_is_max(true, true))) {
570 change_recording_gain(true, true, true);
571 set_gain();
573 agc_risetime = 0;
574 agc_droptime = 0;
576 agc_droptime = MAX(agc_droptime - 1, 0);
578 else if (!(peak_time % 6)) /* on target level every 1.2 sec */
580 agc_risetime = MAX(agc_risetime - 1, 0);
581 agc_droptime = MAX(agc_droptime - 1, 0);
584 #endif /* HAVE_AGC */
586 static const char* const fmtstr[] =
588 "%c%d %s", /* no decimals */
589 "%c%d.%d %s ", /* 1 decimal */
590 "%c%d.%02d %s " /* 2 decimals */
593 static const char factor[] = {1, 10, 100};
595 static char *fmt_gain(int snd, int val, char *str, int len)
597 int i, d, numdec;
598 const char *unit;
599 char sign = ' ';
601 val = sound_val2phys(snd, val);
602 if(val < 0)
604 sign = '-';
605 val = -val;
607 numdec = sound_numdecimals(snd);
608 unit = sound_unit(snd);
610 if(numdec)
612 i = val / factor[numdec];
613 d = val % factor[numdec];
614 snprintf(str, len, fmtstr[numdec], sign, i, d, unit);
616 else
617 snprintf(str, len, fmtstr[numdec], sign, val, unit);
619 return str;
622 /* the list below must match enum audio_sources in audio.h */
623 static const char* const prestr[] =
625 HAVE_MIC_IN_([AUDIO_SRC_MIC] = "R_MIC_",)
626 HAVE_LINE_REC_([AUDIO_SRC_LINEIN] = "R_LINE_",)
627 HAVE_SPDIF_IN_([AUDIO_SRC_SPDIF] = "R_SPDIF_",)
628 HAVE_FMRADIO_REC_([AUDIO_SRC_FMRADIO] = "R_FM_",)
631 char *rec_create_filename(char *buffer)
633 char ext[16];
634 const char *pref = "R_";
636 /* Directory existence and writeablility should have already been
637 * verified - do not pass NULL pointers to pcmrec */
639 if((unsigned)global_settings.rec_source < AUDIO_NUM_SOURCES)
641 pref = prestr[global_settings.rec_source];
644 strcpy(buffer, !strcmp(global_settings.rec_directory, "/")?
645 "": global_settings.rec_directory);
647 snprintf(ext, sizeof(ext), ".%s",
648 REC_FILE_ENDING(global_settings.rec_format));
650 #if CONFIG_RTC == 0
651 return create_numbered_filename(buffer, buffer, pref, ext, 4,
652 &file_number);
653 #else
654 /* We'll wait at least up to the start of the next second so no duplicate
655 names are created */
656 return create_datetime_filename(buffer, buffer, pref, ext, true);
657 #endif
660 #if CONFIG_RTC == 0
661 /* Hit disk to get a starting filename for the type */
662 static void rec_init_filename(void)
664 file_number = -1;
665 rec_create_filename(path_buffer);
666 file_number--;
668 #endif
670 int rec_create_directory(void)
672 int rc = 0;
673 const char * const folder = global_settings.rec_directory;
675 if (strcmp(folder, "/") && !dir_exists(folder))
677 rc = mkdir(folder);
679 if(rc < 0)
681 while (action_userabort(HZ) == false)
683 splashf(0, "%s %s",
684 str(LANG_REC_DIR_NOT_WRITABLE),
685 str(LANG_OFF_ABORT));
688 else
690 rec_status |= RCSTAT_CREATED_DIRECTORY;
691 rc = 1;
695 return rc;
698 void rec_init_recording_options(struct audio_recording_options *options)
700 options->rec_source = global_settings.rec_source;
701 options->rec_frequency = global_settings.rec_frequency;
702 options->rec_channels = global_settings.rec_channels;
703 options->rec_prerecord_time = global_settings.rec_prerecord_time;
704 #if CONFIG_CODEC == SWCODEC
705 options->rec_mono_mode = global_settings.rec_mono_mode;
706 options->rec_source_flags = 0;
707 options->enc_config.rec_format = global_settings.rec_format;
708 global_to_encoder_config(&options->enc_config);
709 #else
710 options->rec_quality = global_settings.rec_quality;
711 options->rec_editable = global_settings.rec_editable;
712 #endif
715 #if CONFIG_CODEC == SWCODEC
716 void rec_set_source(int source, unsigned flags)
718 /* Set audio input source, power up/down devices */
719 audio_set_input_source(source, flags);
721 /* Set peakmeters for recording or reset to playback */
722 peak_meter_playback((flags & SRCF_RECORDING) == 0);
723 peak_meter_enable(true);
725 #endif /* CONFIG_CODEC == SWCODEC */
727 void rec_set_recording_options(struct audio_recording_options *options)
729 #if CONFIG_CODEC != SWCODEC
730 if (global_settings.rec_prerecord_time)
732 talk_buffer_steal(); /* will use the mp3 buffer */
734 #else /* == SWCODEC */
735 rec_set_source(options->rec_source,
736 options->rec_source_flags | SRCF_RECORDING);
737 #endif /* CONFIG_CODEC != SWCODEC */
739 audio_set_recording_options(options);
742 void rec_command(enum recording_command cmd)
744 switch(cmd)
746 case RECORDING_CMD_STOP_SHUTDOWN:
747 pm_activate_clipcount(false);
748 audio_stop_recording();
749 #if CONFIG_CODEC == SWCODEC
750 audio_close_recording();
751 #endif
752 sys_poweroff();
753 break;
754 case RECORDING_CMD_STOP:
755 pm_activate_clipcount(false);
756 audio_stop_recording();
757 break;
758 case RECORDING_CMD_START:
759 /* steal mp3 buffer, create unique filename and start recording */
760 pm_reset_clipcount();
761 pm_activate_clipcount(true);
762 #if CONFIG_CODEC != SWCODEC
763 talk_buffer_steal(); /* we use the mp3 buffer */
764 #endif
765 audio_record(rec_create_filename(path_buffer));
766 break;
767 case RECORDING_CMD_START_NEWFILE:
768 /* create unique filename and start recording*/
769 pm_reset_clipcount();
770 pm_activate_clipcount(true); /* just to be sure */
771 audio_new_file(rec_create_filename(path_buffer));
772 break;
773 case RECORDING_CMD_PAUSE:
774 pm_activate_clipcount(false);
775 audio_pause_recording();
776 break;
777 case RECORDING_CMD_RESUME:
778 pm_activate_clipcount(true);
779 audio_resume_recording();
780 break;
782 update_list = true;
785 /* used in trigger_listerner and recording_screen */
786 static unsigned int last_seconds = 0;
789 * Callback function so that the peak meter code can send an event
790 * to this application. This function can be passed to
791 * peak_meter_set_trigger_listener in order to activate the trigger.
793 static void trigger_listener(int trigger_status)
795 switch (trigger_status)
797 case TRIG_GO:
798 if(!(audio_status() & AUDIO_STATUS_RECORD))
800 rec_status |= RCSTAT_HAVE_RECORDED;
801 rec_command(RECORDING_CMD_START);
802 #if CONFIG_CODEC != SWCODEC
803 /* give control to mpeg thread so that it can start
804 recording */
805 yield(); yield(); yield();
806 #endif
809 /* if we're already recording this is a retrigger */
810 else
812 if((audio_status() & AUDIO_STATUS_PAUSE) &&
813 (global_settings.rec_trigger_type == TRIG_TYPE_PAUSE))
815 rec_command(RECORDING_CMD_RESUME);
817 /* New file on trig start*/
818 else if (global_settings.rec_trigger_type != TRIG_TYPE_NEW_FILE)
820 rec_command(RECORDING_CMD_START_NEWFILE);
821 /* tell recording_screen to reset the time */
822 last_seconds = 0;
825 break;
827 /* A _change_ to TRIG_READY means the current recording has stopped */
828 case TRIG_READY:
829 if(audio_status() & AUDIO_STATUS_RECORD)
831 switch(global_settings.rec_trigger_type)
833 case TRIG_TYPE_STOP: /* Stop */
834 rec_command(RECORDING_CMD_STOP);
835 break;
837 case TRIG_TYPE_PAUSE: /* Pause */
838 rec_command(RECORDING_CMD_PAUSE);
839 break;
841 case TRIG_TYPE_NEW_FILE: /* New file on trig stop*/
842 rec_command(RECORDING_CMD_START_NEWFILE);
843 /* tell recording_screen to reset the time */
844 last_seconds = 0;
845 break;
847 case 3: /* Stop and shutdown */
848 rec_command(RECORDING_CMD_STOP_SHUTDOWN);
849 break;
852 if (global_settings.rec_trigger_mode != TRIG_MODE_REARM)
854 peak_meter_set_trigger_listener(NULL);
855 peak_meter_trigger(false);
858 break;
862 /* Stuff for drawing the screen */
864 enum rec_list_items_stereo {
865 ITEM_VOLUME = 0,
866 ITEM_GAIN = 1,
867 ITEM_GAIN_L = 2,
868 ITEM_GAIN_R = 3,
869 #ifdef HAVE_AGC
870 ITEM_AGC_MODE = 4,
871 ITEM_AGC_MAXDB = 5,
872 ITEM_FILENAME = 7,
873 ITEM_COUNT = 7,
874 #else
875 ITEM_FILENAME = 7,
876 ITEM_COUNT = 5,
877 #endif
880 enum rec_list_items_mono {
881 ITEM_VOLUME_M = 0,
882 ITEM_GAIN_M = 1,
883 #ifdef HAVE_AGC
884 ITEM_AGC_MODE_M = 4,
885 ITEM_AGC_MAXDB_M = 5,
886 ITEM_FILENAME_M = 7,
887 ITEM_COUNT_M = 5,
888 #else
889 ITEM_FILENAME_M = 7,
890 ITEM_COUNT_M = 3,
891 #endif
894 #ifdef HAVE_SPDIF_REC
895 enum rec_list_items_spdif {
896 ITEM_VOLUME_D = 0,
897 #if CONFIG_CODEC == SWCODEC
898 ITEM_SAMPLERATE_D = 6,
899 ITEM_FILENAME_D = 7,
900 ITEM_COUNT_D = 3,
901 #else
902 ITEM_FILENAME_D = 7,
903 ITEM_COUNT_D = 2,
904 #endif
906 #endif
908 static int listid_to_enum[ITEM_COUNT];
910 static const char* reclist_get_name(int selected_item, void * data,
911 char * buffer, size_t buffer_len)
913 char buf2[32];
914 #ifdef HAVE_AGC
915 char buf3[32];
916 #endif
917 data = data; /* not used */
918 if(selected_item >= ITEM_COUNT)
919 return "";
921 switch (listid_to_enum[selected_item])
923 case ITEM_VOLUME:
924 snprintf(buffer, buffer_len, "%s: %s", str(LANG_VOLUME),
925 fmt_gain(SOUND_VOLUME,
926 global_settings.volume,
927 buf2, sizeof(buf2)));
928 break;
929 case ITEM_GAIN:
930 #ifdef HAVE_MIC_REC
931 if(global_settings.rec_source == AUDIO_SRC_MIC)
933 /* Draw MIC recording gain */
934 snprintf(buffer, buffer_len, "%s: %s", str(LANG_GAIN),
935 fmt_gain(SOUND_MIC_GAIN,
936 global_settings.rec_mic_gain,
937 buf2, sizeof(buf2)));
939 else
940 #endif /* MIC */
942 int avg_gain = (global_settings.rec_left_gain +
943 global_settings.rec_right_gain) / 2;
944 snprintf(buffer, buffer_len, "%s: %s", str(LANG_GAIN),
945 fmt_gain(SOUND_LEFT_GAIN,
946 avg_gain,
947 buf2, sizeof(buf2)));
949 break;
950 case ITEM_GAIN_L:
951 snprintf(buffer, buffer_len, "%s: %s",
952 str(LANG_GAIN_LEFT),
953 fmt_gain(SOUND_LEFT_GAIN,
954 global_settings.rec_left_gain,
955 buf2, sizeof(buf2)));
956 break;
957 case ITEM_GAIN_R:
958 snprintf(buffer, buffer_len, "%s: %s",
959 str(LANG_GAIN_RIGHT),
960 fmt_gain(SOUND_RIGHT_GAIN,
961 global_settings.rec_right_gain,
962 buf2, sizeof(buf2)));
963 break;
964 #ifdef HAVE_AGC
965 case ITEM_AGC_MODE:
966 snprintf(buffer, buffer_len, "%s: %s",
967 str(LANG_RECORDING_AGC_PRESET),
968 agc_preset_str[agc_preset]);
969 break;
970 case ITEM_AGC_MAXDB:
971 if (agc_preset == 0)
972 snprintf(buffer, buffer_len, "%s: %s",
973 str(LANG_RECORDING_AGC_MAXGAIN),
974 fmt_gain(SOUND_LEFT_GAIN,
975 agc_maxgain, buf2, sizeof(buf2)));
976 #ifdef HAVE_MIC_REC
977 else if (global_settings.rec_source == AUDIO_SRC_MIC)
978 snprintf(buffer, buffer_len, "%s: %s (%s)",
979 str(LANG_RECORDING_AGC_MAXGAIN),
980 fmt_gain(SOUND_MIC_GAIN,
981 agc_maxgain, buf2, sizeof(buf2)),
982 fmt_gain(SOUND_MIC_GAIN,
983 agc_maxgain - global_settings.rec_mic_gain,
984 buf3, sizeof(buf3)));
985 else
986 #endif /* MIC */
987 snprintf(buffer, buffer_len, "%s: %s (%s)",
988 str(LANG_RECORDING_AGC_MAXGAIN),
989 fmt_gain(SOUND_LEFT_GAIN,
990 agc_maxgain, buf2, sizeof(buf2)),
991 fmt_gain(SOUND_LEFT_GAIN,
992 agc_maxgain -
993 (global_settings.rec_left_gain +
994 global_settings.rec_right_gain)/2,
995 buf3, sizeof(buf3)));
996 break;
997 #endif
998 #if CONFIG_CODEC == SWCODEC
999 #ifdef HAVE_SPDIF_REC
1000 case ITEM_SAMPLERATE_D:
1001 snprintf(buffer, buffer_len, "%s: %lu",
1002 str(LANG_RECORDING_FREQUENCY),
1003 pcm_rec_sample_rate());
1004 break;
1005 #endif
1006 #endif
1007 case ITEM_FILENAME:
1009 if(audio_status() & AUDIO_STATUS_RECORD)
1011 size_t tot_len = strlen(path_buffer) +
1012 strlen(str(LANG_RECORDING_FILENAME)) + 1;
1013 if(tot_len > buffer_len)
1015 snprintf(buffer, buffer_len, "%s %s",
1016 str(LANG_RECORDING_FILENAME),
1017 path_buffer + tot_len - buffer_len);
1019 else
1021 snprintf(buffer, buffer_len, "%s %s",
1022 str(LANG_RECORDING_FILENAME), path_buffer);
1025 else
1027 return str(LANG_RECORDING_FILENAME);
1029 break;
1031 default:
1032 return "";
1034 return buffer;
1038 bool recording_start_automatic = false;
1040 bool recording_screen(bool no_source)
1042 int button;
1043 int done = -1; /* negative to re-init, positive to quit, zero to run */
1044 char buf[32]; /* for preparing strings */
1045 char buf2[32]; /* for preparing strings */
1046 int w, h; /* character width/height */
1047 int update_countdown = 0; /* refresh counter */
1048 unsigned int seconds;
1049 int hours, minutes;
1050 int audio_stat = 0; /* status of the audio system */
1051 int last_audio_stat = -1; /* previous status so we can act on changes */
1052 struct viewport vp_list[NB_SCREENS], vp_top[NB_SCREENS]; /* the viewports */
1054 #if CONFIG_CODEC == SWCODEC
1055 int warning_counter = 0;
1056 #define WARNING_PERIOD 7
1057 #endif
1059 #if CONFIG_CODEC == SWCODEC
1060 #ifdef HAVE_SPDIF_REC
1061 unsigned long prev_sample_rate = 0;
1062 #endif
1063 #endif
1065 #ifdef HAVE_FMRADIO_REC
1066 /* Radio is left on if:
1067 * 1) Is was on at the start and the initial source is FM Radio
1068 * 2) 1) and the source was never changed to something else
1070 int radio_status = (global_settings.rec_source != AUDIO_SRC_FMRADIO) ?
1071 FMRADIO_OFF : get_radio_status();
1072 #endif
1073 #if (CONFIG_LED == LED_REAL)
1074 bool led_state = false;
1075 int led_countdown = 2;
1076 #endif
1077 #ifdef HAVE_AGC
1078 bool peak_read = false;
1079 int peak_l, peak_r;
1080 int balance = 0;
1081 #endif
1082 int i;
1083 int pm_x[NB_SCREENS]; /* peakmeter (and trigger bar) x pos */
1084 int pm_y[NB_SCREENS]; /* peakmeter y pos */
1085 int pm_h[NB_SCREENS]; /* peakmeter height */
1086 int trig_ypos[NB_SCREENS]; /* trigger bar y pos */
1087 int trig_width[NB_SCREENS]; /* trigger bar width */
1088 int top_height_req[NB_SCREENS]; /* required height for top half */
1089 /* tweak layout tiny screens / big fonts */
1090 bool compact_view[NB_SCREENS] = { false };
1091 struct gui_synclist lists; /* the list in the bottom vp */
1092 #if defined(HAVE_AGC) || defined(HAVE_RECORDING_HISTOGRAM)
1093 bool peak_valid = false;
1094 #endif
1095 #if defined(HAVE_RECORDING_HISTOGRAM)
1096 int j;
1097 unsigned short hist_pos_y = 0;
1098 unsigned short hist_size_h = 0;
1099 int history_pos = 0;
1100 short hist_time_interval = 1; /* 1, 2, 4, 8 */
1101 unsigned char history_l[HIST_BUF_SIZE];
1102 unsigned char history_r[HIST_BUF_SIZE];
1103 const char hist_level_marks[6] = { 29, 26, 23, 17, 9, 2};
1104 #endif
1105 #ifdef HAVE_FMRADIO_REC
1106 int prev_rec_source = global_settings.rec_source; /* detect source change */
1107 #endif
1109 struct audio_recording_options rec_options;
1110 rec_status = RCSTAT_IN_RECSCREEN;
1112 #if (CONFIG_STORAGE & STORAGE_ATA) && (CONFIG_LED == LED_REAL) \
1113 && !defined(SIMULATOR)
1114 ata_set_led_enabled(false);
1115 #endif
1117 #if CONFIG_CODEC == SWCODEC
1118 /* This should be done before touching audio settings */
1119 while (!audio_is_thread_ready())
1120 sleep(0);
1122 /* recording_menu gets messed up: so prevent manus talking */
1123 talk_disable(true);
1124 /* audio_init_recording stops anything playing when it takes the audio
1125 buffer */
1126 #else
1127 /* Yes, we use the D/A for monitoring */
1128 peak_meter_enable(true);
1129 peak_meter_playback(true);
1130 #endif
1132 #ifdef HAVE_AGC
1133 peak_meter_get_peakhold(&peak_l, &peak_r);
1134 #endif
1136 pm_reset_clipcount();
1137 pm_activate_clipcount(false);
1138 settings_apply_trigger();
1140 #ifdef HAVE_AGC
1141 agc_preset_str[0] = str(LANG_OFF);
1142 agc_preset_str[1] = str(LANG_AGC_SAFETY);
1143 agc_preset_str[2] = str(LANG_AGC_LIVE);
1144 agc_preset_str[3] = str(LANG_AGC_DJSET);
1145 agc_preset_str[4] = str(LANG_AGC_MEDIUM);
1146 agc_preset_str[5] = str(LANG_AGC_VOICE);
1147 #endif /* HAVE_AGC */
1149 #ifdef HAVE_SPEAKER
1150 /* Disable speaker to prevent feedback */
1151 audiohw_enable_speaker(false);
1152 #endif
1154 #if CONFIG_CODEC == SWCODEC
1155 audio_close_recording();
1156 #endif
1157 audio_init_recording(0);
1158 sound_set_volume(global_settings.volume);
1160 #if CONFIG_RTC == 0
1161 /* Create new filename for recording start */
1162 rec_init_filename();
1163 #endif
1165 /* start of the loop: we stay in this loop until user quits recscreen */
1166 while(done <= 0)
1168 if(done < 0)
1170 /* request to re-init stuff, done after settings screen */
1171 done = 0;
1172 #ifdef HAVE_FMRADIO_REC
1173 /* If input changes away from FM Radio,
1174 radio will remain off when recording screen closes. */
1175 if (global_settings.rec_source != prev_rec_source
1176 && prev_rec_source == AUDIO_SRC_FMRADIO)
1177 radio_status = FMRADIO_OFF;
1178 prev_rec_source = global_settings.rec_source;
1179 #endif
1181 /* viewport init and calculations that only needs to be done once */
1182 FOR_NB_SCREENS(i)
1184 struct viewport *v;
1185 /* top vp, 4 lines, force sys font if total screen < 6 lines
1186 NOTE: one could limit the list to 1 line and get away with 5 lines */
1187 top_height_req[i] = 4;
1188 #if defined(HAVE_RECORDING_HISTOGRAM)
1189 if((global_settings.rec_histogram_interval) && (!i))
1190 top_height_req[i] += 1; /* use one line for histogram */
1191 hist_time_interval = 1 << global_settings.rec_histogram_interval;
1192 #endif
1193 v = &vp_top[i];
1194 viewport_set_defaults(v, i);
1195 if (viewport_get_nb_lines(v) < top_height_req[i])
1197 /* compact needs 4 lines total */
1198 v->font = FONT_SYSFIXED;
1199 compact_view[i] = false;
1201 else
1203 /*top=4,list=2*/
1204 if (viewport_get_nb_lines(v) < (top_height_req[i]+2))
1205 compact_view[i] = true;
1206 else
1207 compact_view[i] = false;
1209 vp_list[i] = *v; /* get a copy now so it can be sized more easily */
1210 v->height = (font_get(v->font)->height)*(compact_view[i] ? 3 :
1211 top_height_req[i]);
1213 /* list section, rest of the screen */
1214 vp_list[i].y += vp_top[i].height;
1215 vp_list[i].height -= vp_top[i].height;
1216 screens[i].set_viewport(&vp_top[i]); /* req for next calls */
1218 screens[i].getstringsize("W", &w, &h);
1219 pm_y[i] = font_get(vp_top[i].font)->height * 2;
1220 trig_ypos[i] = font_get(vp_top[i].font)->height * 3;
1221 if(compact_view[i])
1222 trig_ypos[i] -= (font_get(vp_top[i].font)->height)/2;
1225 /* init the bottom list */
1226 gui_synclist_init(&lists, reclist_get_name, NULL, false, 1, vp_list);
1227 gui_synclist_set_title(&lists, NULL, Icon_NOICON);
1229 send_event(GUI_EVENT_ACTIONUPDATE, (void*)1); /* force a redraw */
1231 #if defined(HAVE_RECORDING_HISTOGRAM)
1232 history_pos = 0;
1233 hist_pos_y = (compact_view[0] ? 3 : 4) * (font_get(vp_top[0].font)->height)
1234 + 1;
1235 hist_size_h = font_get(vp_top[0].font)->height - 2;
1236 memset(history_l, 0, sizeof(unsigned char)*HIST_BUF_SIZE);
1237 memset(history_r, 0, sizeof(unsigned char)*HIST_BUF_SIZE);
1238 #endif
1240 FOR_NB_SCREENS(i)
1242 pm_x[i] = 0;
1243 if(global_settings.peak_meter_clipcounter)
1245 int clipwidth = 0;
1246 screens[i].getstringsize(str(LANG_PM_CLIPCOUNT),
1247 &clipwidth, &h); /* h is same */
1248 pm_x[i] = clipwidth+1;
1250 if(global_settings.rec_trigger_mode == TRIG_MODE_OFF)
1251 pm_h[i] = font_get(vp_top[i].font)->height * 2;
1252 else
1253 pm_h[i] = font_get(vp_top[i].font)->height;
1254 if(compact_view[i])
1255 pm_h[i] /= 2;
1256 trig_width[i] = vp_top[i].width - pm_x[i];
1259 #if CONFIG_CODEC == SWCODEC
1260 audio_close_recording();
1261 audio_init_recording(0);
1262 #endif
1264 rec_init_recording_options(&rec_options);
1265 rec_set_recording_options(&rec_options);
1267 if(rec_create_directory() < 0)
1269 rec_status = 0;
1270 goto rec_abort;
1273 #if CONFIG_CODEC == SWCODEC && CONFIG_RTC == 0
1274 /* If format changed, a new number is required */
1275 rec_init_filename();
1276 #endif
1278 #ifdef HAVE_AGC
1279 #ifdef HAVE_MIC_REC
1280 if (global_settings.rec_source == AUDIO_SRC_MIC) {
1281 agc_preset = global_settings.rec_agc_preset_mic;
1282 agc_maxgain = global_settings.rec_agc_maxgain_mic;
1284 else
1285 #endif /* MIC */
1287 agc_preset = global_settings.rec_agc_preset_line;
1288 agc_maxgain = global_settings.rec_agc_maxgain_line;
1290 #endif /* HAVE_AGC */
1292 set_gain();
1293 update_countdown = 0; /* Update immediately */
1295 /* populate translation table for list id -> enum */
1296 #ifdef HAVE_SPDIF_REC
1297 if(global_settings.rec_source == AUDIO_SRC_SPDIF)
1299 listid_to_enum[0] = ITEM_VOLUME_D;
1300 #if CONFIG_CODEC == SWCODEC
1301 listid_to_enum[1] = ITEM_SAMPLERATE_D;
1302 listid_to_enum[2] = ITEM_FILENAME_D;
1303 #else
1304 listid_to_enum[1] = ITEM_FILENAME_D;
1305 #endif
1307 gui_synclist_set_nb_items(&lists, ITEM_COUNT_D); /* spdif */
1309 else
1310 #endif
1311 if(HAVE_MIC_REC_((global_settings.rec_source == AUDIO_SRC_MIC) || )
1312 (global_settings.rec_channels == 1))
1314 listid_to_enum[0] = ITEM_VOLUME_M;
1315 listid_to_enum[1] = ITEM_GAIN_M;
1316 #ifdef HAVE_AGC
1317 listid_to_enum[2] = ITEM_AGC_MODE_M;
1318 listid_to_enum[3] = ITEM_AGC_MAXDB_M;
1319 listid_to_enum[4] = ITEM_FILENAME_M;
1320 #else
1321 listid_to_enum[2] = ITEM_FILENAME_M;
1322 #endif
1323 gui_synclist_set_nb_items(&lists, ITEM_COUNT_M); /* mono */
1325 else
1327 listid_to_enum[0] = ITEM_VOLUME;
1328 listid_to_enum[1] = ITEM_GAIN;
1329 listid_to_enum[2] = ITEM_GAIN_L;
1330 listid_to_enum[3] = ITEM_GAIN_R;
1331 #ifdef HAVE_AGC
1332 listid_to_enum[4] = ITEM_AGC_MODE;
1333 listid_to_enum[5] = ITEM_AGC_MAXDB;
1334 listid_to_enum[6] = ITEM_FILENAME;
1335 #else
1336 listid_to_enum[4] = ITEM_FILENAME;
1337 #endif
1338 gui_synclist_set_nb_items(&lists, ITEM_COUNT); /* stereo */
1341 gui_synclist_draw(&lists);
1342 } /* if(done < 0) */
1344 audio_stat = audio_status();
1346 #if (CONFIG_LED == LED_REAL)
1349 * Flash the LED while waiting to record. Turn it on while
1350 * recording.
1352 if(audio_stat & AUDIO_STATUS_RECORD)
1354 if (audio_stat & AUDIO_STATUS_PAUSE)
1356 if (--led_countdown <= 0)
1358 led_state = !led_state;
1359 led(led_state);
1360 led_countdown = 2;
1363 else
1365 /* trigger is on in status TRIG_READY (no check needed) */
1366 led(true);
1369 else
1371 int trig_stat = peak_meter_trigger_status();
1373 * other trigger stati than trig_off and trig_steady
1374 * already imply that we are recording.
1376 if (trig_stat == TRIG_STEADY)
1378 if (--led_countdown <= 0)
1380 led_state = !led_state;
1381 led(led_state);
1382 led_countdown = 2;
1385 else
1387 /* trigger is on in status TRIG_READY (no check needed) */
1388 led(false);
1391 #endif /* CONFIG_LED */
1393 /* Wait for a button a while (HZ/10) drawing the peak meter */
1394 button = peak_meter_draw_get_btn(CONTEXT_RECSCREEN,
1395 pm_x, pm_y, pm_h,
1396 screen_update, vp_top);
1397 if (last_audio_stat != audio_stat)
1399 if (audio_stat & AUDIO_STATUS_RECORD)
1401 rec_status |= RCSTAT_HAVE_RECORDED;
1403 last_audio_stat = audio_stat;
1404 update_list = true;
1407 if (recording_start_automatic)
1409 /* simulate a button press */
1410 button = ACTION_REC_PAUSE;
1411 recording_start_automatic = false;
1414 /* let list handle the button */
1415 gui_synclist_do_button(&lists, &button, LIST_WRAP_UNLESS_HELD);
1418 switch(button)
1420 case ACTION_SETTINGS_INC:
1421 case ACTION_SETTINGS_INCREPEAT:
1422 switch (listid_to_enum[gui_synclist_get_sel_pos(&lists)])
1424 case ITEM_VOLUME:
1425 global_settings.volume += sound_steps(SOUND_VOLUME);
1426 setvol();
1427 break;
1428 case ITEM_GAIN:
1429 #ifdef HAVE_MIC_REC
1430 if(global_settings.rec_source == AUDIO_SRC_MIC)
1432 global_settings.rec_mic_gain +=
1433 sound_steps(SOUND_MIC_GAIN);
1435 else
1436 #endif /* MIC */
1438 global_settings.rec_left_gain +=
1439 sound_steps(SOUND_LEFT_GAIN);
1440 global_settings.rec_right_gain +=
1441 sound_steps(SOUND_RIGHT_GAIN);
1443 break;
1444 case ITEM_GAIN_L:
1445 global_settings.rec_left_gain +=
1446 sound_steps(SOUND_LEFT_GAIN);
1448 break;
1449 case ITEM_GAIN_R:
1450 global_settings.rec_right_gain +=
1451 sound_steps(SOUND_RIGHT_GAIN);
1453 break;
1454 #ifdef HAVE_AGC
1455 case ITEM_AGC_MODE:
1456 agc_preset = MIN(agc_preset + 1, AGC_MODE_SIZE);
1457 agc_enable = (agc_preset != 0);
1458 #ifdef HAVE_MIC_REC
1459 if (global_settings.rec_source == AUDIO_SRC_MIC) {
1460 global_settings.rec_agc_preset_mic = agc_preset;
1461 agc_maxgain = global_settings.rec_agc_maxgain_mic;
1462 } else
1463 #endif /* MIC */
1465 global_settings.rec_agc_preset_line = agc_preset;
1466 agc_maxgain = global_settings.rec_agc_maxgain_line;
1468 break;
1469 case ITEM_AGC_MAXDB:
1470 #ifdef HAVE_MIC_REC
1471 if (global_settings.rec_source == AUDIO_SRC_MIC)
1473 agc_maxgain = MIN(agc_maxgain + 1,
1474 sound_max(SOUND_MIC_GAIN));
1475 global_settings.rec_agc_maxgain_mic = agc_maxgain;
1477 else
1478 #endif /* MIC */
1480 agc_maxgain = MIN(agc_maxgain + 1,
1481 sound_max(SOUND_LEFT_GAIN));
1482 global_settings.rec_agc_maxgain_line = agc_maxgain;
1484 break;
1485 #endif /* HAVE_AGC */
1487 set_gain();
1488 update_countdown = 0; /* Update immediately */
1489 break;
1490 case ACTION_SETTINGS_DEC:
1491 case ACTION_SETTINGS_DECREPEAT:
1492 switch (listid_to_enum[gui_synclist_get_sel_pos(&lists)])
1494 case ITEM_VOLUME:
1495 global_settings.volume -= sound_steps(SOUND_VOLUME);
1497 /* check range and update */
1498 setvol();
1499 break;
1500 case ITEM_GAIN:
1501 #ifdef HAVE_MIC_REC
1502 if(global_settings.rec_source == AUDIO_SRC_MIC)
1504 global_settings.rec_mic_gain -=
1505 sound_steps(SOUND_MIC_GAIN);
1507 else
1508 #endif /* MIC */
1510 global_settings.rec_left_gain -=
1511 sound_steps(SOUND_LEFT_GAIN);
1513 global_settings.rec_right_gain -=
1514 sound_steps(SOUND_RIGHT_GAIN);
1516 break;
1517 case ITEM_GAIN_L:
1518 global_settings.rec_left_gain -=
1519 sound_steps(SOUND_LEFT_GAIN);
1521 break;
1522 case ITEM_GAIN_R:
1523 global_settings.rec_right_gain -=
1524 sound_steps(SOUND_RIGHT_GAIN);
1526 break;
1527 #ifdef HAVE_AGC
1528 case ITEM_AGC_MODE:
1529 agc_preset = MAX(agc_preset - 1, 0);
1530 agc_enable = (agc_preset != 0);
1531 #ifdef HAVE_MIC_REC
1532 if (global_settings.rec_source == AUDIO_SRC_MIC) {
1533 global_settings.rec_agc_preset_mic = agc_preset;
1534 agc_maxgain = global_settings.rec_agc_maxgain_mic;
1535 } else
1536 #endif /* MIC */
1538 global_settings.rec_agc_preset_line = agc_preset;
1539 agc_maxgain = global_settings.rec_agc_maxgain_line;
1541 break;
1542 case ITEM_AGC_MAXDB:
1543 #ifdef HAVE_MIC_REC
1544 if (global_settings.rec_source == AUDIO_SRC_MIC)
1546 agc_maxgain = MAX(agc_maxgain - 1,
1547 sound_min(SOUND_MIC_GAIN));
1548 global_settings.rec_agc_maxgain_mic = agc_maxgain;
1549 } else
1550 #endif /* MIC */
1552 agc_maxgain = MAX(agc_maxgain - 1,
1553 sound_min(SOUND_LEFT_GAIN));
1554 global_settings.rec_agc_maxgain_line = agc_maxgain;
1556 break;
1557 #endif /* HAVE_AGC */
1559 set_gain();
1560 update_countdown = 0; /* Update immediately */
1561 break;
1562 case ACTION_STD_CANCEL:
1563 /* turn off the trigger */
1564 peak_meter_trigger(false);
1565 peak_meter_set_trigger_listener(NULL);
1567 if(audio_stat & AUDIO_STATUS_RECORD)
1569 rec_command(RECORDING_CMD_STOP);
1571 else
1573 #if CONFIG_CODEC != SWCODEC
1574 peak_meter_playback(true);
1575 peak_meter_enable(false);
1576 #endif
1577 done = 1;
1579 update_countdown = 0; /* Update immediately */
1580 break;
1581 #ifdef HAVE_REMOTE_LCD
1582 case ACTION_REC_LCD:
1583 /* this feature exists for some h1x0/h3x0 targets that suffer
1584 from noise caused by remote LCD updates
1585 NOTE 1: this will leave the list on the remote
1586 NOTE 2: to be replaced by a global LCD_off() routine */
1587 if(remote_display_on)
1589 /* switch to single screen, leave message on remote */
1590 screen_update = 1;
1591 screens[1].clear_viewport();
1592 screens[1].puts(0, 0, str(LANG_REMOTE_LCD_OFF));
1593 screens[1].puts(0, 1, str(LANG_REMOTE_LCD_ON));
1594 screens[1].update_viewport();
1596 else
1598 /* remote switched on again */
1599 update_list = true;
1600 screen_update = NB_SCREENS;
1602 remote_display_on = !remote_display_on; /* toggle */
1603 update_countdown = 0; /* Update immediately */
1604 break;
1605 #endif
1606 case ACTION_REC_PAUSE:
1607 case ACTION_REC_NEWFILE:
1608 /* Only act if the mpeg is stopped */
1609 if(!(audio_stat & AUDIO_STATUS_RECORD))
1611 /* is this manual or triggered recording? */
1612 if ((global_settings.rec_trigger_mode == TRIG_MODE_OFF) ||
1613 (peak_meter_trigger_status() != TRIG_OFF))
1615 /* manual recording */
1616 rec_status |= RCSTAT_HAVE_RECORDED;
1617 rec_command(RECORDING_CMD_START);
1618 last_seconds = 0;
1619 if (global_settings.talk_menu)
1621 /* no voice possible here, but a beep */
1622 audio_beep(HZ/2); /* longer beep on start */
1625 /* this is triggered recording */
1626 else
1628 /* we don't start recording now, but enable the
1629 trigger and let the callback function
1630 trigger_listener control when the recording starts */
1631 peak_meter_trigger(true);
1632 peak_meter_set_trigger_listener(&trigger_listener);
1635 else
1637 /*if new file button pressed, start new file */
1638 if (button == ACTION_REC_NEWFILE)
1640 rec_command(RECORDING_CMD_START_NEWFILE);
1641 last_seconds = 0;
1643 else
1644 /* if pause button pressed, pause or resume */
1646 if(audio_stat & AUDIO_STATUS_PAUSE)
1648 rec_command(RECORDING_CMD_RESUME);
1649 if (global_settings.talk_menu)
1651 /* no voice possible here, but a beep */
1652 audio_beep(HZ/4); /* short beep on resume */
1655 else
1657 rec_command(RECORDING_CMD_PAUSE);
1661 update_countdown = 0; /* Update immediately */
1662 break;
1663 case ACTION_STD_MENU:
1664 #if CONFIG_CODEC == SWCODEC
1665 if(!(audio_stat & AUDIO_STATUS_RECORD))
1666 #else
1667 if(audio_stat != AUDIO_STATUS_RECORD)
1668 #endif
1670 #if (CONFIG_LED == LED_REAL)
1671 /* led is restored at begin of loop / end of function */
1672 led(false);
1673 #endif
1674 if (recording_menu(no_source))
1676 done = 1;
1677 rec_status |= RCSTAT_BEEN_IN_USB_MODE;
1678 #ifdef HAVE_FMRADIO_REC
1679 radio_status = FMRADIO_OFF;
1680 #endif
1682 else
1684 done = -1;
1685 /* the init is now done at the beginning of the loop */
1688 break;
1690 #if CONFIG_KEYPAD == RECORDER_PAD
1691 case ACTION_REC_F2:
1692 if(audio_stat != AUDIO_STATUS_RECORD)
1694 #if (CONFIG_LED == LED_REAL)
1695 /* led is restored at begin of loop / end of function */
1696 led(false);
1697 #endif
1698 if (f2_rec_screen())
1700 rec_status |= RCSTAT_HAVE_RECORDED;
1701 done = true;
1703 else
1704 update_countdown = 0; /* Update immediately */
1706 break;
1708 case ACTION_REC_F3:
1709 if(audio_stat & AUDIO_STATUS_RECORD)
1711 rec_command(RECORDING_CMD_START_NEWFILE);
1712 last_seconds = 0;
1714 else
1716 #if (CONFIG_LED == LED_REAL)
1717 /* led is restored at begin of loop / end of function */
1718 led(false);
1719 #endif
1720 if (f3_rec_screen())
1722 rec_status |= RCSTAT_HAVE_RECORDED;
1723 done = true;
1725 else
1726 update_countdown = 0; /* Update immediately */
1728 break;
1729 #endif /* CONFIG_KEYPAD == RECORDER_PAD */
1731 case SYS_USB_CONNECTED:
1732 /* Only accept USB connection when not recording */
1733 if(!(audio_stat & AUDIO_STATUS_RECORD))
1735 FOR_NB_SCREENS(i)
1736 screens[i].set_viewport(NULL);
1737 default_event_handler(SYS_USB_CONNECTED);
1738 done = true;
1739 rec_status |= RCSTAT_BEEN_IN_USB_MODE;
1740 #ifdef HAVE_FMRADIO_REC
1741 radio_status = FMRADIO_OFF;
1742 #endif
1744 break;
1745 } /*switch(button)*/
1747 #ifdef HAVE_AGC
1748 peak_read = !peak_read;
1749 if (peak_read) { /* every 2nd run of loop */
1750 peak_time++;
1751 peak_valid = read_peak_levels(&peak_l, &peak_r, &balance);
1754 /* Handle AGC every 200ms when enabled and peak data is valid */
1755 if (peak_read && agc_enable && peak_valid)
1756 auto_gain_control(&peak_l, &peak_r, &balance);
1757 #endif
1759 seconds = audio_recorded_time() / HZ;
1761 /* start of vp_top drawing */
1762 if(update_countdown-- == 0 || seconds > last_seconds)
1764 unsigned int dseconds, dhours, dminutes;
1765 unsigned long num_recorded_bytes, dsize, dmb;
1767 FOR_NB_SCREENS(i)
1769 screens[i].set_viewport(&vp_top[i]);
1770 screens[i].clear_viewport();
1772 update_countdown = 5;
1773 last_seconds = seconds;
1775 dseconds = rec_timesplit_seconds();
1776 dsize = rec_sizesplit_bytes();
1777 num_recorded_bytes = audio_num_recorded_bytes();
1779 #if CONFIG_CODEC == SWCODEC
1780 if ((audio_stat & AUDIO_STATUS_WARNING)
1781 && (warning_counter++ % WARNING_PERIOD) < WARNING_PERIOD/2)
1783 /* Switch back and forth displaying warning on first available
1784 line to ensure visibility - the motion should also help
1785 draw attention */
1786 /* Don't use language string unless agreed upon to make this
1787 method permanent - could do something in the statusbar */
1788 snprintf(buf, sizeof(buf), "Warning: %08lX",
1789 pcm_rec_get_warnings());
1791 else
1792 #endif /* CONFIG_CODEC == SWCODEC */
1793 if ((global_settings.rec_sizesplit) &&
1794 (global_settings.rec_split_method))
1796 dmb = dsize/1024/1024;
1797 snprintf(buf, sizeof(buf), "%s %luMB",
1798 str(LANG_SPLIT_SIZE), dmb);
1800 else
1802 hours = seconds / 3600;
1803 minutes = (seconds - (hours * 3600)) / 60;
1804 snprintf(buf, sizeof(buf), "%s %02d:%02d:%02d",
1805 str(LANG_RECORDING_TIME),
1806 hours, minutes, seconds%60);
1809 FOR_NB_ACTIVE_SCREENS(i)
1810 screens[i].puts(0, 0, buf);
1812 if(audio_stat & AUDIO_STATUS_PRERECORD)
1814 snprintf(buf, sizeof(buf), "%s...",
1815 str(LANG_RECORD_PRERECORD));
1817 else
1819 /* Display the split interval if the record timesplit
1820 is active */
1821 if ((global_settings.rec_timesplit) &&
1822 !(global_settings.rec_split_method))
1824 /* Display the record timesplit interval rather
1825 than the file size if the record timer is active */
1826 dhours = dseconds / 3600;
1827 dminutes = (dseconds - (dhours * 3600)) / 60;
1828 snprintf(buf, sizeof(buf), "%s %02d:%02d",
1829 str(LANG_RECORDING_TIMESPLIT_REC),
1830 dhours, dminutes);
1832 else
1834 output_dyn_value(buf2, sizeof buf2,
1835 num_recorded_bytes,
1836 byte_units, true);
1837 snprintf(buf, sizeof(buf), "%s %s",
1838 str(LANG_RECORDING_SIZE), buf2);
1842 FOR_NB_ACTIVE_SCREENS(i)
1843 screens[i].puts(0, 1, buf);
1845 /* We will do file splitting regardless, either at the end of
1846 a split interval, or when the filesize approaches the 2GB
1847 FAT file size (compatibility) limit. */
1848 if ((audio_stat && !(global_settings.rec_split_method)
1849 && global_settings.rec_timesplit && (seconds >= dseconds))
1850 || (audio_stat && global_settings.rec_split_method
1851 && global_settings.rec_sizesplit
1852 && (num_recorded_bytes >= dsize))
1853 || (num_recorded_bytes >= MAX_FILE_SIZE))
1855 if (!(global_settings.rec_split_type)
1856 || (num_recorded_bytes >= MAX_FILE_SIZE))
1858 rec_command(RECORDING_CMD_START_NEWFILE);
1859 last_seconds = 0;
1861 else
1863 peak_meter_trigger(false);
1864 peak_meter_set_trigger_listener(NULL);
1865 if( global_settings.rec_split_type == 1)
1866 rec_command(RECORDING_CMD_STOP);
1867 else
1868 rec_command(RECORDING_CMD_STOP_SHUTDOWN);
1870 update_countdown = 0;
1873 /* draw the clipcounter just in front of the peakmeter */
1874 if(global_settings.peak_meter_clipcounter)
1876 int clipcount = pm_get_clipcount();
1877 FOR_NB_ACTIVE_SCREENS(i)
1879 if(!compact_view[i])
1881 screens[i].puts(0, 2, str(LANG_PM_CLIPCOUNT));
1882 screens[i].putsf(0, 3, "%4d", clipcount);
1884 else
1885 screens[i].putsf(0, 2, "%4d", clipcount);
1889 #ifdef HAVE_RECORDING_HISTOGRAM
1890 if(global_settings.rec_histogram_interval)
1892 if (peak_valid && !(hist_time % hist_time_interval) && hist_l)
1894 /* fill history buffer */
1895 history_l[history_pos] = hist_l * hist_size_h / 32767;
1896 history_r[history_pos] = hist_r * hist_size_h / 32767;
1897 history_pos = (history_pos + 1) % HIST_BUF_SIZE;
1898 history_l[history_pos] = history_r[history_pos] = 0;
1899 history_l[(history_pos + 1) % HIST_BUF_SIZE] = 0;
1900 history_r[(history_pos + 1) % HIST_BUF_SIZE] = 0;
1901 hist_l = 0;
1902 hist_r = 0;
1904 lcd_set_drawmode(DRMODE_SOLID);
1905 lcd_drawrect(0, hist_pos_y - 1,
1906 HIST_W + 2, hist_size_h + 1);
1907 lcd_drawrect(HIST_W + 6, hist_pos_y - 1,
1908 HIST_W + 2, hist_size_h + 1);
1909 lcd_set_drawmode(DRMODE_FG);
1911 j = history_pos;
1912 for (i = HIST_W-1; i >= 0; i--)
1914 j--;
1915 if(j<0)
1916 j = HIST_BUF_SIZE-1;
1917 if (history_l[j])
1919 if (history_l[j] == hist_size_h)
1920 lcd_set_foreground(LCD_HIST_OVER);
1921 #ifdef HAVE_LCD_COLOR
1922 else if (history_l[j] > hist_level_marks[1])
1923 lcd_set_foreground(LCD_HIST_HI);
1924 #endif
1925 else
1926 lcd_set_foreground(LCD_HIST_OK);
1927 lcd_vline(1 + i, HIST_Y-1, HIST_Y - history_l[j]);
1929 if (history_r[j])
1931 if (history_r[j] == hist_size_h)
1932 lcd_set_foreground(LCD_HIST_OVER);
1933 #ifdef HAVE_LCD_COLOR
1934 else if (history_r[j] > hist_level_marks[1])
1935 lcd_set_foreground(LCD_HIST_HI);
1936 #endif
1937 else
1938 lcd_set_foreground(LCD_HIST_OK);
1939 lcd_vline(HIST_W+7 + i, HIST_Y-1, HIST_Y - history_r[j]);
1942 lcd_set_foreground(
1943 #ifdef HAVE_LCD_COLOR
1944 global_settings.fg_color);
1945 #else
1946 LCD_DEFAULT_FG);
1947 #endif
1948 for (i = 0; i < 6; i++)
1949 lcd_hline(HIST_W + 3, HIST_W + 4,
1950 HIST_Y - hist_level_marks[i]);
1952 #endif /* HAVE_RECORDING_HISTOGRAM */
1954 #ifdef HAVE_AGC
1955 hist_time++;
1956 #endif
1958 /* draw the trigger status */
1959 if (peak_meter_trigger_status() != TRIG_OFF)
1961 peak_meter_draw_trig(pm_x, trig_ypos, trig_width,
1962 screen_update);
1963 FOR_NB_ACTIVE_SCREENS(i)
1964 screens[i].update_viewport_rect(pm_x[i], trig_ypos[i],
1965 trig_width[i] + 2, TRIG_HEIGHT);
1968 #ifdef HAVE_AGC
1969 #ifdef HAVE_MIC_REC
1970 if (global_settings.rec_source == AUDIO_SRC_MIC)
1972 if(agc_maxgain < (global_settings.rec_mic_gain))
1973 change_recording_gain(false, true, true);
1975 else
1976 #endif /* MIC */
1978 if(agc_maxgain < (global_settings.rec_left_gain))
1979 change_recording_gain(false, true, false);
1980 if(agc_maxgain < (global_settings.rec_right_gain))
1981 change_recording_gain(false, false, true);
1983 #endif /* HAVE_AGC */
1985 #if CONFIG_CODEC == SWCODEC
1986 #ifdef HAVE_SPDIF_REC
1987 if((global_settings.rec_source == AUDIO_SRC_SPDIF) &&
1988 (prev_sample_rate != pcm_rec_sample_rate()))
1990 /* spdif samplerate changed */
1991 prev_sample_rate = pcm_rec_sample_rate();
1992 update_list = true;
1994 #endif
1995 #endif
1997 if(update_list)
1999 /* update_list is set whenever content changes */
2000 update_list = false;
2001 gui_synclist_draw(&lists);
2004 /* draw peakmeter again (check if this can be removed) */
2005 FOR_NB_ACTIVE_SCREENS(i)
2007 screens[i].set_viewport(&vp_top[i]);
2008 peak_meter_screen(&screens[i], pm_x[i], pm_y[i], pm_h[i]);
2009 screens[i].update();
2011 } /* display update every second */
2013 if(audio_stat & AUDIO_STATUS_ERROR)
2015 done = true;
2017 } /* end while(!done) */
2019 audio_stat = audio_status();
2020 if (audio_stat & AUDIO_STATUS_ERROR)
2022 splash(0, str(LANG_DISK_FULL));
2024 FOR_NB_SCREENS(i)
2025 screens[i].update();
2027 #if CONFIG_CODEC == SWCODEC
2028 /* stop recording - some players like H10 freeze otherwise
2029 TO DO: find out why it freezes and fix properly */
2030 rec_command(RECORDING_CMD_STOP);
2031 audio_close_recording();
2032 #endif
2034 audio_error_clear();
2036 while(1)
2038 if (action_userabort(TIMEOUT_NOBLOCK))
2039 break;
2043 rec_abort:
2045 #if CONFIG_CODEC == SWCODEC
2046 rec_command(RECORDING_CMD_STOP);
2047 audio_close_recording();
2049 #ifdef HAVE_FMRADIO_REC
2050 if (radio_status != FMRADIO_OFF)
2051 /* Restore radio playback - radio_status should be unchanged if started
2052 through fm radio screen (barring usb connect) */
2053 rec_set_source(AUDIO_SRC_FMRADIO, (radio_status & FMRADIO_PAUSED) ?
2054 SRCF_FMRADIO_PAUSED : SRCF_FMRADIO_PLAYING);
2055 else
2056 #endif
2057 /* Go back to playback mode */
2058 rec_set_source(AUDIO_SRC_PLAYBACK, SRCF_PLAYBACK);
2060 /* restore talking */
2061 talk_disable(false);
2062 #else /* !SWCODEC */
2063 audio_init_playback();
2064 #endif /* CONFIG_CODEC == SWCODEC */
2066 #ifdef HAVE_SPEAKER
2067 /* Re-enable speaker */
2068 audiohw_enable_speaker(global_settings.speaker_enabled);
2069 #endif
2071 /* make sure the trigger is really turned off */
2072 peak_meter_trigger(false);
2073 peak_meter_set_trigger_listener(NULL);
2075 rec_status &= ~RCSTAT_IN_RECSCREEN;
2076 sound_settings_apply();
2078 FOR_NB_SCREENS(i)
2079 screens[i].setfont(FONT_UI);
2081 /* if the directory was created or recording happened, make sure the
2082 browser is updated */
2083 if (rec_status & (RCSTAT_CREATED_DIRECTORY | RCSTAT_HAVE_RECORDED))
2084 reload_directory();
2086 #if (CONFIG_STORAGE & STORAGE_ATA) && (CONFIG_LED == LED_REAL) \
2087 && !defined(SIMULATOR)
2088 ata_set_led_enabled(true);
2089 #endif
2091 settings_save();
2093 return (rec_status & RCSTAT_BEEN_IN_USB_MODE) != 0;
2094 } /* recording_screen */
2096 #if CONFIG_KEYPAD == RECORDER_PAD
2097 static bool f2_rec_screen(void)
2099 static const char* const freq_str[6] =
2101 "44.1kHz",
2102 "48kHz",
2103 "32kHz",
2104 "22.05kHz",
2105 "24kHz",
2106 "16kHz"
2109 bool exit = false;
2110 bool used = false;
2111 int w, h, i;
2112 char buf[32];
2113 int button;
2114 struct audio_recording_options rec_options;
2116 FOR_NB_SCREENS(i)
2118 screens[i].set_viewport(NULL);
2119 screens[i].setfont(FONT_SYSFIXED);
2120 screens[i].getstringsize("A",&w,&h);
2123 while (!exit) {
2124 const char* ptr;
2126 FOR_NB_SCREENS(i)
2128 screens[i].clear_display();
2130 /* Recording quality */
2131 screens[i].putsxy(0, LCD_HEIGHT/2 - h*2,
2132 str(LANG_SYSFONT_RECORDING_QUALITY));
2135 snprintf(buf, sizeof(buf), "%d", global_settings.rec_quality);
2136 FOR_NB_SCREENS(i)
2138 screens[i].putsxy(0, LCD_HEIGHT/2-h, buf);
2139 screens[i].mono_bitmap(bitmap_icons_7x8[Icon_FastBackward],
2140 LCD_WIDTH/2 - 16, LCD_HEIGHT/2 - 4, 7, 8);
2143 /* Frequency */
2144 snprintf(buf, sizeof buf, "%s:", str(LANG_SYSFONT_RECORDING_FREQUENCY));
2145 ptr = freq_str[global_settings.rec_frequency];
2146 FOR_NB_SCREENS(i)
2148 screens[i].getstringsize(buf,&w,&h);
2149 screens[i].putsxy((LCD_WIDTH-w)/2, LCD_HEIGHT - h*2, buf);
2150 screens[i].getstringsize(ptr, &w, &h);
2151 screens[i].putsxy((LCD_WIDTH-w)/2, LCD_HEIGHT - h, ptr);
2152 screens[i].mono_bitmap(bitmap_icons_7x8[Icon_DownArrow],
2153 LCD_WIDTH/2 - 3, LCD_HEIGHT - h*3, 7, 8);
2156 /* Channel mode */
2157 switch ( global_settings.rec_channels ) {
2158 case 0:
2159 ptr = str(LANG_SYSFONT_CHANNEL_STEREO);
2160 break;
2162 case 1:
2163 ptr = str(LANG_SYSFONT_CHANNEL_MONO);
2164 break;
2167 FOR_NB_SCREENS(i)
2169 screens[i].getstringsize(str(LANG_SYSFONT_CHANNELS), &w, &h);
2170 screens[i].putsxy(LCD_WIDTH - w, LCD_HEIGHT/2 - h*2,
2171 str(LANG_SYSFONT_CHANNELS));
2172 screens[i].getstringsize(str(LANG_SYSFONT_MODE), &w, &h);
2173 screens[i].putsxy(LCD_WIDTH - w, LCD_HEIGHT/2 - h,
2174 str(LANG_SYSFONT_MODE));
2175 screens[i].getstringsize(ptr, &w, &h);
2176 screens[i].putsxy(LCD_WIDTH - w, LCD_HEIGHT/2, ptr);
2177 screens[i].mono_bitmap(bitmap_icons_7x8[Icon_FastForward],
2178 LCD_WIDTH/2 + 8, LCD_HEIGHT/2 - 4, 7, 8);
2180 screens[i].update();
2183 button = button_get(true);
2184 switch (button) {
2185 case BUTTON_LEFT:
2186 case BUTTON_F2 | BUTTON_LEFT:
2187 global_settings.rec_quality++;
2188 if(global_settings.rec_quality > 7)
2189 global_settings.rec_quality = 0;
2190 used = true;
2191 break;
2193 case BUTTON_DOWN:
2194 case BUTTON_F2 | BUTTON_DOWN:
2195 global_settings.rec_frequency++;
2196 if(global_settings.rec_frequency > 5)
2197 global_settings.rec_frequency = 0;
2198 used = true;
2199 break;
2201 case BUTTON_RIGHT:
2202 case BUTTON_F2 | BUTTON_RIGHT:
2203 global_settings.rec_channels++;
2204 if(global_settings.rec_channels > 1)
2205 global_settings.rec_channels = 0;
2206 used = true;
2207 break;
2209 case BUTTON_F2 | BUTTON_REL:
2210 if ( used )
2211 exit = true;
2212 used = true;
2213 break;
2215 case BUTTON_F2 | BUTTON_REPEAT:
2216 used = true;
2217 break;
2219 default:
2220 if(default_event_handler(button) == SYS_USB_CONNECTED)
2221 return true;
2222 break;
2226 rec_init_recording_options(&rec_options);
2227 rec_set_recording_options(&rec_options);
2229 set_gain();
2231 settings_save();
2232 FOR_NB_SCREENS(i)
2233 screens[i].setfont(FONT_UI);
2235 return false;
2238 static bool f3_rec_screen(void)
2240 bool exit = false;
2241 bool used = false;
2242 int w, h, i;
2243 int button;
2244 const char *src_str[] =
2246 str(LANG_SYSFONT_RECORDING_SRC_MIC),
2247 str(LANG_SYSFONT_LINE_IN),
2248 str(LANG_SYSFONT_RECORDING_SRC_DIGITAL)
2250 struct audio_recording_options rec_options;
2252 FOR_NB_SCREENS(i)
2254 screens[i].set_viewport(NULL);
2255 screens[i].setfont(FONT_SYSFIXED);
2256 screens[i].getstringsize("A",&w,&h);
2259 while (!exit) {
2260 const char* ptr = src_str[global_settings.rec_source];
2261 FOR_NB_SCREENS(i)
2263 screens[i].clear_display();
2265 /* Recording source */
2266 screens[i].putsxy(0, LCD_HEIGHT/2 - h*2,
2267 str(LANG_SYSFONT_RECORDING_SOURCE));
2269 screens[i].getstringsize(ptr, &w, &h);
2270 screens[i].putsxy(0, LCD_HEIGHT/2-h, ptr);
2271 screens[i].mono_bitmap(bitmap_icons_7x8[Icon_FastBackward],
2272 LCD_WIDTH/2 - 16, LCD_HEIGHT/2 - 4, 7, 8);
2275 /* trigger setup */
2276 ptr = str(LANG_SYSFONT_RECORD_TRIGGER);
2277 FOR_NB_SCREENS(i)
2279 screens[i].getstringsize(ptr,&w,&h);
2280 screens[i].putsxy((LCD_WIDTH-w)/2, LCD_HEIGHT - h*2, ptr);
2281 screens[i].mono_bitmap(bitmap_icons_7x8[Icon_DownArrow],
2282 LCD_WIDTH/2 - 3, LCD_HEIGHT - h*3, 7, 8);
2284 screens[i].update();
2287 button = button_get(true);
2288 switch (button) {
2289 case BUTTON_DOWN:
2290 case BUTTON_F3 | BUTTON_DOWN:
2291 #ifndef SIMULATOR
2292 rectrigger();
2293 settings_apply_trigger();
2294 #endif
2295 exit = true;
2296 break;
2298 case BUTTON_LEFT:
2299 case BUTTON_F3 | BUTTON_LEFT:
2300 global_settings.rec_source++;
2301 if(global_settings.rec_source > AUDIO_SRC_MAX)
2302 global_settings.rec_source = 0;
2303 used = true;
2304 break;
2306 case BUTTON_F3 | BUTTON_REL:
2307 if ( used )
2308 exit = true;
2309 used = true;
2310 break;
2312 case BUTTON_F3 | BUTTON_REPEAT:
2313 used = true;
2314 break;
2316 default:
2317 if(default_event_handler(button) == SYS_USB_CONNECTED)
2318 return true;
2319 break;
2323 rec_init_recording_options(&rec_options);
2324 rec_set_recording_options(&rec_options);
2326 set_gain();
2328 settings_save();
2329 FOR_NB_SCREENS(i)
2330 screens[i].setfont(FONT_UI);
2332 return false;
2334 #endif /* CONFIG_KEYPAD == RECORDER_PAD */
2336 #if CONFIG_CODEC == SWCODEC
2337 void audio_beep(int duration)
2339 /* dummy */
2340 (void)duration;
2342 #endif /* #ifdef CONFIG_CODEC == SWCODEC */
2344 #endif /* HAVE_RECORDING */