-
- All Superinterfaces:
SamplingRateAccessor,SamplingRateAccessor.SamplingRateBuilder<CurveFunctionSoundSampleBuilder>,SamplingRateAccessor.SamplingRateMutator,SamplingRateAccessor.SamplingRateProperty
- All Known Implementing Classes:
CurveFunctionSoundSampleBuilderImpl
public interface CurveFunctionSoundSampleBuilder extends SamplingRateAccessor.SamplingRateProperty, SamplingRateAccessor.SamplingRateBuilder<CurveFunctionSoundSampleBuilder>
TheCurveFunctionSoundSampleBuildermakes it easy to create sound samples for some (trigonometric) functions. The provided function should return double values between -1 and 1.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.refcodes.audio.SamplingRateAccessor
SamplingRateAccessor.SamplingRateBuilder<B extends SamplingRateAccessor.SamplingRateBuilder<B>>, SamplingRateAccessor.SamplingRateMutator, SamplingRateAccessor.SamplingRateProperty
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description static MonoSampleBuilderasMonoSample(double aIndex, Function<Double,Double> aFunction, double aFrequencyHz, double aAmplitude, int aXOffset, double aYOffset, int aSamplingRate)Creates aMonoSamplefor the given arguments and the given function.static CurveFunctionSoundSampleBuilderbuild()This is a convenience method for easily instantiating the according builder.doublegetAmplitude()Returns the amplitude being used when generatingMonoSampleinstances.doublegetFrequency()Returns the frequency in Hz being used when generatingMonoSampleinstances.intgetIndex()Returns the index being used when generatingMonoSampleinstances.Function<Double,Double>getTrigonometricFunction()Returns the trigonometric function being used when generatingMonoSampleinstances.intgetXOffset()Returns the x-offset being used when generatingMonoSampleinstances.doublegetYOffset()Returns the yOffset being used when generatingMonoSampleinstances.MonoSamplenext()Returns the nextMonoSamplefor the current index (as ofgetIndex()) as well as for the other builder's settings and increases the index by one.voidsetAmplitude(double aAmplitude)Sets the amplitude to be used when generatingMonoSampleinstances.voidsetFrequency(double aFrequencyInHz)Sets the frequency in Hz to be used when generatingMonoSampleinstances.voidsetIndex(int aIndex)Sets the index to be used when generatingMonoSampleinstances.voidsetTrigonometricFunction(Function<Double,Double> aFunction)Sets the trigonometric function to be used when generatingMonoSample.default voidsetTrigonometricFunction(CurveFunctionFunction aFunction)Sets the trigonometric function to be used when generatingMonoSample.voidsetXOffset(int aXOffset)Sets the x-offset to be used when generatingMonoSampleinstances.voidsetYOffset(double aYOffset)Sets the y-offset to be used when generatingMonoSampleinstances.MonoSampletoMonoSample()Creates aMonoSampleas of the builder's settings.MonoSampletoMonoSample(int aIndex)Creates aMonoSamplefor the given index and the the builder's settings.default CurveFunctionSoundSampleBuilderwithAmplitude(double aAmplitude)Builder method for setting the amplitude to be used when generatingMonoSampleinstances.default CurveFunctionSoundSampleBuilderwithFrequency(double aFrequencyInHz)Builder method for setting the frequency in Hz to be used when generatingMonoSampleinstances.default CurveFunctionSoundSampleBuilderwithIndex(int aIndex)Builder method for setting the index to be used when generatingMonoSampleinstances.default CurveFunctionSoundSampleBuilderwithSamplingRate(int aSamplingRate)Builder method for setting the sampling rate to be used when generatingMonoSampleinstances.default CurveFunctionSoundSampleBuilderwithTrigonometricFunction(Function<Double,Double> aFunction)Builder method for setting the trigonometric function to be used when generatingMonoSampleinstances.default CurveFunctionSoundSampleBuilderwithTrigonometricFunction(CurveFunctionFunction aFunction)Builder method for setting the trigonometric function to be used when generatingMonoSampleinstances.default CurveFunctionSoundSampleBuilderwithXOffset(int aXOffset)Builder method for setting the x-offset to be used when generatingMonoSampleinstances.default CurveFunctionSoundSampleBuilderwithYOffset(double aYOffset)Builder method for setting the y-offset to be used when generatingMonoSampleinstances.-
Methods inherited from interface org.refcodes.audio.SamplingRateAccessor
getSamplingRate
-
Methods inherited from interface org.refcodes.audio.SamplingRateAccessor.SamplingRateMutator
setSamplingRate
-
Methods inherited from interface org.refcodes.audio.SamplingRateAccessor.SamplingRateProperty
letSamplingRate
-
-
-
-
Method Detail
-
setTrigonometricFunction
void setTrigonometricFunction(Function<Double,Double> aFunction)
Sets the trigonometric function to be used when generatingMonoSample.- Parameters:
aFunction- TheFunctionto be set.
-
getTrigonometricFunction
Function<Double,Double> getTrigonometricFunction()
Returns the trigonometric function being used when generatingMonoSampleinstances.- Returns:
- The
Functionbeing set.
-
withTrigonometricFunction
default CurveFunctionSoundSampleBuilder withTrigonometricFunction(Function<Double,Double> aFunction)
Builder method for setting the trigonometric function to be used when generatingMonoSampleinstances.- Parameters:
aFunction- TheFunctionto be set.- Returns:
- This
CurveFunctionSoundSampleBuilderinstance for chaining multiple builder operations.
-
setTrigonometricFunction
default void setTrigonometricFunction(CurveFunctionFunction aFunction)
Sets the trigonometric function to be used when generatingMonoSample.- Parameters:
aFunction- TheCurveFunctionFunctionto be set.
-
withTrigonometricFunction
default CurveFunctionSoundSampleBuilder withTrigonometricFunction(CurveFunctionFunction aFunction)
Builder method for setting the trigonometric function to be used when generatingMonoSampleinstances.- Parameters:
aFunction- TheCurveFunctionFunctionto be set.- Returns:
- This
CurveFunctionSoundSampleBuilderinstance for chaining multiple builder operations.
-
setIndex
void setIndex(int aIndex)
Sets the index to be used when generatingMonoSampleinstances.- Parameters:
aIndex- The index to be set.
-
getIndex
int getIndex()
Returns the index being used when generatingMonoSampleinstances.- Returns:
- The index being set.
-
withIndex
default CurveFunctionSoundSampleBuilder withIndex(int aIndex)
Builder method for setting the index to be used when generatingMonoSampleinstances.- Parameters:
aIndex- The index to be set.- Returns:
- This
CurveFunctionSoundSampleBuilderinstance for chaining multiple builder operations.
-
setFrequency
void setFrequency(double aFrequencyInHz)
Sets the frequency in Hz to be used when generatingMonoSampleinstances.- Parameters:
aFrequencyInHz- The frequency to be set.
-
getFrequency
double getFrequency()
Returns the frequency in Hz being used when generatingMonoSampleinstances.- 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 generatingMonoSampleinstances.- Parameters:
aFrequencyInHz- The frequency in Hz to be set.- Returns:
- This
CurveFunctionSoundSampleBuilderinstance for chaining multiple builder operations.
-
setAmplitude
void setAmplitude(double aAmplitude)
Sets the amplitude to be used when generatingMonoSampleinstances.- Parameters:
aAmplitude- The amplitude to be set.
-
getAmplitude
double getAmplitude()
Returns the amplitude being used when generatingMonoSampleinstances.- Returns:
- The amplitude being set.
-
withAmplitude
default CurveFunctionSoundSampleBuilder withAmplitude(double aAmplitude)
Builder method for setting the amplitude to be used when generatingMonoSampleinstances.- Parameters:
aAmplitude- The amplitude to be set.- Returns:
- This
CurveFunctionSoundSampleBuilderinstance for chaining multiple builder operations.
-
setXOffset
void setXOffset(int aXOffset)
Sets the x-offset to be used when generatingMonoSampleinstances.- Parameters:
aXOffset- The x-offset to be set.
-
getXOffset
int getXOffset()
Returns the x-offset being used when generatingMonoSampleinstances.- Returns:
- The x-offset being set.
-
withXOffset
default CurveFunctionSoundSampleBuilder withXOffset(int aXOffset)
Builder method for setting the x-offset to be used when generatingMonoSampleinstances.- Parameters:
aXOffset- The x-offset to be set.- Returns:
- This
CurveFunctionSoundSampleBuilderinstance for chaining multiple builder operations.
-
setYOffset
void setYOffset(double aYOffset)
Sets the y-offset to be used when generatingMonoSampleinstances.- Parameters:
aYOffset- The y-offset to be set.
-
getYOffset
double getYOffset()
Returns the yOffset being used when generatingMonoSampleinstances.- Returns:
- The yOffset being set.
-
withYOffset
default CurveFunctionSoundSampleBuilder withYOffset(double aYOffset)
Builder method for setting the y-offset to be used when generatingMonoSampleinstances.- Parameters:
aYOffset- The y-offset to be set.- Returns:
- This
CurveFunctionSoundSampleBuilderinstance for chaining multiple builder operations.
-
withSamplingRate
default CurveFunctionSoundSampleBuilder withSamplingRate(int aSamplingRate)
Builder method for setting the sampling rate to be used when generatingMonoSampleinstances.- Specified by:
withSamplingRatein interfaceSamplingRateAccessor.SamplingRateBuilder<CurveFunctionSoundSampleBuilder>- Parameters:
aSamplingRate- The sampling rate to be set.- Returns:
- This
CurveFunctionSoundSampleBuilderinstance for chaining multiple builder operations.
-
next
MonoSample next()
Returns the nextMonoSamplefor the current index (as ofgetIndex()) as well as for the other builder's settings and increases the index by one.- Returns:
- The next
MonoSamplebeing set up.
-
toMonoSample
MonoSample toMonoSample()
Creates aMonoSampleas of the builder's settings.- Returns:
- The sound sample as of the builder's settings.
-
toMonoSample
MonoSample toMonoSample(int aIndex)
Creates aMonoSamplefor 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 aMonoSamplefor 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
MonoSamplegenerated from the given input values.
-
build
static CurveFunctionSoundSampleBuilder build()
This is a convenience method for easily instantiating the according builder.- Returns:
- an instance (using a default implementation) of this builder
-
-