0

Background:

I'm working on writing a software application where I need to cross fade between 2 digital audio signals. In the software I have 4 variables that play a role:

float sampleA; //The value of signal A in this very instant (values from -1 to 1).
float sampleB; //The value of signal B in this very instant (values from -1 to 1).
float index;   //The index of the crossfade in this very instant (values from 0 to 1).
float result;  //The resulting value of the signal after the crossfade is applied.

However I have no idea how I would achieve this crossfade.

Problem Description:

I've decided to make a visual representation of the problem:

enter image description here

As you can see we have 3 number lines A(blue), B(red), and i(green). A and B represent the 2 floating point values of sampleA and sampleB which can vary between 1 and -1 while i is the crossfade index, a value which determines how far into the crossfade we are. Now what I've done is I've added some values for A, B and i on their respective numberlines and I've connected the points for A and B with a line.

If we then project the value of i on the line between point A and B we get a new point, Let's call this point R. If we project point R on either the numberline for A or B we can then get the final result.

Problem:

What is a formula which I can use, given a value for A, B and i, to calculate the value of R projected on the numberline?

BRHSM
  • 117
  • This is often called a "reset" or a "linear reset" in programming languages which support it. Since your input and output ranges are of equal length, some of the math can be simplified. – abiessu Mar 24 '19 at 16:16
  • @abiessu i know about things like remapping but i don't know how that can help here, i tried looking around google for the linear reset or reset thing you mentiond but I can't seem to find any relevant information – BRHSM Mar 24 '19 at 17:21

1 Answers1

2

From the visual I interpret this as $$R=a+i(b-a)$$ because the value of $R$ is equal to that of $a$ plus some fraction $i$ of the difference between $b$ and $a$.

Peter Foreman
  • 19,947
  • I'm not getting the desired output i want so let me play with it some more and see if i can get this to work! – BRHSM Mar 24 '19 at 17:19