Modifier and Type | Field and Description |
---|---|
protected static Audio |
audio |
static int |
C2 |
static java.lang.String |
VOL_SETTING |
ASCENDING, BEEP, BUZZ, DESCENDING, DOUBLE_BEEP, FLUTE, PIANO, VOL_MAX, XYLOPHONE
Modifier and Type | Method and Description |
---|---|
static void |
beep()
Beeps once.
|
static void |
beepSequence()
Downward tones.
|
static void |
beepSequenceUp()
Upward tones.
|
static void |
buzz()
Low buzz
|
static int |
getTime()
Returns the number of milliseconds remaining of the current tone or sample.
|
static int |
getVolume()
Get the current master volume level
|
static void |
loadSettings()
Load the current system settings associated with this class.
|
static void |
pause(int t) |
static void |
playNote(int[] inst,
int freq,
int len)
Play a note with attack, decay, sustain and release shape, which is known as
a ADSR envelope.
|
static int |
playSample(byte[] data,
int offset,
int len,
int freq,
int vol)
Queue a series of PCM samples to play at the
specified volume and sample rate.
|
static int |
playSample(java.io.File file)
Play a wav file.
|
static int |
playSample(java.io.File file,
int vol)
Play a wav file.
|
static void |
playTone(int freq,
int duration)
Plays a tone, given its frequency and duration.
|
static void |
playTone(int aFrequency,
int aDuration,
int aVolume)
Plays a tone, given its frequency and duration.
|
static void |
setVolume(int vol)
Set the master volume level
|
static void |
systemSound(boolean aQueued,
int aCode)
Play a system sound.
|
static void |
twoBeeps()
Beeps twice.
|
protected static final Audio audio
public static final java.lang.String VOL_SETTING
public static int C2
public static void systemSound(boolean aQueued, int aCode)
aCode | Resulting Sound |
---|---|
0 | short beep |
1 | double beep |
2 | descending arpeggio |
3 | ascending arpeggio |
4 | long, low buzz |
public static void beep()
public static void twoBeeps()
public static void beepSequence()
public static void beepSequenceUp()
public static void buzz()
public static void pause(int t)
public static int getTime()
public static void playTone(int aFrequency, int aDuration, int aVolume)
aFrequency
- The frequency of the tone in Hertz (Hz).aDuration
- The duration of the tone, in milliseconds.aVolume
- The volume of the playback 100 corresponds to 100%public static void playTone(int freq, int duration)
freq
- The frequency of the tone in Hertz (Hz).duration
- The duration of the tone, in milliseconds.public static int playSample(java.io.File file, int vol)
file
- the 8-bit or 16-bit PWM (WAV) sample filevol
- the volume percentage 0 - 100java.io.FileNotFoundException
public static int playSample(java.io.File file)
file
- the 8-bit or 16-bit PWM (WAV) sample filejava.io.FileNotFoundException
public static int playSample(byte[] data, int offset, int len, int freq, int vol)
data
- Buffer containing the samplesoffset
- Offset of the first sample in the bufferlen
- Number of samples to queuefreq
- Sample ratevol
- playback volumepublic static void playNote(int[] inst, int freq, int len)
Play a note with attack, decay, sustain and release shape, which is known as a ADSR envelope. This function plays a more musical sounding note compared to playTone(). It uses a set of supplied "instrument" parameters to define the shape of the note's envelope.
Instruments are defined in the Sounds interface, which is inherited by this class. For example, the piano instrument array looks like this:
public final static int[] PIANO = new int[]{4, 25, 500, 7000, 5};
The parameter len is the total time of the note to be played val 0 is the attack time the time for the volume to go from near zero to 100% val 1 is the decay time during this period the volume decreases by val[2]/100 to the sustain level. the sustain period is (len - val[0] - val[1] - val[4]) during this period the volume decreases by val[3]/100. the final decay period is val[4] and the volume reduces to zero. All of the times are units of 2mS (except for len which is in mS).
Because values equal 2ms, the piano array numbers are doubled:
1. take 8mS to increase the volume from zero to 100%
2. take 50mS to decrese the volume by 5%
3. take len - 8 - 25 - 10 mS to decrease the volume by 70%
4. take 10mS to decrease the volume to 0
inst
- Instrument definition (5 ints in an array).freq
- The note to play (in Hz)len
- The duration of the note (in ms)public static void setVolume(int vol)
vol
- 0-100public static int getVolume()
public static void loadSettings()