OpenShot Library | libopenshot-audio  0.2.0
juce_MixerAudioSource.h
1 
2 /** @weakgroup juce_audio_basics-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 
27 namespace juce
28 {
29 
30 //==============================================================================
31 /**
32  An AudioSource that mixes together the output of a set of other AudioSources.
33 
34  Input sources can be added and removed while the mixer is running as long as their
35  prepareToPlay() and releaseResources() methods are called before and after adding
36  them to the mixer.
37 
38  @tags{Audio}
39 */
41 {
42 public:
43  //==============================================================================
44  /** Creates a MixerAudioSource. */
46 
47  /** Destructor. */
48  ~MixerAudioSource() override;
49 
50  //==============================================================================
51  /** Adds an input source to the mixer.
52 
53  If the mixer is running you'll need to make sure that the input source
54  is ready to play by calling its prepareToPlay() method before adding it.
55  If the mixer is stopped, then its input sources will be automatically
56  prepared when the mixer's prepareToPlay() method is called.
57 
58  @param newInput the source to add to the mixer
59  @param deleteWhenRemoved if true, then this source will be deleted when
60  no longer needed by the mixer.
61  */
62  void addInputSource (AudioSource* newInput, bool deleteWhenRemoved);
63 
64  /** Removes an input source.
65  If the source was added by calling addInputSource() with the deleteWhenRemoved
66  flag set, it will be deleted by this method.
67  */
68  void removeInputSource (AudioSource* input);
69 
70  /** Removes all the input sources.
71  Any sources which were added by calling addInputSource() with the deleteWhenRemoved
72  flag set will be deleted by this method.
73  */
74  void removeAllInputs();
75 
76  //==============================================================================
77  /** Implementation of the AudioSource method.
78  This will call prepareToPlay() on all its input sources.
79  */
80  void prepareToPlay (int samplesPerBlockExpected, double sampleRate) override;
81 
82  /** Implementation of the AudioSource method.
83  This will call releaseResources() on all its input sources.
84  */
85  void releaseResources() override;
86 
87  /** Implementation of the AudioSource method. */
88  void getNextAudioBlock (const AudioSourceChannelInfo&) override;
89 
90 
91 private:
92  //==============================================================================
93  Array<AudioSource*> inputs;
94  BigInteger inputsToDelete;
95  CriticalSection lock;
96  AudioBuffer<float> tempBuffer;
97  double currentSampleRate;
98  int bufferSizeExpected;
99 
100  JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MixerAudioSource)
101 };
102 
103 } // namespace juce
104 
105 /** @}*/
juce::BigInteger
An arbitrarily large integer class.
Definition: juce_BigInteger.h:42
juce::AudioSource
Base class for objects that can produce a continuous stream of audio.
Definition: juce_AudioSource.h:113
juce::AudioBuffer< float >
juce::Array
Holds a resizable array of primitive or copy-by-value objects.
Definition: juce_Array.h:59
JUCE_API
#define JUCE_API
This macro is added to all JUCE public class declarations.
Definition: juce_StandardHeader.h:143
juce::MixerAudioSource
An AudioSource that mixes together the output of a set of other AudioSources.
Definition: juce_MixerAudioSource.h:40
juce::AudioSourceChannelInfo
Used by AudioSource::getNextAudioBlock().
Definition: juce_AudioSource.h:36
juce::CriticalSection
A re-entrant mutex.
Definition: juce_CriticalSection.h:46