OpenShot Library | OpenShotAudio  0.2.2
juce_ChannelRemappingAudioSource.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 takes the audio from another source, and re-maps its
33  input and output channels to a different arrangement.
34 
35  You can use this to increase or decrease the number of channels that an
36  audio source uses, or to re-order those channels.
37 
38  Call the reset() method before using it to set up a default mapping, and then
39  the setInputChannelMapping() and setOutputChannelMapping() methods to
40  create an appropriate mapping, otherwise no channels will be connected and
41  it'll produce silence.
42 
43  @see AudioSource
44 
45  @tags{Audio}
46 */
48 {
49 public:
50  //==============================================================================
51  /** Creates a remapping source that will pass on audio from the given input.
52 
53  @param source the input source to use. Make sure that this doesn't
54  get deleted before the ChannelRemappingAudioSource object
55  @param deleteSourceWhenDeleted if true, the input source will be deleted
56  when this object is deleted, if false, the caller is
57  responsible for its deletion
58  */
60  bool deleteSourceWhenDeleted);
61 
62  /** Destructor. */
64 
65  //==============================================================================
66  /** Specifies a number of channels that this audio source must produce from its
67  getNextAudioBlock() callback.
68  */
69  void setNumberOfChannelsToProduce (int requiredNumberOfChannels);
70 
71  /** Clears any mapped channels.
72 
73  After this, no channels are mapped, so this object will produce silence. Create
74  some mappings with setInputChannelMapping() and setOutputChannelMapping().
75  */
76  void clearAllMappings();
77 
78  /** Creates an input channel mapping.
79 
80  When the getNextAudioBlock() method is called, the data in channel sourceChannelIndex of the incoming
81  data will be sent to destChannelIndex of our input source.
82 
83  @param destChannelIndex the index of an input channel in our input audio source (i.e. the
84  source specified when this object was created).
85  @param sourceChannelIndex the index of the input channel in the incoming audio data buffer
86  during our getNextAudioBlock() callback
87  */
88  void setInputChannelMapping (int destChannelIndex,
89  int sourceChannelIndex);
90 
91  /** Creates an output channel mapping.
92 
93  When the getNextAudioBlock() method is called, the data returned in channel sourceChannelIndex by
94  our input audio source will be copied to channel destChannelIndex of the final buffer.
95 
96  @param sourceChannelIndex the index of an output channel coming from our input audio source
97  (i.e. the source specified when this object was created).
98  @param destChannelIndex the index of the output channel in the incoming audio data buffer
99  during our getNextAudioBlock() callback
100  */
101  void setOutputChannelMapping (int sourceChannelIndex,
102  int destChannelIndex);
103 
104  /** Returns the channel from our input that will be sent to channel inputChannelIndex of
105  our input audio source.
106  */
107  int getRemappedInputChannel (int inputChannelIndex) const;
108 
109  /** Returns the output channel to which channel outputChannelIndex of our input audio
110  source will be sent to.
111  */
112  int getRemappedOutputChannel (int outputChannelIndex) const;
113 
114 
115  //==============================================================================
116  /** Returns an XML object to encapsulate the state of the mappings.
117  @see restoreFromXml
118  */
119  std::unique_ptr<XmlElement> createXml() const;
120 
121  /** Restores the mappings from an XML object created by createXML().
122  @see createXml
123  */
124  void restoreFromXml (const XmlElement&);
125 
126  //==============================================================================
127  void prepareToPlay (int samplesPerBlockExpected, double sampleRate) override;
128  void releaseResources() override;
129  void getNextAudioBlock (const AudioSourceChannelInfo&) override;
130 
131 
132 private:
133  //==============================================================================
135  Array<int> remappedInputs, remappedOutputs;
136  int requiredNumberOfChannels;
137 
138  AudioBuffer<float> buffer;
139  AudioSourceChannelInfo remappedInfo;
140  CriticalSection lock;
141 
142  JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ChannelRemappingAudioSource)
143 };
144 
145 } // namespace juce
146 
147 /** @}*/
Base class for objects that can produce a continuous stream of audio.
An AudioSource that takes the audio from another source, and re-maps its input and output channels to...
void setOutputChannelMapping(int sourceChannelIndex, int destChannelIndex)
Creates an output channel mapping.
void getNextAudioBlock(const AudioSourceChannelInfo &) override
Called repeatedly to fetch subsequent blocks of audio data.
void prepareToPlay(int samplesPerBlockExpected, double sampleRate) override
Tells the source to prepare for playing.
void setNumberOfChannelsToProduce(int requiredNumberOfChannels)
Specifies a number of channels that this audio source must produce from its getNextAudioBlock() callb...
void restoreFromXml(const XmlElement &)
Restores the mappings from an XML object created by createXML().
void clearAllMappings()
Clears any mapped channels.
void releaseResources() override
Allows the source to release anything it no longer needs after playback has stopped.
int getRemappedInputChannel(int inputChannelIndex) const
Returns the channel from our input that will be sent to channel inputChannelIndex of our input audio ...
int getRemappedOutputChannel(int outputChannelIndex) const
Returns the output channel to which channel outputChannelIndex of our input audio source will be sent...
ChannelRemappingAudioSource(AudioSource *source, bool deleteSourceWhenDeleted)
Creates a remapping source that will pass on audio from the given input.
std::unique_ptr< XmlElement > createXml() const
Returns an XML object to encapsulate the state of the mappings.
void setInputChannelMapping(int destChannelIndex, int sourceChannelIndex)
Creates an input channel mapping.
A re-entrant mutex.
Holds a pointer to an object which can optionally be deleted when this pointer goes out of scope.
Used to build a tree of elements representing an XML document.
Used by AudioSource::getNextAudioBlock().