AudaciousTunes/Audacious/Mod.cs
/// <summary>
/// Mixes two sets of sample data.
/// </summary>
/// <param name="samples1">Existing sample data.</param>
/// <param name="samples2">Existing sample data.</param>
/// <param name="bias">
/// A value from 0 to 1 describing the percent mix. 0 = the first
/// sample set, 1 = the second, and everything between mixes the data
/// proportionately.
/// </param>
Mixes two sets of sample data.
Mixes two sets of sample data .
public static List<float> Mix(List<float> samples1, List<float> samples2,
            float bias)
        {
            List<float> newSamples1 = new List<float>(samples1);
            List<float> newSamples2 = new List<float>(samples2);
            while (newSamples1.Count < newSamples2.Count)
            {
                newSamples1.Add(0);
            }
            while (newSamples2.Count < newSamples1.Count)
            {
                newSamples2.Add(0);
            }
            if (bias <= 0.5)
            {
                newSamples2 = Volume(newSamples2, bias * 2);
            }
            else if (bias <= 1)
            {
                newSamples1 = Volume(newSamples1, 1 - ((bias - 0.5f) * 2));
            }
            for (int i = 0; i < newSamples1.Count; i++)
            {
                if (i < newSamples2.Count)
                {
                    newSamples1[i] = Utils.Clamp
                        ((double)newSamples1[i] + (double)newSamples2[i]);
                }
            }
            return newSamples1;
        }
public static List < float > Mix ( List < float > samples1 , List < float > samples2 , float bias ) { List < float > newSamples1 = new List < float > ( samples1 ) ; List < float > newSamples2 = new List < float > ( samples2 ) ; while ( newSamples1 . Count < newSamples2 . Count ) { newSamples1 . Add ( 0 ) ; } while ( newSamples2 . Count < newSamples1 . Count ) { newSamples2 . Add ( 0 ) ; } if ( bias <= 0.5 ) { newSamples2 = Volume ( newSamples2 , bias * 2 ) ; } else if ( bias <= 1 ) { newSamples1 = Volume ( newSamples1 , 1 - ( ( bias - 0.5f ) * 2 ) ) ; } for ( int i = 0 ; i < newSamples1 . Count ; i ++ ) { if ( i < newSamples2 . Count ) { newSamples1 [ i ] = Utils . Clamp ( ( double ) newSamples1 [ i ] + ( double ) newSamples2 [ i ] ) ; } } return newSamples1 ; }
Mixes two sets of sample data.
Mixes two sets of sample data .
//Creates objects to avoid modifying the originals. //Expands the size of each sample list until they are equal. //Applies the bias as a volume change before mixing. //Iterates through all sampleNum, mixing if possible. //Adds two sampleNum if possible and clamps if needed. //Returns the modified sample list.
samples1
List<float>
Existing sample data.
Existing sample data .
samples2
List<float>
Existing sample data.
Existing sample data .
bias
float
A value from 0 to 1 describing the percent mix. 0 = the first
sample set, 1 = the second, and everything between mixes the data
proportionately.
A value from 0 to 1 describing the percent mix . 0 = the first sample set 1 = the second and everything between mixes the data proportionately .