summaryrefslogtreecommitdiffstats
path: root/apps/pcmbuf.c
diff options
context:
space:
mode:
authorJeffrey Goode <jeffg7@gmail.com>2009-10-23 01:01:00 +0000
committerJeffrey Goode <jeffg7@gmail.com>2009-10-23 01:01:00 +0000
commit96bb9efdb795a5b197150a76e4b882504d3c9e69 (patch)
treec4b8f90c3f2a2beded38d9c47b88052b55e2b848 /apps/pcmbuf.c
parent07e8647d88dbc3f7eab01dc3ab5cc431441a4d8f (diff)
downloadrockbox-96bb9efdb795a5b197150a76e4b882504d3c9e69.tar.gz
rockbox-96bb9efdb795a5b197150a76e4b882504d3c9e69.tar.bz2
rockbox-96bb9efdb795a5b197150a76e4b882504d3c9e69.zip
Consolidate almost identical code in pcmbuf.c
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23318 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/pcmbuf.c')
-rw-r--r--apps/pcmbuf.c79
1 files changed, 10 insertions, 69 deletions
diff --git a/apps/pcmbuf.c b/apps/pcmbuf.c
index 5b478362b5..4a338aa900 100644
--- a/apps/pcmbuf.c
+++ b/apps/pcmbuf.c
@@ -687,7 +687,7 @@ static void crossfade_start(void)
}
/* Returns the number of bytes _NOT_ mixed */
-static size_t crossfade_fade_mix(int factor, const char *buf, size_t fade_rem)
+static size_t crossfade_mix(int factor, const char *buf, size_t length)
{
const int16_t *input_buf = (const int16_t *)buf;
int16_t *output_buf = (int16_t *)(crossfade_chunk->addr);
@@ -695,49 +695,16 @@ static size_t crossfade_fade_mix(int factor, const char *buf, size_t fade_rem)
output_buf = &output_buf[crossfade_sample];
int32_t sample;
- while (fade_rem)
+ while (length)
{
/* fade left and right channel at once to keep buffer alignment */
- sample = *input_buf++;
- sample = ((sample * factor) >> 8) + *output_buf;
- *output_buf++ = clip_sample_16(sample);
-
- sample = *input_buf++;
- sample = ((sample * factor) >> 8) + *output_buf;
- *output_buf++ = clip_sample_16(sample);
-
- fade_rem -= 4; /* 2 samples, each 16 bit -> 4 bytes */
-
- if (output_buf >= chunk_end)
+ int i;
+ for (i = 0; i < 2; i++)
{
- crossfade_chunk = crossfade_chunk->link;
- if (!crossfade_chunk)
- return fade_rem;
- output_buf = (int16_t *)crossfade_chunk->addr;
- chunk_end = SKIPBYTES(output_buf, crossfade_chunk->size);
+ sample = *input_buf++;
+ sample = ((sample * factor) >> 8) + *output_buf;
+ *output_buf++ = clip_sample_16(sample);
}
- }
- crossfade_sample = output_buf - (int16_t *)crossfade_chunk->addr;
- return 0;
-}
-
-/* Returns the number of bytes _NOT_ mixed */
-static size_t crossfade_mix(const char *buf, size_t length)
-{
- const int16_t *input_buf = (const int16_t *)buf;
- int16_t *output_buf = (int16_t *)crossfade_chunk->addr;
- int16_t *chunk_end = SKIPBYTES(output_buf, crossfade_chunk->size);
- output_buf = &output_buf[crossfade_sample];
- int32_t sample;
-
- while (length)
- {
- /* fade left and right channel at once to keep buffer alignment */
- sample = *input_buf++ + *output_buf;
- *output_buf++ = clip_sample_16(sample);
-
- sample = *input_buf++ + *output_buf;
- *output_buf++ = clip_sample_16(sample);
length -= 4; /* 2 samples, each 16 bit -> 4 bytes */
@@ -746,7 +713,6 @@ static size_t crossfade_mix(const char *buf, size_t length)
crossfade_chunk = crossfade_chunk->link;
if (!crossfade_chunk)
return length;
-
output_buf = (int16_t *)crossfade_chunk->addr;
chunk_end = SKIPBYTES(output_buf, crossfade_chunk->size);
}
@@ -796,32 +762,28 @@ static void flush_crossfade(char *buf, size_t length)
{
/* Mix the data */
size_t fade_total = fade_rem;
- fade_rem = crossfade_fade_mix(factor, buf, fade_rem);
+ fade_rem = crossfade_mix(factor, buf, fade_rem);
length -= fade_total - fade_rem;
buf += fade_total - fade_rem;
if (!length)
return;
- if (!fade_rem)
- goto fade_done;
}
samples = fade_rem / 2;
input_buf = (int16_t *)buf;
/* Fade remaining samples in place */
- while (samples)
+ while (samples--)
{
int32_t sample = *input_buf;
*input_buf++ = (sample * factor) >> 8;
- samples--;
}
}
-fade_done:
if (crossfade_chunk)
{
/* Mix the data */
size_t mix_total = length;
- length = crossfade_mix(buf, length);
+ length = crossfade_mix(256, buf, length);
buf += mix_total - length;
if (!length)
return;
@@ -959,27 +921,6 @@ void pcmbuf_write_complete(int count)
}
}
-#if 0
-bool pcmbuf_insert_buffer(char *buf, int count)
-{
- size_t length = (size_t)(unsigned int)count << 2;
-
- if (crossfade_active)
- {
- flush_crossfade(buf, length);
- if (!(crossfade_fade_in_rem || crossfade_chunk))
- crossfade_active = false;
- }
- else
- {
- if (!prepare_insert(length))
- return false;
- pcmbuf_flush_buffer(buf, length);
- }
- return true;
-}
-#endif
-
#ifndef HAVE_HARDWARE_BEEP
#define MINIBUF_SAMPLES (NATIVE_FREQUENCY / 1000 * KEYCLICK_DURATION)
#define MINIBUF_SIZE (MINIBUF_SAMPLES*4)