Interface CurveFunctionSoundSampleBuilder

All Superinterfaces:
SamplingRateAccessor, SamplingRateAccessor.SamplingRateBuilder<CurveFunctionSoundSampleBuilder>, SamplingRateAccessor.SamplingRateMutator, SamplingRateAccessor.SamplingRateProperty
All Known Implementing Classes:
CurveFunctionSoundSampleBuilderImpl

The CurveFunctionSoundSampleBuilder makes it easy to create sound samples for some (trigonometric) functions. The provided function should return double values between -1 and 1.
  • Method Details

    • setTrigonometricFunction

      void setTrigonometricFunction(Function<Double,Double> aFunction)
      Sets the trigonometric function to be used when generating MonoSample.
      Parameters:
      aFunction - The Function to be set.
    • getTrigonometricFunction

      Function<Double,Double> getTrigonometricFunction()
      Returns the trigonometric function being used when generating MonoSample instances.
      Returns:
      The Function being set.
    • withTrigonometricFunction

      default CurveFunctionSoundSampleBuilder withTrigonometricFunction(Function<Double,Double> aFunction)
      Builder method for setting the trigonometric function to be used when generating MonoSample instances.
      Parameters:
      aFunction - The Function to be set.
      Returns:
      This CurveFunctionSoundSampleBuilder instance for chaining multiple builder operations.
    • setTrigonometricFunction

      default void setTrigonometricFunction(CurveFunctionFunction aFunction)
      Sets the trigonometric function to be used when generating MonoSample.
      Parameters:
      aFunction - The CurveFunctionFunction to be set.
    • withTrigonometricFunction

      default CurveFunctionSoundSampleBuilder withTrigonometricFunction(CurveFunctionFunction aFunction)
      Builder method for setting the trigonometric function to be used when generating MonoSample instances.
      Parameters:
      aFunction - The CurveFunctionFunction to be set.
      Returns:
      This CurveFunctionSoundSampleBuilder instance for chaining multiple builder operations.
    • setIndex

      void setIndex(int aIndex)
      Sets the index to be used when generating MonoSample instances.
      Parameters:
      aIndex - The index to be set.
    • getIndex

      int getIndex()
      Returns the index being used when generating MonoSample instances.
      Returns:
      The index being set.
    • withIndex

      default CurveFunctionSoundSampleBuilder withIndex(int aIndex)
      Builder method for setting the index to be used when generating MonoSample instances.
      Parameters:
      aIndex - The index to be set.
      Returns:
      This CurveFunctionSoundSampleBuilder instance for chaining multiple builder operations.
    • setFrequency

      void setFrequency(double aFrequencyInHz)
      Sets the frequency in Hz to be used when generating MonoSample instances.
      Parameters:
      aFrequencyInHz - The frequency to be set.
    • getFrequency

      double getFrequency()
      Returns the frequency in Hz being used when generating MonoSample instances.
      Returns:
      The frequency in Hz being set.
    • withFrequency

      default CurveFunctionSoundSampleBuilder withFrequency(double aFrequencyInHz)
      Builder method for setting the frequency in Hz to be used when generating MonoSample instances.
      Parameters:
      aFrequencyInHz - The frequency in Hz to be set.
      Returns:
      This CurveFunctionSoundSampleBuilder instance for chaining multiple builder operations.
    • setAmplitude

      void setAmplitude(double aAmplitude)
      Sets the amplitude to be used when generating MonoSample instances.
      Parameters:
      aAmplitude - The amplitude to be set.
    • getAmplitude

      double getAmplitude()
      Returns the amplitude being used when generating MonoSample instances.
      Returns:
      The amplitude being set.
    • withAmplitude

      default CurveFunctionSoundSampleBuilder withAmplitude(double aAmplitude)
      Builder method for setting the amplitude to be used when generating MonoSample instances.
      Parameters:
      aAmplitude - The amplitude to be set.
      Returns:
      This CurveFunctionSoundSampleBuilder instance for chaining multiple builder operations.
    • setXOffset

      void setXOffset(int aXOffset)
      Sets the x-offset to be used when generating MonoSample instances.
      Parameters:
      aXOffset - The x-offset to be set.
    • getXOffset

      int getXOffset()
      Returns the x-offset being used when generating MonoSample instances.
      Returns:
      The x-offset being set.
    • withXOffset

      default CurveFunctionSoundSampleBuilder withXOffset(int aXOffset)
      Builder method for setting the x-offset to be used when generating MonoSample instances.
      Parameters:
      aXOffset - The x-offset to be set.
      Returns:
      This CurveFunctionSoundSampleBuilder instance for chaining multiple builder operations.
    • setYOffset

      void setYOffset(double aYOffset)
      Sets the y-offset to be used when generating MonoSample instances.
      Parameters:
      aYOffset - The y-offset to be set.
    • getYOffset

      double getYOffset()
      Returns the yOffset being used when generating MonoSample instances.
      Returns:
      The yOffset being set.
    • withYOffset

      default CurveFunctionSoundSampleBuilder withYOffset(double aYOffset)
      Builder method for setting the y-offset to be used when generating MonoSample instances.
      Parameters:
      aYOffset - The y-offset to be set.
      Returns:
      This CurveFunctionSoundSampleBuilder instance for chaining multiple builder operations.
    • withSamplingRate

      default CurveFunctionSoundSampleBuilder withSamplingRate(int aSamplingRate)
      Builder method for setting the sampling rate to be used when generating MonoSample instances.
      Specified by:
      withSamplingRate in interface SamplingRateAccessor.SamplingRateBuilder<CurveFunctionSoundSampleBuilder>
      Parameters:
      aSamplingRate - The sampling rate to be set.
      Returns:
      This CurveFunctionSoundSampleBuilder instance for chaining multiple builder operations.
    • next

      MonoSample next()
      Returns the next MonoSample for the current index (as of getIndex()) as well as for the other builder's settings and increases the index by one.
      Returns:
      The next MonoSample being set up.
    • toMonoSample

      MonoSample toMonoSample()
      Creates a MonoSample as of the builder's settings.
      Returns:
      The sound sample as of the builder's settings.
    • toMonoSample

      MonoSample toMonoSample(int aIndex)
      Creates a MonoSample for the given index and the the builder's settings.
      Parameters:
      aIndex - The index for which to create the sound sample.
      Returns:
      The sound sample as of the index and the builder's settings.
    • asMonoSample

      static MonoSampleBuilder asMonoSample(double aIndex, Function<Double,Double> aFunction, double aFrequencyHz, double aAmplitude, int aXOffset, double aYOffset, int aSamplingRate)
      Creates a MonoSample for the given arguments and the given function. Thanks to willemsenzo, May 18, 2017: return Mathf.Sin(2 * Mathf.PI * timeIndex * frequency / sampleRate); See "https://forum.unity.com/threads/generating-a-simple-sinewave.471529"
      Parameters:
      aIndex - The index of the sample to generate.
      aFunction - The function to be applied (sine, cosine, ...).
      aFrequencyHz - The frequency (Hz) to use.
      aAmplitude - The maximum amplitude to produce.
      aXOffset - The x-offset (in samples) to be used.
      aYOffset - The y-offset for the amplitude to be used.
      aSamplingRate - The samples per second to generate.
      Returns:
      The MonoSample generated from the given input values.
    • build

      This is a convenience method for easily instantiating the according builder.
      Returns:
      an instance (using a default implementation) of this builder