Package ftclib.archive
Class FtcAndroidTone
java.lang.Object
trclib.driverio.TrcTone
ftclib.archive.FtcAndroidTone
- All Implemented Interfaces:
android.media.AudioTrack.OnPlaybackPositionUpdateListener
public class FtcAndroidTone
extends TrcTone
implements android.media.AudioTrack.OnPlaybackPositionUpdateListener
This class implements a platform dependent sound player that can play a tone with specified waveform, frequency,
duration and volume using the Android AudioTrack.
-
Nested Class Summary
Nested classes/interfaces inherited from class trclib.driverio.TrcTone
TrcTone.Waveform
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate double
private android.media.AudioTrack
private double
private static final int
private static final TrcTone.Waveform
private boolean
private boolean
private double
private final int
private double
-
Constructor Summary
ConstructorsConstructorDescriptionFtcAndroidTone
(String instanceName) Constructor: Create and initialize an instance of the object.FtcAndroidTone
(String instanceName, TrcTone.Waveform defWaveform) Constructor: Create and initialize an instance of the object.FtcAndroidTone
(String instanceName, TrcTone.Waveform defWaveform, int sampleRate) Constructor: Create and initialize an instance of the object. -
Method Summary
Modifier and TypeMethodDescriptionboolean
This method checks if the sound is still playing.void
onMarkerReached
(android.media.AudioTrack track) This method is called when the sample at the set marker has been played.void
onPeriodicNotification
(android.media.AudioTrack track) This method is called when the period marker has been reached.void
playSound
(short[] buffer) This method plays the sound data in the specified buffer.void
playTone
(TrcTone.Waveform waveform, double frequency, double duration, double volume) This method plays a tone with the specified waveform, frequency, duration and volume.void
setSoundEnvelope
(double attack, double decay, double sustain, double release) This method sets the sound envelope parameters ADSR (Attack, Decay, Sustain, Release).void
setSoundEnvelopeEnabled
(boolean enabled) This method enables/disables the sound envelope.void
stop()
This method stops the playing of the sound in progress.Methods inherited from class trclib.driverio.TrcTone
applySoundEnvelope, genSineWave, genSquareWave, genTriangleWave, playTone, playTone
-
Field Details
-
DEF_WAVEFORM
-
DEF_SAMPLERATE
private static final int DEF_SAMPLERATE- See Also:
-
sampleRate
private final int sampleRate -
audioTrack
private android.media.AudioTrack audioTrack -
playing
private boolean playing -
attack
private double attack -
decay
private double decay -
sustain
private double sustain -
release
private double release -
envelopeEnabled
private boolean envelopeEnabled
-
-
Constructor Details
-
FtcAndroidTone
Constructor: Create and initialize an instance of the object.- Parameters:
instanceName
- specifies the instance name.defWaveform
- specifies the default waveform type.sampleRate
- specifies the sampling rate.
-
FtcAndroidTone
Constructor: Create and initialize an instance of the object.- Parameters:
instanceName
- specifies the instance name.defWaveform
- specifies the default waveform type.
-
FtcAndroidTone
Constructor: Create and initialize an instance of the object.- Parameters:
instanceName
- specifies the instance name.
-
-
Method Details
-
setSoundEnvelope
public void setSoundEnvelope(double attack, double decay, double sustain, double release) This method sets the sound envelope parameters ADSR (Attack, Decay, Sustain, Release). Attack, Decay and Release are time parameters in seconds. Sustain is a level parameter ranged from 0.0 to 1.0 (i.e. percentage of maximum volume).- Parameters:
attack
- specifies attack time in seconds.decay
- specifies decay time in seconds.sustain
- specifies sustain level in the range of 0.0 to 1.0. It is multiplied with the maximum volume to get the sustain level volume.release
- specifies the release time in seconds.
-
setSoundEnvelopeEnabled
public void setSoundEnvelopeEnabled(boolean enabled) This method enables/disables the sound envelope. -
playSound
public void playSound(short[] buffer) This method plays the sound data in the specified buffer.- Parameters:
buffer
- specifies the sound data buffer.
-
playTone
This method plays a tone with the specified waveform, frequency, duration and volume. -
stop
public void stop()This method stops the playing of the sound in progress. -
isPlaying
public boolean isPlaying()This method checks if the sound is still playing. -
onMarkerReached
public void onMarkerReached(android.media.AudioTrack track) This method is called when the sample at the set marker has been played. This is used to indicate the completion of the tone played.- Specified by:
onMarkerReached
in interfaceandroid.media.AudioTrack.OnPlaybackPositionUpdateListener
- Parameters:
track
- specifies the AudioTrack object that was playing.
-
onPeriodicNotification
public void onPeriodicNotification(android.media.AudioTrack track) This method is called when the period marker has been reached.- Specified by:
onPeriodicNotification
in interfaceandroid.media.AudioTrack.OnPlaybackPositionUpdateListener
- Parameters:
track
- specifies the AudioTrack object that was playing.
-