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