001/* ----------------------------------------------------------------------------
002 * This file was automatically generated by SWIG (http://www.swig.org).
003 * Version 4.0.2
004 *
005 * Do not make changes to this file unless you know what you are doing--modify
006 * the SWIG interface file instead.
007 * ----------------------------------------------------------------------------- */
008
009package com.avpkit.core;
010import com.avpkit.ferry.*;
011/**
012 * Used to resample {IAudioSamples} to different sample rates or number of channels.
013 */
014public class IAudioResampler extends RefCounted {
015  // JNIHelper.swg: Start generated code
016  // >>>>>>>>>>>>>>>>>>>>>>>>>>>
017  /**
018   * This method is only here to use some references and remove
019   * a Eclipse compiler warning.
020   */
021  @SuppressWarnings("unused")
022  private void noop()
023  {
024    IBuffer.make(null, 1);
025  }
026   
027  private volatile long swigCPtr;
028
029  /**
030   * Internal Only.
031   */
032  protected IAudioResampler(long cPtr, boolean cMemoryOwn) {
033    super(AVPKitJNI.IAudioResampler_SWIGUpcast(cPtr), cMemoryOwn);
034    swigCPtr = cPtr;
035  }
036  
037  /**
038   * Internal Only.
039   */
040  protected IAudioResampler(long cPtr, boolean cMemoryOwn,
041      java.util.concurrent.atomic.AtomicLong ref)
042  {
043    super(AVPKitJNI.IAudioResampler_SWIGUpcast(cPtr),
044     cMemoryOwn, ref);
045    swigCPtr = cPtr;
046  }
047    
048  /**
049   * Internal Only.  Not part of public API.
050   *
051   * Get the raw value of the native object that obj is proxying for.
052   *   
053   * @param obj The java proxy object for a native object.
054   * @return The raw pointer obj is proxying for.
055   */
056  public static long getCPtr(IAudioResampler obj) {
057    if (obj == null) return 0;
058    return obj.getMyCPtr();
059  }
060
061  /**
062   * Internal Only.  Not part of public API.
063   *
064   * Get the raw value of the native object that we're proxying for.
065   *   
066   * @return The raw pointer we're proxying for.
067   */  
068  public long getMyCPtr() {
069    if (swigCPtr == 0) throw new IllegalStateException("underlying native object already deleted");
070    return swigCPtr;
071  }
072  
073  /**
074   * Create a new IAudioResampler object that is actually referring to the
075   * exact same underlying native object.
076   *
077   * @return the new Java object.
078   */
079  @Override
080  public IAudioResampler copyReference() {
081    if (swigCPtr == 0)
082      return null;
083    else
084      return new IAudioResampler(swigCPtr, swigCMemOwn, getJavaRefCount());
085  }
086
087  /**
088   * Compares two values, returning true if the underlying objects in native code are the same object.
089   *
090   * That means you can have two different Java objects, but when you do a comparison, you'll find out
091   * they are the EXACT same object.
092   *
093   * @return True if the underlying native object is the same.  False otherwise.
094   */
095  public boolean equals(Object obj) {
096    boolean equal = false;
097    if (obj instanceof IAudioResampler)
098      equal = (((IAudioResampler)obj).swigCPtr == this.swigCPtr);
099    return equal;
100  }
101  
102  /**
103   * Get a hashable value for this object.
104   *
105   * @return the hashable value.
106   */
107  public int hashCode() {
108     return (int)swigCPtr;
109  }
110  
111  // <<<<<<<<<<<<<<<<<<<<<<<<<<<
112  // JNIHelper.swg: End generated code
113  
114  /**
115   * number of channels in output audio.<br>
116   * @return Number of channels we'll resample the output to.
117   */
118  public int getOutputChannels() {
119    return AVPKitJNI.IAudioResampler_getOutputChannels(swigCPtr, this);
120  }
121
122  /**
123   * sample rate of output audio.<br>
124   * @return Sample Rate we'll resample the output to.
125   */
126  public int getOutputRate() {
127    return AVPKitJNI.IAudioResampler_getOutputRate(swigCPtr, this);
128  }
129
130  /**
131   * number of channels expected in input audio.<br>
132   * @return Number of channels we'll expect in the input samples
133   */
134  public int getInputChannels() {
135    return AVPKitJNI.IAudioResampler_getInputChannels(swigCPtr, this);
136  }
137
138  /**
139   * sample rate expected in input audio.<br>
140   * @return Sample rate we'll expect in the input samples
141   */
142  public int getInputRate() {
143    return AVPKitJNI.IAudioResampler_getInputRate(swigCPtr, this);
144  }
145
146  /**
147   * Re-sample up to numSamples from inputSamples to outputSamples.<br>
148   * <p><br>
149   * This function re-samples the audio in inputSamples to have the same<br>
150   * number of channels, and the same sample rate, as this {IAudioResampler} was<br>
151   * initialized with.<br>
152   * </p><br>
153   * <p><br>
154   * Caller is responsible for making sure that the IAudioSamples object<br>
155   * passed in has enough space.  This object requires space for an<br>
156   * additional 16-samples * output-channels<br>
157   * per {IAudioSamples} passed in.<br>
158   * </p><br>
159   * <p><br>
160   * <strong><br>
161   * If the {{@code outputSamples} is not large enough to fit the required
162  resamples, then the {@link IAudioResampler} will attempt to allocate
163  a new output buffer and override the buffer set on {@code outputSamples}.
164  </strong>
165  To ensure you have enough space in your output buffer, use the
166  {@link #getMinimumNumSamplesRequiredInOutputSamples(int)} method.
167  </p>
168  
169  @param outputSamples  [out] The sample buffer we output to.
170  @param inputSamples [in] The samples we're going to re-sample.
171  @param numSamples [in] The number of samples from inputSamples to use.  if 0,
172     this defaults to inputSamples.getNumSamples().
173  
174  @return Number of samples written to outputSamples, or <0 on error.
175  }
176   */
177  public int resample(IAudioSamples outputSamples, IAudioSamples inputSamples, int numSamples) {
178    return AVPKitJNI.IAudioResampler_resample(swigCPtr, this, IAudioSamples.getCPtr(outputSamples), outputSamples, IAudioSamples.getCPtr(inputSamples), inputSamples, numSamples);
179  }
180
181  /**
182   * Create a new {IAudioResampler} object.<br>
183   * <p><br>
184   * Creation of {IAudioResampler} objects is relatively expensive compared<br>
185   * to the {#resample(IAudioSamples, IAudioSamples, long)} method,<br>
186   * so users are encouraged to create once and use often.<br>
187   * </p><br>
188   * <p><br>
189   * This method assumes all samples are in IAudioSamples.Format.FMT_S16 format.<br>
190   * </p><br>
191   * @param outputChannels The number of channels you will want<br>
192   *   in resampled audio we output.<br>
193   * @param inputChannels The number of channels you will pass<br>
194   *   in the source audio for resampling.<br>
195   * @param outputRate The sample rate you will want<br>
196   *   in resampled audio we output.<br>
197   * @param inputRate The sample rate you will pass<br>
198   *   in the source audio for resampling.<br>
199   * @return A new object, or null if we can't allocate one.
200   */
201  public static IAudioResampler make(int outputChannels, int inputChannels, int outputRate, int inputRate) {
202    long cPtr = AVPKitJNI.IAudioResampler_make__SWIG_0(outputChannels, inputChannels, outputRate, inputRate);
203    return (cPtr == 0) ? null : new IAudioResampler(cPtr, false);
204  }
205
206  /**
207   * Get the sample format we expect to resample to.<br>
208   * @return the sample format for output.
209   */
210  public IAudioSamples.Format getOutputFormat() {
211    return IAudioSamples.Format.swigToEnum(AVPKitJNI.IAudioResampler_getOutputFormat(swigCPtr, this));
212  }
213
214  /**
215   * Get the sample format we expect to resample from.<br>
216   * @return the sample format for input.
217   */
218  public IAudioSamples.Format getInputFormat() {
219    return IAudioSamples.Format.swigToEnum(AVPKitJNI.IAudioResampler_getInputFormat(swigCPtr, this));
220  }
221
222  /**
223   * Get the length of each filter in the resampler filter bank.<br>
224   * @return the filter length
225   */
226  public int getFilterLen() {
227    return AVPKitJNI.IAudioResampler_getFilterLen(swigCPtr, this);
228  }
229
230  /**
231   * Get log2(number of entries in filter bank).<br>
232   * @return log2(number of entries in filter bank).
233   */
234  public int getLog2PhaseCount() {
235    return AVPKitJNI.IAudioResampler_getLog2PhaseCount(swigCPtr, this);
236  }
237
238  /**
239   * Are we linearly interpolating between filters?<br>
240   * @return true if interpolating, false if just choosing closest.
241   */
242  public boolean isLinear() {
243    return AVPKitJNI.IAudioResampler_isLinear(swigCPtr, this);
244  }
245
246  /**
247   * What is the cuttoff frequency used?<br>
248   * @return the cuttoff frequency
249   */
250  public double getCutoffFrequency() {
251    return AVPKitJNI.IAudioResampler_getCutoffFrequency(swigCPtr, this);
252  }
253
254  /**
255   * Create a new {IAudioResampler} object.<br>
256   * <p><br>
257   * Creation of {IAudioResampler} objects is relatively expensive compared<br>
258   * to the {#resample(IAudioSamples, IAudioSamples, long)} method,<br>
259   * so users are encouraged to create once and use often.<br>
260   * </p><br>
261   * <p><br>
262   * &quot;Sensible&quot; defaults are passed in for filter length and other<br>
263   * parameters.<br>
264   * </p><br>
265   * @param outputChannels The number of channels you will want<br>
266   *   in resampled audio we output.<br>
267   * @param inputChannels The number of channels you will pass<br>
268   *   in the source audio for resampling.<br>
269   * @param outputRate The sample rate you will want<br>
270   *   in resampled audio we output.<br>
271   * @param inputRate The sample rate you will pass<br>
272   *   in the source audio for resampling.<br>
273   * @param outputFmt The format of the output samples.<br>
274   * @param inputFmt The format of the input samples.<br>
275   * <br>
276   * @return A new object, or null if we can't allocate one.
277   */
278  public static IAudioResampler make(int outputChannels, int inputChannels, int outputRate, int inputRate, IAudioSamples.Format outputFmt, IAudioSamples.Format inputFmt) {
279    long cPtr = AVPKitJNI.IAudioResampler_make__SWIG_1(outputChannels, inputChannels, outputRate, inputRate, outputFmt.swigValue(), inputFmt.swigValue());
280    return (cPtr == 0) ? null : new IAudioResampler(cPtr, false);
281  }
282
283  /**
284   * Create a new {IAudioResampler} object.<br>
285   * <p><br>
286   * Creation of {IAudioResampler} objects is relatively expensive compared<br>
287   * to the {#resample(IAudioSamples, IAudioSamples, long)} method,<br>
288   * so users are encouraged to create once and use often.<br>
289   * </p><br>
290   * <br>
291   * @param outputChannels The number of channels you will want<br>
292   *   in resampled audio we output.<br>
293   * @param inputChannels The number of channels you will pass<br>
294   *   in the source audio for resampling.<br>
295   * @param outputRate The sample rate you will want<br>
296   *   in resampled audio we output.<br>
297   * @param inputRate The sample rate you will pass<br>
298   *   in the source audio for resampling.<br>
299   * @param outputFmt The format of the output samples.<br>
300   * @param inputFmt The format of the input samples.<br>
301   * @param filterLen The length of each filter in the filterbank, relative to the cutoff frequency.<br>
302   * @param log2PhaseCount log2 of the number of entries in the polyphase filterbank<br>
303   * @param isLinear If true, the used filter will be linearly interpolated between the 2 closest filters. <br>
304   *   if false, the closest will be used.<br>
305   * @param cutoffFrequency Cutoff frequency.  1.0 is 1/2 the output sampling rate.<br>
306   * <br>
307   * @return A new object, or null if we can't allocate one.
308   */
309  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) {
310    long cPtr = AVPKitJNI.IAudioResampler_make__SWIG_2(outputChannels, inputChannels, outputRate, inputRate, outputFmt.swigValue(), inputFmt.swigValue(), filterLen, log2PhaseCount, isLinear, cutoffFrequency);
311    return (cPtr == 0) ? null : new IAudioResampler(cPtr, false);
312  }
313
314  /**
315   * Get the minimum number of samples that must be placeable in an<br>
316   * output set of samples in order for a resample with this resampler<br>
317   * to succeed.<br>
318   * <br>
319   * @param inSamples The input samples that will be passed to<br>
320   *   {#resample}.<br>
321   * @return The minimum number of samples, or &lt; 0 on error.<br>
322   * @since 3.2
323   */
324  public int getMinimumNumSamplesRequiredInOutputSamples(IAudioSamples inSamples) {
325    return AVPKitJNI.IAudioResampler_getMinimumNumSamplesRequiredInOutputSamples__SWIG_0(swigCPtr, this, IAudioSamples.getCPtr(inSamples), inSamples);
326  }
327
328  /**
329   * Get the minimum number of samples that must be placeable in an<br>
330   * output set of samples in order for a resample with this resampler<br>
331   * to succeed.<br>
332   * <br>
333   * @param numSamples The number of input samples.<br>
334   * @return The minimum number of samples, or &lt; 0 on error.<br>
335   * @since 3.2
336   */
337  public int getMinimumNumSamplesRequiredInOutputSamples(int numSamples) {
338    return AVPKitJNI.IAudioResampler_getMinimumNumSamplesRequiredInOutputSamples__SWIG_1(swigCPtr, this, numSamples);
339  }
340
341}