Exemple #1
0
        private IEnumerable <ComplexCarrierTone> CreateSideBands(
            double freqLB,
            double freqUB,
            int count,
            AmplitudeDistribution distribution)
        {
            double freqRatio = Math.Pow((freqUB / freqLB), 1.0 / (count - 1));

            if (double.IsNaN(freqRatio) || double.IsInfinity(freqRatio))
            {
                freqRatio = 1.0;
            }

            double freq = freqLB;

            for (int carrierTone = 0; carrierTone < count; carrierTone++)
            {
                yield return(new ComplexCarrierTone(
                                 frequency: freq,
                                 amplitude: Complex64.FromPolarCoordinates(
                                     magnitude: GetFactor(distribution, freq) * CustomRandom.RayleighDistribution(randomizer.NextDouble()),
                                     phase: 2.0 * Math.PI * randomizer.NextDouble())));

                freq *= freqRatio;
            }
        }
Exemple #2
0
        public static string ToDisplayName(this AmplitudeDistribution distribution)
        {
            switch (distribution)
            {
            case AmplitudeDistribution.Unitary: return("Unitary");

            case AmplitudeDistribution.FlatRandom: return("Random (Flat)");

            case AmplitudeDistribution.Rayleigh: return("Random (Rayleigh)");

            default:
                UnityEngine.Debug.LogError($"Unexpected AmplitudeDistribution: {distribution}");
                return("");
            }
        }
Exemple #3
0
        public static double GetFactor(this AmplitudeDistribution amplitudeDistribution, Random randomizer)
        {
            switch (amplitudeDistribution)
            {
            case AmplitudeDistribution.Unitary: return(1.0);

            case AmplitudeDistribution.FlatRandom: return(randomizer.NextDouble());

            case AmplitudeDistribution.Rayleigh: return(CustomRandom.RayleighDistribution(randomizer.NextDouble()));

            default:
                UnityEngine.Debug.LogError($"Unexpected AmplitudeDistribution: {amplitudeDistribution}");
                return(1.0);
            }
        }
        //This function includes an extra factors of sqrt(f) to account for the inherent 1/sqrt(f) from
        //the exponential distribution of frequencies
        private double GetFactor(AmplitudeDistribution amplitudeDistribution, double frequency)
        {
            switch (amplitudeDistribution)
            {
            case AmplitudeDistribution.Violet: return(frequency * Math.Sqrt(frequency));

            case AmplitudeDistribution.Blue: return(frequency);

            case AmplitudeDistribution.White: return(Math.Sqrt(frequency));

            case AmplitudeDistribution.Pink: return(1.0);

            case AmplitudeDistribution.Brown: return(1.0 / Math.Sqrt(frequency));

            default:
                Debug.LogError($"Unexpected AmplitudeFactor: {amplitudeDistribution}");
                return(1.0);
            }
        }
Exemple #5
0
        public STMAudioClip(
            double duration,
            double freqLB,
            double freqUB,
            int frequencyCount,
            double modulationDepth,
            double spectralModulationRate,
            double temporalModulationRate,
            RippleDirection rippleDirection,
            AmplitudeDistribution distribution,
            Random randomizer = null)
        {
            if (randomizer == null)
            {
                randomizer = new Random(CustomRandom.Next());
            }
            this.randomizer = randomizer;

            carrierToneGenerator = CreateSideBands(freqLB, freqUB, frequencyCount, distribution);
            sideBandGenerator    = ExpCarrierToneSideBands;

            this.modulationDepth        = modulationDepth;
            this.temporalModulationRate = temporalModulationRate;

            switch (rippleDirection)
            {
            case RippleDirection.Up:
                this.spectralModulationRate = spectralModulationRate;
                break;

            case RippleDirection.Down:
                this.spectralModulationRate = -spectralModulationRate;
                break;

            default:
                Debug.LogError($"Unexpected RippleDirection: {rippleDirection}");
                break;
            }

            _channelSamples = (int)Math.Ceiling(duration * SamplingRate);
        }
Exemple #6
0
        public AnalyticNoiseStream(
            double rms,
            double freqLB,
            double freqUB,
            int frequencyCount,
            AmplitudeDistribution distribution,
            Random randomizer = null)
        {
            if (randomizer == null)
            {
                randomizer = new Random(CustomRandom.Next());
            }
            this.randomizer = randomizer;

            this.rms            = rms;
            this.freqLB         = freqLB;
            this.freqUB         = freqUB;
            this.frequencyCount = frequencyCount;

            this.distribution = distribution;
        }
Exemple #7
0
        public NoiseAudioClip(
            double duration,
            double rms,
            double freqLB,
            double freqUB,
            int frequencyCount,
            AmplitudeDistribution distribution,
            Random randomizer = null)
        {
            if (randomizer == null)
            {
                randomizer = new Random(CustomRandom.Next());
            }
            this.randomizer = randomizer;

            this.rms            = rms;
            this.freqLB         = freqLB;
            this.freqUB         = freqUB;
            this.frequencyCount = frequencyCount;

            this.distribution = distribution;

            _channelSamples = (int)Math.Ceiling(duration * SamplingRate);
        }