aboutsummaryrefslogtreecommitdiffstats
path: root/src/crossfade.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/crossfade.c')
-rw-r--r--src/crossfade.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/crossfade.c b/src/crossfade.c
index b99b9f7f0..c4a26fa6b 100644
--- a/src/crossfade.c
+++ b/src/crossfade.c
@@ -49,14 +49,28 @@ void cross_fade_apply(ob_chunk * a, const ob_chunk * b,
const struct audio_format *format,
unsigned int current_chunk, unsigned int num_chunks)
{
+ size_t size;
+
assert(current_chunk <= num_chunks);
+ size = b->chunkSize > a->chunkSize
+ ? a->chunkSize
+ : b->chunkSize;
+
pcm_mix(a->data,
b->data,
- a->chunkSize,
- b->chunkSize,
+ size,
format,
((float)current_chunk) / num_chunks);
- if (b->chunkSize > a->chunkSize)
+
+ if (b->chunkSize > a->chunkSize) {
+ /* the second buffer is larger than the first one:
+ there is unmixed rest at the end. Copy it over.
+ The output buffer API guarantees that there is
+ enough room in a->data. */
+ memcpy(a->data + a->chunkSize,
+ b->data + a->chunkSize,
+ b->chunkSize - a->chunkSize);
a->chunkSize = b->chunkSize;
+ }
}