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 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. The code included in this file is provided under the terms of the ISC license
  8. http://www.isc.org/downloads/software-support-policy/isc-license. Permission
  9. To use, copy, modify, and/or distribute this software for any purpose with or
  10. without fee is hereby granted provided that the above copyright notice and
  11. this permission notice appear in all copies.
  12. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  13. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  14. DISCLAIMED.
  15. ==============================================================================
  16. */
  17. namespace juce
  18. {
  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. } // namespace juce