-
- All Superinterfaces:
SamplingRateAccessor
,SamplingRateAccessor.SamplingRateBuilder<CurveFunctionSoundSampleBuilder>
,SamplingRateAccessor.SamplingRateMutator
,SamplingRateAccessor.SamplingRateProperty
- All Known Implementing Classes:
CurveFunctionSoundSampleBuilderImpl
public interface CurveFunctionSoundSampleBuilder extends SamplingRateAccessor.SamplingRateProperty, SamplingRateAccessor.SamplingRateBuilder<CurveFunctionSoundSampleBuilder>
TheCurveFunctionSoundSampleBuilder
makes 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 MonoSampleBuilder
asMonoSample(double aIndex, Function<Double,Double> aFunction, double aFrequencyHz, double aAmplitude, int aXOffset, double aYOffset, int aSamplingRate)
Creates aMonoSample
for the given arguments and the given function.static CurveFunctionSoundSampleBuilder
build()
This is a convenience method for easily instantiating the according builder.double
getAmplitude()
Returns the amplitude being used when generatingMonoSample
instances.double
getFrequency()
Returns the frequency in Hz being used when generatingMonoSample
instances.int
getIndex()
Returns the index being used when generatingMonoSample
instances.Function<Double,Double>
getTrigonometricFunction()
Returns the trigonometric function being used when generatingMonoSample
instances.int
getXOffset()
Returns the x-offset being used when generatingMonoSample
instances.double
getYOffset()
Returns the yOffset being used when generatingMonoSample
instances.MonoSample
next()
Returns the nextMonoSample
for the current index (as ofgetIndex()
) as well as for the other builder's settings and increases the index by one.void
setAmplitude(double aAmplitude)
Sets the amplitude to be used when generatingMonoSample
instances.void
setFrequency(double aFrequencyInHz)
Sets the frequency in Hz to be used when generatingMonoSample
instances.void
setIndex(int aIndex)
Sets the index to be used when generatingMonoSample
instances.void
setTrigonometricFunction(Function<Double,Double> aFunction)
Sets the trigonometric function to be used when generatingMonoSample
.default void
setTrigonometricFunction(CurveFunctionFunction aFunction)
Sets the trigonometric function to be used when generatingMonoSample
.void
setXOffset(int aXOffset)
Sets the x-offset to be used when generatingMonoSample
instances.void
setYOffset(double aYOffset)
Sets the y-offset to be used when generatingMonoSample
instances.MonoSample
toMonoSample()
Creates aMonoSample
as of the builder's settings.MonoSample
toMonoSample(int aIndex)
Creates aMonoSample
for the given index and the the builder's settings.default CurveFunctionSoundSampleBuilder
withAmplitude(double aAmplitude)
Builder method for setting the amplitude to be used when generatingMonoSample
instances.default CurveFunctionSoundSampleBuilder
withFrequency(double aFrequencyInHz)
Builder method for setting the frequency in Hz to be used when generatingMonoSample
instances.default CurveFunctionSoundSampleBuilder
withIndex(int aIndex)
Builder method for setting the index to be used when generatingMonoSample
instances.default CurveFunctionSoundSampleBuilder
withSamplingRate(int aSamplingRate)
Builder method for setting the sampling rate to be used when generatingMonoSample
instances.default CurveFunctionSoundSampleBuilder
withTrigonometricFunction(Function<Double,Double> aFunction)
Builder method for setting the trigonometric function to be used when generatingMonoSample
instances.default CurveFunctionSoundSampleBuilder
withTrigonometricFunction(CurveFunctionFunction aFunction)
Builder method for setting the trigonometric function to be used when generatingMonoSample
instances.default CurveFunctionSoundSampleBuilder
withXOffset(int aXOffset)
Builder method for setting the x-offset to be used when generatingMonoSample
instances.default CurveFunctionSoundSampleBuilder
withYOffset(double aYOffset)
Builder method for setting the y-offset to be used when generatingMonoSample
instances.-
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
- TheFunction
to be set.
-
getTrigonometricFunction
Function<Double,Double> getTrigonometricFunction()
Returns the trigonometric function being used when generatingMonoSample
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 generatingMonoSample
instances.- Parameters:
aFunction
- TheFunction
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 generatingMonoSample
.- Parameters:
aFunction
- TheCurveFunctionFunction
to be set.
-
withTrigonometricFunction
default CurveFunctionSoundSampleBuilder withTrigonometricFunction(CurveFunctionFunction aFunction)
Builder method for setting the trigonometric function to be used when generatingMonoSample
instances.- Parameters:
aFunction
- TheCurveFunctionFunction
to be set.- Returns:
- This
CurveFunctionSoundSampleBuilder
instance for chaining multiple builder operations.
-
setIndex
void setIndex(int aIndex)
Sets the index to be used when generatingMonoSample
instances.- Parameters:
aIndex
- The index to be set.
-
getIndex
int getIndex()
Returns the index being used when generatingMonoSample
instances.- Returns:
- The index being set.
-
withIndex
default CurveFunctionSoundSampleBuilder withIndex(int aIndex)
Builder method for setting the index to be used when generatingMonoSample
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 generatingMonoSample
instances.- Parameters:
aFrequencyInHz
- The frequency to be set.
-
getFrequency
double getFrequency()
Returns the frequency in Hz being used when generatingMonoSample
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 generatingMonoSample
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 generatingMonoSample
instances.- Parameters:
aAmplitude
- The amplitude to be set.
-
getAmplitude
double getAmplitude()
Returns the amplitude being used when generatingMonoSample
instances.- Returns:
- The amplitude being set.
-
withAmplitude
default CurveFunctionSoundSampleBuilder withAmplitude(double aAmplitude)
Builder method for setting the amplitude to be used when generatingMonoSample
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 generatingMonoSample
instances.- Parameters:
aXOffset
- The x-offset to be set.
-
getXOffset
int getXOffset()
Returns the x-offset being used when generatingMonoSample
instances.- Returns:
- The x-offset being set.
-
withXOffset
default CurveFunctionSoundSampleBuilder withXOffset(int aXOffset)
Builder method for setting the x-offset to be used when generatingMonoSample
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 generatingMonoSample
instances.- Parameters:
aYOffset
- The y-offset to be set.
-
getYOffset
double getYOffset()
Returns the yOffset being used when generatingMonoSample
instances.- Returns:
- The yOffset being set.
-
withYOffset
default CurveFunctionSoundSampleBuilder withYOffset(double aYOffset)
Builder method for setting the y-offset to be used when generatingMonoSample
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 generatingMonoSample
instances.- Specified by:
withSamplingRate
in interfaceSamplingRateAccessor.SamplingRateBuilder<CurveFunctionSoundSampleBuilder>
- Parameters:
aSamplingRate
- The sampling rate to be set.- Returns:
- This
CurveFunctionSoundSampleBuilder
instance for chaining multiple builder operations.
-
next
MonoSample next()
Returns the nextMonoSample
for the current index (as ofgetIndex()
) 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 aMonoSample
as of the builder's settings.- Returns:
- The sound sample as of the builder's settings.
-
toMonoSample
MonoSample toMonoSample(int aIndex)
Creates aMonoSample
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 aMonoSample
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
static CurveFunctionSoundSampleBuilder build()
This is a convenience method for easily instantiating the according builder.- Returns:
- an instance (using a default implementation) of this builder
-
-