|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectmckay.utilities.sound.sampled.AudioMethodsSynthesis
public class AudioMethodsSynthesis
A holder class for general static methods relating to sampled audio. Although
all methods can be used individually, the
synthesizeAndWriteToBuffer
method provides a single way of
accessing all of the functionality of the other methods.
The methods whose names beginning with "generateSamples" generate synthesized samples in the form of 2-D arrays of doubles, with dimensions of channel and time.
Arrays of this type can be turned into arrays of bytes in standard audio
formats using the writeSamplesToBuffer
method, or indirectly
using the synthesizeAndWriteToBuffer
method.
See the descriptions below for information on other available methods.
Constructor Summary | |
---|---|
AudioMethodsSynthesis()
|
Method Summary | |
---|---|
static double[][] |
generateSamplesBasicTone(double fund_freq,
int number_of_channels,
float sample_rate,
double max_frac_samp_rate,
int total_samples_per_chan)
Generates sample values for a tone consisting of a sinusoid at a fundamental frequency and additional sinusoids at 1.2 and 1.8 times this frequency. |
static double[][] |
generateSamplesDecayPulse(double fund_freq,
int number_of_channels,
float sample_rate,
double max_frac_samp_rate,
int total_samples_per_chan)
Generates sample values for a tone consisting of a single sinusoid that decays linearly to arrive at silence at the end of the audio. |
static double[][] |
generateSamplesFMSweep(double fund_freq,
int number_of_channels,
float sample_rate,
double max_frac_samp_rate,
int total_samples_per_chan)
Generates sample values for a tone consisting of a single sinusoid that undergoes a gradual linear frequency increase from 1/10 of the provided fundamental_frequency at the beginning of the sound to the fundamental_frequency at the end of the sound. |
static double[][] |
generateSamplesSineWave(double fund_freq,
int number_of_channels,
float sample_rate,
double max_frac_samp_rate,
int total_samples_per_chan)
Generates sample values for a tone consisting of a single sinusoid. |
static double[][] |
generateSamplesStereoPanning(double fund_freq,
int number_of_channels,
float sample_rate,
double max_frac_samp_rate,
int total_samples_per_chan)
Generates sample values for a sound consisting of a stereo sweep, starting with a relatively high frequency sinusoid on the left speaker and moving across to a sinusoid one octave lower on the right speaker. |
static double[][] |
generateSamplesStereoPingpong(double fund_freq,
int number_of_channels,
float sample_rate,
double max_frac_samp_rate,
int total_samples_per_chan)
Generates sample values for a sound consisting of a stereo pinpong, where the signal switches between the four channels four times per second. |
static double[][] |
generateWhiteNoise(int number_of_channels,
int total_samples_per_chan)
Generates sample values for an audio wave consisting of randomly generated white noise. |
static java.lang.String[] |
getSynthesisNames()
Returns the names of the types of synthesis that can be performed. |
static int |
getSynthesisTypeCode(java.lang.String synthesis_type_name)
Returns the code for use in the synthesis_type parameter of the synthesizeAndWriteToBuffer method that specifies to the
given type of synthesis. |
static double[][] |
synthesizeAndWriteToBuffer(byte[] buffer,
double duration,
javax.sound.sampled.AudioFormat audio_format,
int synthesis_type,
double gain,
double panning,
double fundamental_frequency,
double max_frac_samp_rate,
double click_avoid_env_length)
Populates the given buffer with synthesized sound samples using the given AudioFormat . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public AudioMethodsSynthesis()
Method Detail |
---|
public static double[][] synthesizeAndWriteToBuffer(byte[] buffer, double duration, javax.sound.sampled.AudioFormat audio_format, int synthesis_type, double gain, double panning, double fundamental_frequency, double max_frac_samp_rate, double click_avoid_env_length) throws java.lang.Exception
AudioFormat
. Alternatively, returns the sample values
in the form of a 2-D array of doubles if the buffer parameter is
null. If the buffer parameter is not null, then null is returned
and the buffer is filled.
Uses the provided synthesis type, overall gain, panning and (sometimes)
fudamental to synthesize the audiofrequency.
The size of the buffer parameter along with the
AudioFormat
used determines the duration of the sound to be
generated if the buffer parameter is not null. It is otherwise
determined by the duration parameter.
buffer
- The buffer of bytes to write synthesized
samples to. May be null if prefer
samples as a 2-D array of doubles rather
than an array of bytes.duration
- The time in seconds to generate. Is
ignored if the buffer parameter
is not null.audio_format
- The AudioFormat
to use for
encoding samples to the buffer
parameter. Only audio_formats consisting
of bit depths of 8 or 16 bits are
accepted, and encoding must consist of
big endian signed PCM samples.synthesis_type
- The code indicating what type of
synthesis is to be used to fill the
buffer parameter. These codes can
be accessed using the
getSynthesisTypeCode
method.gain
- The overall loudness of the samples.
This value must be between 0.0 and 1.0,
with 0.0 being silence and 1.0 being
maximum amplitude.panning
- The relative strength of the two stereo
channels. This parameter is ignored in
non-stereo cases. Value must be between
-1.0 and +1.0, with -1.0 corresponding
to full amplitude on the left channel
and silence on the right, and +1.0
corresponding to the reverse. A value of
0 indicates equal balance.fundamental_frequency
- The fundamental frequency of the sound
to be synthesiszed. Is ignored for some
types of synthesis.max_frac_samp_rate
- Used to determine the maximum allowable
frequency partial that will be permitted
to be synthesized. This is to avoid
aliasing, and generally a value of 0.45
is best, with values below 0.5 always
needed to ensure protection against
aliasing. The maximum allowable
frequency is determined by multiplying
this value by the sampling rate
contained in the audio_format
paramter.click_avoid_env_length
- The duration in seconds of an envelope
applied at the beginning and end of the
synthesized audio in order to avoid
clicks. Linear attenuation is used for
this amount of time on each end.
java.lang.Exception
- Throws an informative exception if an
invalid parameter is specified.public static int getSynthesisTypeCode(java.lang.String synthesis_type_name) throws java.lang.Exception
synthesizeAndWriteToBuffer
method that specifies to the
given type of synthesis.
synthesis_type_name
- The name of the type of synthesis to use
to generate audio.
java.lang.Exception
public static java.lang.String[] getSynthesisNames()
public static double[][] generateSamplesSineWave(double fund_freq, int number_of_channels, float sample_rate, double max_frac_samp_rate, int total_samples_per_chan) throws java.lang.Exception
This is an example of a standard sample generating method. All of the methods of this type implemented in this class produce a 2-D array of doubles whose first indice corresponds to channel and whose second incice corresponds to sample value. In mono, there is only one channel, and in stereo indice 0 indicates left and indice 1 indicates right. All samples generated by this type of method should fall between -1 and +1.
fund_freq
- The fundamental frequency of the tone to
be generated.number_of_channels
- The number of channels to generate
samples for.sample_rate
- The sampling rate to use for generating
samples.max_frac_samp_rate
- Used to determine the maximum allowable
frequency partial that will be permitted
to be synthesized. This is to avoid
aliasing, and generally a value of 0.45
is best, with values below 0.5 always
needed to ensure protection against
aliasing. The maximum allowable
frequency is determined by multiplying
this value by the sampling rate
contained in the sample_rate
paramter.total_samples_per_chan
- The total number of samples to generate
per channel. Combined with
sample_rate, this can be used to
find the time duration of the sound to
be generated.
java.lang.Exception
- Throws an exception if invalid
parameters provided.public static double[][] generateSamplesBasicTone(double fund_freq, int number_of_channels, float sample_rate, double max_frac_samp_rate, int total_samples_per_chan) throws java.lang.Exception
This is an example of a standard sample generating method. All of the methods of this type implemented in this class produce a 2-D array of doubles whose first indice corresponds to channel and whose second incice corresponds to sample value. In mono, there is only one channel, and in stereo indice 0 indicates left and indice 1 indicates right. All samples generated by this type of method should fall between -1 and +1.
fund_freq
- The fundamental frequency of the tone to
be generated.number_of_channels
- The number of channels to generate
samples for.sample_rate
- The sampling rate to use for generating
samples.max_frac_samp_rate
- Used to determine the maximum allowable
frequency partial that will be permitted
to be synthesized. This is to avoid
aliasing, and generally a value of 0.45
is best, with values below 0.5 always
needed to ensure protection against
aliasing. The maximum allowable
frequency is determined by multiplying
this value by the sampling rate
contained in the sample_rate
paramter.total_samples_per_chan
- The total number of samples to generate
per channel. Combined with
sample_rate, this can be used to
find the time duration of the sound to
be generated.
java.lang.Exception
- Throws an exception if invalid
parameters provided.public static double[][] generateSamplesStereoPanning(double fund_freq, int number_of_channels, float sample_rate, double max_frac_samp_rate, int total_samples_per_chan) throws java.lang.Exception
This is an example of a standard sample generating method. All of the methods of this type implemented in this class produce a 2-D array of doubles whose first indice corresponds to channel and whose second incice corresponds to sample value. In mono, there is only one channel, and in stereo indice 0 indicates left and indice 1 indicates right. All samples generated by this type of method should fall between -1 and +1.
fund_freq
- The frequency of the tone on the left
and twice the frequency of the tone on
the right.number_of_channels
- The number of channels to generate
samples for.sample_rate
- The sampling rate to use for generating
samples.max_frac_samp_rate
- Used to determine the maximum allowable
frequency partial that will be permitted
to be synthesized. This is to avoid
aliasing, and generally a value of 0.45
is best, with values below 0.5 always
needed to ensure protection against
aliasing. The maximum allowable
frequency is determined by multiplying
this value by the sampling rate
contained in the sample_rate
paramter.total_samples_per_chan
- The total number of samples to generate
per channel. Combined with
sample_rate, this can be used to
find the time duration of the sound to
be generated.
java.lang.Exception
- Throws an exception if invalid
parameters provided.public static double[][] generateSamplesStereoPingpong(double fund_freq, int number_of_channels, float sample_rate, double max_frac_samp_rate, int total_samples_per_chan) throws java.lang.Exception
This is an example of a standard sample generating method. All of the methods of this type implemented in this class produce a 2-D array of doubles whose first indice corresponds to channel and whose second incice corresponds to sample value. In mono, there is only one channel, and in stereo indice 0 indicates left and indice 1 indicates right. All samples generated by this type of method should fall between -1 and +1.
fund_freq
- The frequency of the tone on the left
and 1.25 times the frequency of the tone
on the right.number_of_channels
- The number of channels to generate
samples for.sample_rate
- The sampling rate to use for generating
samples.max_frac_samp_rate
- Used to determine the maximum allowable
frequency partial that will be permitted
to be synthesized. This is to avoid
aliasing, and generally a value of 0.45
is best, with values below 0.5 always
needed to ensure protection against
aliasing. The maximum allowable
frequency is determined by multiplying
this value by the sampling rate
contained in the sample_rate
paramter.total_samples_per_chan
- The total number of samples to generate
per channel. Combined with
sample_rate, this can be used to
find the time duration of the sound to
be generated.
java.lang.Exception
- Throws an exception if invalid
parameters provided.public static double[][] generateSamplesFMSweep(double fund_freq, int number_of_channels, float sample_rate, double max_frac_samp_rate, int total_samples_per_chan) throws java.lang.Exception
This is an example of a standard sample generating method. All of the methods of this type implemented in this class produce a 2-D array of doubles whose first indice corresponds to channel and whose second incice corresponds to sample value. In mono, there is only one channel, and in stereo indice 0 indicates left and indice 1 indicates right. All samples generated by this type of method should fall between -1 and +1.
fund_freq
- The final frequency of the tone to be
generated.number_of_channels
- The number of channels to generate
samples for.sample_rate
- The sampling rate to use for generating
samples.max_frac_samp_rate
- Used to determine the maximum allowable
frequency partial that will be permitted
to be synthesized. This is to avoid
aliasing, and generally a value of 0.45
is best, with values below 0.5 always
needed to ensure protection against
aliasing. The maximum allowable
frequency is determined by multiplying
this value by the sampling rate
contained in the sample_rate
paramter.total_samples_per_chan
- The total number of samples to generate
per channel. Combined with
sample_rate, this can be used to
find the time duration of the sound to
be generated.
java.lang.Exception
- Throws an exception if invalid
parameters provided.public static double[][] generateSamplesDecayPulse(double fund_freq, int number_of_channels, float sample_rate, double max_frac_samp_rate, int total_samples_per_chan) throws java.lang.Exception
This is an example of a standard sample generating method. All of the methods of this type implemented in this class produce a 2-D array of doubles whose first indice corresponds to channel and whose second incice corresponds to sample value. In mono, there is only one channel, and in stereo indice 0 indicates left and indice 1 indicates right. All samples generated by this type of method should fall between -1 and +1.
fund_freq
- The fundamental frequency of the tone to
be generated.number_of_channels
- The number of channels to generate
samples for.sample_rate
- The sampling rate to use for generating
samples.max_frac_samp_rate
- Used to determine the maximum allowable
frequency partial that will be permitted
to be synthesized. This is to avoid
aliasing, and generally a value of 0.45
is best, with values below 0.5 always
needed to ensure protection against
aliasing. The maximum allowable
frequency is determined by multiplying
this value by the sampling rate
contained in the sample_rate
paramter.total_samples_per_chan
- The total number of samples to generate
per channel. Combined with
sample_rate, this can be used to
find the time duration of the sound to
be generated.
java.lang.Exception
- Throws an exception if invalid
parameters provided.public static double[][] generateWhiteNoise(int number_of_channels, int total_samples_per_chan) throws java.lang.Exception
This is an example of a standard sample generating method. All of the methods of this type implemented in this class produce a 2-D array of doubles whose first indice corresponds to channel and whose second incice corresponds to sample value. In mono, there is only one channel, and in stereo indice 0 indicates left and indice 1 indicates right. All samples generated by this type of method should fall between -1 and +1.
number_of_channels
- The number of channels to generate
samples for.total_samples_per_chan
- The total number of samples to generate
per channel.
java.lang.Exception
- Throws an exception if invalid
parameters provided.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |