AVPKit
AudioResampler.h
1 /*******************************************************************************
2  * Copyright (c) 2024, 2026, Olivier Ayache. All rights reserved.
3  *
4  * This file is part of AVPKit.
5  *
6  * AVPKit is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * AVPKit is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with AVPKit. If not, see <http://www.gnu.org/licenses/>.
18  *******************************************************************************/
19 
20 #ifndef AUDIORESAMPLER_H_
21 #define AUDIORESAMPLER_H_
22 
23 #include <com/avpkit/core/IAudioResampler.h>
24 #include <com/avpkit/core/FfmpegIncludes.h>
25 
26 namespace com { namespace avpkit { namespace core
27  {
28 
30  {
31  private:
32  VS_JNIUTILS_REFCOUNTED_OBJECT_PRIVATE_MAKE(AudioResampler);
33  public:
34 
35  // IAudioResampler
36  virtual int getOutputChannels();
37  virtual int getOutputRate();
38  virtual int getInputChannels();
39  virtual int getInputRate();
40  virtual int resample(IAudioSamples *pOutputSamples, IAudioSamples *pInputSamples,
41  int32_t numSamples);
42 
45  virtual int32_t getFilterLen();
46  virtual int32_t getLog2PhaseCount();
47  virtual bool isLinear();
48  virtual double getCutoffFrequency();
49 
50  // Not for calling from Java
51  static AudioResampler* make(int32_t outputChannels, int32_t inputChannels,
52  int32_t outputRate, int32_t inputRate);
53 
54  static AudioResampler* make(int32_t outputChannels, int32_t inputChannels,
55  int32_t outputRate, int32_t inputRate,
56  IAudioSamples::Format outputFmt, IAudioSamples::Format inputFmt);
57 
58  static AudioResampler* make(int32_t outputChannels, int32_t inputChannels,
59  int32_t outputRate, int32_t inputRate,
60  IAudioSamples::Format outputFmt, IAudioSamples::Format inputFmt,
61  int32_t filterLen, int32_t log2PhaseCount,
62  bool isLinear, double cutoff);
63 
65  IAudioSamples* inSamples);
67  int32_t numSamples);
68 
69  protected:
71  virtual ~AudioResampler();
72  private:
73  SwrContext *swrContext;//Not used for the moment will replace mContext and deprecated resampler
74  int32_t mOChannels;
75  int32_t mOSampleRate;
76  int32_t mIChannels;
77  int32_t mISampleRate;
80  int32_t mFilterLen;
81  int32_t mLog2PhaseCount;
82  bool mIsLinear;
83  double mCutoff ;
84  int64_t mNextPts;
85  int64_t mPtsOffset;
86  };
87 
88  }}}
89 
90 #endif /*AUDIORESAMPLER_H_*/
virtual int resample(IAudioSamples *pOutputSamples, IAudioSamples *pInputSamples, int32_t numSamples)
Re-sample up to numSamples from inputSamples to outputSamples.
virtual int32_t getMinimumNumSamplesRequiredInOutputSamples(IAudioSamples *inSamples)
Get the minimum number of samples that must be placeable in an output set of samples in order for a r...
virtual int32_t getFilterLen()
Get the length of each filter in the resampler filter bank.
virtual double getCutoffFrequency()
What is the cuttoff frequency used?
virtual int getInputChannels()
number of channels expected in input audio.
virtual int getOutputRate()
sample rate of output audio.
virtual IAudioSamples::Format getInputFormat()
Get the sample format we expect to resample from.
virtual bool isLinear()
Are we linearly interpolating between filters?
virtual int getOutputChannels()
number of channels in output audio.
virtual int32_t getLog2PhaseCount()
Get log2(number of entries in filter bank).
virtual IAudioSamples::Format getOutputFormat()
Get the sample format we expect to resample to.
virtual int getInputRate()
sample rate expected in input audio.
Used to resample IAudioSamples to different sample rates or number of channels.
A set of raw (decoded) samples, plus a timestamp for when to play those samples relative to other ite...
Definition: IAudioSamples.h:38
Format
The format we use to represent audio.
Definition: IAudioSamples.h:46
WARNING: Do not use logging in this class, and do not set any static file variables to values other t...