fix yellow
[kugel-rb.git] / apps / recorder / recording.c
blobdea502c217e46106696dbf0b0fc1152084f06a69
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_BUF_SIZE (LCD_WIDTH)
280 #define HIST_Y (hist_pos_y+hist_size_h-1)
281 #define HIST_W (LCD_WIDTH / 2 - 4)
282 #if LCD_DEPTH > 1
283 #ifdef HAVE_LCD_COLOR
284 #define LCD_BAL_L LCD_RGBPACK(0, 0, 255)
285 #define LCD_BAL_R LCD_RGBPACK(204, 0, 0)
286 #define LCD_HIST_OVER LCD_RGBPACK(204, 0, 0)
287 #define LCD_HIST_HI LCD_RGBPACK(255, 204, 0)
288 #define LCD_HIST_OK LCD_RGBPACK(51, 153, 0)
289 #else /* HAVE_LCD_COLOR */
290 #define LCD_BATT_OK LCD_BLACK
291 #define LCD_BATT_LO LCD_DARKGRAY
292 #define LCD_DISK_OK LCD_BLACK
293 #define LCD_DISK_LO LCD_DARKGRAY
294 #define LCD_HIST_OVER LCD_BLACK
295 #define LCD_HIST_OK LCD_DARKGRAY
296 #define LCD_BAL LCD_DARKGRAY
297 #endif /* HAVE_LCD_COLOR */
298 #else /* LCD_DEPTH > 1 */
299 #define LCD_HIST_OVER LCD_DEFAULT_FG
300 #define LCD_HIST_OK LCD_DEFAULT_FG
301 #define LCD_BAL LCD_DEFAULT_FG
302 #endif /* LCD_DEPTH > 1 */
303 #endif /* HAVE_RECORDING_HISTOGRAM */
305 static void set_gain(void)
307 #ifdef HAVE_MIC_REC
308 if(global_settings.rec_source == AUDIO_SRC_MIC)
310 audio_set_recording_gain(global_settings.rec_mic_gain,
311 0, AUDIO_GAIN_MIC);
313 else
314 #endif /* MIC */
316 /* AUDIO_SRC_LINEIN, AUDIO_SRC_FMRADIO, AUDIO_SRC_SPDIF */
317 audio_set_recording_gain(global_settings.rec_left_gain,
318 global_settings.rec_right_gain,
319 AUDIO_GAIN_LINEIN);
321 /* reset the clipping indicators */
322 peak_meter_set_clip_hold(global_settings.peak_meter_clip_hold);
323 update_list = true;
326 #ifdef HAVE_AGC
327 /* Read peak meter values & calculate balance.
328 * Returns validity of peak values.
329 * Used for automatic gain control and history diagram.
331 static bool read_peak_levels(int *peak_l, int *peak_r, int *balance)
333 peak_meter_get_peakhold(peak_l, peak_r);
334 peak_valid_mem[peak_time % 3] = *peak_l;
335 if (((peak_valid_mem[0] == peak_valid_mem[1]) &&
336 (peak_valid_mem[1] == peak_valid_mem[2])) &&
337 ((*peak_l < 32767) || storage_disk_is_active()))
338 return false;
340 if (*peak_r > *peak_l)
341 balance_mem[peak_time % BAL_MEM_SIZE] = (*peak_l ?
342 MIN((10000 * *peak_r) / *peak_l - 10000, 15118) : 15118);
343 else
344 balance_mem[peak_time % BAL_MEM_SIZE] = (*peak_r ?
345 MAX(10000 - (10000 * *peak_l) / *peak_r, -15118) : -15118);
346 *balance = 0;
347 int i;
348 for (i = 0; i < BAL_MEM_SIZE; i++)
349 *balance += balance_mem[i];
350 *balance = *balance / BAL_MEM_SIZE;
352 #ifdef HAVE_RECORDING_HISTOGRAM
353 if (*peak_l > hist_l)
354 hist_l = *peak_l;
355 if (*peak_r > hist_r)
356 hist_r = *peak_r;
357 #endif
359 return true;
362 /* AGC helper function to check if maximum gain is reached */
363 static bool agc_gain_is_max(bool left, bool right)
365 /* range -128...+108 [0.5dB] */
366 short gain_current_l;
367 short gain_current_r;
369 if (agc_preset == 0)
370 return false;
372 switch (global_settings.rec_source)
374 #if defined(HAVE_LINE_REC) || defined(HAVE_FMRADIO_REC)
375 HAVE_LINE_REC_(case AUDIO_SRC_LINEIN:)
376 HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO:)
377 gain_current_l = global_settings.rec_left_gain;
378 gain_current_r = global_settings.rec_right_gain;
379 break;
380 #endif /* LINE, FMRADIO */
381 #if defined(HAVE_MIC_REC)
382 case AUDIO_SRC_MIC:
383 default:
384 gain_current_l = global_settings.rec_mic_gain;
385 gain_current_r = global_settings.rec_mic_gain;
386 #endif /* MIC */
389 return ((left && (gain_current_l >= agc_maxgain)) ||
390 (right && (gain_current_r >= agc_maxgain)));
393 static void change_recording_gain(bool increment, bool left, bool right)
395 int factor = (increment ? 1 : -1);
397 switch (global_settings.rec_source)
399 #if defined(HAVE_LINE_REC) || defined(HAVE_FMRADIO_REC)
400 HAVE_LINE_REC_(case AUDIO_SRC_LINEIN:)
401 HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO:)
402 if (left) global_settings.rec_left_gain += factor;
403 if (right) global_settings.rec_right_gain += factor;
404 break;
405 #endif /* LINE, FMRADIO */
406 #if defined(HAVE_MIC_REC)
407 case AUDIO_SRC_MIC:
408 global_settings.rec_mic_gain += factor;
409 #endif
414 * Handle automatic gain control (AGC).
415 * Change recording gain if peak_x levels are above or below
416 * target volume for specified timeouts.
418 static void auto_gain_control(int *peak_l, int *peak_r, int *balance)
420 int agc_mono;
421 short agc_mode;
422 bool increment;
424 if (*peak_l > agc_left)
425 agc_left = *peak_l;
426 else
427 agc_left -= (agc_left - *peak_l + 3) >> 2;
428 if (*peak_r > agc_right)
429 agc_right = *peak_r;
430 else
431 agc_right -= (agc_right - *peak_r + 3) >> 2;
432 agc_mono = (agc_left + agc_right) / 2;
434 agc_mode = abs(agc_preset) - 1;
435 if (agc_mode < 0) {
436 agc_enable = false;
437 return;
440 if (agc_mode != AGC_SAFETY_MODE) {
441 /* Automatic balance control - only if not in safety mode */
442 if ((agc_left > AGC_IMG) && (agc_right > AGC_IMG))
444 if (*balance < -556)
446 if (*balance > -900)
447 agc_baltime -= !(peak_time % 4); /* 0.47 - 0.75dB */
448 else if (*balance > -4125)
449 agc_baltime--; /* 0.75 - 3.00dB */
450 else if (*balance > -7579)
451 agc_baltime -= 2; /* 3.00 - 4.90dB */
452 else
453 agc_baltime -= !(peak_time % 8); /* 4.90 - inf dB */
454 if (agc_baltime > 0)
455 agc_baltime -= (peak_time % 2);
457 else if (*balance > 556)
459 if (*balance < 900)
460 agc_baltime += !(peak_time % 4);
461 else if (*balance < 4125)
462 agc_baltime++;
463 else if (*balance < 7579)
464 agc_baltime += 2;
465 else
466 agc_baltime += !(peak_time % 8);
467 if (agc_baltime < 0)
468 agc_baltime += (peak_time % 2);
471 if ((*balance * agc_baltime) < 0)
473 if (*balance < 0)
474 agc_baltime -= peak_time % 2;
475 else
476 agc_baltime += peak_time % 2;
479 increment = ((agc_risetime / 2) > agc_droptime);
481 if (agc_baltime < -agc_tbal[agc_mode])
483 if (!increment || !agc_gain_is_max(!increment, increment)) {
484 change_recording_gain(increment, !increment, increment);
485 set_gain();
487 agc_baltime = 0;
489 else if (agc_baltime > +agc_tbal[agc_mode])
491 if (!increment || !agc_gain_is_max(increment, !increment)) {
492 change_recording_gain(increment, increment, !increment);
493 set_gain();
495 agc_baltime = 0;
498 else if (!(hist_time % 4))
500 if (agc_baltime < 0)
501 agc_baltime++;
502 else
503 agc_baltime--;
507 /* Automatic gain control */
508 if ((agc_left > agc_th_hi[agc_mode]) || (agc_right > agc_th_hi[agc_mode]))
510 if ((agc_left > AGC_CLIP) || (agc_right > AGC_CLIP))
511 agc_droptime += agc_tdrop[agc_mode] /
512 (global_settings.rec_agc_cliptime + 1);
513 if (agc_left > AGC_HIGH) {
514 agc_droptime++;
515 agc_risetime=0;
516 if (agc_left > AGC_PEAK)
517 agc_droptime += 2;
519 if (agc_right > AGC_HIGH) {
520 agc_droptime++;
521 agc_risetime=0;
522 if (agc_right > AGC_PEAK)
523 agc_droptime += 2;
525 if (agc_mono > agc_th_hi[agc_mode])
526 agc_droptime++;
527 else
528 agc_droptime += !(peak_time % 2);
530 if (agc_droptime >= agc_tdrop[agc_mode])
532 change_recording_gain(false, true, true);
533 agc_droptime = 0;
534 agc_risetime = 0;
535 set_gain();
537 agc_risetime = MAX(agc_risetime - 1, 0);
539 else if (agc_mono < agc_th_lo[agc_mode])
541 if (agc_mono < (agc_th_lo[agc_mode] / 8))
542 agc_risetime += !(peak_time % 5);
543 else if (agc_mono < (agc_th_lo[agc_mode] / 2))
544 agc_risetime += 2;
545 else
546 agc_risetime++;
548 if (agc_risetime >= agc_trise[agc_mode]) {
549 if ((agc_mode != AGC_SAFETY_MODE) &&
550 (!agc_gain_is_max(true, true))) {
551 change_recording_gain(true, true, true);
552 set_gain();
554 agc_risetime = 0;
555 agc_droptime = 0;
557 agc_droptime = MAX(agc_droptime - 1, 0);
559 else if (!(peak_time % 6)) /* on target level every 1.2 sec */
561 agc_risetime = MAX(agc_risetime - 1, 0);
562 agc_droptime = MAX(agc_droptime - 1, 0);
565 #endif /* HAVE_AGC */
567 static const char* const fmtstr[] =
569 "%c%d %s", /* no decimals */
570 "%c%d.%d %s ", /* 1 decimal */
571 "%c%d.%02d %s " /* 2 decimals */
574 static char *fmt_gain(int snd, int val, char *str, int len)
576 int i, d, numdec;
577 const char *unit;
578 char sign = ' ';
580 val = sound_val2phys(snd, val);
581 if(val < 0)
583 sign = '-';
584 val = -val;
586 numdec = sound_numdecimals(snd);
587 unit = sound_unit(snd);
589 if(numdec)
591 i = val / (10*numdec);
592 d = val % (10*numdec);
593 snprintf(str, len, fmtstr[numdec], sign, i, d, unit);
595 else
596 snprintf(str, len, fmtstr[numdec], sign, val, unit);
598 return str;
601 /* the list below must match enum audio_sources in audio.h */
602 static const char* const prestr[] =
604 HAVE_MIC_IN_([AUDIO_SRC_MIC] = "R_MIC_",)
605 HAVE_LINE_REC_([AUDIO_SRC_LINEIN] = "R_LINE_",)
606 HAVE_SPDIF_IN_([AUDIO_SRC_SPDIF] = "R_SPDIF_",)
607 HAVE_FMRADIO_REC_([AUDIO_SRC_FMRADIO] = "R_FM_",)
610 char *rec_create_filename(char *buffer)
612 char ext[16];
613 const char *pref = "R_";
615 /* Directory existence and writeablility should have already been
616 * verified - do not pass NULL pointers to pcmrec */
618 if((unsigned)global_settings.rec_source < AUDIO_NUM_SOURCES)
620 pref = prestr[global_settings.rec_source];
623 strcpy(buffer, global_settings.rec_directory);
625 snprintf(ext, sizeof(ext), ".%s",
626 REC_FILE_ENDING(global_settings.rec_format));
628 #if CONFIG_RTC == 0
629 return create_numbered_filename(buffer, buffer, pref, ext, 4,
630 &file_number);
631 #else
632 /* We'll wait at least up to the start of the next second so no duplicate
633 names are created */
634 return create_datetime_filename(buffer, buffer, pref, ext, true);
635 #endif
638 #if CONFIG_RTC == 0
639 /* Hit disk to get a starting filename for the type */
640 static void rec_init_filename(void)
642 file_number = -1;
643 rec_create_filename(path_buffer);
644 file_number--;
646 #endif
648 int rec_create_directory(void)
650 int rc = 0;
651 const char * const folder = global_settings.rec_directory;
653 if (strcmp(folder, "/") && !dir_exists(folder))
655 rc = mkdir(folder);
657 if(rc < 0)
659 while (action_userabort(HZ) == false)
661 splashf(0, "%s %s",
662 str(LANG_REC_DIR_NOT_WRITABLE),
663 str(LANG_OFF_ABORT));
666 else
668 rec_status |= RCSTAT_CREATED_DIRECTORY;
669 rc = 1;
673 return rc;
676 void rec_init_recording_options(struct audio_recording_options *options)
678 options->rec_source = global_settings.rec_source;
679 options->rec_frequency = global_settings.rec_frequency;
680 options->rec_channels = global_settings.rec_channels;
681 options->rec_prerecord_time = global_settings.rec_prerecord_time;
682 #if CONFIG_CODEC == SWCODEC
683 options->rec_mono_mode = global_settings.rec_mono_mode;
684 options->rec_source_flags = 0;
685 options->enc_config.rec_format = global_settings.rec_format;
686 global_to_encoder_config(&options->enc_config);
687 #else
688 options->rec_quality = global_settings.rec_quality;
689 options->rec_editable = global_settings.rec_editable;
690 #endif
693 #if CONFIG_CODEC == SWCODEC && !defined (SIMULATOR)
694 void rec_set_source(int source, unsigned flags)
696 /* Set audio input source, power up/down devices */
697 audio_set_input_source(source, flags);
699 /* Set peakmeters for recording or reset to playback */
700 peak_meter_playback((flags & SRCF_RECORDING) == 0);
701 peak_meter_enabled = true;
703 #endif /* CONFIG_CODEC == SWCODEC && !defined (SIMULATOR) */
705 void rec_set_recording_options(struct audio_recording_options *options)
707 #if CONFIG_CODEC != SWCODEC
708 if (global_settings.rec_prerecord_time)
710 talk_buffer_steal(); /* will use the mp3 buffer */
712 #else /* == SWCODEC */
713 rec_set_source(options->rec_source,
714 options->rec_source_flags | SRCF_RECORDING);
715 #endif /* CONFIG_CODEC != SWCODEC */
717 audio_set_recording_options(options);
720 void rec_command(enum recording_command cmd)
722 switch(cmd)
724 case RECORDING_CMD_STOP_SHUTDOWN:
725 pm_activate_clipcount(false);
726 audio_stop_recording();
727 #if CONFIG_CODEC == SWCODEC
728 audio_close_recording();
729 #endif
730 sys_poweroff();
731 break;
732 case RECORDING_CMD_STOP:
733 pm_activate_clipcount(false);
734 audio_stop_recording();
735 break;
736 case RECORDING_CMD_START:
737 /* steal mp3 buffer, create unique filename and start recording */
738 pm_reset_clipcount();
739 pm_activate_clipcount(true);
740 #if CONFIG_CODEC != SWCODEC
741 talk_buffer_steal(); /* we use the mp3 buffer */
742 #endif
743 audio_record(rec_create_filename(path_buffer));
744 break;
745 case RECORDING_CMD_START_NEWFILE:
746 /* create unique filename and start recording*/
747 pm_reset_clipcount();
748 pm_activate_clipcount(true); /* just to be sure */
749 audio_new_file(rec_create_filename(path_buffer));
750 break;
751 case RECORDING_CMD_PAUSE:
752 pm_activate_clipcount(false);
753 audio_pause_recording();
754 break;
755 case RECORDING_CMD_RESUME:
756 pm_activate_clipcount(true);
757 audio_resume_recording();
758 break;
760 update_list = true;
763 /* used in trigger_listerner and recording_screen */
764 static unsigned int last_seconds = 0;
767 * Callback function so that the peak meter code can send an event
768 * to this application. This function can be passed to
769 * peak_meter_set_trigger_listener in order to activate the trigger.
771 static void trigger_listener(int trigger_status)
773 switch (trigger_status)
775 case TRIG_GO:
776 if(!(audio_status() & AUDIO_STATUS_RECORD))
778 rec_status |= RCSTAT_HAVE_RECORDED;
779 rec_command(RECORDING_CMD_START);
780 #if CONFIG_CODEC != SWCODEC
781 /* give control to mpeg thread so that it can start
782 recording */
783 yield(); yield(); yield();
784 #endif
787 /* if we're already recording this is a retrigger */
788 else
790 if((audio_status() & AUDIO_STATUS_PAUSE) &&
791 (global_settings.rec_trigger_type == TRIG_TYPE_PAUSE))
793 rec_command(RECORDING_CMD_RESUME);
795 /* New file on trig start*/
796 else if (global_settings.rec_trigger_type != TRIG_TYPE_NEW_FILE)
798 rec_command(RECORDING_CMD_START_NEWFILE);
799 /* tell recording_screen to reset the time */
800 last_seconds = 0;
803 break;
805 /* A _change_ to TRIG_READY means the current recording has stopped */
806 case TRIG_READY:
807 if(audio_status() & AUDIO_STATUS_RECORD)
809 switch(global_settings.rec_trigger_type)
811 case TRIG_TYPE_STOP: /* Stop */
812 rec_command(RECORDING_CMD_STOP);
813 break;
815 case TRIG_TYPE_PAUSE: /* Pause */
816 rec_command(RECORDING_CMD_PAUSE);
817 break;
819 case TRIG_TYPE_NEW_FILE: /* New file on trig stop*/
820 rec_command(RECORDING_CMD_START_NEWFILE);
821 /* tell recording_screen to reset the time */
822 last_seconds = 0;
823 break;
825 case 3: /* Stop and shutdown */
826 rec_command(RECORDING_CMD_STOP_SHUTDOWN);
827 break;
830 if (global_settings.rec_trigger_mode != TRIG_MODE_REARM)
832 peak_meter_set_trigger_listener(NULL);
833 peak_meter_trigger(false);
836 break;
840 /* Stuff for drawing the screen */
842 enum rec_list_items_stereo {
843 ITEM_VOLUME = 0,
844 ITEM_GAIN = 1,
845 ITEM_GAIN_L = 2,
846 ITEM_GAIN_R = 3,
847 #ifdef HAVE_AGC
848 ITEM_AGC_MODE = 4,
849 ITEM_AGC_MAXDB = 5,
850 ITEM_FILENAME = 7,
851 ITEM_COUNT = 7,
852 #else
853 ITEM_FILENAME = 7,
854 ITEM_COUNT = 5,
855 #endif
858 enum rec_list_items_mono {
859 ITEM_VOLUME_M = 0,
860 ITEM_GAIN_M = 1,
861 #ifdef HAVE_AGC
862 ITEM_AGC_MODE_M = 4,
863 ITEM_AGC_MAXDB_M = 5,
864 ITEM_FILENAME_M = 7,
865 ITEM_COUNT_M = 5,
866 #else
867 ITEM_FILENAME_M = 7,
868 ITEM_COUNT_M = 3,
869 #endif
872 #ifdef HAVE_SPDIF_REC
873 enum rec_list_items_spdif {
874 ITEM_VOLUME_D = 0,
875 #if CONFIG_CODEC == SWCODEC
876 ITEM_SAMPLERATE_D = 6,
877 ITEM_FILENAME_D = 7,
878 ITEM_COUNT_D = 3,
879 #else
880 ITEM_FILENAME_D = 7,
881 ITEM_COUNT_D = 2,
882 #endif
884 #endif
886 static int listid_to_enum[ITEM_COUNT];
888 static const char* reclist_get_name(int selected_item, void * data,
889 char * buffer, size_t buffer_len)
891 char buf2[32];
892 #ifdef HAVE_AGC
893 char buf3[32];
894 #endif
895 data = data; /* not used */
896 if(selected_item >= ITEM_COUNT)
897 return "";
899 switch (listid_to_enum[selected_item])
901 case ITEM_VOLUME:
902 snprintf(buffer, buffer_len, "%s: %s", str(LANG_VOLUME),
903 fmt_gain(SOUND_VOLUME,
904 global_settings.volume,
905 buf2, sizeof(buf2)));
906 break;
907 case ITEM_GAIN:
908 #ifdef HAVE_MIC_REC
909 if(global_settings.rec_source == AUDIO_SRC_MIC)
911 /* Draw MIC recording gain */
912 snprintf(buffer, buffer_len, "%s: %s", str(LANG_GAIN),
913 fmt_gain(SOUND_MIC_GAIN,
914 global_settings.rec_mic_gain,
915 buf2, sizeof(buf2)));
917 else
918 #endif /* MIC */
920 int avg_gain = (global_settings.rec_left_gain +
921 global_settings.rec_right_gain) / 2;
922 snprintf(buffer, buffer_len, "%s: %s", str(LANG_GAIN),
923 fmt_gain(SOUND_LEFT_GAIN,
924 avg_gain,
925 buf2, sizeof(buf2)));
927 break;
928 case ITEM_GAIN_L:
929 snprintf(buffer, buffer_len, "%s: %s",
930 str(LANG_GAIN_LEFT),
931 fmt_gain(SOUND_LEFT_GAIN,
932 global_settings.rec_left_gain,
933 buf2, sizeof(buf2)));
934 break;
935 case ITEM_GAIN_R:
936 snprintf(buffer, buffer_len, "%s: %s",
937 str(LANG_GAIN_RIGHT),
938 fmt_gain(SOUND_RIGHT_GAIN,
939 global_settings.rec_right_gain,
940 buf2, sizeof(buf2)));
941 break;
942 #ifdef HAVE_AGC
943 case ITEM_AGC_MODE:
944 snprintf(buffer, buffer_len, "%s: %s",
945 str(LANG_RECORDING_AGC_PRESET),
946 agc_preset_str[agc_preset]);
947 break;
948 case ITEM_AGC_MAXDB:
949 if (agc_preset == 0)
950 snprintf(buffer, buffer_len, "%s: %s",
951 str(LANG_RECORDING_AGC_MAXGAIN),
952 fmt_gain(SOUND_LEFT_GAIN,
953 agc_maxgain, buf2, sizeof(buf2)));
954 #ifdef HAVE_MIC_REC
955 else if (global_settings.rec_source == AUDIO_SRC_MIC)
956 snprintf(buffer, buffer_len, "%s: %s (%s)",
957 str(LANG_RECORDING_AGC_MAXGAIN),
958 fmt_gain(SOUND_MIC_GAIN,
959 agc_maxgain, buf2, sizeof(buf2)),
960 fmt_gain(SOUND_MIC_GAIN,
961 agc_maxgain - global_settings.rec_mic_gain,
962 buf3, sizeof(buf3)));
963 else
964 #endif /* MIC */
965 snprintf(buffer, buffer_len, "%s: %s (%s)",
966 str(LANG_RECORDING_AGC_MAXGAIN),
967 fmt_gain(SOUND_LEFT_GAIN,
968 agc_maxgain, buf2, sizeof(buf2)),
969 fmt_gain(SOUND_LEFT_GAIN,
970 agc_maxgain -
971 (global_settings.rec_left_gain +
972 global_settings.rec_right_gain)/2,
973 buf3, sizeof(buf3)));
974 break;
975 #endif
976 #if CONFIG_CODEC == SWCODEC
977 #ifdef HAVE_SPDIF_REC
978 case ITEM_SAMPLERATE_D:
979 snprintf(buffer, buffer_len, "%s: %d",
980 str(LANG_RECORDING_FREQUENCY),
981 pcm_rec_sample_rate());
982 break;
983 #endif
984 #endif
985 case ITEM_FILENAME:
987 if(audio_status() & AUDIO_STATUS_RECORD)
989 size_t tot_len = strlen(path_buffer) +
990 strlen(str(LANG_RECORDING_FILENAME)) + 1;
991 if(tot_len > buffer_len)
993 snprintf(buffer, buffer_len, "%s %s",
994 str(LANG_RECORDING_FILENAME),
995 path_buffer + tot_len - buffer_len);
997 else
999 snprintf(buffer, buffer_len, "%s %s",
1000 str(LANG_RECORDING_FILENAME), path_buffer);
1003 else
1005 return str(LANG_RECORDING_FILENAME);
1007 break;
1009 default:
1010 return "";
1012 return buffer;
1016 bool recording_start_automatic = false;
1018 bool recording_screen(bool no_source)
1020 int button;
1021 int done = -1; /* negative to re-init, positive to quit, zero to run */
1022 char buf[32]; /* for preparing strings */
1023 char buf2[32]; /* for preparing strings */
1024 int w, h; /* character width/height */
1025 int update_countdown = 0; /* refresh counter */
1026 unsigned int seconds;
1027 int hours, minutes;
1028 int audio_stat = 0; /* status of the audio system */
1029 int last_audio_stat = -1; /* previous status so we can act on changes */
1030 struct viewport vp_list[NB_SCREENS], vp_top[NB_SCREENS]; /* the viewports */
1032 #if CONFIG_CODEC == SWCODEC
1033 int warning_counter = 0;
1034 #define WARNING_PERIOD 7
1035 #endif
1037 #if CONFIG_CODEC == SWCODEC
1038 #ifdef HAVE_SPDIF_REC
1039 unsigned long prev_sample_rate = 0;
1040 #endif
1041 #endif
1043 #ifdef HAVE_FMRADIO_REC
1044 /* Radio is left on if:
1045 * 1) Is was on at the start and the initial source is FM Radio
1046 * 2) 1) and the source was never changed to something else
1048 int radio_status = (global_settings.rec_source != AUDIO_SRC_FMRADIO) ?
1049 FMRADIO_OFF : get_radio_status();
1050 #endif
1051 #if (CONFIG_LED == LED_REAL)
1052 bool led_state = false;
1053 int led_countdown = 2;
1054 #endif
1055 #ifdef HAVE_AGC
1056 bool peak_read = false;
1057 int peak_l, peak_r;
1058 int balance = 0;
1059 #endif
1060 int i;
1061 int pm_x[NB_SCREENS]; /* peakmeter (and trigger bar) x pos */
1062 int pm_y[NB_SCREENS]; /* peakmeter y pos */
1063 int pm_h[NB_SCREENS]; /* peakmeter height */
1064 int trig_ypos[NB_SCREENS]; /* trigger bar y pos */
1065 int trig_width[NB_SCREENS]; /* trigger bar width */
1066 int top_height_req[NB_SCREENS]; /* required height for top half */
1067 bool compact_view[NB_SCREENS]; /* tweak layout tiny screens / big fonts */
1068 struct gui_synclist lists; /* the list in the bottom vp */
1069 #if defined(HAVE_AGC) || defined(HAVE_RECORDING_HISTOGRAM)
1070 bool peak_valid = false;
1071 #endif
1072 #if defined(HAVE_RECORDING_HISTOGRAM)
1073 int j;
1074 unsigned short hist_pos_y = 0;
1075 unsigned short hist_size_h = 0;
1076 int history_pos = 0;
1077 short hist_time_interval = 1; /* 1, 2, 4, 8 */
1078 unsigned char history_l[HIST_BUF_SIZE];
1079 unsigned char history_r[HIST_BUF_SIZE];
1080 const char hist_level_marks[6] = { 29, 26, 23, 17, 9, 2};
1081 #endif
1082 #ifdef HAVE_FMRADIO_REC
1083 int prev_rec_source = global_settings.rec_source; /* detect source change */
1084 #endif
1086 struct audio_recording_options rec_options;
1087 rec_status = RCSTAT_IN_RECSCREEN;
1089 #if (CONFIG_STORAGE & STORAGE_ATA) && (CONFIG_LED == LED_REAL) \
1090 && !defined(SIMULATOR)
1091 ata_set_led_enabled(false);
1092 #endif
1094 #if CONFIG_CODEC == SWCODEC
1095 /* recording_menu gets messed up: so prevent manus talking */
1096 talk_disable(true);
1097 /* audio_init_recording stops anything playing when it takes the audio
1098 buffer */
1099 #else
1100 /* Yes, we use the D/A for monitoring */
1101 peak_meter_enabled = true;
1102 peak_meter_playback(true);
1103 #endif
1105 #ifdef HAVE_AGC
1106 peak_meter_get_peakhold(&peak_l, &peak_r);
1107 #endif
1109 pm_reset_clipcount();
1110 pm_activate_clipcount(false);
1111 settings_apply_trigger();
1113 #ifdef HAVE_AGC
1114 agc_preset_str[0] = str(LANG_OFF);
1115 agc_preset_str[1] = str(LANG_AGC_SAFETY);
1116 agc_preset_str[2] = str(LANG_AGC_LIVE);
1117 agc_preset_str[3] = str(LANG_AGC_DJSET);
1118 agc_preset_str[4] = str(LANG_AGC_MEDIUM);
1119 agc_preset_str[5] = str(LANG_AGC_VOICE);
1120 #endif /* HAVE_AGC */
1122 #ifdef HAVE_SPEAKER
1123 /* Disable speaker to prevent feedback */
1124 audiohw_enable_speaker(false);
1125 #endif
1127 #if CONFIG_CODEC == SWCODEC
1128 audio_close_recording();
1129 #endif
1130 audio_init_recording(0);
1131 sound_set_volume(global_settings.volume);
1133 #if CONFIG_RTC == 0
1134 /* Create new filename for recording start */
1135 rec_init_filename();
1136 #endif
1138 /* start of the loop: we stay in this loop until user quits recscreen */
1139 while(done <= 0)
1141 if(done < 0)
1143 /* request to re-init stuff, done after settings screen */
1144 done = 0;
1145 #ifdef HAVE_FMRADIO_REC
1146 /* If input changes away from FM Radio,
1147 radio will remain off when recording screen closes. */
1148 if (global_settings.rec_source != prev_rec_source
1149 && prev_rec_source == AUDIO_SRC_FMRADIO)
1150 radio_status = FMRADIO_OFF;
1151 prev_rec_source = global_settings.rec_source;
1152 #endif
1154 /* viewport init and calculations that only needs to be done once */
1155 FOR_NB_SCREENS(i)
1157 struct viewport *v;
1158 /* top vp, 4 lines, force sys font if total screen < 6 lines
1159 NOTE: one could limit the list to 1 line and get away with 5 lines */
1160 top_height_req[i] = 4;
1161 #if defined(HAVE_RECORDING_HISTOGRAM)
1162 if((global_settings.rec_histogram_interval) && (!i))
1163 top_height_req[i] += 1; /* use one line for histogram */
1164 hist_time_interval = 1 << global_settings.rec_histogram_interval;
1165 #endif
1166 v = &vp_top[i];
1167 viewport_set_defaults(v, i);
1168 if (viewport_get_nb_lines(v) < top_height_req[i])
1170 /* compact needs 4 lines total */
1171 v->font = FONT_SYSFIXED;
1172 compact_view[i] = false;
1174 else
1176 /*top=4,list=2*/
1177 if (viewport_get_nb_lines(v) < (top_height_req[i]+2))
1178 compact_view[i] = true;
1179 else
1180 compact_view[i] = false;
1182 vp_list[i] = *v; /* get a copy now so it can be sized more easily */
1183 v->height = (font_get(v->font)->height)*(compact_view[i] ? 3 :
1184 top_height_req[i]);
1186 /* list section, rest of the screen */
1187 vp_list[i].y += vp_top[i].height;
1188 vp_list[i].height -= vp_top[i].height;
1189 screens[i].set_viewport(&vp_top[i]); /* req for next calls */
1191 screens[i].getstringsize("W", &w, &h);
1192 pm_y[i] = font_get(vp_top[i].font)->height * 2;
1193 trig_ypos[i] = font_get(vp_top[i].font)->height * 3;
1194 if(compact_view[i])
1195 trig_ypos[i] -= (font_get(vp_top[i].font)->height)/2;
1198 /* init the bottom list */
1199 gui_synclist_init(&lists, reclist_get_name, NULL, false, 1, vp_list);
1200 gui_synclist_set_title(&lists, NULL, Icon_NOICON);
1202 send_event(GUI_EVENT_ACTIONUPDATE, (void*)1); /* force a redraw */
1204 #if defined(HAVE_RECORDING_HISTOGRAM)
1205 history_pos = 0;
1206 hist_pos_y = (compact_view[0] ? 3 : 4) * (font_get(vp_top[0].font)->height)
1207 + 1;
1208 hist_size_h = font_get(vp_top[0].font)->height - 2;
1209 memset(history_l, 0, sizeof(unsigned char)*HIST_BUF_SIZE);
1210 memset(history_r, 0, sizeof(unsigned char)*HIST_BUF_SIZE);
1211 #endif
1213 FOR_NB_SCREENS(i)
1215 pm_x[i] = 0;
1216 if(global_settings.peak_meter_clipcounter)
1218 int clipwidth = 0;
1219 screens[i].getstringsize(str(LANG_PM_CLIPCOUNT),
1220 &clipwidth, &h); /* h is same */
1221 pm_x[i] = clipwidth+1;
1223 if(global_settings.rec_trigger_mode == TRIG_MODE_OFF)
1224 pm_h[i] = font_get(vp_top[i].font)->height * 2;
1225 else
1226 pm_h[i] = font_get(vp_top[i].font)->height;
1227 if(compact_view[i])
1228 pm_h[i] /= 2;
1229 trig_width[i] = vp_top[i].width - pm_x[i];
1232 #if CONFIG_CODEC == SWCODEC
1233 audio_close_recording();
1234 audio_init_recording(0);
1235 #endif
1237 rec_init_recording_options(&rec_options);
1238 rec_set_recording_options(&rec_options);
1240 if(rec_create_directory() < 0)
1242 rec_status = 0;
1243 goto rec_abort;
1246 #if CONFIG_CODEC == SWCODEC && CONFIG_RTC == 0
1247 /* If format changed, a new number is required */
1248 rec_init_filename();
1249 #endif
1251 #ifdef HAVE_AGC
1252 #ifdef HAVE_MIC_REC
1253 if (global_settings.rec_source == AUDIO_SRC_MIC) {
1254 agc_preset = global_settings.rec_agc_preset_mic;
1255 agc_maxgain = global_settings.rec_agc_maxgain_mic;
1257 else
1258 #endif /* MIC */
1260 agc_preset = global_settings.rec_agc_preset_line;
1261 agc_maxgain = global_settings.rec_agc_maxgain_line;
1263 #endif /* HAVE_AGC */
1265 set_gain();
1266 update_countdown = 0; /* Update immediately */
1268 /* populate translation table for list id -> enum */
1269 #ifdef HAVE_SPDIF_REC
1270 if(global_settings.rec_source == AUDIO_SRC_SPDIF)
1272 listid_to_enum[0] = ITEM_VOLUME_D;
1273 #if CONFIG_CODEC == SWCODEC
1274 listid_to_enum[1] = ITEM_SAMPLERATE_D;
1275 listid_to_enum[2] = ITEM_FILENAME_D;
1276 #else
1277 listid_to_enum[1] = ITEM_FILENAME_D;
1278 #endif
1280 gui_synclist_set_nb_items(&lists, ITEM_COUNT_D); /* spdif */
1282 else
1283 #endif
1284 if(HAVE_MIC_REC_((global_settings.rec_source == AUDIO_SRC_MIC) || )
1285 (global_settings.rec_channels == 1))
1287 listid_to_enum[0] = ITEM_VOLUME_M;
1288 listid_to_enum[1] = ITEM_GAIN_M;
1289 #ifdef HAVE_AGC
1290 listid_to_enum[2] = ITEM_AGC_MODE_M;
1291 listid_to_enum[3] = ITEM_AGC_MAXDB_M;
1292 listid_to_enum[4] = ITEM_FILENAME_M;
1293 #else
1294 listid_to_enum[2] = ITEM_FILENAME_M;
1295 #endif
1296 gui_synclist_set_nb_items(&lists, ITEM_COUNT_M); /* mono */
1298 else
1300 listid_to_enum[0] = ITEM_VOLUME;
1301 listid_to_enum[1] = ITEM_GAIN;
1302 listid_to_enum[2] = ITEM_GAIN_L;
1303 listid_to_enum[3] = ITEM_GAIN_R;
1304 #ifdef HAVE_AGC
1305 listid_to_enum[4] = ITEM_AGC_MODE;
1306 listid_to_enum[5] = ITEM_AGC_MAXDB;
1307 listid_to_enum[6] = ITEM_FILENAME;
1308 #else
1309 listid_to_enum[4] = ITEM_FILENAME;
1310 #endif
1311 gui_synclist_set_nb_items(&lists, ITEM_COUNT); /* stereo */
1314 gui_synclist_draw(&lists);
1315 } /* if(done < 0) */
1317 audio_stat = audio_status();
1319 #if (CONFIG_LED == LED_REAL)
1322 * Flash the LED while waiting to record. Turn it on while
1323 * recording.
1325 if(audio_stat & AUDIO_STATUS_RECORD)
1327 if (audio_stat & AUDIO_STATUS_PAUSE)
1329 if (--led_countdown <= 0)
1331 led_state = !led_state;
1332 led(led_state);
1333 led_countdown = 2;
1336 else
1338 /* trigger is on in status TRIG_READY (no check needed) */
1339 led(true);
1342 else
1344 int trig_stat = peak_meter_trigger_status();
1346 * other trigger stati than trig_off and trig_steady
1347 * already imply that we are recording.
1349 if (trig_stat == TRIG_STEADY)
1351 if (--led_countdown <= 0)
1353 led_state = !led_state;
1354 led(led_state);
1355 led_countdown = 2;
1358 else
1360 /* trigger is on in status TRIG_READY (no check needed) */
1361 led(false);
1364 #endif /* CONFIG_LED */
1366 /* Wait for a button a while (HZ/10) drawing the peak meter */
1367 button = peak_meter_draw_get_btn(CONTEXT_RECSCREEN,
1368 pm_x, pm_y, pm_h,
1369 screen_update, vp_top);
1370 if (last_audio_stat != audio_stat)
1372 if (audio_stat & AUDIO_STATUS_RECORD)
1374 rec_status |= RCSTAT_HAVE_RECORDED;
1376 last_audio_stat = audio_stat;
1377 update_list = true;
1380 if (recording_start_automatic)
1382 /* simulate a button press */
1383 button = ACTION_REC_PAUSE;
1384 recording_start_automatic = false;
1387 /* let list handle the button */
1388 gui_synclist_do_button(&lists, &button, LIST_WRAP_UNLESS_HELD);
1391 switch(button)
1393 case ACTION_SETTINGS_INC:
1394 case ACTION_SETTINGS_INCREPEAT:
1395 switch (listid_to_enum[gui_synclist_get_sel_pos(&lists)])
1397 case ITEM_VOLUME:
1398 global_settings.volume++;
1399 setvol();
1400 break;
1401 case ITEM_GAIN:
1402 #ifdef HAVE_MIC_REC
1403 if(global_settings.rec_source == AUDIO_SRC_MIC)
1405 if(global_settings.rec_mic_gain <
1406 sound_max(SOUND_MIC_GAIN))
1407 global_settings.rec_mic_gain++;
1409 else
1410 #endif /* MIC */
1412 if(global_settings.rec_left_gain <
1413 sound_max(SOUND_LEFT_GAIN))
1414 global_settings.rec_left_gain++;
1415 if(global_settings.rec_right_gain <
1416 sound_max(SOUND_RIGHT_GAIN))
1417 global_settings.rec_right_gain++;
1419 break;
1420 case ITEM_GAIN_L:
1421 if(global_settings.rec_left_gain <
1422 sound_max(SOUND_LEFT_GAIN))
1423 global_settings.rec_left_gain++;
1424 break;
1425 case ITEM_GAIN_R:
1426 if(global_settings.rec_right_gain <
1427 sound_max(SOUND_RIGHT_GAIN))
1428 global_settings.rec_right_gain++;
1429 break;
1430 #ifdef HAVE_AGC
1431 case ITEM_AGC_MODE:
1432 agc_preset = MIN(agc_preset + 1, AGC_MODE_SIZE);
1433 agc_enable = (agc_preset != 0);
1434 #ifdef HAVE_MIC_REC
1435 if (global_settings.rec_source == AUDIO_SRC_MIC) {
1436 global_settings.rec_agc_preset_mic = agc_preset;
1437 agc_maxgain = global_settings.rec_agc_maxgain_mic;
1438 } else
1439 #endif /* MIC */
1441 global_settings.rec_agc_preset_line = agc_preset;
1442 agc_maxgain = global_settings.rec_agc_maxgain_line;
1444 break;
1445 case ITEM_AGC_MAXDB:
1446 #ifdef HAVE_MIC_REC
1447 if (global_settings.rec_source == AUDIO_SRC_MIC)
1449 agc_maxgain = MIN(agc_maxgain + 1,
1450 sound_max(SOUND_MIC_GAIN));
1451 global_settings.rec_agc_maxgain_mic = agc_maxgain;
1453 else
1454 #endif /* MIC */
1456 agc_maxgain = MIN(agc_maxgain + 1,
1457 sound_max(SOUND_LEFT_GAIN));
1458 global_settings.rec_agc_maxgain_line = agc_maxgain;
1460 break;
1461 #endif /* HAVE_AGC */
1463 set_gain();
1464 update_countdown = 0; /* Update immediately */
1465 break;
1466 case ACTION_SETTINGS_DEC:
1467 case ACTION_SETTINGS_DECREPEAT:
1468 switch (listid_to_enum[gui_synclist_get_sel_pos(&lists)])
1470 case ITEM_VOLUME:
1471 global_settings.volume--;
1472 setvol();
1473 break;
1474 case ITEM_GAIN:
1475 #ifdef HAVE_MIC_REC
1476 if(global_settings.rec_source == AUDIO_SRC_MIC)
1478 if(global_settings.rec_mic_gain >
1479 sound_min(SOUND_MIC_GAIN))
1480 global_settings.rec_mic_gain--;
1482 else
1483 #endif /* MIC */
1485 if(global_settings.rec_left_gain >
1486 sound_min(SOUND_LEFT_GAIN))
1487 global_settings.rec_left_gain--;
1488 if(global_settings.rec_right_gain >
1489 sound_min(SOUND_RIGHT_GAIN))
1490 global_settings.rec_right_gain--;
1492 break;
1493 case ITEM_GAIN_L:
1494 if(global_settings.rec_left_gain >
1495 sound_min(SOUND_LEFT_GAIN))
1496 global_settings.rec_left_gain--;
1497 break;
1498 case ITEM_GAIN_R:
1499 if(global_settings.rec_right_gain >
1500 sound_min(SOUND_RIGHT_GAIN))
1501 global_settings.rec_right_gain--;
1502 break;
1503 #ifdef HAVE_AGC
1504 case ITEM_AGC_MODE:
1505 agc_preset = MAX(agc_preset - 1, 0);
1506 agc_enable = (agc_preset != 0);
1507 #ifdef HAVE_MIC_REC
1508 if (global_settings.rec_source == AUDIO_SRC_MIC) {
1509 global_settings.rec_agc_preset_mic = agc_preset;
1510 agc_maxgain = global_settings.rec_agc_maxgain_mic;
1511 } else
1512 #endif /* MIC */
1514 global_settings.rec_agc_preset_line = agc_preset;
1515 agc_maxgain = global_settings.rec_agc_maxgain_line;
1517 break;
1518 case ITEM_AGC_MAXDB:
1519 #ifdef HAVE_MIC_REC
1520 if (global_settings.rec_source == AUDIO_SRC_MIC)
1522 agc_maxgain = MAX(agc_maxgain - 1,
1523 sound_min(SOUND_MIC_GAIN));
1524 global_settings.rec_agc_maxgain_mic = agc_maxgain;
1525 } else
1526 #endif /* MIC */
1528 agc_maxgain = MAX(agc_maxgain - 1,
1529 sound_min(SOUND_LEFT_GAIN));
1530 global_settings.rec_agc_maxgain_line = agc_maxgain;
1532 break;
1533 #endif /* HAVE_AGC */
1535 set_gain();
1536 update_countdown = 0; /* Update immediately */
1537 break;
1538 case ACTION_STD_CANCEL:
1539 /* turn off the trigger */
1540 peak_meter_trigger(false);
1541 peak_meter_set_trigger_listener(NULL);
1543 if(audio_stat & AUDIO_STATUS_RECORD)
1545 rec_command(RECORDING_CMD_STOP);
1547 else
1549 #if CONFIG_CODEC != SWCODEC
1550 peak_meter_playback(true);
1551 peak_meter_enabled = false;
1552 #endif
1553 done = 1;
1555 update_countdown = 0; /* Update immediately */
1556 break;
1557 #ifdef HAVE_REMOTE_LCD
1558 case ACTION_REC_LCD:
1559 /* this feature exists for some h1x0/h3x0 targets that suffer
1560 from noise caused by remote LCD updates
1561 NOTE 1: this will leave the list on the remote
1562 NOTE 2: to be replaced by a global LCD_off() routine */
1563 if(remote_display_on)
1565 /* switch to single screen, leave message on remote */
1566 screen_update = 1;
1567 screens[1].clear_viewport();
1568 screens[1].puts(0, 0, str(LANG_REMOTE_LCD_OFF));
1569 screens[1].puts(0, 1, str(LANG_REMOTE_LCD_ON));
1570 screens[1].update_viewport();
1572 else
1574 /* remote switched on again */
1575 update_list = true;
1576 screen_update = NB_SCREENS;
1578 remote_display_on = !remote_display_on; /* toggle */
1579 update_countdown = 0; /* Update immediately */
1580 break;
1581 #endif
1582 case ACTION_REC_PAUSE:
1583 case ACTION_REC_NEWFILE:
1584 /* Only act if the mpeg is stopped */
1585 if(!(audio_stat & AUDIO_STATUS_RECORD))
1587 /* is this manual or triggered recording? */
1588 if ((global_settings.rec_trigger_mode == TRIG_MODE_OFF) ||
1589 (peak_meter_trigger_status() != TRIG_OFF))
1591 /* manual recording */
1592 rec_status |= RCSTAT_HAVE_RECORDED;
1593 rec_command(RECORDING_CMD_START);
1594 last_seconds = 0;
1595 if (global_settings.talk_menu)
1597 /* no voice possible here, but a beep */
1598 audio_beep(HZ/2); /* longer beep on start */
1601 /* this is triggered recording */
1602 else
1604 /* we don't start recording now, but enable the
1605 trigger and let the callback function
1606 trigger_listener control when the recording starts */
1607 peak_meter_trigger(true);
1608 peak_meter_set_trigger_listener(&trigger_listener);
1611 else
1613 /*if new file button pressed, start new file */
1614 if (button == ACTION_REC_NEWFILE)
1616 rec_command(RECORDING_CMD_START_NEWFILE);
1617 last_seconds = 0;
1619 else
1620 /* if pause button pressed, pause or resume */
1622 if(audio_stat & AUDIO_STATUS_PAUSE)
1624 rec_command(RECORDING_CMD_RESUME);
1625 if (global_settings.talk_menu)
1627 /* no voice possible here, but a beep */
1628 audio_beep(HZ/4); /* short beep on resume */
1631 else
1633 rec_command(RECORDING_CMD_PAUSE);
1637 update_countdown = 0; /* Update immediately */
1638 break;
1639 case ACTION_STD_MENU:
1640 #if CONFIG_CODEC == SWCODEC
1641 if(!(audio_stat & AUDIO_STATUS_RECORD))
1642 #else
1643 if(audio_stat != AUDIO_STATUS_RECORD)
1644 #endif
1646 #if (CONFIG_LED == LED_REAL)
1647 /* led is restored at begin of loop / end of function */
1648 led(false);
1649 #endif
1650 if (recording_menu(no_source))
1652 done = 1;
1653 rec_status |= RCSTAT_BEEN_IN_USB_MODE;
1654 #ifdef HAVE_FMRADIO_REC
1655 radio_status = FMRADIO_OFF;
1656 #endif
1658 else
1660 done = -1;
1661 /* the init is now done at the beginning of the loop */
1664 break;
1666 #if CONFIG_KEYPAD == RECORDER_PAD
1667 case ACTION_REC_F2:
1668 if(audio_stat != AUDIO_STATUS_RECORD)
1670 #if (CONFIG_LED == LED_REAL)
1671 /* led is restored at begin of loop / end of function */
1672 led(false);
1673 #endif
1674 if (f2_rec_screen())
1676 rec_status |= RCSTAT_HAVE_RECORDED;
1677 done = true;
1679 else
1680 update_countdown = 0; /* Update immediately */
1682 break;
1684 case ACTION_REC_F3:
1685 if(audio_stat & AUDIO_STATUS_RECORD)
1687 rec_command(RECORDING_CMD_START_NEWFILE);
1688 last_seconds = 0;
1690 else
1692 #if (CONFIG_LED == LED_REAL)
1693 /* led is restored at begin of loop / end of function */
1694 led(false);
1695 #endif
1696 if (f3_rec_screen())
1698 rec_status |= RCSTAT_HAVE_RECORDED;
1699 done = true;
1701 else
1702 update_countdown = 0; /* Update immediately */
1704 break;
1705 #endif /* CONFIG_KEYPAD == RECORDER_PAD */
1707 case SYS_USB_CONNECTED:
1708 /* Only accept USB connection when not recording */
1709 if(!(audio_stat & AUDIO_STATUS_RECORD))
1711 FOR_NB_SCREENS(i)
1712 screens[i].set_viewport(NULL);
1713 default_event_handler(SYS_USB_CONNECTED);
1714 done = true;
1715 rec_status |= RCSTAT_BEEN_IN_USB_MODE;
1716 #ifdef HAVE_FMRADIO_REC
1717 radio_status = FMRADIO_OFF;
1718 #endif
1720 break;
1721 } /*switch(button)*/
1723 #ifdef HAVE_AGC
1724 peak_read = !peak_read;
1725 if (peak_read) { /* every 2nd run of loop */
1726 peak_time++;
1727 peak_valid = read_peak_levels(&peak_l, &peak_r, &balance);
1730 /* Handle AGC every 200ms when enabled and peak data is valid */
1731 if (peak_read && agc_enable && peak_valid)
1732 auto_gain_control(&peak_l, &peak_r, &balance);
1733 #endif
1735 seconds = audio_recorded_time() / HZ;
1737 /* start of vp_top drawing */
1738 if(update_countdown-- == 0 || seconds > last_seconds)
1740 unsigned int dseconds, dhours, dminutes;
1741 unsigned long num_recorded_bytes, dsize, dmb;
1743 FOR_NB_SCREENS(i)
1745 screens[i].set_viewport(&vp_top[i]);
1746 screens[i].clear_viewport();
1748 update_countdown = 5;
1749 last_seconds = seconds;
1751 dseconds = rec_timesplit_seconds();
1752 dsize = rec_sizesplit_bytes();
1753 num_recorded_bytes = audio_num_recorded_bytes();
1755 #if CONFIG_CODEC == SWCODEC
1756 if ((audio_stat & AUDIO_STATUS_WARNING)
1757 && (warning_counter++ % WARNING_PERIOD) < WARNING_PERIOD/2)
1759 /* Switch back and forth displaying warning on first available
1760 line to ensure visibility - the motion should also help
1761 draw attention */
1762 /* Don't use language string unless agreed upon to make this
1763 method permanent - could do something in the statusbar */
1764 snprintf(buf, sizeof(buf), "Warning: %08X",
1765 pcm_rec_get_warnings());
1767 else
1768 #endif /* CONFIG_CODEC == SWCODEC */
1769 if ((global_settings.rec_sizesplit) &&
1770 (global_settings.rec_split_method))
1772 dmb = dsize/1024/1024;
1773 snprintf(buf, sizeof(buf), "%s %dMB",
1774 str(LANG_SPLIT_SIZE), dmb);
1776 else
1778 hours = seconds / 3600;
1779 minutes = (seconds - (hours * 3600)) / 60;
1780 snprintf(buf, sizeof(buf), "%s %02d:%02d:%02d",
1781 str(LANG_RECORDING_TIME),
1782 hours, minutes, seconds%60);
1785 FOR_NB_ACTIVE_SCREENS(i)
1786 screens[i].puts(0, 0, buf);
1788 if(audio_stat & AUDIO_STATUS_PRERECORD)
1790 snprintf(buf, sizeof(buf), "%s...",
1791 str(LANG_RECORD_PRERECORD));
1793 else
1795 /* Display the split interval if the record timesplit
1796 is active */
1797 if ((global_settings.rec_timesplit) &&
1798 !(global_settings.rec_split_method))
1800 /* Display the record timesplit interval rather
1801 than the file size if the record timer is active */
1802 dhours = dseconds / 3600;
1803 dminutes = (dseconds - (dhours * 3600)) / 60;
1804 snprintf(buf, sizeof(buf), "%s %02d:%02d",
1805 str(LANG_RECORDING_TIMESPLIT_REC),
1806 dhours, dminutes);
1808 else
1810 output_dyn_value(buf2, sizeof buf2,
1811 num_recorded_bytes,
1812 byte_units, true);
1813 snprintf(buf, sizeof(buf), "%s %s",
1814 str(LANG_RECORDING_SIZE), buf2);
1818 FOR_NB_ACTIVE_SCREENS(i)
1819 screens[i].puts(0, 1, buf);
1821 /* We will do file splitting regardless, either at the end of
1822 a split interval, or when the filesize approaches the 2GB
1823 FAT file size (compatibility) limit. */
1824 if ((audio_stat && !(global_settings.rec_split_method)
1825 && global_settings.rec_timesplit && (seconds >= dseconds))
1826 || (audio_stat && global_settings.rec_split_method
1827 && global_settings.rec_sizesplit
1828 && (num_recorded_bytes >= dsize))
1829 || (num_recorded_bytes >= MAX_FILE_SIZE))
1831 if (!(global_settings.rec_split_type)
1832 || (num_recorded_bytes >= MAX_FILE_SIZE))
1834 rec_command(RECORDING_CMD_START_NEWFILE);
1835 last_seconds = 0;
1837 else
1839 peak_meter_trigger(false);
1840 peak_meter_set_trigger_listener(NULL);
1841 if( global_settings.rec_split_type == 1)
1842 rec_command(RECORDING_CMD_STOP);
1843 else
1844 rec_command(RECORDING_CMD_STOP_SHUTDOWN);
1846 update_countdown = 0;
1849 /* draw the clipcounter just in front of the peakmeter */
1850 if(global_settings.peak_meter_clipcounter)
1852 int clipcount = pm_get_clipcount();
1853 FOR_NB_ACTIVE_SCREENS(i)
1855 if(!compact_view[i])
1857 screens[i].puts(0, 2, str(LANG_PM_CLIPCOUNT));
1858 screens[i].putsf(0, 3, "%4d", clipcount);
1860 else
1861 screens[i].putsf(0, 2, "%4d", clipcount);
1865 #ifdef HAVE_RECORDING_HISTOGRAM
1866 if(global_settings.rec_histogram_interval)
1868 if (peak_valid && !(hist_time % hist_time_interval) && hist_l)
1870 /* fill history buffer */
1871 history_l[history_pos] = hist_l * hist_size_h / 32767;
1872 history_r[history_pos] = hist_r * hist_size_h / 32767;
1873 history_pos = (history_pos + 1) % HIST_BUF_SIZE;
1874 history_l[history_pos] = history_r[history_pos] = 0;
1875 history_l[(history_pos + 1) % HIST_BUF_SIZE] = 0;
1876 history_r[(history_pos + 1) % HIST_BUF_SIZE] = 0;
1877 hist_l = 0;
1878 hist_r = 0;
1880 lcd_set_drawmode(DRMODE_SOLID);
1881 lcd_drawrect(0, hist_pos_y - 1,
1882 HIST_W + 2, hist_size_h + 1);
1883 lcd_drawrect(HIST_W + 6, hist_pos_y - 1,
1884 HIST_W + 2, hist_size_h + 1);
1885 lcd_set_drawmode(DRMODE_FG);
1887 j = history_pos;
1888 for (i = HIST_W-1; i >= 0; i--)
1890 j--;
1891 if(j<0)
1892 j = HIST_BUF_SIZE-1;
1893 if (history_l[j])
1895 if (history_l[j] == hist_size_h)
1896 lcd_set_foreground(LCD_HIST_OVER);
1897 #ifdef HAVE_LCD_COLOR
1898 else if (history_l[j] > hist_level_marks[1])
1899 lcd_set_foreground(LCD_HIST_HI);
1900 #endif
1901 else
1902 lcd_set_foreground(LCD_HIST_OK);
1903 lcd_vline(1 + i, HIST_Y-1, HIST_Y - history_l[j]);
1905 if (history_r[j])
1907 if (history_r[j] == hist_size_h)
1908 lcd_set_foreground(LCD_HIST_OVER);
1909 #ifdef HAVE_LCD_COLOR
1910 else if (history_r[j] > hist_level_marks[1])
1911 lcd_set_foreground(LCD_HIST_HI);
1912 #endif
1913 else
1914 lcd_set_foreground(LCD_HIST_OK);
1915 lcd_vline(HIST_W+7 + i, HIST_Y-1, HIST_Y - history_r[j]);
1918 lcd_set_foreground(
1919 #ifdef HAVE_LCD_COLOR
1920 global_settings.fg_color);
1921 #else
1922 LCD_DEFAULT_FG);
1923 #endif
1924 for (i = 0; i < 6; i++)
1925 lcd_hline(HIST_W + 3, HIST_W + 4,
1926 HIST_Y - hist_level_marks[i]);
1928 #endif /* HAVE_RECORDING_HISTOGRAM */
1930 #ifdef HAVE_AGC
1931 hist_time++;
1932 #endif
1934 /* draw the trigger status */
1935 if (peak_meter_trigger_status() != TRIG_OFF)
1937 peak_meter_draw_trig(pm_x, trig_ypos, trig_width,
1938 screen_update);
1939 FOR_NB_ACTIVE_SCREENS(i)
1940 screens[i].update_viewport_rect(pm_x[i], trig_ypos[i],
1941 trig_width[i] + 2, TRIG_HEIGHT);
1944 #ifdef HAVE_AGC
1945 #ifdef HAVE_MIC_REC
1946 if (global_settings.rec_source == AUDIO_SRC_MIC)
1948 if(agc_maxgain < (global_settings.rec_mic_gain))
1949 change_recording_gain(false, true, true);
1951 else
1952 #endif /* MIC */
1954 if(agc_maxgain < (global_settings.rec_left_gain))
1955 change_recording_gain(false, true, false);
1956 if(agc_maxgain < (global_settings.rec_right_gain))
1957 change_recording_gain(false, false, true);
1959 #endif /* HAVE_AGC */
1961 #if CONFIG_CODEC == SWCODEC
1962 #ifdef HAVE_SPDIF_REC
1963 if((global_settings.rec_source == AUDIO_SRC_SPDIF) &&
1964 (prev_sample_rate != pcm_rec_sample_rate()))
1966 /* spdif samplerate changed */
1967 prev_sample_rate = pcm_rec_sample_rate();
1968 update_list = true;
1970 #endif
1971 #endif
1973 if(update_list)
1975 /* update_list is set whenever content changes */
1976 update_list = false;
1977 gui_synclist_draw(&lists);
1980 /* draw peakmeter again (check if this can be removed) */
1981 FOR_NB_ACTIVE_SCREENS(i)
1983 screens[i].set_viewport(&vp_top[i]);
1984 peak_meter_screen(&screens[i], pm_x[i], pm_y[i], pm_h[i]);
1985 screens[i].update();
1987 } /* display update every second */
1989 if(audio_stat & AUDIO_STATUS_ERROR)
1991 done = true;
1993 } /* end while(!done) */
1995 audio_stat = audio_status();
1996 if (audio_stat & AUDIO_STATUS_ERROR)
1998 splash(0, str(LANG_DISK_FULL));
2000 FOR_NB_SCREENS(i)
2001 screens[i].update();
2003 #if CONFIG_CODEC == SWCODEC
2004 /* stop recording - some players like H10 freeze otherwise
2005 TO DO: find out why it freezes and fix properly */
2006 rec_command(RECORDING_CMD_STOP);
2007 audio_close_recording();
2008 #endif
2010 audio_error_clear();
2012 while(1)
2014 if (action_userabort(TIMEOUT_NOBLOCK))
2015 break;
2019 rec_abort:
2021 #if CONFIG_CODEC == SWCODEC
2022 rec_command(RECORDING_CMD_STOP);
2023 audio_close_recording();
2025 #ifdef HAVE_FMRADIO_REC
2026 if (radio_status != FMRADIO_OFF)
2027 /* Restore radio playback - radio_status should be unchanged if started
2028 through fm radio screen (barring usb connect) */
2029 rec_set_source(AUDIO_SRC_FMRADIO, (radio_status & FMRADIO_PAUSED) ?
2030 SRCF_FMRADIO_PAUSED : SRCF_FMRADIO_PLAYING);
2031 else
2032 #endif
2033 /* Go back to playback mode */
2034 rec_set_source(AUDIO_SRC_PLAYBACK, SRCF_PLAYBACK);
2036 /* restore talking */
2037 talk_disable(false);
2038 #else /* !SWCODEC */
2039 audio_init_playback();
2040 #endif /* CONFIG_CODEC == SWCODEC */
2042 #ifdef HAVE_SPEAKER
2043 /* Re-enable speaker */
2044 audiohw_enable_speaker(global_settings.speaker_enabled);
2045 #endif
2047 /* make sure the trigger is really turned off */
2048 peak_meter_trigger(false);
2049 peak_meter_set_trigger_listener(NULL);
2051 rec_status &= ~RCSTAT_IN_RECSCREEN;
2052 sound_settings_apply();
2054 FOR_NB_SCREENS(i)
2055 screens[i].setfont(FONT_UI);
2057 /* if the directory was created or recording happened, make sure the
2058 browser is updated */
2059 if (rec_status & (RCSTAT_CREATED_DIRECTORY | RCSTAT_HAVE_RECORDED))
2060 reload_directory();
2062 #if (CONFIG_STORAGE & STORAGE_ATA) && (CONFIG_LED == LED_REAL) \
2063 && !defined(SIMULATOR)
2064 ata_set_led_enabled(true);
2065 #endif
2067 settings_save();
2069 return (rec_status & RCSTAT_BEEN_IN_USB_MODE) != 0;
2070 } /* recording_screen */
2072 #if CONFIG_KEYPAD == RECORDER_PAD
2073 static bool f2_rec_screen(void)
2075 static const char* const freq_str[6] =
2077 "44.1kHz",
2078 "48kHz",
2079 "32kHz",
2080 "22.05kHz",
2081 "24kHz",
2082 "16kHz"
2085 bool exit = false;
2086 bool used = false;
2087 int w, h, i;
2088 char buf[32];
2089 int button;
2090 struct audio_recording_options rec_options;
2092 FOR_NB_SCREENS(i)
2094 screens[i].set_viewport(NULL);
2095 screens[i].setfont(FONT_SYSFIXED);
2096 screens[i].getstringsize("A",&w,&h);
2099 while (!exit) {
2100 const char* ptr;
2102 FOR_NB_SCREENS(i)
2104 screens[i].clear_display();
2106 /* Recording quality */
2107 screens[i].putsxy(0, LCD_HEIGHT/2 - h*2,
2108 str(LANG_SYSFONT_RECORDING_QUALITY));
2111 snprintf(buf, sizeof(buf), "%d", global_settings.rec_quality);
2112 FOR_NB_SCREENS(i)
2114 screens[i].putsxy(0, LCD_HEIGHT/2-h, buf);
2115 screens[i].mono_bitmap(bitmap_icons_7x8[Icon_FastBackward],
2116 LCD_WIDTH/2 - 16, LCD_HEIGHT/2 - 4, 7, 8);
2119 /* Frequency */
2120 snprintf(buf, sizeof buf, "%s:", str(LANG_SYSFONT_RECORDING_FREQUENCY));
2121 ptr = freq_str[global_settings.rec_frequency];
2122 FOR_NB_SCREENS(i)
2124 screens[i].getstringsize(buf,&w,&h);
2125 screens[i].putsxy((LCD_WIDTH-w)/2, LCD_HEIGHT - h*2, buf);
2126 screens[i].getstringsize(ptr, &w, &h);
2127 screens[i].putsxy((LCD_WIDTH-w)/2, LCD_HEIGHT - h, ptr);
2128 screens[i].mono_bitmap(bitmap_icons_7x8[Icon_DownArrow],
2129 LCD_WIDTH/2 - 3, LCD_HEIGHT - h*3, 7, 8);
2132 /* Channel mode */
2133 switch ( global_settings.rec_channels ) {
2134 case 0:
2135 ptr = str(LANG_SYSFONT_CHANNEL_STEREO);
2136 break;
2138 case 1:
2139 ptr = str(LANG_SYSFONT_CHANNEL_MONO);
2140 break;
2143 FOR_NB_SCREENS(i)
2145 screens[i].getstringsize(str(LANG_SYSFONT_CHANNELS), &w, &h);
2146 screens[i].putsxy(LCD_WIDTH - w, LCD_HEIGHT/2 - h*2,
2147 str(LANG_SYSFONT_CHANNELS));
2148 screens[i].getstringsize(str(LANG_SYSFONT_MODE), &w, &h);
2149 screens[i].putsxy(LCD_WIDTH - w, LCD_HEIGHT/2 - h,
2150 str(LANG_SYSFONT_MODE));
2151 screens[i].getstringsize(ptr, &w, &h);
2152 screens[i].putsxy(LCD_WIDTH - w, LCD_HEIGHT/2, ptr);
2153 screens[i].mono_bitmap(bitmap_icons_7x8[Icon_FastForward],
2154 LCD_WIDTH/2 + 8, LCD_HEIGHT/2 - 4, 7, 8);
2156 screens[i].update();
2159 button = button_get(true);
2160 switch (button) {
2161 case BUTTON_LEFT:
2162 case BUTTON_F2 | BUTTON_LEFT:
2163 global_settings.rec_quality++;
2164 if(global_settings.rec_quality > 7)
2165 global_settings.rec_quality = 0;
2166 used = true;
2167 break;
2169 case BUTTON_DOWN:
2170 case BUTTON_F2 | BUTTON_DOWN:
2171 global_settings.rec_frequency++;
2172 if(global_settings.rec_frequency > 5)
2173 global_settings.rec_frequency = 0;
2174 used = true;
2175 break;
2177 case BUTTON_RIGHT:
2178 case BUTTON_F2 | BUTTON_RIGHT:
2179 global_settings.rec_channels++;
2180 if(global_settings.rec_channels > 1)
2181 global_settings.rec_channels = 0;
2182 used = true;
2183 break;
2185 case BUTTON_F2 | BUTTON_REL:
2186 if ( used )
2187 exit = true;
2188 used = true;
2189 break;
2191 case BUTTON_F2 | BUTTON_REPEAT:
2192 used = true;
2193 break;
2195 default:
2196 if(default_event_handler(button) == SYS_USB_CONNECTED)
2197 return true;
2198 break;
2202 rec_init_recording_options(&rec_options);
2203 rec_set_recording_options(&rec_options);
2205 set_gain();
2207 settings_save();
2208 FOR_NB_SCREENS(i)
2209 screens[i].setfont(FONT_UI);
2211 return false;
2214 static bool f3_rec_screen(void)
2216 bool exit = false;
2217 bool used = false;
2218 int w, h, i;
2219 int button;
2220 const char *src_str[] =
2222 str(LANG_SYSFONT_RECORDING_SRC_MIC),
2223 str(LANG_SYSFONT_LINE_IN),
2224 str(LANG_SYSFONT_RECORDING_SRC_DIGITAL)
2226 struct audio_recording_options rec_options;
2228 FOR_NB_SCREENS(i)
2230 screens[i].set_viewport(NULL);
2231 screens[i].setfont(FONT_SYSFIXED);
2232 screens[i].getstringsize("A",&w,&h);
2235 while (!exit) {
2236 const char* ptr = src_str[global_settings.rec_source];
2237 FOR_NB_SCREENS(i)
2239 screens[i].clear_display();
2241 /* Recording source */
2242 screens[i].putsxy(0, LCD_HEIGHT/2 - h*2,
2243 str(LANG_SYSFONT_RECORDING_SOURCE));
2245 screens[i].getstringsize(ptr, &w, &h);
2246 screens[i].putsxy(0, LCD_HEIGHT/2-h, ptr);
2247 screens[i].mono_bitmap(bitmap_icons_7x8[Icon_FastBackward],
2248 LCD_WIDTH/2 - 16, LCD_HEIGHT/2 - 4, 7, 8);
2251 /* trigger setup */
2252 ptr = str(LANG_SYSFONT_RECORD_TRIGGER);
2253 FOR_NB_SCREENS(i)
2255 screens[i].getstringsize(ptr,&w,&h);
2256 screens[i].putsxy((LCD_WIDTH-w)/2, LCD_HEIGHT - h*2, ptr);
2257 screens[i].mono_bitmap(bitmap_icons_7x8[Icon_DownArrow],
2258 LCD_WIDTH/2 - 3, LCD_HEIGHT - h*3, 7, 8);
2260 screens[i].update();
2263 button = button_get(true);
2264 switch (button) {
2265 case BUTTON_DOWN:
2266 case BUTTON_F3 | BUTTON_DOWN:
2267 #ifndef SIMULATOR
2268 rectrigger();
2269 settings_apply_trigger();
2270 #endif
2271 exit = true;
2272 break;
2274 case BUTTON_LEFT:
2275 case BUTTON_F3 | BUTTON_LEFT:
2276 global_settings.rec_source++;
2277 if(global_settings.rec_source > AUDIO_SRC_MAX)
2278 global_settings.rec_source = 0;
2279 used = true;
2280 break;
2282 case BUTTON_F3 | BUTTON_REL:
2283 if ( used )
2284 exit = true;
2285 used = true;
2286 break;
2288 case BUTTON_F3 | BUTTON_REPEAT:
2289 used = true;
2290 break;
2292 default:
2293 if(default_event_handler(button) == SYS_USB_CONNECTED)
2294 return true;
2295 break;
2299 rec_init_recording_options(&rec_options);
2300 rec_set_recording_options(&rec_options);
2302 set_gain();
2304 settings_save();
2305 FOR_NB_SCREENS(i)
2306 screens[i].setfont(FONT_UI);
2308 return false;
2310 #endif /* CONFIG_KEYPAD == RECORDER_PAD */
2312 #if CONFIG_CODEC == SWCODEC
2313 void audio_beep(int duration)
2315 /* dummy */
2316 (void)duration;
2319 #ifdef SIMULATOR
2320 /* stubs for recording sim */
2321 void audio_init_recording(unsigned int buffer_offset)
2323 buffer_offset = buffer_offset;
2326 void audio_close_recording(void)
2330 unsigned long pcm_rec_get_warnings(void)
2332 return 0;
2335 unsigned long pcm_rec_sample_rate(void)
2337 return 0;
2340 unsigned long audio_recorded_time(void)
2342 return 123;
2345 unsigned long audio_num_recorded_bytes(void)
2347 return 5 * 1024 * 1024;
2350 void rec_set_source(int source, unsigned flags)
2352 source = source;
2353 flags = flags;
2356 void audio_set_recording_options(struct audio_recording_options *options)
2358 options = options;
2361 void audio_set_recording_gain(int left, int right, int type)
2363 left = left;
2364 right = right;
2365 type = type;
2368 void audio_record(const char *filename)
2370 filename = filename;
2373 void audio_new_file(const char *filename)
2375 filename = filename;
2378 void audio_stop_recording(void)
2382 void audio_pause_recording(void)
2386 void audio_resume_recording(void)
2390 #endif /* #ifdef SIMULATOR */
2391 #endif /* #ifdef CONFIG_CODEC == SWCODEC */
2393 #endif /* HAVE_RECORDING */