Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

juce_ChannelRemappingAudioSource.h 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #ifndef JUCE_CHANNELREMAPPINGAUDIOSOURCE_H_INCLUDED
  18. #define JUCE_CHANNELREMAPPINGAUDIOSOURCE_H_INCLUDED
  19. //==============================================================================
  20. /**
  21. An AudioSource that takes the audio from another source, and re-maps its
  22. input and output channels to a different arrangement.
  23. You can use this to increase or decrease the number of channels that an
  24. audio source uses, or to re-order those channels.
  25. Call the reset() method before using it to set up a default mapping, and then
  26. the setInputChannelMapping() and setOutputChannelMapping() methods to
  27. create an appropriate mapping, otherwise no channels will be connected and
  28. it'll produce silence.
  29. @see AudioSource
  30. */
  31. class ChannelRemappingAudioSource : public AudioSource
  32. {
  33. public:
  34. //==============================================================================
  35. /** Creates a remapping source that will pass on audio from the given input.
  36. @param source the input source to use. Make sure that this doesn't
  37. get deleted before the ChannelRemappingAudioSource object
  38. @param deleteSourceWhenDeleted if true, the input source will be deleted
  39. when this object is deleted, if false, the caller is
  40. responsible for its deletion
  41. */
  42. ChannelRemappingAudioSource (AudioSource* source,
  43. bool deleteSourceWhenDeleted);
  44. /** Destructor. */
  45. ~ChannelRemappingAudioSource();
  46. //==============================================================================
  47. /** Specifies a number of channels that this audio source must produce from its
  48. getNextAudioBlock() callback.
  49. */
  50. void setNumberOfChannelsToProduce (int requiredNumberOfChannels);
  51. /** Clears any mapped channels.
  52. After this, no channels are mapped, so this object will produce silence. Create
  53. some mappings with setInputChannelMapping() and setOutputChannelMapping().
  54. */
  55. void clearAllMappings();
  56. /** Creates an input channel mapping.
  57. When the getNextAudioBlock() method is called, the data in channel sourceChannelIndex of the incoming
  58. data will be sent to destChannelIndex of our input source.
  59. @param destChannelIndex the index of an input channel in our input audio source (i.e. the
  60. source specified when this object was created).
  61. @param sourceChannelIndex the index of the input channel in the incoming audio data buffer
  62. during our getNextAudioBlock() callback
  63. */
  64. void setInputChannelMapping (int destChannelIndex,
  65. int sourceChannelIndex);
  66. /** Creates an output channel mapping.
  67. When the getNextAudioBlock() method is called, the data returned in channel sourceChannelIndex by
  68. our input audio source will be copied to channel destChannelIndex of the final buffer.
  69. @param sourceChannelIndex the index of an output channel coming from our input audio source
  70. (i.e. the source specified when this object was created).
  71. @param destChannelIndex the index of the output channel in the incoming audio data buffer
  72. during our getNextAudioBlock() callback
  73. */
  74. void setOutputChannelMapping (int sourceChannelIndex,
  75. int destChannelIndex);
  76. /** Returns the channel from our input that will be sent to channel inputChannelIndex of
  77. our input audio source.
  78. */
  79. int getRemappedInputChannel (int inputChannelIndex) const;
  80. /** Returns the output channel to which channel outputChannelIndex of our input audio
  81. source will be sent to.
  82. */
  83. int getRemappedOutputChannel (int outputChannelIndex) const;
  84. //==============================================================================
  85. /** Returns an XML object to encapsulate the state of the mappings.
  86. @see restoreFromXml
  87. */
  88. XmlElement* createXml() const;
  89. /** Restores the mappings from an XML object created by createXML().
  90. @see createXml
  91. */
  92. void restoreFromXml (const XmlElement&);
  93. //==============================================================================
  94. void prepareToPlay (int samplesPerBlockExpected, double sampleRate) override;
  95. void releaseResources() override;
  96. void getNextAudioBlock (const AudioSourceChannelInfo&) override;
  97. private:
  98. //==============================================================================
  99. OptionalScopedPointer<AudioSource> source;
  100. Array<int> remappedInputs, remappedOutputs;
  101. int requiredNumberOfChannels;
  102. AudioSampleBuffer buffer;
  103. AudioSourceChannelInfo remappedInfo;
  104. CriticalSection lock;
  105. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ChannelRemappingAudioSource)
  106. };
  107. #endif // JUCE_CHANNELREMAPPINGAUDIOSOURCE_H_INCLUDED