OpenShot Library | libopenshot  0.2.7
AudioResampler.h
Go to the documentation of this file.
1 /**
2  * @file
3  * @brief Header file for AudioResampler class
4  * @author Jonathan Thomas <jonathan@openshot.org>
5  *
6  * @ref License
7  */
8 
9 /* LICENSE
10  *
11  * Copyright (c) 2008-2019 OpenShot Studios, LLC
12  * <http://www.openshotstudios.com/>. This file is part of
13  * OpenShot Library (libopenshot), an open-source project dedicated to
14  * delivering high quality video editing and animation solutions to the
15  * world. For more information visit <http://www.openshot.org/>.
16  *
17  * OpenShot Library (libopenshot) is free software: you can redistribute it
18  * and/or modify it under the terms of the GNU Lesser General Public License
19  * as published by the Free Software Foundation, either version 3 of the
20  * License, or (at your option) any later version.
21  *
22  * OpenShot Library (libopenshot) is distributed in the hope that it will be
23  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25  * GNU Lesser General Public License for more details.
26  *
27  * You should have received a copy of the GNU Lesser General Public License
28  * along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
29  */
30 
31 #ifndef OPENSHOT_RESAMPLER_H
32 #define OPENSHOT_RESAMPLER_H
33 
34 #include "AudioBufferSource.h"
35 #include <OpenShotAudio.h>
36 
37 namespace openshot {
38 
39  /**
40  * @brief This class is used to resample audio data for many sequential frames.
41  *
42  * It maintains some data from the last call to GetResampledBuffer(), so there
43  * are no pops and clicks between frames.
44  */
46  private:
47  juce::AudioSampleBuffer *buffer;
48  juce::AudioSampleBuffer *resampled_buffer;
49  openshot::AudioBufferSource *buffer_source;
50  juce::ResamplingAudioSource *resample_source;
51  juce::AudioSourceChannelInfo resample_callback_buffer;
52 
53  int num_of_samples;
54  int new_num_of_samples;
55  double dest_ratio;
56  double source_ratio;
57  bool isPrepared;
58 
59  public:
60  /// Default constructor
62 
63  /// Destructor
65 
66  /// @brief Sets the audio buffer and key settings
67  /// @param new_buffer The buffer of audio samples needing to be resampled
68  /// @param sample_rate The original sample rate of the buffered samples
69  /// @param new_sample_rate The requested sample rate you need
70  void SetBuffer(juce::AudioSampleBuffer *new_buffer, double sample_rate, double new_sample_rate);
71 
72  /// @brief Sets the audio buffer and key settings
73  /// @param new_buffer The buffer of audio samples needing to be resampled
74  /// @param ratio The multiplier that needs to be applied to the sample rate (this is how resampling happens)
75  void SetBuffer(juce::AudioSampleBuffer *new_buffer, double ratio);
76 
77  /// Get the resampled audio buffer
78  juce::AudioSampleBuffer* GetResampledBuffer();
79  };
80 
81 }
82 
83 #endif
Header file for AudioBufferSource class.
This class is used to expose an AudioSampleBuffer as an AudioSource in JUCE.
This class is used to resample audio data for many sequential frames.
juce::AudioSampleBuffer * GetResampledBuffer()
Get the resampled audio buffer.
AudioResampler()
Default constructor.
void SetBuffer(juce::AudioSampleBuffer *new_buffer, double sample_rate, double new_sample_rate)
Sets the audio buffer and key settings.
This namespace is the default namespace for all code in the openshot library.
Definition: Compressor.h:47