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