OpenShot Library | libopenshot  0.2.5
AudioBufferSource.h
Go to the documentation of this file.
1 /**
2  * @file
3  * @brief Header file for AudioBufferSource 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_AUDIOBUFFERSOURCE_H
32 #define OPENSHOT_AUDIOBUFFERSOURCE_H
33 
34 #include <iomanip>
35 #include "JuceHeader.h"
36 
37 /// This namespace is the default namespace for all code in the openshot library
38 namespace openshot
39 {
40 
41  /**
42  * @brief This class is used to expose an AudioSampleBuffer as an AudioSource in JUCE.
43  *
44  * The <a href="http://www.juce.com/">JUCE</a> library cannot play audio directly from an AudioSampleBuffer, so this class exposes
45  * an AudioSampleBuffer as a AudioSource, so that JUCE can play the audio.
46  */
47  class AudioBufferSource : public juce::PositionableAudioSource
48  {
49  private:
50  int position;
51  int start;
52  bool repeat;
53  juce::AudioSampleBuffer *buffer;
54 
55  public:
56  /// @brief Default constructor
57  /// @param audio_buffer This buffer contains the samples you want to play through JUCE.
58  AudioBufferSource(juce::AudioSampleBuffer *audio_buffer);
59 
60  /// Destructor
62 
63  /// @brief Get the next block of audio samples
64  /// @param info This struct informs us of which samples are needed next.
65  void getNextAudioBlock (const juce::AudioSourceChannelInfo& info);
66 
67  /// Prepare to play this audio source
68  void prepareToPlay(int, double);
69 
70  /// Release all resources
71  void releaseResources();
72 
73  /// @brief Set the next read position of this source
74  /// @param newPosition The sample # to start reading from
75  void setNextReadPosition (juce::int64 newPosition);
76 
77  /// Get the next read position of this source
78  juce::int64 getNextReadPosition() const;
79 
80  /// Get the total length (in samples) of this audio source
81  juce::int64 getTotalLength() const;
82 
83  /// Determines if this audio source should repeat when it reaches the end
84  bool isLooping() const;
85 
86  /// @brief Set if this audio source should repeat when it reaches the end
87  /// @param shouldLoop Determines if the audio source should repeat when it reaches the end
88  void setLooping (bool shouldLoop);
89 
90  /// Update the internal buffer used by this source
91  void setBuffer (juce::AudioSampleBuffer *audio_buffer);
92  };
93 
94 }
95 
96 #endif
openshot::AudioBufferSource::getNextReadPosition
juce::int64 getNextReadPosition() const
Get the next read position of this source.
Definition: AudioBufferSource.cpp:109
openshot::AudioBufferSource::getNextAudioBlock
void getNextAudioBlock(const juce::AudioSourceChannelInfo &info)
Get the next block of audio samples.
Definition: AudioBufferSource.cpp:49
openshot::AudioBufferSource::setLooping
void setLooping(bool shouldLoop)
Set if this audio source should repeat when it reaches the end.
Definition: AudioBufferSource.cpp:130
openshot
This namespace is the default namespace for all code in the openshot library.
Definition: AudioBufferSource.h:39
openshot::AudioBufferSource::isLooping
bool isLooping() const
Determines if this audio source should repeat when it reaches the end.
Definition: AudioBufferSource.cpp:123
openshot::AudioBufferSource::setNextReadPosition
void setNextReadPosition(juce::int64 newPosition)
Set the next read position of this source.
Definition: AudioBufferSource.cpp:101
openshot::AudioBufferSource
This class is used to expose an AudioSampleBuffer as an AudioSource in JUCE.
Definition: AudioBufferSource.h:48
openshot::AudioBufferSource::setBuffer
void setBuffer(juce::AudioSampleBuffer *audio_buffer)
Update the internal buffer used by this source.
Definition: AudioBufferSource.cpp:137
openshot::AudioBufferSource::AudioBufferSource
AudioBufferSource(juce::AudioSampleBuffer *audio_buffer)
Default constructor.
Definition: AudioBufferSource.cpp:37
openshot::AudioBufferSource::releaseResources
void releaseResources()
Release all resources.
Definition: AudioBufferSource.cpp:98
openshot::AudioBufferSource::getTotalLength
juce::int64 getTotalLength() const
Get the total length (in samples) of this audio source.
Definition: AudioBufferSource.cpp:116
openshot::AudioBufferSource::prepareToPlay
void prepareToPlay(int, double)
Prepare to play this audio source.
Definition: AudioBufferSource.cpp:95
openshot::AudioBufferSource::~AudioBufferSource
~AudioBufferSource()
Destructor.
Definition: AudioBufferSource.cpp:42