Class WASAPIRenderer

  • All Implemented Interfaces:
    javax.media.Controls, javax.media.PlugIn, javax.media.Renderer

    public class WASAPIRenderer
    extends AbstractAudioRenderer<WASAPISystem>
    Implements an audio Renderer using Windows Audio Session API (WASAPI) and related Core Audio APIs such as Multimedia Device (MMDevice) API.
    Author:
    Lyubomir Marinov
    • Constructor Detail

      • WASAPIRenderer

        public WASAPIRenderer()
        Initializes a new WASAPIRenderer instance which is to perform playback (as opposed to sound a notification).
      • WASAPIRenderer

        public WASAPIRenderer​(boolean playback)
        Initializes a new WASAPIRenderer instance which is to either perform playback or sound a notification.
        Parameters:
        playback - true if the new instance is to perform playback or false if the new instance is to sound a notification
    • Method Detail

      • maybeOpenResampler

        public static javax.media.Codec maybeOpenResampler​(javax.media.format.AudioFormat inFormat,
                                                           javax.media.format.AudioFormat outFormat)
        Attempts to initialize and open a new Codec to resample media data from a specific input AudioFormat into a specific output AudioFormat. If no suitable resampler is found, returns null. If a suitable resampler is found but its initialization or opening fails, logs and swallows any Throwable and returns null.
        Parameters:
        inFormat - the AudioFormat in which the new instance is to input media data
        outFormat - the AudioFormat in which the new instance is to output media data
        Returns:
        a new Codec which is able to resample media data from the specified inFormat into the specified outFormat if such a resampler could be found, initialized and opened; otherwise, null
      • pop

        public static int pop​(byte[] array,
                              int arrayLength,
                              int length)
        Pops a specific number of bytes from (the head of) a specific array of bytes.
        Parameters:
        array - the array of byte from which the specified number of bytes are to be popped
        arrayLength - the number of elements in array which contain valid data
        length - the number of bytes to be popped from array
        Returns:
        the number of elements in array which contain valid data after the specified number of bytes have been popped from it
      • getName

        public String getName()
      • getSupportedInputFormats

        public javax.media.Format[] getSupportedInputFormats()
        Overrides the super implementation to handle the case in which the user has selected "none" for the playback/notify device.
        Specified by:
        getSupportedInputFormats in interface javax.media.Renderer
        Overrides:
        getSupportedInputFormats in class AbstractAudioRenderer<WASAPISystem>
      • open

        public void open()
                  throws javax.media.ResourceUnavailableException
        Specified by:
        open in interface javax.media.PlugIn
        Overrides:
        open in class AbstractAudioRenderer<WASAPISystem>
        Throws:
        javax.media.ResourceUnavailableException
      • process

        public int process​(javax.media.Buffer buffer)
      • setInputFormat

        public javax.media.Format setInputFormat​(javax.media.Format format)
        Sets the Format of the media data to be rendered by this Renderer. Disallows mid-stream changes of the inputFormat of this AbstractRenderer.
        Specified by:
        setInputFormat in interface javax.media.Renderer
        Overrides:
        setInputFormat in class AbstractRenderer<javax.media.format.AudioFormat>
        Parameters:
        format - the Format of the media data to be rendered by this Renderer
        Returns:
        null if the specified format is not compatible with this Renderer; otherwise, the Format which has been successfully set
      • start

        public void start()
      • stop

        public void stop()