summaryrefslogtreecommitdiff
path: root/apps/recorder/peakmeter.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/recorder/peakmeter.c')
-rw-r--r--apps/recorder/peakmeter.c75
1 files changed, 6 insertions, 69 deletions
diff --git a/apps/recorder/peakmeter.c b/apps/recorder/peakmeter.c
index 5ff2f21215..5a03534040 100644
--- a/apps/recorder/peakmeter.c
+++ b/apps/recorder/peakmeter.c
@@ -19,9 +19,6 @@
19 * 19 *
20 ****************************************************************************/ 20 ****************************************************************************/
21#include "config.h" 21#include "config.h"
22#if defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
23#include <stdlib.h> /* sim uses rand for peakmeter simulation */
24#endif
25#include "thread.h" 22#include "thread.h"
26#include "kernel.h" 23#include "kernel.h"
27#include "settings.h" 24#include "settings.h"
@@ -42,7 +39,6 @@
42#endif 39#endif
43#include "action.h" 40#include "action.h"
44 41
45#if CONFIG_CODEC == SWCODEC
46#include "pcm.h" 42#include "pcm.h"
47#include "pcm_mixer.h" 43#include "pcm_mixer.h"
48 44
@@ -50,17 +46,12 @@
50#include "pcm_record.h" 46#include "pcm_record.h"
51#endif 47#endif
52 48
49#if !(CONFIG_PLATFORM & PLATFORM_HOSTED)
53static bool pm_playback = true; /* selects between playback and recording peaks */ 50static bool pm_playback = true; /* selects between playback and recording peaks */
54#endif 51#endif
55 52
56static struct meter_scales scales[NB_SCREENS]; 53static struct meter_scales scales[NB_SCREENS];
57 54
58#if !defined(SIMULATOR) && CONFIG_CODEC != SWCODEC
59/* Data source */
60static int pm_src_left = MAS_REG_DQPEAK_L;
61static int pm_src_right = MAS_REG_DQPEAK_R;
62#endif
63
64/* Current values and cumulation */ 55/* Current values and cumulation */
65static int pm_cur_left; /* current values (last peak_meter_peek) */ 56static int pm_cur_left; /* current values (last peak_meter_peek) */
66static int pm_cur_right; 57static int pm_cur_right;
@@ -554,16 +545,8 @@ void peak_meter_playback(bool playback)
554{ 545{
555#if (CONFIG_PLATFORM & PLATFORM_HOSTED) 546#if (CONFIG_PLATFORM & PLATFORM_HOSTED)
556 (void)playback; 547 (void)playback;
557#elif CONFIG_CODEC == SWCODEC
558 pm_playback = playback;
559#else 548#else
560 if (playback) { 549 pm_playback = playback;
561 pm_src_left = MAS_REG_DQPEAK_L;
562 pm_src_right = MAS_REG_DQPEAK_R;
563 } else {
564 pm_src_left = MAS_REG_QPEAK_L;
565 pm_src_right = MAS_REG_QPEAK_R;
566 }
567#endif 550#endif
568 /* reset the scales just in case recording and playback 551 /* reset the scales just in case recording and playback
569 use different viewport sizes. Normally we should be checking viewport 552 use different viewport sizes. Normally we should be checking viewport
@@ -599,7 +582,10 @@ void peak_meter_peek(void)
599 bool was_clipping = pm_clip_left || pm_clip_right; 582 bool was_clipping = pm_clip_left || pm_clip_right;
600#endif 583#endif
601 /* read current values */ 584 /* read current values */
602#if CONFIG_CODEC == SWCODEC 585#if (CONFIG_PLATFORM & PLATFORM_HOSTED)
586 pm_cur_left = left = 8000;
587 pm_cur_right = right = 9000;
588#else
603 if (pm_playback) 589 if (pm_playback)
604 { 590 {
605 static struct pcm_peaks chan_peaks; /* *MUST* be static */ 591 static struct pcm_peaks chan_peaks; /* *MUST* be static */
@@ -614,14 +600,6 @@ void peak_meter_peek(void)
614#endif 600#endif
615 left = pm_cur_left; 601 left = pm_cur_left;
616 right = pm_cur_right; 602 right = pm_cur_right;
617#else
618#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
619 pm_cur_left = left = mas_codec_readreg(pm_src_left);
620 pm_cur_right = right = mas_codec_readreg(pm_src_right);
621#else
622 pm_cur_left = left = 8000;
623 pm_cur_right = right = 9000;
624#endif
625#endif 603#endif
626 604
627 /* check for clips 605 /* check for clips
@@ -632,22 +610,12 @@ void peak_meter_peek(void)
632 a real clip. For software codecs, the peak is already 610 a real clip. For software codecs, the peak is already
633 the max of a bunch of samples, so use one max value 611 the max of a bunch of samples, so use one max value
634 or you fail to detect clipping! */ 612 or you fail to detect clipping! */
635#if CONFIG_CODEC == SWCODEC
636 if (left == MAX_PEAK - 1) { 613 if (left == MAX_PEAK - 1) {
637#else
638 if ((left == pm_max_left) &&
639 (left == MAX_PEAK - 1)) {
640#endif
641 pm_clip_left = true; 614 pm_clip_left = true;
642 pm_clip_timeout_l = current_tick + pm_clip_hold; 615 pm_clip_timeout_l = current_tick + pm_clip_hold;
643 } 616 }
644 617
645#if CONFIG_CODEC == SWCODEC
646 if (right == MAX_PEAK - 1) { 618 if (right == MAX_PEAK - 1) {
647#else
648 if ((right == pm_max_right) &&
649 (right == MAX_PEAK - 1)) {
650#endif
651 pm_clip_right = true; 619 pm_clip_right = true;
652 pm_clip_timeout_r = current_tick + pm_clip_hold; 620 pm_clip_timeout_r = current_tick + pm_clip_hold;
653 } 621 }
@@ -668,14 +636,12 @@ void peak_meter_peek(void)
668 pm_max_right = MAX(pm_max_right, right); 636 pm_max_right = MAX(pm_max_right, right);
669 637
670#ifdef HAVE_RECORDING 638#ifdef HAVE_RECORDING
671#if CONFIG_CODEC == SWCODEC
672 /* Ignore any unread peakmeter data */ 639 /* Ignore any unread peakmeter data */
673#define MAX_DROP_TIME HZ/7 /* this value may need tweaking. Increase if you are 640#define MAX_DROP_TIME HZ/7 /* this value may need tweaking. Increase if you are
674 getting trig events when you shouldn't with 641 getting trig events when you shouldn't with
675 trig_stp_hold = 0 */ 642 trig_stp_hold = 0 */
676 if (!trig_stp_hold) 643 if (!trig_stp_hold)
677 trig_stp_hold = MAX_DROP_TIME; 644 trig_stp_hold = MAX_DROP_TIME;
678#endif
679 645
680 switch (trig_status) { 646 switch (trig_status) {
681 case TRIG_READY: 647 case TRIG_READY:
@@ -735,11 +701,7 @@ void peak_meter_peek(void)
735 || (right > trig_stp_threshold)) { 701 || (right > trig_stp_threshold)) {
736 /* restart hold time countdown */ 702 /* restart hold time countdown */
737 trig_lowtime = current_tick; 703 trig_lowtime = current_tick;
738#if CONFIG_CODEC == SWCODEC
739 } else if (current_tick - trig_lowtime > MAX_DROP_TIME){ 704 } else if (current_tick - trig_lowtime > MAX_DROP_TIME){
740#else
741 } else {
742#endif
743 set_trig_status(TRIG_POSTREC); 705 set_trig_status(TRIG_POSTREC);
744 trig_hightime = current_tick; 706 trig_hightime = current_tick;
745 } 707 }
@@ -797,12 +759,10 @@ void peak_meter_peek(void)
797 } 759 }
798 break; 760 break;
799 } 761 }
800#if CONFIG_CODEC == SWCODEC
801 /* restore stop hold value */ 762 /* restore stop hold value */
802 if (trig_stp_hold == MAX_DROP_TIME) 763 if (trig_stp_hold == MAX_DROP_TIME)
803 trig_stp_hold = 0; 764 trig_stp_hold = 0;
804#endif 765#endif
805#endif
806 /* check levels next time peakmeter drawn */ 766 /* check levels next time peakmeter drawn */
807 level_check = true; 767 level_check = true;
808#ifdef PM_DEBUG 768#ifdef PM_DEBUG
@@ -822,11 +782,6 @@ static int peak_meter_read_l(void)
822 by peak_meter_peek since the last call of peak_meter_read_l */ 782 by peak_meter_peek since the last call of peak_meter_read_l */
823 int retval; 783 int retval;
824 784
825#if defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
826 srand(current_tick);
827 pm_max_left = rand()%MAX_PEAK;
828#endif
829
830 retval = pm_max_left; 785 retval = pm_max_left;
831 786
832#if defined(HAVE_HISTOGRAM) || defined(HAVE_AGC) 787#if defined(HAVE_HISTOGRAM) || defined(HAVE_AGC)
@@ -855,11 +810,6 @@ static int peak_meter_read_r(void)
855 by peak_meter_peek since the last call of peak_meter_read_r */ 810 by peak_meter_peek since the last call of peak_meter_read_r */
856 int retval; 811 int retval;
857 812
858#if defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
859 srand(current_tick);
860 pm_max_right = rand()%MAX_PEAK;
861#endif
862
863 retval = pm_max_right; 813 retval = pm_max_right;
864 814
865#if defined(HAVE_HISTOGRAM) || defined(HAVE_AGC) 815#if defined(HAVE_HISTOGRAM) || defined(HAVE_AGC)
@@ -1128,11 +1078,7 @@ static void peak_meter_draw(struct screen *display, struct meter_scales *scales,
1128 /* cliplight */ 1078 /* cliplight */
1129 if ((pm_clip_left || pm_clip_right) && 1079 if ((pm_clip_left || pm_clip_right) &&
1130 global_settings.cliplight && 1080 global_settings.cliplight &&
1131#if CONFIG_CODEC == SWCODEC
1132 !pm_playback) 1081 !pm_playback)
1133#else
1134 !(audio_status() & (AUDIO_STATUS_PLAY | AUDIO_STATUS_ERROR)))
1135#endif
1136 { 1082 {
1137 /* if clipping, cliplight setting on and in recording screen */ 1083 /* if clipping, cliplight setting on and in recording screen */
1138 if (global_settings.cliplight <= 2) 1084 if (global_settings.cliplight <= 2)
@@ -1375,16 +1321,7 @@ int peak_meter_draw_get_btn(int action_context, int x[], int y[],
1375 long next_refresh = current_tick; 1321 long next_refresh = current_tick;
1376 long next_big_refresh = current_tick + HZ / 10; 1322 long next_big_refresh = current_tick + HZ / 10;
1377 int i; 1323 int i;
1378#if (CONFIG_CODEC == SWCODEC)
1379 bool highperf = false; 1324 bool highperf = false;
1380#else
1381 /* On MAS targets, we need to poll as often as possible in order to not
1382 * miss a peak, as the MAS does only provide a quasi-peak. When the disk
1383 * is active, it must not draw too much CPU power or a buffer overrun can
1384 * happen when saving a recording. As a compromise, poll only once per tick
1385 * when the disk is active, otherwise spin around as fast as possible. */
1386 bool highperf = !storage_disk_is_active();
1387#endif
1388 bool dopeek = true; 1325 bool dopeek = true;
1389 1326
1390 while (TIME_BEFORE(current_tick, next_big_refresh)) { 1327 while (TIME_BEFORE(current_tick, next_big_refresh)) {