Class ShadowAudioTrack


  • @Implements(value=android.media.AudioTrack.class,
                looseSignatures=true)
    public class ShadowAudioTrack
    extends java.lang.Object
    Implementation of a couple methods in AudioTrack. Only a couple methods are supported, other methods are expected run through the real class. The two AudioTrack.WriteMode are treated the same.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected static int native_get_min_buff_size​(int sampleRateInHz, int channelConfig, int audioFormat)
      Returns a predefined or default minimum buffer size.
      protected int native_write_byte​(byte[] audioData, int offsetInBytes, int sizeInBytes, int format, boolean isBlocking)
      Always return the number of bytes to write.
      static void setMinBufferSize​(int bufferSize)
      In the real class, the minimum buffer size is estimated from audio sample rate and other factors.
      protected int write​(java.nio.ByteBuffer audioData, int sizeInBytes, int writeMode)
      Always return the number of bytes to write except with invalid parameters.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • DEFAULT_MIN_BUFFER_SIZE

        protected static final int DEFAULT_MIN_BUFFER_SIZE
        See Also:
        Constant Field Values
    • Constructor Detail

      • ShadowAudioTrack

        public ShadowAudioTrack()
    • Method Detail

      • setMinBufferSize

        public static void setMinBufferSize​(int bufferSize)
        In the real class, the minimum buffer size is estimated from audio sample rate and other factors. We do not provide such estimation in native_get_min_buff_size(int, int, int), instead letting users set the minimum for the expected audio sample. Usually higher sample rate requires bigger buffer size.
      • native_get_min_buff_size

        @Implementation
        protected static int native_get_min_buff_size​(int sampleRateInHz,
                                                      int channelConfig,
                                                      int audioFormat)
        Returns a predefined or default minimum buffer size. Audio format and config are neglected.
      • native_write_byte

        @Implementation(minSdk=23)
        protected final int native_write_byte​(byte[] audioData,
                                              int offsetInBytes,
                                              int sizeInBytes,
                                              int format,
                                              boolean isBlocking)
        Always return the number of bytes to write. This method returns immedidately even with AudioTrack.WRITE_BLOCKING
      • write

        @Implementation(minSdk=21)
        protected int write​(@NonNull
                            java.nio.ByteBuffer audioData,
                            int sizeInBytes,
                            int writeMode)
        Always return the number of bytes to write except with invalid parameters. Assumes AudioTrack is already initialized (object properly created). Do not block even if AudioTrack in offload mode is in STOPPING play state. This method returns immediately even with AudioTrack.WRITE_BLOCKING