Build doom on clipv2 and clip+
[kugel-rb.git] / apps / recorder / recording.c
blobfd1ff75e08d2ea5d5e5696f0263b4caa5cd8915a
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 "mas.h"
46 #include "button.h"
47 #include "kernel.h"
48 #include "settings.h"
49 #include "lang.h"
50 #include "font.h"
51 #include "icons.h"
52 #include "icon.h"
53 #include "screens.h"
54 #include "peakmeter.h"
55 #include "menu.h"
56 #include "sound_menu.h"
57 #include "timefuncs.h"
58 #include "debug.h"
59 #include "misc.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, global_settings.rec_directory);
626 snprintf(ext, sizeof(ext), ".%s",
627 REC_FILE_ENDING(global_settings.rec_format));
629 #if CONFIG_RTC == 0
630 return create_numbered_filename(buffer, buffer, pref, ext, 4,
631 &file_number);
632 #else
633 /* We'll wait at least up to the start of the next second so no duplicate
634 names are created */
635 return create_datetime_filename(buffer, buffer, pref, ext, true);
636 #endif
639 #if CONFIG_RTC == 0
640 /* Hit disk to get a starting filename for the type */
641 static void rec_init_filename(void)
643 file_number = -1;
644 rec_create_filename(path_buffer);
645 file_number--;
647 #endif
649 int rec_create_directory(void)
651 int rc = 0;
652 const char * const folder = global_settings.rec_directory;
654 if (strcmp(folder, "/") && !dir_exists(folder))
656 rc = mkdir(folder);
658 if(rc < 0)
660 while (action_userabort(HZ) == false)
662 splashf(0, "%s %s",
663 str(LANG_REC_DIR_NOT_WRITABLE),
664 str(LANG_OFF_ABORT));
667 else
669 rec_status |= RCSTAT_CREATED_DIRECTORY;
670 rc = 1;
674 return rc;
677 void rec_init_recording_options(struct audio_recording_options *options)
679 options->rec_source = global_settings.rec_source;
680 options->rec_frequency = global_settings.rec_frequency;
681 options->rec_channels = global_settings.rec_channels;
682 options->rec_prerecord_time = global_settings.rec_prerecord_time;
683 #if CONFIG_CODEC == SWCODEC
684 options->rec_mono_mode = global_settings.rec_mono_mode;
685 options->rec_source_flags = 0;
686 options->enc_config.rec_format = global_settings.rec_format;
687 global_to_encoder_config(&options->enc_config);
688 #else
689 options->rec_quality = global_settings.rec_quality;
690 options->rec_editable = global_settings.rec_editable;
691 #endif
694 #if CONFIG_CODEC == SWCODEC && !defined (SIMULATOR)
695 void rec_set_source(int source, unsigned flags)
697 /* Set audio input source, power up/down devices */
698 audio_set_input_source(source, flags);
700 /* Set peakmeters for recording or reset to playback */
701 peak_meter_playback((flags & SRCF_RECORDING) == 0);
702 peak_meter_enable(true);
704 #endif /* CONFIG_CODEC == SWCODEC && !defined (SIMULATOR) */
706 void rec_set_recording_options(struct audio_recording_options *options)
708 #if CONFIG_CODEC != SWCODEC
709 if (global_settings.rec_prerecord_time)
711 talk_buffer_steal(); /* will use the mp3 buffer */
713 #else /* == SWCODEC */
714 rec_set_source(options->rec_source,
715 options->rec_source_flags | SRCF_RECORDING);
716 #endif /* CONFIG_CODEC != SWCODEC */
718 audio_set_recording_options(options);
721 void rec_command(enum recording_command cmd)
723 switch(cmd)
725 case RECORDING_CMD_STOP_SHUTDOWN:
726 pm_activate_clipcount(false);
727 audio_stop_recording();
728 #if CONFIG_CODEC == SWCODEC
729 audio_close_recording();
730 #endif
731 sys_poweroff();
732 break;
733 case RECORDING_CMD_STOP:
734 pm_activate_clipcount(false);
735 audio_stop_recording();
736 break;
737 case RECORDING_CMD_START:
738 /* steal mp3 buffer, create unique filename and start recording */
739 pm_reset_clipcount();
740 pm_activate_clipcount(true);
741 #if CONFIG_CODEC != SWCODEC
742 talk_buffer_steal(); /* we use the mp3 buffer */
743 #endif
744 audio_record(rec_create_filename(path_buffer));
745 break;
746 case RECORDING_CMD_START_NEWFILE:
747 /* create unique filename and start recording*/
748 pm_reset_clipcount();
749 pm_activate_clipcount(true); /* just to be sure */
750 audio_new_file(rec_create_filename(path_buffer));
751 break;
752 case RECORDING_CMD_PAUSE:
753 pm_activate_clipcount(false);
754 audio_pause_recording();
755 break;
756 case RECORDING_CMD_RESUME:
757 pm_activate_clipcount(true);
758 audio_resume_recording();
759 break;
761 update_list = true;
764 /* used in trigger_listerner and recording_screen */
765 static unsigned int last_seconds = 0;
768 * Callback function so that the peak meter code can send an event
769 * to this application. This function can be passed to
770 * peak_meter_set_trigger_listener in order to activate the trigger.
772 static void trigger_listener(int trigger_status)
774 switch (trigger_status)
776 case TRIG_GO:
777 if(!(audio_status() & AUDIO_STATUS_RECORD))
779 rec_status |= RCSTAT_HAVE_RECORDED;
780 rec_command(RECORDING_CMD_START);
781 #if CONFIG_CODEC != SWCODEC
782 /* give control to mpeg thread so that it can start
783 recording */
784 yield(); yield(); yield();
785 #endif
788 /* if we're already recording this is a retrigger */
789 else
791 if((audio_status() & AUDIO_STATUS_PAUSE) &&
792 (global_settings.rec_trigger_type == TRIG_TYPE_PAUSE))
794 rec_command(RECORDING_CMD_RESUME);
796 /* New file on trig start*/
797 else if (global_settings.rec_trigger_type != TRIG_TYPE_NEW_FILE)
799 rec_command(RECORDING_CMD_START_NEWFILE);
800 /* tell recording_screen to reset the time */
801 last_seconds = 0;
804 break;
806 /* A _change_ to TRIG_READY means the current recording has stopped */
807 case TRIG_READY:
808 if(audio_status() & AUDIO_STATUS_RECORD)
810 switch(global_settings.rec_trigger_type)
812 case TRIG_TYPE_STOP: /* Stop */
813 rec_command(RECORDING_CMD_STOP);
814 break;
816 case TRIG_TYPE_PAUSE: /* Pause */
817 rec_command(RECORDING_CMD_PAUSE);
818 break;
820 case TRIG_TYPE_NEW_FILE: /* New file on trig stop*/
821 rec_command(RECORDING_CMD_START_NEWFILE);
822 /* tell recording_screen to reset the time */
823 last_seconds = 0;
824 break;
826 case 3: /* Stop and shutdown */
827 rec_command(RECORDING_CMD_STOP_SHUTDOWN);
828 break;
831 if (global_settings.rec_trigger_mode != TRIG_MODE_REARM)
833 peak_meter_set_trigger_listener(NULL);
834 peak_meter_trigger(false);
837 break;
841 /* Stuff for drawing the screen */
843 enum rec_list_items_stereo {
844 ITEM_VOLUME = 0,
845 ITEM_GAIN = 1,
846 ITEM_GAIN_L = 2,
847 ITEM_GAIN_R = 3,
848 #ifdef HAVE_AGC
849 ITEM_AGC_MODE = 4,
850 ITEM_AGC_MAXDB = 5,
851 ITEM_FILENAME = 7,
852 ITEM_COUNT = 7,
853 #else
854 ITEM_FILENAME = 7,
855 ITEM_COUNT = 5,
856 #endif
859 enum rec_list_items_mono {
860 ITEM_VOLUME_M = 0,
861 ITEM_GAIN_M = 1,
862 #ifdef HAVE_AGC
863 ITEM_AGC_MODE_M = 4,
864 ITEM_AGC_MAXDB_M = 5,
865 ITEM_FILENAME_M = 7,
866 ITEM_COUNT_M = 5,
867 #else
868 ITEM_FILENAME_M = 7,
869 ITEM_COUNT_M = 3,
870 #endif
873 #ifdef HAVE_SPDIF_REC
874 enum rec_list_items_spdif {
875 ITEM_VOLUME_D = 0,
876 #if CONFIG_CODEC == SWCODEC
877 ITEM_SAMPLERATE_D = 6,
878 ITEM_FILENAME_D = 7,
879 ITEM_COUNT_D = 3,
880 #else
881 ITEM_FILENAME_D = 7,
882 ITEM_COUNT_D = 2,
883 #endif
885 #endif
887 static int listid_to_enum[ITEM_COUNT];
889 static const char* reclist_get_name(int selected_item, void * data,
890 char * buffer, size_t buffer_len)
892 char buf2[32];
893 #ifdef HAVE_AGC
894 char buf3[32];
895 #endif
896 data = data; /* not used */
897 if(selected_item >= ITEM_COUNT)
898 return "";
900 switch (listid_to_enum[selected_item])
902 case ITEM_VOLUME:
903 snprintf(buffer, buffer_len, "%s: %s", str(LANG_VOLUME),
904 fmt_gain(SOUND_VOLUME,
905 global_settings.volume,
906 buf2, sizeof(buf2)));
907 break;
908 case ITEM_GAIN:
909 #ifdef HAVE_MIC_REC
910 if(global_settings.rec_source == AUDIO_SRC_MIC)
912 /* Draw MIC recording gain */
913 snprintf(buffer, buffer_len, "%s: %s", str(LANG_GAIN),
914 fmt_gain(SOUND_MIC_GAIN,
915 global_settings.rec_mic_gain,
916 buf2, sizeof(buf2)));
918 else
919 #endif /* MIC */
921 int avg_gain = (global_settings.rec_left_gain +
922 global_settings.rec_right_gain) / 2;
923 snprintf(buffer, buffer_len, "%s: %s", str(LANG_GAIN),
924 fmt_gain(SOUND_LEFT_GAIN,
925 avg_gain,
926 buf2, sizeof(buf2)));
928 break;
929 case ITEM_GAIN_L:
930 snprintf(buffer, buffer_len, "%s: %s",
931 str(LANG_GAIN_LEFT),
932 fmt_gain(SOUND_LEFT_GAIN,
933 global_settings.rec_left_gain,
934 buf2, sizeof(buf2)));
935 break;
936 case ITEM_GAIN_R:
937 snprintf(buffer, buffer_len, "%s: %s",
938 str(LANG_GAIN_RIGHT),
939 fmt_gain(SOUND_RIGHT_GAIN,
940 global_settings.rec_right_gain,
941 buf2, sizeof(buf2)));
942 break;
943 #ifdef HAVE_AGC
944 case ITEM_AGC_MODE:
945 snprintf(buffer, buffer_len, "%s: %s",
946 str(LANG_RECORDING_AGC_PRESET),
947 agc_preset_str[agc_preset]);
948 break;
949 case ITEM_AGC_MAXDB:
950 if (agc_preset == 0)
951 snprintf(buffer, buffer_len, "%s: %s",
952 str(LANG_RECORDING_AGC_MAXGAIN),
953 fmt_gain(SOUND_LEFT_GAIN,
954 agc_maxgain, buf2, sizeof(buf2)));
955 #ifdef HAVE_MIC_REC
956 else if (global_settings.rec_source == AUDIO_SRC_MIC)
957 snprintf(buffer, buffer_len, "%s: %s (%s)",
958 str(LANG_RECORDING_AGC_MAXGAIN),
959 fmt_gain(SOUND_MIC_GAIN,
960 agc_maxgain, buf2, sizeof(buf2)),
961 fmt_gain(SOUND_MIC_GAIN,
962 agc_maxgain - global_settings.rec_mic_gain,
963 buf3, sizeof(buf3)));
964 else
965 #endif /* MIC */
966 snprintf(buffer, buffer_len, "%s: %s (%s)",
967 str(LANG_RECORDING_AGC_MAXGAIN),
968 fmt_gain(SOUND_LEFT_GAIN,
969 agc_maxgain, buf2, sizeof(buf2)),
970 fmt_gain(SOUND_LEFT_GAIN,
971 agc_maxgain -
972 (global_settings.rec_left_gain +
973 global_settings.rec_right_gain)/2,
974 buf3, sizeof(buf3)));
975 break;
976 #endif
977 #if CONFIG_CODEC == SWCODEC
978 #ifdef HAVE_SPDIF_REC
979 case ITEM_SAMPLERATE_D:
980 snprintf(buffer, buffer_len, "%s: %lu",
981 str(LANG_RECORDING_FREQUENCY),
982 pcm_rec_sample_rate());
983 break;
984 #endif
985 #endif
986 case ITEM_FILENAME:
988 if(audio_status() & AUDIO_STATUS_RECORD)
990 size_t tot_len = strlen(path_buffer) +
991 strlen(str(LANG_RECORDING_FILENAME)) + 1;
992 if(tot_len > buffer_len)
994 snprintf(buffer, buffer_len, "%s %s",
995 str(LANG_RECORDING_FILENAME),
996 path_buffer + tot_len - buffer_len);
998 else
1000 snprintf(buffer, buffer_len, "%s %s",
1001 str(LANG_RECORDING_FILENAME), path_buffer);
1004 else
1006 return str(LANG_RECORDING_FILENAME);
1008 break;
1010 default:
1011 return "";
1013 return buffer;
1017 bool recording_start_automatic = false;
1019 bool recording_screen(bool no_source)
1021 int button;
1022 int done = -1; /* negative to re-init, positive to quit, zero to run */
1023 char buf[32]; /* for preparing strings */
1024 char buf2[32]; /* for preparing strings */
1025 int w, h; /* character width/height */
1026 int update_countdown = 0; /* refresh counter */
1027 unsigned int seconds;
1028 int hours, minutes;
1029 int audio_stat = 0; /* status of the audio system */
1030 int last_audio_stat = -1; /* previous status so we can act on changes */
1031 struct viewport vp_list[NB_SCREENS], vp_top[NB_SCREENS]; /* the viewports */
1033 #if CONFIG_CODEC == SWCODEC
1034 int warning_counter = 0;
1035 #define WARNING_PERIOD 7
1036 #endif
1038 #if CONFIG_CODEC == SWCODEC
1039 #ifdef HAVE_SPDIF_REC
1040 unsigned long prev_sample_rate = 0;
1041 #endif
1042 #endif
1044 #ifdef HAVE_FMRADIO_REC
1045 /* Radio is left on if:
1046 * 1) Is was on at the start and the initial source is FM Radio
1047 * 2) 1) and the source was never changed to something else
1049 int radio_status = (global_settings.rec_source != AUDIO_SRC_FMRADIO) ?
1050 FMRADIO_OFF : get_radio_status();
1051 #endif
1052 #if (CONFIG_LED == LED_REAL)
1053 bool led_state = false;
1054 int led_countdown = 2;
1055 #endif
1056 #ifdef HAVE_AGC
1057 bool peak_read = false;
1058 int peak_l, peak_r;
1059 int balance = 0;
1060 #endif
1061 int i;
1062 int pm_x[NB_SCREENS]; /* peakmeter (and trigger bar) x pos */
1063 int pm_y[NB_SCREENS]; /* peakmeter y pos */
1064 int pm_h[NB_SCREENS]; /* peakmeter height */
1065 int trig_ypos[NB_SCREENS]; /* trigger bar y pos */
1066 int trig_width[NB_SCREENS]; /* trigger bar width */
1067 int top_height_req[NB_SCREENS]; /* required height for top half */
1068 /* tweak layout tiny screens / big fonts */
1069 bool compact_view[NB_SCREENS] = { false };
1070 struct gui_synclist lists; /* the list in the bottom vp */
1071 #if defined(HAVE_AGC) || defined(HAVE_RECORDING_HISTOGRAM)
1072 bool peak_valid = false;
1073 #endif
1074 #if defined(HAVE_RECORDING_HISTOGRAM)
1075 int j;
1076 unsigned short hist_pos_y = 0;
1077 unsigned short hist_size_h = 0;
1078 int history_pos = 0;
1079 short hist_time_interval = 1; /* 1, 2, 4, 8 */
1080 unsigned char history_l[HIST_BUF_SIZE];
1081 unsigned char history_r[HIST_BUF_SIZE];
1082 const char hist_level_marks[6] = { 29, 26, 23, 17, 9, 2};
1083 #endif
1084 #ifdef HAVE_FMRADIO_REC
1085 int prev_rec_source = global_settings.rec_source; /* detect source change */
1086 #endif
1088 struct audio_recording_options rec_options;
1089 rec_status = RCSTAT_IN_RECSCREEN;
1091 #if (CONFIG_STORAGE & STORAGE_ATA) && (CONFIG_LED == LED_REAL) \
1092 && !defined(SIMULATOR)
1093 ata_set_led_enabled(false);
1094 #endif
1096 #if CONFIG_CODEC == SWCODEC
1097 /* This should be done before touching audio settings */
1098 while (!audio_is_thread_ready())
1099 sleep(0);
1101 /* recording_menu gets messed up: so prevent manus talking */
1102 talk_disable(true);
1103 /* audio_init_recording stops anything playing when it takes the audio
1104 buffer */
1105 #else
1106 /* Yes, we use the D/A for monitoring */
1107 peak_meter_enable(true);
1108 peak_meter_playback(true);
1109 #endif
1111 #ifdef HAVE_AGC
1112 peak_meter_get_peakhold(&peak_l, &peak_r);
1113 #endif
1115 pm_reset_clipcount();
1116 pm_activate_clipcount(false);
1117 settings_apply_trigger();
1119 #ifdef HAVE_AGC
1120 agc_preset_str[0] = str(LANG_OFF);
1121 agc_preset_str[1] = str(LANG_AGC_SAFETY);
1122 agc_preset_str[2] = str(LANG_AGC_LIVE);
1123 agc_preset_str[3] = str(LANG_AGC_DJSET);
1124 agc_preset_str[4] = str(LANG_AGC_MEDIUM);
1125 agc_preset_str[5] = str(LANG_AGC_VOICE);
1126 #endif /* HAVE_AGC */
1128 #ifdef HAVE_SPEAKER
1129 /* Disable speaker to prevent feedback */
1130 audiohw_enable_speaker(false);
1131 #endif
1133 #if CONFIG_CODEC == SWCODEC
1134 audio_close_recording();
1135 #endif
1136 audio_init_recording(0);
1137 sound_set_volume(global_settings.volume);
1139 #if CONFIG_RTC == 0
1140 /* Create new filename for recording start */
1141 rec_init_filename();
1142 #endif
1144 /* start of the loop: we stay in this loop until user quits recscreen */
1145 while(done <= 0)
1147 if(done < 0)
1149 /* request to re-init stuff, done after settings screen */
1150 done = 0;
1151 #ifdef HAVE_FMRADIO_REC
1152 /* If input changes away from FM Radio,
1153 radio will remain off when recording screen closes. */
1154 if (global_settings.rec_source != prev_rec_source
1155 && prev_rec_source == AUDIO_SRC_FMRADIO)
1156 radio_status = FMRADIO_OFF;
1157 prev_rec_source = global_settings.rec_source;
1158 #endif
1160 /* viewport init and calculations that only needs to be done once */
1161 FOR_NB_SCREENS(i)
1163 struct viewport *v;
1164 /* top vp, 4 lines, force sys font if total screen < 6 lines
1165 NOTE: one could limit the list to 1 line and get away with 5 lines */
1166 top_height_req[i] = 4;
1167 #if defined(HAVE_RECORDING_HISTOGRAM)
1168 if((global_settings.rec_histogram_interval) && (!i))
1169 top_height_req[i] += 1; /* use one line for histogram */
1170 hist_time_interval = 1 << global_settings.rec_histogram_interval;
1171 #endif
1172 v = &vp_top[i];
1173 viewport_set_defaults(v, i);
1174 if (viewport_get_nb_lines(v) < top_height_req[i])
1176 /* compact needs 4 lines total */
1177 v->font = FONT_SYSFIXED;
1178 compact_view[i] = false;
1180 else
1182 /*top=4,list=2*/
1183 if (viewport_get_nb_lines(v) < (top_height_req[i]+2))
1184 compact_view[i] = true;
1185 else
1186 compact_view[i] = false;
1188 vp_list[i] = *v; /* get a copy now so it can be sized more easily */
1189 v->height = (font_get(v->font)->height)*(compact_view[i] ? 3 :
1190 top_height_req[i]);
1192 /* list section, rest of the screen */
1193 vp_list[i].y += vp_top[i].height;
1194 vp_list[i].height -= vp_top[i].height;
1195 screens[i].set_viewport(&vp_top[i]); /* req for next calls */
1197 screens[i].getstringsize("W", &w, &h);
1198 pm_y[i] = font_get(vp_top[i].font)->height * 2;
1199 trig_ypos[i] = font_get(vp_top[i].font)->height * 3;
1200 if(compact_view[i])
1201 trig_ypos[i] -= (font_get(vp_top[i].font)->height)/2;
1204 /* init the bottom list */
1205 gui_synclist_init(&lists, reclist_get_name, NULL, false, 1, vp_list);
1206 gui_synclist_set_title(&lists, NULL, Icon_NOICON);
1208 send_event(GUI_EVENT_ACTIONUPDATE, (void*)1); /* force a redraw */
1210 #if defined(HAVE_RECORDING_HISTOGRAM)
1211 history_pos = 0;
1212 hist_pos_y = (compact_view[0] ? 3 : 4) * (font_get(vp_top[0].font)->height)
1213 + 1;
1214 hist_size_h = font_get(vp_top[0].font)->height - 2;
1215 memset(history_l, 0, sizeof(unsigned char)*HIST_BUF_SIZE);
1216 memset(history_r, 0, sizeof(unsigned char)*HIST_BUF_SIZE);
1217 #endif
1219 FOR_NB_SCREENS(i)
1221 pm_x[i] = 0;
1222 if(global_settings.peak_meter_clipcounter)
1224 int clipwidth = 0;
1225 screens[i].getstringsize(str(LANG_PM_CLIPCOUNT),
1226 &clipwidth, &h); /* h is same */
1227 pm_x[i] = clipwidth+1;
1229 if(global_settings.rec_trigger_mode == TRIG_MODE_OFF)
1230 pm_h[i] = font_get(vp_top[i].font)->height * 2;
1231 else
1232 pm_h[i] = font_get(vp_top[i].font)->height;
1233 if(compact_view[i])
1234 pm_h[i] /= 2;
1235 trig_width[i] = vp_top[i].width - pm_x[i];
1238 #if CONFIG_CODEC == SWCODEC
1239 audio_close_recording();
1240 audio_init_recording(0);
1241 #endif
1243 rec_init_recording_options(&rec_options);
1244 rec_set_recording_options(&rec_options);
1246 if(rec_create_directory() < 0)
1248 rec_status = 0;
1249 goto rec_abort;
1252 #if CONFIG_CODEC == SWCODEC && CONFIG_RTC == 0
1253 /* If format changed, a new number is required */
1254 rec_init_filename();
1255 #endif
1257 #ifdef HAVE_AGC
1258 #ifdef HAVE_MIC_REC
1259 if (global_settings.rec_source == AUDIO_SRC_MIC) {
1260 agc_preset = global_settings.rec_agc_preset_mic;
1261 agc_maxgain = global_settings.rec_agc_maxgain_mic;
1263 else
1264 #endif /* MIC */
1266 agc_preset = global_settings.rec_agc_preset_line;
1267 agc_maxgain = global_settings.rec_agc_maxgain_line;
1269 #endif /* HAVE_AGC */
1271 set_gain();
1272 update_countdown = 0; /* Update immediately */
1274 /* populate translation table for list id -> enum */
1275 #ifdef HAVE_SPDIF_REC
1276 if(global_settings.rec_source == AUDIO_SRC_SPDIF)
1278 listid_to_enum[0] = ITEM_VOLUME_D;
1279 #if CONFIG_CODEC == SWCODEC
1280 listid_to_enum[1] = ITEM_SAMPLERATE_D;
1281 listid_to_enum[2] = ITEM_FILENAME_D;
1282 #else
1283 listid_to_enum[1] = ITEM_FILENAME_D;
1284 #endif
1286 gui_synclist_set_nb_items(&lists, ITEM_COUNT_D); /* spdif */
1288 else
1289 #endif
1290 if(HAVE_MIC_REC_((global_settings.rec_source == AUDIO_SRC_MIC) || )
1291 (global_settings.rec_channels == 1))
1293 listid_to_enum[0] = ITEM_VOLUME_M;
1294 listid_to_enum[1] = ITEM_GAIN_M;
1295 #ifdef HAVE_AGC
1296 listid_to_enum[2] = ITEM_AGC_MODE_M;
1297 listid_to_enum[3] = ITEM_AGC_MAXDB_M;
1298 listid_to_enum[4] = ITEM_FILENAME_M;
1299 #else
1300 listid_to_enum[2] = ITEM_FILENAME_M;
1301 #endif
1302 gui_synclist_set_nb_items(&lists, ITEM_COUNT_M); /* mono */
1304 else
1306 listid_to_enum[0] = ITEM_VOLUME;
1307 listid_to_enum[1] = ITEM_GAIN;
1308 listid_to_enum[2] = ITEM_GAIN_L;
1309 listid_to_enum[3] = ITEM_GAIN_R;
1310 #ifdef HAVE_AGC
1311 listid_to_enum[4] = ITEM_AGC_MODE;
1312 listid_to_enum[5] = ITEM_AGC_MAXDB;
1313 listid_to_enum[6] = ITEM_FILENAME;
1314 #else
1315 listid_to_enum[4] = ITEM_FILENAME;
1316 #endif
1317 gui_synclist_set_nb_items(&lists, ITEM_COUNT); /* stereo */
1320 gui_synclist_draw(&lists);
1321 } /* if(done < 0) */
1323 audio_stat = audio_status();
1325 #if (CONFIG_LED == LED_REAL)
1328 * Flash the LED while waiting to record. Turn it on while
1329 * recording.
1331 if(audio_stat & AUDIO_STATUS_RECORD)
1333 if (audio_stat & AUDIO_STATUS_PAUSE)
1335 if (--led_countdown <= 0)
1337 led_state = !led_state;
1338 led(led_state);
1339 led_countdown = 2;
1342 else
1344 /* trigger is on in status TRIG_READY (no check needed) */
1345 led(true);
1348 else
1350 int trig_stat = peak_meter_trigger_status();
1352 * other trigger stati than trig_off and trig_steady
1353 * already imply that we are recording.
1355 if (trig_stat == TRIG_STEADY)
1357 if (--led_countdown <= 0)
1359 led_state = !led_state;
1360 led(led_state);
1361 led_countdown = 2;
1364 else
1366 /* trigger is on in status TRIG_READY (no check needed) */
1367 led(false);
1370 #endif /* CONFIG_LED */
1372 /* Wait for a button a while (HZ/10) drawing the peak meter */
1373 button = peak_meter_draw_get_btn(CONTEXT_RECSCREEN,
1374 pm_x, pm_y, pm_h,
1375 screen_update, vp_top);
1376 if (last_audio_stat != audio_stat)
1378 if (audio_stat & AUDIO_STATUS_RECORD)
1380 rec_status |= RCSTAT_HAVE_RECORDED;
1382 last_audio_stat = audio_stat;
1383 update_list = true;
1386 if (recording_start_automatic)
1388 /* simulate a button press */
1389 button = ACTION_REC_PAUSE;
1390 recording_start_automatic = false;
1393 /* let list handle the button */
1394 gui_synclist_do_button(&lists, &button, LIST_WRAP_UNLESS_HELD);
1397 switch(button)
1399 case ACTION_SETTINGS_INC:
1400 case ACTION_SETTINGS_INCREPEAT:
1401 switch (listid_to_enum[gui_synclist_get_sel_pos(&lists)])
1403 case ITEM_VOLUME:
1404 global_settings.volume++;
1405 setvol();
1406 break;
1407 case ITEM_GAIN:
1408 #ifdef HAVE_MIC_REC
1409 if(global_settings.rec_source == AUDIO_SRC_MIC)
1411 if(global_settings.rec_mic_gain <
1412 sound_max(SOUND_MIC_GAIN))
1413 global_settings.rec_mic_gain++;
1415 else
1416 #endif /* MIC */
1418 if(global_settings.rec_left_gain <
1419 sound_max(SOUND_LEFT_GAIN))
1420 global_settings.rec_left_gain++;
1421 if(global_settings.rec_right_gain <
1422 sound_max(SOUND_RIGHT_GAIN))
1423 global_settings.rec_right_gain++;
1425 break;
1426 case ITEM_GAIN_L:
1427 if(global_settings.rec_left_gain <
1428 sound_max(SOUND_LEFT_GAIN))
1429 global_settings.rec_left_gain++;
1430 break;
1431 case ITEM_GAIN_R:
1432 if(global_settings.rec_right_gain <
1433 sound_max(SOUND_RIGHT_GAIN))
1434 global_settings.rec_right_gain++;
1435 break;
1436 #ifdef HAVE_AGC
1437 case ITEM_AGC_MODE:
1438 agc_preset = MIN(agc_preset + 1, AGC_MODE_SIZE);
1439 agc_enable = (agc_preset != 0);
1440 #ifdef HAVE_MIC_REC
1441 if (global_settings.rec_source == AUDIO_SRC_MIC) {
1442 global_settings.rec_agc_preset_mic = agc_preset;
1443 agc_maxgain = global_settings.rec_agc_maxgain_mic;
1444 } else
1445 #endif /* MIC */
1447 global_settings.rec_agc_preset_line = agc_preset;
1448 agc_maxgain = global_settings.rec_agc_maxgain_line;
1450 break;
1451 case ITEM_AGC_MAXDB:
1452 #ifdef HAVE_MIC_REC
1453 if (global_settings.rec_source == AUDIO_SRC_MIC)
1455 agc_maxgain = MIN(agc_maxgain + 1,
1456 sound_max(SOUND_MIC_GAIN));
1457 global_settings.rec_agc_maxgain_mic = agc_maxgain;
1459 else
1460 #endif /* MIC */
1462 agc_maxgain = MIN(agc_maxgain + 1,
1463 sound_max(SOUND_LEFT_GAIN));
1464 global_settings.rec_agc_maxgain_line = agc_maxgain;
1466 break;
1467 #endif /* HAVE_AGC */
1469 set_gain();
1470 update_countdown = 0; /* Update immediately */
1471 break;
1472 case ACTION_SETTINGS_DEC:
1473 case ACTION_SETTINGS_DECREPEAT:
1474 switch (listid_to_enum[gui_synclist_get_sel_pos(&lists)])
1476 case ITEM_VOLUME:
1477 global_settings.volume--;
1478 setvol();
1479 break;
1480 case ITEM_GAIN:
1481 #ifdef HAVE_MIC_REC
1482 if(global_settings.rec_source == AUDIO_SRC_MIC)
1484 if(global_settings.rec_mic_gain >
1485 sound_min(SOUND_MIC_GAIN))
1486 global_settings.rec_mic_gain--;
1488 else
1489 #endif /* MIC */
1491 if(global_settings.rec_left_gain >
1492 sound_min(SOUND_LEFT_GAIN))
1493 global_settings.rec_left_gain--;
1494 if(global_settings.rec_right_gain >
1495 sound_min(SOUND_RIGHT_GAIN))
1496 global_settings.rec_right_gain--;
1498 break;
1499 case ITEM_GAIN_L:
1500 if(global_settings.rec_left_gain >
1501 sound_min(SOUND_LEFT_GAIN))
1502 global_settings.rec_left_gain--;
1503 break;
1504 case ITEM_GAIN_R:
1505 if(global_settings.rec_right_gain >
1506 sound_min(SOUND_RIGHT_GAIN))
1507 global_settings.rec_right_gain--;
1508 break;
1509 #ifdef HAVE_AGC
1510 case ITEM_AGC_MODE:
1511 agc_preset = MAX(agc_preset - 1, 0);
1512 agc_enable = (agc_preset != 0);
1513 #ifdef HAVE_MIC_REC
1514 if (global_settings.rec_source == AUDIO_SRC_MIC) {
1515 global_settings.rec_agc_preset_mic = agc_preset;
1516 agc_maxgain = global_settings.rec_agc_maxgain_mic;
1517 } else
1518 #endif /* MIC */
1520 global_settings.rec_agc_preset_line = agc_preset;
1521 agc_maxgain = global_settings.rec_agc_maxgain_line;
1523 break;
1524 case ITEM_AGC_MAXDB:
1525 #ifdef HAVE_MIC_REC
1526 if (global_settings.rec_source == AUDIO_SRC_MIC)
1528 agc_maxgain = MAX(agc_maxgain - 1,
1529 sound_min(SOUND_MIC_GAIN));
1530 global_settings.rec_agc_maxgain_mic = agc_maxgain;
1531 } else
1532 #endif /* MIC */
1534 agc_maxgain = MAX(agc_maxgain - 1,
1535 sound_min(SOUND_LEFT_GAIN));
1536 global_settings.rec_agc_maxgain_line = agc_maxgain;
1538 break;
1539 #endif /* HAVE_AGC */
1541 set_gain();
1542 update_countdown = 0; /* Update immediately */
1543 break;
1544 case ACTION_STD_CANCEL:
1545 /* turn off the trigger */
1546 peak_meter_trigger(false);
1547 peak_meter_set_trigger_listener(NULL);
1549 if(audio_stat & AUDIO_STATUS_RECORD)
1551 rec_command(RECORDING_CMD_STOP);
1553 else
1555 #if CONFIG_CODEC != SWCODEC
1556 peak_meter_playback(true);
1557 peak_meter_enable(false);
1558 #endif
1559 done = 1;
1561 update_countdown = 0; /* Update immediately */
1562 break;
1563 #ifdef HAVE_REMOTE_LCD
1564 case ACTION_REC_LCD:
1565 /* this feature exists for some h1x0/h3x0 targets that suffer
1566 from noise caused by remote LCD updates
1567 NOTE 1: this will leave the list on the remote
1568 NOTE 2: to be replaced by a global LCD_off() routine */
1569 if(remote_display_on)
1571 /* switch to single screen, leave message on remote */
1572 screen_update = 1;
1573 screens[1].clear_viewport();
1574 screens[1].puts(0, 0, str(LANG_REMOTE_LCD_OFF));
1575 screens[1].puts(0, 1, str(LANG_REMOTE_LCD_ON));
1576 screens[1].update_viewport();
1578 else
1580 /* remote switched on again */
1581 update_list = true;
1582 screen_update = NB_SCREENS;
1584 remote_display_on = !remote_display_on; /* toggle */
1585 update_countdown = 0; /* Update immediately */
1586 break;
1587 #endif
1588 case ACTION_REC_PAUSE:
1589 case ACTION_REC_NEWFILE:
1590 /* Only act if the mpeg is stopped */
1591 if(!(audio_stat & AUDIO_STATUS_RECORD))
1593 /* is this manual or triggered recording? */
1594 if ((global_settings.rec_trigger_mode == TRIG_MODE_OFF) ||
1595 (peak_meter_trigger_status() != TRIG_OFF))
1597 /* manual recording */
1598 rec_status |= RCSTAT_HAVE_RECORDED;
1599 rec_command(RECORDING_CMD_START);
1600 last_seconds = 0;
1601 if (global_settings.talk_menu)
1603 /* no voice possible here, but a beep */
1604 audio_beep(HZ/2); /* longer beep on start */
1607 /* this is triggered recording */
1608 else
1610 /* we don't start recording now, but enable the
1611 trigger and let the callback function
1612 trigger_listener control when the recording starts */
1613 peak_meter_trigger(true);
1614 peak_meter_set_trigger_listener(&trigger_listener);
1617 else
1619 /*if new file button pressed, start new file */
1620 if (button == ACTION_REC_NEWFILE)
1622 rec_command(RECORDING_CMD_START_NEWFILE);
1623 last_seconds = 0;
1625 else
1626 /* if pause button pressed, pause or resume */
1628 if(audio_stat & AUDIO_STATUS_PAUSE)
1630 rec_command(RECORDING_CMD_RESUME);
1631 if (global_settings.talk_menu)
1633 /* no voice possible here, but a beep */
1634 audio_beep(HZ/4); /* short beep on resume */
1637 else
1639 rec_command(RECORDING_CMD_PAUSE);
1643 update_countdown = 0; /* Update immediately */
1644 break;
1645 case ACTION_STD_MENU:
1646 #if CONFIG_CODEC == SWCODEC
1647 if(!(audio_stat & AUDIO_STATUS_RECORD))
1648 #else
1649 if(audio_stat != AUDIO_STATUS_RECORD)
1650 #endif
1652 #if (CONFIG_LED == LED_REAL)
1653 /* led is restored at begin of loop / end of function */
1654 led(false);
1655 #endif
1656 if (recording_menu(no_source))
1658 done = 1;
1659 rec_status |= RCSTAT_BEEN_IN_USB_MODE;
1660 #ifdef HAVE_FMRADIO_REC
1661 radio_status = FMRADIO_OFF;
1662 #endif
1664 else
1666 done = -1;
1667 /* the init is now done at the beginning of the loop */
1670 break;
1672 #if CONFIG_KEYPAD == RECORDER_PAD
1673 case ACTION_REC_F2:
1674 if(audio_stat != AUDIO_STATUS_RECORD)
1676 #if (CONFIG_LED == LED_REAL)
1677 /* led is restored at begin of loop / end of function */
1678 led(false);
1679 #endif
1680 if (f2_rec_screen())
1682 rec_status |= RCSTAT_HAVE_RECORDED;
1683 done = true;
1685 else
1686 update_countdown = 0; /* Update immediately */
1688 break;
1690 case ACTION_REC_F3:
1691 if(audio_stat & AUDIO_STATUS_RECORD)
1693 rec_command(RECORDING_CMD_START_NEWFILE);
1694 last_seconds = 0;
1696 else
1698 #if (CONFIG_LED == LED_REAL)
1699 /* led is restored at begin of loop / end of function */
1700 led(false);
1701 #endif
1702 if (f3_rec_screen())
1704 rec_status |= RCSTAT_HAVE_RECORDED;
1705 done = true;
1707 else
1708 update_countdown = 0; /* Update immediately */
1710 break;
1711 #endif /* CONFIG_KEYPAD == RECORDER_PAD */
1713 case SYS_USB_CONNECTED:
1714 /* Only accept USB connection when not recording */
1715 if(!(audio_stat & AUDIO_STATUS_RECORD))
1717 FOR_NB_SCREENS(i)
1718 screens[i].set_viewport(NULL);
1719 default_event_handler(SYS_USB_CONNECTED);
1720 done = true;
1721 rec_status |= RCSTAT_BEEN_IN_USB_MODE;
1722 #ifdef HAVE_FMRADIO_REC
1723 radio_status = FMRADIO_OFF;
1724 #endif
1726 break;
1727 } /*switch(button)*/
1729 #ifdef HAVE_AGC
1730 peak_read = !peak_read;
1731 if (peak_read) { /* every 2nd run of loop */
1732 peak_time++;
1733 peak_valid = read_peak_levels(&peak_l, &peak_r, &balance);
1736 /* Handle AGC every 200ms when enabled and peak data is valid */
1737 if (peak_read && agc_enable && peak_valid)
1738 auto_gain_control(&peak_l, &peak_r, &balance);
1739 #endif
1741 seconds = audio_recorded_time() / HZ;
1743 /* start of vp_top drawing */
1744 if(update_countdown-- == 0 || seconds > last_seconds)
1746 unsigned int dseconds, dhours, dminutes;
1747 unsigned long num_recorded_bytes, dsize, dmb;
1749 FOR_NB_SCREENS(i)
1751 screens[i].set_viewport(&vp_top[i]);
1752 screens[i].clear_viewport();
1754 update_countdown = 5;
1755 last_seconds = seconds;
1757 dseconds = rec_timesplit_seconds();
1758 dsize = rec_sizesplit_bytes();
1759 num_recorded_bytes = audio_num_recorded_bytes();
1761 #if CONFIG_CODEC == SWCODEC
1762 if ((audio_stat & AUDIO_STATUS_WARNING)
1763 && (warning_counter++ % WARNING_PERIOD) < WARNING_PERIOD/2)
1765 /* Switch back and forth displaying warning on first available
1766 line to ensure visibility - the motion should also help
1767 draw attention */
1768 /* Don't use language string unless agreed upon to make this
1769 method permanent - could do something in the statusbar */
1770 snprintf(buf, sizeof(buf), "Warning: %08lX",
1771 pcm_rec_get_warnings());
1773 else
1774 #endif /* CONFIG_CODEC == SWCODEC */
1775 if ((global_settings.rec_sizesplit) &&
1776 (global_settings.rec_split_method))
1778 dmb = dsize/1024/1024;
1779 snprintf(buf, sizeof(buf), "%s %luMB",
1780 str(LANG_SPLIT_SIZE), dmb);
1782 else
1784 hours = seconds / 3600;
1785 minutes = (seconds - (hours * 3600)) / 60;
1786 snprintf(buf, sizeof(buf), "%s %02d:%02d:%02d",
1787 str(LANG_RECORDING_TIME),
1788 hours, minutes, seconds%60);
1791 FOR_NB_ACTIVE_SCREENS(i)
1792 screens[i].puts(0, 0, buf);
1794 if(audio_stat & AUDIO_STATUS_PRERECORD)
1796 snprintf(buf, sizeof(buf), "%s...",
1797 str(LANG_RECORD_PRERECORD));
1799 else
1801 /* Display the split interval if the record timesplit
1802 is active */
1803 if ((global_settings.rec_timesplit) &&
1804 !(global_settings.rec_split_method))
1806 /* Display the record timesplit interval rather
1807 than the file size if the record timer is active */
1808 dhours = dseconds / 3600;
1809 dminutes = (dseconds - (dhours * 3600)) / 60;
1810 snprintf(buf, sizeof(buf), "%s %02d:%02d",
1811 str(LANG_RECORDING_TIMESPLIT_REC),
1812 dhours, dminutes);
1814 else
1816 output_dyn_value(buf2, sizeof buf2,
1817 num_recorded_bytes,
1818 byte_units, true);
1819 snprintf(buf, sizeof(buf), "%s %s",
1820 str(LANG_RECORDING_SIZE), buf2);
1824 FOR_NB_ACTIVE_SCREENS(i)
1825 screens[i].puts(0, 1, buf);
1827 /* We will do file splitting regardless, either at the end of
1828 a split interval, or when the filesize approaches the 2GB
1829 FAT file size (compatibility) limit. */
1830 if ((audio_stat && !(global_settings.rec_split_method)
1831 && global_settings.rec_timesplit && (seconds >= dseconds))
1832 || (audio_stat && global_settings.rec_split_method
1833 && global_settings.rec_sizesplit
1834 && (num_recorded_bytes >= dsize))
1835 || (num_recorded_bytes >= MAX_FILE_SIZE))
1837 if (!(global_settings.rec_split_type)
1838 || (num_recorded_bytes >= MAX_FILE_SIZE))
1840 rec_command(RECORDING_CMD_START_NEWFILE);
1841 last_seconds = 0;
1843 else
1845 peak_meter_trigger(false);
1846 peak_meter_set_trigger_listener(NULL);
1847 if( global_settings.rec_split_type == 1)
1848 rec_command(RECORDING_CMD_STOP);
1849 else
1850 rec_command(RECORDING_CMD_STOP_SHUTDOWN);
1852 update_countdown = 0;
1855 /* draw the clipcounter just in front of the peakmeter */
1856 if(global_settings.peak_meter_clipcounter)
1858 int clipcount = pm_get_clipcount();
1859 FOR_NB_ACTIVE_SCREENS(i)
1861 if(!compact_view[i])
1863 screens[i].puts(0, 2, str(LANG_PM_CLIPCOUNT));
1864 screens[i].putsf(0, 3, "%4d", clipcount);
1866 else
1867 screens[i].putsf(0, 2, "%4d", clipcount);
1871 #ifdef HAVE_RECORDING_HISTOGRAM
1872 if(global_settings.rec_histogram_interval)
1874 if (peak_valid && !(hist_time % hist_time_interval) && hist_l)
1876 /* fill history buffer */
1877 history_l[history_pos] = hist_l * hist_size_h / 32767;
1878 history_r[history_pos] = hist_r * hist_size_h / 32767;
1879 history_pos = (history_pos + 1) % HIST_BUF_SIZE;
1880 history_l[history_pos] = history_r[history_pos] = 0;
1881 history_l[(history_pos + 1) % HIST_BUF_SIZE] = 0;
1882 history_r[(history_pos + 1) % HIST_BUF_SIZE] = 0;
1883 hist_l = 0;
1884 hist_r = 0;
1886 lcd_set_drawmode(DRMODE_SOLID);
1887 lcd_drawrect(0, hist_pos_y - 1,
1888 HIST_W + 2, hist_size_h + 1);
1889 lcd_drawrect(HIST_W + 6, hist_pos_y - 1,
1890 HIST_W + 2, hist_size_h + 1);
1891 lcd_set_drawmode(DRMODE_FG);
1893 j = history_pos;
1894 for (i = HIST_W-1; i >= 0; i--)
1896 j--;
1897 if(j<0)
1898 j = HIST_BUF_SIZE-1;
1899 if (history_l[j])
1901 if (history_l[j] == hist_size_h)
1902 lcd_set_foreground(LCD_HIST_OVER);
1903 #ifdef HAVE_LCD_COLOR
1904 else if (history_l[j] > hist_level_marks[1])
1905 lcd_set_foreground(LCD_HIST_HI);
1906 #endif
1907 else
1908 lcd_set_foreground(LCD_HIST_OK);
1909 lcd_vline(1 + i, HIST_Y-1, HIST_Y - history_l[j]);
1911 if (history_r[j])
1913 if (history_r[j] == hist_size_h)
1914 lcd_set_foreground(LCD_HIST_OVER);
1915 #ifdef HAVE_LCD_COLOR
1916 else if (history_r[j] > hist_level_marks[1])
1917 lcd_set_foreground(LCD_HIST_HI);
1918 #endif
1919 else
1920 lcd_set_foreground(LCD_HIST_OK);
1921 lcd_vline(HIST_W+7 + i, HIST_Y-1, HIST_Y - history_r[j]);
1924 lcd_set_foreground(
1925 #ifdef HAVE_LCD_COLOR
1926 global_settings.fg_color);
1927 #else
1928 LCD_DEFAULT_FG);
1929 #endif
1930 for (i = 0; i < 6; i++)
1931 lcd_hline(HIST_W + 3, HIST_W + 4,
1932 HIST_Y - hist_level_marks[i]);
1934 #endif /* HAVE_RECORDING_HISTOGRAM */
1936 #ifdef HAVE_AGC
1937 hist_time++;
1938 #endif
1940 /* draw the trigger status */
1941 if (peak_meter_trigger_status() != TRIG_OFF)
1943 peak_meter_draw_trig(pm_x, trig_ypos, trig_width,
1944 screen_update);
1945 FOR_NB_ACTIVE_SCREENS(i)
1946 screens[i].update_viewport_rect(pm_x[i], trig_ypos[i],
1947 trig_width[i] + 2, TRIG_HEIGHT);
1950 #ifdef HAVE_AGC
1951 #ifdef HAVE_MIC_REC
1952 if (global_settings.rec_source == AUDIO_SRC_MIC)
1954 if(agc_maxgain < (global_settings.rec_mic_gain))
1955 change_recording_gain(false, true, true);
1957 else
1958 #endif /* MIC */
1960 if(agc_maxgain < (global_settings.rec_left_gain))
1961 change_recording_gain(false, true, false);
1962 if(agc_maxgain < (global_settings.rec_right_gain))
1963 change_recording_gain(false, false, true);
1965 #endif /* HAVE_AGC */
1967 #if CONFIG_CODEC == SWCODEC
1968 #ifdef HAVE_SPDIF_REC
1969 if((global_settings.rec_source == AUDIO_SRC_SPDIF) &&
1970 (prev_sample_rate != pcm_rec_sample_rate()))
1972 /* spdif samplerate changed */
1973 prev_sample_rate = pcm_rec_sample_rate();
1974 update_list = true;
1976 #endif
1977 #endif
1979 if(update_list)
1981 /* update_list is set whenever content changes */
1982 update_list = false;
1983 gui_synclist_draw(&lists);
1986 /* draw peakmeter again (check if this can be removed) */
1987 FOR_NB_ACTIVE_SCREENS(i)
1989 screens[i].set_viewport(&vp_top[i]);
1990 peak_meter_screen(&screens[i], pm_x[i], pm_y[i], pm_h[i]);
1991 screens[i].update();
1993 } /* display update every second */
1995 if(audio_stat & AUDIO_STATUS_ERROR)
1997 done = true;
1999 } /* end while(!done) */
2001 audio_stat = audio_status();
2002 if (audio_stat & AUDIO_STATUS_ERROR)
2004 splash(0, str(LANG_DISK_FULL));
2006 FOR_NB_SCREENS(i)
2007 screens[i].update();
2009 #if CONFIG_CODEC == SWCODEC
2010 /* stop recording - some players like H10 freeze otherwise
2011 TO DO: find out why it freezes and fix properly */
2012 rec_command(RECORDING_CMD_STOP);
2013 audio_close_recording();
2014 #endif
2016 audio_error_clear();
2018 while(1)
2020 if (action_userabort(TIMEOUT_NOBLOCK))
2021 break;
2025 rec_abort:
2027 #if CONFIG_CODEC == SWCODEC
2028 rec_command(RECORDING_CMD_STOP);
2029 audio_close_recording();
2031 #ifdef HAVE_FMRADIO_REC
2032 if (radio_status != FMRADIO_OFF)
2033 /* Restore radio playback - radio_status should be unchanged if started
2034 through fm radio screen (barring usb connect) */
2035 rec_set_source(AUDIO_SRC_FMRADIO, (radio_status & FMRADIO_PAUSED) ?
2036 SRCF_FMRADIO_PAUSED : SRCF_FMRADIO_PLAYING);
2037 else
2038 #endif
2039 /* Go back to playback mode */
2040 rec_set_source(AUDIO_SRC_PLAYBACK, SRCF_PLAYBACK);
2042 /* restore talking */
2043 talk_disable(false);
2044 #else /* !SWCODEC */
2045 audio_init_playback();
2046 #endif /* CONFIG_CODEC == SWCODEC */
2048 #ifdef HAVE_SPEAKER
2049 /* Re-enable speaker */
2050 audiohw_enable_speaker(global_settings.speaker_enabled);
2051 #endif
2053 /* make sure the trigger is really turned off */
2054 peak_meter_trigger(false);
2055 peak_meter_set_trigger_listener(NULL);
2057 rec_status &= ~RCSTAT_IN_RECSCREEN;
2058 sound_settings_apply();
2060 FOR_NB_SCREENS(i)
2061 screens[i].setfont(FONT_UI);
2063 /* if the directory was created or recording happened, make sure the
2064 browser is updated */
2065 if (rec_status & (RCSTAT_CREATED_DIRECTORY | RCSTAT_HAVE_RECORDED))
2066 reload_directory();
2068 #if (CONFIG_STORAGE & STORAGE_ATA) && (CONFIG_LED == LED_REAL) \
2069 && !defined(SIMULATOR)
2070 ata_set_led_enabled(true);
2071 #endif
2073 settings_save();
2075 return (rec_status & RCSTAT_BEEN_IN_USB_MODE) != 0;
2076 } /* recording_screen */
2078 #if CONFIG_KEYPAD == RECORDER_PAD
2079 static bool f2_rec_screen(void)
2081 static const char* const freq_str[6] =
2083 "44.1kHz",
2084 "48kHz",
2085 "32kHz",
2086 "22.05kHz",
2087 "24kHz",
2088 "16kHz"
2091 bool exit = false;
2092 bool used = false;
2093 int w, h, i;
2094 char buf[32];
2095 int button;
2096 struct audio_recording_options rec_options;
2098 FOR_NB_SCREENS(i)
2100 screens[i].set_viewport(NULL);
2101 screens[i].setfont(FONT_SYSFIXED);
2102 screens[i].getstringsize("A",&w,&h);
2105 while (!exit) {
2106 const char* ptr;
2108 FOR_NB_SCREENS(i)
2110 screens[i].clear_display();
2112 /* Recording quality */
2113 screens[i].putsxy(0, LCD_HEIGHT/2 - h*2,
2114 str(LANG_SYSFONT_RECORDING_QUALITY));
2117 snprintf(buf, sizeof(buf), "%d", global_settings.rec_quality);
2118 FOR_NB_SCREENS(i)
2120 screens[i].putsxy(0, LCD_HEIGHT/2-h, buf);
2121 screens[i].mono_bitmap(bitmap_icons_7x8[Icon_FastBackward],
2122 LCD_WIDTH/2 - 16, LCD_HEIGHT/2 - 4, 7, 8);
2125 /* Frequency */
2126 snprintf(buf, sizeof buf, "%s:", str(LANG_SYSFONT_RECORDING_FREQUENCY));
2127 ptr = freq_str[global_settings.rec_frequency];
2128 FOR_NB_SCREENS(i)
2130 screens[i].getstringsize(buf,&w,&h);
2131 screens[i].putsxy((LCD_WIDTH-w)/2, LCD_HEIGHT - h*2, buf);
2132 screens[i].getstringsize(ptr, &w, &h);
2133 screens[i].putsxy((LCD_WIDTH-w)/2, LCD_HEIGHT - h, ptr);
2134 screens[i].mono_bitmap(bitmap_icons_7x8[Icon_DownArrow],
2135 LCD_WIDTH/2 - 3, LCD_HEIGHT - h*3, 7, 8);
2138 /* Channel mode */
2139 switch ( global_settings.rec_channels ) {
2140 case 0:
2141 ptr = str(LANG_SYSFONT_CHANNEL_STEREO);
2142 break;
2144 case 1:
2145 ptr = str(LANG_SYSFONT_CHANNEL_MONO);
2146 break;
2149 FOR_NB_SCREENS(i)
2151 screens[i].getstringsize(str(LANG_SYSFONT_CHANNELS), &w, &h);
2152 screens[i].putsxy(LCD_WIDTH - w, LCD_HEIGHT/2 - h*2,
2153 str(LANG_SYSFONT_CHANNELS));
2154 screens[i].getstringsize(str(LANG_SYSFONT_MODE), &w, &h);
2155 screens[i].putsxy(LCD_WIDTH - w, LCD_HEIGHT/2 - h,
2156 str(LANG_SYSFONT_MODE));
2157 screens[i].getstringsize(ptr, &w, &h);
2158 screens[i].putsxy(LCD_WIDTH - w, LCD_HEIGHT/2, ptr);
2159 screens[i].mono_bitmap(bitmap_icons_7x8[Icon_FastForward],
2160 LCD_WIDTH/2 + 8, LCD_HEIGHT/2 - 4, 7, 8);
2162 screens[i].update();
2165 button = button_get(true);
2166 switch (button) {
2167 case BUTTON_LEFT:
2168 case BUTTON_F2 | BUTTON_LEFT:
2169 global_settings.rec_quality++;
2170 if(global_settings.rec_quality > 7)
2171 global_settings.rec_quality = 0;
2172 used = true;
2173 break;
2175 case BUTTON_DOWN:
2176 case BUTTON_F2 | BUTTON_DOWN:
2177 global_settings.rec_frequency++;
2178 if(global_settings.rec_frequency > 5)
2179 global_settings.rec_frequency = 0;
2180 used = true;
2181 break;
2183 case BUTTON_RIGHT:
2184 case BUTTON_F2 | BUTTON_RIGHT:
2185 global_settings.rec_channels++;
2186 if(global_settings.rec_channels > 1)
2187 global_settings.rec_channels = 0;
2188 used = true;
2189 break;
2191 case BUTTON_F2 | BUTTON_REL:
2192 if ( used )
2193 exit = true;
2194 used = true;
2195 break;
2197 case BUTTON_F2 | BUTTON_REPEAT:
2198 used = true;
2199 break;
2201 default:
2202 if(default_event_handler(button) == SYS_USB_CONNECTED)
2203 return true;
2204 break;
2208 rec_init_recording_options(&rec_options);
2209 rec_set_recording_options(&rec_options);
2211 set_gain();
2213 settings_save();
2214 FOR_NB_SCREENS(i)
2215 screens[i].setfont(FONT_UI);
2217 return false;
2220 static bool f3_rec_screen(void)
2222 bool exit = false;
2223 bool used = false;
2224 int w, h, i;
2225 int button;
2226 const char *src_str[] =
2228 str(LANG_SYSFONT_RECORDING_SRC_MIC),
2229 str(LANG_SYSFONT_LINE_IN),
2230 str(LANG_SYSFONT_RECORDING_SRC_DIGITAL)
2232 struct audio_recording_options rec_options;
2234 FOR_NB_SCREENS(i)
2236 screens[i].set_viewport(NULL);
2237 screens[i].setfont(FONT_SYSFIXED);
2238 screens[i].getstringsize("A",&w,&h);
2241 while (!exit) {
2242 const char* ptr = src_str[global_settings.rec_source];
2243 FOR_NB_SCREENS(i)
2245 screens[i].clear_display();
2247 /* Recording source */
2248 screens[i].putsxy(0, LCD_HEIGHT/2 - h*2,
2249 str(LANG_SYSFONT_RECORDING_SOURCE));
2251 screens[i].getstringsize(ptr, &w, &h);
2252 screens[i].putsxy(0, LCD_HEIGHT/2-h, ptr);
2253 screens[i].mono_bitmap(bitmap_icons_7x8[Icon_FastBackward],
2254 LCD_WIDTH/2 - 16, LCD_HEIGHT/2 - 4, 7, 8);
2257 /* trigger setup */
2258 ptr = str(LANG_SYSFONT_RECORD_TRIGGER);
2259 FOR_NB_SCREENS(i)
2261 screens[i].getstringsize(ptr,&w,&h);
2262 screens[i].putsxy((LCD_WIDTH-w)/2, LCD_HEIGHT - h*2, ptr);
2263 screens[i].mono_bitmap(bitmap_icons_7x8[Icon_DownArrow],
2264 LCD_WIDTH/2 - 3, LCD_HEIGHT - h*3, 7, 8);
2266 screens[i].update();
2269 button = button_get(true);
2270 switch (button) {
2271 case BUTTON_DOWN:
2272 case BUTTON_F3 | BUTTON_DOWN:
2273 #ifndef SIMULATOR
2274 rectrigger();
2275 settings_apply_trigger();
2276 #endif
2277 exit = true;
2278 break;
2280 case BUTTON_LEFT:
2281 case BUTTON_F3 | BUTTON_LEFT:
2282 global_settings.rec_source++;
2283 if(global_settings.rec_source > AUDIO_SRC_MAX)
2284 global_settings.rec_source = 0;
2285 used = true;
2286 break;
2288 case BUTTON_F3 | BUTTON_REL:
2289 if ( used )
2290 exit = true;
2291 used = true;
2292 break;
2294 case BUTTON_F3 | BUTTON_REPEAT:
2295 used = true;
2296 break;
2298 default:
2299 if(default_event_handler(button) == SYS_USB_CONNECTED)
2300 return true;
2301 break;
2305 rec_init_recording_options(&rec_options);
2306 rec_set_recording_options(&rec_options);
2308 set_gain();
2310 settings_save();
2311 FOR_NB_SCREENS(i)
2312 screens[i].setfont(FONT_UI);
2314 return false;
2316 #endif /* CONFIG_KEYPAD == RECORDER_PAD */
2318 #if CONFIG_CODEC == SWCODEC
2319 void audio_beep(int duration)
2321 /* dummy */
2322 (void)duration;
2325 #ifdef SIMULATOR
2326 /* stubs for recording sim */
2327 void audio_init_recording(unsigned int buffer_offset)
2329 buffer_offset = buffer_offset;
2332 void audio_close_recording(void)
2336 unsigned long pcm_rec_get_warnings(void)
2338 return 0;
2341 unsigned long pcm_rec_sample_rate(void)
2343 return 0;
2346 unsigned long audio_recorded_time(void)
2348 return 123;
2351 unsigned long audio_num_recorded_bytes(void)
2353 return 5 * 1024 * 1024;
2356 void rec_set_source(int source, unsigned flags)
2358 source = source;
2359 flags = flags;
2362 void audio_set_recording_options(struct audio_recording_options *options)
2364 options = options;
2367 void audio_set_recording_gain(int left, int right, int type)
2369 left = left;
2370 right = right;
2371 type = type;
2374 void audio_record(const char *filename)
2376 filename = filename;
2379 void audio_new_file(const char *filename)
2381 filename = filename;
2384 void audio_stop_recording(void)
2388 void audio_pause_recording(void)
2392 void audio_resume_recording(void)
2396 #endif /* #ifdef SIMULATOR */
2397 #endif /* #ifdef CONFIG_CODEC == SWCODEC */
2399 #endif /* HAVE_RECORDING */