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.
  • Field Details

    • DEF_WAVEFORM

      private static final TrcTone.Waveform 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

      public FtcAndroidTone(String instanceName, TrcTone.Waveform defWaveform, int sampleRate)
      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

      public FtcAndroidTone(String instanceName, TrcTone.Waveform defWaveform)
      Constructor: Create and initialize an instance of the object.
      Parameters:
      instanceName - specifies the instance name.
      defWaveform - specifies the default waveform type.
    • FtcAndroidTone

      public FtcAndroidTone(String instanceName)
      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

      public void playTone(TrcTone.Waveform waveform, double frequency, double duration, double volume)
      This method plays a tone with the specified waveform, frequency, duration and volume.
      Specified by:
      playTone in class TrcTone
      Parameters:
      waveform - specifies the waveform type.
      frequency - specifies the tone frequency in Hz.
      duration - specifies the duration in seconds.
      volume - specifies the volume in the range 0.0 to 1.0.
    • stop

      public void stop()
      This method stops the playing of the sound in progress.
      Specified by:
      stop in class TrcTone
    • isPlaying

      public boolean isPlaying()
      This method checks if the sound is still playing.
      Specified by:
      isPlaying in class TrcTone
      Returns:
      true if the sound is still playing, false otherwise.
    • 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 interface android.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 interface android.media.AudioTrack.OnPlaybackPositionUpdateListener
      Parameters:
      track - specifies the AudioTrack object that was playing.