[xiph-commits] r7406 - icecast/trunk/ices0/src
brendan at dactyl.lonelymoon.com
brendan
Wed Jul 28 15:47:59 PDT 2004
Author: brendan
Date: Wed Jul 28 15:47:59 2004
New Revision: 7406
Modified:
icecast/trunk/ices0/src/crossfade.c
Log:
Use memcpy while emptying ring buffer.
Don't fade tracks less than 10 seconds or twice the fade length.
Modified: icecast/trunk/ices0/src/crossfade.c
===================================================================
--- icecast/trunk/ices0/src/crossfade.c 2004-07-28 22:30:04 UTC (rev 7405)
+++ icecast/trunk/ices0/src/crossfade.c 2004-07-28 22:47:58 UTC (rev 7406)
@@ -36,6 +36,7 @@
static int FadeSamples;
static int16_t* FL;
static int16_t* FR;
+static int16_t* Swap;
static int fpos = 0;
static int flen = 0;
@@ -46,6 +47,7 @@
FadeSamples = secs * 44100;
FL = malloc(FadeSamples * 2);
FR = malloc(FadeSamples * 2);
+ Swap = malloc(FadeSamples *2);
ices_log_debug("Crossfading %d seconds between tracks", secs);
return &Crossfader;
@@ -70,7 +72,7 @@
if (source->filesize && source->bitrate) {
filesecs = source->filesize / (source->bitrate * 128);
- if (filesecs < FadeSamples * 2 / 44100) {
+ if (filesecs < 10 || filesecs <= FadeSamples * 2 / 44100) {
ices_log_debug("crossfade: not fading short track of %d secs", filesecs);
skipnext = 1;
return;
@@ -84,7 +86,6 @@
{
int i, j, clen;
float weight;
- int16_t swap;
i = 0;
/* if the buffer is not full, don't attempt to crossfade, just fill it */
@@ -117,16 +118,17 @@
}
while (ilen) {
- swap = il[j];
- il[i] = FL[fpos];
- FL[fpos] = swap;
- swap = ir[j];
- ir[i] = FR[fpos];
- FR[fpos] = swap;
- i++;
- j++;
- fpos = (fpos + 1) % FadeSamples;
- ilen--;
+ clen = ilen < (FadeSamples - fpos) ? ilen : FadeSamples - fpos;
+ memcpy(Swap, il + j, clen * 2);
+ memcpy(il + i, FL + fpos, clen * 2);
+ memcpy(FL + fpos, Swap, clen * 2);
+ memcpy(Swap, ir + j, clen * 2);
+ memcpy(ir + i, FR + fpos, clen * 2);
+ memcpy(FR + fpos, Swap, clen * 2);
+ fpos = (fpos + clen) % FadeSamples;
+ i += clen;
+ j += clen;
+ ilen -= clen;
}
return i;
More information about the commits
mailing list