OpenShot Library | libopenshot-audio 0.2.0
juce_AudioTransportSource.h
1
2/** @weakgroup juce_audio_devices-sources
3 * @{
4 */
5/*
6 ==============================================================================
7
8 This file is part of the JUCE library.
9 Copyright (c) 2017 - ROLI Ltd.
10
11 JUCE is an open source library subject to commercial or open-source
12 licensing.
13
14 The code included in this file is provided under the terms of the ISC license
15 http://www.isc.org/downloads/software-support-policy/isc-license. Permission
16 To use, copy, modify, and/or distribute this software for any purpose with or
17 without fee is hereby granted provided that the above copyright notice and
18 this permission notice appear in all copies.
19
20 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
21 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
22 DISCLAIMED.
23
24 ==============================================================================
25*/
26
27namespace juce
28{
29
30//==============================================================================
31/**
32 An AudioSource that takes a PositionableAudioSource and allows it to be
33 played, stopped, started, etc.
34
35 This can also be told use a buffer and background thread to read ahead, and
36 if can correct for different sample-rates.
37
38 You may want to use one of these along with an AudioSourcePlayer and AudioIODevice
39 to control playback of an audio file.
40
41 @see AudioSource, AudioSourcePlayer
42
43 @tags{Audio}
44*/
47{
48public:
49 //==============================================================================
50 /** Creates an AudioTransportSource.
51 After creating one of these, use the setSource() method to select an input source.
52 */
54
55 /** Destructor. */
56 ~AudioTransportSource() override;
57
58 //==============================================================================
59 /** Sets the reader that is being used as the input source.
60
61 This will stop playback, reset the position to 0 and change to the new reader.
62
63 The source passed in will not be deleted by this object, so must be managed by
64 the caller.
65
66 @param newSource the new input source to use. This may be a nullptr
67 @param readAheadBufferSize a size of buffer to use for reading ahead. If this
68 is zero, no reading ahead will be done; if it's
69 greater than zero, a BufferingAudioSource will be used
70 to do the reading-ahead. If you set a non-zero value here,
71 you'll also need to set the readAheadThread parameter.
72 @param readAheadThread if you set readAheadBufferSize to a non-zero value, then
73 you'll also need to supply this TimeSliceThread object for
74 the background reader to use. The thread object must not be
75 deleted while the AudioTransport source is still using it.
76 @param sourceSampleRateToCorrectFor if this is non-zero, it specifies the sample
77 rate of the source, and playback will be sample-rate
78 adjusted to maintain playback at the correct pitch. If
79 this is 0, no sample-rate adjustment will be performed
80 @param maxNumChannels the maximum number of channels that may need to be played
81 */
82 void setSource (PositionableAudioSource* newSource,
83 int readAheadBufferSize = 0,
86 int maxNumChannels = 2);
87
88 //==============================================================================
89 /** Changes the current playback position in the source stream.
90
91 The next time the getNextAudioBlock() method is called, this
92 is the time from which it'll read data.
93
94 @param newPosition the new playback position in seconds
95
96 @see getCurrentPosition
97 */
98 void setPosition (double newPosition);
99
100 /** Returns the position that the next data block will be read from
101 This is a time in seconds.
102 */
103 double getCurrentPosition() const;
104
105 /** Returns the stream's length in seconds. */
106 double getLengthInSeconds() const;
107
108 /** Returns true if the player has stopped because its input stream ran out of data. */
109 bool hasStreamFinished() const noexcept { return inputStreamEOF; }
110
111 //==============================================================================
112 /** Starts playing (if a source has been selected).
113
114 If it starts playing, this will send a message to any ChangeListeners
115 that are registered with this object.
116 */
117 void start();
118
119 /** Stops playing.
120
121 If it's actually playing, this will send a message to any ChangeListeners
122 that are registered with this object.
123 */
124 void stop();
125
126 /** Returns true if it's currently playing. */
127 bool isPlaying() const noexcept { return playing; }
128
129 //==============================================================================
130 /** Changes the gain to apply to the output.
131 @param newGain a factor by which to multiply the outgoing samples,
132 so 1.0 = 0dB, 0.5 = -6dB, 2.0 = 6dB, etc.
133 */
134 void setGain (float newGain) noexcept;
135
136 /** Returns the current gain setting.
137 @see setGain
138 */
139 float getGain() const noexcept { return gain; }
140
141 //==============================================================================
142 /** Implementation of the AudioSource method. */
143 void prepareToPlay (int samplesPerBlockExpected, double sampleRate) override;
144
145 /** Implementation of the AudioSource method. */
146 void releaseResources() override;
147
148 /** Implementation of the AudioSource method. */
149 void getNextAudioBlock (const AudioSourceChannelInfo&) override;
150
151 //==============================================================================
152 /** Implements the PositionableAudioSource method. */
153 void setNextReadPosition (int64 newPosition) override;
154
155 /** Implements the PositionableAudioSource method. */
156 int64 getNextReadPosition() const override;
157
158 /** Implements the PositionableAudioSource method. */
159 int64 getTotalLength() const override;
160
161 /** Implements the PositionableAudioSource method. */
162 bool isLooping() const override;
163
164private:
165 //==============================================================================
166 PositionableAudioSource* source = nullptr;
167 ResamplingAudioSource* resamplerSource = nullptr;
168 BufferingAudioSource* bufferingSource = nullptr;
169 PositionableAudioSource* positionableSource = nullptr;
170 AudioSource* masterSource = nullptr;
171
172 CriticalSection callbackLock;
173 float gain = 1.0f, lastGain = 1.0f;
174 bool playing = false, stopped = true;
175 double sampleRate = 44100.0, sourceSampleRate = 0;
176 int blockSize = 128, readAheadBufferSize = 0;
177 bool isPrepared = false, inputStreamEOF = false;
178
179 void releaseMasterResources();
180
181 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AudioTransportSource)
182};
183
184} // namespace juce
185
186/** @}*/
Holds a resizable array of primitive or copy-by-value objects.
Definition juce_Array.h:60
Base class for objects that can produce a continuous stream of audio.
An AudioSource that takes a PositionableAudioSource and allows it to be played, stopped,...
bool hasStreamFinished() const noexcept
Returns true if the player has stopped because its input stream ran out of data.
float getGain() const noexcept
Returns the current gain setting.
bool isPlaying() const noexcept
Returns true if it's currently playing.
An AudioSource which takes another source as input, and buffers it using a thread.
Holds a list of ChangeListeners, and sends messages to them when instructed.
A type of AudioSource which can be repositioned.
A type of AudioSource that takes an input source and changes its sample rate.
A thread that keeps a list of clients, and calls each one in turn, giving them all a chance to run so...
#define JUCE_API
This macro is added to all JUCE public class declarations.
Used by AudioSource::getNextAudioBlock().