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.

83 lines
3.3KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2020 - Raw Material Software Limited
  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 which takes some float audio data as an input.
  22. @tags{Audio}
  23. */
  24. class JUCE_API MemoryAudioSource : public PositionableAudioSource
  25. {
  26. public:
  27. //==============================================================================
  28. /** Creates a MemoryAudioSource by providing an audio buffer.
  29. If copyMemory is true then the buffer will be copied into an internal
  30. buffer which will be owned by the MemoryAudioSource. If copyMemory is
  31. false, then you must ensure that the lifetime of the audio buffer is
  32. at least as long as the MemoryAudioSource.
  33. */
  34. MemoryAudioSource (AudioBuffer<float>& audioBuffer, bool copyMemory, bool shouldLoop = false);
  35. //==============================================================================
  36. /** Implementation of the AudioSource method. */
  37. void prepareToPlay (int samplesPerBlockExpected, double sampleRate) override;
  38. /** Implementation of the AudioSource method. */
  39. void releaseResources() override;
  40. /** Implementation of the AudioSource method. */
  41. void getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill) override;
  42. //==============================================================================
  43. /** Implementation of the PositionableAudioSource method. */
  44. void setNextReadPosition (int64 newPosition) override;
  45. /** Implementation of the PositionableAudioSource method. */
  46. int64 getNextReadPosition() const override;
  47. /** Implementation of the PositionableAudioSource method. */
  48. int64 getTotalLength() const override;
  49. //==============================================================================
  50. /** Implementation of the PositionableAudioSource method. */
  51. bool isLooping() const override;
  52. /** Implementation of the PositionableAudioSource method. */
  53. void setLooping (bool shouldLoop) override;
  54. private:
  55. //==============================================================================
  56. AudioBuffer<float> buffer;
  57. int position = 0;
  58. bool isCurrentlyLooping;
  59. //==============================================================================
  60. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MemoryAudioSource)
  61. };
  62. } // namespace juce