Class IAudioResampler


  • public class IAudioResampler
    extends RefCounted
    Used to resample {IAudioSamples} to different sample rates or number of channels.
    • Constructor Detail

      • IAudioResampler

        protected IAudioResampler​(long cPtr,
                                  boolean cMemoryOwn)
        Internal Only.
      • IAudioResampler

        protected IAudioResampler​(long cPtr,
                                  boolean cMemoryOwn,
                                  java.util.concurrent.atomic.AtomicLong ref)
        Internal Only.
    • Method Detail

      • getCPtr

        public static long getCPtr​(IAudioResampler obj)
        Internal Only. Not part of public API. Get the raw value of the native object that obj is proxying for.
        Parameters:
        obj - The java proxy object for a native object.
        Returns:
        The raw pointer obj is proxying for.
      • getMyCPtr

        public long getMyCPtr()
        Internal Only. Not part of public API. Get the raw value of the native object that we're proxying for.
        Overrides:
        getMyCPtr in class RefCounted
        Returns:
        The raw pointer we're proxying for.
      • equals

        public boolean equals​(java.lang.Object obj)
        Compares two values, returning true if the underlying objects in native code are the same object. That means you can have two different Java objects, but when you do a comparison, you'll find out they are the EXACT same object.
        Overrides:
        equals in class java.lang.Object
        Returns:
        True if the underlying native object is the same. False otherwise.
      • hashCode

        public int hashCode()
        Get a hashable value for this object.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        the hashable value.
      • getOutputChannels

        public int getOutputChannels()
        number of channels in output audio.
        Returns:
        Number of channels we'll resample the output to.
      • getOutputRate

        public int getOutputRate()
        sample rate of output audio.
        Returns:
        Sample Rate we'll resample the output to.
      • getInputChannels

        public int getInputChannels()
        number of channels expected in input audio.
        Returns:
        Number of channels we'll expect in the input samples
      • getInputRate

        public int getInputRate()
        sample rate expected in input audio.
        Returns:
        Sample rate we'll expect in the input samples
      • resample

        public int resample​(IAudioSamples outputSamples,
                            IAudioSamples inputSamples,
                            int numSamples)
        Re-sample up to numSamples from inputSamples to outputSamples.


        This function re-samples the audio in inputSamples to have the same
        number of channels, and the same sample rate, as this {IAudioResampler} was
        initialized with.



        Caller is responsible for making sure that the IAudioSamples object
        passed in has enough space. This object requires space for an
        additional 16-samples * output-channels
        per {IAudioSamples} passed in.




        If the {outputSamples is not large enough to fit the required resamples, then the IAudioResampler will attempt to allocate a new output buffer and override the buffer set on outputSamples.
        To ensure you have enough space in your output buffer, use the getMinimumNumSamplesRequiredInOutputSamples(int) method.

        Parameters:
        outputSamples - [out] The sample buffer we output to.
        inputSamples - [in] The samples we're going to re-sample.
        numSamples - [in] The number of samples from inputSamples to use. if 0, this defaults to inputSamples.getNumSamples().
        Returns:
        Number of samples written to outputSamples, or <0 on error. }
      • make

        public static IAudioResampler make​(int outputChannels,
                                           int inputChannels,
                                           int outputRate,
                                           int inputRate)
        Create a new {IAudioResampler} object.


        Creation of {IAudioResampler} objects is relatively expensive compared
        to the {#resample(IAudioSamples, IAudioSamples, long)} method,
        so users are encouraged to create once and use often.



        This method assumes all samples are in IAudioSamples.Format.FMT_S16 format.


        Parameters:
        outputChannels - The number of channels you will want
        in resampled audio we output.
        inputChannels - The number of channels you will pass
        in the source audio for resampling.
        outputRate - The sample rate you will want
        in resampled audio we output.
        inputRate - The sample rate you will pass
        in the source audio for resampling.
        Returns:
        A new object, or null if we can't allocate one.
      • getFilterLen

        public int getFilterLen()
        Get the length of each filter in the resampler filter bank.
        Returns:
        the filter length
      • getLog2PhaseCount

        public int getLog2PhaseCount()
        Get log2(number of entries in filter bank).
        Returns:
        log2(number of entries in filter bank).
      • isLinear

        public boolean isLinear()
        Are we linearly interpolating between filters?
        Returns:
        true if interpolating, false if just choosing closest.
      • getCutoffFrequency

        public double getCutoffFrequency()
        What is the cuttoff frequency used?
        Returns:
        the cuttoff frequency
      • make

        public static IAudioResampler make​(int outputChannels,
                                           int inputChannels,
                                           int outputRate,
                                           int inputRate,
                                           IAudioSamples.Format outputFmt,
                                           IAudioSamples.Format inputFmt)
        Create a new {IAudioResampler} object.


        Creation of {IAudioResampler} objects is relatively expensive compared
        to the {#resample(IAudioSamples, IAudioSamples, long)} method,
        so users are encouraged to create once and use often.



        "Sensible" defaults are passed in for filter length and other
        parameters.


        Parameters:
        outputChannels - The number of channels you will want
        in resampled audio we output.
        inputChannels - The number of channels you will pass
        in the source audio for resampling.
        outputRate - The sample rate you will want
        in resampled audio we output.
        inputRate - The sample rate you will pass
        in the source audio for resampling.
        outputFmt - The format of the output samples.
        inputFmt - The format of the input samples.

        Returns:
        A new object, or null if we can't allocate one.
      • make

        public static IAudioResampler make​(int outputChannels,
                                           int inputChannels,
                                           int outputRate,
                                           int inputRate,
                                           IAudioSamples.Format outputFmt,
                                           IAudioSamples.Format inputFmt,
                                           int filterLen,
                                           int log2PhaseCount,
                                           boolean isLinear,
                                           double cutoffFrequency)
        Create a new {IAudioResampler} object.


        Creation of {IAudioResampler} objects is relatively expensive compared
        to the {#resample(IAudioSamples, IAudioSamples, long)} method,
        so users are encouraged to create once and use often.



        Parameters:
        outputChannels - The number of channels you will want
        in resampled audio we output.
        inputChannels - The number of channels you will pass
        in the source audio for resampling.
        outputRate - The sample rate you will want
        in resampled audio we output.
        inputRate - The sample rate you will pass
        in the source audio for resampling.
        outputFmt - The format of the output samples.
        inputFmt - The format of the input samples.
        filterLen - The length of each filter in the filterbank, relative to the cutoff frequency.
        log2PhaseCount - log2 of the number of entries in the polyphase filterbank
        isLinear - If true, the used filter will be linearly interpolated between the 2 closest filters.
        if false, the closest will be used.
        cutoffFrequency - Cutoff frequency. 1.0 is 1/2 the output sampling rate.

        Returns:
        A new object, or null if we can't allocate one.
      • getMinimumNumSamplesRequiredInOutputSamples

        public int getMinimumNumSamplesRequiredInOutputSamples​(IAudioSamples inSamples)
        Get the minimum number of samples that must be placeable in an
        output set of samples in order for a resample with this resampler
        to succeed.

        Parameters:
        inSamples - The input samples that will be passed to
        {#resample}.
        Returns:
        The minimum number of samples, or < 0 on error.
        Since:
        3.2
      • getMinimumNumSamplesRequiredInOutputSamples

        public int getMinimumNumSamplesRequiredInOutputSamples​(int numSamples)
        Get the minimum number of samples that must be placeable in an
        output set of samples in order for a resample with this resampler
        to succeed.

        Parameters:
        numSamples - The number of input samples.
        Returns:
        The minimum number of samples, or < 0 on error.
        Since:
        3.2