Class AudioCaptureClient


  • public class AudioCaptureClient
    extends Object
    Abstracts the initialization of an IAudioCaptureClient instance from a MediaLocator, the input of data from that IAudioCaptureClient, the buffering of that data, the starting, stopping and closing of the IAudioCaptureClient. Allows WASAPIStream to simultaneously utilize multiple IAudioCaptureClient instances (e.g. in the case of acoustic echo cancellation in which audio is input from both the capture and the render endpoint devices).
    Author:
    Lyubomir Marinov
    • Constructor Summary

      Constructors 
      Constructor Description
      AudioCaptureClient​(WASAPISystem audioSystem, javax.media.MediaLocator locator, AudioSystem.DataFlow dataFlow, int streamFlags, long hnsBufferDuration, javax.media.format.AudioFormat outFormat, javax.media.protocol.BufferTransferHandler transferHandler)
      Initializes a new AudioCaptureClient instance.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Releases the resources acquired by this instance throughout its lifetime and prepares it to be garbage collected.
      int read​(byte[] buffer, int offset, int length)
      Reads audio data from this instance into a specific byte array.
      int read​(IMediaBuffer iMediaBuffer, int length)
      Reads audio data from this instance into a specific IMediaBuffer.
      void start()
      Starts the transfer of media from the IAudioCaptureClient identified by the MediaLocator with which this instance has been initialized.
      void stop()
      Stops the transfer of media from the IAudioCaptureClient identified by the MediaLocator with which this instance has been initialized.
    • Constructor Detail

      • AudioCaptureClient

        public AudioCaptureClient​(WASAPISystem audioSystem,
                                  javax.media.MediaLocator locator,
                                  AudioSystem.DataFlow dataFlow,
                                  int streamFlags,
                                  long hnsBufferDuration,
                                  javax.media.format.AudioFormat outFormat,
                                  javax.media.protocol.BufferTransferHandler transferHandler)
                           throws Exception
        Initializes a new AudioCaptureClient instance.
        Parameters:
        audioSystem - the WASAPISystem instance which has contributed locator
        locator - a MediaLocator which identifies the audio endpoint device to be opened and read by the new instance
        dataFlow - the AudioSystem.DataFlow of the audio endpoint device identified by locator. If AudioSystem.DataFlow.PLAYBACK and streamFlags includes WASAPI.AUDCLNT_STREAMFLAGS_LOOPBACK, allows opening a render endpoint device in loopback mode and inputing the data that is being written on that render endpoint device
        streamFlags - zero or more of the AUDCLNT_STREAMFLAGS_XXX flags defined by the WASAPI class
        hnsBufferDuration - the base of the duration in milliseconds of the buffer that the audio application will share with the audio engine. If Format.NOT_SPECIFIED, the method uses the default interval between periodic passes by the audio engine.
        outFormat - the AudioFormat of the data to be made available by the new instance. Eventually, the IAudioCaptureClient to be represented by the new instance may be initialized with a different AudioFormat in which case the new instance will automatically transcode the data input from the IAudioCaptureClient into the specified outFormat.
        transferHandler - the BufferTransferHandler to be invoked when the new instance has made data available to be read via read(byte[], int, int)
        Throws:
        Exception - if the initialization of the new instance fails
    • Method Detail

      • close

        public void close()
        Releases the resources acquired by this instance throughout its lifetime and prepares it to be garbage collected.
      • read

        public int read​(byte[] buffer,
                        int offset,
                        int length)
                 throws IOException
        Reads audio data from this instance into a specific byte array.
        Parameters:
        buffer - the byte array into which the audio data read from this instance is to be written
        offset - the offset in buffer at which the writing of the audio data is to start
        length - the maximum number of bytes in buffer starting at offset to be written
        Returns:
        the number of bytes read from this instance and written into the specified buffer
        Throws:
        IOException - if the reading from this instance or the writing into the specified buffer fails
      • read

        public int read​(IMediaBuffer iMediaBuffer,
                        int length)
                 throws IOException
        Reads audio data from this instance into a specific IMediaBuffer.
        Parameters:
        iMediaBuffer - the IMediaBuffer into which the audio data read from this instance is to be written
        length - the maximum number of bytes to read from this instance and write into the specified iMediaBuffer
        Returns:
        the number of bytes read from this instance and written into the specified iMediaBuffer
        Throws:
        IOException - if the reading of audio data from this instance or the writing into the specified iMediaBuffer fails
      • start

        public void start()
                   throws IOException
        Starts the transfer of media from the IAudioCaptureClient identified by the MediaLocator with which this instance has been initialized.
        Throws:
        IOException - if the starting of the transfer of media fails
      • stop

        public void stop()
                  throws IOException
        Stops the transfer of media from the IAudioCaptureClient identified by the MediaLocator with which this instance has been initialized.
        Throws:
        IOException - if the stopping of the transfer of media fails