summaryrefslogtreecommitdiffstats
path: root/apps/pcmbuf.c
diff options
context:
space:
mode:
authorAndree Buschmann <AndreeBuschmann@t-online.de>2008-03-30 10:11:31 +0000
committerAndree Buschmann <AndreeBuschmann@t-online.de>2008-03-30 10:11:31 +0000
commit21870cfd9bd4778ea3b69ff0090292df14c49641 (patch)
tree2d1ebb62656d3b7316664c7f44ee389d52bc14d1 /apps/pcmbuf.c
parent63acf3eb167cab7722e61e857a109b718ff2b561 (diff)
downloadrockbox-21870cfd9bd4778ea3b69ff0090292df14c49641.tar.gz
rockbox-21870cfd9bd4778ea3b69ff0090292df14c49641.tar.bz2
rockbox-21870cfd9bd4778ea3b69ff0090292df14c49641.zip
Fixes FS#8651 (noise and/or crash while crossfading). Latest ARM-asm submit for dsp showed we had a possible alignment issue with pcm-buffer when using crossfade.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@16890 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/pcmbuf.c')
-rw-r--r--apps/pcmbuf.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/apps/pcmbuf.c b/apps/pcmbuf.c
index 8f16c90523..99a440ad6b 100644
--- a/apps/pcmbuf.c
+++ b/apps/pcmbuf.c
@@ -687,13 +687,20 @@ static size_t crossfade_fade_mix(int factor, const char *buf, size_t fade_rem)
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 (fade_rem)
{
- int32_t sample = *input_buf++;
+ /* 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);
- fade_rem -= 2;
+
+ 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)
{
@@ -715,12 +722,18 @@ static size_t crossfade_mix(const char *buf, size_t length)
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)
{
- int32_t sample = *input_buf++ + *output_buf;
+ /* 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 -= 2;
+
+ length -= 4; /* 2 samples, each 16 bit -> 4 bytes */
if (output_buf >= chunk_end)
{