MPEGPlayer: Skip to next file when there is a problem with a video file in all-play...
[kugel-rb.git] / apps / recorder / recording.c
blobd5db37371706261e3b53f5da888ce81c16275a21
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 audio_set_recording_gain(global_settings.rec_mic_gain,
312 0, AUDIO_GAIN_MIC);
314 else
315 #endif /* MIC */
317 /* AUDIO_SRC_LINEIN, AUDIO_SRC_FMRADIO, AUDIO_SRC_SPDIF */
318 audio_set_recording_gain(global_settings.rec_left_gain,
319 global_settings.rec_right_gain,
320 AUDIO_GAIN_LINEIN);
322 /* reset the clipping indicators */
323 peak_meter_set_clip_hold(global_settings.peak_meter_clip_hold);
324 update_list = true;
327 #ifdef HAVE_AGC
328 /* Read peak meter values & calculate balance.
329 * Returns validity of peak values.
330 * Used for automatic gain control and history diagram.
332 static bool read_peak_levels(int *peak_l, int *peak_r, int *balance)
334 peak_meter_get_peakhold(peak_l, peak_r);
335 peak_valid_mem[peak_time % 3] = *peak_l;
336 if (((peak_valid_mem[0] == peak_valid_mem[1]) &&
337 (peak_valid_mem[1] == peak_valid_mem[2])) &&
338 ((*peak_l < 32767) || storage_disk_is_active()))
339 return false;
341 if (*peak_r > *peak_l)
342 balance_mem[peak_time % BAL_MEM_SIZE] = (*peak_l ?
343 MIN((10000 * *peak_r) / *peak_l - 10000, 15118) : 15118);
344 else
345 balance_mem[peak_time % BAL_MEM_SIZE] = (*peak_r ?
346 MAX(10000 - (10000 * *peak_l) / *peak_r, -15118) : -15118);
347 *balance = 0;
348 int i;
349 for (i = 0; i < BAL_MEM_SIZE; i++)
350 *balance += balance_mem[i];
351 *balance = *balance / BAL_MEM_SIZE;
353 #ifdef HAVE_RECORDING_HISTOGRAM
354 if (*peak_l > hist_l)
355 hist_l = *peak_l;
356 if (*peak_r > hist_r)
357 hist_r = *peak_r;
358 #endif
360 return true;
363 /* AGC helper function to check if maximum gain is reached */
364 static bool agc_gain_is_max(bool left, bool right)
366 /* range -128...+108 [0.5dB] */
367 short gain_current_l;
368 short gain_current_r;
370 if (agc_preset == 0)
371 return false;
373 switch (global_settings.rec_source)
375 #if defined(HAVE_LINE_REC) || defined(HAVE_FMRADIO_REC)
376 HAVE_LINE_REC_(case AUDIO_SRC_LINEIN:)
377 HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO:)
378 gain_current_l = global_settings.rec_left_gain;
379 gain_current_r = global_settings.rec_right_gain;
380 break;
381 #endif /* LINE, FMRADIO */
382 #if defined(HAVE_MIC_REC)
383 case AUDIO_SRC_MIC:
384 default:
385 gain_current_l = global_settings.rec_mic_gain;
386 gain_current_r = global_settings.rec_mic_gain;
387 #endif /* MIC */
390 return ((left && (gain_current_l >= agc_maxgain)) ||
391 (right && (gain_current_r >= agc_maxgain)));
394 static void change_recording_gain(bool increment, bool left, bool right)
396 int factor = (increment ? 1 : -1);
398 switch (global_settings.rec_source)
400 #if defined(HAVE_LINE_REC) || defined(HAVE_FMRADIO_REC)
401 HAVE_LINE_REC_(case AUDIO_SRC_LINEIN:)
402 HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO:)
403 if (left) global_settings.rec_left_gain += factor;
404 if (right) global_settings.rec_right_gain += factor;
405 break;
406 #endif /* LINE, FMRADIO */
407 #if defined(HAVE_MIC_REC)
408 case AUDIO_SRC_MIC:
409 global_settings.rec_mic_gain += factor;
410 #endif
415 * Handle automatic gain control (AGC).
416 * Change recording gain if peak_x levels are above or below
417 * target volume for specified timeouts.
419 static void auto_gain_control(int *peak_l, int *peak_r, int *balance)
421 int agc_mono;
422 short agc_mode;
423 bool increment;
425 if (*peak_l > agc_left)
426 agc_left = *peak_l;
427 else
428 agc_left -= (agc_left - *peak_l + 3) >> 2;
429 if (*peak_r > agc_right)
430 agc_right = *peak_r;
431 else
432 agc_right -= (agc_right - *peak_r + 3) >> 2;
433 agc_mono = (agc_left + agc_right) / 2;
435 agc_mode = abs(agc_preset) - 1;
436 if (agc_mode < 0) {
437 agc_enable = false;
438 return;
441 if (agc_mode != AGC_SAFETY_MODE) {
442 /* Automatic balance control - only if not in safety mode */
443 if ((agc_left > AGC_IMG) && (agc_right > AGC_IMG))
445 if (*balance < -556)
447 if (*balance > -900)
448 agc_baltime -= !(peak_time % 4); /* 0.47 - 0.75dB */
449 else if (*balance > -4125)
450 agc_baltime--; /* 0.75 - 3.00dB */
451 else if (*balance > -7579)
452 agc_baltime -= 2; /* 3.00 - 4.90dB */
453 else
454 agc_baltime -= !(peak_time % 8); /* 4.90 - inf dB */
455 if (agc_baltime > 0)
456 agc_baltime -= (peak_time % 2);
458 else if (*balance > 556)
460 if (*balance < 900)
461 agc_baltime += !(peak_time % 4);
462 else if (*balance < 4125)
463 agc_baltime++;
464 else if (*balance < 7579)
465 agc_baltime += 2;
466 else
467 agc_baltime += !(peak_time % 8);
468 if (agc_baltime < 0)
469 agc_baltime += (peak_time % 2);
472 if ((*balance * agc_baltime) < 0)
474 if (*balance < 0)
475 agc_baltime -= peak_time % 2;
476 else
477 agc_baltime += peak_time % 2;
480 increment = ((agc_risetime / 2) > agc_droptime);
482 if (agc_baltime < -agc_tbal[agc_mode])
484 if (!increment || !agc_gain_is_max(!increment, increment)) {
485 change_recording_gain(increment, !increment, increment);
486 set_gain();
488 agc_baltime = 0;
490 else if (agc_baltime > +agc_tbal[agc_mode])
492 if (!increment || !agc_gain_is_max(increment, !increment)) {
493 change_recording_gain(increment, increment, !increment);
494 set_gain();
496 agc_baltime = 0;
499 else if (!(hist_time % 4))
501 if (agc_baltime < 0)
502 agc_baltime++;
503 else
504 agc_baltime--;
508 /* Automatic gain control */
509 if ((agc_left > agc_th_hi[agc_mode]) || (agc_right > agc_th_hi[agc_mode]))
511 if ((agc_left > AGC_CLIP) || (agc_right > AGC_CLIP))
512 agc_droptime += agc_tdrop[agc_mode] /
513 (global_settings.rec_agc_cliptime + 1);
514 if (agc_left > AGC_HIGH) {
515 agc_droptime++;
516 agc_risetime=0;
517 if (agc_left > AGC_PEAK)
518 agc_droptime += 2;
520 if (agc_right > AGC_HIGH) {
521 agc_droptime++;
522 agc_risetime=0;
523 if (agc_right > AGC_PEAK)
524 agc_droptime += 2;
526 if (agc_mono > agc_th_hi[agc_mode])
527 agc_droptime++;
528 else
529 agc_droptime += !(peak_time % 2);
531 if (agc_droptime >= agc_tdrop[agc_mode])
533 change_recording_gain(false, true, true);
534 agc_droptime = 0;
535 agc_risetime = 0;
536 set_gain();
538 agc_risetime = MAX(agc_risetime - 1, 0);
540 else if (agc_mono < agc_th_lo[agc_mode])
542 if (agc_mono < (agc_th_lo[agc_mode] / 8))
543 agc_risetime += !(peak_time % 5);
544 else if (agc_mono < (agc_th_lo[agc_mode] / 2))
545 agc_risetime += 2;
546 else
547 agc_risetime++;
549 if (agc_risetime >= agc_trise[agc_mode]) {
550 if ((agc_mode != AGC_SAFETY_MODE) &&
551 (!agc_gain_is_max(true, true))) {
552 change_recording_gain(true, true, true);
553 set_gain();
555 agc_risetime = 0;
556 agc_droptime = 0;
558 agc_droptime = MAX(agc_droptime - 1, 0);
560 else if (!(peak_time % 6)) /* on target level every 1.2 sec */
562 agc_risetime = MAX(agc_risetime - 1, 0);
563 agc_droptime = MAX(agc_droptime - 1, 0);
566 #endif /* HAVE_AGC */
568 static const char* const fmtstr[] =
570 "%c%d %s", /* no decimals */
571 "%c%d.%d %s ", /* 1 decimal */
572 "%c%d.%02d %s " /* 2 decimals */
575 static char *fmt_gain(int snd, int val, char *str, int len)
577 int i, d, numdec;
578 const char *unit;
579 char sign = ' ';
581 val = sound_val2phys(snd, val);
582 if(val < 0)
584 sign = '-';
585 val = -val;
587 numdec = sound_numdecimals(snd);
588 unit = sound_unit(snd);
590 if(numdec)
592 i = val / (10*numdec);
593 d = val % (10*numdec);
594 snprintf(str, len, fmtstr[numdec], sign, i, d, unit);
596 else
597 snprintf(str, len, fmtstr[numdec], sign, val, unit);
599 return str;
602 /* the list below must match enum audio_sources in audio.h */
603 static const char* const prestr[] =
605 HAVE_MIC_IN_([AUDIO_SRC_MIC] = "R_MIC_",)
606 HAVE_LINE_REC_([AUDIO_SRC_LINEIN] = "R_LINE_",)
607 HAVE_SPDIF_IN_([AUDIO_SRC_SPDIF] = "R_SPDIF_",)
608 HAVE_FMRADIO_REC_([AUDIO_SRC_FMRADIO] = "R_FM_",)
611 char *rec_create_filename(char *buffer)
613 char ext[16];
614 const char *pref = "R_";
616 /* Directory existence and writeablility should have already been
617 * verified - do not pass NULL pointers to pcmrec */
619 if((unsigned)global_settings.rec_source < AUDIO_NUM_SOURCES)
621 pref = prestr[global_settings.rec_source];
624 strcpy(buffer, !strcmp(global_settings.rec_directory, "/")?
625 "": global_settings.rec_directory);
627 snprintf(ext, sizeof(ext), ".%s",
628 REC_FILE_ENDING(global_settings.rec_format));
630 #if CONFIG_RTC == 0
631 return create_numbered_filename(buffer, buffer, pref, ext, 4,
632 &file_number);
633 #else
634 /* We'll wait at least up to the start of the next second so no duplicate
635 names are created */
636 return create_datetime_filename(buffer, buffer, pref, ext, true);
637 #endif
640 #if CONFIG_RTC == 0
641 /* Hit disk to get a starting filename for the type */
642 static void rec_init_filename(void)
644 file_number = -1;
645 rec_create_filename(path_buffer);
646 file_number--;
648 #endif
650 int rec_create_directory(void)
652 int rc = 0;
653 const char * const folder = global_settings.rec_directory;
655 if (strcmp(folder, "/") && !dir_exists(folder))
657 rc = mkdir(folder);
659 if(rc < 0)
661 while (action_userabort(HZ) == false)
663 splashf(0, "%s %s",
664 str(LANG_REC_DIR_NOT_WRITABLE),
665 str(LANG_OFF_ABORT));
668 else
670 rec_status |= RCSTAT_CREATED_DIRECTORY;
671 rc = 1;
675 return rc;
678 void rec_init_recording_options(struct audio_recording_options *options)
680 options->rec_source = global_settings.rec_source;
681 options->rec_frequency = global_settings.rec_frequency;
682 options->rec_channels = global_settings.rec_channels;
683 options->rec_prerecord_time = global_settings.rec_prerecord_time;
684 #if CONFIG_CODEC == SWCODEC
685 options->rec_mono_mode = global_settings.rec_mono_mode;
686 options->rec_source_flags = 0;
687 options->enc_config.rec_format = global_settings.rec_format;
688 global_to_encoder_config(&options->enc_config);
689 #else
690 options->rec_quality = global_settings.rec_quality;
691 options->rec_editable = global_settings.rec_editable;
692 #endif
695 #if CONFIG_CODEC == SWCODEC
696 void rec_set_source(int source, unsigned flags)
698 /* Set audio input source, power up/down devices */
699 audio_set_input_source(source, flags);
701 /* Set peakmeters for recording or reset to playback */
702 peak_meter_playback((flags & SRCF_RECORDING) == 0);
703 peak_meter_enable(true);
705 #endif /* CONFIG_CODEC == SWCODEC */
707 void rec_set_recording_options(struct audio_recording_options *options)
709 #if CONFIG_CODEC != SWCODEC
710 if (global_settings.rec_prerecord_time)
712 talk_buffer_steal(); /* will use the mp3 buffer */
714 #else /* == SWCODEC */
715 rec_set_source(options->rec_source,
716 options->rec_source_flags | SRCF_RECORDING);
717 #endif /* CONFIG_CODEC != SWCODEC */
719 audio_set_recording_options(options);
722 void rec_command(enum recording_command cmd)
724 switch(cmd)
726 case RECORDING_CMD_STOP_SHUTDOWN:
727 pm_activate_clipcount(false);
728 audio_stop_recording();
729 #if CONFIG_CODEC == SWCODEC
730 audio_close_recording();
731 #endif
732 sys_poweroff();
733 break;
734 case RECORDING_CMD_STOP:
735 pm_activate_clipcount(false);
736 audio_stop_recording();
737 break;
738 case RECORDING_CMD_START:
739 /* steal mp3 buffer, create unique filename and start recording */
740 pm_reset_clipcount();
741 pm_activate_clipcount(true);
742 #if CONFIG_CODEC != SWCODEC
743 talk_buffer_steal(); /* we use the mp3 buffer */
744 #endif
745 audio_record(rec_create_filename(path_buffer));
746 break;
747 case RECORDING_CMD_START_NEWFILE:
748 /* create unique filename and start recording*/
749 pm_reset_clipcount();
750 pm_activate_clipcount(true); /* just to be sure */
751 audio_new_file(rec_create_filename(path_buffer));
752 break;
753 case RECORDING_CMD_PAUSE:
754 pm_activate_clipcount(false);
755 audio_pause_recording();
756 break;
757 case RECORDING_CMD_RESUME:
758 pm_activate_clipcount(true);
759 audio_resume_recording();
760 break;
762 update_list = true;
765 /* used in trigger_listerner and recording_screen */
766 static unsigned int last_seconds = 0;
769 * Callback function so that the peak meter code can send an event
770 * to this application. This function can be passed to
771 * peak_meter_set_trigger_listener in order to activate the trigger.
773 static void trigger_listener(int trigger_status)
775 switch (trigger_status)
777 case TRIG_GO:
778 if(!(audio_status() & AUDIO_STATUS_RECORD))
780 rec_status |= RCSTAT_HAVE_RECORDED;
781 rec_command(RECORDING_CMD_START);
782 #if CONFIG_CODEC != SWCODEC
783 /* give control to mpeg thread so that it can start
784 recording */
785 yield(); yield(); yield();
786 #endif
789 /* if we're already recording this is a retrigger */
790 else
792 if((audio_status() & AUDIO_STATUS_PAUSE) &&
793 (global_settings.rec_trigger_type == TRIG_TYPE_PAUSE))
795 rec_command(RECORDING_CMD_RESUME);
797 /* New file on trig start*/
798 else if (global_settings.rec_trigger_type != TRIG_TYPE_NEW_FILE)
800 rec_command(RECORDING_CMD_START_NEWFILE);
801 /* tell recording_screen to reset the time */
802 last_seconds = 0;
805 break;
807 /* A _change_ to TRIG_READY means the current recording has stopped */
808 case TRIG_READY:
809 if(audio_status() & AUDIO_STATUS_RECORD)
811 switch(global_settings.rec_trigger_type)
813 case TRIG_TYPE_STOP: /* Stop */
814 rec_command(RECORDING_CMD_STOP);
815 break;
817 case TRIG_TYPE_PAUSE: /* Pause */
818 rec_command(RECORDING_CMD_PAUSE);
819 break;
821 case TRIG_TYPE_NEW_FILE: /* New file on trig stop*/
822 rec_command(RECORDING_CMD_START_NEWFILE);
823 /* tell recording_screen to reset the time */
824 last_seconds = 0;
825 break;
827 case 3: /* Stop and shutdown */
828 rec_command(RECORDING_CMD_STOP_SHUTDOWN);
829 break;
832 if (global_settings.rec_trigger_mode != TRIG_MODE_REARM)
834 peak_meter_set_trigger_listener(NULL);
835 peak_meter_trigger(false);
838 break;
842 /* Stuff for drawing the screen */
844 enum rec_list_items_stereo {
845 ITEM_VOLUME = 0,
846 ITEM_GAIN = 1,
847 ITEM_GAIN_L = 2,
848 ITEM_GAIN_R = 3,
849 #ifdef HAVE_AGC
850 ITEM_AGC_MODE = 4,
851 ITEM_AGC_MAXDB = 5,
852 ITEM_FILENAME = 7,
853 ITEM_COUNT = 7,
854 #else
855 ITEM_FILENAME = 7,
856 ITEM_COUNT = 5,
857 #endif
860 enum rec_list_items_mono {
861 ITEM_VOLUME_M = 0,
862 ITEM_GAIN_M = 1,
863 #ifdef HAVE_AGC
864 ITEM_AGC_MODE_M = 4,
865 ITEM_AGC_MAXDB_M = 5,
866 ITEM_FILENAME_M = 7,
867 ITEM_COUNT_M = 5,
868 #else
869 ITEM_FILENAME_M = 7,
870 ITEM_COUNT_M = 3,
871 #endif
874 #ifdef HAVE_SPDIF_REC
875 enum rec_list_items_spdif {
876 ITEM_VOLUME_D = 0,
877 #if CONFIG_CODEC == SWCODEC
878 ITEM_SAMPLERATE_D = 6,
879 ITEM_FILENAME_D = 7,
880 ITEM_COUNT_D = 3,
881 #else
882 ITEM_FILENAME_D = 7,
883 ITEM_COUNT_D = 2,
884 #endif
886 #endif
888 static int listid_to_enum[ITEM_COUNT];
890 static const char* reclist_get_name(int selected_item, void * data,
891 char * buffer, size_t buffer_len)
893 char buf2[32];
894 #ifdef HAVE_AGC
895 char buf3[32];
896 #endif
897 data = data; /* not used */
898 if(selected_item >= ITEM_COUNT)
899 return "";
901 switch (listid_to_enum[selected_item])
903 case ITEM_VOLUME:
904 snprintf(buffer, buffer_len, "%s: %s", str(LANG_VOLUME),
905 fmt_gain(SOUND_VOLUME,
906 global_settings.volume,
907 buf2, sizeof(buf2)));
908 break;
909 case ITEM_GAIN:
910 #ifdef HAVE_MIC_REC
911 if(global_settings.rec_source == AUDIO_SRC_MIC)
913 /* Draw MIC recording gain */
914 snprintf(buffer, buffer_len, "%s: %s", str(LANG_GAIN),
915 fmt_gain(SOUND_MIC_GAIN,
916 global_settings.rec_mic_gain,
917 buf2, sizeof(buf2)));
919 else
920 #endif /* MIC */
922 int avg_gain = (global_settings.rec_left_gain +
923 global_settings.rec_right_gain) / 2;
924 snprintf(buffer, buffer_len, "%s: %s", str(LANG_GAIN),
925 fmt_gain(SOUND_LEFT_GAIN,
926 avg_gain,
927 buf2, sizeof(buf2)));
929 break;
930 case ITEM_GAIN_L:
931 snprintf(buffer, buffer_len, "%s: %s",
932 str(LANG_GAIN_LEFT),
933 fmt_gain(SOUND_LEFT_GAIN,
934 global_settings.rec_left_gain,
935 buf2, sizeof(buf2)));
936 break;
937 case ITEM_GAIN_R:
938 snprintf(buffer, buffer_len, "%s: %s",
939 str(LANG_GAIN_RIGHT),
940 fmt_gain(SOUND_RIGHT_GAIN,
941 global_settings.rec_right_gain,
942 buf2, sizeof(buf2)));
943 break;
944 #ifdef HAVE_AGC
945 case ITEM_AGC_MODE:
946 snprintf(buffer, buffer_len, "%s: %s",
947 str(LANG_RECORDING_AGC_PRESET),
948 agc_preset_str[agc_preset]);
949 break;
950 case ITEM_AGC_MAXDB:
951 if (agc_preset == 0)
952 snprintf(buffer, buffer_len, "%s: %s",
953 str(LANG_RECORDING_AGC_MAXGAIN),
954 fmt_gain(SOUND_LEFT_GAIN,
955 agc_maxgain, buf2, sizeof(buf2)));
956 #ifdef HAVE_MIC_REC
957 else if (global_settings.rec_source == AUDIO_SRC_MIC)
958 snprintf(buffer, buffer_len, "%s: %s (%s)",
959 str(LANG_RECORDING_AGC_MAXGAIN),
960 fmt_gain(SOUND_MIC_GAIN,
961 agc_maxgain, buf2, sizeof(buf2)),
962 fmt_gain(SOUND_MIC_GAIN,
963 agc_maxgain - global_settings.rec_mic_gain,
964 buf3, sizeof(buf3)));
965 else
966 #endif /* MIC */
967 snprintf(buffer, buffer_len, "%s: %s (%s)",
968 str(LANG_RECORDING_AGC_MAXGAIN),
969 fmt_gain(SOUND_LEFT_GAIN,
970 agc_maxgain, buf2, sizeof(buf2)),
971 fmt_gain(SOUND_LEFT_GAIN,
972 agc_maxgain -
973 (global_settings.rec_left_gain +
974 global_settings.rec_right_gain)/2,
975 buf3, sizeof(buf3)));
976 break;
977 #endif
978 #if CONFIG_CODEC == SWCODEC
979 #ifdef HAVE_SPDIF_REC
980 case ITEM_SAMPLERATE_D:
981 snprintf(buffer, buffer_len, "%s: %lu",
982 str(LANG_RECORDING_FREQUENCY),
983 pcm_rec_sample_rate());
984 break;
985 #endif
986 #endif
987 case ITEM_FILENAME:
989 if(audio_status() & AUDIO_STATUS_RECORD)
991 size_t tot_len = strlen(path_buffer) +
992 strlen(str(LANG_RECORDING_FILENAME)) + 1;
993 if(tot_len > buffer_len)
995 snprintf(buffer, buffer_len, "%s %s",
996 str(LANG_RECORDING_FILENAME),
997 path_buffer + tot_len - buffer_len);
999 else
1001 snprintf(buffer, buffer_len, "%s %s",
1002 str(LANG_RECORDING_FILENAME), path_buffer);
1005 else
1007 return str(LANG_RECORDING_FILENAME);
1009 break;
1011 default:
1012 return "";
1014 return buffer;
1018 bool recording_start_automatic = false;
1020 bool recording_screen(bool no_source)
1022 int button;
1023 int done = -1; /* negative to re-init, positive to quit, zero to run */
1024 char buf[32]; /* for preparing strings */
1025 char buf2[32]; /* for preparing strings */
1026 int w, h; /* character width/height */
1027 int update_countdown = 0; /* refresh counter */
1028 unsigned int seconds;
1029 int hours, minutes;
1030 int audio_stat = 0; /* status of the audio system */
1031 int last_audio_stat = -1; /* previous status so we can act on changes */
1032 struct viewport vp_list[NB_SCREENS], vp_top[NB_SCREENS]; /* the viewports */
1034 #if CONFIG_CODEC == SWCODEC
1035 int warning_counter = 0;
1036 #define WARNING_PERIOD 7
1037 #endif
1039 #if CONFIG_CODEC == SWCODEC
1040 #ifdef HAVE_SPDIF_REC
1041 unsigned long prev_sample_rate = 0;
1042 #endif
1043 #endif
1045 #ifdef HAVE_FMRADIO_REC
1046 /* Radio is left on if:
1047 * 1) Is was on at the start and the initial source is FM Radio
1048 * 2) 1) and the source was never changed to something else
1050 int radio_status = (global_settings.rec_source != AUDIO_SRC_FMRADIO) ?
1051 FMRADIO_OFF : get_radio_status();
1052 #endif
1053 #if (CONFIG_LED == LED_REAL)
1054 bool led_state = false;
1055 int led_countdown = 2;
1056 #endif
1057 #ifdef HAVE_AGC
1058 bool peak_read = false;
1059 int peak_l, peak_r;
1060 int balance = 0;
1061 #endif
1062 int i;
1063 int pm_x[NB_SCREENS]; /* peakmeter (and trigger bar) x pos */
1064 int pm_y[NB_SCREENS]; /* peakmeter y pos */
1065 int pm_h[NB_SCREENS]; /* peakmeter height */
1066 int trig_ypos[NB_SCREENS]; /* trigger bar y pos */
1067 int trig_width[NB_SCREENS]; /* trigger bar width */
1068 int top_height_req[NB_SCREENS]; /* required height for top half */
1069 /* tweak layout tiny screens / big fonts */
1070 bool compact_view[NB_SCREENS] = { false };
1071 struct gui_synclist lists; /* the list in the bottom vp */
1072 #if defined(HAVE_AGC) || defined(HAVE_RECORDING_HISTOGRAM)
1073 bool peak_valid = false;
1074 #endif
1075 #if defined(HAVE_RECORDING_HISTOGRAM)
1076 int j;
1077 unsigned short hist_pos_y = 0;
1078 unsigned short hist_size_h = 0;
1079 int history_pos = 0;
1080 short hist_time_interval = 1; /* 1, 2, 4, 8 */
1081 unsigned char history_l[HIST_BUF_SIZE];
1082 unsigned char history_r[HIST_BUF_SIZE];
1083 const char hist_level_marks[6] = { 29, 26, 23, 17, 9, 2};
1084 #endif
1085 #ifdef HAVE_FMRADIO_REC
1086 int prev_rec_source = global_settings.rec_source; /* detect source change */
1087 #endif
1089 struct audio_recording_options rec_options;
1090 rec_status = RCSTAT_IN_RECSCREEN;
1092 #if (CONFIG_STORAGE & STORAGE_ATA) && (CONFIG_LED == LED_REAL) \
1093 && !defined(SIMULATOR)
1094 ata_set_led_enabled(false);
1095 #endif
1097 #if CONFIG_CODEC == SWCODEC
1098 /* This should be done before touching audio settings */
1099 while (!audio_is_thread_ready())
1100 sleep(0);
1102 /* recording_menu gets messed up: so prevent manus talking */
1103 talk_disable(true);
1104 /* audio_init_recording stops anything playing when it takes the audio
1105 buffer */
1106 #else
1107 /* Yes, we use the D/A for monitoring */
1108 peak_meter_enable(true);
1109 peak_meter_playback(true);
1110 #endif
1112 #ifdef HAVE_AGC
1113 peak_meter_get_peakhold(&peak_l, &peak_r);
1114 #endif
1116 pm_reset_clipcount();
1117 pm_activate_clipcount(false);
1118 settings_apply_trigger();
1120 #ifdef HAVE_AGC
1121 agc_preset_str[0] = str(LANG_OFF);
1122 agc_preset_str[1] = str(LANG_AGC_SAFETY);
1123 agc_preset_str[2] = str(LANG_AGC_LIVE);
1124 agc_preset_str[3] = str(LANG_AGC_DJSET);
1125 agc_preset_str[4] = str(LANG_AGC_MEDIUM);
1126 agc_preset_str[5] = str(LANG_AGC_VOICE);
1127 #endif /* HAVE_AGC */
1129 #ifdef HAVE_SPEAKER
1130 /* Disable speaker to prevent feedback */
1131 audiohw_enable_speaker(false);
1132 #endif
1134 #if CONFIG_CODEC == SWCODEC
1135 audio_close_recording();
1136 #endif
1137 audio_init_recording(0);
1138 sound_set_volume(global_settings.volume);
1140 #if CONFIG_RTC == 0
1141 /* Create new filename for recording start */
1142 rec_init_filename();
1143 #endif
1145 /* start of the loop: we stay in this loop until user quits recscreen */
1146 while(done <= 0)
1148 if(done < 0)
1150 /* request to re-init stuff, done after settings screen */
1151 done = 0;
1152 #ifdef HAVE_FMRADIO_REC
1153 /* If input changes away from FM Radio,
1154 radio will remain off when recording screen closes. */
1155 if (global_settings.rec_source != prev_rec_source
1156 && prev_rec_source == AUDIO_SRC_FMRADIO)
1157 radio_status = FMRADIO_OFF;
1158 prev_rec_source = global_settings.rec_source;
1159 #endif
1161 /* viewport init and calculations that only needs to be done once */
1162 FOR_NB_SCREENS(i)
1164 struct viewport *v;
1165 /* top vp, 4 lines, force sys font if total screen < 6 lines
1166 NOTE: one could limit the list to 1 line and get away with 5 lines */
1167 top_height_req[i] = 4;
1168 #if defined(HAVE_RECORDING_HISTOGRAM)
1169 if((global_settings.rec_histogram_interval) && (!i))
1170 top_height_req[i] += 1; /* use one line for histogram */
1171 hist_time_interval = 1 << global_settings.rec_histogram_interval;
1172 #endif
1173 v = &vp_top[i];
1174 viewport_set_defaults(v, i);
1175 if (viewport_get_nb_lines(v) < top_height_req[i])
1177 /* compact needs 4 lines total */
1178 v->font = FONT_SYSFIXED;
1179 compact_view[i] = false;
1181 else
1183 /*top=4,list=2*/
1184 if (viewport_get_nb_lines(v) < (top_height_req[i]+2))
1185 compact_view[i] = true;
1186 else
1187 compact_view[i] = false;
1189 vp_list[i] = *v; /* get a copy now so it can be sized more easily */
1190 v->height = (font_get(v->font)->height)*(compact_view[i] ? 3 :
1191 top_height_req[i]);
1193 /* list section, rest of the screen */
1194 vp_list[i].y += vp_top[i].height;
1195 vp_list[i].height -= vp_top[i].height;
1196 screens[i].set_viewport(&vp_top[i]); /* req for next calls */
1198 screens[i].getstringsize("W", &w, &h);
1199 pm_y[i] = font_get(vp_top[i].font)->height * 2;
1200 trig_ypos[i] = font_get(vp_top[i].font)->height * 3;
1201 if(compact_view[i])
1202 trig_ypos[i] -= (font_get(vp_top[i].font)->height)/2;
1205 /* init the bottom list */
1206 gui_synclist_init(&lists, reclist_get_name, NULL, false, 1, vp_list);
1207 gui_synclist_set_title(&lists, NULL, Icon_NOICON);
1209 send_event(GUI_EVENT_ACTIONUPDATE, (void*)1); /* force a redraw */
1211 #if defined(HAVE_RECORDING_HISTOGRAM)
1212 history_pos = 0;
1213 hist_pos_y = (compact_view[0] ? 3 : 4) * (font_get(vp_top[0].font)->height)
1214 + 1;
1215 hist_size_h = font_get(vp_top[0].font)->height - 2;
1216 memset(history_l, 0, sizeof(unsigned char)*HIST_BUF_SIZE);
1217 memset(history_r, 0, sizeof(unsigned char)*HIST_BUF_SIZE);
1218 #endif
1220 FOR_NB_SCREENS(i)
1222 pm_x[i] = 0;
1223 if(global_settings.peak_meter_clipcounter)
1225 int clipwidth = 0;
1226 screens[i].getstringsize(str(LANG_PM_CLIPCOUNT),
1227 &clipwidth, &h); /* h is same */
1228 pm_x[i] = clipwidth+1;
1230 if(global_settings.rec_trigger_mode == TRIG_MODE_OFF)
1231 pm_h[i] = font_get(vp_top[i].font)->height * 2;
1232 else
1233 pm_h[i] = font_get(vp_top[i].font)->height;
1234 if(compact_view[i])
1235 pm_h[i] /= 2;
1236 trig_width[i] = vp_top[i].width - pm_x[i];
1239 #if CONFIG_CODEC == SWCODEC
1240 audio_close_recording();
1241 audio_init_recording(0);
1242 #endif
1244 rec_init_recording_options(&rec_options);
1245 rec_set_recording_options(&rec_options);
1247 if(rec_create_directory() < 0)
1249 rec_status = 0;
1250 goto rec_abort;
1253 #if CONFIG_CODEC == SWCODEC && CONFIG_RTC == 0
1254 /* If format changed, a new number is required */
1255 rec_init_filename();
1256 #endif
1258 #ifdef HAVE_AGC
1259 #ifdef HAVE_MIC_REC
1260 if (global_settings.rec_source == AUDIO_SRC_MIC) {
1261 agc_preset = global_settings.rec_agc_preset_mic;
1262 agc_maxgain = global_settings.rec_agc_maxgain_mic;
1264 else
1265 #endif /* MIC */
1267 agc_preset = global_settings.rec_agc_preset_line;
1268 agc_maxgain = global_settings.rec_agc_maxgain_line;
1270 #endif /* HAVE_AGC */
1272 set_gain();
1273 update_countdown = 0; /* Update immediately */
1275 /* populate translation table for list id -> enum */
1276 #ifdef HAVE_SPDIF_REC
1277 if(global_settings.rec_source == AUDIO_SRC_SPDIF)
1279 listid_to_enum[0] = ITEM_VOLUME_D;
1280 #if CONFIG_CODEC == SWCODEC
1281 listid_to_enum[1] = ITEM_SAMPLERATE_D;
1282 listid_to_enum[2] = ITEM_FILENAME_D;
1283 #else
1284 listid_to_enum[1] = ITEM_FILENAME_D;
1285 #endif
1287 gui_synclist_set_nb_items(&lists, ITEM_COUNT_D); /* spdif */
1289 else
1290 #endif
1291 if(HAVE_MIC_REC_((global_settings.rec_source == AUDIO_SRC_MIC) || )
1292 (global_settings.rec_channels == 1))
1294 listid_to_enum[0] = ITEM_VOLUME_M;
1295 listid_to_enum[1] = ITEM_GAIN_M;
1296 #ifdef HAVE_AGC
1297 listid_to_enum[2] = ITEM_AGC_MODE_M;
1298 listid_to_enum[3] = ITEM_AGC_MAXDB_M;
1299 listid_to_enum[4] = ITEM_FILENAME_M;
1300 #else
1301 listid_to_enum[2] = ITEM_FILENAME_M;
1302 #endif
1303 gui_synclist_set_nb_items(&lists, ITEM_COUNT_M); /* mono */
1305 else
1307 listid_to_enum[0] = ITEM_VOLUME;
1308 listid_to_enum[1] = ITEM_GAIN;
1309 listid_to_enum[2] = ITEM_GAIN_L;
1310 listid_to_enum[3] = ITEM_GAIN_R;
1311 #ifdef HAVE_AGC
1312 listid_to_enum[4] = ITEM_AGC_MODE;
1313 listid_to_enum[5] = ITEM_AGC_MAXDB;
1314 listid_to_enum[6] = ITEM_FILENAME;
1315 #else
1316 listid_to_enum[4] = ITEM_FILENAME;
1317 #endif
1318 gui_synclist_set_nb_items(&lists, ITEM_COUNT); /* stereo */
1321 gui_synclist_draw(&lists);
1322 } /* if(done < 0) */
1324 audio_stat = audio_status();
1326 #if (CONFIG_LED == LED_REAL)
1329 * Flash the LED while waiting to record. Turn it on while
1330 * recording.
1332 if(audio_stat & AUDIO_STATUS_RECORD)
1334 if (audio_stat & AUDIO_STATUS_PAUSE)
1336 if (--led_countdown <= 0)
1338 led_state = !led_state;
1339 led(led_state);
1340 led_countdown = 2;
1343 else
1345 /* trigger is on in status TRIG_READY (no check needed) */
1346 led(true);
1349 else
1351 int trig_stat = peak_meter_trigger_status();
1353 * other trigger stati than trig_off and trig_steady
1354 * already imply that we are recording.
1356 if (trig_stat == TRIG_STEADY)
1358 if (--led_countdown <= 0)
1360 led_state = !led_state;
1361 led(led_state);
1362 led_countdown = 2;
1365 else
1367 /* trigger is on in status TRIG_READY (no check needed) */
1368 led(false);
1371 #endif /* CONFIG_LED */
1373 /* Wait for a button a while (HZ/10) drawing the peak meter */
1374 button = peak_meter_draw_get_btn(CONTEXT_RECSCREEN,
1375 pm_x, pm_y, pm_h,
1376 screen_update, vp_top);
1377 if (last_audio_stat != audio_stat)
1379 if (audio_stat & AUDIO_STATUS_RECORD)
1381 rec_status |= RCSTAT_HAVE_RECORDED;
1383 last_audio_stat = audio_stat;
1384 update_list = true;
1387 if (recording_start_automatic)
1389 /* simulate a button press */
1390 button = ACTION_REC_PAUSE;
1391 recording_start_automatic = false;
1394 /* let list handle the button */
1395 gui_synclist_do_button(&lists, &button, LIST_WRAP_UNLESS_HELD);
1398 switch(button)
1400 case ACTION_SETTINGS_INC:
1401 case ACTION_SETTINGS_INCREPEAT:
1402 switch (listid_to_enum[gui_synclist_get_sel_pos(&lists)])
1404 case ITEM_VOLUME:
1405 global_settings.volume++;
1406 setvol();
1407 break;
1408 case ITEM_GAIN:
1409 #ifdef HAVE_MIC_REC
1410 if(global_settings.rec_source == AUDIO_SRC_MIC)
1412 if(global_settings.rec_mic_gain <
1413 sound_max(SOUND_MIC_GAIN))
1414 global_settings.rec_mic_gain++;
1416 else
1417 #endif /* MIC */
1419 if(global_settings.rec_left_gain <
1420 sound_max(SOUND_LEFT_GAIN))
1421 global_settings.rec_left_gain++;
1422 if(global_settings.rec_right_gain <
1423 sound_max(SOUND_RIGHT_GAIN))
1424 global_settings.rec_right_gain++;
1426 break;
1427 case ITEM_GAIN_L:
1428 if(global_settings.rec_left_gain <
1429 sound_max(SOUND_LEFT_GAIN))
1430 global_settings.rec_left_gain++;
1431 break;
1432 case ITEM_GAIN_R:
1433 if(global_settings.rec_right_gain <
1434 sound_max(SOUND_RIGHT_GAIN))
1435 global_settings.rec_right_gain++;
1436 break;
1437 #ifdef HAVE_AGC
1438 case ITEM_AGC_MODE:
1439 agc_preset = MIN(agc_preset + 1, AGC_MODE_SIZE);
1440 agc_enable = (agc_preset != 0);
1441 #ifdef HAVE_MIC_REC
1442 if (global_settings.rec_source == AUDIO_SRC_MIC) {
1443 global_settings.rec_agc_preset_mic = agc_preset;
1444 agc_maxgain = global_settings.rec_agc_maxgain_mic;
1445 } else
1446 #endif /* MIC */
1448 global_settings.rec_agc_preset_line = agc_preset;
1449 agc_maxgain = global_settings.rec_agc_maxgain_line;
1451 break;
1452 case ITEM_AGC_MAXDB:
1453 #ifdef HAVE_MIC_REC
1454 if (global_settings.rec_source == AUDIO_SRC_MIC)
1456 agc_maxgain = MIN(agc_maxgain + 1,
1457 sound_max(SOUND_MIC_GAIN));
1458 global_settings.rec_agc_maxgain_mic = agc_maxgain;
1460 else
1461 #endif /* MIC */
1463 agc_maxgain = MIN(agc_maxgain + 1,
1464 sound_max(SOUND_LEFT_GAIN));
1465 global_settings.rec_agc_maxgain_line = agc_maxgain;
1467 break;
1468 #endif /* HAVE_AGC */
1470 set_gain();
1471 update_countdown = 0; /* Update immediately */
1472 break;
1473 case ACTION_SETTINGS_DEC:
1474 case ACTION_SETTINGS_DECREPEAT:
1475 switch (listid_to_enum[gui_synclist_get_sel_pos(&lists)])
1477 case ITEM_VOLUME:
1478 global_settings.volume--;
1479 setvol();
1480 break;
1481 case ITEM_GAIN:
1482 #ifdef HAVE_MIC_REC
1483 if(global_settings.rec_source == AUDIO_SRC_MIC)
1485 if(global_settings.rec_mic_gain >
1486 sound_min(SOUND_MIC_GAIN))
1487 global_settings.rec_mic_gain--;
1489 else
1490 #endif /* MIC */
1492 if(global_settings.rec_left_gain >
1493 sound_min(SOUND_LEFT_GAIN))
1494 global_settings.rec_left_gain--;
1495 if(global_settings.rec_right_gain >
1496 sound_min(SOUND_RIGHT_GAIN))
1497 global_settings.rec_right_gain--;
1499 break;
1500 case ITEM_GAIN_L:
1501 if(global_settings.rec_left_gain >
1502 sound_min(SOUND_LEFT_GAIN))
1503 global_settings.rec_left_gain--;
1504 break;
1505 case ITEM_GAIN_R:
1506 if(global_settings.rec_right_gain >
1507 sound_min(SOUND_RIGHT_GAIN))
1508 global_settings.rec_right_gain--;
1509 break;
1510 #ifdef HAVE_AGC
1511 case ITEM_AGC_MODE:
1512 agc_preset = MAX(agc_preset - 1, 0);
1513 agc_enable = (agc_preset != 0);
1514 #ifdef HAVE_MIC_REC
1515 if (global_settings.rec_source == AUDIO_SRC_MIC) {
1516 global_settings.rec_agc_preset_mic = agc_preset;
1517 agc_maxgain = global_settings.rec_agc_maxgain_mic;
1518 } else
1519 #endif /* MIC */
1521 global_settings.rec_agc_preset_line = agc_preset;
1522 agc_maxgain = global_settings.rec_agc_maxgain_line;
1524 break;
1525 case ITEM_AGC_MAXDB:
1526 #ifdef HAVE_MIC_REC
1527 if (global_settings.rec_source == AUDIO_SRC_MIC)
1529 agc_maxgain = MAX(agc_maxgain - 1,
1530 sound_min(SOUND_MIC_GAIN));
1531 global_settings.rec_agc_maxgain_mic = agc_maxgain;
1532 } else
1533 #endif /* MIC */
1535 agc_maxgain = MAX(agc_maxgain - 1,
1536 sound_min(SOUND_LEFT_GAIN));
1537 global_settings.rec_agc_maxgain_line = agc_maxgain;
1539 break;
1540 #endif /* HAVE_AGC */
1542 set_gain();
1543 update_countdown = 0; /* Update immediately */
1544 break;
1545 case ACTION_STD_CANCEL:
1546 /* turn off the trigger */
1547 peak_meter_trigger(false);
1548 peak_meter_set_trigger_listener(NULL);
1550 if(audio_stat & AUDIO_STATUS_RECORD)
1552 rec_command(RECORDING_CMD_STOP);
1554 else
1556 #if CONFIG_CODEC != SWCODEC
1557 peak_meter_playback(true);
1558 peak_meter_enable(false);
1559 #endif
1560 done = 1;
1562 update_countdown = 0; /* Update immediately */
1563 break;
1564 #ifdef HAVE_REMOTE_LCD
1565 case ACTION_REC_LCD:
1566 /* this feature exists for some h1x0/h3x0 targets that suffer
1567 from noise caused by remote LCD updates
1568 NOTE 1: this will leave the list on the remote
1569 NOTE 2: to be replaced by a global LCD_off() routine */
1570 if(remote_display_on)
1572 /* switch to single screen, leave message on remote */
1573 screen_update = 1;
1574 screens[1].clear_viewport();
1575 screens[1].puts(0, 0, str(LANG_REMOTE_LCD_OFF));
1576 screens[1].puts(0, 1, str(LANG_REMOTE_LCD_ON));
1577 screens[1].update_viewport();
1579 else
1581 /* remote switched on again */
1582 update_list = true;
1583 screen_update = NB_SCREENS;
1585 remote_display_on = !remote_display_on; /* toggle */
1586 update_countdown = 0; /* Update immediately */
1587 break;
1588 #endif
1589 case ACTION_REC_PAUSE:
1590 case ACTION_REC_NEWFILE:
1591 /* Only act if the mpeg is stopped */
1592 if(!(audio_stat & AUDIO_STATUS_RECORD))
1594 /* is this manual or triggered recording? */
1595 if ((global_settings.rec_trigger_mode == TRIG_MODE_OFF) ||
1596 (peak_meter_trigger_status() != TRIG_OFF))
1598 /* manual recording */
1599 rec_status |= RCSTAT_HAVE_RECORDED;
1600 rec_command(RECORDING_CMD_START);
1601 last_seconds = 0;
1602 if (global_settings.talk_menu)
1604 /* no voice possible here, but a beep */
1605 audio_beep(HZ/2); /* longer beep on start */
1608 /* this is triggered recording */
1609 else
1611 /* we don't start recording now, but enable the
1612 trigger and let the callback function
1613 trigger_listener control when the recording starts */
1614 peak_meter_trigger(true);
1615 peak_meter_set_trigger_listener(&trigger_listener);
1618 else
1620 /*if new file button pressed, start new file */
1621 if (button == ACTION_REC_NEWFILE)
1623 rec_command(RECORDING_CMD_START_NEWFILE);
1624 last_seconds = 0;
1626 else
1627 /* if pause button pressed, pause or resume */
1629 if(audio_stat & AUDIO_STATUS_PAUSE)
1631 rec_command(RECORDING_CMD_RESUME);
1632 if (global_settings.talk_menu)
1634 /* no voice possible here, but a beep */
1635 audio_beep(HZ/4); /* short beep on resume */
1638 else
1640 rec_command(RECORDING_CMD_PAUSE);
1644 update_countdown = 0; /* Update immediately */
1645 break;
1646 case ACTION_STD_MENU:
1647 #if CONFIG_CODEC == SWCODEC
1648 if(!(audio_stat & AUDIO_STATUS_RECORD))
1649 #else
1650 if(audio_stat != AUDIO_STATUS_RECORD)
1651 #endif
1653 #if (CONFIG_LED == LED_REAL)
1654 /* led is restored at begin of loop / end of function */
1655 led(false);
1656 #endif
1657 if (recording_menu(no_source))
1659 done = 1;
1660 rec_status |= RCSTAT_BEEN_IN_USB_MODE;
1661 #ifdef HAVE_FMRADIO_REC
1662 radio_status = FMRADIO_OFF;
1663 #endif
1665 else
1667 done = -1;
1668 /* the init is now done at the beginning of the loop */
1671 break;
1673 #if CONFIG_KEYPAD == RECORDER_PAD
1674 case ACTION_REC_F2:
1675 if(audio_stat != AUDIO_STATUS_RECORD)
1677 #if (CONFIG_LED == LED_REAL)
1678 /* led is restored at begin of loop / end of function */
1679 led(false);
1680 #endif
1681 if (f2_rec_screen())
1683 rec_status |= RCSTAT_HAVE_RECORDED;
1684 done = true;
1686 else
1687 update_countdown = 0; /* Update immediately */
1689 break;
1691 case ACTION_REC_F3:
1692 if(audio_stat & AUDIO_STATUS_RECORD)
1694 rec_command(RECORDING_CMD_START_NEWFILE);
1695 last_seconds = 0;
1697 else
1699 #if (CONFIG_LED == LED_REAL)
1700 /* led is restored at begin of loop / end of function */
1701 led(false);
1702 #endif
1703 if (f3_rec_screen())
1705 rec_status |= RCSTAT_HAVE_RECORDED;
1706 done = true;
1708 else
1709 update_countdown = 0; /* Update immediately */
1711 break;
1712 #endif /* CONFIG_KEYPAD == RECORDER_PAD */
1714 case SYS_USB_CONNECTED:
1715 /* Only accept USB connection when not recording */
1716 if(!(audio_stat & AUDIO_STATUS_RECORD))
1718 FOR_NB_SCREENS(i)
1719 screens[i].set_viewport(NULL);
1720 default_event_handler(SYS_USB_CONNECTED);
1721 done = true;
1722 rec_status |= RCSTAT_BEEN_IN_USB_MODE;
1723 #ifdef HAVE_FMRADIO_REC
1724 radio_status = FMRADIO_OFF;
1725 #endif
1727 break;
1728 } /*switch(button)*/
1730 #ifdef HAVE_AGC
1731 peak_read = !peak_read;
1732 if (peak_read) { /* every 2nd run of loop */
1733 peak_time++;
1734 peak_valid = read_peak_levels(&peak_l, &peak_r, &balance);
1737 /* Handle AGC every 200ms when enabled and peak data is valid */
1738 if (peak_read && agc_enable && peak_valid)
1739 auto_gain_control(&peak_l, &peak_r, &balance);
1740 #endif
1742 seconds = audio_recorded_time() / HZ;
1744 /* start of vp_top drawing */
1745 if(update_countdown-- == 0 || seconds > last_seconds)
1747 unsigned int dseconds, dhours, dminutes;
1748 unsigned long num_recorded_bytes, dsize, dmb;
1750 FOR_NB_SCREENS(i)
1752 screens[i].set_viewport(&vp_top[i]);
1753 screens[i].clear_viewport();
1755 update_countdown = 5;
1756 last_seconds = seconds;
1758 dseconds = rec_timesplit_seconds();
1759 dsize = rec_sizesplit_bytes();
1760 num_recorded_bytes = audio_num_recorded_bytes();
1762 #if CONFIG_CODEC == SWCODEC
1763 if ((audio_stat & AUDIO_STATUS_WARNING)
1764 && (warning_counter++ % WARNING_PERIOD) < WARNING_PERIOD/2)
1766 /* Switch back and forth displaying warning on first available
1767 line to ensure visibility - the motion should also help
1768 draw attention */
1769 /* Don't use language string unless agreed upon to make this
1770 method permanent - could do something in the statusbar */
1771 snprintf(buf, sizeof(buf), "Warning: %08lX",
1772 pcm_rec_get_warnings());
1774 else
1775 #endif /* CONFIG_CODEC == SWCODEC */
1776 if ((global_settings.rec_sizesplit) &&
1777 (global_settings.rec_split_method))
1779 dmb = dsize/1024/1024;
1780 snprintf(buf, sizeof(buf), "%s %luMB",
1781 str(LANG_SPLIT_SIZE), dmb);
1783 else
1785 hours = seconds / 3600;
1786 minutes = (seconds - (hours * 3600)) / 60;
1787 snprintf(buf, sizeof(buf), "%s %02d:%02d:%02d",
1788 str(LANG_RECORDING_TIME),
1789 hours, minutes, seconds%60);
1792 FOR_NB_ACTIVE_SCREENS(i)
1793 screens[i].puts(0, 0, buf);
1795 if(audio_stat & AUDIO_STATUS_PRERECORD)
1797 snprintf(buf, sizeof(buf), "%s...",
1798 str(LANG_RECORD_PRERECORD));
1800 else
1802 /* Display the split interval if the record timesplit
1803 is active */
1804 if ((global_settings.rec_timesplit) &&
1805 !(global_settings.rec_split_method))
1807 /* Display the record timesplit interval rather
1808 than the file size if the record timer is active */
1809 dhours = dseconds / 3600;
1810 dminutes = (dseconds - (dhours * 3600)) / 60;
1811 snprintf(buf, sizeof(buf), "%s %02d:%02d",
1812 str(LANG_RECORDING_TIMESPLIT_REC),
1813 dhours, dminutes);
1815 else
1817 output_dyn_value(buf2, sizeof buf2,
1818 num_recorded_bytes,
1819 byte_units, true);
1820 snprintf(buf, sizeof(buf), "%s %s",
1821 str(LANG_RECORDING_SIZE), buf2);
1825 FOR_NB_ACTIVE_SCREENS(i)
1826 screens[i].puts(0, 1, buf);
1828 /* We will do file splitting regardless, either at the end of
1829 a split interval, or when the filesize approaches the 2GB
1830 FAT file size (compatibility) limit. */
1831 if ((audio_stat && !(global_settings.rec_split_method)
1832 && global_settings.rec_timesplit && (seconds >= dseconds))
1833 || (audio_stat && global_settings.rec_split_method
1834 && global_settings.rec_sizesplit
1835 && (num_recorded_bytes >= dsize))
1836 || (num_recorded_bytes >= MAX_FILE_SIZE))
1838 if (!(global_settings.rec_split_type)
1839 || (num_recorded_bytes >= MAX_FILE_SIZE))
1841 rec_command(RECORDING_CMD_START_NEWFILE);
1842 last_seconds = 0;
1844 else
1846 peak_meter_trigger(false);
1847 peak_meter_set_trigger_listener(NULL);
1848 if( global_settings.rec_split_type == 1)
1849 rec_command(RECORDING_CMD_STOP);
1850 else
1851 rec_command(RECORDING_CMD_STOP_SHUTDOWN);
1853 update_countdown = 0;
1856 /* draw the clipcounter just in front of the peakmeter */
1857 if(global_settings.peak_meter_clipcounter)
1859 int clipcount = pm_get_clipcount();
1860 FOR_NB_ACTIVE_SCREENS(i)
1862 if(!compact_view[i])
1864 screens[i].puts(0, 2, str(LANG_PM_CLIPCOUNT));
1865 screens[i].putsf(0, 3, "%4d", clipcount);
1867 else
1868 screens[i].putsf(0, 2, "%4d", clipcount);
1872 #ifdef HAVE_RECORDING_HISTOGRAM
1873 if(global_settings.rec_histogram_interval)
1875 if (peak_valid && !(hist_time % hist_time_interval) && hist_l)
1877 /* fill history buffer */
1878 history_l[history_pos] = hist_l * hist_size_h / 32767;
1879 history_r[history_pos] = hist_r * hist_size_h / 32767;
1880 history_pos = (history_pos + 1) % HIST_BUF_SIZE;
1881 history_l[history_pos] = history_r[history_pos] = 0;
1882 history_l[(history_pos + 1) % HIST_BUF_SIZE] = 0;
1883 history_r[(history_pos + 1) % HIST_BUF_SIZE] = 0;
1884 hist_l = 0;
1885 hist_r = 0;
1887 lcd_set_drawmode(DRMODE_SOLID);
1888 lcd_drawrect(0, hist_pos_y - 1,
1889 HIST_W + 2, hist_size_h + 1);
1890 lcd_drawrect(HIST_W + 6, hist_pos_y - 1,
1891 HIST_W + 2, hist_size_h + 1);
1892 lcd_set_drawmode(DRMODE_FG);
1894 j = history_pos;
1895 for (i = HIST_W-1; i >= 0; i--)
1897 j--;
1898 if(j<0)
1899 j = HIST_BUF_SIZE-1;
1900 if (history_l[j])
1902 if (history_l[j] == hist_size_h)
1903 lcd_set_foreground(LCD_HIST_OVER);
1904 #ifdef HAVE_LCD_COLOR
1905 else if (history_l[j] > hist_level_marks[1])
1906 lcd_set_foreground(LCD_HIST_HI);
1907 #endif
1908 else
1909 lcd_set_foreground(LCD_HIST_OK);
1910 lcd_vline(1 + i, HIST_Y-1, HIST_Y - history_l[j]);
1912 if (history_r[j])
1914 if (history_r[j] == hist_size_h)
1915 lcd_set_foreground(LCD_HIST_OVER);
1916 #ifdef HAVE_LCD_COLOR
1917 else if (history_r[j] > hist_level_marks[1])
1918 lcd_set_foreground(LCD_HIST_HI);
1919 #endif
1920 else
1921 lcd_set_foreground(LCD_HIST_OK);
1922 lcd_vline(HIST_W+7 + i, HIST_Y-1, HIST_Y - history_r[j]);
1925 lcd_set_foreground(
1926 #ifdef HAVE_LCD_COLOR
1927 global_settings.fg_color);
1928 #else
1929 LCD_DEFAULT_FG);
1930 #endif
1931 for (i = 0; i < 6; i++)
1932 lcd_hline(HIST_W + 3, HIST_W + 4,
1933 HIST_Y - hist_level_marks[i]);
1935 #endif /* HAVE_RECORDING_HISTOGRAM */
1937 #ifdef HAVE_AGC
1938 hist_time++;
1939 #endif
1941 /* draw the trigger status */
1942 if (peak_meter_trigger_status() != TRIG_OFF)
1944 peak_meter_draw_trig(pm_x, trig_ypos, trig_width,
1945 screen_update);
1946 FOR_NB_ACTIVE_SCREENS(i)
1947 screens[i].update_viewport_rect(pm_x[i], trig_ypos[i],
1948 trig_width[i] + 2, TRIG_HEIGHT);
1951 #ifdef HAVE_AGC
1952 #ifdef HAVE_MIC_REC
1953 if (global_settings.rec_source == AUDIO_SRC_MIC)
1955 if(agc_maxgain < (global_settings.rec_mic_gain))
1956 change_recording_gain(false, true, true);
1958 else
1959 #endif /* MIC */
1961 if(agc_maxgain < (global_settings.rec_left_gain))
1962 change_recording_gain(false, true, false);
1963 if(agc_maxgain < (global_settings.rec_right_gain))
1964 change_recording_gain(false, false, true);
1966 #endif /* HAVE_AGC */
1968 #if CONFIG_CODEC == SWCODEC
1969 #ifdef HAVE_SPDIF_REC
1970 if((global_settings.rec_source == AUDIO_SRC_SPDIF) &&
1971 (prev_sample_rate != pcm_rec_sample_rate()))
1973 /* spdif samplerate changed */
1974 prev_sample_rate = pcm_rec_sample_rate();
1975 update_list = true;
1977 #endif
1978 #endif
1980 if(update_list)
1982 /* update_list is set whenever content changes */
1983 update_list = false;
1984 gui_synclist_draw(&lists);
1987 /* draw peakmeter again (check if this can be removed) */
1988 FOR_NB_ACTIVE_SCREENS(i)
1990 screens[i].set_viewport(&vp_top[i]);
1991 peak_meter_screen(&screens[i], pm_x[i], pm_y[i], pm_h[i]);
1992 screens[i].update();
1994 } /* display update every second */
1996 if(audio_stat & AUDIO_STATUS_ERROR)
1998 done = true;
2000 } /* end while(!done) */
2002 audio_stat = audio_status();
2003 if (audio_stat & AUDIO_STATUS_ERROR)
2005 splash(0, str(LANG_DISK_FULL));
2007 FOR_NB_SCREENS(i)
2008 screens[i].update();
2010 #if CONFIG_CODEC == SWCODEC
2011 /* stop recording - some players like H10 freeze otherwise
2012 TO DO: find out why it freezes and fix properly */
2013 rec_command(RECORDING_CMD_STOP);
2014 audio_close_recording();
2015 #endif
2017 audio_error_clear();
2019 while(1)
2021 if (action_userabort(TIMEOUT_NOBLOCK))
2022 break;
2026 rec_abort:
2028 #if CONFIG_CODEC == SWCODEC
2029 rec_command(RECORDING_CMD_STOP);
2030 audio_close_recording();
2032 #ifdef HAVE_FMRADIO_REC
2033 if (radio_status != FMRADIO_OFF)
2034 /* Restore radio playback - radio_status should be unchanged if started
2035 through fm radio screen (barring usb connect) */
2036 rec_set_source(AUDIO_SRC_FMRADIO, (radio_status & FMRADIO_PAUSED) ?
2037 SRCF_FMRADIO_PAUSED : SRCF_FMRADIO_PLAYING);
2038 else
2039 #endif
2040 /* Go back to playback mode */
2041 rec_set_source(AUDIO_SRC_PLAYBACK, SRCF_PLAYBACK);
2043 /* restore talking */
2044 talk_disable(false);
2045 #else /* !SWCODEC */
2046 audio_init_playback();
2047 #endif /* CONFIG_CODEC == SWCODEC */
2049 #ifdef HAVE_SPEAKER
2050 /* Re-enable speaker */
2051 audiohw_enable_speaker(global_settings.speaker_enabled);
2052 #endif
2054 /* make sure the trigger is really turned off */
2055 peak_meter_trigger(false);
2056 peak_meter_set_trigger_listener(NULL);
2058 rec_status &= ~RCSTAT_IN_RECSCREEN;
2059 sound_settings_apply();
2061 FOR_NB_SCREENS(i)
2062 screens[i].setfont(FONT_UI);
2064 /* if the directory was created or recording happened, make sure the
2065 browser is updated */
2066 if (rec_status & (RCSTAT_CREATED_DIRECTORY | RCSTAT_HAVE_RECORDED))
2067 reload_directory();
2069 #if (CONFIG_STORAGE & STORAGE_ATA) && (CONFIG_LED == LED_REAL) \
2070 && !defined(SIMULATOR)
2071 ata_set_led_enabled(true);
2072 #endif
2074 settings_save();
2076 return (rec_status & RCSTAT_BEEN_IN_USB_MODE) != 0;
2077 } /* recording_screen */
2079 #if CONFIG_KEYPAD == RECORDER_PAD
2080 static bool f2_rec_screen(void)
2082 static const char* const freq_str[6] =
2084 "44.1kHz",
2085 "48kHz",
2086 "32kHz",
2087 "22.05kHz",
2088 "24kHz",
2089 "16kHz"
2092 bool exit = false;
2093 bool used = false;
2094 int w, h, i;
2095 char buf[32];
2096 int button;
2097 struct audio_recording_options rec_options;
2099 FOR_NB_SCREENS(i)
2101 screens[i].set_viewport(NULL);
2102 screens[i].setfont(FONT_SYSFIXED);
2103 screens[i].getstringsize("A",&w,&h);
2106 while (!exit) {
2107 const char* ptr;
2109 FOR_NB_SCREENS(i)
2111 screens[i].clear_display();
2113 /* Recording quality */
2114 screens[i].putsxy(0, LCD_HEIGHT/2 - h*2,
2115 str(LANG_SYSFONT_RECORDING_QUALITY));
2118 snprintf(buf, sizeof(buf), "%d", global_settings.rec_quality);
2119 FOR_NB_SCREENS(i)
2121 screens[i].putsxy(0, LCD_HEIGHT/2-h, buf);
2122 screens[i].mono_bitmap(bitmap_icons_7x8[Icon_FastBackward],
2123 LCD_WIDTH/2 - 16, LCD_HEIGHT/2 - 4, 7, 8);
2126 /* Frequency */
2127 snprintf(buf, sizeof buf, "%s:", str(LANG_SYSFONT_RECORDING_FREQUENCY));
2128 ptr = freq_str[global_settings.rec_frequency];
2129 FOR_NB_SCREENS(i)
2131 screens[i].getstringsize(buf,&w,&h);
2132 screens[i].putsxy((LCD_WIDTH-w)/2, LCD_HEIGHT - h*2, buf);
2133 screens[i].getstringsize(ptr, &w, &h);
2134 screens[i].putsxy((LCD_WIDTH-w)/2, LCD_HEIGHT - h, ptr);
2135 screens[i].mono_bitmap(bitmap_icons_7x8[Icon_DownArrow],
2136 LCD_WIDTH/2 - 3, LCD_HEIGHT - h*3, 7, 8);
2139 /* Channel mode */
2140 switch ( global_settings.rec_channels ) {
2141 case 0:
2142 ptr = str(LANG_SYSFONT_CHANNEL_STEREO);
2143 break;
2145 case 1:
2146 ptr = str(LANG_SYSFONT_CHANNEL_MONO);
2147 break;
2150 FOR_NB_SCREENS(i)
2152 screens[i].getstringsize(str(LANG_SYSFONT_CHANNELS), &w, &h);
2153 screens[i].putsxy(LCD_WIDTH - w, LCD_HEIGHT/2 - h*2,
2154 str(LANG_SYSFONT_CHANNELS));
2155 screens[i].getstringsize(str(LANG_SYSFONT_MODE), &w, &h);
2156 screens[i].putsxy(LCD_WIDTH - w, LCD_HEIGHT/2 - h,
2157 str(LANG_SYSFONT_MODE));
2158 screens[i].getstringsize(ptr, &w, &h);
2159 screens[i].putsxy(LCD_WIDTH - w, LCD_HEIGHT/2, ptr);
2160 screens[i].mono_bitmap(bitmap_icons_7x8[Icon_FastForward],
2161 LCD_WIDTH/2 + 8, LCD_HEIGHT/2 - 4, 7, 8);
2163 screens[i].update();
2166 button = button_get(true);
2167 switch (button) {
2168 case BUTTON_LEFT:
2169 case BUTTON_F2 | BUTTON_LEFT:
2170 global_settings.rec_quality++;
2171 if(global_settings.rec_quality > 7)
2172 global_settings.rec_quality = 0;
2173 used = true;
2174 break;
2176 case BUTTON_DOWN:
2177 case BUTTON_F2 | BUTTON_DOWN:
2178 global_settings.rec_frequency++;
2179 if(global_settings.rec_frequency > 5)
2180 global_settings.rec_frequency = 0;
2181 used = true;
2182 break;
2184 case BUTTON_RIGHT:
2185 case BUTTON_F2 | BUTTON_RIGHT:
2186 global_settings.rec_channels++;
2187 if(global_settings.rec_channels > 1)
2188 global_settings.rec_channels = 0;
2189 used = true;
2190 break;
2192 case BUTTON_F2 | BUTTON_REL:
2193 if ( used )
2194 exit = true;
2195 used = true;
2196 break;
2198 case BUTTON_F2 | BUTTON_REPEAT:
2199 used = true;
2200 break;
2202 default:
2203 if(default_event_handler(button) == SYS_USB_CONNECTED)
2204 return true;
2205 break;
2209 rec_init_recording_options(&rec_options);
2210 rec_set_recording_options(&rec_options);
2212 set_gain();
2214 settings_save();
2215 FOR_NB_SCREENS(i)
2216 screens[i].setfont(FONT_UI);
2218 return false;
2221 static bool f3_rec_screen(void)
2223 bool exit = false;
2224 bool used = false;
2225 int w, h, i;
2226 int button;
2227 const char *src_str[] =
2229 str(LANG_SYSFONT_RECORDING_SRC_MIC),
2230 str(LANG_SYSFONT_LINE_IN),
2231 str(LANG_SYSFONT_RECORDING_SRC_DIGITAL)
2233 struct audio_recording_options rec_options;
2235 FOR_NB_SCREENS(i)
2237 screens[i].set_viewport(NULL);
2238 screens[i].setfont(FONT_SYSFIXED);
2239 screens[i].getstringsize("A",&w,&h);
2242 while (!exit) {
2243 const char* ptr = src_str[global_settings.rec_source];
2244 FOR_NB_SCREENS(i)
2246 screens[i].clear_display();
2248 /* Recording source */
2249 screens[i].putsxy(0, LCD_HEIGHT/2 - h*2,
2250 str(LANG_SYSFONT_RECORDING_SOURCE));
2252 screens[i].getstringsize(ptr, &w, &h);
2253 screens[i].putsxy(0, LCD_HEIGHT/2-h, ptr);
2254 screens[i].mono_bitmap(bitmap_icons_7x8[Icon_FastBackward],
2255 LCD_WIDTH/2 - 16, LCD_HEIGHT/2 - 4, 7, 8);
2258 /* trigger setup */
2259 ptr = str(LANG_SYSFONT_RECORD_TRIGGER);
2260 FOR_NB_SCREENS(i)
2262 screens[i].getstringsize(ptr,&w,&h);
2263 screens[i].putsxy((LCD_WIDTH-w)/2, LCD_HEIGHT - h*2, ptr);
2264 screens[i].mono_bitmap(bitmap_icons_7x8[Icon_DownArrow],
2265 LCD_WIDTH/2 - 3, LCD_HEIGHT - h*3, 7, 8);
2267 screens[i].update();
2270 button = button_get(true);
2271 switch (button) {
2272 case BUTTON_DOWN:
2273 case BUTTON_F3 | BUTTON_DOWN:
2274 #ifndef SIMULATOR
2275 rectrigger();
2276 settings_apply_trigger();
2277 #endif
2278 exit = true;
2279 break;
2281 case BUTTON_LEFT:
2282 case BUTTON_F3 | BUTTON_LEFT:
2283 global_settings.rec_source++;
2284 if(global_settings.rec_source > AUDIO_SRC_MAX)
2285 global_settings.rec_source = 0;
2286 used = true;
2287 break;
2289 case BUTTON_F3 | BUTTON_REL:
2290 if ( used )
2291 exit = true;
2292 used = true;
2293 break;
2295 case BUTTON_F3 | BUTTON_REPEAT:
2296 used = true;
2297 break;
2299 default:
2300 if(default_event_handler(button) == SYS_USB_CONNECTED)
2301 return true;
2302 break;
2306 rec_init_recording_options(&rec_options);
2307 rec_set_recording_options(&rec_options);
2309 set_gain();
2311 settings_save();
2312 FOR_NB_SCREENS(i)
2313 screens[i].setfont(FONT_UI);
2315 return false;
2317 #endif /* CONFIG_KEYPAD == RECORDER_PAD */
2319 #if CONFIG_CODEC == SWCODEC
2320 void audio_beep(int duration)
2322 /* dummy */
2323 (void)duration;
2325 #endif /* #ifdef CONFIG_CODEC == SWCODEC */
2327 #endif /* HAVE_RECORDING */