2013-09-08 23:09:54 -05:00
|
|
|
/**
|
|
|
|
|
* @file
|
|
|
|
|
* @brief Header file for AudioResampler class
|
|
|
|
|
* @author Jonathan Thomas <jonathan@openshot.org>
|
|
|
|
|
*
|
2019-06-09 08:31:04 -04:00
|
|
|
* @ref License
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* LICENSE
|
2013-09-08 23:09:54 -05:00
|
|
|
*
|
2019-06-11 06:48:32 -04:00
|
|
|
* Copyright (c) 2008-2019 OpenShot Studios, LLC
|
2014-03-29 18:49:22 -05:00
|
|
|
* <http://www.openshotstudios.com/>. This file is part of
|
|
|
|
|
* OpenShot Library (libopenshot), an open-source project dedicated to
|
|
|
|
|
* delivering high quality video editing and animation solutions to the
|
|
|
|
|
* world. For more information visit <http://www.openshot.org/>.
|
2013-09-08 23:09:54 -05:00
|
|
|
*
|
2014-03-29 18:49:22 -05:00
|
|
|
* OpenShot Library (libopenshot) is free software: you can redistribute it
|
2014-07-11 16:52:14 -05:00
|
|
|
* and/or modify it under the terms of the GNU Lesser General Public License
|
2014-03-29 18:49:22 -05:00
|
|
|
* as published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
* License, or (at your option) any later version.
|
2013-09-08 23:09:54 -05:00
|
|
|
*
|
2014-03-29 18:49:22 -05:00
|
|
|
* OpenShot Library (libopenshot) is distributed in the hope that it will be
|
|
|
|
|
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2014-07-11 16:52:14 -05:00
|
|
|
* GNU Lesser General Public License for more details.
|
2013-09-08 23:09:54 -05:00
|
|
|
*
|
2014-07-11 16:52:14 -05:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
2014-03-29 18:49:22 -05:00
|
|
|
* along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
|
2013-09-08 23:09:54 -05:00
|
|
|
*/
|
|
|
|
|
|
2012-08-05 15:17:37 -05:00
|
|
|
#ifndef OPENSHOT_RESAMPLER_H
|
|
|
|
|
#define OPENSHOT_RESAMPLER_H
|
|
|
|
|
|
|
|
|
|
/// Do not include the juce unittest headers, because it collides with unittest++
|
|
|
|
|
#ifndef __JUCE_UNITTEST_JUCEHEADER__
|
|
|
|
|
#define __JUCE_UNITTEST_JUCEHEADER__
|
|
|
|
|
#endif
|
|
|
|
|
|
2013-06-09 01:08:23 -05:00
|
|
|
#ifndef _NDEBUG
|
|
|
|
|
// Define NO debug for JUCE on mac os
|
|
|
|
|
#define _NDEBUG
|
|
|
|
|
#endif
|
|
|
|
|
|
2012-08-05 15:17:37 -05:00
|
|
|
#include "AudioBufferSource.h"
|
|
|
|
|
#include "Exceptions.h"
|
2019-03-30 14:23:50 -05:00
|
|
|
#include "JuceHeader.h"
|
2012-08-05 15:17:37 -05:00
|
|
|
|
|
|
|
|
namespace openshot {
|
|
|
|
|
|
|
|
|
|
/**
|
2013-09-10 12:59:06 -05:00
|
|
|
* @brief This class is used to resample audio data for many sequential frames.
|
|
|
|
|
*
|
|
|
|
|
* It maintains some data from the last call to GetResampledBuffer(), so there
|
|
|
|
|
* are no pops and clicks between frames.
|
2012-08-05 15:17:37 -05:00
|
|
|
*/
|
|
|
|
|
class AudioResampler {
|
|
|
|
|
private:
|
2019-08-05 02:15:01 -04:00
|
|
|
juce::AudioSampleBuffer *buffer;
|
|
|
|
|
juce::AudioSampleBuffer *resampled_buffer;
|
|
|
|
|
openshot::AudioBufferSource *buffer_source;
|
|
|
|
|
juce::ResamplingAudioSource *resample_source;
|
|
|
|
|
juce::AudioSourceChannelInfo resample_callback_buffer;
|
2012-08-05 15:17:37 -05:00
|
|
|
|
|
|
|
|
int num_of_samples;
|
|
|
|
|
int new_num_of_samples;
|
|
|
|
|
double dest_ratio;
|
|
|
|
|
double source_ratio;
|
|
|
|
|
bool isPrepared;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
/// Default constructor
|
|
|
|
|
AudioResampler();
|
|
|
|
|
|
|
|
|
|
/// Destructor
|
|
|
|
|
~AudioResampler();
|
|
|
|
|
|
2013-09-10 13:56:16 -05:00
|
|
|
/// @brief Sets the audio buffer and key settings
|
2013-09-10 22:11:47 -05:00
|
|
|
/// @param new_buffer The buffer of audio samples needing to be resampled
|
2013-09-10 13:56:16 -05:00
|
|
|
/// @param sample_rate The original sample rate of the buffered samples
|
2013-09-10 22:11:47 -05:00
|
|
|
/// @param new_sample_rate The requested sample rate you need
|
2019-08-05 02:15:01 -04:00
|
|
|
void SetBuffer(juce::AudioSampleBuffer *new_buffer, double sample_rate, double new_sample_rate);
|
2012-08-05 15:17:37 -05:00
|
|
|
|
2013-09-10 13:56:16 -05:00
|
|
|
/// @brief Sets the audio buffer and key settings
|
2013-09-10 22:11:47 -05:00
|
|
|
/// @param new_buffer The buffer of audio samples needing to be resampled
|
2013-09-10 13:56:16 -05:00
|
|
|
/// @param ratio The multiplier that needs to be applied to the sample rate (this is how resampling happens)
|
2019-08-05 02:15:01 -04:00
|
|
|
void SetBuffer(juce::AudioSampleBuffer *new_buffer, double ratio);
|
2012-10-21 05:29:29 -05:00
|
|
|
|
2012-08-05 15:17:37 -05:00
|
|
|
/// Get the resampled audio buffer
|
2019-08-05 02:15:01 -04:00
|
|
|
juce::AudioSampleBuffer* GetResampledBuffer();
|
2012-08-05 15:17:37 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|