Skip to content
This repository has been archived by the owner on Jun 7, 2019. It is now read-only.

Commit

Permalink
Cross-fade fixed (mostly)
Browse files Browse the repository at this point in the history
  • Loading branch information
PaintYourDragon committed Sep 22, 2012
1 parent 8245566 commit 15fcfd1
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions adavoice.pde
Expand Up @@ -319,25 +319,26 @@ ISR(TIMER2_OVF_vect) { // Playback interrupt
uint8_t w, inv, hi, lo, bit;
int o2, i2, pos;

// Cross fade around circular buffer 'seam'
// NEED TO WORK ON THIS
// Cross fade around circular buffer 'seam'.
// Need to work on this -- cross-fade index stuff might be off by one
// here and there.
if((o2 = (int)out) == (i2 = (int)in)) {
// Sample positions coincide. Use cross-fade buffer data directly.
pos = nSamples + xf;
hi = (buffer2[pos] << 2) | (buffer1[pos] >> 6); // Expand 10-bit data
lo = (buffer1[pos] << 2) | buffer2[pos]; // to 12 bits
} if((o2 < i2) && (o2 > (i2 - XFADE))) {
w = in - out; // Weight of sample (1-n)
inv = XFADE - w; // Weight of xfade
pos = nSamples + inv; // Index of xfade data
w = in - out; // Weight of sample (1-n)
inv = XFADE - w; // Weight of xfade
pos = nSamples + ((inv + xf) % XFADE);
s = ((buffer2[out] << 8) | buffer1[out]) * w +
((buffer2[pos] << 8) | buffer1[pos]) * inv;
hi = s >> 10; // Shift 14 bit result
lo = s >> 2; // down to 12 bits
} else if (o2 > (i2 + nSamples - XFADE)) {
w = in + nSamples - out;
inv = XFADE - w;
pos = nSamples + inv;
pos = nSamples + ((inv + xf) % XFADE);
s = ((buffer2[out] << 8) | buffer1[out]) * w +
((buffer2[pos] << 8) | buffer1[pos]) * inv;
hi = s >> 10; // Shift 14 bit result
Expand Down

0 comments on commit 15fcfd1

Please sign in to comment.