fix cutoff of f2/f3_rec_screen in the recording screen.
[kugel-rb.git] / apps / recorder / recording.c
blobbcb9169c574301ca539bce823b641f0ca5c8c2f2
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 #if defined(HAVE_SPDIF_IN) || defined(HAVE_SPDIF_OUT)
38 #include "spdif.h"
39 #endif
40 #endif /* CONFIG_CODEC == SWCODEC */
41 #include "pcm_record.h"
42 #include "recording.h"
43 #include "mp3_playback.h"
44 #include "mas.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 "tree.h"
60 #include "string.h"
61 #include "dir.h"
62 #include "errno.h"
63 #include "talk.h"
64 #include "sound.h"
65 #include "storage.h"
66 #if (CONFIG_STORAGE & STORAGE_ATA) && (CONFIG_LED == LED_REAL) \
67 && !defined(SIMULATOR)
68 #include "ata.h"
69 #endif
70 #include "splash.h"
71 #include "screen_access.h"
72 #include "action.h"
73 #include "radio.h"
74 #include "viewport.h"
75 #include "list.h"
76 #include "general.h"
77 #include "appevents.h"
79 #ifdef HAVE_RECORDING
80 /* This array holds the record timer interval lengths, in seconds */
81 static const unsigned long rec_timer_seconds[] =
83 0, /* 0 means OFF */
84 5*60, /* 00:05 */
85 10*60, /* 00:10 */
86 15*60, /* 00:15 */
87 30*60, /* 00:30 */
88 60*60, /* 01:00 */
89 74*60, /* 01:14 */
90 80*60, /* 01:20 */
91 2*60*60, /* 02:00 */
92 4*60*60, /* 04:00 */
93 6*60*60, /* 06:00 */
94 8*60*60, /* 08:00 */
95 10L*60*60, /* 10:00 */
96 12L*60*60, /* 12:00 */
97 18L*60*60, /* 18:00 */
98 24L*60*60 /* 24:00 */
101 static unsigned int rec_timesplit_seconds(void)
103 return rec_timer_seconds[global_settings.rec_timesplit];
106 /* This array holds the record size interval lengths, in bytes */
107 static const unsigned long rec_size_bytes[] =
109 0, /* 0 means OFF */
110 5*1024*1024, /* 5MB */
111 10*1024*1024, /* 10MB */
112 15*1024*1024, /* 15MB */
113 32*1024*1024, /* 32MB */
114 64*1024*1024, /* 64MB */
115 75*1024*1024, /* 75MB */
116 100*1024*1024, /* 100MB */
117 128*1024*1024, /* 128MB */
118 256*1024*1024, /* 256MB */
119 512*1024*1024, /* 512MB */
120 650*1024*1024, /* 650MB */
121 700*1024*1024, /* 700MB */
122 1024*1024*1024, /* 1GB */
123 1536*1024*1024, /* 1.5GB */
124 1792*1024*1024, /* 1.75GB */
127 static unsigned long rec_sizesplit_bytes(void)
129 return rec_size_bytes[global_settings.rec_sizesplit];
132 void settings_apply_trigger(void)
134 int start_thres, stop_thres;
135 if (global_settings.peak_meter_dbfs)
137 start_thres = global_settings.rec_start_thres_db - 1;
138 stop_thres = global_settings.rec_stop_thres_db - 1;
140 else
142 start_thres = global_settings.rec_start_thres_linear;
143 stop_thres = global_settings.rec_stop_thres_linear;
146 peak_meter_define_trigger(
147 start_thres,
148 global_settings.rec_start_duration*HZ,
149 MIN(global_settings.rec_start_duration*HZ / 2, 2*HZ),
150 stop_thres,
151 global_settings.rec_stop_postrec*HZ,
152 global_settings.rec_stop_gap*HZ
155 /* recording screen status flags */
156 enum rec_status_flags
158 RCSTAT_IN_RECSCREEN = 0x00000001,
159 RCSTAT_BEEN_IN_USB_MODE = 0x00000002,
160 RCSTAT_CREATED_DIRECTORY = 0x00000004,
161 RCSTAT_HAVE_RECORDED = 0x00000008,
164 static int rec_status = 0;
166 bool in_recording_screen(void)
168 return (rec_status & RCSTAT_IN_RECSCREEN) != 0;
171 #if CONFIG_KEYPAD == RECORDER_PAD
172 static bool f2_rec_screen(void);
173 static bool f3_rec_screen(void);
174 #endif
176 #define MAX_FILE_SIZE 0x7F800000 /* 2 GB - 4 MB */
178 #ifndef HAVE_REMOTE_LCD
179 static const int screen_update = NB_SCREENS;
180 #else
181 static int screen_update = NB_SCREENS;
182 static bool remote_display_on = true;
183 #endif
185 /* as we have the ability to disable the remote, we need an alternative loop */
186 #define FOR_NB_ACTIVE_SCREENS(i) for(i = 0; i < screen_update; i++)
188 static bool update_list = false; /* (GIU) list needs updating */
190 /** File name creation **/
191 #if CONFIG_RTC == 0
192 /* current file number to assist in creating unique numbered filenames
193 without actually having to create the file on disk */
194 static int file_number = -1;
195 #endif /* CONFIG_RTC */
197 #if CONFIG_CODEC == SWCODEC
199 #define REC_FILE_ENDING(rec_format) \
200 (audio_formats[rec_format_afmt[rec_format]].ext_list)
202 #else /* CONFIG_CODEC != SWCODEC */
204 /* default record file extension for HWCODEC */
205 #define REC_FILE_ENDING(rec_format) \
206 (audio_formats[AFMT_MPA_L3].ext_list)
208 #endif /* CONFIG_CODEC == SWCODEC */
210 /* path for current file */
211 static char path_buffer[MAX_PATH];
213 /** Automatic Gain Control (AGC) **/
214 #ifdef HAVE_AGC
215 /* Timing counters:
216 * peak_time is incremented every 0.2s, every 2nd run of record screen loop.
217 * hist_time is incremented every 0.5s, display update.
218 * peak_time is the counter of the peak hold read and agc process,
219 * overflow every 13 years 8-)
221 static long peak_time = 0;
223 static short peak_valid_mem[4];
224 #define BAL_MEM_SIZE 24
225 static short balance_mem[BAL_MEM_SIZE];
227 /* Automatic Gain Control */
228 #define AGC_MODE_SIZE 5
229 #define AGC_SAFETY_MODE 0
231 static const char* agc_preset_str[] =
232 { "Off", "S", "L", "D", "M", "V" };
233 /* "Off",
234 "Safety (clip)",
235 "Live (slow)",
236 "DJ-Set (slow)",
237 "Medium",
238 "Voice (fast)" */
239 #define AGC_CLIP 32766
240 #define AGC_PEAK 29883 /* fast gain reduction threshold -0.8dB */
241 #define AGC_HIGH 27254 /* accelerated gain reduction threshold -1.6dB */
242 #define AGC_IMG 823 /* threshold for balance control -32dB */
243 /* autogain high level thresholds (-3dB, -7dB, -4dB, -5dB, -5dB) */
244 static const short agc_th_hi[AGC_MODE_SIZE] =
245 { 23197, 14637, 21156, 18428, 18426 };
246 /* autogain low level thresholds (-14dB, -11dB, -6dB, -7dB, -8dB) */
247 static const short agc_th_lo[AGC_MODE_SIZE] =
248 { 6538, 9235, 16422, 14636, 13045 };
249 /* autogain threshold times [1/5s] or [200ms] */
250 static const short agc_tdrop[AGC_MODE_SIZE] =
251 { 900, 225, 150, 60, 8 };
252 static const short agc_trise[AGC_MODE_SIZE] =
253 { 9000, 750, 400, 150, 20 };
254 static const short agc_tbal[AGC_MODE_SIZE] =
255 { 4500, 500, 300, 100, 15 };
256 /* AGC operation */
257 static bool agc_enable = true;
258 static short agc_preset;
259 /* AGC levels */
260 static int agc_left = 0;
261 static int agc_right = 0;
262 /* AGC time since high target volume was exceeded */
263 static short agc_droptime = 0;
264 /* AGC time since volume fallen below low target */
265 static short agc_risetime = 0;
266 /* AGC balance time exceeding +/- 0.7dB */
267 static short agc_baltime = 0;
268 /* AGC maximum gain */
269 static short agc_maxgain;
270 #endif /* HAVE_AGC */
271 #if defined(HAVE_AGC) || defined(HAVE_RECORDING_HISTOGRAM)
272 static long hist_time = 0;
273 #endif /* HAVE_AGC or HAVE_RECORDING_HISTOGRAM */
274 /* Histogram data */
275 /* TO DO: move some of this stuff inside the recording function? */
276 #ifdef HAVE_RECORDING_HISTOGRAM
277 static int hist_l = 0;
278 static int hist_r = 0;
279 #define HIST_Y (hist_pos_y+hist_size_h-1)
280 #define HIST_W (LCD_WIDTH / 2 - 4)
281 #if LCD_DEPTH > 1
282 #ifdef HAVE_LCD_COLOR
283 #define LCD_BAL_L LCD_RGBPACK(0, 0, 255)
284 #define LCD_BAL_R LCD_RGBPACK(204, 0, 0)
285 #define LCD_HIST_OVER LCD_RGBPACK(204, 0, 0)
286 #define LCD_HIST_HI LCD_RGBPACK(255, 204, 0)
287 #define LCD_HIST_OK LCD_RGBPACK(51, 153, 0)
288 #else /* HAVE_LCD_COLOR */
289 #define LCD_BATT_OK LCD_BLACK
290 #define LCD_BATT_LO LCD_DARKGRAY
291 #define LCD_DISK_OK LCD_BLACK
292 #define LCD_DISK_LO LCD_DARKGRAY
293 #define LCD_HIST_OVER LCD_BLACK
294 #define LCD_HIST_OK LCD_DARKGRAY
295 #define LCD_BAL LCD_DARKGRAY
296 #endif /* HAVE_LCD_COLOR */
297 #else /* LCD_DEPTH > 1 */
298 #define LCD_HIST_OVER LCD_DEFAULT_FG
299 #define LCD_HIST_OK LCD_DEFAULT_FG
300 #define LCD_BAL LCD_DEFAULT_FG
301 #endif /* LCD_DEPTH > 1 */
302 #endif /* HAVE_RECORDING_HISTOGRAM */
304 static void set_gain(void)
306 #ifdef HAVE_MIC_REC
307 if(global_settings.rec_source == AUDIO_SRC_MIC)
309 audio_set_recording_gain(global_settings.rec_mic_gain,
310 0, AUDIO_GAIN_MIC);
312 else
313 #endif /* MIC */
315 /* AUDIO_SRC_LINEIN, AUDIO_SRC_FMRADIO, AUDIO_SRC_SPDIF */
316 audio_set_recording_gain(global_settings.rec_left_gain,
317 global_settings.rec_right_gain,
318 AUDIO_GAIN_LINEIN);
320 /* reset the clipping indicators */
321 peak_meter_set_clip_hold(global_settings.peak_meter_clip_hold);
322 update_list = true;
325 #ifdef HAVE_AGC
326 /* Read peak meter values & calculate balance.
327 * Returns validity of peak values.
328 * Used for automatic gain control and history diagram.
330 static bool read_peak_levels(int *peak_l, int *peak_r, int *balance)
332 peak_meter_get_peakhold(peak_l, peak_r);
333 peak_valid_mem[peak_time % 3] = *peak_l;
334 if (((peak_valid_mem[0] == peak_valid_mem[1]) &&
335 (peak_valid_mem[1] == peak_valid_mem[2])) &&
336 ((*peak_l < 32767) || storage_disk_is_active()))
337 return false;
339 if (*peak_r > *peak_l)
340 balance_mem[peak_time % BAL_MEM_SIZE] = (*peak_l ?
341 MIN((10000 * *peak_r) / *peak_l - 10000, 15118) : 15118);
342 else
343 balance_mem[peak_time % BAL_MEM_SIZE] = (*peak_r ?
344 MAX(10000 - (10000 * *peak_l) / *peak_r, -15118) : -15118);
345 *balance = 0;
346 int i;
347 for (i = 0; i < BAL_MEM_SIZE; i++)
348 *balance += balance_mem[i];
349 *balance = *balance / BAL_MEM_SIZE;
351 #ifdef HAVE_RECORDING_HISTOGRAM
352 if (*peak_l > hist_l)
353 hist_l = *peak_l;
354 if (*peak_r > hist_r)
355 hist_r = *peak_r;
356 #endif
358 return true;
361 /* AGC helper function to check if maximum gain is reached */
362 static bool agc_gain_is_max(bool left, bool right)
364 /* range -128...+108 [0.5dB] */
365 short gain_current_l;
366 short gain_current_r;
368 if (agc_preset == 0)
369 return false;
371 switch (global_settings.rec_source)
373 #if defined(HAVE_LINE_REC) || defined(HAVE_FMRADIO_REC)
374 HAVE_LINE_REC_(case AUDIO_SRC_LINEIN:)
375 HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO:)
376 gain_current_l = global_settings.rec_left_gain;
377 gain_current_r = global_settings.rec_right_gain;
378 break;
379 #endif /* LINE, FMRADIO */
380 #if defined(HAVE_MIC_REC)
381 case AUDIO_SRC_MIC:
382 default:
383 gain_current_l = global_settings.rec_mic_gain;
384 gain_current_r = global_settings.rec_mic_gain;
385 #endif /* MIC */
388 return ((left && (gain_current_l >= agc_maxgain)) ||
389 (right && (gain_current_r >= agc_maxgain)));
392 static void change_recording_gain(bool increment, bool left, bool right)
394 int factor = (increment ? 1 : -1);
396 switch (global_settings.rec_source)
398 #if defined(HAVE_LINE_REC) || defined(HAVE_FMRADIO_REC)
399 HAVE_LINE_REC_(case AUDIO_SRC_LINEIN:)
400 HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO:)
401 if (left) global_settings.rec_left_gain += factor;
402 if (right) global_settings.rec_right_gain += factor;
403 break;
404 #endif /* LINE, FMRADIO */
405 #if defined(HAVE_MIC_REC)
406 case AUDIO_SRC_MIC:
407 global_settings.rec_mic_gain += factor;
408 #endif
413 * Handle automatic gain control (AGC).
414 * Change recording gain if peak_x levels are above or below
415 * target volume for specified timeouts.
417 static void auto_gain_control(int *peak_l, int *peak_r, int *balance)
419 int agc_mono;
420 short agc_mode;
421 bool increment;
423 if (*peak_l > agc_left)
424 agc_left = *peak_l;
425 else
426 agc_left -= (agc_left - *peak_l + 3) >> 2;
427 if (*peak_r > agc_right)
428 agc_right = *peak_r;
429 else
430 agc_right -= (agc_right - *peak_r + 3) >> 2;
431 agc_mono = (agc_left + agc_right) / 2;
433 agc_mode = abs(agc_preset) - 1;
434 if (agc_mode < 0) {
435 agc_enable = false;
436 return;
439 if (agc_mode != AGC_SAFETY_MODE) {
440 /* Automatic balance control - only if not in safety mode */
441 if ((agc_left > AGC_IMG) && (agc_right > AGC_IMG))
443 if (*balance < -556)
445 if (*balance > -900)
446 agc_baltime -= !(peak_time % 4); /* 0.47 - 0.75dB */
447 else if (*balance > -4125)
448 agc_baltime--; /* 0.75 - 3.00dB */
449 else if (*balance > -7579)
450 agc_baltime -= 2; /* 3.00 - 4.90dB */
451 else
452 agc_baltime -= !(peak_time % 8); /* 4.90 - inf dB */
453 if (agc_baltime > 0)
454 agc_baltime -= (peak_time % 2);
456 else if (*balance > 556)
458 if (*balance < 900)
459 agc_baltime += !(peak_time % 4);
460 else if (*balance < 4125)
461 agc_baltime++;
462 else if (*balance < 7579)
463 agc_baltime += 2;
464 else
465 agc_baltime += !(peak_time % 8);
466 if (agc_baltime < 0)
467 agc_baltime += (peak_time % 2);
470 if ((*balance * agc_baltime) < 0)
472 if (*balance < 0)
473 agc_baltime -= peak_time % 2;
474 else
475 agc_baltime += peak_time % 2;
478 increment = ((agc_risetime / 2) > agc_droptime);
480 if (agc_baltime < -agc_tbal[agc_mode])
482 if (!increment || !agc_gain_is_max(!increment, increment)) {
483 change_recording_gain(increment, !increment, increment);
484 set_gain();
486 agc_baltime = 0;
488 else if (agc_baltime > +agc_tbal[agc_mode])
490 if (!increment || !agc_gain_is_max(increment, !increment)) {
491 change_recording_gain(increment, increment, !increment);
492 set_gain();
494 agc_baltime = 0;
497 else if (!(hist_time % 4))
499 if (agc_baltime < 0)
500 agc_baltime++;
501 else
502 agc_baltime--;
506 /* Automatic gain control */
507 if ((agc_left > agc_th_hi[agc_mode]) || (agc_right > agc_th_hi[agc_mode]))
509 if ((agc_left > AGC_CLIP) || (agc_right > AGC_CLIP))
510 agc_droptime += agc_tdrop[agc_mode] /
511 (global_settings.rec_agc_cliptime + 1);
512 if (agc_left > AGC_HIGH) {
513 agc_droptime++;
514 agc_risetime=0;
515 if (agc_left > AGC_PEAK)
516 agc_droptime += 2;
518 if (agc_right > AGC_HIGH) {
519 agc_droptime++;
520 agc_risetime=0;
521 if (agc_right > AGC_PEAK)
522 agc_droptime += 2;
524 if (agc_mono > agc_th_hi[agc_mode])
525 agc_droptime++;
526 else
527 agc_droptime += !(peak_time % 2);
529 if (agc_droptime >= agc_tdrop[agc_mode])
531 change_recording_gain(false, true, true);
532 agc_droptime = 0;
533 agc_risetime = 0;
534 set_gain();
536 agc_risetime = MAX(agc_risetime - 1, 0);
538 else if (agc_mono < agc_th_lo[agc_mode])
540 if (agc_mono < (agc_th_lo[agc_mode] / 8))
541 agc_risetime += !(peak_time % 5);
542 else if (agc_mono < (agc_th_lo[agc_mode] / 2))
543 agc_risetime += 2;
544 else
545 agc_risetime++;
547 if (agc_risetime >= agc_trise[agc_mode]) {
548 if ((agc_mode != AGC_SAFETY_MODE) &&
549 (!agc_gain_is_max(true, true))) {
550 change_recording_gain(true, true, true);
551 set_gain();
553 agc_risetime = 0;
554 agc_droptime = 0;
556 agc_droptime = MAX(agc_droptime - 1, 0);
558 else if (!(peak_time % 6)) /* on target level every 1.2 sec */
560 agc_risetime = MAX(agc_risetime - 1, 0);
561 agc_droptime = MAX(agc_droptime - 1, 0);
564 #endif /* HAVE_AGC */
566 static const char* const fmtstr[] =
568 "%c%d %s", /* no decimals */
569 "%c%d.%d %s ", /* 1 decimal */
570 "%c%d.%02d %s " /* 2 decimals */
573 static char *fmt_gain(int snd, int val, char *str, int len)
575 int i, d, numdec;
576 const char *unit;
577 char sign = ' ';
579 val = sound_val2phys(snd, val);
580 if(val < 0)
582 sign = '-';
583 val = -val;
585 numdec = sound_numdecimals(snd);
586 unit = sound_unit(snd);
588 if(numdec)
590 i = val / (10*numdec);
591 d = val % (10*numdec);
592 snprintf(str, len, fmtstr[numdec], sign, i, d, unit);
594 else
595 snprintf(str, len, fmtstr[numdec], sign, val, unit);
597 return str;
600 /* the list below must match enum audio_sources in audio.h */
601 static const char* const prestr[] =
603 HAVE_MIC_IN_([AUDIO_SRC_MIC] = "R_MIC_",)
604 HAVE_LINE_REC_([AUDIO_SRC_LINEIN] = "R_LINE_",)
605 HAVE_SPDIF_IN_([AUDIO_SRC_SPDIF] = "R_SPDIF_",)
606 HAVE_FMRADIO_REC_([AUDIO_SRC_FMRADIO] = "R_FM_",)
609 char *rec_create_filename(char *buffer)
611 char ext[16];
612 const char *pref = "R_";
614 /* Directory existence and writeablility should have already been
615 * verified - do not pass NULL pointers to pcmrec */
617 if((unsigned)global_settings.rec_source < AUDIO_NUM_SOURCES)
619 pref = prestr[global_settings.rec_source];
622 strcpy(buffer, global_settings.rec_directory);
624 snprintf(ext, sizeof(ext), ".%s",
625 REC_FILE_ENDING(global_settings.rec_format));
627 #if CONFIG_RTC == 0
628 return create_numbered_filename(buffer, buffer, pref, ext, 4,
629 &file_number);
630 #else
631 /* We'll wait at least up to the start of the next second so no duplicate
632 names are created */
633 return create_datetime_filename(buffer, buffer, pref, ext, true);
634 #endif
637 #if CONFIG_RTC == 0
638 /* Hit disk to get a starting filename for the type */
639 static void rec_init_filename(void)
641 file_number = -1;
642 rec_create_filename(path_buffer);
643 file_number--;
645 #endif
647 int rec_create_directory(void)
649 int rc = 0;
650 const char * const folder = global_settings.rec_directory;
652 if (strcmp(folder, "/") && !dir_exists(folder))
654 rc = mkdir(folder);
656 if(rc < 0)
658 while (action_userabort(HZ) == false)
660 splashf(0, "%s %s",
661 str(LANG_REC_DIR_NOT_WRITABLE),
662 str(LANG_OFF_ABORT));
665 else
667 rec_status |= RCSTAT_CREATED_DIRECTORY;
668 rc = 1;
672 return rc;
675 void rec_init_recording_options(struct audio_recording_options *options)
677 options->rec_source = global_settings.rec_source;
678 options->rec_frequency = global_settings.rec_frequency;
679 options->rec_channels = global_settings.rec_channels;
680 options->rec_prerecord_time = global_settings.rec_prerecord_time;
681 #if CONFIG_CODEC == SWCODEC
682 options->rec_mono_mode = global_settings.rec_mono_mode;
683 options->rec_source_flags = 0;
684 options->enc_config.rec_format = global_settings.rec_format;
685 global_to_encoder_config(&options->enc_config);
686 #else
687 options->rec_quality = global_settings.rec_quality;
688 options->rec_editable = global_settings.rec_editable;
689 #endif
692 #if CONFIG_CODEC == SWCODEC && !defined (SIMULATOR)
693 void rec_set_source(int source, unsigned flags)
695 /* Set audio input source, power up/down devices */
696 audio_set_input_source(source, flags);
698 /* Set peakmeters for recording or reset to playback */
699 peak_meter_playback((flags & SRCF_RECORDING) == 0);
700 peak_meter_enabled = true;
702 #endif /* CONFIG_CODEC == SWCODEC && !defined (SIMULATOR) */
704 void rec_set_recording_options(struct audio_recording_options *options)
706 #if CONFIG_CODEC != SWCODEC
707 if (global_settings.rec_prerecord_time)
709 talk_buffer_steal(); /* will use the mp3 buffer */
711 #else /* == SWCODEC */
712 rec_set_source(options->rec_source,
713 options->rec_source_flags | SRCF_RECORDING);
714 #endif /* CONFIG_CODEC != SWCODEC */
716 audio_set_recording_options(options);
719 void rec_command(enum recording_command cmd)
721 switch(cmd)
723 case RECORDING_CMD_STOP_SHUTDOWN:
724 pm_activate_clipcount(false);
725 audio_stop_recording();
726 #if CONFIG_CODEC == SWCODEC
727 audio_close_recording();
728 #endif
729 sys_poweroff();
730 break;
731 case RECORDING_CMD_STOP:
732 pm_activate_clipcount(false);
733 audio_stop_recording();
734 break;
735 case RECORDING_CMD_START:
736 /* steal mp3 buffer, create unique filename and start recording */
737 pm_reset_clipcount();
738 pm_activate_clipcount(true);
739 #if CONFIG_CODEC != SWCODEC
740 talk_buffer_steal(); /* we use the mp3 buffer */
741 #endif
742 audio_record(rec_create_filename(path_buffer));
743 break;
744 case RECORDING_CMD_START_NEWFILE:
745 /* create unique filename and start recording*/
746 pm_reset_clipcount();
747 pm_activate_clipcount(true); /* just to be sure */
748 audio_new_file(rec_create_filename(path_buffer));
749 break;
750 case RECORDING_CMD_PAUSE:
751 pm_activate_clipcount(false);
752 audio_pause_recording();
753 break;
754 case RECORDING_CMD_RESUME:
755 pm_activate_clipcount(true);
756 audio_resume_recording();
757 break;
759 update_list = true;
762 /* used in trigger_listerner and recording_screen */
763 static unsigned int last_seconds = 0;
766 * Callback function so that the peak meter code can send an event
767 * to this application. This function can be passed to
768 * peak_meter_set_trigger_listener in order to activate the trigger.
770 static void trigger_listener(int trigger_status)
772 switch (trigger_status)
774 case TRIG_GO:
775 if(!(audio_status() & AUDIO_STATUS_RECORD))
777 rec_status |= RCSTAT_HAVE_RECORDED;
778 rec_command(RECORDING_CMD_START);
779 #if CONFIG_CODEC != SWCODEC
780 /* give control to mpeg thread so that it can start
781 recording */
782 yield(); yield(); yield();
783 #endif
786 /* if we're already recording this is a retrigger */
787 else
789 if((audio_status() & AUDIO_STATUS_PAUSE) &&
790 (global_settings.rec_trigger_type == TRIG_TYPE_PAUSE))
792 rec_command(RECORDING_CMD_RESUME);
794 /* New file on trig start*/
795 else if (global_settings.rec_trigger_type != TRIG_TYPE_NEW_FILE)
797 rec_command(RECORDING_CMD_START_NEWFILE);
798 /* tell recording_screen to reset the time */
799 last_seconds = 0;
802 break;
804 /* A _change_ to TRIG_READY means the current recording has stopped */
805 case TRIG_READY:
806 if(audio_status() & AUDIO_STATUS_RECORD)
808 switch(global_settings.rec_trigger_type)
810 case TRIG_TYPE_STOP: /* Stop */
811 rec_command(RECORDING_CMD_STOP);
812 break;
814 case TRIG_TYPE_PAUSE: /* Pause */
815 rec_command(RECORDING_CMD_PAUSE);
816 break;
818 case TRIG_TYPE_NEW_FILE: /* New file on trig stop*/
819 rec_command(RECORDING_CMD_START_NEWFILE);
820 /* tell recording_screen to reset the time */
821 last_seconds = 0;
822 break;
824 case 3: /* Stop and shutdown */
825 rec_command(RECORDING_CMD_STOP_SHUTDOWN);
826 break;
829 if (global_settings.rec_trigger_mode != TRIG_MODE_REARM)
831 peak_meter_set_trigger_listener(NULL);
832 peak_meter_trigger(false);
835 break;
839 /* Stuff for drawing the screen */
841 enum rec_list_items_stereo {
842 ITEM_VOLUME = 0,
843 ITEM_GAIN = 1,
844 ITEM_GAIN_L = 2,
845 ITEM_GAIN_R = 3,
846 #ifdef HAVE_AGC
847 ITEM_AGC_MODE = 4,
848 ITEM_AGC_MAXDB = 5,
849 ITEM_FILENAME = 7,
850 ITEM_COUNT = 7,
851 #else
852 ITEM_FILENAME = 7,
853 ITEM_COUNT = 5,
854 #endif
857 enum rec_list_items_mono {
858 ITEM_VOLUME_M = 0,
859 ITEM_GAIN_M = 1,
860 #ifdef HAVE_AGC
861 ITEM_AGC_MODE_M = 4,
862 ITEM_AGC_MAXDB_M = 5,
863 ITEM_FILENAME_M = 7,
864 ITEM_COUNT_M = 5,
865 #else
866 ITEM_FILENAME_M = 7,
867 ITEM_COUNT_M = 3,
868 #endif
871 #ifdef HAVE_SPDIF_REC
872 enum rec_list_items_spdif {
873 ITEM_VOLUME_D = 0,
874 #if CONFIG_CODEC == SWCODEC
875 ITEM_SAMPLERATE_D = 6,
876 ITEM_FILENAME_D = 7,
877 ITEM_COUNT_D = 3,
878 #else
879 ITEM_FILENAME_D = 7,
880 ITEM_COUNT_D = 2,
881 #endif
883 #endif
885 static int listid_to_enum[ITEM_COUNT];
887 static const char* reclist_get_name(int selected_item, void * data,
888 char * buffer, size_t buffer_len)
890 char buf2[32];
891 #ifdef HAVE_AGC
892 char buf3[32];
893 #endif
894 data = data; /* not used */
895 if(selected_item >= ITEM_COUNT)
896 return "";
898 switch (listid_to_enum[selected_item])
900 case ITEM_VOLUME:
901 snprintf(buffer, buffer_len, "%s: %s", str(LANG_VOLUME),
902 fmt_gain(SOUND_VOLUME,
903 global_settings.volume,
904 buf2, sizeof(buf2)));
905 break;
906 case ITEM_GAIN:
907 #ifdef HAVE_MIC_REC
908 if(global_settings.rec_source == AUDIO_SRC_MIC)
910 /* Draw MIC recording gain */
911 snprintf(buffer, buffer_len, "%s: %s", str(LANG_GAIN),
912 fmt_gain(SOUND_MIC_GAIN,
913 global_settings.rec_mic_gain,
914 buf2, sizeof(buf2)));
916 else
917 #endif /* MIC */
919 int avg_gain = (global_settings.rec_left_gain +
920 global_settings.rec_right_gain) / 2;
921 snprintf(buffer, buffer_len, "%s: %s", str(LANG_GAIN),
922 fmt_gain(SOUND_LEFT_GAIN,
923 avg_gain,
924 buf2, sizeof(buf2)));
926 break;
927 case ITEM_GAIN_L:
928 snprintf(buffer, buffer_len, "%s: %s",
929 str(LANG_GAIN_LEFT),
930 fmt_gain(SOUND_LEFT_GAIN,
931 global_settings.rec_left_gain,
932 buf2, sizeof(buf2)));
933 break;
934 case ITEM_GAIN_R:
935 snprintf(buffer, buffer_len, "%s: %s",
936 str(LANG_GAIN_RIGHT),
937 fmt_gain(SOUND_RIGHT_GAIN,
938 global_settings.rec_right_gain,
939 buf2, sizeof(buf2)));
940 break;
941 #ifdef HAVE_AGC
942 case ITEM_AGC_MODE:
943 snprintf(buffer, buffer_len, "%s: %s",
944 str(LANG_RECORDING_AGC_PRESET),
945 agc_preset_str[agc_preset]);
946 break;
947 case ITEM_AGC_MAXDB:
948 if (agc_preset == 0)
949 snprintf(buffer, buffer_len, "%s: %s",
950 str(LANG_RECORDING_AGC_MAXGAIN),
951 fmt_gain(SOUND_LEFT_GAIN,
952 agc_maxgain, buf2, sizeof(buf2)));
953 #ifdef HAVE_MIC_REC
954 else if (global_settings.rec_source == AUDIO_SRC_MIC)
955 snprintf(buffer, buffer_len, "%s: %s (%s)",
956 str(LANG_RECORDING_AGC_MAXGAIN),
957 fmt_gain(SOUND_MIC_GAIN,
958 agc_maxgain, buf2, sizeof(buf2)),
959 fmt_gain(SOUND_MIC_GAIN,
960 agc_maxgain - global_settings.rec_mic_gain,
961 buf3, sizeof(buf3)));
962 else
963 #endif /* MIC */
964 snprintf(buffer, buffer_len, "%s: %s (%s)",
965 str(LANG_RECORDING_AGC_MAXGAIN),
966 fmt_gain(SOUND_LEFT_GAIN,
967 agc_maxgain, buf2, sizeof(buf2)),
968 fmt_gain(SOUND_LEFT_GAIN,
969 agc_maxgain -
970 (global_settings.rec_left_gain +
971 global_settings.rec_right_gain)/2,
972 buf3, sizeof(buf3)));
973 break;
974 #endif
975 #if CONFIG_CODEC == SWCODEC
976 #ifdef HAVE_SPDIF_REC
977 case ITEM_SAMPLERATE_D:
978 snprintf(buffer, buffer_len, "%s: %d",
979 str(LANG_RECORDING_FREQUENCY),
980 pcm_rec_sample_rate());
981 break;
982 #endif
983 #endif
984 case ITEM_FILENAME:
986 if(audio_status() & AUDIO_STATUS_RECORD)
988 size_t tot_len = strlen(path_buffer) +
989 strlen(str(LANG_RECORDING_FILENAME)) + 1;
990 if(tot_len > buffer_len)
992 snprintf(buffer, buffer_len, "%s %s",
993 str(LANG_RECORDING_FILENAME),
994 path_buffer + tot_len - buffer_len);
996 else
998 snprintf(buffer, buffer_len, "%s %s",
999 str(LANG_RECORDING_FILENAME), path_buffer);
1002 else
1004 return str(LANG_RECORDING_FILENAME);
1006 break;
1008 default:
1009 return "";
1011 return buffer;
1015 bool recording_start_automatic = false;
1017 bool recording_screen(bool no_source)
1019 int button;
1020 int done = -1; /* negative to re-init, positive to quit, zero to run */
1021 char buf[32]; /* for preparing strings */
1022 char buf2[32]; /* for preparing strings */
1023 int w, h; /* character width/height */
1024 int update_countdown = 0; /* refresh counter */
1025 unsigned int seconds;
1026 int hours, minutes;
1027 int audio_stat = 0; /* status of the audio system */
1028 int last_audio_stat = -1; /* previous status so we can act on changes */
1029 struct viewport vp_list[NB_SCREENS], vp_top[NB_SCREENS]; /* the viewports */
1031 #if CONFIG_CODEC == SWCODEC
1032 int warning_counter = 0;
1033 #define WARNING_PERIOD 7
1034 #endif
1036 #if CONFIG_CODEC == SWCODEC
1037 #ifdef HAVE_SPDIF_REC
1038 unsigned long prev_sample_rate = 0;
1039 #endif
1040 #endif
1042 #ifdef HAVE_FMRADIO_REC
1043 /* Radio is left on if:
1044 * 1) Is was on at the start and the initial source is FM Radio
1045 * 2) 1) and the source was never changed to something else
1047 int radio_status = (global_settings.rec_source != AUDIO_SRC_FMRADIO) ?
1048 FMRADIO_OFF : get_radio_status();
1049 #endif
1050 #if (CONFIG_LED == LED_REAL)
1051 bool led_state = false;
1052 int led_countdown = 2;
1053 #endif
1054 #ifdef HAVE_AGC
1055 bool peak_read = false;
1056 int peak_l, peak_r;
1057 int balance = 0;
1058 #endif
1059 int i;
1060 int pm_x[NB_SCREENS]; /* peakmeter (and trigger bar) x pos */
1061 int pm_y[NB_SCREENS]; /* peakmeter y pos */
1062 int pm_h[NB_SCREENS]; /* peakmeter height */
1063 int trig_ypos[NB_SCREENS]; /* trigger bar y pos */
1064 int trig_width[NB_SCREENS]; /* trigger bar width */
1065 int top_height_req[NB_SCREENS]; /* required height for top half */
1066 bool compact_view[NB_SCREENS]; /* tweak layout tiny screens / big fonts */
1067 struct gui_synclist lists; /* the list in the bottom vp */
1068 #if defined(HAVE_AGC) || defined(HAVE_RECORDING_HISTOGRAM)
1069 bool peak_valid = false;
1070 #endif
1071 #if defined(HAVE_RECORDING_HISTOGRAM)
1072 unsigned short hist_pos_y = 0;
1073 unsigned short hist_size_h = 0;
1074 int history_pos = 0;
1075 short hist_time_interval = 1; /* 1, 2, 4, 8 */
1076 unsigned char history_l[HIST_W];
1077 unsigned char history_r[HIST_W];
1078 const char hist_level_marks[6] = { 29, 26, 23, 17, 9, 2};
1079 #endif
1080 #ifdef HAVE_FMRADIO_REC
1081 int prev_rec_source = global_settings.rec_source; /* detect source change */
1082 #endif
1084 struct audio_recording_options rec_options;
1085 rec_status = RCSTAT_IN_RECSCREEN;
1087 #if (CONFIG_STORAGE & STORAGE_ATA) && (CONFIG_LED == LED_REAL) \
1088 && !defined(SIMULATOR)
1089 ata_set_led_enabled(false);
1090 #endif
1092 #if CONFIG_CODEC == SWCODEC
1093 /* recording_menu gets messed up: so prevent manus talking */
1094 talk_disable(true);
1095 /* audio_init_recording stops anything playing when it takes the audio
1096 buffer */
1097 #else
1098 /* Yes, we use the D/A for monitoring */
1099 peak_meter_enabled = true;
1100 peak_meter_playback(true);
1101 #endif
1103 #ifdef HAVE_AGC
1104 peak_meter_get_peakhold(&peak_l, &peak_r);
1105 #endif
1107 pm_reset_clipcount();
1108 pm_activate_clipcount(false);
1109 settings_apply_trigger();
1111 #ifdef HAVE_AGC
1112 agc_preset_str[0] = str(LANG_OFF);
1113 agc_preset_str[1] = str(LANG_AGC_SAFETY);
1114 agc_preset_str[2] = str(LANG_AGC_LIVE);
1115 agc_preset_str[3] = str(LANG_AGC_DJSET);
1116 agc_preset_str[4] = str(LANG_AGC_MEDIUM);
1117 agc_preset_str[5] = str(LANG_AGC_VOICE);
1118 #endif /* HAVE_AGC */
1120 #ifdef HAVE_SPEAKER
1121 /* Disable speaker to prevent feedback */
1122 audiohw_enable_speaker(false);
1123 #endif
1125 #if CONFIG_CODEC == SWCODEC
1126 audio_close_recording();
1127 #endif
1128 audio_init_recording(0);
1129 sound_set_volume(global_settings.volume);
1131 #if CONFIG_RTC == 0
1132 /* Create new filename for recording start */
1133 rec_init_filename();
1134 #endif
1136 /* start of the loop: we stay in this loop until user quits recscreen */
1137 while(done <= 0)
1139 if(done < 0)
1141 /* request to re-init stuff, done after settings screen */
1142 done = 0;
1143 #ifdef HAVE_FMRADIO_REC
1144 /* If input changes away from FM Radio,
1145 radio will remain off when recording screen closes. */
1146 if (global_settings.rec_source != prev_rec_source
1147 && prev_rec_source == AUDIO_SRC_FMRADIO)
1148 radio_status = FMRADIO_OFF;
1149 prev_rec_source = global_settings.rec_source;
1150 #endif
1152 /* viewport init and calculations that only needs to be done once */
1153 FOR_NB_SCREENS(i)
1155 struct viewport *v;
1156 /* top vp, 4 lines, force sys font if total screen < 6 lines
1157 NOTE: one could limit the list to 1 line and get away with 5 lines */
1158 top_height_req[i] = 4;
1159 #if defined(HAVE_RECORDING_HISTOGRAM)
1160 if((global_settings.rec_histogram_interval) && (!i))
1161 top_height_req[i] += 1; /* use one line for histogram */
1162 hist_time_interval = 1 << global_settings.rec_histogram_interval;
1163 #endif
1164 v = &vp_top[i];
1165 viewport_set_defaults(v, i);
1166 if (viewport_get_nb_lines(v) < top_height_req[i])
1168 /* compact needs 4 lines total */
1169 v->font = FONT_SYSFIXED;
1170 compact_view[i] = false;
1172 else
1174 /*top=4,list=2*/
1175 if (viewport_get_nb_lines(v) < (top_height_req[i]+2))
1176 compact_view[i] = true;
1177 else
1178 compact_view[i] = false;
1180 vp_list[i] = *v; /* get a copy now so it can be sized more easily */
1181 v->height = (font_get(v->font)->height)*(compact_view[i] ? 3 :
1182 top_height_req[i]);
1184 /* list section, rest of the screen */
1185 vp_list[i].y += vp_top[i].height;
1186 vp_list[i].height -= vp_top[i].height;
1187 screens[i].set_viewport(&vp_top[i]); /* req for next calls */
1189 screens[i].getstringsize("W", &w, &h);
1190 pm_y[i] = font_get(vp_top[i].font)->height * 2;
1191 trig_ypos[i] = font_get(vp_top[i].font)->height * 3;
1192 if(compact_view[i])
1193 trig_ypos[i] -= (font_get(vp_top[i].font)->height)/2;
1196 /* init the bottom list */
1197 gui_synclist_init(&lists, reclist_get_name, NULL, false, 1, vp_list);
1198 gui_synclist_set_title(&lists, NULL, Icon_NOICON);
1200 send_event(GUI_EVENT_ACTIONUPDATE, (void*)1); /* force a redraw */
1202 #if defined(HAVE_RECORDING_HISTOGRAM)
1203 history_pos = 0;
1204 hist_pos_y = (compact_view[0] ? 3 : 4) * (font_get(vp_top[0].font)->height)
1205 + 1;
1206 hist_size_h = font_get(vp_top[0].font)->height - 2;
1207 memset(history_l, 0, sizeof(unsigned char)*HIST_W);
1208 memset(history_r, 0, sizeof(unsigned char)*HIST_W);
1209 #endif
1211 FOR_NB_SCREENS(i)
1213 pm_x[i] = 0;
1214 if(global_settings.peak_meter_clipcounter)
1216 int clipwidth = 0;
1217 screens[i].getstringsize(str(LANG_PM_CLIPCOUNT),
1218 &clipwidth, &h); /* h is same */
1219 pm_x[i] = clipwidth+1;
1221 if(global_settings.rec_trigger_mode == TRIG_MODE_OFF)
1222 pm_h[i] = font_get(vp_top[i].font)->height * 2;
1223 else
1224 pm_h[i] = font_get(vp_top[i].font)->height;
1225 if(compact_view[i])
1226 pm_h[i] /= 2;
1227 trig_width[i] = vp_top[i].width - pm_x[i];
1230 #if CONFIG_CODEC == SWCODEC
1231 audio_close_recording();
1232 audio_init_recording(0);
1233 #endif
1235 rec_init_recording_options(&rec_options);
1236 rec_set_recording_options(&rec_options);
1238 if(rec_create_directory() < 0)
1240 rec_status = 0;
1241 goto rec_abort;
1244 #if CONFIG_CODEC == SWCODEC && CONFIG_RTC == 0
1245 /* If format changed, a new number is required */
1246 rec_init_filename();
1247 #endif
1249 #ifdef HAVE_AGC
1250 #ifdef HAVE_MIC_REC
1251 if (global_settings.rec_source == AUDIO_SRC_MIC) {
1252 agc_preset = global_settings.rec_agc_preset_mic;
1253 agc_maxgain = global_settings.rec_agc_maxgain_mic;
1255 else
1256 #endif /* MIC */
1258 agc_preset = global_settings.rec_agc_preset_line;
1259 agc_maxgain = global_settings.rec_agc_maxgain_line;
1261 #endif /* HAVE_AGC */
1263 set_gain();
1264 update_countdown = 0; /* Update immediately */
1266 /* populate translation table for list id -> enum */
1267 #ifdef HAVE_SPDIF_REC
1268 if(global_settings.rec_source == AUDIO_SRC_SPDIF)
1270 listid_to_enum[0] = ITEM_VOLUME_D;
1271 #if CONFIG_CODEC == SWCODEC
1272 listid_to_enum[1] = ITEM_SAMPLERATE_D;
1273 listid_to_enum[2] = ITEM_FILENAME_D;
1274 #else
1275 listid_to_enum[1] = ITEM_FILENAME_D;
1276 #endif
1278 gui_synclist_set_nb_items(&lists, ITEM_COUNT_D); /* spdif */
1280 else
1281 #endif
1282 if(HAVE_MIC_REC_((global_settings.rec_source == AUDIO_SRC_MIC) || )
1283 (global_settings.rec_channels == 1))
1285 listid_to_enum[0] = ITEM_VOLUME_M;
1286 listid_to_enum[1] = ITEM_GAIN_M;
1287 #ifdef HAVE_AGC
1288 listid_to_enum[2] = ITEM_AGC_MODE_M;
1289 listid_to_enum[3] = ITEM_AGC_MAXDB_M;
1290 listid_to_enum[4] = ITEM_FILENAME_M;
1291 #else
1292 listid_to_enum[2] = ITEM_FILENAME_M;
1293 #endif
1294 gui_synclist_set_nb_items(&lists, ITEM_COUNT_M); /* mono */
1296 else
1298 listid_to_enum[0] = ITEM_VOLUME;
1299 listid_to_enum[1] = ITEM_GAIN;
1300 listid_to_enum[2] = ITEM_GAIN_L;
1301 listid_to_enum[3] = ITEM_GAIN_R;
1302 #ifdef HAVE_AGC
1303 listid_to_enum[4] = ITEM_AGC_MODE;
1304 listid_to_enum[5] = ITEM_AGC_MAXDB;
1305 listid_to_enum[6] = ITEM_FILENAME;
1306 #else
1307 listid_to_enum[4] = ITEM_FILENAME;
1308 #endif
1309 gui_synclist_set_nb_items(&lists, ITEM_COUNT); /* stereo */
1312 gui_synclist_draw(&lists);
1313 } /* if(done < 0) */
1315 audio_stat = audio_status();
1317 #if (CONFIG_LED == LED_REAL)
1320 * Flash the LED while waiting to record. Turn it on while
1321 * recording.
1323 if(audio_stat & AUDIO_STATUS_RECORD)
1325 if (audio_stat & AUDIO_STATUS_PAUSE)
1327 if (--led_countdown <= 0)
1329 led_state = !led_state;
1330 led(led_state);
1331 led_countdown = 2;
1334 else
1336 /* trigger is on in status TRIG_READY (no check needed) */
1337 led(true);
1340 else
1342 int trig_stat = peak_meter_trigger_status();
1344 * other trigger stati than trig_off and trig_steady
1345 * already imply that we are recording.
1347 if (trig_stat == TRIG_STEADY)
1349 if (--led_countdown <= 0)
1351 led_state = !led_state;
1352 led(led_state);
1353 led_countdown = 2;
1356 else
1358 /* trigger is on in status TRIG_READY (no check needed) */
1359 led(false);
1362 #endif /* CONFIG_LED */
1364 /* Wait for a button a while (HZ/10) drawing the peak meter */
1365 button = peak_meter_draw_get_btn(CONTEXT_RECSCREEN,
1366 pm_x, pm_y, pm_h,
1367 screen_update, vp_top);
1368 if (last_audio_stat != audio_stat)
1370 if (audio_stat & AUDIO_STATUS_RECORD)
1372 rec_status |= RCSTAT_HAVE_RECORDED;
1374 last_audio_stat = audio_stat;
1375 update_list = true;
1378 if (recording_start_automatic)
1380 /* simulate a button press */
1381 button = ACTION_REC_PAUSE;
1382 recording_start_automatic = false;
1385 /* let list handle the button */
1386 gui_synclist_do_button(&lists, &button, LIST_WRAP_UNLESS_HELD);
1389 switch(button)
1391 case ACTION_SETTINGS_INC:
1392 case ACTION_SETTINGS_INCREPEAT:
1393 switch (listid_to_enum[gui_synclist_get_sel_pos(&lists)])
1395 case ITEM_VOLUME:
1396 global_settings.volume++;
1397 setvol();
1398 break;
1399 case ITEM_GAIN:
1400 #ifdef HAVE_MIC_REC
1401 if(global_settings.rec_source == AUDIO_SRC_MIC)
1403 if(global_settings.rec_mic_gain <
1404 sound_max(SOUND_MIC_GAIN))
1405 global_settings.rec_mic_gain++;
1407 else
1408 #endif /* MIC */
1410 if(global_settings.rec_left_gain <
1411 sound_max(SOUND_LEFT_GAIN))
1412 global_settings.rec_left_gain++;
1413 if(global_settings.rec_right_gain <
1414 sound_max(SOUND_RIGHT_GAIN))
1415 global_settings.rec_right_gain++;
1417 break;
1418 case ITEM_GAIN_L:
1419 if(global_settings.rec_left_gain <
1420 sound_max(SOUND_LEFT_GAIN))
1421 global_settings.rec_left_gain++;
1422 break;
1423 case ITEM_GAIN_R:
1424 if(global_settings.rec_right_gain <
1425 sound_max(SOUND_RIGHT_GAIN))
1426 global_settings.rec_right_gain++;
1427 break;
1428 #ifdef HAVE_AGC
1429 case ITEM_AGC_MODE:
1430 agc_preset = MIN(agc_preset + 1, AGC_MODE_SIZE);
1431 agc_enable = (agc_preset != 0);
1432 #ifdef HAVE_MIC_REC
1433 if (global_settings.rec_source == AUDIO_SRC_MIC) {
1434 global_settings.rec_agc_preset_mic = agc_preset;
1435 agc_maxgain = global_settings.rec_agc_maxgain_mic;
1436 } else
1437 #endif /* MIC */
1439 global_settings.rec_agc_preset_line = agc_preset;
1440 agc_maxgain = global_settings.rec_agc_maxgain_line;
1442 break;
1443 case ITEM_AGC_MAXDB:
1444 #ifdef HAVE_MIC_REC
1445 if (global_settings.rec_source == AUDIO_SRC_MIC)
1447 agc_maxgain = MIN(agc_maxgain + 1,
1448 sound_max(SOUND_MIC_GAIN));
1449 global_settings.rec_agc_maxgain_mic = agc_maxgain;
1451 else
1452 #endif /* MIC */
1454 agc_maxgain = MIN(agc_maxgain + 1,
1455 sound_max(SOUND_LEFT_GAIN));
1456 global_settings.rec_agc_maxgain_line = agc_maxgain;
1458 break;
1459 #endif /* HAVE_AGC */
1461 set_gain();
1462 update_countdown = 0; /* Update immediately */
1463 break;
1464 case ACTION_SETTINGS_DEC:
1465 case ACTION_SETTINGS_DECREPEAT:
1466 switch (listid_to_enum[gui_synclist_get_sel_pos(&lists)])
1468 case ITEM_VOLUME:
1469 global_settings.volume--;
1470 setvol();
1471 break;
1472 case ITEM_GAIN:
1473 #ifdef HAVE_MIC_REC
1474 if(global_settings.rec_source == AUDIO_SRC_MIC)
1476 if(global_settings.rec_mic_gain >
1477 sound_min(SOUND_MIC_GAIN))
1478 global_settings.rec_mic_gain--;
1480 else
1481 #endif /* MIC */
1483 if(global_settings.rec_left_gain >
1484 sound_min(SOUND_LEFT_GAIN))
1485 global_settings.rec_left_gain--;
1486 if(global_settings.rec_right_gain >
1487 sound_min(SOUND_RIGHT_GAIN))
1488 global_settings.rec_right_gain--;
1490 break;
1491 case ITEM_GAIN_L:
1492 if(global_settings.rec_left_gain >
1493 sound_min(SOUND_LEFT_GAIN))
1494 global_settings.rec_left_gain--;
1495 break;
1496 case ITEM_GAIN_R:
1497 if(global_settings.rec_right_gain >
1498 sound_min(SOUND_RIGHT_GAIN))
1499 global_settings.rec_right_gain--;
1500 break;
1501 #ifdef HAVE_AGC
1502 case ITEM_AGC_MODE:
1503 agc_preset = MAX(agc_preset - 1, 0);
1504 agc_enable = (agc_preset != 0);
1505 #ifdef HAVE_MIC_REC
1506 if (global_settings.rec_source == AUDIO_SRC_MIC) {
1507 global_settings.rec_agc_preset_mic = agc_preset;
1508 agc_maxgain = global_settings.rec_agc_maxgain_mic;
1509 } else
1510 #endif /* MIC */
1512 global_settings.rec_agc_preset_line = agc_preset;
1513 agc_maxgain = global_settings.rec_agc_maxgain_line;
1515 break;
1516 case ITEM_AGC_MAXDB:
1517 #ifdef HAVE_MIC_REC
1518 if (global_settings.rec_source == AUDIO_SRC_MIC)
1520 agc_maxgain = MAX(agc_maxgain - 1,
1521 sound_min(SOUND_MIC_GAIN));
1522 global_settings.rec_agc_maxgain_mic = agc_maxgain;
1523 } else
1524 #endif /* MIC */
1526 agc_maxgain = MAX(agc_maxgain - 1,
1527 sound_min(SOUND_LEFT_GAIN));
1528 global_settings.rec_agc_maxgain_line = agc_maxgain;
1530 break;
1531 #endif /* HAVE_AGC */
1533 set_gain();
1534 update_countdown = 0; /* Update immediately */
1535 break;
1536 case ACTION_STD_CANCEL:
1537 /* turn off the trigger */
1538 peak_meter_trigger(false);
1539 peak_meter_set_trigger_listener(NULL);
1541 if(audio_stat & AUDIO_STATUS_RECORD)
1543 rec_command(RECORDING_CMD_STOP);
1545 else
1547 #if CONFIG_CODEC != SWCODEC
1548 peak_meter_playback(true);
1549 peak_meter_enabled = false;
1550 #endif
1551 done = 1;
1553 update_countdown = 0; /* Update immediately */
1554 break;
1555 #ifdef HAVE_REMOTE_LCD
1556 case ACTION_REC_LCD:
1557 /* this feature exists for some h1x0/h3x0 targets that suffer
1558 from noise caused by remote LCD updates
1559 NOTE 1: this will leave the list on the remote
1560 NOTE 2: to be replaced by a global LCD_off() routine */
1561 if(remote_display_on)
1563 /* switch to single screen, leave message on remote */
1564 screen_update = 1;
1565 screens[1].clear_viewport();
1566 screens[1].puts(0, 0, str(LANG_REMOTE_LCD_OFF));
1567 screens[1].puts(0, 1, str(LANG_REMOTE_LCD_ON));
1568 screens[1].update_viewport();
1570 else
1572 /* remote switched on again */
1573 update_list = true;
1574 screen_update = NB_SCREENS;
1576 remote_display_on = !remote_display_on; /* toggle */
1577 update_countdown = 0; /* Update immediately */
1578 break;
1579 #endif
1580 case ACTION_REC_PAUSE:
1581 case ACTION_REC_NEWFILE:
1582 /* Only act if the mpeg is stopped */
1583 if(!(audio_stat & AUDIO_STATUS_RECORD))
1585 /* is this manual or triggered recording? */
1586 if ((global_settings.rec_trigger_mode == TRIG_MODE_OFF) ||
1587 (peak_meter_trigger_status() != TRIG_OFF))
1589 /* manual recording */
1590 rec_status |= RCSTAT_HAVE_RECORDED;
1591 rec_command(RECORDING_CMD_START);
1592 last_seconds = 0;
1593 if (global_settings.talk_menu)
1595 /* no voice possible here, but a beep */
1596 audio_beep(HZ/2); /* longer beep on start */
1599 /* this is triggered recording */
1600 else
1602 /* we don't start recording now, but enable the
1603 trigger and let the callback function
1604 trigger_listener control when the recording starts */
1605 peak_meter_trigger(true);
1606 peak_meter_set_trigger_listener(&trigger_listener);
1609 else
1611 /*if new file button pressed, start new file */
1612 if (button == ACTION_REC_NEWFILE)
1614 rec_command(RECORDING_CMD_START_NEWFILE);
1615 last_seconds = 0;
1617 else
1618 /* if pause button pressed, pause or resume */
1620 if(audio_stat & AUDIO_STATUS_PAUSE)
1622 rec_command(RECORDING_CMD_RESUME);
1623 if (global_settings.talk_menu)
1625 /* no voice possible here, but a beep */
1626 audio_beep(HZ/4); /* short beep on resume */
1629 else
1631 rec_command(RECORDING_CMD_PAUSE);
1635 update_countdown = 0; /* Update immediately */
1636 break;
1637 case ACTION_STD_MENU:
1638 #if CONFIG_CODEC == SWCODEC
1639 if(!(audio_stat & AUDIO_STATUS_RECORD))
1640 #else
1641 if(audio_stat != AUDIO_STATUS_RECORD)
1642 #endif
1644 #if (CONFIG_LED == LED_REAL)
1645 /* led is restored at begin of loop / end of function */
1646 led(false);
1647 #endif
1648 if (recording_menu(no_source))
1650 done = 1;
1651 rec_status |= RCSTAT_BEEN_IN_USB_MODE;
1652 #ifdef HAVE_FMRADIO_REC
1653 radio_status = FMRADIO_OFF;
1654 #endif
1656 else
1658 done = -1;
1659 /* the init is now done at the beginning of the loop */
1662 break;
1664 #if CONFIG_KEYPAD == RECORDER_PAD
1665 case ACTION_REC_F2:
1666 if(audio_stat != AUDIO_STATUS_RECORD)
1668 #if (CONFIG_LED == LED_REAL)
1669 /* led is restored at begin of loop / end of function */
1670 led(false);
1671 #endif
1672 if (f2_rec_screen())
1674 rec_status |= RCSTAT_HAVE_RECORDED;
1675 done = true;
1677 else
1678 update_countdown = 0; /* Update immediately */
1680 break;
1682 case ACTION_REC_F3:
1683 if(audio_stat & AUDIO_STATUS_RECORD)
1685 rec_command(RECORDING_CMD_START_NEWFILE);
1686 last_seconds = 0;
1688 else
1690 #if (CONFIG_LED == LED_REAL)
1691 /* led is restored at begin of loop / end of function */
1692 led(false);
1693 #endif
1694 if (f3_rec_screen())
1696 rec_status |= RCSTAT_HAVE_RECORDED;
1697 done = true;
1699 else
1700 update_countdown = 0; /* Update immediately */
1702 break;
1703 #endif /* CONFIG_KEYPAD == RECORDER_PAD */
1705 case SYS_USB_CONNECTED:
1706 /* Only accept USB connection when not recording */
1707 if(!(audio_stat & AUDIO_STATUS_RECORD))
1709 FOR_NB_SCREENS(i)
1710 screens[i].set_viewport(NULL);
1711 default_event_handler(SYS_USB_CONNECTED);
1712 done = true;
1713 rec_status |= RCSTAT_BEEN_IN_USB_MODE;
1714 #ifdef HAVE_FMRADIO_REC
1715 radio_status = FMRADIO_OFF;
1716 #endif
1718 break;
1719 } /*switch(button)*/
1721 #ifdef HAVE_AGC
1722 peak_read = !peak_read;
1723 if (peak_read) { /* every 2nd run of loop */
1724 peak_time++;
1725 peak_valid = read_peak_levels(&peak_l, &peak_r, &balance);
1728 /* Handle AGC every 200ms when enabled and peak data is valid */
1729 if (peak_read && agc_enable && peak_valid)
1730 auto_gain_control(&peak_l, &peak_r, &balance);
1731 #endif
1733 seconds = audio_recorded_time() / HZ;
1735 /* start of vp_top drawing */
1736 if(update_countdown-- == 0 || seconds > last_seconds)
1738 unsigned int dseconds, dhours, dminutes;
1739 unsigned long num_recorded_bytes, dsize, dmb;
1741 FOR_NB_SCREENS(i)
1743 screens[i].set_viewport(&vp_top[i]);
1744 screens[i].clear_viewport();
1746 update_countdown = 5;
1747 last_seconds = seconds;
1749 dseconds = rec_timesplit_seconds();
1750 dsize = rec_sizesplit_bytes();
1751 num_recorded_bytes = audio_num_recorded_bytes();
1753 #if CONFIG_CODEC == SWCODEC
1754 if ((audio_stat & AUDIO_STATUS_WARNING)
1755 && (warning_counter++ % WARNING_PERIOD) < WARNING_PERIOD/2)
1757 /* Switch back and forth displaying warning on first available
1758 line to ensure visibility - the motion should also help
1759 draw attention */
1760 /* Don't use language string unless agreed upon to make this
1761 method permanent - could do something in the statusbar */
1762 snprintf(buf, sizeof(buf), "Warning: %08X",
1763 pcm_rec_get_warnings());
1765 else
1766 #endif /* CONFIG_CODEC == SWCODEC */
1767 if ((global_settings.rec_sizesplit) &&
1768 (global_settings.rec_split_method))
1770 dmb = dsize/1024/1024;
1771 snprintf(buf, sizeof(buf), "%s %dMB",
1772 str(LANG_SPLIT_SIZE), dmb);
1774 else
1776 hours = seconds / 3600;
1777 minutes = (seconds - (hours * 3600)) / 60;
1778 snprintf(buf, sizeof(buf), "%s %02d:%02d:%02d",
1779 str(LANG_RECORDING_TIME),
1780 hours, minutes, seconds%60);
1783 FOR_NB_ACTIVE_SCREENS(i)
1784 screens[i].puts(0, 0, buf);
1786 if(audio_stat & AUDIO_STATUS_PRERECORD)
1788 snprintf(buf, sizeof(buf), "%s...",
1789 str(LANG_RECORD_PRERECORD));
1791 else
1793 /* Display the split interval if the record timesplit
1794 is active */
1795 if ((global_settings.rec_timesplit) &&
1796 !(global_settings.rec_split_method))
1798 /* Display the record timesplit interval rather
1799 than the file size if the record timer is active */
1800 dhours = dseconds / 3600;
1801 dminutes = (dseconds - (dhours * 3600)) / 60;
1802 snprintf(buf, sizeof(buf), "%s %02d:%02d",
1803 str(LANG_RECORDING_TIMESPLIT_REC),
1804 dhours, dminutes);
1806 else
1808 output_dyn_value(buf2, sizeof buf2,
1809 num_recorded_bytes,
1810 byte_units, true);
1811 snprintf(buf, sizeof(buf), "%s %s",
1812 str(LANG_RECORDING_SIZE), buf2);
1816 FOR_NB_ACTIVE_SCREENS(i)
1817 screens[i].puts(0, 1, buf);
1819 /* We will do file splitting regardless, either at the end of
1820 a split interval, or when the filesize approaches the 2GB
1821 FAT file size (compatibility) limit. */
1822 if ((audio_stat && !(global_settings.rec_split_method)
1823 && global_settings.rec_timesplit && (seconds >= dseconds))
1824 || (audio_stat && global_settings.rec_split_method
1825 && global_settings.rec_sizesplit
1826 && (num_recorded_bytes >= dsize))
1827 || (num_recorded_bytes >= MAX_FILE_SIZE))
1829 if (!(global_settings.rec_split_type)
1830 || (num_recorded_bytes >= MAX_FILE_SIZE))
1832 rec_command(RECORDING_CMD_START_NEWFILE);
1833 last_seconds = 0;
1835 else
1837 peak_meter_trigger(false);
1838 peak_meter_set_trigger_listener(NULL);
1839 if( global_settings.rec_split_type == 1)
1840 rec_command(RECORDING_CMD_STOP);
1841 else
1842 rec_command(RECORDING_CMD_STOP_SHUTDOWN);
1844 update_countdown = 0;
1847 /* draw the clipcounter just in front of the peakmeter */
1848 if(global_settings.peak_meter_clipcounter)
1850 int clipcount = pm_get_clipcount();
1851 FOR_NB_ACTIVE_SCREENS(i)
1853 if(!compact_view[i])
1855 screens[i].puts(0, 2, str(LANG_PM_CLIPCOUNT));
1856 screens[i].putsf(0, 3, "%4d", clipcount);
1858 else
1859 screens[i].putsf(0, 2, "%4d", clipcount);
1863 #ifdef HAVE_RECORDING_HISTOGRAM
1864 if(global_settings.rec_histogram_interval)
1866 if (peak_valid && !(hist_time % hist_time_interval) && hist_l)
1868 history_l[history_pos] = hist_l * hist_size_h / 32767;
1869 history_r[history_pos] = hist_r * hist_size_h / 32767;
1870 history_pos = (history_pos + 1) % HIST_W;
1871 history_l[history_pos] = history_r[history_pos] = 0;
1872 history_l[(history_pos + 1) % HIST_W] = 0;
1873 history_r[(history_pos + 1) % HIST_W] = 0;
1874 hist_l = 0;
1875 hist_r = 0;
1877 lcd_set_drawmode(DRMODE_SOLID);
1878 lcd_drawrect(0, hist_pos_y - 1,
1879 HIST_W + 2, hist_size_h + 1);
1880 lcd_drawrect(HIST_W + 6, hist_pos_y - 1,
1881 HIST_W + 2, hist_size_h + 1);
1882 lcd_set_drawmode(DRMODE_FG);
1883 #ifdef HAVE_LCD_COLOR
1884 for (i = 0; i < HIST_W; i++)
1886 if (history_l[i])
1888 if (history_l[i] == hist_size_h)
1889 lcd_set_foreground(LCD_HIST_OVER);
1890 else if (history_l[i] > hist_level_marks[1])
1891 lcd_set_foreground(LCD_HIST_HI);
1892 else
1893 lcd_set_foreground(LCD_HIST_OK);
1894 lcd_vline(1 + i, HIST_Y-1, HIST_Y - history_l[i]);
1896 if (history_r[i])
1898 if (history_r[i] == hist_size_h)
1899 lcd_set_foreground(LCD_HIST_OVER);
1900 else if (history_r[i] > hist_level_marks[1])
1901 lcd_set_foreground(LCD_HIST_HI);
1902 else
1903 lcd_set_foreground(LCD_HIST_OK);
1904 lcd_vline(HIST_W+7 + i, HIST_Y-1, HIST_Y - history_r[i]);
1907 #else
1908 for (i = 0; i < HIST_W; i++)
1910 if (history_l[i])
1912 if (history_l[i] == hist_size_h)
1913 lcd_set_foreground(LCD_HIST_OVER);
1914 else
1915 lcd_set_foreground(LCD_HIST_OK);
1916 lcd_vline(1 + i, HIST_Y-1, HIST_Y - history_l[i]);
1918 if (history_r[i])
1920 if (history_r[i] == hist_size_h)
1921 lcd_set_foreground(LCD_HIST_OVER);
1922 else
1923 lcd_set_foreground(LCD_HIST_OK);
1924 lcd_vline(HIST_W+7 + i, HIST_Y-1, HIST_Y - history_r[i]);
1927 #endif /* HAVE_LCD_COLOR */
1928 lcd_set_foreground(
1929 #ifdef HAVE_LCD_COLOR
1930 global_settings.fg_color);
1931 #else
1932 LCD_DEFAULT_FG);
1933 #endif
1934 for (i = 0; i < 6; i++)
1935 lcd_hline(HIST_W + 3, HIST_W + 4,
1936 HIST_Y - hist_level_marks[i]);
1938 #endif /* HAVE_RECORDING_HISTOGRAM */
1940 #ifdef HAVE_AGC
1941 hist_time++;
1942 #endif
1944 /* draw the trigger status */
1945 if (peak_meter_trigger_status() != TRIG_OFF)
1947 peak_meter_draw_trig(pm_x, trig_ypos, trig_width,
1948 screen_update);
1949 FOR_NB_ACTIVE_SCREENS(i)
1950 screens[i].update_viewport_rect(pm_x[i], trig_ypos[i],
1951 trig_width[i] + 2, TRIG_HEIGHT);
1954 #ifdef HAVE_AGC
1955 #ifdef HAVE_MIC_REC
1956 if (global_settings.rec_source == AUDIO_SRC_MIC)
1958 if(agc_maxgain < (global_settings.rec_mic_gain))
1959 change_recording_gain(false, true, true);
1961 else
1962 #endif /* MIC */
1964 if(agc_maxgain < (global_settings.rec_left_gain))
1965 change_recording_gain(false, true, false);
1966 if(agc_maxgain < (global_settings.rec_right_gain))
1967 change_recording_gain(false, false, true);
1969 #endif /* HAVE_AGC */
1971 #if CONFIG_CODEC == SWCODEC
1972 #ifdef HAVE_SPDIF_REC
1973 if((global_settings.rec_source == AUDIO_SRC_SPDIF) &&
1974 (prev_sample_rate != pcm_rec_sample_rate()))
1976 /* spdif samplerate changed */
1977 prev_sample_rate = pcm_rec_sample_rate();
1978 update_list = true;
1980 #endif
1981 #endif
1983 if(update_list)
1985 /* update_list is set whenever content changes */
1986 update_list = false;
1987 gui_synclist_draw(&lists);
1990 /* draw peakmeter again (check if this can be removed) */
1991 FOR_NB_ACTIVE_SCREENS(i)
1993 screens[i].set_viewport(&vp_top[i]);
1994 peak_meter_screen(&screens[i], pm_x[i], pm_y[i], pm_h[i]);
1995 screens[i].update();
1997 } /* display update every second */
1999 if(audio_stat & AUDIO_STATUS_ERROR)
2001 done = true;
2003 } /* end while(!done) */
2005 audio_stat = audio_status();
2006 if (audio_stat & AUDIO_STATUS_ERROR)
2008 splash(0, str(LANG_DISK_FULL));
2010 FOR_NB_SCREENS(i)
2011 screens[i].update();
2013 #if CONFIG_CODEC == SWCODEC
2014 /* stop recording - some players like H10 freeze otherwise
2015 TO DO: find out why it freezes and fix properly */
2016 rec_command(RECORDING_CMD_STOP);
2017 audio_close_recording();
2018 #endif
2020 audio_error_clear();
2022 while(1)
2024 if (action_userabort(TIMEOUT_NOBLOCK))
2025 break;
2029 rec_abort:
2031 #if CONFIG_CODEC == SWCODEC
2032 rec_command(RECORDING_CMD_STOP);
2033 audio_close_recording();
2035 #ifdef HAVE_FMRADIO_REC
2036 if (radio_status != FMRADIO_OFF)
2037 /* Restore radio playback - radio_status should be unchanged if started
2038 through fm radio screen (barring usb connect) */
2039 rec_set_source(AUDIO_SRC_FMRADIO, (radio_status & FMRADIO_PAUSED) ?
2040 SRCF_FMRADIO_PAUSED : SRCF_FMRADIO_PLAYING);
2041 else
2042 #endif
2043 /* Go back to playback mode */
2044 rec_set_source(AUDIO_SRC_PLAYBACK, SRCF_PLAYBACK);
2046 /* restore talking */
2047 talk_disable(false);
2048 #else /* !SWCODEC */
2049 audio_init_playback();
2050 #endif /* CONFIG_CODEC == SWCODEC */
2052 #ifdef HAVE_SPEAKER
2053 /* Re-enable speaker */
2054 audiohw_enable_speaker(global_settings.speaker_enabled);
2055 #endif
2057 /* make sure the trigger is really turned off */
2058 peak_meter_trigger(false);
2059 peak_meter_set_trigger_listener(NULL);
2061 rec_status &= ~RCSTAT_IN_RECSCREEN;
2062 sound_settings_apply();
2064 FOR_NB_SCREENS(i)
2065 screens[i].setfont(FONT_UI);
2067 /* if the directory was created or recording happened, make sure the
2068 browser is updated */
2069 if (rec_status & (RCSTAT_CREATED_DIRECTORY | RCSTAT_HAVE_RECORDED))
2070 reload_directory();
2072 #if (CONFIG_STORAGE & STORAGE_ATA) && (CONFIG_LED == LED_REAL) \
2073 && !defined(SIMULATOR)
2074 ata_set_led_enabled(true);
2075 #endif
2077 settings_save();
2079 return (rec_status & RCSTAT_BEEN_IN_USB_MODE) != 0;
2080 } /* recording_screen */
2082 #if CONFIG_KEYPAD == RECORDER_PAD
2083 static bool f2_rec_screen(void)
2085 static const char* const freq_str[6] =
2087 "44.1kHz",
2088 "48kHz",
2089 "32kHz",
2090 "22.05kHz",
2091 "24kHz",
2092 "16kHz"
2095 bool exit = false;
2096 bool used = false;
2097 int w, h, i;
2098 char buf[32];
2099 int button;
2100 struct audio_recording_options rec_options;
2102 FOR_NB_SCREENS(i)
2104 screens[i].set_viewport(NULL);
2105 screens[i].setfont(FONT_SYSFIXED);
2106 screens[i].getstringsize("A",&w,&h);
2109 while (!exit) {
2110 const char* ptr;
2112 FOR_NB_SCREENS(i)
2114 screens[i].clear_display();
2116 /* Recording quality */
2117 screens[i].putsxy(0, LCD_HEIGHT/2 - h*2,
2118 str(LANG_SYSFONT_RECORDING_QUALITY));
2121 snprintf(buf, sizeof(buf), "%d", global_settings.rec_quality);
2122 FOR_NB_SCREENS(i)
2124 screens[i].putsxy(0, LCD_HEIGHT/2-h, buf);
2125 screens[i].mono_bitmap(bitmap_icons_7x8[Icon_FastBackward],
2126 LCD_WIDTH/2 - 16, LCD_HEIGHT/2 - 4, 7, 8);
2129 /* Frequency */
2130 snprintf(buf, sizeof buf, "%s:", str(LANG_SYSFONT_RECORDING_FREQUENCY));
2131 ptr = freq_str[global_settings.rec_frequency];
2132 FOR_NB_SCREENS(i)
2134 screens[i].getstringsize(buf,&w,&h);
2135 screens[i].putsxy((LCD_WIDTH-w)/2, LCD_HEIGHT - h*2, buf);
2136 screens[i].getstringsize(ptr, &w, &h);
2137 screens[i].putsxy((LCD_WIDTH-w)/2, LCD_HEIGHT - h, ptr);
2138 screens[i].mono_bitmap(bitmap_icons_7x8[Icon_DownArrow],
2139 LCD_WIDTH/2 - 3, LCD_HEIGHT - h*3, 7, 8);
2142 /* Channel mode */
2143 switch ( global_settings.rec_channels ) {
2144 case 0:
2145 ptr = str(LANG_SYSFONT_CHANNEL_STEREO);
2146 break;
2148 case 1:
2149 ptr = str(LANG_SYSFONT_CHANNEL_MONO);
2150 break;
2153 FOR_NB_SCREENS(i)
2155 screens[i].getstringsize(str(LANG_SYSFONT_CHANNELS), &w, &h);
2156 screens[i].putsxy(LCD_WIDTH - w, LCD_HEIGHT/2 - h*2,
2157 str(LANG_SYSFONT_CHANNELS));
2158 screens[i].getstringsize(str(LANG_SYSFONT_MODE), &w, &h);
2159 screens[i].putsxy(LCD_WIDTH - w, LCD_HEIGHT/2 - h,
2160 str(LANG_SYSFONT_MODE));
2161 screens[i].getstringsize(ptr, &w, &h);
2162 screens[i].putsxy(LCD_WIDTH - w, LCD_HEIGHT/2, ptr);
2163 screens[i].mono_bitmap(bitmap_icons_7x8[Icon_FastForward],
2164 LCD_WIDTH/2 + 8, LCD_HEIGHT/2 - 4, 7, 8);
2166 screens[i].update();
2169 button = button_get(true);
2170 switch (button) {
2171 case BUTTON_LEFT:
2172 case BUTTON_F2 | BUTTON_LEFT:
2173 global_settings.rec_quality++;
2174 if(global_settings.rec_quality > 7)
2175 global_settings.rec_quality = 0;
2176 used = true;
2177 break;
2179 case BUTTON_DOWN:
2180 case BUTTON_F2 | BUTTON_DOWN:
2181 global_settings.rec_frequency++;
2182 if(global_settings.rec_frequency > 5)
2183 global_settings.rec_frequency = 0;
2184 used = true;
2185 break;
2187 case BUTTON_RIGHT:
2188 case BUTTON_F2 | BUTTON_RIGHT:
2189 global_settings.rec_channels++;
2190 if(global_settings.rec_channels > 1)
2191 global_settings.rec_channels = 0;
2192 used = true;
2193 break;
2195 case BUTTON_F2 | BUTTON_REL:
2196 if ( used )
2197 exit = true;
2198 used = true;
2199 break;
2201 case BUTTON_F2 | BUTTON_REPEAT:
2202 used = true;
2203 break;
2205 default:
2206 if(default_event_handler(button) == SYS_USB_CONNECTED)
2207 return true;
2208 break;
2212 rec_init_recording_options(&rec_options);
2213 rec_set_recording_options(&rec_options);
2215 set_gain();
2217 settings_save();
2218 FOR_NB_SCREENS(i)
2219 screens[i].setfont(FONT_UI);
2221 return false;
2224 static bool f3_rec_screen(void)
2226 bool exit = false;
2227 bool used = false;
2228 int w, h, i;
2229 int button;
2230 const char *src_str[] =
2232 str(LANG_SYSFONT_RECORDING_SRC_MIC),
2233 str(LANG_SYSFONT_LINE_IN),
2234 str(LANG_SYSFONT_RECORDING_SRC_DIGITAL)
2236 struct audio_recording_options rec_options;
2238 FOR_NB_SCREENS(i)
2240 screens[i].set_viewport(NULL);
2241 screens[i].setfont(FONT_SYSFIXED);
2242 screens[i].getstringsize("A",&w,&h);
2245 while (!exit) {
2246 const char* ptr = src_str[global_settings.rec_source];
2247 FOR_NB_SCREENS(i)
2249 screens[i].clear_display();
2251 /* Recording source */
2252 screens[i].putsxy(0, LCD_HEIGHT/2 - h*2,
2253 str(LANG_SYSFONT_RECORDING_SOURCE));
2255 screens[i].getstringsize(ptr, &w, &h);
2256 screens[i].putsxy(0, LCD_HEIGHT/2-h, ptr);
2257 screens[i].mono_bitmap(bitmap_icons_7x8[Icon_FastBackward],
2258 LCD_WIDTH/2 - 16, LCD_HEIGHT/2 - 4, 7, 8);
2261 /* trigger setup */
2262 ptr = str(LANG_SYSFONT_RECORD_TRIGGER);
2263 FOR_NB_SCREENS(i)
2265 screens[i].getstringsize(ptr,&w,&h);
2266 screens[i].putsxy((LCD_WIDTH-w)/2, LCD_HEIGHT - h*2, ptr);
2267 screens[i].mono_bitmap(bitmap_icons_7x8[Icon_DownArrow],
2268 LCD_WIDTH/2 - 3, LCD_HEIGHT - h*3, 7, 8);
2270 screens[i].update();
2273 button = button_get(true);
2274 switch (button) {
2275 case BUTTON_DOWN:
2276 case BUTTON_F3 | BUTTON_DOWN:
2277 #ifndef SIMULATOR
2278 rectrigger();
2279 settings_apply_trigger();
2280 #endif
2281 exit = true;
2282 break;
2284 case BUTTON_LEFT:
2285 case BUTTON_F3 | BUTTON_LEFT:
2286 global_settings.rec_source++;
2287 if(global_settings.rec_source > AUDIO_SRC_MAX)
2288 global_settings.rec_source = 0;
2289 used = true;
2290 break;
2292 case BUTTON_F3 | BUTTON_REL:
2293 if ( used )
2294 exit = true;
2295 used = true;
2296 break;
2298 case BUTTON_F3 | BUTTON_REPEAT:
2299 used = true;
2300 break;
2302 default:
2303 if(default_event_handler(button) == SYS_USB_CONNECTED)
2304 return true;
2305 break;
2309 rec_init_recording_options(&rec_options);
2310 rec_set_recording_options(&rec_options);
2312 set_gain();
2314 settings_save();
2315 FOR_NB_SCREENS(i)
2316 screens[i].setfont(FONT_UI);
2318 return false;
2320 #endif /* CONFIG_KEYPAD == RECORDER_PAD */
2322 #if CONFIG_CODEC == SWCODEC
2323 void audio_beep(int duration)
2325 /* dummy */
2326 (void)duration;
2329 #ifdef SIMULATOR
2330 /* stubs for recording sim */
2331 void audio_init_recording(unsigned int buffer_offset)
2333 buffer_offset = buffer_offset;
2336 void audio_close_recording(void)
2340 unsigned long pcm_rec_get_warnings(void)
2342 return 0;
2345 unsigned long pcm_rec_sample_rate(void)
2347 return 0;
2350 unsigned long audio_recorded_time(void)
2352 return 123;
2355 unsigned long audio_num_recorded_bytes(void)
2357 return 5 * 1024 * 1024;
2360 void rec_set_source(int source, unsigned flags)
2362 source = source;
2363 flags = flags;
2366 void audio_set_recording_options(struct audio_recording_options *options)
2368 options = options;
2371 void audio_set_recording_gain(int left, int right, int type)
2373 left = left;
2374 right = right;
2375 type = type;
2378 void audio_record(const char *filename)
2380 filename = filename;
2383 void audio_new_file(const char *filename)
2385 filename = filename;
2388 void audio_stop_recording(void)
2392 void audio_pause_recording(void)
2396 void audio_resume_recording(void)
2400 #endif /* #ifdef SIMULATOR */
2401 #endif /* #ifdef CONFIG_CODEC == SWCODEC */
2403 #endif /* HAVE_RECORDING */