summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter D'Hoye <peter.dhoye@gmail.com>2006-02-24 22:28:57 +0000
committerPeter D'Hoye <peter.dhoye@gmail.com>2006-02-24 22:28:57 +0000
commit9ace16f87f71d616161f7d1f1aa721b1a72b54ec (patch)
treedf6f0a7caeaf2d60aa59ffb6a16ca39617f8fb88
parentac115693da005aa76b63d30d025a0a8f060ee525 (diff)
downloadrockbox-9ace16f87f71d616161f7d1f1aa721b1a72b54ec.zip
rockbox-9ace16f87f71d616161f7d1f1aa721b1a72b54ec.tar.gz
rockbox-9ace16f87f71d616161f7d1f1aa721b1a72b54ec.tar.bz2
rockbox-9ace16f87f71d616161f7d1f1aa721b1a72b54ec.tar.xz
use all recorded samples for peak metering and clipping detection
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8837 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/pcm_record.c86
1 files changed, 46 insertions, 40 deletions
diff --git a/firmware/pcm_record.c b/firmware/pcm_record.c
index c4ba7ba..511b95e 100644
--- a/firmware/pcm_record.c
+++ b/firmware/pcm_record.c
@@ -365,42 +365,39 @@ void pcm_rec_get_peaks(int *left, int *right)
/* Functions that executes in the context of pcmrec_thread */
/***************************************************************************/
-/* Skip PEAK_STRIDE sample-pairs for each compare */
+/* Skip PEAK_STRIDE sample-pairs for each compare
#define PEAK_STRIDE 3
-static void pcmrec_find_peaks(int chunk)
+static void pcmrec_find_peaks(int chunk, int* peak_l, int* peak_r)
{
short *ptr, value;
- int peak_l, peak_r;
int j;
-
+
+ if(!peak_l || ! peak_r) return;
+
ptr = GET_CHUNK(chunk);
- peak_l = 0;
- peak_r = 0;
+ *peak_l = 0;
+ *peak_r = 0;
for (j=0; j<CHUNK_SIZE/4; j+=PEAK_STRIDE+1)
{
- if ((value = ptr[0]) > peak_l)
- peak_l = value;
- else if (-value > peak_l)
- peak_l = -value;
+ if ((value = ptr[0]) > *peak_l)
+ *peak_l = value;
+ else if (-value > *peak_l)
+ *peak_l = -value;
ptr++;
- if ((value = ptr[0]) > peak_r)
- peak_r = value;
- else if (-value > peak_r)
- peak_r = -value;
+ if ((value = ptr[0]) > *peak_r)
+ *peak_r = value;
+ else if (-value > *peak_r)
+ *peak_r = -value;
ptr++;
ptr += PEAK_STRIDE * 2;
}
-
- peak_left = peak_l;
- peak_right = peak_r;
-
}
-
+*/
/**
* Process the chunks using read_index and write_index.
@@ -418,38 +415,40 @@ static void pcmrec_callback(bool flush)
int num_ready, num_free, num_new;
unsigned short *ptr;
int i, j, w;
-
+ short value;
+
w = write_index;
-
+
num_new = w - read2_index;
if (num_new < 0)
num_new += num_chunks;
- if (num_new > 0)
- {
- /* Collect peak values for the last buffer only */
- j = w - 1;
- if (j < 0)
- j += num_chunks;
- pcmrec_find_peaks(j);
- }
-
- if ((!is_recording || is_paused) && !flush)
- {
- /* not recording = no saving to disk, fake buffer clearing */
- read_index = write_index;
- return;
- }
-
+ peak_left = 0;
+ peak_right = 0;
for (i=0; i<num_new; i++)
{
/* Convert the samples to little-endian so we only have to write later
- (Less hd-spinning time)
+ (Less hd-spinning time), also do peak detection while we're at it
*/
ptr = GET_CHUNK(read2_index);
- for (j=0; j<CHUNK_SIZE/2; j++)
+ for (j=0; j<CHUNK_SIZE/4; j++)
{
- *ptr = htole16(*ptr);
+ value = *ptr;
+ if(value > peak_left)
+ peak_left = value;
+ else if (-value > peak_left)
+ peak_left = -value;
+
+ *ptr = htole16(value);
+ ptr++;
+
+ value = *ptr;
+ if(value > peak_right)
+ peak_right = value;
+ else if (-value > peak_right)
+ peak_right = -value;
+
+ *ptr = htole16(value);
ptr++;
}
@@ -460,6 +459,13 @@ static void pcmrec_callback(bool flush)
read2_index = 0;
}
+ if ((!is_recording || is_paused) && !flush)
+ {
+ /* not recording = no saving to disk, fake buffer clearing */
+ read_index = write_index;
+ return;
+ }
+
num_ready = w - read_index;
if (num_ready < 0)
num_ready += num_chunks;