Move c/h files implementing/defining standard library stuff into a new libc directory...
[kugel-rb.git] / apps / recorder / recording.c
blob0f1ff30cf536ac19094c2a0c042827fffaf8d38c
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 /* tweak layout tiny screens / big fonts */
1068 bool compact_view[NB_SCREENS] = { false };
1069 struct gui_synclist lists; /* the list in the bottom vp */
1070 #if defined(HAVE_AGC) || defined(HAVE_RECORDING_HISTOGRAM)
1071 bool peak_valid = false;
1072 #endif
1073 #if defined(HAVE_RECORDING_HISTOGRAM)
1074 int j;
1075 unsigned short hist_pos_y = 0;
1076 unsigned short hist_size_h = 0;
1077 int history_pos = 0;
1078 short hist_time_interval = 1; /* 1, 2, 4, 8 */
1079 unsigned char history_l[HIST_BUF_SIZE];
1080 unsigned char history_r[HIST_BUF_SIZE];
1081 const char hist_level_marks[6] = { 29, 26, 23, 17, 9, 2};
1082 #endif
1083 #ifdef HAVE_FMRADIO_REC
1084 int prev_rec_source = global_settings.rec_source; /* detect source change */
1085 #endif
1087 struct audio_recording_options rec_options;
1088 rec_status = RCSTAT_IN_RECSCREEN;
1090 #if (CONFIG_STORAGE & STORAGE_ATA) && (CONFIG_LED == LED_REAL) \
1091 && !defined(SIMULATOR)
1092 ata_set_led_enabled(false);
1093 #endif
1095 #if CONFIG_CODEC == SWCODEC
1096 /* recording_menu gets messed up: so prevent manus talking */
1097 talk_disable(true);
1098 /* audio_init_recording stops anything playing when it takes the audio
1099 buffer */
1100 #else
1101 /* Yes, we use the D/A for monitoring */
1102 peak_meter_enabled = true;
1103 peak_meter_playback(true);
1104 #endif
1106 #ifdef HAVE_AGC
1107 peak_meter_get_peakhold(&peak_l, &peak_r);
1108 #endif
1110 pm_reset_clipcount();
1111 pm_activate_clipcount(false);
1112 settings_apply_trigger();
1114 #ifdef HAVE_AGC
1115 agc_preset_str[0] = str(LANG_OFF);
1116 agc_preset_str[1] = str(LANG_AGC_SAFETY);
1117 agc_preset_str[2] = str(LANG_AGC_LIVE);
1118 agc_preset_str[3] = str(LANG_AGC_DJSET);
1119 agc_preset_str[4] = str(LANG_AGC_MEDIUM);
1120 agc_preset_str[5] = str(LANG_AGC_VOICE);
1121 #endif /* HAVE_AGC */
1123 #ifdef HAVE_SPEAKER
1124 /* Disable speaker to prevent feedback */
1125 audiohw_enable_speaker(false);
1126 #endif
1128 #if CONFIG_CODEC == SWCODEC
1129 audio_close_recording();
1130 #endif
1131 audio_init_recording(0);
1132 sound_set_volume(global_settings.volume);
1134 #if CONFIG_RTC == 0
1135 /* Create new filename for recording start */
1136 rec_init_filename();
1137 #endif
1139 /* start of the loop: we stay in this loop until user quits recscreen */
1140 while(done <= 0)
1142 if(done < 0)
1144 /* request to re-init stuff, done after settings screen */
1145 done = 0;
1146 #ifdef HAVE_FMRADIO_REC
1147 /* If input changes away from FM Radio,
1148 radio will remain off when recording screen closes. */
1149 if (global_settings.rec_source != prev_rec_source
1150 && prev_rec_source == AUDIO_SRC_FMRADIO)
1151 radio_status = FMRADIO_OFF;
1152 prev_rec_source = global_settings.rec_source;
1153 #endif
1155 /* viewport init and calculations that only needs to be done once */
1156 FOR_NB_SCREENS(i)
1158 struct viewport *v;
1159 /* top vp, 4 lines, force sys font if total screen < 6 lines
1160 NOTE: one could limit the list to 1 line and get away with 5 lines */
1161 top_height_req[i] = 4;
1162 #if defined(HAVE_RECORDING_HISTOGRAM)
1163 if((global_settings.rec_histogram_interval) && (!i))
1164 top_height_req[i] += 1; /* use one line for histogram */
1165 hist_time_interval = 1 << global_settings.rec_histogram_interval;
1166 #endif
1167 v = &vp_top[i];
1168 viewport_set_defaults(v, i);
1169 if (viewport_get_nb_lines(v) < top_height_req[i])
1171 /* compact needs 4 lines total */
1172 v->font = FONT_SYSFIXED;
1173 compact_view[i] = false;
1175 else
1177 /*top=4,list=2*/
1178 if (viewport_get_nb_lines(v) < (top_height_req[i]+2))
1179 compact_view[i] = true;
1180 else
1181 compact_view[i] = false;
1183 vp_list[i] = *v; /* get a copy now so it can be sized more easily */
1184 v->height = (font_get(v->font)->height)*(compact_view[i] ? 3 :
1185 top_height_req[i]);
1187 /* list section, rest of the screen */
1188 vp_list[i].y += vp_top[i].height;
1189 vp_list[i].height -= vp_top[i].height;
1190 screens[i].set_viewport(&vp_top[i]); /* req for next calls */
1192 screens[i].getstringsize("W", &w, &h);
1193 pm_y[i] = font_get(vp_top[i].font)->height * 2;
1194 trig_ypos[i] = font_get(vp_top[i].font)->height * 3;
1195 if(compact_view[i])
1196 trig_ypos[i] -= (font_get(vp_top[i].font)->height)/2;
1199 /* init the bottom list */
1200 gui_synclist_init(&lists, reclist_get_name, NULL, false, 1, vp_list);
1201 gui_synclist_set_title(&lists, NULL, Icon_NOICON);
1203 send_event(GUI_EVENT_ACTIONUPDATE, (void*)1); /* force a redraw */
1205 #if defined(HAVE_RECORDING_HISTOGRAM)
1206 history_pos = 0;
1207 hist_pos_y = (compact_view[0] ? 3 : 4) * (font_get(vp_top[0].font)->height)
1208 + 1;
1209 hist_size_h = font_get(vp_top[0].font)->height - 2;
1210 memset(history_l, 0, sizeof(unsigned char)*HIST_BUF_SIZE);
1211 memset(history_r, 0, sizeof(unsigned char)*HIST_BUF_SIZE);
1212 #endif
1214 FOR_NB_SCREENS(i)
1216 pm_x[i] = 0;
1217 if(global_settings.peak_meter_clipcounter)
1219 int clipwidth = 0;
1220 screens[i].getstringsize(str(LANG_PM_CLIPCOUNT),
1221 &clipwidth, &h); /* h is same */
1222 pm_x[i] = clipwidth+1;
1224 if(global_settings.rec_trigger_mode == TRIG_MODE_OFF)
1225 pm_h[i] = font_get(vp_top[i].font)->height * 2;
1226 else
1227 pm_h[i] = font_get(vp_top[i].font)->height;
1228 if(compact_view[i])
1229 pm_h[i] /= 2;
1230 trig_width[i] = vp_top[i].width - pm_x[i];
1233 #if CONFIG_CODEC == SWCODEC
1234 audio_close_recording();
1235 audio_init_recording(0);
1236 #endif
1238 rec_init_recording_options(&rec_options);
1239 rec_set_recording_options(&rec_options);
1241 if(rec_create_directory() < 0)
1243 rec_status = 0;
1244 goto rec_abort;
1247 #if CONFIG_CODEC == SWCODEC && CONFIG_RTC == 0
1248 /* If format changed, a new number is required */
1249 rec_init_filename();
1250 #endif
1252 #ifdef HAVE_AGC
1253 #ifdef HAVE_MIC_REC
1254 if (global_settings.rec_source == AUDIO_SRC_MIC) {
1255 agc_preset = global_settings.rec_agc_preset_mic;
1256 agc_maxgain = global_settings.rec_agc_maxgain_mic;
1258 else
1259 #endif /* MIC */
1261 agc_preset = global_settings.rec_agc_preset_line;
1262 agc_maxgain = global_settings.rec_agc_maxgain_line;
1264 #endif /* HAVE_AGC */
1266 set_gain();
1267 update_countdown = 0; /* Update immediately */
1269 /* populate translation table for list id -> enum */
1270 #ifdef HAVE_SPDIF_REC
1271 if(global_settings.rec_source == AUDIO_SRC_SPDIF)
1273 listid_to_enum[0] = ITEM_VOLUME_D;
1274 #if CONFIG_CODEC == SWCODEC
1275 listid_to_enum[1] = ITEM_SAMPLERATE_D;
1276 listid_to_enum[2] = ITEM_FILENAME_D;
1277 #else
1278 listid_to_enum[1] = ITEM_FILENAME_D;
1279 #endif
1281 gui_synclist_set_nb_items(&lists, ITEM_COUNT_D); /* spdif */
1283 else
1284 #endif
1285 if(HAVE_MIC_REC_((global_settings.rec_source == AUDIO_SRC_MIC) || )
1286 (global_settings.rec_channels == 1))
1288 listid_to_enum[0] = ITEM_VOLUME_M;
1289 listid_to_enum[1] = ITEM_GAIN_M;
1290 #ifdef HAVE_AGC
1291 listid_to_enum[2] = ITEM_AGC_MODE_M;
1292 listid_to_enum[3] = ITEM_AGC_MAXDB_M;
1293 listid_to_enum[4] = ITEM_FILENAME_M;
1294 #else
1295 listid_to_enum[2] = ITEM_FILENAME_M;
1296 #endif
1297 gui_synclist_set_nb_items(&lists, ITEM_COUNT_M); /* mono */
1299 else
1301 listid_to_enum[0] = ITEM_VOLUME;
1302 listid_to_enum[1] = ITEM_GAIN;
1303 listid_to_enum[2] = ITEM_GAIN_L;
1304 listid_to_enum[3] = ITEM_GAIN_R;
1305 #ifdef HAVE_AGC
1306 listid_to_enum[4] = ITEM_AGC_MODE;
1307 listid_to_enum[5] = ITEM_AGC_MAXDB;
1308 listid_to_enum[6] = ITEM_FILENAME;
1309 #else
1310 listid_to_enum[4] = ITEM_FILENAME;
1311 #endif
1312 gui_synclist_set_nb_items(&lists, ITEM_COUNT); /* stereo */
1315 gui_synclist_draw(&lists);
1316 } /* if(done < 0) */
1318 audio_stat = audio_status();
1320 #if (CONFIG_LED == LED_REAL)
1323 * Flash the LED while waiting to record. Turn it on while
1324 * recording.
1326 if(audio_stat & AUDIO_STATUS_RECORD)
1328 if (audio_stat & AUDIO_STATUS_PAUSE)
1330 if (--led_countdown <= 0)
1332 led_state = !led_state;
1333 led(led_state);
1334 led_countdown = 2;
1337 else
1339 /* trigger is on in status TRIG_READY (no check needed) */
1340 led(true);
1343 else
1345 int trig_stat = peak_meter_trigger_status();
1347 * other trigger stati than trig_off and trig_steady
1348 * already imply that we are recording.
1350 if (trig_stat == TRIG_STEADY)
1352 if (--led_countdown <= 0)
1354 led_state = !led_state;
1355 led(led_state);
1356 led_countdown = 2;
1359 else
1361 /* trigger is on in status TRIG_READY (no check needed) */
1362 led(false);
1365 #endif /* CONFIG_LED */
1367 /* Wait for a button a while (HZ/10) drawing the peak meter */
1368 button = peak_meter_draw_get_btn(CONTEXT_RECSCREEN,
1369 pm_x, pm_y, pm_h,
1370 screen_update, vp_top);
1371 if (last_audio_stat != audio_stat)
1373 if (audio_stat & AUDIO_STATUS_RECORD)
1375 rec_status |= RCSTAT_HAVE_RECORDED;
1377 last_audio_stat = audio_stat;
1378 update_list = true;
1381 if (recording_start_automatic)
1383 /* simulate a button press */
1384 button = ACTION_REC_PAUSE;
1385 recording_start_automatic = false;
1388 /* let list handle the button */
1389 gui_synclist_do_button(&lists, &button, LIST_WRAP_UNLESS_HELD);
1392 switch(button)
1394 case ACTION_SETTINGS_INC:
1395 case ACTION_SETTINGS_INCREPEAT:
1396 switch (listid_to_enum[gui_synclist_get_sel_pos(&lists)])
1398 case ITEM_VOLUME:
1399 global_settings.volume++;
1400 setvol();
1401 break;
1402 case ITEM_GAIN:
1403 #ifdef HAVE_MIC_REC
1404 if(global_settings.rec_source == AUDIO_SRC_MIC)
1406 if(global_settings.rec_mic_gain <
1407 sound_max(SOUND_MIC_GAIN))
1408 global_settings.rec_mic_gain++;
1410 else
1411 #endif /* MIC */
1413 if(global_settings.rec_left_gain <
1414 sound_max(SOUND_LEFT_GAIN))
1415 global_settings.rec_left_gain++;
1416 if(global_settings.rec_right_gain <
1417 sound_max(SOUND_RIGHT_GAIN))
1418 global_settings.rec_right_gain++;
1420 break;
1421 case ITEM_GAIN_L:
1422 if(global_settings.rec_left_gain <
1423 sound_max(SOUND_LEFT_GAIN))
1424 global_settings.rec_left_gain++;
1425 break;
1426 case ITEM_GAIN_R:
1427 if(global_settings.rec_right_gain <
1428 sound_max(SOUND_RIGHT_GAIN))
1429 global_settings.rec_right_gain++;
1430 break;
1431 #ifdef HAVE_AGC
1432 case ITEM_AGC_MODE:
1433 agc_preset = MIN(agc_preset + 1, AGC_MODE_SIZE);
1434 agc_enable = (agc_preset != 0);
1435 #ifdef HAVE_MIC_REC
1436 if (global_settings.rec_source == AUDIO_SRC_MIC) {
1437 global_settings.rec_agc_preset_mic = agc_preset;
1438 agc_maxgain = global_settings.rec_agc_maxgain_mic;
1439 } else
1440 #endif /* MIC */
1442 global_settings.rec_agc_preset_line = agc_preset;
1443 agc_maxgain = global_settings.rec_agc_maxgain_line;
1445 break;
1446 case ITEM_AGC_MAXDB:
1447 #ifdef HAVE_MIC_REC
1448 if (global_settings.rec_source == AUDIO_SRC_MIC)
1450 agc_maxgain = MIN(agc_maxgain + 1,
1451 sound_max(SOUND_MIC_GAIN));
1452 global_settings.rec_agc_maxgain_mic = agc_maxgain;
1454 else
1455 #endif /* MIC */
1457 agc_maxgain = MIN(agc_maxgain + 1,
1458 sound_max(SOUND_LEFT_GAIN));
1459 global_settings.rec_agc_maxgain_line = agc_maxgain;
1461 break;
1462 #endif /* HAVE_AGC */
1464 set_gain();
1465 update_countdown = 0; /* Update immediately */
1466 break;
1467 case ACTION_SETTINGS_DEC:
1468 case ACTION_SETTINGS_DECREPEAT:
1469 switch (listid_to_enum[gui_synclist_get_sel_pos(&lists)])
1471 case ITEM_VOLUME:
1472 global_settings.volume--;
1473 setvol();
1474 break;
1475 case ITEM_GAIN:
1476 #ifdef HAVE_MIC_REC
1477 if(global_settings.rec_source == AUDIO_SRC_MIC)
1479 if(global_settings.rec_mic_gain >
1480 sound_min(SOUND_MIC_GAIN))
1481 global_settings.rec_mic_gain--;
1483 else
1484 #endif /* MIC */
1486 if(global_settings.rec_left_gain >
1487 sound_min(SOUND_LEFT_GAIN))
1488 global_settings.rec_left_gain--;
1489 if(global_settings.rec_right_gain >
1490 sound_min(SOUND_RIGHT_GAIN))
1491 global_settings.rec_right_gain--;
1493 break;
1494 case ITEM_GAIN_L:
1495 if(global_settings.rec_left_gain >
1496 sound_min(SOUND_LEFT_GAIN))
1497 global_settings.rec_left_gain--;
1498 break;
1499 case ITEM_GAIN_R:
1500 if(global_settings.rec_right_gain >
1501 sound_min(SOUND_RIGHT_GAIN))
1502 global_settings.rec_right_gain--;
1503 break;
1504 #ifdef HAVE_AGC
1505 case ITEM_AGC_MODE:
1506 agc_preset = MAX(agc_preset - 1, 0);
1507 agc_enable = (agc_preset != 0);
1508 #ifdef HAVE_MIC_REC
1509 if (global_settings.rec_source == AUDIO_SRC_MIC) {
1510 global_settings.rec_agc_preset_mic = agc_preset;
1511 agc_maxgain = global_settings.rec_agc_maxgain_mic;
1512 } else
1513 #endif /* MIC */
1515 global_settings.rec_agc_preset_line = agc_preset;
1516 agc_maxgain = global_settings.rec_agc_maxgain_line;
1518 break;
1519 case ITEM_AGC_MAXDB:
1520 #ifdef HAVE_MIC_REC
1521 if (global_settings.rec_source == AUDIO_SRC_MIC)
1523 agc_maxgain = MAX(agc_maxgain - 1,
1524 sound_min(SOUND_MIC_GAIN));
1525 global_settings.rec_agc_maxgain_mic = agc_maxgain;
1526 } else
1527 #endif /* MIC */
1529 agc_maxgain = MAX(agc_maxgain - 1,
1530 sound_min(SOUND_LEFT_GAIN));
1531 global_settings.rec_agc_maxgain_line = agc_maxgain;
1533 break;
1534 #endif /* HAVE_AGC */
1536 set_gain();
1537 update_countdown = 0; /* Update immediately */
1538 break;
1539 case ACTION_STD_CANCEL:
1540 /* turn off the trigger */
1541 peak_meter_trigger(false);
1542 peak_meter_set_trigger_listener(NULL);
1544 if(audio_stat & AUDIO_STATUS_RECORD)
1546 rec_command(RECORDING_CMD_STOP);
1548 else
1550 #if CONFIG_CODEC != SWCODEC
1551 peak_meter_playback(true);
1552 peak_meter_enabled = false;
1553 #endif
1554 done = 1;
1556 update_countdown = 0; /* Update immediately */
1557 break;
1558 #ifdef HAVE_REMOTE_LCD
1559 case ACTION_REC_LCD:
1560 /* this feature exists for some h1x0/h3x0 targets that suffer
1561 from noise caused by remote LCD updates
1562 NOTE 1: this will leave the list on the remote
1563 NOTE 2: to be replaced by a global LCD_off() routine */
1564 if(remote_display_on)
1566 /* switch to single screen, leave message on remote */
1567 screen_update = 1;
1568 screens[1].clear_viewport();
1569 screens[1].puts(0, 0, str(LANG_REMOTE_LCD_OFF));
1570 screens[1].puts(0, 1, str(LANG_REMOTE_LCD_ON));
1571 screens[1].update_viewport();
1573 else
1575 /* remote switched on again */
1576 update_list = true;
1577 screen_update = NB_SCREENS;
1579 remote_display_on = !remote_display_on; /* toggle */
1580 update_countdown = 0; /* Update immediately */
1581 break;
1582 #endif
1583 case ACTION_REC_PAUSE:
1584 case ACTION_REC_NEWFILE:
1585 /* Only act if the mpeg is stopped */
1586 if(!(audio_stat & AUDIO_STATUS_RECORD))
1588 /* is this manual or triggered recording? */
1589 if ((global_settings.rec_trigger_mode == TRIG_MODE_OFF) ||
1590 (peak_meter_trigger_status() != TRIG_OFF))
1592 /* manual recording */
1593 rec_status |= RCSTAT_HAVE_RECORDED;
1594 rec_command(RECORDING_CMD_START);
1595 last_seconds = 0;
1596 if (global_settings.talk_menu)
1598 /* no voice possible here, but a beep */
1599 audio_beep(HZ/2); /* longer beep on start */
1602 /* this is triggered recording */
1603 else
1605 /* we don't start recording now, but enable the
1606 trigger and let the callback function
1607 trigger_listener control when the recording starts */
1608 peak_meter_trigger(true);
1609 peak_meter_set_trigger_listener(&trigger_listener);
1612 else
1614 /*if new file button pressed, start new file */
1615 if (button == ACTION_REC_NEWFILE)
1617 rec_command(RECORDING_CMD_START_NEWFILE);
1618 last_seconds = 0;
1620 else
1621 /* if pause button pressed, pause or resume */
1623 if(audio_stat & AUDIO_STATUS_PAUSE)
1625 rec_command(RECORDING_CMD_RESUME);
1626 if (global_settings.talk_menu)
1628 /* no voice possible here, but a beep */
1629 audio_beep(HZ/4); /* short beep on resume */
1632 else
1634 rec_command(RECORDING_CMD_PAUSE);
1638 update_countdown = 0; /* Update immediately */
1639 break;
1640 case ACTION_STD_MENU:
1641 #if CONFIG_CODEC == SWCODEC
1642 if(!(audio_stat & AUDIO_STATUS_RECORD))
1643 #else
1644 if(audio_stat != AUDIO_STATUS_RECORD)
1645 #endif
1647 #if (CONFIG_LED == LED_REAL)
1648 /* led is restored at begin of loop / end of function */
1649 led(false);
1650 #endif
1651 if (recording_menu(no_source))
1653 done = 1;
1654 rec_status |= RCSTAT_BEEN_IN_USB_MODE;
1655 #ifdef HAVE_FMRADIO_REC
1656 radio_status = FMRADIO_OFF;
1657 #endif
1659 else
1661 done = -1;
1662 /* the init is now done at the beginning of the loop */
1665 break;
1667 #if CONFIG_KEYPAD == RECORDER_PAD
1668 case ACTION_REC_F2:
1669 if(audio_stat != AUDIO_STATUS_RECORD)
1671 #if (CONFIG_LED == LED_REAL)
1672 /* led is restored at begin of loop / end of function */
1673 led(false);
1674 #endif
1675 if (f2_rec_screen())
1677 rec_status |= RCSTAT_HAVE_RECORDED;
1678 done = true;
1680 else
1681 update_countdown = 0; /* Update immediately */
1683 break;
1685 case ACTION_REC_F3:
1686 if(audio_stat & AUDIO_STATUS_RECORD)
1688 rec_command(RECORDING_CMD_START_NEWFILE);
1689 last_seconds = 0;
1691 else
1693 #if (CONFIG_LED == LED_REAL)
1694 /* led is restored at begin of loop / end of function */
1695 led(false);
1696 #endif
1697 if (f3_rec_screen())
1699 rec_status |= RCSTAT_HAVE_RECORDED;
1700 done = true;
1702 else
1703 update_countdown = 0; /* Update immediately */
1705 break;
1706 #endif /* CONFIG_KEYPAD == RECORDER_PAD */
1708 case SYS_USB_CONNECTED:
1709 /* Only accept USB connection when not recording */
1710 if(!(audio_stat & AUDIO_STATUS_RECORD))
1712 FOR_NB_SCREENS(i)
1713 screens[i].set_viewport(NULL);
1714 default_event_handler(SYS_USB_CONNECTED);
1715 done = true;
1716 rec_status |= RCSTAT_BEEN_IN_USB_MODE;
1717 #ifdef HAVE_FMRADIO_REC
1718 radio_status = FMRADIO_OFF;
1719 #endif
1721 break;
1722 } /*switch(button)*/
1724 #ifdef HAVE_AGC
1725 peak_read = !peak_read;
1726 if (peak_read) { /* every 2nd run of loop */
1727 peak_time++;
1728 peak_valid = read_peak_levels(&peak_l, &peak_r, &balance);
1731 /* Handle AGC every 200ms when enabled and peak data is valid */
1732 if (peak_read && agc_enable && peak_valid)
1733 auto_gain_control(&peak_l, &peak_r, &balance);
1734 #endif
1736 seconds = audio_recorded_time() / HZ;
1738 /* start of vp_top drawing */
1739 if(update_countdown-- == 0 || seconds > last_seconds)
1741 unsigned int dseconds, dhours, dminutes;
1742 unsigned long num_recorded_bytes, dsize, dmb;
1744 FOR_NB_SCREENS(i)
1746 screens[i].set_viewport(&vp_top[i]);
1747 screens[i].clear_viewport();
1749 update_countdown = 5;
1750 last_seconds = seconds;
1752 dseconds = rec_timesplit_seconds();
1753 dsize = rec_sizesplit_bytes();
1754 num_recorded_bytes = audio_num_recorded_bytes();
1756 #if CONFIG_CODEC == SWCODEC
1757 if ((audio_stat & AUDIO_STATUS_WARNING)
1758 && (warning_counter++ % WARNING_PERIOD) < WARNING_PERIOD/2)
1760 /* Switch back and forth displaying warning on first available
1761 line to ensure visibility - the motion should also help
1762 draw attention */
1763 /* Don't use language string unless agreed upon to make this
1764 method permanent - could do something in the statusbar */
1765 snprintf(buf, sizeof(buf), "Warning: %08lX",
1766 pcm_rec_get_warnings());
1768 else
1769 #endif /* CONFIG_CODEC == SWCODEC */
1770 if ((global_settings.rec_sizesplit) &&
1771 (global_settings.rec_split_method))
1773 dmb = dsize/1024/1024;
1774 snprintf(buf, sizeof(buf), "%s %luMB",
1775 str(LANG_SPLIT_SIZE), dmb);
1777 else
1779 hours = seconds / 3600;
1780 minutes = (seconds - (hours * 3600)) / 60;
1781 snprintf(buf, sizeof(buf), "%s %02d:%02d:%02d",
1782 str(LANG_RECORDING_TIME),
1783 hours, minutes, seconds%60);
1786 FOR_NB_ACTIVE_SCREENS(i)
1787 screens[i].puts(0, 0, buf);
1789 if(audio_stat & AUDIO_STATUS_PRERECORD)
1791 snprintf(buf, sizeof(buf), "%s...",
1792 str(LANG_RECORD_PRERECORD));
1794 else
1796 /* Display the split interval if the record timesplit
1797 is active */
1798 if ((global_settings.rec_timesplit) &&
1799 !(global_settings.rec_split_method))
1801 /* Display the record timesplit interval rather
1802 than the file size if the record timer is active */
1803 dhours = dseconds / 3600;
1804 dminutes = (dseconds - (dhours * 3600)) / 60;
1805 snprintf(buf, sizeof(buf), "%s %02d:%02d",
1806 str(LANG_RECORDING_TIMESPLIT_REC),
1807 dhours, dminutes);
1809 else
1811 output_dyn_value(buf2, sizeof buf2,
1812 num_recorded_bytes,
1813 byte_units, true);
1814 snprintf(buf, sizeof(buf), "%s %s",
1815 str(LANG_RECORDING_SIZE), buf2);
1819 FOR_NB_ACTIVE_SCREENS(i)
1820 screens[i].puts(0, 1, buf);
1822 /* We will do file splitting regardless, either at the end of
1823 a split interval, or when the filesize approaches the 2GB
1824 FAT file size (compatibility) limit. */
1825 if ((audio_stat && !(global_settings.rec_split_method)
1826 && global_settings.rec_timesplit && (seconds >= dseconds))
1827 || (audio_stat && global_settings.rec_split_method
1828 && global_settings.rec_sizesplit
1829 && (num_recorded_bytes >= dsize))
1830 || (num_recorded_bytes >= MAX_FILE_SIZE))
1832 if (!(global_settings.rec_split_type)
1833 || (num_recorded_bytes >= MAX_FILE_SIZE))
1835 rec_command(RECORDING_CMD_START_NEWFILE);
1836 last_seconds = 0;
1838 else
1840 peak_meter_trigger(false);
1841 peak_meter_set_trigger_listener(NULL);
1842 if( global_settings.rec_split_type == 1)
1843 rec_command(RECORDING_CMD_STOP);
1844 else
1845 rec_command(RECORDING_CMD_STOP_SHUTDOWN);
1847 update_countdown = 0;
1850 /* draw the clipcounter just in front of the peakmeter */
1851 if(global_settings.peak_meter_clipcounter)
1853 int clipcount = pm_get_clipcount();
1854 FOR_NB_ACTIVE_SCREENS(i)
1856 if(!compact_view[i])
1858 screens[i].puts(0, 2, str(LANG_PM_CLIPCOUNT));
1859 screens[i].putsf(0, 3, "%4d", clipcount);
1861 else
1862 screens[i].putsf(0, 2, "%4d", clipcount);
1866 #ifdef HAVE_RECORDING_HISTOGRAM
1867 if(global_settings.rec_histogram_interval)
1869 if (peak_valid && !(hist_time % hist_time_interval) && hist_l)
1871 /* fill history buffer */
1872 history_l[history_pos] = hist_l * hist_size_h / 32767;
1873 history_r[history_pos] = hist_r * hist_size_h / 32767;
1874 history_pos = (history_pos + 1) % HIST_BUF_SIZE;
1875 history_l[history_pos] = history_r[history_pos] = 0;
1876 history_l[(history_pos + 1) % HIST_BUF_SIZE] = 0;
1877 history_r[(history_pos + 1) % HIST_BUF_SIZE] = 0;
1878 hist_l = 0;
1879 hist_r = 0;
1881 lcd_set_drawmode(DRMODE_SOLID);
1882 lcd_drawrect(0, hist_pos_y - 1,
1883 HIST_W + 2, hist_size_h + 1);
1884 lcd_drawrect(HIST_W + 6, hist_pos_y - 1,
1885 HIST_W + 2, hist_size_h + 1);
1886 lcd_set_drawmode(DRMODE_FG);
1888 j = history_pos;
1889 for (i = HIST_W-1; i >= 0; i--)
1891 j--;
1892 if(j<0)
1893 j = HIST_BUF_SIZE-1;
1894 if (history_l[j])
1896 if (history_l[j] == hist_size_h)
1897 lcd_set_foreground(LCD_HIST_OVER);
1898 #ifdef HAVE_LCD_COLOR
1899 else if (history_l[j] > hist_level_marks[1])
1900 lcd_set_foreground(LCD_HIST_HI);
1901 #endif
1902 else
1903 lcd_set_foreground(LCD_HIST_OK);
1904 lcd_vline(1 + i, HIST_Y-1, HIST_Y - history_l[j]);
1906 if (history_r[j])
1908 if (history_r[j] == hist_size_h)
1909 lcd_set_foreground(LCD_HIST_OVER);
1910 #ifdef HAVE_LCD_COLOR
1911 else if (history_r[j] > hist_level_marks[1])
1912 lcd_set_foreground(LCD_HIST_HI);
1913 #endif
1914 else
1915 lcd_set_foreground(LCD_HIST_OK);
1916 lcd_vline(HIST_W+7 + i, HIST_Y-1, HIST_Y - history_r[j]);
1919 lcd_set_foreground(
1920 #ifdef HAVE_LCD_COLOR
1921 global_settings.fg_color);
1922 #else
1923 LCD_DEFAULT_FG);
1924 #endif
1925 for (i = 0; i < 6; i++)
1926 lcd_hline(HIST_W + 3, HIST_W + 4,
1927 HIST_Y - hist_level_marks[i]);
1929 #endif /* HAVE_RECORDING_HISTOGRAM */
1931 #ifdef HAVE_AGC
1932 hist_time++;
1933 #endif
1935 /* draw the trigger status */
1936 if (peak_meter_trigger_status() != TRIG_OFF)
1938 peak_meter_draw_trig(pm_x, trig_ypos, trig_width,
1939 screen_update);
1940 FOR_NB_ACTIVE_SCREENS(i)
1941 screens[i].update_viewport_rect(pm_x[i], trig_ypos[i],
1942 trig_width[i] + 2, TRIG_HEIGHT);
1945 #ifdef HAVE_AGC
1946 #ifdef HAVE_MIC_REC
1947 if (global_settings.rec_source == AUDIO_SRC_MIC)
1949 if(agc_maxgain < (global_settings.rec_mic_gain))
1950 change_recording_gain(false, true, true);
1952 else
1953 #endif /* MIC */
1955 if(agc_maxgain < (global_settings.rec_left_gain))
1956 change_recording_gain(false, true, false);
1957 if(agc_maxgain < (global_settings.rec_right_gain))
1958 change_recording_gain(false, false, true);
1960 #endif /* HAVE_AGC */
1962 #if CONFIG_CODEC == SWCODEC
1963 #ifdef HAVE_SPDIF_REC
1964 if((global_settings.rec_source == AUDIO_SRC_SPDIF) &&
1965 (prev_sample_rate != pcm_rec_sample_rate()))
1967 /* spdif samplerate changed */
1968 prev_sample_rate = pcm_rec_sample_rate();
1969 update_list = true;
1971 #endif
1972 #endif
1974 if(update_list)
1976 /* update_list is set whenever content changes */
1977 update_list = false;
1978 gui_synclist_draw(&lists);
1981 /* draw peakmeter again (check if this can be removed) */
1982 FOR_NB_ACTIVE_SCREENS(i)
1984 screens[i].set_viewport(&vp_top[i]);
1985 peak_meter_screen(&screens[i], pm_x[i], pm_y[i], pm_h[i]);
1986 screens[i].update();
1988 } /* display update every second */
1990 if(audio_stat & AUDIO_STATUS_ERROR)
1992 done = true;
1994 } /* end while(!done) */
1996 audio_stat = audio_status();
1997 if (audio_stat & AUDIO_STATUS_ERROR)
1999 splash(0, str(LANG_DISK_FULL));
2001 FOR_NB_SCREENS(i)
2002 screens[i].update();
2004 #if CONFIG_CODEC == SWCODEC
2005 /* stop recording - some players like H10 freeze otherwise
2006 TO DO: find out why it freezes and fix properly */
2007 rec_command(RECORDING_CMD_STOP);
2008 audio_close_recording();
2009 #endif
2011 audio_error_clear();
2013 while(1)
2015 if (action_userabort(TIMEOUT_NOBLOCK))
2016 break;
2020 rec_abort:
2022 #if CONFIG_CODEC == SWCODEC
2023 rec_command(RECORDING_CMD_STOP);
2024 audio_close_recording();
2026 #ifdef HAVE_FMRADIO_REC
2027 if (radio_status != FMRADIO_OFF)
2028 /* Restore radio playback - radio_status should be unchanged if started
2029 through fm radio screen (barring usb connect) */
2030 rec_set_source(AUDIO_SRC_FMRADIO, (radio_status & FMRADIO_PAUSED) ?
2031 SRCF_FMRADIO_PAUSED : SRCF_FMRADIO_PLAYING);
2032 else
2033 #endif
2034 /* Go back to playback mode */
2035 rec_set_source(AUDIO_SRC_PLAYBACK, SRCF_PLAYBACK);
2037 /* restore talking */
2038 talk_disable(false);
2039 #else /* !SWCODEC */
2040 audio_init_playback();
2041 #endif /* CONFIG_CODEC == SWCODEC */
2043 #ifdef HAVE_SPEAKER
2044 /* Re-enable speaker */
2045 audiohw_enable_speaker(global_settings.speaker_enabled);
2046 #endif
2048 /* make sure the trigger is really turned off */
2049 peak_meter_trigger(false);
2050 peak_meter_set_trigger_listener(NULL);
2052 rec_status &= ~RCSTAT_IN_RECSCREEN;
2053 sound_settings_apply();
2055 FOR_NB_SCREENS(i)
2056 screens[i].setfont(FONT_UI);
2058 /* if the directory was created or recording happened, make sure the
2059 browser is updated */
2060 if (rec_status & (RCSTAT_CREATED_DIRECTORY | RCSTAT_HAVE_RECORDED))
2061 reload_directory();
2063 #if (CONFIG_STORAGE & STORAGE_ATA) && (CONFIG_LED == LED_REAL) \
2064 && !defined(SIMULATOR)
2065 ata_set_led_enabled(true);
2066 #endif
2068 settings_save();
2070 return (rec_status & RCSTAT_BEEN_IN_USB_MODE) != 0;
2071 } /* recording_screen */
2073 #if CONFIG_KEYPAD == RECORDER_PAD
2074 static bool f2_rec_screen(void)
2076 static const char* const freq_str[6] =
2078 "44.1kHz",
2079 "48kHz",
2080 "32kHz",
2081 "22.05kHz",
2082 "24kHz",
2083 "16kHz"
2086 bool exit = false;
2087 bool used = false;
2088 int w, h, i;
2089 char buf[32];
2090 int button;
2091 struct audio_recording_options rec_options;
2093 FOR_NB_SCREENS(i)
2095 screens[i].set_viewport(NULL);
2096 screens[i].setfont(FONT_SYSFIXED);
2097 screens[i].getstringsize("A",&w,&h);
2100 while (!exit) {
2101 const char* ptr;
2103 FOR_NB_SCREENS(i)
2105 screens[i].clear_display();
2107 /* Recording quality */
2108 screens[i].putsxy(0, LCD_HEIGHT/2 - h*2,
2109 str(LANG_SYSFONT_RECORDING_QUALITY));
2112 snprintf(buf, sizeof(buf), "%d", global_settings.rec_quality);
2113 FOR_NB_SCREENS(i)
2115 screens[i].putsxy(0, LCD_HEIGHT/2-h, buf);
2116 screens[i].mono_bitmap(bitmap_icons_7x8[Icon_FastBackward],
2117 LCD_WIDTH/2 - 16, LCD_HEIGHT/2 - 4, 7, 8);
2120 /* Frequency */
2121 snprintf(buf, sizeof buf, "%s:", str(LANG_SYSFONT_RECORDING_FREQUENCY));
2122 ptr = freq_str[global_settings.rec_frequency];
2123 FOR_NB_SCREENS(i)
2125 screens[i].getstringsize(buf,&w,&h);
2126 screens[i].putsxy((LCD_WIDTH-w)/2, LCD_HEIGHT - h*2, buf);
2127 screens[i].getstringsize(ptr, &w, &h);
2128 screens[i].putsxy((LCD_WIDTH-w)/2, LCD_HEIGHT - h, ptr);
2129 screens[i].mono_bitmap(bitmap_icons_7x8[Icon_DownArrow],
2130 LCD_WIDTH/2 - 3, LCD_HEIGHT - h*3, 7, 8);
2133 /* Channel mode */
2134 switch ( global_settings.rec_channels ) {
2135 case 0:
2136 ptr = str(LANG_SYSFONT_CHANNEL_STEREO);
2137 break;
2139 case 1:
2140 ptr = str(LANG_SYSFONT_CHANNEL_MONO);
2141 break;
2144 FOR_NB_SCREENS(i)
2146 screens[i].getstringsize(str(LANG_SYSFONT_CHANNELS), &w, &h);
2147 screens[i].putsxy(LCD_WIDTH - w, LCD_HEIGHT/2 - h*2,
2148 str(LANG_SYSFONT_CHANNELS));
2149 screens[i].getstringsize(str(LANG_SYSFONT_MODE), &w, &h);
2150 screens[i].putsxy(LCD_WIDTH - w, LCD_HEIGHT/2 - h,
2151 str(LANG_SYSFONT_MODE));
2152 screens[i].getstringsize(ptr, &w, &h);
2153 screens[i].putsxy(LCD_WIDTH - w, LCD_HEIGHT/2, ptr);
2154 screens[i].mono_bitmap(bitmap_icons_7x8[Icon_FastForward],
2155 LCD_WIDTH/2 + 8, LCD_HEIGHT/2 - 4, 7, 8);
2157 screens[i].update();
2160 button = button_get(true);
2161 switch (button) {
2162 case BUTTON_LEFT:
2163 case BUTTON_F2 | BUTTON_LEFT:
2164 global_settings.rec_quality++;
2165 if(global_settings.rec_quality > 7)
2166 global_settings.rec_quality = 0;
2167 used = true;
2168 break;
2170 case BUTTON_DOWN:
2171 case BUTTON_F2 | BUTTON_DOWN:
2172 global_settings.rec_frequency++;
2173 if(global_settings.rec_frequency > 5)
2174 global_settings.rec_frequency = 0;
2175 used = true;
2176 break;
2178 case BUTTON_RIGHT:
2179 case BUTTON_F2 | BUTTON_RIGHT:
2180 global_settings.rec_channels++;
2181 if(global_settings.rec_channels > 1)
2182 global_settings.rec_channels = 0;
2183 used = true;
2184 break;
2186 case BUTTON_F2 | BUTTON_REL:
2187 if ( used )
2188 exit = true;
2189 used = true;
2190 break;
2192 case BUTTON_F2 | BUTTON_REPEAT:
2193 used = true;
2194 break;
2196 default:
2197 if(default_event_handler(button) == SYS_USB_CONNECTED)
2198 return true;
2199 break;
2203 rec_init_recording_options(&rec_options);
2204 rec_set_recording_options(&rec_options);
2206 set_gain();
2208 settings_save();
2209 FOR_NB_SCREENS(i)
2210 screens[i].setfont(FONT_UI);
2212 return false;
2215 static bool f3_rec_screen(void)
2217 bool exit = false;
2218 bool used = false;
2219 int w, h, i;
2220 int button;
2221 const char *src_str[] =
2223 str(LANG_SYSFONT_RECORDING_SRC_MIC),
2224 str(LANG_SYSFONT_LINE_IN),
2225 str(LANG_SYSFONT_RECORDING_SRC_DIGITAL)
2227 struct audio_recording_options rec_options;
2229 FOR_NB_SCREENS(i)
2231 screens[i].set_viewport(NULL);
2232 screens[i].setfont(FONT_SYSFIXED);
2233 screens[i].getstringsize("A",&w,&h);
2236 while (!exit) {
2237 const char* ptr = src_str[global_settings.rec_source];
2238 FOR_NB_SCREENS(i)
2240 screens[i].clear_display();
2242 /* Recording source */
2243 screens[i].putsxy(0, LCD_HEIGHT/2 - h*2,
2244 str(LANG_SYSFONT_RECORDING_SOURCE));
2246 screens[i].getstringsize(ptr, &w, &h);
2247 screens[i].putsxy(0, LCD_HEIGHT/2-h, ptr);
2248 screens[i].mono_bitmap(bitmap_icons_7x8[Icon_FastBackward],
2249 LCD_WIDTH/2 - 16, LCD_HEIGHT/2 - 4, 7, 8);
2252 /* trigger setup */
2253 ptr = str(LANG_SYSFONT_RECORD_TRIGGER);
2254 FOR_NB_SCREENS(i)
2256 screens[i].getstringsize(ptr,&w,&h);
2257 screens[i].putsxy((LCD_WIDTH-w)/2, LCD_HEIGHT - h*2, ptr);
2258 screens[i].mono_bitmap(bitmap_icons_7x8[Icon_DownArrow],
2259 LCD_WIDTH/2 - 3, LCD_HEIGHT - h*3, 7, 8);
2261 screens[i].update();
2264 button = button_get(true);
2265 switch (button) {
2266 case BUTTON_DOWN:
2267 case BUTTON_F3 | BUTTON_DOWN:
2268 #ifndef SIMULATOR
2269 rectrigger();
2270 settings_apply_trigger();
2271 #endif
2272 exit = true;
2273 break;
2275 case BUTTON_LEFT:
2276 case BUTTON_F3 | BUTTON_LEFT:
2277 global_settings.rec_source++;
2278 if(global_settings.rec_source > AUDIO_SRC_MAX)
2279 global_settings.rec_source = 0;
2280 used = true;
2281 break;
2283 case BUTTON_F3 | BUTTON_REL:
2284 if ( used )
2285 exit = true;
2286 used = true;
2287 break;
2289 case BUTTON_F3 | BUTTON_REPEAT:
2290 used = true;
2291 break;
2293 default:
2294 if(default_event_handler(button) == SYS_USB_CONNECTED)
2295 return true;
2296 break;
2300 rec_init_recording_options(&rec_options);
2301 rec_set_recording_options(&rec_options);
2303 set_gain();
2305 settings_save();
2306 FOR_NB_SCREENS(i)
2307 screens[i].setfont(FONT_UI);
2309 return false;
2311 #endif /* CONFIG_KEYPAD == RECORDER_PAD */
2313 #if CONFIG_CODEC == SWCODEC
2314 void audio_beep(int duration)
2316 /* dummy */
2317 (void)duration;
2320 #ifdef SIMULATOR
2321 /* stubs for recording sim */
2322 void audio_init_recording(unsigned int buffer_offset)
2324 buffer_offset = buffer_offset;
2327 void audio_close_recording(void)
2331 unsigned long pcm_rec_get_warnings(void)
2333 return 0;
2336 unsigned long pcm_rec_sample_rate(void)
2338 return 0;
2341 unsigned long audio_recorded_time(void)
2343 return 123;
2346 unsigned long audio_num_recorded_bytes(void)
2348 return 5 * 1024 * 1024;
2351 void rec_set_source(int source, unsigned flags)
2353 source = source;
2354 flags = flags;
2357 void audio_set_recording_options(struct audio_recording_options *options)
2359 options = options;
2362 void audio_set_recording_gain(int left, int right, int type)
2364 left = left;
2365 right = right;
2366 type = type;
2369 void audio_record(const char *filename)
2371 filename = filename;
2374 void audio_new_file(const char *filename)
2376 filename = filename;
2379 void audio_stop_recording(void)
2383 void audio_pause_recording(void)
2387 void audio_resume_recording(void)
2391 #endif /* #ifdef SIMULATOR */
2392 #endif /* #ifdef CONFIG_CODEC == SWCODEC */
2394 #endif /* HAVE_RECORDING */