OpenShot Library | libopenshot  0.2.4
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 "Exceptions.h"
36 #include "JuceHeader.h"
37 
38 namespace openshot {
39 
40  /**
41  * @brief This class is used to resample audio data for many sequential frames.
42  *
43  * It maintains some data from the last call to GetResampledBuffer(), so there
44  * are no pops and clicks between frames.
45  */
47  private:
48  juce::AudioSampleBuffer *buffer;
49  juce::AudioSampleBuffer *resampled_buffer;
50  openshot::AudioBufferSource *buffer_source;
51  juce::ResamplingAudioSource *resample_source;
52  juce::AudioSourceChannelInfo resample_callback_buffer;
53 
54  int num_of_samples;
55  int new_num_of_samples;
56  double dest_ratio;
57  double source_ratio;
58  bool isPrepared;
59 
60  public:
61  /// Default constructor
63 
64  /// Destructor
66 
67  /// @brief Sets the audio buffer and key settings
68  /// @param new_buffer The buffer of audio samples needing to be resampled
69  /// @param sample_rate The original sample rate of the buffered samples
70  /// @param new_sample_rate The requested sample rate you need
71  void SetBuffer(juce::AudioSampleBuffer *new_buffer, double sample_rate, double new_sample_rate);
72 
73  /// @brief Sets the audio buffer and key settings
74  /// @param new_buffer The buffer of audio samples needing to be resampled
75  /// @param ratio The multiplier that needs to be applied to the sample rate (this is how resampling happens)
76  void SetBuffer(juce::AudioSampleBuffer *new_buffer, double ratio);
77 
78  /// Get the resampled audio buffer
79  juce::AudioSampleBuffer* GetResampledBuffer();
80  };
81 
82 }
83 
84 #endif
Header file for AudioBufferSource class.
This class is used to expose an AudioSampleBuffer as an AudioSource in JUCE.
Header file for all Exception classes.
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.
juce::AudioSampleBuffer * GetResampledBuffer()
Get the resampled audio buffer.
This class is used to resample audio data for many sequential frames.